Search in sources :

Example 6 with GraalVMExtension

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

the class NativeImagePlugin method configureAutomaticTaskCreation.

private void configureAutomaticTaskCreation(Project project, GraalVMExtension graalExtension, Map<String, Provider<Boolean>> agents, TaskContainer tasks, SourceSetContainer sourceSets) {
    graalExtension.getBinaries().configureEach(options -> {
        String binaryName = options.getName();
        String compileTaskName = deriveTaskName(binaryName, "native", "Compile");
        if ("main".equals(binaryName)) {
            compileTaskName = NATIVE_COMPILE_TASK_NAME;
        }
        Provider<Boolean> agent = agentPropertyOverride(project, options);
        agents.put(binaryName, agent);
        TaskProvider<BuildNativeImageTask> imageBuilder = tasks.register(compileTaskName, BuildNativeImageTask.class, builder -> {
            builder.setDescription("Compiles a native image for the " + options.getName() + " binary");
            builder.setGroup(LifecycleBasePlugin.BUILD_GROUP);
            builder.getOptions().convention(options);
            builder.getAgentEnabled().set(agent);
            builder.getUseArgFile().convention(graalExtension.getUseArgFile());
        });
        String runTaskName = deriveTaskName(binaryName, "native", "Run");
        if ("main".equals(binaryName)) {
            runTaskName = NativeRunTask.TASK_NAME;
        } else if (binaryName.toLowerCase(Locale.US).endsWith("test")) {
            runTaskName = "native" + capitalize(binaryName);
        }
        tasks.register(runTaskName, NativeRunTask.class, task -> {
            task.setGroup(LifecycleBasePlugin.BUILD_GROUP);
            task.setDescription("Executes the " + options.getName() + " native binary");
            task.getImage().convention(imageBuilder.map(t -> t.getOutputFile().get()));
            task.getRuntimeArgs().convention(options.getRuntimeArgs());
        });
        configureClasspathJarFor(tasks, options, imageBuilder);
        SourceSet sourceSet = "test".equals(binaryName) ? sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME) : sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        TaskProvider<GenerateResourcesConfigFile> generateResourcesConfig = registerResourcesConfigTask(graalExtension.getGeneratedResourcesDirectory(), options, tasks, transitiveProjectArtifacts(project, sourceSet.getRuntimeClasspathConfigurationName()), deriveTaskName(binaryName, "generate", "ResourcesConfigFile"));
        options.getConfigurationFileDirectories().from(generateResourcesConfig.map(t -> t.getOutputFile().map(f -> f.getAsFile().getParentFile())));
        configureJvmReachabilityConfigurationDirectories(project, graalExtension, options, sourceSet);
    });
}
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) SourceSet(org.gradle.api.tasks.SourceSet) BuildNativeImageTask(org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask) GenerateResourcesConfigFile(org.graalvm.buildtools.gradle.tasks.GenerateResourcesConfigFile)

Example 7 with GraalVMExtension

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

the class NativeImagePlugin method createTestOptions.

private static NativeImageOptions createTestOptions(GraalVMExtension graalExtension, String binaryName, Project project, NativeImageOptions mainExtension, DirectoryProperty testListDirectory, SourceSet sourceSet) {
    NativeImageOptions testExtension = graalExtension.getBinaries().create(binaryName);
    NativeConfigurations configs = createNativeConfigurations(project, binaryName, JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    testExtension.getMainClass().set("org.graalvm.junit.platform.NativeImageJUnitLauncher");
    testExtension.getMainClass().finalizeValue();
    testExtension.getImageName().convention(mainExtension.getImageName().map(name -> name + SharedConstants.NATIVE_TESTS_SUFFIX));
    ListProperty<String> runtimeArgs = testExtension.getRuntimeArgs();
    runtimeArgs.add("--xml-output-dir");
    runtimeArgs.add(project.getLayout().getBuildDirectory().dir("test-results/" + binaryName + "-native").map(d -> d.getAsFile().getAbsolutePath()));
    testExtension.buildArgs("--features=org.graalvm.junit.platform.JUnitPlatformFeature");
    ConfigurableFileCollection classpath = testExtension.getClasspath();
    classpath.from(configs.getImageClasspathConfiguration());
    classpath.from(sourceSet.getOutput().getClassesDirs());
    classpath.from(sourceSet.getOutput().getResourcesDir());
    return testExtension;
}
Also used : NativeConfigurations(org.graalvm.buildtools.gradle.internal.NativeConfigurations) 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) NativeImageOptions(org.graalvm.buildtools.gradle.dsl.NativeImageOptions) BaseNativeImageOptions(org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions) DeprecatedNativeImageOptions(org.graalvm.buildtools.gradle.internal.DeprecatedNativeImageOptions) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection)

Example 8 with GraalVMExtension

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

the class NativeImagePlugin method registerGraalVMExtension.

private GraalVMExtension registerGraalVMExtension(Project project) {
    NamedDomainObjectContainer<NativeImageOptions> nativeImages = project.getObjects().domainObjectContainer(NativeImageOptions.class, name -> project.getObjects().newInstance(BaseNativeImageOptions.class, name, project.getObjects(), project.getProviders(), project.getExtensions().findByType(JavaToolchainService.class), project.getName()));
    GraalVMExtension graalvmNative = project.getExtensions().create(GraalVMExtension.class, "graalvmNative", DefaultGraalVmExtension.class, nativeImages, this, project);
    graalvmNative.getGeneratedResourcesDirectory().set(project.getLayout().getBuildDirectory().dir("native/generated/"));
    configureNativeConfigurationRepo((ExtensionAware) graalvmNative);
    return graalvmNative;
}
Also used : BaseNativeImageOptions(org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions) GraalVMExtension(org.graalvm.buildtools.gradle.dsl.GraalVMExtension) NativeImageOptions(org.graalvm.buildtools.gradle.dsl.NativeImageOptions) BaseNativeImageOptions(org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions) DeprecatedNativeImageOptions(org.graalvm.buildtools.gradle.internal.DeprecatedNativeImageOptions)

Aggregations

GraalVMExtension (org.graalvm.buildtools.gradle.dsl.GraalVMExtension)8 NativeImageOptions (org.graalvm.buildtools.gradle.dsl.NativeImageOptions)5 File (java.io.File)4 Path (java.nio.file.Path)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 BaseNativeImageOptions (org.graalvm.buildtools.gradle.internal.BaseNativeImageOptions)4 BuildNativeImageTask (org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask)4 Plugin (org.gradle.api.Plugin)4 Project (org.gradle.api.Project)4 SourceSet (org.gradle.api.tasks.SourceSet)4 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 Locale (java.util.Locale)3 Map (java.util.Map)3 Callable (java.util.concurrent.Callable)3 Consumer (java.util.function.Consumer)3