Skip to content

Commit

Permalink
Fix issue with system properties not being applied on configuration r…
Browse files Browse the repository at this point in the history
…eading.

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]>
  • Loading branch information
Maksim Turaev committed Oct 1, 2020
1 parent e0cfe31 commit 4b9dafa
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public class DefaultGradleBuildConfigurationReader implements GradleBuildConfigu
private final File buildDetails;
private final Map<String, GradleBuildConfiguration> versions = new HashMap<>();
private GradleBuildConfiguration defaultVersion;
private final Map<String, String> systemProperties;

public DefaultGradleBuildConfigurationReader(File projectDir, File gradleUserHome, DaemonControl daemonControl) throws IOException {
public DefaultGradleBuildConfigurationReader(File projectDir, File gradleUserHome, DaemonControl daemonControl, Map<String, String> systemProperties) throws IOException {
this.projectDir = projectDir;
this.gradleUserHome = gradleUserHome;
this.daemonControl = daemonControl;
this.systemProperties = systemProperties;
initScript = File.createTempFile("gradle-profiler", ".gradle").getCanonicalFile();
initScript.deleteOnExit();
buildDetails = File.createTempFile("gradle-profiler", "build-details");
Expand Down Expand Up @@ -107,7 +109,8 @@ private GradleBuildConfiguration probe(GradleConnector connector) {
GradleBuildConfiguration version;
try (ProjectConnection connection = connector.forProjectDirectory(projectDir).connect()) {
BuildEnvironment buildEnvironment = connection.getModel(BuildEnvironment.class);
new ToolingApiGradleClient(connection).runTasks(ImmutableList.of("help"), ImmutableList.of("-I", initScript.getAbsolutePath()), ImmutableList.of());
List<String> gradleArgs = buildGradleArgs();
new ToolingApiGradleClient(connection).runTasks(ImmutableList.of("help"), gradleArgs, ImmutableList.of());
List<String> buildDetails = readBuildDetails();
JavaEnvironment javaEnvironment = buildEnvironment.getJava();
List<String> allJvmArgs = new ArrayList<>(javaEnvironment.getJvmArguments());
Expand All @@ -124,6 +127,16 @@ private GradleBuildConfiguration probe(GradleConnector connector) {
return version;
}

private List<String> buildGradleArgs() {
List<String> result = new ArrayList<>();

result.add("-I");
result.add(initScript.getAbsolutePath());

systemProperties.forEach((key, value) -> result.add("-D" + key + "=" + value));
return Collections.unmodifiableList(result);
}

private List<String> readSystemPropertiesFromGradleProperties() {
String jvmArgs = getJvmArgsProperty(gradleUserHome);
if (jvmArgs == null) {
Expand Down

0 comments on commit 4b9dafa

Please sign in to comment.