Skip to content

Commit

Permalink
test: add test for jlink plugin
Browse files Browse the repository at this point in the history
A smoke test for jlink plugin.
It builds Java hello world rocks for bare and Ubuntu 24.04 bases.
The test depends on Maven plugin to work properly.
  • Loading branch information
vpa1977 committed Jan 31, 2025
1 parent f46970d commit 886930b
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
base: bare
build-base: [email protected]
name: bare-build-2404
84 changes: 84 additions & 0 deletions tests/spread/rockcraft/plugin-jlink/base-2404/helloworld/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>helloworld</groupId>
<artifactId>helloworld</artifactId>
<version>1.0-SNAPSHOT</version>

<name>helloworld</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be
moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>helloworld.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.yourcompany.helloworld;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yourcompany.helloworld;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
2 changes: 2 additions & 0 deletions tests/spread/rockcraft/plugin-jlink/base-2404/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
base: [email protected]
name: base-2404
82 changes: 82 additions & 0 deletions tests/spread/rockcraft/plugin-jlink/helloworld/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.yourcompany</groupId>
<artifactId>helloworld</artifactId>
<version>1.0-SNAPSHOT</version>

<name>helloworld</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>helloworld.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package helloworld;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package helloworld;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
40 changes: 40 additions & 0 deletions tests/spread/rockcraft/plugin-jlink/parts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Actual parts definition for the rockcraft + python cases that we are testing.
# (this gets appended to all rockcraft.yaml files in the subdirectories in the
# main task.yaml).

version: "0.1"
summary: A rock that bundles a Java project.
description: A rock that bundles a Java project.
license: GPL-3.0
platforms:
amd64:

parts:
helloworld:
source: helloworld
source-type: local
build-packages:
- openjdk-21-jdk
- maven
plugin: maven
build-environment:
- JAVA_HOME: "/usr/lib/jvm/java-21-openjdk-${CRAFT_ARCH_BUILD_FOR}"

deps:
plugin: nil
stage-packages:
- openjdk-21-jre-headless_standard
stage:
- -usr/lib/jvm

runtime:
after:
- helloworld
- deps
plugin: jlink
build-packages:
- openjdk-21-jdk
build-environment:
- JAVA_HOME: /usr/lib/jvm/java-21-openjdk-${CRAFT_ARCH_BUILD_FOR}
jlink-jars:
- jar/helloworld-1.0-SNAPSHOT.jar
29 changes: 29 additions & 0 deletions tests/spread/rockcraft/plugin-jlink/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
summary: JLink plugin tests
environment:
SCENARIO/base_2404: base-2404
SCENARIO/bare_build_2004: bare-build-2404
execute: |
SCENARIO_DIR="${SCENARIO}"
ROCK_FILE="${SCENARIO}_0.1_amd64.rock"
IMAGE="${SCENARIO}:0.1"
# change into the scenario's directory
cd ${SCENARIO_DIR}
# add the parts definition, common to all scenarios
cat ../parts.yaml >> rockcraft.yaml
# copy the source of the project we're building (also shared)
cp -r ../helloworld .
# Build the rock & load it into docker
run_rockcraft pack
test -f ${ROCK_FILE}
sudo rockcraft.skopeo --insecure-policy copy oci-archive:${ROCK_FILE} docker-daemon:${IMAGE}
docker images
rm ${ROCK_FILE}
# Run the packaged project
docker run --rm $IMAGE exec /usr/bin/java -jar /jar/helloworld-1.0-SNAPSHOT.jar | MATCH "Hello World!"
docker system prune -a -f

0 comments on commit 886930b

Please sign in to comment.