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 <turaev.m.al@sberbank.ru>
  • Loading branch information
Maksim Turaev committed Oct 6, 2020
1 parent e0cfe31 commit a3b2a20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 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
2 changes: 1 addition & 1 deletion src/main/java/org/gradle/profiler/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void run(String[] args) throws Exception {
settings.printTo(System.out);

DaemonControl daemonControl = new DaemonControl(settings.getGradleUserHome());
GradleBuildConfigurationReader gradleBuildConfigurationReader = new DefaultGradleBuildConfigurationReader(settings.getProjectDir(), settings.getGradleUserHome(), daemonControl);
GradleBuildConfigurationReader gradleBuildConfigurationReader = new DefaultGradleBuildConfigurationReader(settings.getProjectDir(), settings.getGradleUserHome(), daemonControl, settings.getSystemProperties());
ScenarioLoader scenarioLoader = new ScenarioLoader(gradleBuildConfigurationReader);
List<ScenarioDefinition> scenarios = scenarioLoader.loadScenarios(settings);
int totalScenarios = scenarios.size();
Expand Down

0 comments on commit a3b2a20

Please sign in to comment.