Skip to content

Commit

Permalink
Merge pull request #662 from bci-oss/661-refactor-native-image-config…
Browse files Browse the repository at this point in the history
…uration-into-separate-module

Extract esmf-native-support module from samm-cli
  • Loading branch information
atextor authored Nov 4, 2024
2 parents bf0f521 + bae3ae8 commit 6a5fa29
Show file tree
Hide file tree
Showing 50 changed files with 3,993 additions and 1,319 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/pull-request-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,21 @@ jobs:
java --version
export MAVEN_OPTS="-Xmx4096m"
export JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean install -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
cd tools/samm-cli
unset JAVA_TOOL_OPTIONS
mvn -B clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean install -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
shell: bash

- name: Build native image
if: matrix.os != 'macos-13'
run: |
export MAVEN_OPTS="-Xmx4096m"
cd tools/samm-cli
mvn -B package -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B -pl tools/samm-cli clean verify -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
shell: bash

- name: Build native image (Mac)
if: matrix.os == 'macos-13'
run: |
export MAVEN_OPTS="-Xmx4096m"
mvn -B -pl tools/samm-cli clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
bundle="samm-bundle-DEV-SNAPSHOT-$(date +%s)"
mkdir ${bundle}
curl -Lo jre.tar.gz https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.3%2B9/OpenJDK21U-jre_x64_mac_hotspot_21.0.3_9.tar.gz
Expand Down
24 changes: 9 additions & 15 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@2f25c0caae5b220866f732832d5e3e29ff493338 # v1.2.1
with:
java-version: '17.0.8'
java-version: '17.0.10'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -99,13 +99,10 @@ jobs:
release_version=${{ github.event.inputs.release_version }}
# Actual build of core SDK
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean deploy -Dmaven.wagon.httpconnectionManager.ttlSeconds=60 -DaltDeploymentRepository=local::default::file://nexus-staging -Psign
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean deploy -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60 -DaltDeploymentRepository=local::default::file://nexus-staging -Psign
# Build of CLI
pushd tools/samm-cli
unset JAVA_TOOL_OPTIONS
mvn -B clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B verify -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
popd
mvn -B -pl tools/samm-cli clean verify -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
# Create .tar.gz of samm-cli
pushd tools/samm-cli/target
Expand Down Expand Up @@ -152,7 +149,7 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@2f25c0caae5b220866f732832d5e3e29ff493338 # v1.2.1
with:
java-version: '17.0.8'
java-version: '17.0.10'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -174,11 +171,10 @@ jobs:
mvn versions:set -DnewVersion=${{ github.event.inputs.release_version }}
mvn versions:commit
# Actual build of core SDK
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean install -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean install -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
# Build of CLI
cd tools/samm-cli
unset JAVA_TOOL_OPTIONS
mvn -B clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B -pl tools/samm-cli clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
shell: bash

- name: Build native executable
Expand Down Expand Up @@ -226,7 +222,7 @@ jobs:
- name: Setup JDK
uses: graalvm/setup-graalvm@2f25c0caae5b220866f732832d5e3e29ff493338 # v1.2.1
with:
java-version: '17.0.8'
java-version: '17.0.10'
distribution: 'graalvm'
components: 'native-image,js'
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -261,12 +257,10 @@ jobs:
mvn versions:commit
# Actual build of core SDK
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean install -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B -pl '!org.eclipse.esmf:samm-cli' clean install -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
# Build of CLI
cd tools/samm-cli
unset JAVA_TOOL_OPTIONS
mvn -B clean verify -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B verify -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
mvn -B -pl tools/samm-cli clean verify -Pnative -Dmaven.wagon.httpconnectionManager.ttlSeconds=60
shell: bash

- name: Upload Windows binary
Expand Down
5 changes: 0 additions & 5 deletions core/esmf-aspect-meta-model-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
<name>ESMF Aspect Meta Model Java</name>
<packaging>jar</packaging>

<properties>
<generated-sources>${project.basedir}/src-gen</generated-sources>
<build-time-sources>${project.basedir}/src-buildtime</build-time-sources>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.esmf</groupId>
Expand Down
172 changes: 172 additions & 0 deletions core/esmf-native-support/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
~
~ See the AUTHORS file(s) distributed with this work for additional
~ information regarding authorship.
~
~ This Source Code Form is subject to the terms of the Mozilla Public
~ License, v. 2.0. If a copy of the MPL was not distributed with this
~ file, You can obtain one at https://mozilla.org/MPL/2.0/.
~
~ SPDX-License-Identifier: MPL-2.0
-->

