Search in sources :

Example 11 with TaskDependency

use of org.gradle.api.tasks.TaskDependency 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

TaskDependency (org.gradle.api.tasks.TaskDependency)11 Task (org.gradle.api.Task)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Expectations (org.jmock.Expectations)3 List (java.util.List)2 Set (java.util.Set)2 Buildable (org.gradle.api.Buildable)2 Project (org.gradle.api.Project)2 EclipseWorkspaceProject (org.gradle.tooling.model.eclipse.EclipseWorkspaceProject)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Closure (groovy.lang.Closure)1 Path (java.nio.file.Path)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 RandomAccess (java.util.RandomAccess)1 Callable (java.util.concurrent.Callable)1 Nullable (javax.annotation.Nullable)1