78
78
import org .graalvm .nativeimage .libgraal .hosted .LibGraalLoader ;
79
79
80
80
import com .oracle .svm .core .NativeImageClassLoaderOptions ;
81
+ import com .oracle .svm .core .SharedConstants ;
81
82
import com .oracle .svm .core .SubstrateOptions ;
82
83
import com .oracle .svm .core .SubstrateUtil ;
83
84
import com .oracle .svm .core .option .AccumulatingLocatableMultiOptionValue ;
@@ -114,6 +115,8 @@ public final class NativeImageClassLoaderSupport {
114
115
private final List <Path > imagemp ;
115
116
private final List <Path > buildmp ;
116
117
118
+ private final Set <Path > imageProvidedJars ;
119
+
117
120
private final EconomicMap <URI , EconomicSet <String >> classes ;
118
121
private final EconomicMap <URI , EconomicSet <String >> packages ;
119
122
private final EconomicSet <String > emptySet ;
@@ -245,6 +248,8 @@ protected NativeImageClassLoaderSupport(ClassLoader defaultSystemClassLoader, St
245
248
246
249
upgradeAndSystemModuleFinder = createUpgradeAndSystemModuleFinder ();
247
250
251
+ imageProvidedJars = parseImageProvidedJarsProperty ();
252
+
248
253
ModuleFinder modulePathsFinder = getModulePathsFinder ();
249
254
Set <String > moduleNames = modulePathsFinder .findAll ().stream ()
250
255
.map (moduleReference -> moduleReference .descriptor ().name ())
@@ -305,7 +310,7 @@ public List<ClassLoader> getClassLoaders() {
305
310
return classLoaders ;
306
311
}
307
312
308
- private ModuleFinder getModulePathsFinder () {
313
+ public ModuleFinder getModulePathsFinder () {
309
314
return ModuleFinder .of (imagemp .toArray (Path []::new ));
310
315
}
311
316
@@ -324,7 +329,12 @@ public void loadAllClasses(ForkJoinPool executor, ImageClassLoader imageClassLoa
324
329
LogUtils .warning (msg );
325
330
326
331
var origin = new IncludeOptionsSupport .ExtendedOptionWithOrigin (new IncludeOptionsSupport .ExtendedOption ("" , PreserveOptionsSupport .PRESERVE_ALL ), preserveAllOrigin );
327
- getModulePathsFinder ().findAll ().forEach (m -> preserveSelectors .addModule (m .descriptor ().name (), origin ));
332
+ for (ModuleReference m : getModulePathsFinder ().findAll ()) {
333
+ var modulePath = m .location ().map (Path ::of ).orElse (null );
334
+ if (!imageProvidedJars .contains (modulePath )) {
335
+ preserveSelectors .addModule (m .descriptor ().name (), origin );
336
+ }
337
+ }
328
338
PreserveOptionsSupport .JDK_MODULES_TO_PRESERVE .forEach (moduleName -> preserveSelectors .addModule (moduleName , origin ));
329
339
preserveSelectors .addModule (ALL_UNNAMED , origin );
330
340
}
@@ -775,6 +785,18 @@ static Optional<String> getMainClassFromModule(Object module) {
775
785
return ((Module ) module ).getDescriptor ().mainClass ();
776
786
}
777
787
788
+ private static Set <Path > parseImageProvidedJarsProperty () {
789
+ Set <Path > imageProvidedJars = new HashSet <>();
790
+ String args = System .getProperty (SharedConstants .IMAGE_PROVIDED_JARS_ENV_VARIABLE , "" );
791
+ if (!args .isEmpty ()) {
792
+ String [] parts = args .split (File .pathSeparator );
793
+ for (String part : parts ) {
794
+ imageProvidedJars .add (Path .of (part ));
795
+ }
796
+ }
797
+ return Collections .unmodifiableSet (imageProvidedJars );
798
+ }
799
+
778
800
private final class LoadClassHandler {
779
801
780
802
private final ForkJoinPool executor ;
@@ -1180,7 +1202,12 @@ public void setPreserveAll(ValueWithOrigin<String> valueWithOrigin) {
1180
1202
1181
1203
public void setTrackAllDynamicAccess (ValueWithOrigin <String > valueWithOrigin ) {
1182
1204
var origin = new IncludeOptionsSupport .ExtendedOptionWithOrigin (new IncludeOptionsSupport .ExtendedOption ("" , DynamicAccessDetectionFeature .TRACK_ALL ), valueWithOrigin );
1183
- getModulePathsFinder ().findAll ().forEach (m -> dynamicAccessSelectors .addModule (m .descriptor ().name (), origin ));
1205
+ for (ModuleReference m : getModulePathsFinder ().findAll ()) {
1206
+ var modulePath = m .location ().map (Path ::of ).orElse (null );
1207
+ if (!imageProvidedJars .contains (modulePath )) {
1208
+ dynamicAccessSelectors .addModule (m .descriptor ().name (), origin );
1209
+ }
1210
+ }
1184
1211
dynamicAccessSelectors .addModule (ALL_UNNAMED , origin );
1185
1212
}
1186
1213
@@ -1307,7 +1334,9 @@ public void addModule(String moduleName, IncludeOptionsSupport.ExtendedOptionWit
1307
1334
IncludeOptionsSupport .ExtendedOptionWithOrigin includeOptionsSupport = new IncludeOptionsSupport .ExtendedOptionWithOrigin (extendedOptionWithOrigin .option (),
1308
1335
extendedOptionWithOrigin .valueWithOrigin ());
1309
1336
for (Path path : applicationClassPath ()) {
1310
- classpathEntries .put (path , includeOptionsSupport );
1337
+ if (!imageProvidedJars .contains (path )) {
1338
+ classpathEntries .put (path , includeOptionsSupport );
1339
+ }
1311
1340
}
1312
1341
} else {
1313
1342
moduleNames .put (moduleName , extendedOptionWithOrigin );
0 commit comments