<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>org.eclipse.esmf</groupId>
<artifactId>esmf-sdk-parent</artifactId>
<version>DEV-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>esmf-native-support</artifactId>
<name>ESMF Native Support</name>

<properties>
<skip.maven.shade>false</skip.maven.shade>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.esmf</groupId>
<artifactId>esmf-aspect-model-starter</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<!-- This needs to take place after the customize-resource-config exec-maven-plugin goal runs and before the package phase -->
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory>
<resources>
<resource>
<directory>${generated-sources}/main/resources/META-INF</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
<arg>--add-exports</arg>
<arg>java.desktop/sun.awt=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>java.desktop/sun.font=ALL-UNNAMED</arg>
<arg>--add-exports</arg>
<arg>org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED</arg>
</compilerArgs>
<showWarnings>false</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<excludePackageNames>org.eclipse.esmf.substitution,org.eclipse.esmf.buildtime</excludePackageNames>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>--add-exports org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED</argLine>
</configuration>
</plugin>

<!-- Executes build-time-only code -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<!-- Generate admin-shell reflection config -->
<execution>
<id>generate-admin-shell-reflection-config</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<!-- The main class of your build-time scanning code -->
<mainClass>org.eclipse.esmf.buildtime.Aas4jClassSetup</mainClass>
<!-- Pass the directory where to write the properties file -->
<commandlineArgs>${project.build.outputDirectory}</commandlineArgs>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</execution>
<!-- Execute adjustments of native configs that were generated during the tests -->
<execution>
<id>customize-resource-config</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<!-- The main class of your build-time scanning code -->
<mainClass>org.eclipse.esmf.buildtime.CustomizeGraalVmConfigs</mainClass>
<!-- Pass the native image configs directory as a commandline param -->
<commandlineArgs>${native-config-path}</commandlineArgs>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- Exclude build-time-only code from jar -->
<excludes>
<exclude>org/eclipse/esmf/buildtime/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
import static org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.util.ReflectionHelper.MODEL_PACKAGE_NAME;
import static org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.util.ReflectionHelper.MODEL_TYPE_SUPERCLASSES;
import static org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.util.ReflectionHelper.XML_MIXINS_PACKAGE_NAME;
import static org.eclipse.esmf.nativefeatures.AssetAdministrationShellFeature.ADMINSHELL_PROPERTIES;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -70,14 +70,22 @@ public Aas4jClassSetup() {
config.interfaces = scanAasInterfaces();
config.enums = modelScan.getAllEnums().loadClasses( Enum.class );
config.interfacesWithoutDefaultImplementation = getInterfacesWithoutDefaultImplementation( modelScan );
config.classesInModelPackage = classesInPackage( MODEL_PACKAGE_NAME );
config.classesInDefaultImplementationPackage = classesInPackage( DEFAULT_IMPLEMENTATION_PACKAGE_NAME );
config.classesInJsonMixinsPackage = classesInPackage( JSON_MIXINS_PACKAGE_NAME );
config.classesInXmlMixinsPackage = classesInPackage( XML_MIXINS_PACKAGE_NAME );
}

public static void main( final String[] args ) throws IOException {
final AdminShellConfig config = new Aas4jClassSetup().config;
final Properties p = config.toProperties();
final File out = new File( args[0] );
final FileOutputStream outputStream = new FileOutputStream( out );
p.store( outputStream, null );
try ( final FileOutputStream outputStream = new FileOutputStream( Path.of( args[0] ).resolve( ADMINSHELL_PROPERTIES ).toFile() ) ) {
new Aas4jClassSetup().config.toProperties().store( outputStream, null );
}
}

private Set<Class<?>> classesInPackage( final String packageName ) {
try ( final ScanResult scanResult = new ClassGraph().enableAllInfo().acceptPackages( packageName ).scan() ) {
return new HashSet<>( scanResult.getAllClasses().loadClasses() );
}
}

/**
Expand Down
Loading

0 comments on commit 6a5fa29

Please sign in to comment.