Skip to content

Commit 4b9dafa

Browse files
author
Maksim Turaev
committed
Fix issue with system properties not being applied on configuration reading.
Previously, when you run profiler with some scenario and add system property with -Dkey=value. This property would not be passed to a configurationReader. So in our case, nexus credentials were not provided and :help task in the configuration reader couldn't be executed. I've added an additional parameter to a BuildConfigurationReader, so it taking into account system properties. Signed-off-by: Maksim Turaev <[email protected]>
1 parent e0cfe31 commit 4b9dafa

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main/java/org/gradle/profiler/DefaultGradleBuildConfigurationReader.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ public class DefaultGradleBuildConfigurationReader implements GradleBuildConfigu
2929
private final File buildDetails;
3030
private final Map<String, GradleBuildConfiguration> versions = new HashMap<>();
3131
private GradleBuildConfiguration defaultVersion;
32+
private final Map<String, String> systemProperties;
3233

33-
public DefaultGradleBuildConfigurationReader(File projectDir, File gradleUserHome, DaemonControl daemonControl) throws IOException {
34+
public DefaultGradleBuildConfigurationReader(File projectDir, File gradleUserHome, DaemonControl daemonControl, Map<String, String> systemProperties) throws IOException {
3435
this.projectDir = projectDir;
3536
this.gradleUserHome = gradleUserHome;
3637
this.daemonControl = daemonControl;
38+
this.systemProperties = systemProperties;
3739
initScript = File.createTempFile("gradle-profiler", ".gradle").getCanonicalFile();
3840
initScript.deleteOnExit();
3941
buildDetails = File.createTempFile("gradle-profiler", "build-details");
@@ -107,7 +109,8 @@ private GradleBuildConfiguration probe(GradleConnector connector) {
107109
GradleBuildConfiguration version;
108110
try (ProjectConnection connection = connector.forProjectDirectory(projectDir).connect()) {
109111
BuildEnvironment buildEnvironment = connection.getModel(BuildEnvironment.class);
110-
new ToolingApiGradleClient(connection).runTasks(ImmutableList.of("help"), ImmutableList.of("-I", initScript.getAbsolutePath()), ImmutableList.of());
112+
List<String> gradleArgs = buildGradleArgs();
113+
new ToolingApiGradleClient(connection).runTasks(ImmutableList.of("help"), gradleArgs, ImmutableList.of());
111114
List<String> buildDetails = readBuildDetails();
112115
JavaEnvironment javaEnvironment = buildEnvironment.getJava();
113116
List<String> allJvmArgs = new ArrayList<>(javaEnvironment.getJvmArguments());
@@ -124,6 +127,16 @@ private GradleBuildConfiguration probe(GradleConnector connector) {
124127
return version;
125128
}
126129

130+
private List<String> buildGradleArgs() {
131+
List<String> result = new ArrayList<>();
132+
133+
result.add("-I");
134+
result.add(initScript.getAbsolutePath());
135+
136+
systemProperties.forEach((key, value) -> result.add("-D" + key + "=" + value));
137+
return Collections.unmodifiableList(result);
138+
}
139+
127140
private List<String> readSystemPropertiesFromGradleProperties() {
128141
String jvmArgs = getJvmArgsProperty(gradleUserHome);
129142
if (jvmArgs == null) {

0 commit comments

Comments
 (0)