Search in sources :

Example 1 with JvmReachabilityMetadataRepositoryExtension

use of org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension in project native-build-tools by graalvm.

the class NativeImagePlugin method configureJvmReachabilityConfigurationDirectories.

private void configureJvmReachabilityConfigurationDirectories(Project project, GraalVMExtension graalExtension, NativeImageOptions options, SourceSet sourceSet) {
    JvmReachabilityMetadataRepositoryExtension repositoryExtension = reachabilityExtensionOn(graalExtension);
    Provider<JvmReachabilityMetadataService> serviceProvider = project.getGradle().getSharedServices().registerIfAbsent("nativeConfigurationService", JvmReachabilityMetadataService.class, spec -> {
        LogLevel logLevel = determineLogLevel();
        spec.getParameters().getLogLevel().set(logLevel);
        spec.getParameters().getUri().set(repositoryExtension.getUri());
        spec.getParameters().getCacheDir().set(new File(project.getGradle().getGradleUserHomeDir(), "native-build-tools/repositories"));
    });
    options.getConfigurationFileDirectories().from(repositoryExtension.getEnabled().flatMap(enabled -> {
        if (enabled) {
            if (repositoryExtension.getUri().isPresent()) {
                Configuration classpath = project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName());
                Set<String> excludedModules = repositoryExtension.getExcludedModules().getOrElse(Collections.emptySet());
                Map<String, String> forcedVersions = repositoryExtension.getModuleToConfigVersion().getOrElse(Collections.emptyMap());
                return serviceProvider.map(repo -> repo.findConfigurationDirectoriesFor(query -> classpath.getIncoming().getResolutionResult().allComponents(component -> {
                    ModuleVersionIdentifier moduleVersion = component.getModuleVersion();
                    String module = moduleVersion.getGroup() + ":" + moduleVersion.getName();
                    if (!excludedModules.contains(module)) {
                        query.forArtifact(artifact -> {
                            artifact.gav(module + ":" + moduleVersion.getVersion());
                            if (forcedVersions.containsKey(module)) {
                                artifact.forceConfigVersion(forcedVersions.get(module));
                            }
                        });
                    }
                    query.useLatestConfigWhenVersionIsUntested();
                })).stream().map(Path::toAbsolutePath).map(Path::toFile).collect(Collectors.toList()));
            }
        }
        return project.getProviders().provider(Collections::emptySet);
    }));
}
Also used : GradleUtils(org.graalvm.buildtools.gradle.internal.GradleUtils) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) NativeImageExecutableLocator.graalvmHomeProvider(org.graalvm.buildtools.gradle.internal.NativeImageExecutableLocator.graalvmHomeProvider) BuildNativeImageTask(org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask) URISyntaxException(java.net.URISyntaxException) ListProperty(org.gradle.api.provider.ListProperty) JavaPlugin(org.gradle.api.plugins.JavaPlugin) NamedDomainObjectContainer(org.gradle.api.NamedDomainObjectContainer) NativeConfigurations(org.graalvm.buildtools.gradle.internal.NativeConfigurations) ApplicationPlugin(org.gradle.api.plugins.ApplicationPlugin) OutputDirectory(org.gradle.api.tasks.OutputDirectory) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) NativeImageOptions(org.graalvm.buildtools.gradle.dsl.NativeImageOptions) Locale(java.util.Locale) Map(java.util.Map) DuplicatesStrategy(org.gradle.api.file.DuplicatesStrategy) ExtensionAware(org.gradle.api.plugins.ExtensionAware) GraalVMExtension(org.graalvm.buildtools.gradle.dsl.GraalVMExtension) URI(java.net.URI) Path(java.nio.file.Path) LogLevel(org.gradle.api.logging.LogLevel) Project(org.gradle.api.Project) SharedConstants(org.graalvm.buildtools.utils.SharedConstants) GenerateResourcesConfigFile(org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile) GraalVMLogger(org.graalvm.buildtools.gradle.internal.GraalVMLogger) Set(java.util.Set) JavaForkOptions(org.gradle.process.JavaForkOptions) GFileUtils(org.gradle.util.GFileUtils) Collectors(java.util.stream.Collectors) TaskContainer(org.gradle.api.tasks.TaskContainer) ArchiveOperations(org.gradle.api.file.ArchiveOperations) DefaultTestBinaryConfig(org.graalvm.buildtools.gradle.internal.DefaultTestBinaryConfig) AGENT_OUTPUT_FOLDER(org.graalvm.buildtools.utils.SharedConstants.AGENT_OUTPUT_FOLDER) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) AgentConfiguration(org.graalvm.buildtools.gradle.dsl.AgentConfiguration) Callable(java.util.concurrent.Callable) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) FileCollection(org.gradle.api.file.FileCollection) CommandLineArgumentProvider(org.gradle.process.CommandLineArgumentProvider) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) VersionInfo(org.graalvm.buildtools.VersionInfo) AttributeContainer(org.gradle.api.attributes.AttributeContainer) Attribute(org.gradle.api.attributes.Attribute) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProcessGeneratedGraalResourceFiles(org.graalvm.buildtools.gradle.internal.ProcessGeneratedGraalResourceFiles) Directory(org.gradle.api.file.Directory) JvmReachabilityMetadataRepositoryExtension(org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension) Test(org.gradle.api.tasks.testing.Test) FileSystemLocation(org.gradle.api.file.FileSystemLocation) FileSystemOperations(org.gradle.api.file.FileSystemOperations) BaseNativeImageOptions(org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions) Jar(org.gradle.api.tasks.bundling.Jar) AGENT_PROPERTY(org.graalvm.buildtools.utils.SharedConstants.AGENT_PROPERTY) Action(org.gradle.api.Action) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) AgentCommandLineProvider(org.graalvm.buildtools.gradle.internal.AgentCommandLineProvider) NativeRunTask(org.graalvm.buildtools.gradle.tasks.NativeRunTask) ExecOperations(org.gradle.process.ExecOperations) DeprecatedNativeImageOptions(org.graalvm.buildtools.gradle.internal.DeprecatedNativeImageOptions) JavaApplication(org.gradle.api.plugins.JavaApplication) File(java.io.File) Consumer(java.util.function.Consumer) ObjectFactory(org.gradle.api.model.ObjectFactory) GradleUtils.transitiveProjectArtifacts(org.graalvm.buildtools.gradle.internal.GradleUtils.transitiveProjectArtifacts) Property(org.gradle.api.provider.Property) DefaultGraalVmExtension(org.graalvm.buildtools.gradle.internal.DefaultGraalVmExtension) JavaExec(org.gradle.api.tasks.JavaExec) JvmReachabilityMetadataService(org.graalvm.buildtools.gradle.internal.JvmReachabilityMetadataService) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) Path(java.nio.file.Path) Set(java.util.Set) SourceSet(org.gradle.api.tasks.SourceSet) AgentConfiguration(org.graalvm.buildtools.gradle.dsl.AgentConfiguration) Configuration(org.gradle.api.artifacts.Configuration) JvmReachabilityMetadataRepositoryExtension(org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension) JvmReachabilityMetadataService(org.graalvm.buildtools.gradle.internal.JvmReachabilityMetadataService) GenerateResourcesConfigFile(org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile) File(java.io.File) Map(java.util.Map) LogLevel(org.gradle.api.logging.LogLevel)

