From f3415c98361bc71d411b58cf136e6693a937d4b1 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Thu, 11 Nov 2021 11:59:18 +0000 Subject: [PATCH 1/3] Switch to Maven --- .gitignore | 1 + Dockerfile | 12 ++- bin/run.sh | 2 + exercise/pom.xml | 92 +++++++++++++++++++ .../java/com/exercism/runner/TestRunner.java | 31 ++++--- run_in_docker.sh | 2 +- 6 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 exercise/pom.xml diff --git a/.gitignore b/.gitignore index d026eaa..5f656fc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ .settings **/bin/ **/build/ +target results.json \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8a2c7eb..73b8ab6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,18 +9,21 @@ COPY lib/src ./src COPY lib/build.gradle ./ # Build test runner +RUN echo "no-cache" RUN gradle -i clean build RUN gradle -i shadowJar \ && cp build/libs/autotest-runner.jar . +FROM maven:3.8.3-jdk-11 AS cache + # Ensure exercise dependencies are downloaded WORKDIR /opt/exercise COPY exercise . -RUN gradle build +RUN mvn test dependency:go-offline -DexcludeReactor=false # === Build runtime image === -FROM gradle:6.8.3-jdk11 +FROM maven:3.8.3-jdk-11 WORKDIR /opt/test-runner # Copy binary and launcher script @@ -28,6 +31,9 @@ COPY bin/ ./bin/ COPY --from=build /home/builder/autotest-runner.jar ./ # Copy cached dependencies -COPY --from=build /home/gradle /home/gradle +COPY --from=cache /root/.m2 /root/.m2 + +# Copy Maven pom.xml +COPY --from=cache /opt/exercise/pom.xml /home/pom.xml ENTRYPOINT ["sh", "/opt/test-runner/bin/run.sh"] diff --git a/bin/run.sh b/bin/run.sh index 6cb902f..2e12f76 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -22,5 +22,7 @@ cp -R $input_folder/* . find . -mindepth 1 -type f | grep 'Test.java' | xargs -I file sed -i "s/@Ignore(.*)//g;s/@Ignore//g;" file +cp /home/pom.xml . + java -jar /opt/test-runner/autotest-runner.jar $problem_slug mv results.json $output_folder diff --git a/exercise/pom.xml b/exercise/pom.xml new file mode 100644 index 0000000..5507967 --- /dev/null +++ b/exercise/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + com.exercism + exercise + 1.0-SNAPSHOT + + + UTF-8 + 11 + 11 + + + + + junit + junit + 4.13 + test + + + org.assertj + assertj-core + 3.15.0 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + 11 + 11 + + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + + diff --git a/lib/src/main/java/com/exercism/runner/TestRunner.java b/lib/src/main/java/com/exercism/runner/TestRunner.java index 6b5e5b5..2395745 100644 --- a/lib/src/main/java/com/exercism/runner/TestRunner.java +++ b/lib/src/main/java/com/exercism/runner/TestRunner.java @@ -16,33 +16,36 @@ import java.nio.file.Paths; public final class TestRunner { - private static final String GRADLE_TEST_ERR = "gradle-test.err"; + private static final String MAVEN_TEST_OUTPUT = "maven-test.out"; public static void main(String[] args) throws InterruptedException, IOException { run(args[0]); } private static void run(String slug) throws InterruptedException, IOException { - Process gradleTest = new ProcessBuilder( - "gradle", + Process mavenTest = new ProcessBuilder( + "mvn", "test", "--offline", - "--no-daemon", - "--warning-mode=none") - .redirectError(new File(GRADLE_TEST_ERR)) + "--legacy-local-repository", + "--batch-mode", + "--non-recursive", + "--quiet") + .redirectOutput(new File(MAVEN_TEST_OUTPUT)) .start(); - if (!gradleTest.waitFor(20, SECONDS)) { - throw new IllegalStateException("gradle test did not complete within 20 seconds"); + if (!mavenTest.waitFor(20, SECONDS)) { + throw new IllegalStateException("test did not complete within 20 seconds"); } - if (gradleTest.exitValue() != 0) { - String gradleErrorOutput = Files.asCharSource( - Paths.get(GRADLE_TEST_ERR).toFile(), StandardCharsets.UTF_8) + + if (mavenTest.exitValue() != 0) { + String mavenOutput = Files.asCharSource( + Paths.get(MAVEN_TEST_OUTPUT).toFile(), StandardCharsets.UTF_8) .read(); - if (gradleErrorOutput.contains("compileJava")) { + if (mavenOutput.contains("ERROR")) { ReportGenerator.report( Report.builder() .setStatus("error") - .setMessage(gradleErrorOutput) + .setMessage(mavenOutput) .build()); return; } @@ -56,7 +59,7 @@ private static void run(String slug) throws InterruptedException, IOException { } ImmutableMap testCodeByTestName = testParser.buildTestCodeMap(); JUnitXmlParser xmlParser = new JUnitXmlParser(testCodeByTestName); - for (Path filePath : MoreFiles.listFiles(Paths.get("build", "test-results", "test"))) { + for (Path filePath : MoreFiles.listFiles(Paths.get("target", "surefire-reports"))) { if (MoreFiles.getFileExtension(filePath).equals("xml")) { xmlParser.parse(filePath.toFile()); } diff --git a/run_in_docker.sh b/run_in_docker.sh index 3b88f12..1a32a09 100755 --- a/run_in_docker.sh +++ b/run_in_docker.sh @@ -13,7 +13,7 @@ OutputDirectory="$3" docker build -t exercism/java-test-runner . -docker run \ +time docker run \ --network none \ --mount type=bind,src="${InputDirectory}",dst=/solution \ --mount type=bind,src="${OutputDirectory}",dst=/results \ From 49b3ba7376c9e78a9c75a7e9cc247bdf42a9b96e Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Thu, 11 Nov 2021 12:05:43 +0000 Subject: [PATCH 2/3] cleanup --- Dockerfile | 3 +-- bin/run.sh | 2 +- lib/src/main/java/com/exercism/runner/TestRunner.java | 2 +- run_in_docker.sh | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 73b8ab6..1e0aec3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ COPY lib/src ./src COPY lib/build.gradle ./ # Build test runner -RUN echo "no-cache" RUN gradle -i clean build RUN gradle -i shadowJar \ && cp build/libs/autotest-runner.jar . @@ -34,6 +33,6 @@ COPY --from=build /home/builder/autotest-runner.jar ./ COPY --from=cache /root/.m2 /root/.m2 # Copy Maven pom.xml -COPY --from=cache /opt/exercise/pom.xml /home/pom.xml +COPY --from=cache /opt/exercise/pom.xml /root/pom.xml ENTRYPOINT ["sh", "/opt/test-runner/bin/run.sh"] diff --git a/bin/run.sh b/bin/run.sh index 2e12f76..afa9911 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -22,7 +22,7 @@ cp -R $input_folder/* . find . -mindepth 1 -type f | grep 'Test.java' | xargs -I file sed -i "s/@Ignore(.*)//g;s/@Ignore//g;" file -cp /home/pom.xml . +cp /root/pom.xml . java -jar /opt/test-runner/autotest-runner.jar $problem_slug mv results.json $output_folder diff --git a/lib/src/main/java/com/exercism/runner/TestRunner.java b/lib/src/main/java/com/exercism/runner/TestRunner.java index 2395745..9195dcc 100644 --- a/lib/src/main/java/com/exercism/runner/TestRunner.java +++ b/lib/src/main/java/com/exercism/runner/TestRunner.java @@ -41,7 +41,7 @@ private static void run(String slug) throws InterruptedException, IOException { String mavenOutput = Files.asCharSource( Paths.get(MAVEN_TEST_OUTPUT).toFile(), StandardCharsets.UTF_8) .read(); - if (mavenOutput.contains("ERROR")) { + if (mavenOutput.contains("COMPILATION ERROR")) { ReportGenerator.report( Report.builder() .setStatus("error") diff --git a/run_in_docker.sh b/run_in_docker.sh index 1a32a09..3b88f12 100755 --- a/run_in_docker.sh +++ b/run_in_docker.sh @@ -13,7 +13,7 @@ OutputDirectory="$3" docker build -t exercism/java-test-runner . -time docker run \ +docker run \ --network none \ --mount type=bind,src="${InputDirectory}",dst=/solution \ --mount type=bind,src="${OutputDirectory}",dst=/results \ From 68d47811cde4f9029049b4d63811a489a5c390ee Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Fri, 12 Nov 2021 10:05:30 +0000 Subject: [PATCH 3/3] Add extra dependencies for the tests --- exercise/pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/exercise/pom.xml b/exercise/pom.xml index 5507967..f0f2b61 100644 --- a/exercise/pom.xml +++ b/exercise/pom.xml @@ -27,6 +27,16 @@ 3.15.0 test + + org.json + json + 20190722 + + + io.reactivex.rxjava2 + rxjava + 2.2.12 +