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 ;
@@ -340,69 +344,52 @@ private void configureAutomaticTaskCreation(Project project,
340
344
});
341
345
}
342
346
343
- private void configureJvmReachabilityConfigurationDirectories (Project project , GraalVMExtension graalExtension , NativeImageOptions options , SourceSet sourceSet ) {
344
- GraalVMReachabilityMetadataRepositoryExtension repositoryExtension = reachabilityExtensionOn (graalExtension );
345
- Provider <GraalVMReachabilityMetadataService > serviceProvider = graalVMReachabilityMetadataService (project , repositoryExtension );
346
- options .getConfigurationFileDirectories ().from (repositoryExtension .getEnabled ().flatMap (enabled -> {
347
- if (enabled ) {
348
- if (repositoryExtension .getUri ().isPresent ()) {
349
- Configuration classpath = project .getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ());
350
- Set <String > excludedModules = repositoryExtension .getExcludedModules ().getOrElse (Collections .emptySet ());
351
- Map <String , String > forcedVersions = repositoryExtension .getModuleToConfigVersion ().getOrElse (Collections .emptyMap ());
352
- return serviceProvider .map (repo -> repo .findConfigurationsFor (query -> classpath .getIncoming ().getResolutionResult ().allComponents (component -> {
353
- ModuleVersionIdentifier moduleVersion = component .getModuleVersion ();
354
- String module = Objects .requireNonNull (moduleVersion ).getGroup () + ":" + moduleVersion .getName ();
355
- if (!excludedModules .contains (module )) {
356
- query .forArtifact (artifact -> {
357
- artifact .gav (module + ":" + moduleVersion .getVersion ());
358
- if (forcedVersions .containsKey (module )) {
359
- artifact .forceConfigVersion (forcedVersions .get (module ));
360
- }
361
- });
362
- }
363
- query .useLatestConfigWhenVersionIsUntested ();
364
- })).stream ()
365
- .map (configuration -> configuration .getDirectory ().toAbsolutePath ())
366
- .map (Path ::toFile )
367
- .collect (Collectors .toList ()));
368
- }
369
- }
370
- return project .getProviders ().provider (Collections ::emptySet );
371
- }));
347
+ private void configureJvmReachabilityConfigurationDirectories (Project project , GraalVMExtension graalExtension ,
348
+ NativeImageOptions options , SourceSet sourceSet ) {
349
+ options .getConfigurationFileDirectories ().from (graalVMReachabilityQuery (project , graalExtension , sourceSet ,
350
+ configuration -> true , this ::getConfigurationDirectory ,
351
+ Collectors .toList ()));
352
+ }
353
+
354
+ private File getConfigurationDirectory (ModuleVersionIdentifier moduleVersion ,
355
+ DirectoryConfiguration configuration ) {
356
+ return configuration .getDirectory ().toAbsolutePath ().toFile ();
357
+ }
358
+
359
+ private void configureJvmReachabilityExcludeConfigArgs (Project project , GraalVMExtension graalExtension ,
360
+ NativeImageOptions options , SourceSet sourceSet ) {
361
+ options .getExcludeConfig ().putAll (graalVMReachabilityQuery (project , graalExtension , sourceSet ,
362
+ DirectoryConfiguration ::isOverride , this ::getExclusionConfig ,
363
+ Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue )));
372
364
}
373
365
374
- private void configureJvmReachabilityExcludeConfigArgs (Project project , GraalVMExtension graalExtension , NativeImageOptions options , SourceSet sourceSet ) {
375
- GraalVMReachabilityMetadataRepositoryExtension repositoryExtension = reachabilityExtensionOn (graalExtension );
376
- Provider <GraalVMReachabilityMetadataService > serviceProvider = graalVMReachabilityMetadataService (project , repositoryExtension );
377
- options .getExcludeConfig ().putAll (repositoryExtension .getEnabled ().flatMap (enabled -> {
378
- if (enabled ) {
379
- if (repositoryExtension .getUri ().isPresent ()) {
380
- Configuration classpath = project .getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ());
381
- Set <String > excludedModules = repositoryExtension .getExcludedModules ().getOrElse (Collections .emptySet ());
382
- Map <String , String > forcedVersions = repositoryExtension .getModuleToConfigVersion ().getOrElse (Collections .emptyMap ());
383
- return serviceProvider .map (repo -> classpath .getIncoming ().getResolutionResult ().getAllComponents ().stream ().flatMap (component -> {
366
+ private Map .Entry <String , List <String >> getExclusionConfig (ModuleVersionIdentifier moduleVersion ,
367
+ DirectoryConfiguration configuration ) {
368
+ String gav = moduleVersion .getGroup () + ":" + moduleVersion .getName () + ":" + moduleVersion .getVersion ();
369
+ return new AbstractMap .SimpleEntry <>(gav , Arrays .asList ("^/META-INF/native-image/.*" ));
370
+ }
371
+
372
+ private <T , A , R > Provider <R > graalVMReachabilityQuery (Project project , GraalVMExtension graalExtension ,
373
+ SourceSet sourceSet , Predicate <DirectoryConfiguration > filter ,
374
+ BiFunction <ModuleVersionIdentifier , DirectoryConfiguration , T > mapper , Collector <T , A , R > collector ) {
375
+ GraalVMReachabilityMetadataRepositoryExtension extension = reachabilityExtensionOn (graalExtension );
376
+ return extension .getEnabled ().flatMap (enabled -> {
377
+ if (enabled && extension .getUri ().isPresent ()) {
378
+ Configuration classpath = project .getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ());
379
+ Set <String > excludedModules = extension .getExcludedModules ().getOrElse (Collections .emptySet ());
380
+ Map <String , String > forcedVersions = extension .getModuleToConfigVersion ().getOrElse (Collections .emptyMap ());
381
+ return graalVMReachabilityMetadataService (project , extension ).map (service -> {
382
+ Set <ResolvedComponentResult > components = classpath .getIncoming ().getResolutionResult ().getAllComponents ();
383
+ Stream <T > mapped = components .stream ().flatMap (component -> {
384
384
ModuleVersionIdentifier moduleVersion = component .getModuleVersion ();
385
- return repo .findConfigurationsFor (query -> {
386
- String module = Objects .requireNonNull (moduleVersion ).getGroup () + ":" + moduleVersion .getName ();
387
- if (!excludedModules .contains (module )) {
388
- query .forArtifact (artifact -> {
389
- artifact .gav (module + ":" + moduleVersion .getVersion ());
390
- if (forcedVersions .containsKey (module )) {
391
- artifact .forceConfigVersion (forcedVersions .get (module ));
392
- }
393
- });
394
- }
395
- query .useLatestConfigWhenVersionIsUntested ();
396
- }).stream ()
397
- .filter (DirectoryConfiguration ::isOverride )
398
- .map (configuration -> new AbstractMap .SimpleEntry <>(
399
- moduleVersion .getGroup () + ":" + moduleVersion .getName () + ":" + moduleVersion .getVersion (),
400
- Arrays .asList ("^/META-INF/native-image/.*" )));
401
- }).collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue )));
402
- }
385
+ Set <DirectoryConfiguration > configurations = service .findConfigurationsFor (excludedModules , forcedVersions , moduleVersion );
386
+ return configurations .stream ().filter (filter ).map (configuration -> mapper .apply (moduleVersion , configuration ));
387
+ });
388
+ return mapped .collect (collector );
389
+ });
403
390
}
404
- return project .getProviders ().provider (Collections :: emptyMap );
405
- })) ;
391
+ return project .getProviders ().provider (() -> Stream .< T > empty (). collect ( collector ) );
392
+ });
406
393
}
407
394
408
395
private Provider <GraalVMReachabilityMetadataService > graalVMReachabilityMetadataService (Project project ,
@@ -413,7 +400,8 @@ private Provider<GraalVMReachabilityMetadataService> graalVMReachabilityMetadata
413
400
LogLevel logLevel = determineLogLevel ();
414
401
spec .getParameters ().getLogLevel ().set (logLevel );
415
402
spec .getParameters ().getUri ().set (repositoryExtension .getUri ());
416
- spec .getParameters ().getCacheDir ().set (new File (project .getGradle ().getGradleUserHomeDir (), "native-build-tools/repositories" ));
403
+ spec .getParameters ().getCacheDir ().set (
404
+ new File (project .getGradle ().getGradleUserHomeDir (), "native-build-tools/repositories" ));
417
405
});
418
406
}
419
407
0 commit comments