-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from avaje/feature/add-native-image
Add native-image support and test
- Loading branch information
Showing
6 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: native image build | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '40 1 1 1 6' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
permissions: | ||
contents: read | ||
packages: write | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: graalvm/setup-graalvm@v1 | ||
with: | ||
java-version: '21' | ||
distribution: 'graalvm' | ||
cache: 'maven' | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Versions | ||
run: | | ||
echo "GRAALVM_HOME: $GRAALVM_HOME" | ||
echo "JAVA_HOME: $JAVA_HOME" | ||
java --version | ||
native-image --version | ||
- name: Build with Maven | ||
run: | | ||
mvn clean install -DskipTests | ||
cd test-native-image | ||
mvn clean package -Pnative | ||
./target/test-native-image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?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> | ||
<parent> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-validator-parent</artifactId> | ||
<version>1.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>test-native-image</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.release>21</maven.compiler.release> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<version.plugin.nativeimage>0.9.27</version.plugin.nativeimage> | ||
<mainClass>org.example.Main</mainClass> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-validator</artifactId> | ||
<version>1.2-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>validator-constraints</artifactId> | ||
<version>1.2-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-validator-generator</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>1.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.graalvm.buildtools</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
<version>${version.plugin.nativeimage}</version> | ||
<executions> | ||
<execution> | ||
<id>build-native</id> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
<phase>package</phase> | ||
<configuration> | ||
<buildArgs> | ||
<buildArg>--no-fallback</buildArg> | ||
<buildArg>-H:IncludeLocales=de,en</buildArg> | ||
</buildArgs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.example; | ||
|
||
|
||
import io.avaje.validation.constraints.NotBlank; | ||
import io.avaje.validation.constraints.Valid; | ||
|
||
@Valid | ||
public class Customer { | ||
|
||
@NotBlank | ||
final String name; | ||
@NotBlank | ||
final String email; | ||
|
||
public Customer(String name, String email) { | ||
this.name = name; | ||
this.email = email; | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public String email() { | ||
return email; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.example; | ||
|
||
import io.avaje.validation.ConstraintViolation; | ||
import io.avaje.validation.Validator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Validator validator = Validator.builder() | ||
.addLocales(Locale.GERMAN) | ||
.build(); | ||
|
||
var customer = new Customer("hello", ""); | ||
System.out.println("violations EN - " + validator.check(customer)); | ||
System.out.println("violations DE - " + validator.check(customer, Locale.GERMAN)); | ||
|
||
if (!"must not be blank".equals(first(validator.check(customer)).message())) { | ||
System.exit(1); | ||
} | ||
if (!"darf nicht leer sein".equals(first(validator.check(customer, Locale.GERMAN)).message())) { | ||
System.exit(1); | ||
} | ||
} | ||
|
||
private static ConstraintViolation first(Set<ConstraintViolation> check) { | ||
return new ArrayList<>(check).get(0); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test-native-image/src/test/java/org/example/CustomerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.example; | ||
|
||
import io.avaje.validation.ConstraintViolation; | ||
import io.avaje.validation.Validator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
class CustomerTest { | ||
|
||
@Test | ||
void test() { | ||
Validator validator = Validator.builder() | ||
.addLocales(Locale.GERMAN) | ||
.build(); | ||
|
||
var customer = new Customer("hello", ""); | ||
System.out.println("violations EN - " + validator.check(customer)); | ||
System.out.println("violations DE - " + validator.check(customer, Locale.GERMAN)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...n/resources/META-INF/native-image/io.avaje.validator.avaje-validator/resource-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"bundles": [ | ||
{ | ||
"name": "io.avaje.validation.Messages" | ||
} | ||
] | ||
} |