Skip to content

Commit 02bdaa6

Browse files
committed
test: add maven toolchain integration test
1 parent afd5c53 commit 02bdaa6

5 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package foo;
2+
3+
public class Foo {
4+
public static void main(String[] args) {
5+
System.out.println("Hello from Foo!");
6+
}
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals=clean package
2+
invoker.toolchain=toolchains.xml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<project>
2+
<groupId>foo</groupId>
3+
<artifactId>toolchain-test</artifactId>
4+
<version>1</version>
5+
<modelVersion>4.0.0</modelVersion>
6+
<build>
7+
<directory>${project.basedir}/target</directory>
8+
<outputDirectory>${project.basedir}/target/classes</outputDirectory>
9+
<testOutputDirectory>${project.basedir}/target/test-classes</testOutputDirectory>
10+
<plugins>
11+
<plugin>
12+
<groupId>io.github.rockcrafters</groupId>
13+
<artifactId>rockcraft-maven-plugin</artifactId>
14+
<executions>
15+
<execution>
16+
<goals>
17+
<goal>create-rock</goal>
18+
</goals>
19+
</execution>
20+
</executions>
21+
</plugin>
22+
</plugins>
23+
</build>
24+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
5+
<toolchain>
6+
<type>jdk</type>
7+
<provides>
8+
<version>17</version>
9+
</provides>
10+
<configuration>
11+
<jdkHome>${env.JAVA_HOME}</jdkHome>
12+
</configuration>
13+
</toolchain>
14+
</toolchains>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.io.*;
2+
import org.yaml.snakeyaml.Yaml;
3+
4+
File target = new File( basedir, "target" );
5+
6+
// Check that rockcraft.yaml was generated
7+
var files = target.listFiles(new FilenameFilter(){
8+
public boolean accept(File dir, String name) {
9+
return name.equals("rockcraft.yaml");
10+
}
11+
});
12+
13+
if ( files == null || files.length == 0 )
14+
{
15+
throw new FileNotFoundException( "Could not find generated rockcraft.yaml file in " + target.getAbsolutePath() );
16+
}
17+
18+
File rockcraftYaml = files[0];
19+
20+
// Parse the YAML file
21+
Yaml yaml = new Yaml();
22+
FileInputStream inputStream = new FileInputStream(rockcraftYaml);
23+
Map<String, Object> obj = yaml.load(inputStream);
24+
inputStream.close();
25+
26+
// Verify that build-packages contains the toolchain-detected JDK package
27+
// The Toolchain class should detect the JDK from toolchains.xml
28+
List<String> buildPackages = (List<String>) obj.get("build-packages");
29+
30+
if (buildPackages == null) {
31+
throw new RuntimeException("build-packages not found in rockcraft.yaml");
32+
}
33+
34+
String packageName = buildPackages.get(0);
35+
if (!"openjdk-17-jdk".equals(packageName )) {
36+
throw new RuntimeException("Expected openjdk-17-jdk, but got " + packageName);
37+
}

0 commit comments

Comments
 (0)