Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with system properties not being applied on config reading #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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