Skip to content

Commit 4fef0f8

Browse files
committed
Use same keys for system props and env vars
The previous mapping of env var keys to lowercase for system props was at attempt to make build scripts look nicer, but violated the principle of least surprise.
1 parent a3e4937 commit 4fef0f8

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@ The following environment variables configure the snapshot generated by the `Git
3838
- `DEPENDENCY_GRAPH_REPORT_DIR` (optional): Specifies where the dependency graph report will be generated
3939

4040
Each of these values can also be provided via a system property.
41-
The equivalent system property name is lower case, with '_' replaced by '-'.
42-
eg: Env var `DEPENDENCY_GRAPH_REPORT_DIR` can be set as `-Ddependency-graph-report-dir=foo` on the command-line.
41+
eg: Env var `DEPENDENCY_GRAPH_REPORT_DIR` can be set with `-DDEPENDENCY_GRAPH_REPORT_DIR=...` on the command-line.
4342

4443
### Filtering which Gradle Configurations contribute to the dependency graph
4544

4645
If you do not want to include every dependency configuration in every project in your build, you can limit the
4746
dependency extraction to a subset of these.
4847

4948
To restrict which Gradle subprojects contribute to the report, specify which projects to include via a regular expression.
50-
You can provide this value via the `DEPENDENCY_GRAPH_INCLUDE_PROJECTS` environment variable, or the `dependency-graph-include-projects` System property.
49+
You can provide this value via the `DEPENDENCY_GRAPH_INCLUDE_PROJECTS` environment variable or system property.
5150

5251
To restrict which Gradle configurations contribute to the report, you can filter configurations by name using a regular expression.
53-
You can provide this value via the `DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS` environment variable, or the `dependency-graph-include-configurations` System property.
52+
You can provide this value via the `DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS` environment variable or system property.
5453

5554
### Gradle compatibility
5655

plugin-test/src/test/groovy/org/gradle/github/dependencygraph/DependencyExtractorConfigTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class DependencyExtractorConfigTest extends BaseExtractorTest {
3838

3939
when:
4040
executer
41-
.withArgument("-Dgithub-job-correlator=TEST_CORRELATOR")
42-
.withArgument("-Dgithub-ref=refs/my-branch/foo")
41+
.withArgument("-DGITHUB_JOB_CORRELATOR=TEST_CORRELATOR")
42+
.withArgument("-DGITHUB_REF=refs/my-branch/foo")
4343
run()
4444

4545
then:

plugin-test/src/test/groovy/org/gradle/github/dependencygraph/MultiProjectDependencyExtractorTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class MultiProjectDependencyExtractorTest extends BaseExtractorTest {
271271
"""
272272

273273
when:
274-
executer.withArgument("-Ddependency-graph-include-projects=:b")
274+
executer.withArgument("-DDEPENDENCY_GRAPH_INCLUDE_PROJECTS=:b")
275275
run()
276276

277277
then:
@@ -304,7 +304,7 @@ class MultiProjectDependencyExtractorTest extends BaseExtractorTest {
304304
"""
305305

306306
when:
307-
executer.withArgument("-Ddependency-graph-include-configurations=compileClasspath")
307+
executer.withArgument("-DDEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS=compileClasspath")
308308
run()
309309

310310
then:

plugin/src/main/kotlin/org/gradle/github/dependencygraph/internal/util/PluginParameters.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,19 @@ const val PARAM_GITHUB_WORKSPACE = "GITHUB_WORKSPACE"
1919

2020
class PluginParameters {
2121
fun load(envName: String, default: String? = null): String {
22-
return System.getProperty(sysPropName(envName))
22+
return System.getProperty(envName)
2323
?: System.getenv()[envName]
2424
?: default
2525
?: throwEnvironmentVariableMissingException(envName)
2626
}
2727

2828
fun loadOptional(envName: String): String? {
29-
return System.getProperty(sysPropName(envName))
29+
return System.getProperty(envName)
3030
?: System.getenv()[envName]
3131
}
3232

33-
private fun sysPropName(envName: String): String {
34-
return envName.toLowerCase().replace('_', '-')
35-
}
36-
3733
private fun throwEnvironmentVariableMissingException(variable: String): Nothing {
3834
throw IllegalStateException("The configuration parameter '$variable' must be set: " +
39-
"set an environment variable, or '-D${sysPropName(variable)}=value' on the command-line.")
35+
"set an environment variable, or use '-D${variable}=value' on the command-line.")
4036
}
4137
}

0 commit comments

Comments
 (0)