Skip to content
Snippets Groups Projects
Commit 3b037fb2 authored by René Schöne's avatar René Schöne
Browse files

Use actual new process to start Gradle for sandbox run.

- using a new process rather than the GradleConnection is now the default, but can be changed in scenarios.json using the key useGradleConnection
parent 896578ff
No related branches found
No related tags found
No related merge requests found
......@@ -32,12 +32,20 @@ public class FullBenchmarkMain {
static class InvokeJavaVMBenchmark extends Benchmark {
BenchmarkSettings settings;
int repetitions;
private boolean useGradleConnection = false;
private final String gradleCommand = System.getProperty("os.name")
.toLowerCase().contains("windows") ? "./gradle.bat" : "./gradlew";
InvokeJavaVMBenchmark(BenchmarkSettings settings, int repetitions) {
this.settings = settings;
this.repetitions = repetitions;
}
InvokeJavaVMBenchmark setUseGradleConnection(boolean useGradleConnection) {
this.useGradleConnection = useGradleConnection;
return this;
}
@Override
public void run() {
for (int i = 0; i < this.repetitions; i++) {
......@@ -49,7 +57,8 @@ public class FullBenchmarkMain {
logger.catching(e);
throw new RuntimeException("Could not create temporary file for sandBoxed use. Exiting.");
}
// invoke Gradle target
if (useGradleConnection) {
// invoke Gradle target directly
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(new File("."))
.connect();
......@@ -62,10 +71,34 @@ public class FullBenchmarkMain {
} finally {
connection.close();
}
} else {
// start a new process calling gradle
File currentDir = getCurrentDir();
try {
ProcessBuilder pb = new ProcessBuilder(gradleCommand, "sandboxRun",
"-PrunSettingsFile=" + tempPath.toAbsolutePath().toString());
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
pb.directory(currentDir);
Process p = pb.start();
p.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
}
private File getCurrentDir() {
// hacky solution to get to the root of the repository
File maybeCurrentDir = new File("").getAbsoluteFile();
if ("jastadd-mquat-benchmark".equals(maybeCurrentDir.getName())) {
maybeCurrentDir = maybeCurrentDir.getParentFile();
}
return maybeCurrentDir;
}
}
public static void main(String[] args) {
List<Benchmark> benchmarks = createFromConfig(args);
if (benchmarks == null || benchmarks.isEmpty()) {
......@@ -95,7 +128,7 @@ public class FullBenchmarkMain {
.map(SolverFactory::getSolverByName).collect(Collectors.toList());
return settings.scenarios.stream()
.filter(data -> takeAll || allowedIds.contains(data.getId()) || allowedNames.contains(data.name))
.map(data -> create(from(settings, data), solvers, settings.repetitions, settings.sandBoxed))
.map(data -> create(settings, data, solvers))
.collect(Collectors.toList());
}
......@@ -143,10 +176,15 @@ public class FullBenchmarkMain {
return result;
}
private static Benchmark create(BenchmarkSettings settings, List<BenchmarkableSolver> solvers, int repetitions, boolean sandBoxed) {
return sandBoxed ?
new InvokeJavaVMBenchmark(settings, repetitions) :
new ScenarioBenchmark(settings, solvers, repetitions);
private static Benchmark create(ScenarioSettings scenarioSettings, ScenarioData data,
List<BenchmarkableSolver> solvers) {
BenchmarkSettings settings = from(scenarioSettings, data);
if (scenarioSettings.sandBoxed) {
return new InvokeJavaVMBenchmark(settings, scenarioSettings.repetitions)
.setUseGradleConnection(scenarioSettings.useGradleConnection);
} else {
return new ScenarioBenchmark(settings, solvers, scenarioSettings.repetitions);
}
}
}
......@@ -17,4 +17,5 @@ public class ScenarioSettings {
public int repetitions = 1;
public List<ScenarioData> scenarios;
public boolean sandBoxed;
public boolean useGradleConnection = false;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment