Search in sources :

Example 6 with DefaultSourceSetOutput

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

the class DefaultJvmPluginServices method registerClassesDirVariant.

private void registerClassesDirVariant(final SourceSet sourceSet, Configuration configuration) {
    // Define a classes variant to use for compilation
    ConfigurationPublications publications = configuration.getOutgoing();
    ConfigurationVariantInternal variant = (ConfigurationVariantInternal) publications.getVariants().maybeCreate("classes");
    variant.setDescription("Directories containing compiled class files for " + sourceSet.getName() + ".");
    variant.getAttributes().attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.class, LibraryElements.CLASSES));
    variant.artifactsProvider(new Factory<List<PublishArtifact>>() {

        @Nullable
        @Override
        public List<PublishArtifact> create() {
            Set<File> classesDirs = sourceSet.getOutput().getClassesDirs().getFiles();
            DefaultSourceSetOutput output = Cast.uncheckedCast(sourceSet.getOutput());
            TaskDependency classesContributors = output.getClassesContributors();
            ImmutableList.Builder<PublishArtifact> artifacts = ImmutableList.builderWithExpectedSize(classesDirs.size());
            for (File classesDir : classesDirs) {
                // this is an approximation: all "compiled" sources will use the same task dependency
                artifacts.add(new JvmPluginsHelper.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, classesContributors) {

                    @Override
                    public File getFile() {
                        return classesDir;
                    }
                });
            }
            return artifacts.build();
        }
    });
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Set(java.util.Set) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) ConfigurationVariantInternal(org.gradle.api.internal.artifacts.ConfigurationVariantInternal) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) LibraryElements(org.gradle.api.attributes.LibraryElements) File(java.io.File) Nullable(javax.annotation.Nullable)

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