Skip to content

Commit 024da50

Browse files
committed
Fix aas4j setup for GraalVM build
1 parent 0df4250 commit 024da50

File tree

5 files changed

+112
-20
lines changed

5 files changed

+112
-20
lines changed

tools/samm-cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
</goals>
199199
<configuration>
200200
<!-- The main class of your build-time scanning code -->
201-
<mainClass>org.eclipse.esmf.buildtime.IoAdminShellAasClassSetup</mainClass>
201+
<mainClass>org.eclipse.esmf.buildtime.Aas4jClassSetup</mainClass>
202202
<!-- Pass the build target file as a commandline param -->
203203
<commandlineArgs>${project.build.outputDirectory}/adminshell.properties</commandlineArgs>
204204
<cleanupDaemonThreads>false</cleanupDaemonThreads>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
import org.eclipse.esmf.substitution.AdminShellConfig;
3838
import org.eclipse.esmf.substitution.ImplementationInfo;
39-
import org.eclipse.esmf.substitution.Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper;
39+
import org.eclipse.esmf.substitution.Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper;
4040

4141
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper;
4242
import io.github.classgraph.ClassGraph;
@@ -47,14 +47,14 @@
4747
/**
4848
* This class generates the reflection information normally stored by {@link ReflectionHelper} and serializes it into a .properties file.
4949
* It is part of the substitution logic for this class, see
50-
* {@link Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper} for more information.
50+
* {@link Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper} for more information.
5151
* Note that this class is <i>only</i> supposed to run at build time (via execution from the Maven build) and is not part of the
5252
* resulting CLI codebase. Running this class is configured in the pom.xml of the CLI Maven module (via exec-maven-plugin).
5353
*/
54-
public class IoAdminShellAasClassSetup {
54+
public class Aas4jClassSetup {
5555
private final AdminShellConfig config;
5656

57-
public IoAdminShellAasClassSetup() {
57+
public Aas4jClassSetup() {
5858
// The following replicates the logic from ReflectionHelper's static constructor, but instead stores its result
5959
// in the AdminShellConfig object that can then be written to a .properties file
6060
final ScanResult modelScan = new ClassGraph()
@@ -73,7 +73,7 @@ public IoAdminShellAasClassSetup() {
7373
}
7474

7575
public static void main( final String[] args ) throws IOException {
76-
final AdminShellConfig config = new IoAdminShellAasClassSetup().config;
76+
final AdminShellConfig config = new Aas4jClassSetup().config;
7777
final Properties p = config.toProperties();
7878
final File out = new File( args[0] );
7979
final FileOutputStream outputStream = new FileOutputStream( out );

tools/samm-cli/src/main/java/org/eclipse/esmf/substitution/AdminShellConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/**
3030
* An instance of this class encapsulates the information normally stored by {@link ReflectionHelper}. It is used in its substitution class,
31-
* see {@link Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper} for more information.
31+
* see {@link Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper} for more information.
3232
* This class provides capabilities to serialize and deserialize its objects to/from a {@link Properties} object; more convenient serialization
3333
* (e.g., Java's builtin serialization or Jackson's ObjectMapper) can't be used here due to the limitations of the GraalVM substitution classes.
3434
*/

tools/samm-cli/src/main/java/org/eclipse/esmf/substitution/ImplementationInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
/**
2121
* This is used as a stand-in/replacement for its superclass {@link ReflectionHelper.ImplementationInfo}, which unfortunately can't be
22-
* instantiated directly due to its protected constructor. This class is used in the substition class for {@link ReflectionHelper}, see
23-
* {@link Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper} for more information.
22+
* instantiated directly due to its protected constructor. This class is used in the substitution class for {@link ReflectionHelper}, see
23+
* {@link Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper} for more information.
2424
*/
2525
public class ImplementationInfo<T> extends ReflectionHelper.ImplementationInfo<T> {
2626
public ImplementationInfo( final Class<?> interfaceType, final Class<?> implementationType ) {
Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,29 @@
1313

1414
package org.eclipse.esmf.substitution;
1515

16-
import java.io.FileNotFoundException;
1716
import java.io.IOException;
1817
import java.io.InputStream;
1918
import java.util.List;
2019
import java.util.Map;
2120
import java.util.Properties;
2221
import java.util.Set;
2322

24-
import org.eclipse.esmf.buildtime.IoAdminShellAasClassSetup;
23+
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper;
24+
import org.eclipse.esmf.buildtime.Aas4jClassSetup;
2525

2626
import com.oracle.svm.core.annotate.Alias;
2727
import com.oracle.svm.core.annotate.KeepOriginal;
2828
import com.oracle.svm.core.annotate.RecomputeFieldValue;
2929
import com.oracle.svm.core.annotate.Substitute;
3030
import com.oracle.svm.core.annotate.TargetClass;
3131

32-
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.ReflectionHelper;
33-
3432
/**
3533
* This is a <a href="https://build-native-java-apps.cc/developer-guide/substitution/">GraalVM substitution class</a>
3634
* for {@link ReflectionHelper}, the central point of reflection information of the io.admin-shell.aas library. The original ReflectionHelper
3735
* has a static constructor that initializes several maps and collections (using ClassGraph scans) that hold information about implementations
3836
* of interfaces etc.. For the build of the native image, this logic is replaced by the following logic:
3937
* <ol>
40-
* <li>At build time, the {@link IoAdminShellAasClassSetup} is ran (as a standalone program).
38+
* <li>At build time, the {@link Aas4jClassSetup} is ran (as a standalone program).
4139
* This creates an instance of {@link AdminShellConfig} which contains all the information extracted from the ClassGraph scans.</li>
4240
* <li>The AdminShellConfig is serialized into a .properties file.</li>
4341
* <li>The .properties file is then included as a regular resource in the build.</li>
@@ -53,52 +51,89 @@
5351
@TargetClass( ReflectionHelper.class )
5452
@SuppressWarnings( {
5553
"unused",
56-
"squid:S00101" // Class name uses GraalVM substitution class naming schema, see
54+
"squid:S00101", "NewClassNamingConvention" // Class name uses GraalVM substitution class naming schema, see
5755
// https://github.com/oracle/graal/tree/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk
5856
} )
59-
public final class Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper {
57+
public final class Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper {
6058
@Alias
6159
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
62-
private static final String ROOT_PACKAGE_NAME = "io.adminshell.aas.v3";
60+
private static final String ROOT_PACKAGE_NAME = "org.eclipse.digitaltwin.aas4j.v3";
6361

62+
/**
63+
* @see ReflectionHelper#MODEL_PACKAGE_NAME
64+
*/
65+
@SuppressWarnings( "NonConstantFieldWithUpperCaseName" ) // Field name must match substituted class
6466
@Alias
6567
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
6668
public static String MODEL_PACKAGE_NAME = ROOT_PACKAGE_NAME + ".model";
6769

70+
/**
71+
* @see ReflectionHelper#TYPES_WITH_MODEL_TYPE
72+
*/
73+
@SuppressWarnings( "NonConstantFieldWithUpperCaseName" ) // Field name must match substituted class
6874
@Alias
6975
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
7076
public static Set<Class<?>> TYPES_WITH_MODEL_TYPE;
7177

78+
/**
79+
* @see ReflectionHelper#SUBTYPES
80+
*/
81+
@SuppressWarnings( "NonConstantFieldWithUpperCaseName" ) // Field name must match substituted class
7282
@Alias
7383
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
7484
public static Map<Class<?>, Set<Class<?>>> SUBTYPES;
7585

86+
/**
87+
* @see ReflectionHelper#INTERFACES
88+
*/
89+
@SuppressWarnings( { "NonConstantFieldWithUpperCaseName", "rawtypes" } ) // Field name and signature must match substituted class
7690
@Alias
7791
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
7892
public static Set<Class> INTERFACES;
7993

94+
/**
95+
* @see ReflectionHelper#SUBTYPES
96+
*/
97+
@SuppressWarnings( "NonConstantFieldWithUpperCaseName" ) // Field name must match substituted class
8098
@Alias
8199
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
82100
public static Map<Class<?>, Class<?>> JSON_MIXINS;
83101

102+
/**
103+
* @see ReflectionHelper#XML_MIXINS
104+
*/
105+
@SuppressWarnings( "NonConstantFieldWithUpperCaseName" ) // Field name must match substituted class
84106
@Alias
85107
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
86108
public static Map<Class<?>, Class<?>> XML_MIXINS;
87109

110+
/**
111+
* @see ReflectionHelper#DEFAULT_IMPLEMENTATIONS
112+
*/
113+
@SuppressWarnings( { "NonConstantFieldWithUpperCaseName", "rawtypes" } ) // Field name and signature must match substituted class
88114
@Alias
89115
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
90116
public static List<ReflectionHelper.ImplementationInfo> DEFAULT_IMPLEMENTATIONS;
91117

118+
/**
119+
* @see ReflectionHelper#INTERFACES_WITHOUT_DEFAULT_IMPLEMENTATION
120+
*/
121+
@SuppressWarnings( "NonConstantFieldWithUpperCaseName" ) // Field name must match substituted class
92122
@Alias
93123
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
94124
public static Set<Class<?>> INTERFACES_WITHOUT_DEFAULT_IMPLEMENTATION;
95125

126+
/**
127+
* @see ReflectionHelper#ENUMS
128+
*/
129+
@SuppressWarnings( { "NonConstantFieldWithUpperCaseName", "rawtypes" } ) // Field name and signature must match substituted class
96130
@Alias
97131
@RecomputeFieldValue( kind = RecomputeFieldValue.Kind.FromAlias )
98132
public static List<Class<Enum>> ENUMS;
99133

100134
static {
101-
try ( final InputStream input = Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper.class.getResourceAsStream( "/adminshell.properties" ) ) {
135+
try ( final InputStream input = Target_org_eclipse_digitaltwin_aas4j_v3_dataformat_core_util_ReflectionHelper.class.getResourceAsStream(
136+
"/adminshell.properties" ) ) {
102137
final Properties properties = new Properties();
103138
properties.load( input );
104139
final AdminShellConfig config = AdminShellConfig.fromProperties( properties );
@@ -110,40 +145,97 @@ public final class Target_io_adminshell_aas_v3_dataformat_core_ReflectionHelper
110145
DEFAULT_IMPLEMENTATIONS = config.defaultImplementations;
111146
INTERFACES_WITHOUT_DEFAULT_IMPLEMENTATION = config.interfacesWithoutDefaultImplementation;
112147
ENUMS = config.enums;
113-
} catch ( final FileNotFoundException e ) {
114-
throw new RuntimeException( e );
115148
} catch ( final IOException e ) {
116149
throw new RuntimeException( e );
117150
}
118151
}
119152

153+
/**
154+
* @see ReflectionHelper#isModelInterface(Class)
155+
* @param type see {@link ReflectionHelper#isModelInterface(Class)}
156+
* @return see {@link ReflectionHelper#isModelInterface(Class)}
157+
*/
120158
@KeepOriginal
121159
public static native boolean isModelInterface( final Class<?> type );
122160

161+
/**
162+
* @see ReflectionHelper#isDefaultImplementation(Class)
163+
* @param type see {@link ReflectionHelper#isDefaultImplementation(Class)}
164+
* @return see {@link ReflectionHelper#isDefaultImplementation(Class)}
165+
*/
123166
@KeepOriginal
124167
public static native boolean isDefaultImplementation( final Class<?> type );
125168

169+
/**
170+
* @see ReflectionHelper#hasDefaultImplementation(Class)
171+
* @param interfaceType see {@link ReflectionHelper#hasDefaultImplementation(Class)}
172+
* @return see {@link ReflectionHelper#hasDefaultImplementation(Class)}
173+
*/
126174
@KeepOriginal
127175
public static native boolean hasDefaultImplementation( final Class<?> interfaceType );
128176

177+
/**
178+
* @see ReflectionHelper#getDefaultImplementation(Class)
179+
* @param <T> see {@link ReflectionHelper#getDefaultImplementation(Class)}
180+
* @param interfaceType see {@link ReflectionHelper#getDefaultImplementation(Class)}
181+
* @return see {@link ReflectionHelper#getDefaultImplementation(Class)}
182+
*/
129183
@KeepOriginal
130184
public static native <T> Class<? extends T> getDefaultImplementation( final Class<T> interfaceType );
131185

186+
/**
187+
* @see ReflectionHelper#hasDefaultImplementation(Class)
188+
* @param type see {@link ReflectionHelper#hasDefaultImplementation(Class)}
189+
* @return see {@link ReflectionHelper#hasDefaultImplementation(Class)}
190+
*/
132191
@KeepOriginal
133192
public static native boolean isModelInterfaceOrDefaultImplementation( final Class<?> type );
134193

194+
/**
195+
* @see ReflectionHelper#getAasInterface(Class)
196+
* @param type see {@link ReflectionHelper#getAasInterface(Class)}
197+
* @return see {@link ReflectionHelper#getAasInterface(Class)}
198+
*/
135199
@KeepOriginal
136200
public static native Class<?> getAasInterface( final Class<?> type );
137201

202+
/**
203+
* @see ReflectionHelper#getAasInterfaces(Class)
204+
* @param type see {@link ReflectionHelper#getAasInterfaces(Class)}
205+
* @return see {@link ReflectionHelper#getAasInterfaces(Class)}
206+
*/
138207
@KeepOriginal
139208
public static native Set<Class<?>> getAasInterfaces( final Class<?> type );
140209

210+
/**
211+
* @see ReflectionHelper#getModelType(Class)
212+
* @param clazz see {@link ReflectionHelper#getModelType(Class)}
213+
* @return see {@link ReflectionHelper#getModelType(Class)}
214+
*/
141215
@KeepOriginal
142216
public static native String getModelType( final Class<?> clazz );
143217

218+
/**
219+
* @see ReflectionHelper#getMostSpecificTypeWithModelType(Class)
220+
* @param clazz see {@link ReflectionHelper#getMostSpecificTypeWithModelType(Class)}
221+
* @return see {@link ReflectionHelper#getMostSpecificTypeWithModelType(Class)}
222+
*/
144223
@KeepOriginal
145224
public static native Class<?> getMostSpecificTypeWithModelType( final Class<?> clazz );
146225

226+
/**
227+
* @see ReflectionHelper#getSuperTypes(Class, boolean)
228+
* @param clazz see {@link ReflectionHelper#getSuperTypes(Class, boolean)}
229+
* @param recursive {@link ReflectionHelper#getSuperTypes(Class, boolean)}
230+
* @return see {@link ReflectionHelper#getSuperTypes(Class, boolean)}
231+
*/
147232
@KeepOriginal
148233
public static native Set<Class<?>> getSuperTypes( final Class<?> clazz, final boolean recursive );
234+
235+
/**
236+
* @see ReflectionHelper#setEmptyListsToNull(Object)
237+
* @param element see {@link ReflectionHelper#setEmptyListsToNull(Object)}
238+
*/
239+
@KeepOriginal
240+
public static native void setEmptyListsToNull( Object element );
149241
}

0 commit comments

Comments
 (0)