Search in sources :

Example 6 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService in project gradle by gradle.

the class GroovyBasePlugin method getToolchainTool.

private <T> Provider<T> getToolchainTool(Project project, BiFunction<JavaToolchainService, JavaToolchainSpec, Provider<T>> toolMapper) {
    final JavaPluginExtension extension = extensionOf(project, JavaPluginExtension.class);
    final JavaToolchainService service = extensionOf(project, JavaToolchainService.class);
    return toolMapper.apply(service, extension.getToolchain());
}
Also used : JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService)

Example 7 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService in project webpieces by deanhiller.

the class TemplateCompilerPlugin method configureSourceSetDefaults.

private void configureSourceSetDefaults(Project project) {
    log.debug("setup configure source set defaults");
    JavaPluginExtension javaPluginExtension = javaPluginExtension();
    // SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
    // SourceSet main = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME);
    // SourceSet test = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME);
    // 
    // test.setRuntimeClasspath(project.getObjects().fileCollection().from(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
    // // Register the project's source set output directories
    // sourceSets.all(sourceSet ->
    // buildOutputCleanupRegistry.registerOutputs(sourceSet.getOutput())
    // );
    javaPluginExtension.getSourceSets().all(sourceSet -> {
        String name = "templates";
        final DefaultTemplateSourceSet groovySourceSet = new DefaultTemplateSourceSet(name, ((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
        (new DslObject(sourceSet)).getConvention().getPlugins().put("templates", groovySourceSet);
        // copied from JavaBasePlugin
        processCopyTemplateResources(project, sourceSet);
        // sourceSet.getExtensions().add(GroovySourceDirectorySet.class, "groovy", groovySourceSet.getGroovy()); //We do not need this one
        SourceDirectorySet groovySource = groovySourceSet.getTemplateDirSet();
        groovySource.srcDir("src/" + sourceSet.getName() + "/java");
        sourceSet.getResources().getFilter().exclude(SerializableLambdas.spec((element) -> {
            return groovySource.contains(element.getFile());
        }));
        sourceSet.getAllJava().source(groovySource);
        sourceSet.getAllSource().source(groovySource);
        // copy over but comment as I think no longer needed anymore
        // NEEDED?: configureOutputDirectoryForSourceSet(sourceSet, groovySourceSet.getTemplateDirSet(), project);
        final TaskProvider<TemplateCompile> compileTask = project.getTasks().register(sourceSet.getCompileTaskName("templates"), TemplateCompile.class, compile -> {
            JvmPluginsHelper.configureForSourceSet(sourceSet, groovySource, compile, compile.getOptions(), project);
            // copy over but comment as I think no longer needed anymore
            // NEEDED?: compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription("Compiles the " + sourceSet.getName() + " Webpieces Templates.");
            compile.setSource(groovySource);
        // copy over but comment as I think no longer needed anymore
        // NEEDED?: compile.setDestinationDir(new File(project.getBuildDir(), "classes/" + groovySourceSet.getTemplateDirSet().getName() + "/" + sourceSet.getName()));
        // we do not support different versions of java from gradle right now...
        // compile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
        });
        JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, groovySource, this.project, compileTask, compileTask.map(TemplateCompile::getOptions));
        this.jvmPluginServices.useDefaultTargetPlatformInference(this.project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()), compileTask);
        this.jvmPluginServices.useDefaultTargetPlatformInference(this.project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName()), compileTask);
        this.project.getTasks().named(sourceSet.getClassesTaskName(), (task) -> {
            task.dependsOn(new Object[] { compileTask });
        });
    // Ties resources to be done first or something but we don't need this
    // this.project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()).attributes((attrs) -> {
    // attrs.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, (LibraryElements)this.project.getObjects().named(LibraryElements.class, "classes+resources"));
    // });
    });
// this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new ConfigureAction(this.project, objectFactory));
}
Also used : ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) Closure(groovy.lang.Closure) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) SerializableLambdas(org.gradle.api.internal.lambdas.SerializableLambdas) FileCollection(org.gradle.api.file.FileCollection) Logger(org.gradle.api.logging.Logger) LibraryElements(org.gradle.api.attributes.LibraryElements) Inject(javax.inject.Inject) DslObject(org.gradle.api.internal.plugins.DslObject) Configuration(org.gradle.api.artifacts.Configuration) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) FileTreeElement(org.gradle.api.file.FileTreeElement) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) FileCopyDetails(org.gradle.api.file.FileCopyDetails) LogLevel(org.gradle.api.logging.LogLevel) Action(org.gradle.api.Action) org.gradle.api.plugins(org.gradle.api.plugins) Project(org.gradle.api.Project) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) Cast(org.gradle.internal.Cast) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File) ConventionMapping(org.gradle.api.internal.ConventionMapping) JvmEcosystemUtilities(org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities) org.gradle.api.tasks(org.gradle.api.tasks) ObjectFactory(org.gradle.api.model.ObjectFactory) Spec(org.gradle.api.specs.Spec) Logging(org.gradle.api.logging.Logging) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) Plugin(org.gradle.api.Plugin) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) DslObject(org.gradle.api.internal.plugins.DslObject) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet)

Aggregations

JavaToolchainService (org.gradle.jvm.toolchain.JavaToolchainService)7 Inject (javax.inject.Inject)2 Plugin (org.gradle.api.Plugin)2 Project (org.gradle.api.Project)2 LibraryElements (org.gradle.api.attributes.LibraryElements)2 FileCollection (org.gradle.api.file.FileCollection)2 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)2 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)2 DslObject (org.gradle.api.internal.plugins.DslObject)2 DefaultSourceSet (org.gradle.api.internal.tasks.DefaultSourceSet)2 ObjectFactory (org.gradle.api.model.ObjectFactory)2 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)2 JvmPluginsHelper (org.gradle.api.plugins.internal.JvmPluginsHelper)2 JvmEcosystemUtilities (org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities)2 JvmPluginServices (org.gradle.api.plugins.jvm.internal.JvmPluginServices)2 Provider (org.gradle.api.provider.Provider)2 GroovyCompile (org.gradle.api.tasks.compile.GroovyCompile)2 JavaToolchainSpec (org.gradle.jvm.toolchain.JavaToolchainSpec)2 Sets (com.google.common.collect.Sets)1 Closure (groovy.lang.Closure)1