Example 2 with JvmReachabilityMetadataRepositoryExtension

use of org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension in project native-build-tools by graalvm.

the class NativeImagePlugin method configureNativeConfigurationRepo.

private void configureNativeConfigurationRepo(ExtensionAware graalvmNative) {
    JvmReachabilityMetadataRepositoryExtension configurationRepository = graalvmNative.getExtensions().create("metadataRepository", JvmReachabilityMetadataRepositoryExtension.class);
    configurationRepository.getEnabled().convention(false);
    configurationRepository.getUri().convention(configurationRepository.getVersion().map(v -> {
        try {
            return new URI("https://github.com/graalvm/jvm-reachability-metadata/releases/download/" + v + "/jvm-reachability-metadata-" + v + ".zip");
        } catch (URISyntaxException e) {
            return null;
        }
    }));
    configurationRepository.getExcludedModules().convention(Collections.emptySet());
    configurationRepository.getModuleToConfigVersion().convention(Collections.emptyMap());
}
Also used : GradleUtils(org.graalvm.buildtools.gradle.internal.GradleUtils) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) NativeImageExecutableLocator.graalvmHomeProvider(org.graalvm.buildtools.gradle.internal.NativeImageExecutableLocator.graalvmHomeProvider) BuildNativeImageTask(org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask) URISyntaxException(java.net.URISyntaxException) ListProperty(org.gradle.api.provider.ListProperty) JavaPlugin(org.gradle.api.plugins.JavaPlugin) NamedDomainObjectContainer(org.gradle.api.NamedDomainObjectContainer) NativeConfigurations(org.graalvm.buildtools.gradle.internal.NativeConfigurations) ApplicationPlugin(org.gradle.api.plugins.ApplicationPlugin) OutputDirectory(org.gradle.api.tasks.OutputDirectory) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) NativeImageOptions(org.graalvm.buildtools.gradle.dsl.NativeImageOptions) Locale(java.util.Locale) Map(java.util.Map) DuplicatesStrategy(org.gradle.api.file.DuplicatesStrategy) ExtensionAware(org.gradle.api.plugins.ExtensionAware) GraalVMExtension(org.graalvm.buildtools.gradle.dsl.GraalVMExtension) URI(java.net.URI) Path(java.nio.file.Path) LogLevel(org.gradle.api.logging.LogLevel) Project(org.gradle.api.Project) SharedConstants(org.graalvm.buildtools.utils.SharedConstants) GenerateResourcesConfigFile(org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile) GraalVMLogger(org.graalvm.buildtools.gradle.internal.GraalVMLogger) Set(java.util.Set) JavaForkOptions(org.gradle.process.JavaForkOptions) GFileUtils(org.gradle.util.GFileUtils) Collectors(java.util.stream.Collectors) TaskContainer(org.gradle.api.tasks.TaskContainer) ArchiveOperations(org.gradle.api.file.ArchiveOperations) DefaultTestBinaryConfig(org.graalvm.buildtools.gradle.internal.DefaultTestBinaryConfig) AGENT_OUTPUT_FOLDER(org.graalvm.buildtools.utils.SharedConstants.AGENT_OUTPUT_FOLDER) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) AgentConfiguration(org.graalvm.buildtools.gradle.dsl.AgentConfiguration) Callable(java.util.concurrent.Callable) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) FileCollection(org.gradle.api.file.FileCollection) CommandLineArgumentProvider(org.gradle.process.CommandLineArgumentProvider) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) VersionInfo(org.graalvm.buildtools.VersionInfo) AttributeContainer(org.gradle.api.attributes.AttributeContainer) Attribute(org.gradle.api.attributes.Attribute) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProcessGeneratedGraalResourceFiles(org.graalvm.buildtools.gradle.internal.ProcessGeneratedGraalResourceFiles) Directory(org.gradle.api.file.Directory) JvmReachabilityMetadataRepositoryExtension(org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension) Test(org.gradle.api.tasks.testing.Test) FileSystemLocation(org.gradle.api.file.FileSystemLocation) FileSystemOperations(org.gradle.api.file.FileSystemOperations) BaseNativeImageOptions(org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions) Jar(org.gradle.api.tasks.bundling.Jar) AGENT_PROPERTY(org.graalvm.buildtools.utils.SharedConstants.AGENT_PROPERTY) Action(org.gradle.api.Action) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) AgentCommandLineProvider(org.graalvm.buildtools.gradle.internal.AgentCommandLineProvider) NativeRunTask(org.graalvm.buildtools.gradle.tasks.NativeRunTask) ExecOperations(org.gradle.process.ExecOperations) DeprecatedNativeImageOptions(org.graalvm.buildtools.gradle.internal.DeprecatedNativeImageOptions) JavaApplication(org.gradle.api.plugins.JavaApplication) File(java.io.File) Consumer(java.util.function.Consumer) ObjectFactory(org.gradle.api.model.ObjectFactory) GradleUtils.transitiveProjectArtifacts(org.graalvm.buildtools.gradle.internal.GradleUtils.transitiveProjectArtifacts) Property(org.gradle.api.provider.Property) DefaultGraalVmExtension(org.graalvm.buildtools.gradle.internal.DefaultGraalVmExtension) JavaExec(org.gradle.api.tasks.JavaExec) JvmReachabilityMetadataService(org.graalvm.buildtools.gradle.internal.JvmReachabilityMetadataService) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) JvmReachabilityMetadataRepositoryExtension(org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

File (java.io.File)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2 Callable (java.util.concurrent.Callable)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 VersionInfo (org.graalvm.buildtools.VersionInfo)2 AgentConfiguration (org.graalvm.buildtools.gradle.dsl.AgentConfiguration)2 GraalVMExtension (org.graalvm.buildtools.gradle.dsl.GraalVMExtension)2 JvmReachabilityMetadataRepositoryExtension (org.graalvm.buildtools.gradle.dsl.JvmReachabilityMetadataRepositoryExtension)2 NativeImageOptions (org.graalvm.buildtools.gradle.dsl.NativeImageOptions)2 AgentCommandLineProvider (org.graalvm.buildtools.gradle.internal.AgentCommandLineProvider)2 BaseNativeImageOptions (org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions)2