Skip to content

Commit f3415c9

Browse files
committed
Switch to Maven
1 parent 333a308 commit f3415c9

File tree

6 files changed

+122
-18
lines changed

6 files changed

+122
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
.settings
55
**/bin/
66
**/build/
7+
target
78

89
results.json

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ COPY lib/src ./src
99
COPY lib/build.gradle ./
1010

1111
# Build test runner
12+
RUN echo "no-cache"
1213
RUN gradle -i clean build
1314
RUN gradle -i shadowJar \
1415
&& cp build/libs/autotest-runner.jar .
1516

17+
FROM maven:3.8.3-jdk-11 AS cache
18+
1619
# Ensure exercise dependencies are downloaded
1720
WORKDIR /opt/exercise
1821
COPY exercise .
19-
RUN gradle build
22+
RUN mvn test dependency:go-offline -DexcludeReactor=false
2023

2124
# === Build runtime image ===
2225

23-
FROM gradle:6.8.3-jdk11
26+
FROM maven:3.8.3-jdk-11
2427
WORKDIR /opt/test-runner
2528

2629
# Copy binary and launcher script
2730
COPY bin/ ./bin/
2831
COPY --from=build /home/builder/autotest-runner.jar ./
2932

3033
# Copy cached dependencies
31-
COPY --from=build /home/gradle /home/gradle
34+
COPY --from=cache /root/.m2 /root/.m2
35+
36+
# Copy Maven pom.xml
37+
COPY --from=cache /opt/exercise/pom.xml /home/pom.xml
3238

3339
ENTRYPOINT ["sh", "/opt/test-runner/bin/run.sh"]

bin/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ cp -R $input_folder/* .
2222

2323
find . -mindepth 1 -type f | grep 'Test.java' | xargs -I file sed -i "s/@Ignore(.*)//g;s/@Ignore//g;" file
2424

25+
cp /home/pom.xml .
26+
2527
java -jar /opt/test-runner/autotest-runner.jar $problem_slug
2628
mv results.json $output_folder

exercise/pom.xml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.exercism</groupId>
8+
<artifactId>exercise</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>4.13</version>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.assertj</groupId>
26+
<artifactId>assertj-core</artifactId>
27+
<version>3.15.0</version>
28+
<scope>test</scope>
29+
</dependency>
30+
</dependencies>
31+
32+
<build>
33+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
34+
<plugins>
35+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
36+
<plugin>
37+
<artifactId>maven-clean-plugin</artifactId>
38+
<version>3.1.0</version>
39+
</plugin>
40+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
41+
<plugin>
42+
<artifactId>maven-resources-plugin</artifactId>
43+
<version>3.0.2</version>
44+
</plugin>
45+
<plugin>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<version>3.8.0</version>
48+
<configuration>
49+
<source>11</source>
50+
<target>11</target>
51+
</configuration>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-surefire-plugin</artifactId>
55+
<version>2.22.1</version>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-jar-plugin</artifactId>
59+
<version>3.0.2</version>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-install-plugin</artifactId>
63+
<version>2.5.2</version>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-deploy-plugin</artifactId>
67+
<version>2.8.2</version>
68+
</plugin>
69+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
70+
<plugin>
71+
<artifactId>maven-site-plugin</artifactId>
72+
<version>3.7.1</version>
73+
</plugin>
74+
<plugin>
75+
<artifactId>maven-project-info-reports-plugin</artifactId>
76+
<version>3.0.0</version>
77+
</plugin>
78+
</plugins>
79+
</pluginManagement>
80+
<plugins>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-compiler-plugin</artifactId>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.codehaus.mojo</groupId>
87+
<artifactId>exec-maven-plugin</artifactId>
88+
<version>3.0.0</version>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
</project>

lib/src/main/java/com/exercism/runner/TestRunner.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,36 @@
1616
import java.nio.file.Paths;
1717

1818
public final class TestRunner {
19-
private static final String GRADLE_TEST_ERR = "gradle-test.err";
19+
private static final String MAVEN_TEST_OUTPUT = "maven-test.out";
2020

2121
public static void main(String[] args) throws InterruptedException, IOException {
2222
run(args[0]);
2323
}
2424

2525
private static void run(String slug) throws InterruptedException, IOException {
26-
Process gradleTest = new ProcessBuilder(
27-
"gradle",
26+
Process mavenTest = new ProcessBuilder(
27+
"mvn",
2828
"test",
2929
"--offline",
30-
"--no-daemon",
31-
"--warning-mode=none")
32-
.redirectError(new File(GRADLE_TEST_ERR))
30+
"--legacy-local-repository",
31+
"--batch-mode",
32+
"--non-recursive",
33+
"--quiet")
34+
.redirectOutput(new File(MAVEN_TEST_OUTPUT))
3335
.start();
34-
if (!gradleTest.waitFor(20, SECONDS)) {
35-
throw new IllegalStateException("gradle test did not complete within 20 seconds");
36+
if (!mavenTest.waitFor(20, SECONDS)) {
37+
throw new IllegalStateException("test did not complete within 20 seconds");
3638
}
37-
if (gradleTest.exitValue() != 0) {
38-
String gradleErrorOutput = Files.asCharSource(
39-
Paths.get(GRADLE_TEST_ERR).toFile(), StandardCharsets.UTF_8)
39+
40+
if (mavenTest.exitValue() != 0) {
41+
String mavenOutput = Files.asCharSource(
42+
Paths.get(MAVEN_TEST_OUTPUT).toFile(), StandardCharsets.UTF_8)
4043
.read();
41-
if (gradleErrorOutput.contains("compileJava")) {
44+
if (mavenOutput.contains("ERROR")) {
4245
ReportGenerator.report(
4346
Report.builder()
4447
.setStatus("error")
45-
.setMessage(gradleErrorOutput)
48+
.setMessage(mavenOutput)
4649
.build());
4750
return;
4851
}
@@ -56,7 +59,7 @@ private static void run(String slug) throws InterruptedException, IOException {
5659
}
5760
ImmutableMap<String, String> testCodeByTestName = testParser.buildTestCodeMap();
5861
JUnitXmlParser xmlParser = new JUnitXmlParser(testCodeByTestName);
59-
for (Path filePath : MoreFiles.listFiles(Paths.get("build", "test-results", "test"))) {
62+
for (Path filePath : MoreFiles.listFiles(Paths.get("target", "surefire-reports"))) {
6063
if (MoreFiles.getFileExtension(filePath).equals("xml")) {
6164
xmlParser.parse(filePath.toFile());
6265
}

run_in_docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ OutputDirectory="$3"
1313

1414
docker build -t exercism/java-test-runner .
1515

16-
docker run \
16+
time docker run \
1717
--network none \
1818
--mount type=bind,src="${InputDirectory}",dst=/solution \
1919
--mount type=bind,src="${OutputDirectory}",dst=/results \

0 commit comments

Comments
 (0)