Java 类org.gradle.api.plugins.GroovyBasePlugin 实例源码

项目:spotless    文件:GroovyExtension.java   
/** If the user hasn't specified the files yet, we'll assume he/she means all of the groovy files. */
@Override
protected void setupTask(SpotlessTask task) {
    if (target == null) {
        JavaPluginConvention convention = getProject().getConvention().getPlugin(JavaPluginConvention.class);
        if (convention == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) {
            throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension.");
        }
        //Add all Groovy files (may contain Java files as well)

        FileCollection union = getProject().files();
        for (SourceSet sourceSet : convention.getSourceSets()) {
            GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
            if (excludeJava) {
                union = union.plus(groovySourceSet.getAllGroovy());
            } else {
                union = union.plus(groovySourceSet.getGroovy());
            }
        }
        target = union;
    } else if (excludeJava) {
        throw new IllegalArgumentException("'excludeJava' is not supported in combination with a custom 'target'.");
    }
    // LicenseHeaderStep completely blows apart package-info.java/groovy - this common-sense check
    // ensures that it skips both. See https://github.com/diffplug/spotless/issues/1
    steps.replaceAll(step -> {
        if (LicenseHeaderStep.name().equals(step.getName())) {
            return step.filterByFile(SerializableFileFilter.skipFilesNamed("package-info.java", "package-info.groovy"));
        } else {
            return step;
        }
    });
    super.setupTask(task);
}
项目:Reer    文件:CodeNarcPlugin.java   
@Override
protected Class<? extends Plugin> getBasePlugin() {
    return GroovyBasePlugin.class;
}
项目:Pushjet-Android    文件:GroovyRuntime.java   
/**
 * 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();
                }
            };
        }
    };
}