Search in sources :

Example 11 with SourceDirectorySet

use of org.gradle.api.file.SourceDirectorySet 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)

Example 12 with SourceDirectorySet

use of org.gradle.api.file.SourceDirectorySet in project gradle-eta by typelead.

the class EtaAndroidPlugin method configureBaseVariant.

private void configureBaseVariant(BaseVariant variant) {
    final EtaOptions etaOptions = createEtaOptions();
    final String variantName = variant.getName();
    final Provider<String> packageName = project.provider(() -> NamingScheme.getPackageName(project, variantName));
    final Provider<String> packageVersion = project.provider(() -> NamingScheme.fixVersion(project.getVersion().toString()));
    project.getLogger().debug("Processing variant " + variantName + " for Eta compilation.");
    final JavaCompile javaCompileTask = variant.getJavaCompile();
    if (javaCompileTask == null) {
        project.getLogger().info("EtaAndroidPlugin: javaCompileTask is missing for " + variantName + " so the Eta compilation tasks will be skipped.");
        return;
    }
    final SourceDirectorySet etaSourceDirectorySet = sourceDirectorySetFactory.create("eta", variantName + " Eta source");
    for (SourceProvider sourceProvider : variant.getSourceSets()) {
        final EtaSourceSet etaSourceSet = ExtensionHelper.getConvention(sourceProvider, EtaSourceSet.class);
        if (etaSourceSet != null) {
            etaSourceDirectorySet.source(etaSourceSet.getEta());
        }
    }
    final EtaResolveDependencies resolveDependenciesTask = (EtaResolveDependencies) project.getRootProject().getTasks().getByPath(EtaBasePlugin.ETA_RESOLVE_DEPENDENCIES_TASK_NAME);
    final FileCollection freezeConfigFile = resolveDependenciesTask.getOutputs().getFiles();
    final Provider<String> targetConfiguration = project.provider(() -> variant.getCompileConfiguration().getName());
    final Provider<Directory> destinationDir = project.getLayout().getBuildDirectory().dir(NamingScheme.getRelativeOutputDir(variant.getDirName()));
    /* Create the install dependencies task. */
    final EtaInstallDependencies installDependenciesTask = project.getTasks().create(NamingScheme.getInstallDependenciesTaskName(variantName), EtaInstallDependencies.class);
    installDependenciesTask.setPackageName(packageName);
    installDependenciesTask.setPackageVersion(packageVersion);
    installDependenciesTask.setTargetConfiguration(targetConfiguration);
    installDependenciesTask.setFreezeConfigFile(freezeConfigFile);
    installDependenciesTask.setFreezeConfigChanged(project.provider(() -> resolveDependenciesTask.getDidWork()));
    installDependenciesTask.setDestinationDir(destinationDir);
    installDependenciesTask.setOptions(etaOptions);
    installDependenciesTask.setSource(etaSourceDirectorySet);
    installDependenciesTask.dependsOn(resolveDependenciesTask);
    installDependenciesTask.setDescription("Installs dependencies for the " + variantName + " Eta source.");
    installDependenciesTask.dependsOnOtherEtaProjects();
    /* Because the installDependenciesTask injects dependencies into the
           configuration, it must run *before* the preBuild phase since every task
           after that will resolve configurations. */
    variant.getPreBuild().dependsOn(installDependenciesTask);
    /* Create the compile task. */
    EtaCompile compileTask = project.getTasks().create(NamingScheme.getCompileTaskName(variantName), EtaCompile.class);
    compileTask.setPackageName(packageName);
    compileTask.setPackageVersion(packageVersion);
    compileTask.setCabalProjectFile(installDependenciesTask.getCabalProjectFileProvider());
    compileTask.setCabalFile(installDependenciesTask.getCabalFileProvider());
    compileTask.setDestinationDir(destinationDir);
    compileTask.setOptions(etaOptions);
    compileTask.setSource(etaSourceDirectorySet);
    compileTask.dependsOn(installDependenciesTask);
    compileTask.setDescription("Compiles the " + variantName + " Eta source.");
    /* Register the Eta output jar file with the Android build system. */
    Object etaClasspathKey = variant.registerPreJavacGeneratedBytecode(project.files(compileTask.getOutputJarFileProvider()).builtBy(compileTask));
    /* Setup the classpath for Eta */
    compileTask.setClasspath(project.provider(() -> variant.getCompileClasspath(etaClasspathKey).plus(project.files(AndroidHelper.getAndroidSDKClasspath(androidExtension)))));
    /* Register the package databases as artifacts that will be collected
           upon dependency resolution of project dependencies. */
    addArtifacts(compileTask.getPackageDBProvider(), variant.getRuntimeConfiguration());
}
Also used : EtaResolveDependencies(com.typelead.gradle.eta.tasks.EtaResolveDependencies) SourceProvider(com.android.builder.model.SourceProvider) FileCollection(org.gradle.api.file.FileCollection) EtaOptions(com.typelead.gradle.eta.api.EtaOptions) EtaInstallDependencies(com.typelead.gradle.eta.tasks.EtaInstallDependencies) EtaSourceSet(com.typelead.gradle.eta.api.EtaSourceSet) DefaultEtaSourceSet(com.typelead.gradle.eta.internal.DefaultEtaSourceSet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) EtaCompile(com.typelead.gradle.eta.tasks.EtaCompile) Directory(org.gradle.api.file.Directory)

