Search in sources :

Example 1 with LibraryElements

use of org.gradle.api.attributes.LibraryElements 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

Closure (groovy.lang.Closure)1 File (java.io.File)1 Inject (javax.inject.Inject)1 Action (org.gradle.api.Action)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1 LibraryElements (org.gradle.api.attributes.LibraryElements)1 FileCollection (org.gradle.api.file.FileCollection)1 FileCopyDetails (org.gradle.api.file.FileCopyDetails)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 ConfigurationInternal (org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)1 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)1 SerializableLambdas (org.gradle.api.internal.lambdas.SerializableLambdas)1 DslObject (org.gradle.api.internal.plugins.DslObject)1