Skip to content

Commit aa41288

Browse files
authored
Merge pull request #169 from avaje/feature/add-native-image
Add native-image support and test
2 parents f7c2f41 + c39f223 commit aa41288

File tree

6 files changed

+205
-0
lines changed

6 files changed

+205
-0
lines changed

.github/workflows/native-image.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: native image build
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '40 1 1 1 6'
7+
8+
jobs:
9+
build:
10+
runs-on: ${{ matrix.os }}
11+
permissions:
12+
contents: read
13+
packages: write
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
os: [ubuntu-latest]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: graalvm/setup-graalvm@v1
22+
with:
23+
java-version: '21'
24+
distribution: 'graalvm'
25+
cache: 'maven'
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Versions
29+
run: |
30+
echo "GRAALVM_HOME: $GRAALVM_HOME"
31+
echo "JAVA_HOME: $JAVA_HOME"
32+
java --version
33+
native-image --version
34+
- name: Build with Maven
35+
run: |
36+
mvn clean install -DskipTests
37+
cd test-native-image
38+
mvn clean package -Pnative
39+
./target/test-native-image

test-native-image/pom.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
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+
<parent>
7+
<groupId>io.avaje</groupId>
8+
<artifactId>avaje-validator-parent</artifactId>
9+
<version>1.2-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>org.example</groupId>
13+
<artifactId>test-native-image</artifactId>
14+
15+
<properties>
16+
<maven.compiler.release>21</maven.compiler.release>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<version.plugin.nativeimage>0.9.27</version.plugin.nativeimage>
19+
<mainClass>org.example.Main</mainClass>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>io.avaje</groupId>
25+
<artifactId>avaje-validator</artifactId>
26+
<version>1.2-SNAPSHOT</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.avaje</groupId>
30+
<artifactId>validator-constraints</artifactId>
31+
<version>1.2-SNAPSHOT</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.avaje</groupId>
35+
<artifactId>avaje-validator-generator</artifactId>
36+
<version>${project.version}</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.avaje</groupId>
41+
<artifactId>junit</artifactId>
42+
<version>1.1</version>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
</dependencies>
47+
48+
<profiles>
49+
<profile>
50+
<id>native</id>
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.graalvm.buildtools</groupId>
55+
<artifactId>native-maven-plugin</artifactId>
56+
<version>${version.plugin.nativeimage}</version>
57+
<executions>
58+
<execution>
59+
<id>build-native</id>
60+
<goals>
61+
<goal>build</goal>
62+
</goals>
63+
<phase>package</phase>
64+
<configuration>
65+
<buildArgs>
66+
<buildArg>--no-fallback</buildArg>
67+
<buildArg>-H:IncludeLocales=de,en</buildArg>
68+
</buildArgs>
69+
</configuration>
70+
</execution>
71+
</executions>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
</profile>
76+
</profiles>
77+
78+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.example;
2+
3+
4+
import io.avaje.validation.constraints.NotBlank;
5+
import io.avaje.validation.constraints.Valid;
6+
7+
@Valid
8+
public class Customer {
9+
10+
@NotBlank
11+
final String name;
12+
@NotBlank
13+
final String email;
14+
15+
public Customer(String name, String email) {
16+
this.name = name;
17+
this.email = email;
18+
}
19+
20+
public String name() {
21+
return name;
22+
}
23+
24+
public String email() {
25+
return email;
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.example;
2+
3+
import io.avaje.validation.ConstraintViolation;
4+
import io.avaje.validation.Validator;
5+
6+
import java.util.ArrayList;
7+
import java.util.Locale;
8+
import java.util.Set;
9+
10+
public class Main {
11+
12+
public static void main(String[] args) {
13+
Validator validator = Validator.builder()
14+
.addLocales(Locale.GERMAN)
15+
.build();
16+
17+
var customer = new Customer("hello", "");
18+
System.out.println("violations EN - " + validator.check(customer));
19+
System.out.println("violations DE - " + validator.check(customer, Locale.GERMAN));
20+
21+
if (!"must not be blank".equals(first(validator.check(customer)).message())) {
22+
System.exit(1);
23+
}
24+
if (!"darf nicht leer sein".equals(first(validator.check(customer, Locale.GERMAN)).message())) {
25+
System.exit(1);
26+
}
27+
}
28+
29+
private static ConstraintViolation first(Set<ConstraintViolation> check) {
30+
return new ArrayList<>(check).get(0);
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.example;
2+
3+
import io.avaje.validation.ConstraintViolation;
4+
import io.avaje.validation.Validator;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Locale;
8+
import java.util.Set;
9+
10+
class CustomerTest {
11+
12+
@Test
13+
void test() {
14+
Validator validator = Validator.builder()
15+
.addLocales(Locale.GERMAN)
16+
.build();
17+
18+
var customer = new Customer("hello", "");
19+
System.out.println("violations EN - " + validator.check(customer));
20+
System.out.println("violations DE - " + validator.check(customer, Locale.GERMAN));
21+
}
22+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"bundles": [
3+
{
4+
"name": "io.avaje.validation.Messages"
5+
}
6+
]
7+
}

0 commit comments

Comments
 (0)