Example 13 with SourceDirectorySet

use of org.gradle.api.file.SourceDirectorySet in project gradle-eta by typelead.

the class EtaPlugin method configureSourceSet.

private void configureSourceSet(SourceSet sourceSet) {
    final EtaOptions etaOptions = createEtaOptions();
    final Provider<String> packageName = project.provider(() -> NamingScheme.getPackageName(project, sourceSet.getName()));
    final Provider<String> packageVersion = project.provider(() -> NamingScheme.fixVersion(project.getVersion().toString()));
    final DefaultEtaSourceSet etaSourceSet = project.getObjects().newInstance(DefaultEtaSourceSet.class, sourceSet, "eta", ((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
    ExtensionHelper.createConvention(sourceSet, "eta", etaSourceSet);
    final SourceDirectorySet etaSourceDirectorySet = etaSourceSet.getEta();
    etaSourceDirectorySet.srcDir("src/" + sourceSet.getName() + "/eta");
    /* Ensure that you exclude any Eta source files from the
           resources set. */
    sourceSet.getResources().getFilter().exclude(element -> etaSourceSet.getEta().contains(element.getFile()));
    sourceSet.getAllSource().source(etaSourceDirectorySet);
    final EtaResolveDependencies resolveDependenciesTask = (EtaResolveDependencies) project.getRootProject().getTasks().getByPath(EtaBasePlugin.ETA_RESOLVE_DEPENDENCIES_TASK_NAME);
    final FileCollection freezeConfigFile = resolveDependenciesTask.getOutputs().getFiles();
    final Provider<String> targetConfiguration = project.provider(() -> sourceSet.getCompileClasspathConfigurationName());
    final Provider<Directory> destinationDir = project.getLayout().getBuildDirectory().dir(etaSourceSet.getRelativeOutputDir());
    /* Create the install dependencies task. */
    final EtaInstallDependencies installDependenciesTask = project.getTasks().create(etaSourceSet.getInstallDependenciesTaskName(), EtaInstallDependencies.class);
    installDependenciesTask.setPackageName(packageName);
    installDependenciesTask.setPackageVersion(packageVersion);
    installDependenciesTask.setTargetConfiguration(targetConfiguration);
    installDependenciesTask.setFreezeConfigFile(freezeConfigFile);
    installDependenciesTask.setFreezeConfigChanged(project.provider(() -> resolveDependenciesTask.getDidWork()));
    installDependenciesTask.setDestinationDir(destinationDir);
    installDependenciesTask.setOptions(etaOptions);
    installDependenciesTask.setSource(etaSourceDirectorySet);
    installDependenciesTask.dependsOn(resolveDependenciesTask);
    installDependenciesTask.setDescription("Installs dependencies for the " + sourceSet.getName() + " Eta source.");
    installDependenciesTask.dependsOnOtherEtaProjects();
    final EtaRepl replTask = project.getTasks().create(etaSourceSet.getReplTaskName(), EtaRepl.class);
    replTask.setPackageName(packageName);
    replTask.setDestinationDir(destinationDir);
    replTask.dependsOn(installDependenciesTask);
    /* The install dependencies tasks injects into this configuration so we must
           ensure that it runs before the Java compilation. */
    final AbstractCompile javaCompileTask = (AbstractCompile) project.getTasks().getByName(sourceSet.getCompileJavaTaskName());
    javaCompileTask.dependsOn(installDependenciesTask);
    /* Create the compile task. */
    EtaCompile compileTask = project.getTasks().create(etaSourceSet.getCompileTaskName(), EtaCompile.class);
    Provider<Directory> classesDir = project.provider(() -> {
        final DirectoryProperty buildDir = project.getLayout().getBuildDirectory();
        if (sourceSet.getOutput().isLegacyLayout()) {
            return buildDir.dir(buildDir.getAsFile().get().toPath().relativize(sourceSet.getOutput().getClassesDir().toPath()).toString()).get();
        }
        return buildDir.dir(etaSourceSet.getClassesDir()).get();
    });
    compileTask.setPackageName(packageName);
    compileTask.setPackageVersion(packageVersion);
    compileTask.setClasspath(project.provider(() -> sourceSet.getCompileClasspath()));
    compileTask.setCabalProjectFile(installDependenciesTask.getCabalProjectFileProvider());
    compileTask.setCabalFile(installDependenciesTask.getCabalFileProvider());
    compileTask.setDestinationDir(destinationDir);
    compileTask.addExtraClasspath(javaCompileTask.getDestinationDir());
    compileTask.setClassesDir(classesDir);
    compileTask.setOptions(etaOptions);
    compileTask.setSource(etaSourceDirectorySet);
    compileTask.dependsOn(javaCompileTask);
    compileTask.setDescription("Compiles the " + sourceSet.getName() + " Eta source.");
    /* NOTE: We have commented out the code below since it may be useful later.

           Map<String, Object> builtByOptions = new HashMap<String, Object>();
           builtByOptions.put("builtBy", compileTask);
           sourceSet.getOutput().dir(builtByOptions, classesDir);
        */
    /* Register the Eta classes directory as an output so that the Jar task
           will pick it up nicely. */
    etaSourceDirectorySet.setOutputDir(project.provider(() -> classesDir.get().getAsFile()));
    ((DefaultSourceSetOutput) sourceSet.getOutput()).addClassesDir(() -> etaSourceDirectorySet.getOutputDir());
    project.getTasks().findByName(sourceSet.getClassesTaskName()).dependsOn(compileTask);
    /* Register the package databases as artifacts that will be collected
           upon dependency resolution of project dependencies. */
    addArtifacts(compileTask.getPackageDBProvider(), sourceSet.getApiElementsConfigurationName(), sourceSet.getRuntimeConfigurationName(), sourceSet.getRuntimeElementsConfigurationName());
}
Also used : EtaResolveDependencies(com.typelead.gradle.eta.tasks.EtaResolveDependencies) FileCollection(org.gradle.api.file.FileCollection) DefaultEtaSourceSet(com.typelead.gradle.eta.internal.DefaultEtaSourceSet) EtaOptions(com.typelead.gradle.eta.api.EtaOptions) AbstractCompile(org.gradle.api.tasks.compile.AbstractCompile) DirectoryProperty(org.gradle.api.file.DirectoryProperty) EtaInstallDependencies(com.typelead.gradle.eta.tasks.EtaInstallDependencies) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) EtaRepl(com.typelead.gradle.eta.tasks.EtaRepl) EtaCompile(com.typelead.gradle.eta.tasks.EtaCompile) Directory(org.gradle.api.file.Directory)

Aggregations

SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)13 SourceSet (org.gradle.api.tasks.SourceSet)6 File (java.io.File)5 Inject (javax.inject.Inject)4 Plugin (org.gradle.api.Plugin)4 FileCollection (org.gradle.api.file.FileCollection)4 GroovySourceDirectorySet (org.gradle.api.tasks.GroovySourceDirectorySet)4 Project (org.gradle.api.Project)3 Configuration (org.gradle.api.artifacts.Configuration)3 DirectoryProperty (org.gradle.api.file.DirectoryProperty)3 TaskProvider (org.gradle.api.tasks.TaskProvider)3 EtaOptions (com.typelead.gradle.eta.api.EtaOptions)2 DefaultEtaSourceSet (com.typelead.gradle.eta.internal.DefaultEtaSourceSet)2 EtaCompile (com.typelead.gradle.eta.tasks.EtaCompile)2 EtaInstallDependencies (com.typelead.gradle.eta.tasks.EtaInstallDependencies)2 EtaResolveDependencies (com.typelead.gradle.eta.tasks.EtaResolveDependencies)2 Action (org.gradle.api.Action)2 Task (org.gradle.api.Task)2 LibraryElements (org.gradle.api.attributes.LibraryElements)2 Directory (org.gradle.api.file.Directory)2