Search in sources :

Example 1 with DefaultSourceSetOutput

use of org.gradle.api.internal.tasks.DefaultSourceSetOutput in project gradle by gradle.

the class DefaultJvmLanguageGeneratedSourceDirectoryBuilder method build.

void build() {
    if (taskBuilder == null) {
        throw new IllegalStateException("You must specify how sources will be compiled either by calling compiledWithJava or compiledBy");
    }
    if (mapping == null) {
        throw new IllegalStateException("You must specify the mapping function from your source generating task to a directory property");
    }
    if (sourceTaskProvider == null) {
        throw new IllegalStateException("You must specify the source generation task");
    }
    Provider<Directory> sourceDirectory = sourceTaskProvider.flatMap(task -> mapping.apply(Cast.uncheckedCast(task)));
    DefaultCompileTaskDetails details = createTaskDetails(project.getObjects().directoryProperty().convention(sourceDirectory));
    DefaultSourceSetOutput sourceSetOutput = Cast.cast(DefaultSourceSetOutput.class, sourceSet.getOutput());
    sourceSetOutput.addClassesDir(details.compileTask.flatMap(task -> details.compileMapping.apply(Cast.uncheckedCast(task))));
    sourceSetOutput.registerClassesContributor(details.compileTask);
    sourceSetOutput.getGeneratedSourcesDirs().from(sourceDirectory);
    project.getTasks().matching(DefaultJvmLanguageGeneratedSourceDirectoryBuilder::isClassesTask).configureEach(classes -> classes.dependsOn(details.compileTask));
    if (includeInAllJava) {
        sourceSet.getAllJava().srcDir(sourceDirectory);
    }
    sourceSet.getAllSource().srcDir(sourceDirectory);
}
Also used : JavaCompile(org.gradle.api.tasks.compile.JavaCompile) StringUtils(org.apache.commons.lang.StringUtils) Action(org.gradle.api.Action) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Cast(org.gradle.internal.Cast) Function(java.util.function.Function) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Directory(org.gradle.api.file.Directory) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) Directory(org.gradle.api.file.Directory)

Example 2 with DefaultSourceSetOutput

use of org.gradle.api.internal.tasks.DefaultSourceSetOutput in project gradle by gradle.

the class JvmPluginsHelper method configureOutputDirectoryForSourceSet.

public static <T extends Task> void configureOutputDirectoryForSourceSet(final SourceSet sourceSet, final SourceDirectorySet sourceDirectorySet, final Project target, TaskProvider<T> compileTask, Provider<CompileOptions> options, Function<T, DirectoryProperty> classesDirectoryExtractor) {
    final String sourceSetChildPath = "classes/" + sourceDirectorySet.getName() + "/" + sourceSet.getName();
    sourceDirectorySet.getDestinationDirectory().convention(target.getLayout().getBuildDirectory().dir(sourceSetChildPath));
    DefaultSourceSetOutput sourceSetOutput = Cast.cast(DefaultSourceSetOutput.class, sourceSet.getOutput());
    sourceSetOutput.addClassesDir(sourceDirectorySet.getDestinationDirectory());
    sourceSetOutput.registerClassesContributor(compileTask);
    sourceSetOutput.getGeneratedSourcesDirs().from(options.flatMap(CompileOptions::getGeneratedSourceOutputDirectory));
    sourceDirectorySet.compiledBy(compileTask, classesDirectoryExtractor);
}
Also used : DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput)

Example 3 with DefaultSourceSetOutput

use of org.gradle.api.internal.tasks.DefaultSourceSetOutput in project gradle-eta by typelead.

the class EtaPlugin method configureSourceSet.

