org.gradle.api.internal.file.collections.LazilyInitializedFileCollection Java Examples

The following examples show how to use org.gradle.api.internal.file.collections.LazilyInitializedFileCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScalaRuntime.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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>If the (deprecated) 'scalaTools' configuration is explicitly configured, no repository
 * is declared for the project, no 'scala-library' Jar is found on the specified class path,
 * or its version cannot be determined, a class path with the contents of the 'scalaTools'
 * configuration is 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 a 'scala-library' Jar
 * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies
 */
public FileCollection inferScalaClasspath(final Iterable<File> classpath) {
    // alternatively, we could return project.files(Runnable)
    // 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 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 TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #2
Source File: ScalaRuntime.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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>If the (deprecated) 'scalaTools' configuration is explicitly configured, no repository
 * is declared for the project, no 'scala-library' Jar is found on the specified class path,
 * or its version cannot be determined, a class path with the contents of the 'scalaTools'
 * configuration is 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 a 'scala-library' Jar
 * @return a class path containing a corresponding 'scala-compiler' Jar and its dependencies
 */
public FileCollection inferScalaClasspath(final Iterable<File> classpath) {
    // alternatively, we could return project.files(Runnable)
    // 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 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 TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #3
Source File: GroovyRuntime.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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) {
    // alternatively, we could return project.files(Runnable)
    // would differ in at least the following ways: 1. live 2. no autowiring
    return new LazilyInitializedFileCollection() {
        @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 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[dependencies.size()]));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #4
Source File: GroovyRuntime.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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) {
    final Configuration groovyConfiguration = project.getConfigurations().getByName(GroovyBasePlugin.GROOVY_CONFIGURATION_NAME);
    if (!groovyConfiguration.getDependencies().isEmpty()) {
        return groovyConfiguration;
    }

    // alternatively, we could return project.files(Runnable)
    // would differ in at least the following ways: 1. live 2. no autowiring
    return new LazilyInitializedFileCollection() {
        @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 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 AntGroovyCompiler
                dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:")));
            }
            return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[dependencies.size()]));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #5
Source File: GroovyRuntime.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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) {
    // alternatively, we could return project.files(Runnable)
    // would differ in at least the following ways: 1. live 2. no autowiring
    return new LazilyInitializedFileCollection() {
        @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 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[dependencies.size()]));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}
 
Example #6
Source File: GroovyRuntime.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 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) {
    final Configuration groovyConfiguration = project.getConfigurations().getByName(GroovyBasePlugin.GROOVY_CONFIGURATION_NAME);
    if (!groovyConfiguration.getDependencies().isEmpty()) {
        return groovyConfiguration;
    }

    // alternatively, we could return project.files(Runnable)
    // would differ in at least the following ways: 1. live 2. no autowiring
    return new LazilyInitializedFileCollection() {
        @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 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 AntGroovyCompiler
                dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:")));
            }
            return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[dependencies.size()]));
        }

        // let's override this so that delegate isn't created at autowiring time (which would mean on every build)
        @Override
        public TaskDependency getBuildDependencies() {
            if (classpath instanceof Buildable) {
                return ((Buildable) classpath).getBuildDependencies();
            }
            return new TaskDependency() {
                public Set<? extends Task> getDependencies(Task task) {
                    return Collections.emptySet();
                }
            };
        }
    };
}