Skip to content

Commit

Permalink
#135: simplify functionality, add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabrina Wullschleger committed Aug 9, 2024
1 parent 6cd5b6a commit ad737b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,49 @@ public static void executeTestRunner(File projectDirectory, String taskName) thr

public static void executeTestRunner(File projectDirectory, String taskName, GradleVariable[] variables) throws IOException{
if(TestType.IMAGE.equals(TEST_TYPE)){
int result = executeDockerRunCommand(projectDirectory.getAbsolutePath(), variables);
assertEquals(0, result);
executeDockerRunCommand(projectDirectory.getAbsolutePath(), variables);
} else if(TestType.JAR.equals(TEST_TYPE)){
int result = executeGradleRunner(projectDirectory, taskName, variables);
assertTrue(result == TaskOutcome.SUCCESS.ordinal() || result == TaskOutcome.UP_TO_DATE.ordinal());
executeGradleRunner(projectDirectory, taskName, variables);
} else {
throw new GretlException("Unknown test type: " + TEST_TYPE);
}
}

private static int executeGradleRunner(File projectDirectory, String taskName, GradleVariable[] variables) throws IOException{
private static void executeGradleRunner(File projectDirectory, String taskName, GradleVariable[] variables) throws IOException{
List<String> arguments = getRunnerArguments(taskName, variables);
BuildResult result = GradleRunner.create()
.withProjectDir(projectDirectory)
.withPluginClasspath(getPluginClassPaths())
.withArguments(arguments)
.forwardOutput().build();
TaskOutcome outcome = Objects.requireNonNull(result.task(":" + taskName)).getOutcome();
return TaskOutcomeConverter.convertTaskOutcomeToInteger(outcome);
assertTrue(outcome == TaskOutcome.SUCCESS || outcome == TaskOutcome.UP_TO_DATE);
}

private static int executeDockerRunCommand(String jobPath, GradleVariable[] variables){
private static void executeDockerRunCommand(String jobPath, GradleVariable[] variables){
String dockerRunCommand = getDockerRunCommand(jobPath, variables);
StringBuffer stdError = new StringBuffer();
StringBuffer stdOut = new StringBuffer();

try {
Process process = Runtime.getRuntime().exec(dockerRunCommand);
appendProcessOutputToStdStreams(process, new StringBuffer(), new StringBuffer());
appendProcessOutputToStdStreams(process, stdError, stdOut);
process.waitFor();
return process.exitValue();
logDockerRunOutput(dockerRunCommand, stdError, stdOut);
int result = process.exitValue();
assertEquals(0, result);
} catch (IOException | InterruptedException e) {
throw new GretlException("Error while executing docker run command: " + dockerRunCommand, e);
}
}

private static void logDockerRunOutput(String dockerRunCommand, StringBuffer stdError, StringBuffer stdOut){
System.out.printf("Here is the standard output of the command [%s]:\n%n", dockerRunCommand);
System.out.print(stdOut);
System.out.printf("Here is the standard error of the command [%s] (if any):\n%n", dockerRunCommand);
System.out.print(stdError);
}

private static String getDockerRunCommand(String jobPath, GradleVariable[] variables){
String pathToRunCommandExecutionFile = Paths.get(ROOT_PROJECT_ABSOLUTE_PATH).resolve("runtimeImage/start-gretl.sh").toString();
String jobDirectoryOption = buildJobDirectoryOptionString(jobPath);
Expand Down

This file was deleted.

0 comments on commit ad737b3

Please sign in to comment.