private void configureSourceSet(SourceSet sourceSet) {
    final EtaOptions etaOptions = createEtaOptions();
    final DefaultEtaSourceSet etaSourceSet = ExtensionHelper.createExtension(sourceSet, "eta", DefaultEtaSourceSet.class, sourceSet, sourceDirectorySetFactory);
    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.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();
    /* 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.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.");
    /* Register the Eta classes directory as an output so that the Jar task
           will pick it up nicely. */
    Map<String, Object> builtByOptions = new HashMap<String, Object>();
    builtByOptions.put("builtBy", compileTask);
    etaSourceDirectorySet.setOutputDir(project.provider(() -> classesDir.get().getAsFile()));
    /* TODO: Are both classesDir and the output registration below required? */
    ((DefaultSourceSetOutput) sourceSet.getOutput()).addClassesDir(() -> etaSourceDirectorySet.getOutputDir());
    sourceSet.getOutput().dir(builtByOptions, classesDir);
    /* 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 : HashMap(java.util.HashMap) 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) EtaCompile(com.typelead.gradle.eta.tasks.EtaCompile) Directory(org.gradle.api.file.Directory)

Example 4 with DefaultSourceSetOutput

use of org.gradle.api.internal.tasks.DefaultSourceSetOutput in project gradle by gradle.

the class SourceSetUtil method configureOutputDirectoryForSourceSet.

public static void configureOutputDirectoryForSourceSet(final SourceSet sourceSet, final SourceDirectorySet sourceDirectorySet, AbstractCompile compile, final Project target) {
    final String sourceSetChildPath = "classes/" + sourceDirectorySet.getName() + "/" + sourceSet.getName();
    sourceDirectorySet.setOutputDir(target.provider(new Callable<File>() {

        @Override
        public File call() throws Exception {
            if (sourceSet.getOutput().isLegacyLayout()) {
                return sourceSet.getOutput().getClassesDir();
            }
            return new File(target.getBuildDir(), sourceSetChildPath);
        }
    }));
    DefaultSourceSetOutput sourceSetOutput = Cast.cast(DefaultSourceSetOutput.class, sourceSet.getOutput());
    sourceSetOutput.addClassesDir(new Callable<File>() {

        @Override
        public File call() throws Exception {
            return sourceDirectorySet.getOutputDir();
        }
    });
    compile.setDestinationDir(target.provider(new Callable<File>() {

        @Override
        public File call() throws Exception {
            return sourceDirectorySet.getOutputDir();
        }
    }));
}
Also used : DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) File(java.io.File) Callable(java.util.concurrent.Callable)

Example 5 with DefaultSourceSetOutput

use of org.gradle.api.internal.tasks.DefaultSourceSetOutput in project webpieces by deanhiller.

the class TemplateCompilerPlugin method configureOutputDirectoryForSourceSet.

public static void configureOutputDirectoryForSourceSet(final SourceSet sourceSet, final SourceDirectorySet sourceDirectorySet, final Project target) {
    final String sourceSetChildPath = "classes/" + sourceDirectorySet.getName() + "/" + sourceSet.getName();
    sourceDirectorySet.setOutputDir(target.provider(() -> new File(target.getBuildDir(), sourceSetChildPath)));
    DefaultSourceSetOutput sourceSetOutput = Cast.cast(DefaultSourceSetOutput.class, sourceSet.getOutput());
    sourceSetOutput.addClassesDir(sourceDirectorySet.getClassesDirectory());
}
Also used : DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) File(java.io.File)

Aggregations

DefaultSourceSetOutput (org.gradle.api.internal.tasks.DefaultSourceSetOutput)6 File (java.io.File)3 Directory (org.gradle.api.file.Directory)2 DirectoryProperty (org.gradle.api.file.DirectoryProperty)2 SourceSet (org.gradle.api.tasks.SourceSet)2 ImmutableList (com.google.common.collect.ImmutableList)1 EtaOptions (com.typelead.gradle.eta.api.EtaOptions)1 DefaultEtaSourceSet (com.typelead.gradle.eta.internal.DefaultEtaSourceSet)1 EtaCompile (com.typelead.gradle.eta.tasks.EtaCompile)1 EtaInstallDependencies (com.typelead.gradle.eta.tasks.EtaInstallDependencies)1 EtaResolveDependencies (com.typelead.gradle.eta.tasks.EtaResolveDependencies)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Function (java.util.function.Function)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang.StringUtils)1