Search in sources :

Example 1 with TaskDependencyResolveContext

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

the class CompositeFileCollection method getAsFileTree.

@Override
public FileTree getAsFileTree() {
    return new CompositeFileTree() {

        @Override
        public void visitContents(FileCollectionResolveContext context) {
            ResolvableFileCollectionResolveContext nested = context.newContext();
            CompositeFileCollection.this.visitContents(nested);
            context.add(nested.resolveAsFileTrees());
        }

        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            CompositeFileCollection.this.visitDependencies(context);
        }

        @Override
        public String getDisplayName() {
            return CompositeFileCollection.this.getDisplayName();
        }
    };
}
Also used : ResolvableFileCollectionResolveContext(org.gradle.api.internal.file.collections.ResolvableFileCollectionResolveContext) BuildDependenciesOnlyFileCollectionResolveContext(org.gradle.api.internal.file.collections.BuildDependenciesOnlyFileCollectionResolveContext) FileCollectionResolveContext(org.gradle.api.internal.file.collections.FileCollectionResolveContext) DefaultFileCollectionResolveContext(org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext) ResolvableFileCollectionResolveContext(org.gradle.api.internal.file.collections.ResolvableFileCollectionResolveContext) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext)

Example 2 with TaskDependencyResolveContext

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

the class AbstractFileCollection method getAsFileTree.

public FileTree getAsFileTree() {
    return new CompositeFileTree() {

        @Override
        public void visitContents(FileCollectionResolveContext context) {
            ResolvableFileCollectionResolveContext nested = context.newContext();
            nested.add(AbstractFileCollection.this);
            context.add(nested.resolveAsFileTrees());
        }

        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            context.add(AbstractFileCollection.this);
        }

        @Override
        public String getDisplayName() {
            return AbstractFileCollection.this.getDisplayName();
        }
    };
}
Also used : ResolvableFileCollectionResolveContext(org.gradle.api.internal.file.collections.ResolvableFileCollectionResolveContext) FileCollectionResolveContext(org.gradle.api.internal.file.collections.FileCollectionResolveContext) ResolvableFileCollectionResolveContext(org.gradle.api.internal.file.collections.ResolvableFileCollectionResolveContext) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext)

Example 3 with TaskDependencyResolveContext

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

the class ScalaRuntime method inferScalaClasspath.

/**
     * Searches the specified class path for a 'scala-library' Jar, and returns a class path
     * containing a corresponding (same version) 'scala-compiler' Jar and its dependencies.
     *
     * <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
     *
     * @param classpath a class path containing a 'scala-library' Jar
     * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies
     */
public FileCollection inferScalaClasspath(final Iterable<File> classpath) {
    // would differ in the following ways: 1. live (not sure if we want live here) 2. no autowiring (probably want autowiring here)
    return new LazilyInitializedFileCollection() {

        @Override
        public String getDisplayName() {
            return "Scala runtime classpath";
        }

        @Override
        public FileCollection createDelegate() {
            if (project.getRepositories().isEmpty()) {
                throw new GradleException(String.format("Cannot infer Scala class path because no repository is declared in %s", project));
            }
            File scalaLibraryJar = findScalaJar(classpath, "library");
            if (scalaLibraryJar == null) {
                throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. " + "Does %s declare dependency to scala-library? Searched classpath: %s.", project, classpath));
            }
            String scalaVersion = getScalaVersion(scalaLibraryJar);
            if (scalaVersion == null) {
                throw new AssertionError(String.format("Unexpectedly failed to parse version of Scala Jar file: %s in %s", scalaLibraryJar, project));
            }
            return project.getConfigurations().detachedConfiguration(new DefaultExternalModuleDependency("org.scala-lang", "scala-compiler", scalaVersion));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            if (classpath instanceof Buildable) {
                context.add(classpath);
            }
        }
    };
}
Also used : TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) LazilyInitializedFileCollection(org.gradle.api.internal.file.collections.LazilyInitializedFileCollection) File(java.io.File)

Example 4 with TaskDependencyResolveContext

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

the class GroovyRuntime method inferGroovyClasspath.

/**
     * Searches the specified class path for Groovy Jars ({@code groovy(-indy)}, {@code groovy-all(-indy)}) and returns a corresponding class path for executing Groovy tools such as the Groovy
     * compiler and Groovydoc tool. The tool versions will match those of the Groovy Jars found. If no Groovy Jars are found on the specified class path, a class path with the contents of the {@code
     * groovy} configuration will be returned.
     *
     * <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
     *
     * @param classpath a class path containing Groovy Jars
     * @return a corresponding class path for executing Groovy tools such as the Groovy compiler and Groovydoc tool
     */
public FileCollection inferGroovyClasspath(final Iterable<File> classpath) {
    // would differ in at least the following ways: 1. live 2. no autowiring
    return new LazilyInitializedFileCollection() {

        @Override
        public String getDisplayName() {
            return "Groovy runtime classpath";
        }

        @Override
        public FileCollection createDelegate() {
            GroovyJarFile groovyJar = findGroovyJarFile(classpath);
            if (groovyJar == null) {
                throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", classpath));
            }
            if (groovyJar.isGroovyAll()) {
                return Cast.cast(FileCollectionInternal.class, project.files(groovyJar.getFile()));
            }
            if (project.getRepositories().isEmpty()) {
                throw new GradleException("Cannot infer Groovy class path because no repository is declared for the project.");
            }
            String notation = groovyJar.getDependencyNotation();
            List<Dependency> dependencies = Lists.newArrayList();
            // project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier
            dependencies.add(project.getDependencies().create(notation));
            if (groovyJar.getVersion().getMajor() >= 2) {
                // add groovy-ant to bring in Groovydoc
                dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:")));
            }
            return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[0]));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            if (classpath instanceof Buildable) {
                context.add(classpath);
            }
        }
    };
}
Also used : GroovyJarFile(org.gradle.api.internal.plugins.GroovyJarFile) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) GradleException(org.gradle.api.GradleException) LazilyInitializedFileCollection(org.gradle.api.internal.file.collections.LazilyInitializedFileCollection) Dependency(org.gradle.api.artifacts.Dependency) Buildable(org.gradle.api.Buildable)

Aggregations

TaskDependencyResolveContext (org.gradle.api.internal.tasks.TaskDependencyResolveContext)4 FileCollectionResolveContext (org.gradle.api.internal.file.collections.FileCollectionResolveContext)2 LazilyInitializedFileCollection (org.gradle.api.internal.file.collections.LazilyInitializedFileCollection)2 ResolvableFileCollectionResolveContext (org.gradle.api.internal.file.collections.ResolvableFileCollectionResolveContext)2 File (java.io.File)1 Buildable (org.gradle.api.Buildable)1 GradleException (org.gradle.api.GradleException)1 Dependency (org.gradle.api.artifacts.Dependency)1 DefaultExternalModuleDependency (org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)1 BuildDependenciesOnlyFileCollectionResolveContext (org.gradle.api.internal.file.collections.BuildDependenciesOnlyFileCollectionResolveContext)1 DefaultFileCollectionResolveContext (org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext)1 GroovyJarFile (org.gradle.api.internal.plugins.GroovyJarFile)1