77
77
import org .gradle .api .artifacts .ConfigurationContainer ;
78
78
import org .gradle .api .artifacts .ModuleVersionIdentifier ;
79
79
import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
80
+ import org .gradle .api .artifacts .result .ResolvedComponentResult ;
80
81
import org .gradle .api .attributes .Attribute ;
81
82
import org .gradle .api .attributes .AttributeContainer ;
82
83
import org .gradle .api .file .ArchiveOperations ;
128
129
import java .util .Map ;
129
130
import java .util .Objects ;
130
131
import java .util .Set ;
132
+ import java .util .function .BiFunction ;
131
133
import java .util .function .Predicate ;
132
134
import java .util .function .Supplier ;
133
135
import java .util .regex .Pattern ;
136
+ import java .util .stream .Collector ;
134
137
import java .util .stream .Collectors ;
138
+ import java .util .stream .Stream ;
135
139
136
140
import static org .graalvm .buildtools .gradle .internal .ConfigurationCacheSupport .serializablePredicateOf ;
137
141
import static org .graalvm .buildtools .gradle .internal .ConfigurationCacheSupport .serializableSupplierOf ;
@@ -335,69 +339,52 @@ private void configureAutomaticTaskCreation(Project project,
335
339
});
336
340
}
337
341
338
- private void configureJvmReachabilityConfigurationDirectories (Project project , GraalVMExtension graalExtension , NativeImageOptions options , SourceSet sourceSet ) {
339
- GraalVMReachabilityMetadataRepositoryExtension repositoryExtension = reachabilityExtensionOn (graalExtension );
340
- Provider <GraalVMReachabilityMetadataService > serviceProvider = graalVMReachabilityMetadataService (project , repositoryExtension );
341
- options .getConfigurationFileDirectories ().from (repositoryExtension .getEnabled ().flatMap (enabled -> {
342
- if (enabled ) {
343
- if (repositoryExtension .getUri ().isPresent ()) {
344
- Configuration classpath = project .getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ());
345
- Set <String > excludedModules = repositoryExtension .getExcludedModules ().getOrElse (Collections .emptySet ());
346
- Map <String , String > forcedVersions = repositoryExtension .getModuleToConfigVersion ().getOrElse (Collections .emptyMap ());
347
- return serviceProvider .map (repo -> repo .findConfigurationsFor (query -> classpath .getIncoming ().getResolutionResult ().allComponents (component -> {
348
- ModuleVersionIdentifier moduleVersion = component .getModuleVersion ();
349
- String module = Objects .requireNonNull (moduleVersion ).getGroup () + ":" + moduleVersion .getName ();
350
- if (!excludedModules .contains (module )) {
351
- query .forArtifact (artifact -> {
352
- artifact .gav (module + ":" + moduleVersion .getVersion ());
353
- if (forcedVersions .containsKey (module )) {
354
- artifact .forceConfigVersion (forcedVersions .get (module ));
355
- }
356
- });
357
- }
358
- query .useLatestConfigWhenVersionIsUntested ();
359
- })).stream ()
360
- .map (configuration -> configuration .getDirectory ().toAbsolutePath ())
361
- .map (Path ::toFile )
362
- .collect (Collectors .toList ()));
363
- }
364
- }
365
- return project .getProviders ().provider (Collections ::emptySet );
366
- }));
342
+ private void configureJvmReachabilityConfigurationDirectories (Project project , GraalVMExtension graalExtension ,
343
+ NativeImageOptions options , SourceSet sourceSet ) {
344
+ options .getConfigurationFileDirectories ().from (graalVMReachabilityQuery (project , graalExtension , sourceSet ,
345
+ configuration -> true , this ::getConfigurationDirectory ,
346
+ Collectors .toList ()));
347
+ }
348
+
349
+ private File getConfigurationDirectory (ModuleVersionIdentifier moduleVersion ,
350
+ DirectoryConfiguration configuration ) {
351
+ return configuration .getDirectory ().toAbsolutePath ().toFile ();
352
+ }
353
+
354
+ private void configureJvmReachabilityExcludeConfigArgs (Project project , GraalVMExtension graalExtension ,
355
+ NativeImageOptions options , SourceSet sourceSet ) {
356
+ options .getExcludeConfig ().putAll (graalVMReachabilityQuery (project , graalExtension , sourceSet ,
357
+ DirectoryConfiguration ::isOverride , this ::getExclusionConfig ,
358
+ Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue )));
367
359
}
368
360
369
- private void configureJvmReachabilityExcludeConfigArgs (Project project , GraalVMExtension graalExtension , NativeImageOptions options , SourceSet sourceSet ) {
370
- GraalVMReachabilityMetadataRepositoryExtension repositoryExtension = reachabilityExtensionOn (graalExtension );
371
- Provider <GraalVMReachabilityMetadataService > serviceProvider = graalVMReachabilityMetadataService (project , repositoryExtension );
372
- options .getExcludeConfig ().putAll (repositoryExtension .getEnabled ().flatMap (enabled -> {
373
- if (enabled ) {
374
- if (repositoryExtension .getUri ().isPresent ()) {
375
- Configuration classpath = project .getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ());
376
- Set <String > excludedModules = repositoryExtension .getExcludedModules ().getOrElse (Collections .emptySet ());
377
- Map <String , String > forcedVersions = repositoryExtension .getModuleToConfigVersion ().getOrElse (Collections .emptyMap ());
378
- return serviceProvider .map (repo -> classpath .getIncoming ().getResolutionResult ().getAllComponents ().stream ().flatMap (component -> {
361
+ private Map .Entry <String , List <String >> getExclusionConfig (ModuleVersionIdentifier moduleVersion ,
362
+ DirectoryConfiguration configuration ) {
363
+ String gav = moduleVersion .getGroup () + ":" + moduleVersion .getName () + ":" + moduleVersion .getVersion ();
364
+ return new AbstractMap .SimpleEntry <>(gav , Arrays .asList ("^/META-INF/native-image/.*" ));
365
+ }
366
+
367
+ private <T , A , R > Provider <R > graalVMReachabilityQuery (Project project , GraalVMExtension graalExtension ,
368
+ SourceSet sourceSet , Predicate <DirectoryConfiguration > filter ,
369
+ BiFunction <ModuleVersionIdentifier , DirectoryConfiguration , T > mapper , Collector <T , A , R > collector ) {
370
+ GraalVMReachabilityMetadataRepositoryExtension extension = reachabilityExtensionOn (graalExtension );
371
+ return extension .getEnabled ().flatMap (enabled -> {
372
+ if (enabled && extension .getUri ().isPresent ()) {
373
+ Configuration classpath = project .getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ());
374
+ Set <String > excludedModules = extension .getExcludedModules ().getOrElse (Collections .emptySet ());
375
+ Map <String , String > forcedVersions = extension .getModuleToConfigVersion ().getOrElse (Collections .emptyMap ());
376
+ return graalVMReachabilityMetadataService (project , extension ).map (service -> {
377
+ Set <ResolvedComponentResult > components = classpath .getIncoming ().getResolutionResult ().getAllComponents ();
378
+ Stream <T > mapped = components .stream ().flatMap (component -> {
379
379
ModuleVersionIdentifier moduleVersion = component .getModuleVersion ();
380
- return repo .findConfigurationsFor (query -> {
381
- String module = Objects .requireNonNull (moduleVersion ).getGroup () + ":" + moduleVersion .getName ();
382
- if (!excludedModules .contains (module )) {
383
- query .forArtifact (artifact -> {
384
- artifact .gav (module + ":" + moduleVersion .getVersion ());
385
- if (forcedVersions .containsKey (module )) {
386
- artifact .forceConfigVersion (forcedVersions .get (module ));
387
- }
388
- });
389
- }
390
- query .useLatestConfigWhenVersionIsUntested ();
391
- }).stream ()
392
- .filter (DirectoryConfiguration ::isOverride )
393
- .map (configuration -> new AbstractMap .SimpleEntry <>(
394
- moduleVersion .getGroup () + ":" + moduleVersion .getName () + ":" + moduleVersion .getVersion (),
395
- Arrays .asList ("^/META-INF/native-image/.*" )));
396
- }).collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue )));
397
- }
380
+ Set <DirectoryConfiguration > configurations = service .findConfigurationsFor (excludedModules , forcedVersions , moduleVersion );
381
+ return configurations .stream ().filter (filter ).map (configuration -> mapper .apply (moduleVersion , configuration ));
382
+ });
383
+ return mapped .collect (collector );
384
+ });
398
385
}
399
- return project .getProviders ().provider (Collections :: emptyMap );
400
- })) ;
386
+ return project .getProviders ().provider (() -> Stream .< T > empty (). collect ( collector ) );
387
+ });
401
388
}
402
389
403
390
private Provider <GraalVMReachabilityMetadataService > graalVMReachabilityMetadataService (Project project ,
@@ -408,7 +395,8 @@ private Provider<GraalVMReachabilityMetadataService> graalVMReachabilityMetadata
408
395
LogLevel logLevel = determineLogLevel ();
409
396
spec .getParameters ().getLogLevel ().set (logLevel );
410
397
spec .getParameters ().getUri ().set (repositoryExtension .getUri ());
411
- spec .getParameters ().getCacheDir ().set (new File (project .getGradle ().getGradleUserHomeDir (), "native-build-tools/repositories" ));
398
+ spec .getParameters ().getCacheDir ().set (
399
+ new File (project .getGradle ().getGradleUserHomeDir (), "native-build-tools/repositories" ));
412
400
});
413
401
}
414
402
0 commit comments