Java 类org.gradle.api.tasks.SourceSet 实例源码

项目:Reer    文件:FindBugsPlugin.java   
@Override
protected void configureForSourceSet(final SourceSet sourceSet, FindBugs task) {
    task.setDescription("Run FindBugs analysis for " + sourceSet.getName() + " classes");
    task.setSource(sourceSet.getAllJava());
    ConventionMapping taskMapping = task.getConventionMapping();
    taskMapping.map("classes", new Callable<FileCollection>() {
        @Override
        public FileCollection call() {
            // the simple "classes = sourceSet.output" may lead to non-existing resources directory
            // being passed to FindBugs Ant task, resulting in an error
            return project.fileTree(sourceSet.getOutput().getClassesDir()).builtBy(sourceSet.getOutput());
        }
    });
    taskMapping.map("classpath", new Callable<FileCollection>() {
        @Override
        public FileCollection call() {
            return sourceSet.getCompileClasspath();
        }
    });
}
项目:Reer    文件:SourceFoldersCreator.java   
/**
 * see {@link #getRegularSourceFolders}
 *
 * @return source folders that live outside of the project
 */
public List<SourceFolder> getExternalSourceFolders(Iterable<SourceSet> sourceSets, Function<File, String> provideRelativePath) {
    List<SourceFolder> sourceFolders = projectRelativeFolders(sourceSets, provideRelativePath);
    List<SourceFolder> externalSourceFolders = CollectionUtils.filter(sourceFolders, new Spec<SourceFolder>() {
        @Override
        public boolean isSatisfiedBy(SourceFolder element) {
            return element.getPath().contains("..");
        }
    });
    List<SourceFolder> regularSourceFolders = getRegularSourceFolders(sourceSets, provideRelativePath);
    List<String> sources = Lists.newArrayList(Lists.transform(regularSourceFolders, new Function<SourceFolder, String>() {
        @Override
        public String apply(SourceFolder sourceFolder) {
            return sourceFolder.getName();
        }
    }));
    return trimAndDedup(externalSourceFolders, sources);
}
项目:Reer    文件:SourceFoldersCreator.java   
private List<SourceFolder> projectRelativeFolders(Iterable<SourceSet> sourceSets, Function<File, String> provideRelativePath) {
    ArrayList<SourceFolder> entries = Lists.newArrayList();
    List<SourceSet> sortedSourceSets = sortSourceSetsAsPerUsualConvention(sourceSets);
    for (SourceSet sourceSet : sortedSourceSets) {
        List<DirectoryTree> sortedSourceDirs = sortSourceDirsAsPerUsualConvention(sourceSet.getAllSource().getSrcDirTrees());
        for (DirectoryTree tree : sortedSourceDirs) {
            File dir = tree.getDir();
            if (dir.isDirectory()) {
                String relativePath = provideRelativePath.apply(dir);
                SourceFolder folder = new SourceFolder(relativePath, null);
                folder.setDir(dir);
                folder.setName(dir.getName());
                folder.setIncludes(getIncludesForTree(sourceSet, tree));
                folder.setExcludes(getExcludesForTree(sourceSet, tree));
                entries.add(folder);
            }
        }
    }
    return entries;
}
项目:Reer    文件:JavaPlugin.java   
private void configureSourceSets(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();

    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);

    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CONFIGURATION_NAME)));
}
项目:Reer    文件:GroovyBasePlugin.java   
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        public void execute(SourceSet sourceSet) {
            final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
            new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet);

            groovySourceSet.getGroovy().srcDir("src/" + sourceSet.getName() + "/groovy");
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return groovySourceSet.getGroovy().contains(element.getFile());
                }
            });
            sourceSet.getAllJava().source(groovySourceSet.getGroovy());
            sourceSet.getAllSource().source(groovySourceSet.getGroovy());

            String compileTaskName = sourceSet.getCompileTaskName("groovy");
            GroovyCompile compile = project.getTasks().create(compileTaskName, GroovyCompile.class);
            javaBasePlugin.configureForSourceSet(sourceSet, compile);
            compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription("Compiles the " + sourceSet.getName() + " Groovy source.");
            compile.setSource(groovySourceSet.getGroovy());

            project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
        }
    });
}
项目:Reer    文件:ApplicationPlugin.java   
private void addRunTask() {
    JavaExec run = project.getTasks().create(TASK_RUN_NAME, JavaExec.class);
    run.setDescription("Runs this project as a JVM application");
    run.setGroup(APPLICATION_GROUP);

    JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    run.setClasspath(javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
    run.getConventionMapping().map("main", new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            return pluginConvention.getMainClassName();
        }
    });
    run.getConventionMapping().map("jvmArgs", new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            return pluginConvention.getApplicationDefaultJvmArgs();
        }
    });
}
项目:Reer    文件:JavaBasePlugin.java   
private void createCompileJavaTaskForBinary(final SourceSet sourceSet, SourceDirectorySet javaSourceSet, Project target) {
    JavaCompile compileTask = target.getTasks().create(sourceSet.getCompileJavaTaskName(), JavaCompile.class);
    compileTask.setDescription("Compiles " + javaSourceSet + ".");
    compileTask.setSource(javaSourceSet);
    ConventionMapping conventionMapping = compileTask.getConventionMapping();
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
项目:Reer    文件:JavaBasePlugin.java   
private void defineConfigurationsForSourceSet(SourceSet sourceSet, ConfigurationContainer configurations) {
    Configuration compileConfiguration = configurations.maybeCreate(sourceSet.getCompileConfigurationName());
    compileConfiguration.setVisible(false);
    compileConfiguration.setDescription("Dependencies for " + sourceSet + ".");

    Configuration runtimeConfiguration = configurations.maybeCreate(sourceSet.getRuntimeConfigurationName());
    runtimeConfiguration.setVisible(false);
    runtimeConfiguration.extendsFrom(compileConfiguration);
    runtimeConfiguration.setDescription("Runtime dependencies for " + sourceSet + ".");

    Configuration compileOnlyConfiguration = configurations.maybeCreate(sourceSet.getCompileOnlyConfigurationName());
    compileOnlyConfiguration.setVisible(false);
    compileOnlyConfiguration.extendsFrom(compileConfiguration);
    compileOnlyConfiguration.setDescription("Compile dependencies for " + sourceSet + ".");

    Configuration compileClasspathConfiguration = configurations.maybeCreate(sourceSet.getCompileClasspathConfigurationName());
    compileClasspathConfiguration.setVisible(false);
    compileClasspathConfiguration.extendsFrom(compileOnlyConfiguration);
    compileClasspathConfiguration.setDescription("Compile classpath for " + sourceSet + ".");

    sourceSet.setCompileClasspath(compileClasspathConfiguration);
    sourceSet.setRuntimeClasspath(sourceSet.getOutput().plus(runtimeConfiguration));
}
项目:Reer    文件:JavaBasePlugin.java   
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
    ConventionMapping conventionMapping;
    compile.setDescription("Compiles the " + sourceSet.getJava() + ".");
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
项目:gradle-clojure    文件:ClojurePlugin.java   
private void configureDev(Project project, JavaPluginConvention javaConvention) {
  SourceSet main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
  SourceSet test = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
  SourceSet dev = javaConvention.getSourceSets().create(DEV_SOURCE_SET_NAME);
  dev.setCompileClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(dev.getCompileClasspathConfigurationName())));
  dev.setRuntimeClasspath(project.files(dev.getAllSource().getSourceDirectories(), test.getAllSource().getSourceDirectories(), main.getAllSource().getSourceDirectories(), project.getConfigurations().getByName(dev.getRuntimeClasspathConfigurationName())));

  Stream.<Function<SourceSet, String>>of(SourceSet::getCompileConfigurationName, SourceSet::getImplementationConfigurationName, SourceSet::getRuntimeConfigurationName, SourceSet::getRuntimeOnlyConfigurationName).forEach(getter -> {
    Configuration devConf = project.getConfigurations().getByName(getter.apply(dev));
    Configuration testConf = project.getConfigurations().getByName(getter.apply(test));
    devConf.extendsFrom(testConf);
  });

  project.getTasks().create("clojureRepl", ClojureNRepl.class, task -> {
    task.setGroup("run");
    task.setDescription("Starts an nREPL server.");
    task.setClasspath(dev.getRuntimeClasspath());
  });
}
项目:gradle-java-modules    文件:JigsawPlugin.java   
private void configureCompileTestJavaTask(final Project project) {
    final JavaCompile compileTestJava = (JavaCompile) project.getTasks()
            .findByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    compileTestJava.getInputs().property("moduleName", module.geName());
    compileTestJava.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(compileTestJava.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("junit");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getSourceDirectories().getAsPath());
            compileTestJava.getOptions().setCompilerArgs(args);
            compileTestJava.setClasspath(project.files());
        }
    });
}
项目:gradle-java-modules    文件:JigsawPlugin.java   
private void configureTestTask(final Project project) {
    final Test testTask = (Test) project.getTasks().findByName(JavaPlugin.TEST_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    testTask.getInputs().property("moduleName", module.geName());
    testTask.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(testTask.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("ALL-MODULE-PATH");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getOutputDir());
            testTask.setJvmArgs(args);
            testTask.setClasspath(project.files());
        }
    });
}
项目:gradle-project-config    文件:MavenConfigPlugin.java   
/**
 * Initialize the Maven configuration
 *
 * @param mavenConfig Maven configuration to initialize
 * @param projectContext Project context
 * @param configurations Configuration container
 */
@Defaults
public void initializeMavenConfig(MavenConfig mavenConfig, ProjectContext projectContext,
        ConfigurationContainer configurations) {
    mavenConfig.getPublications().create(SourceSet.MAIN_SOURCE_SET_NAME, p -> {
        p.setArtifactId(projectContext.getName());
        p.setArchivesConfiguration(Dependency.ARCHIVES_CONFIGURATION);
        p.setAddProjectArtifacts(false);
        p.setCompileConfigurations(Collections.singletonList(JavaPlugin.COMPILE_CONFIGURATION_NAME));
        p.setRuntimeConfigurations(Collections.singletonList(JavaPlugin.RUNTIME_CONFIGURATION_NAME));
    });

    if (configurations.findByName("testArchives") != null) {
        mavenConfig.getPublications().create(SourceSet.TEST_SOURCE_SET_NAME, p -> {
            p.setArtifactId(projectContext.getName() + "-" + SourceSet.TEST_SOURCE_SET_NAME);
            p.setArchivesConfiguration(Names.formatName("", Dependency.ARCHIVES_CONFIGURATION,
                    SourceSet.TEST_SOURCE_SET_NAME));
            p.setAddProjectArtifacts(true);
            p.setCompileConfigurations(
                    Collections.singletonList(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME));
            p.setRuntimeConfigurations(
                    Collections.singletonList(JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME));
        });
    }
}
项目:gradle-project-config    文件:MavenConfigPlugin.java   
/**
 * Initialize the Maven configuration
 *
 * @param mavenConfig Maven configuration to initialize
 * @param projectContext Project context
 */
@Defaults
public void initializeMavenConfig(MavenConfig mavenConfig, ProjectContext projectContext) {
    mavenConfig.getPublications().create(SourceSet.MAIN_SOURCE_SET_NAME, p -> {
        p.setArtifactId(projectContext.getName());
        p.setArchivesConfiguration(Dependency.ARCHIVES_CONFIGURATION);
        p.setAddProjectArtifacts(false);
        p.setCompileConfigurations(Collections.singletonList(JavaPlugin.COMPILE_CONFIGURATION_NAME));
        p.setRuntimeConfigurations(Collections.singletonList(JavaPlugin.RUNTIME_CONFIGURATION_NAME));
    });

    mavenConfig.getPublications().create(SourceSet.TEST_SOURCE_SET_NAME, p -> {
        p.setArtifactId(projectContext.getName() + "-" + SourceSet.TEST_SOURCE_SET_NAME);
        p.setArchivesConfiguration(
                Names.formatName("", Dependency.ARCHIVES_CONFIGURATION, SourceSet.TEST_SOURCE_SET_NAME));
        p.setAddProjectArtifacts(true);
        p.setCompileConfigurations(Collections.singletonList(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME));
        p.setRuntimeConfigurations(Collections.singletonList(JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME));
    });
}
项目:gradle-project-config    文件:Names.java   
/**
 * Create a name derived from a source set
 *
 * @param prefix Name prefix
 * @param suffix Name suffix
 * @param name Source set name
 * @return Derived name
 */
public static String formatName(String prefix, String suffix, String name) {
    StringBuilder result = new StringBuilder();

    result.append(prefix);

    if (!name.equalsIgnoreCase(SourceSet.MAIN_SOURCE_SET_NAME)) {
        if (result.length() > 0) {
            result.append(NAME_FORMATTER.convert(name));
        }
        else {
            result.append(name);
        }
    }

    if (result.length() > 0) {
        result.append(NAME_FORMATTER.convert(suffix));
    }
    else {
        result.append(suffix);
    }

    return result.toString();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RunPluginFeatures.java   
private void mainClassNameFinder(Project project) {
    FindMainClassTask findMainClassTask = project.getTasks()
            .create(FIND_MAIN_CLASS_TASK_NAME, FindMainClassTask.class);
    SourceSet mainSourceSet = SourceSets.findMainSourceSet(project);
    if (mainSourceSet != null) {
        findMainClassTask.setMainClassSourceSetOutput(mainSourceSet.getOutput());
    }
    project.getTasks().all(new Action<Task>() {
        @Override
        public void execute(Task task) {
            if (task instanceof BootRunTask || task instanceof CreateStartScripts) {
                task.dependsOn(FIND_MAIN_CLASS_TASK_NAME);
            }
        }
    });
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:BootRunTask.java   
private void addResourcesIfNecessary() {
    if (this.addResources) {
        SourceSet mainSourceSet = SourceSets.findMainSourceSet(getProject());
        final File outputDir = (mainSourceSet == null ? null
                : mainSourceSet.getOutput().getResourcesDir());
        final Set<File> resources = new LinkedHashSet<File>();
        if (mainSourceSet != null) {
            resources.addAll(mainSourceSet.getResources().getSrcDirs());
        }
        List<File> classPath = new ArrayList<File>(getClasspath().getFiles());
        classPath.addAll(0, resources);
        getLogger().info("Adding classpath: " + resources);
        setClasspath(new SimpleFileCollection(classPath));
        if (outputDir != null) {
            for (File directory : resources) {
                FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory);
            }
        }
    }
}
项目:parsec    文件:ParsecGradlePlugin.java   
@Override
public void apply(Project project) {
    ParsecPluginExtension pluginExtension = project.getExtensions().create("parsec", ParsecPluginExtension.class);
    PathUtils pathUtils = new PathUtils(project, pluginExtension);
    TaskContainer tasks = project.getTasks();

    // Create tasks (when applied as a plugin)
    ParsecInitTask initTask = tasks.create("parsec-init", ParsecInitTask.class);
    ParsecGenerateTask generateTask = tasks.create("parsec-generate", ParsecGenerateTask.class);

    // Make generate trigger init.
    generateTask.dependsOn(initTask);

    project.getPlugins().withType(JavaPlugin.class, plugin -> {
        SourceSet sourceSet = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("main");

        // Add ${buildDir}/generated-sources/java to sources
        sourceSet.getJava().srcDir(pathUtils.getGeneratedSourcesPath());

        // Add ${buildDir}/generated-resources/parsec to resources
        sourceSet.getResources().srcDir(pathUtils.getGeneratedResourcesPath());

        // Make compileJava trigger generate
        tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).dependsOn(generateTask);
    });
}
项目:spring-boot-concourse    文件:RunPluginFeatures.java   
private void mainClassNameFinder(Project project) {
    FindMainClassTask findMainClassTask = project.getTasks()
            .create(FIND_MAIN_CLASS_TASK_NAME, FindMainClassTask.class);
    SourceSet mainSourceSet = SourceSets.findMainSourceSet(project);
    if (mainSourceSet != null) {
        findMainClassTask.setMainClassSourceSetOutput(mainSourceSet.getOutput());
    }
    project.getTasks().all(new Action<Task>() {
        @Override
        public void execute(Task task) {
            if (task instanceof BootRunTask || task instanceof CreateStartScripts) {
                task.dependsOn(FIND_MAIN_CLASS_TASK_NAME);
            }
        }
    });
}
项目:spring-boot-concourse    文件:BootRunTask.java   
private void addResourcesIfNecessary() {
    if (this.addResources) {
        SourceSet mainSourceSet = SourceSets.findMainSourceSet(getProject());
        final File outputDir = (mainSourceSet == null ? null
                : mainSourceSet.getOutput().getResourcesDir());
        final Set<File> resources = new LinkedHashSet<File>();
        if (mainSourceSet != null) {
            resources.addAll(mainSourceSet.getResources().getSrcDirs());
        }
        List<File> classPath = new ArrayList<File>(getClasspath().getFiles());
        classPath.addAll(0, resources);
        getLogger().info("Adding classpath: " + resources);
        setClasspath(new SimpleFileCollection(classPath));
        if (outputDir != null) {
            for (File directory : resources) {
                FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory);
            }
        }
    }
}
项目:intellij-ce-playground    文件:DefaultAndroidSourceSet.java   
@Override
@NonNull
public String getPackageConfigurationName() {
    if (isLibrary) {
        if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
            return "publish";
        } else {
            return String.format("%sPublish", name);
        }
    }

    if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
        return "apk";
    } else {
        return String.format("%sApk", name);
    }
}
项目:contestparser    文件:RunPluginFeatures.java   
private void mainClassNameFinder(Project project) {
    FindMainClassTask findMainClassTask = project.getTasks()
            .create(FIND_MAIN_CLASS_TASK_NAME, FindMainClassTask.class);
    SourceSet mainSourceSet = SourceSets.findMainSourceSet(project);
    if (mainSourceSet != null) {
        findMainClassTask.setMainClassSourceSetOutput(mainSourceSet.getOutput());
    }
    project.getTasks().all(new Action<Task>() {
        @Override
        public void execute(Task task) {
            if (task instanceof JavaExec || task instanceof CreateStartScripts) {
                task.dependsOn(FIND_MAIN_CLASS_TASK_NAME);
            }
        }
    });
}
项目:contestparser    文件:BootRunTask.java   
private void addResourcesIfNecessary() {
    if (this.addResources) {
        SourceSet mainSourceSet = SourceSets.findMainSourceSet(getProject());
        final File outputDir = (mainSourceSet == null ? null
                : mainSourceSet.getOutput().getResourcesDir());
        final Set<File> resources = new LinkedHashSet<File>();
        if (mainSourceSet != null) {
            resources.addAll(mainSourceSet.getResources().getSrcDirs());
        }
        List<File> classPath = new ArrayList<File>(getClasspath().getFiles());
        classPath.addAll(0, resources);
        getLogger().info("Adding classpath: " + resources);
        setClasspath(new SimpleFileCollection(classPath));
        if (outputDir != null) {
            for (File directory : resources) {
                FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory);
            }
        }
    }
}
项目:jsweet-gradle-plugin    文件:JSweetPlugin.java   
@Override
public void apply(final Project project) {
    Logger logger = project.getLogger();
    logger.info("applying jsweet plugin");

    if (!project.getPlugins().hasPlugin(JavaPlugin.class) && !project.getPlugins().hasPlugin(WarPlugin.class)) {
        logger.error("No java or war plugin detected. Enable java or war plugin.");
        throw new IllegalStateException("No java or war plugin detected. Enable java or war plugin.");
    }

    JSweetPluginExtension extension = project.getExtensions().create("jsweet", JSweetPluginExtension.class);

    JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    SourceSetContainer sourceSets = javaPluginConvention.getSourceSets();
    SourceSet mainSources = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);

    JSweetTranspileTask task = project.getTasks().create("jsweet", JSweetTranspileTask.class);
    task.setGroup("generate");
    task.dependsOn(JavaPlugin.COMPILE_JAVA_TASK_NAME);
    task.setConfiguration(extension);
    task.setSources(mainSources.getAllJava());
    task.setClasspath(mainSources.getCompileClasspath());

    JSweetCleanTask cleanTask = project.getTasks().create("jsweetClean", JSweetCleanTask.class);
    cleanTask.setConfiguration(extension);
}
项目:putnami-gradle-plugin    文件:CodeServerBuilder.java   
private Collection<File> listProjectDepsSrcDirs(Project project) {
    ConfigurationContainer configs = project.getConfigurations();
    Configuration compileConf = configs.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
    DependencySet depSet = compileConf.getAllDependencies();

    List<File> result = Lists.newArrayList();
    for (Dependency dep : depSet) {
        if (dep instanceof ProjectDependency) {
            Project projectDependency = ((ProjectDependency) dep).getDependencyProject();
            if (projectDependency.getPlugins().hasPlugin(PwtLibPlugin.class)) {
                JavaPluginConvention javaConvention = projectDependency.getConvention().getPlugin(JavaPluginConvention.class);
                SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);

                result.addAll(mainSourceSet.getAllSource().getSrcDirs());
            }
        }
    }
    return result;
}
项目:Pushjet-Android    文件:GroovyBasePlugin.java   
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        public void execute(SourceSet sourceSet) {
            final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver);
            new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet);

            groovySourceSet.getGroovy().srcDir(String.format("src/%s/groovy", sourceSet.getName()));
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return groovySourceSet.getGroovy().contains(element.getFile());
                }
            });
            sourceSet.getAllJava().source(groovySourceSet.getGroovy());
            sourceSet.getAllSource().source(groovySourceSet.getGroovy());

            String compileTaskName = sourceSet.getCompileTaskName("groovy");
            GroovyCompile compile = project.getTasks().create(compileTaskName, GroovyCompile.class);
            javaBasePlugin.configureForSourceSet(sourceSet, compile);
            compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription(String.format("Compiles the %s Groovy source.", sourceSet.getName()));
            compile.setSource(groovySourceSet.getGroovy());

            project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
        }
    });
}
项目:Pushjet-Android    文件:JavaBasePlugin.java   
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
    ConventionMapping conventionMapping;
    compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
项目:Pushjet-Android    文件:JavaPlugin.java   
private void configureArchivesAndComponent(final Project project, final JavaPluginConvention pluginConvention) {
    Jar jar = project.getTasks().create(JAR_TASK_NAME, Jar.class);
    jar.getManifest().from(pluginConvention.getManifest());
    jar.setDescription("Assembles a jar archive containing the main classes.");
    jar.setGroup(BasePlugin.BUILD_GROUP);
    jar.from(pluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput());
    jar.getMetaInf().from(new Callable() {
        public Object call() throws Exception {
            return pluginConvention.getMetaInf();
        }
    });

    ArchivePublishArtifact jarArtifact = new ArchivePublishArtifact(jar);
    Configuration runtimeConfiguration = project.getConfigurations().getByName(RUNTIME_CONFIGURATION_NAME);

    runtimeConfiguration.getArtifacts().add(jarArtifact);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(jarArtifact);
    project.getComponents().add(new JavaLibrary(jarArtifact, runtimeConfiguration.getAllDependencies()));
}
项目:Pushjet-Android    文件:GroovyBasePlugin.java   
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        public void execute(SourceSet sourceSet) {
            final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), fileResolver);
            new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet);

            groovySourceSet.getGroovy().srcDir(String.format("src/%s/groovy", sourceSet.getName()));
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return groovySourceSet.getGroovy().contains(element.getFile());
                }
            });
            sourceSet.getAllJava().source(groovySourceSet.getGroovy());
            sourceSet.getAllSource().source(groovySourceSet.getGroovy());

            String compileTaskName = sourceSet.getCompileTaskName("groovy");
            GroovyCompile compile = project.getTasks().create(compileTaskName, GroovyCompile.class);
            javaBasePlugin.configureForSourceSet(sourceSet, compile);
            compile.dependsOn(sourceSet.getCompileJavaTaskName());
            compile.setDescription(String.format("Compiles the %s Groovy source.", sourceSet.getName()));
            compile.setSource(groovySourceSet.getGroovy());

            project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
        }
    });
}
项目:Pushjet-Android    文件:JavaBasePlugin.java   
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
    ConventionMapping conventionMapping;
    compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
项目:spotless    文件:KotlinExtension.java   
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */
@Override
protected void setupTask(SpotlessTask task) {
    if (target == null) {
        JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
        if (javaPlugin == null) {
            throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin.");
        }
        FileCollection union = getProject().files();
        for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
            union = union.plus(sourceSet.getAllSource().filter(file -> {
                String name = file.getName();
                return name.endsWith(".kt") || name.endsWith(".kts");
            }));
        }
        target = union;
    }
    super.setupTask(task);
}
项目:spotless    文件:JavaExtension.java   
/** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */
@Override
protected void setupTask(SpotlessTask task) {
    if (target == null) {
        JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
        if (javaPlugin == null) {
            throw new GradleException("You must apply the java plugin before the spotless plugin if you are using the java extension.");
        }
        FileCollection union = getProject().files();
        for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
            union = union.plus(sourceSet.getAllJava());
        }
        target = union;
    }
    // LicenseHeaderStep completely blows apart package-info.java - this common-sense check ensures that
    // it skips package-info.java. 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"));
        } else {
            return step;
        }
    });
    super.setupTask(task);
}
项目:spotless    文件:ScalaExtension.java   
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */
@Override
protected void setupTask(SpotlessTask task) {
    if (target == null) {
        JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
        if (javaPlugin == null) {
            throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin.");
        }
        FileCollection union = getProject().files();
        for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
            union = union.plus(sourceSet.getAllSource().filter(file -> {
                String name = file.getName();
                return name.endsWith(".scala") || name.endsWith(".sc");
            }));
        }
        target = union;
    }
    super.setupTask(task);
}
项目:gradle-pylizard    文件:SourceSetAnalyzer.java   
/**
 * Actually get the directories from the Object.
 * First it checks to see if the Object implements SourceSet,
 * otherwise it tries to get the directories using reflection.
 * Before calling this method, be sure to set the internal object
 * reference using setObject()
 *
 * @see SourceSetAnalyzer#setObject(Object)
 * @see org.gradle.api.tasks.SourceSet#getAllSource()
 * @see org.gradle.api.tasks.SourceSet#getAllJava()
 * @see org.gradle.api.tasks.SourceSet#getJava()
 */
public void analyze() {
    if (object == null) {
        return;
    }

    if (object instanceof SourceSet) {
        sourceDirectories.addAll(((SourceSet) object).getAllSource().getSrcDirs());
        return;
    }

    final String[] methodsToTry = {"getAllSource", "getAllJava", "getJava"};
    boolean atLeastOneSuccess = false;
    for (final String methodName : methodsToTry) {
        if (tryToGetDirectoriesWithMethod(methodName)) {
            atLeastOneSuccess = true;
        }
    }

    if (!atLeastOneSuccess) {
        failWithMessage("Unusable SourceSet of type " + object.getClass().getCanonicalName());
    }
}
项目:checkstyle-addons    文件:CreateJarSourcesTask.java   
@Override
public void configureFor(@Nonnull final DependencyConfig pDepConfig)
{
    // set appendix for archive name
    if (!pDepConfig.isDefaultConfig()) {
        final String appendix = pDepConfig.getName();
        setAppendix(appendix);
    }
    setDescription(
        getBuildUtil().getLongName() + ": Build the source JAR for dependency configuration '" + pDepConfig
            .getName() + "'");

    // SourceSet that fits the dependency configuration
    final SourceSet mainSourceSet = getBuildUtil().getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
    final SourceSet sqSourceSet = getBuildUtil().getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME);

    // Configuration of JAR file contents
    from(mainSourceSet.getAllJava());
    from(sqSourceSet.getAllJava());
    intoFrom("META-INF", "LICENSE");

    // Manifest
    getBuildUtil().inheritManifest(this, pDepConfig);
}
项目:checkstyle-addons    文件:TaskCreator.java   
public void establishSonarQubeSourceSet()
{
    final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    final SourceSetContainer sourceSets = javaConvention.getSourceSets();
    final ConfigurationContainer configs = project.getConfigurations();

    final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    final SourceSet sqSourceSet = sourceSets.create(BuildUtil.SONARQUBE_SOURCE_SET_NAME);

    configs.getByName(testSourceSet.getImplementationConfigurationName()).extendsFrom(
        configs.getByName(sqSourceSet.getImplementationConfigurationName()));
    configs.getByName(testSourceSet.getRuntimeOnlyConfigurationName()).extendsFrom(
        configs.getByName(sqSourceSet.getRuntimeOnlyConfigurationName()));

    final TaskContainer tasks = project.getTasks();
    tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).dependsOn(
        tasks.getByName(sqSourceSet.getClassesTaskName()));

    final FileCollection sqOutputs = sqSourceSet.getOutput().getClassesDirs().plus(
        project.files(sqSourceSet.getOutput().getResourcesDir()));
    testSourceSet.setCompileClasspath(testSourceSet.getCompileClasspath().plus(sqOutputs));
    testSourceSet.setRuntimeClasspath(testSourceSet.getRuntimeClasspath().plus(sqOutputs));
}
项目:checkstyle-addons    文件:TaskCreator.java   
public void setupBuildTasks(@Nonnull final DependencyConfig pDepConfig)
{
    final TaskContainer tasks = project.getTasks();

    // compile, classes
    setupCompileTaskForSourceSet(pDepConfig, SourceSet.MAIN_SOURCE_SET_NAME, TaskNames.compileJava,
        TaskNames.mainClasses);
    setupCompileTaskForSourceSet(pDepConfig, BuildUtil.SONARQUBE_SOURCE_SET_NAME, TaskNames.compileSonarqubeJava,
        TaskNames.sonarqubeClasses);
    setupCompileTaskForSourceSet(pDepConfig, SourceSet.TEST_SOURCE_SET_NAME, TaskNames.compileTestJava,
        TaskNames.testClasses);

    // test
    final TestTask testTask = tasks.create(TaskNames.test.getName(pDepConfig), TestTask.class);
    testTask.configureFor(pDepConfig, pDepConfig.getCheckstyleBaseVersion());

    // javadoc
    final JavadocTask javadocTask = tasks.create(TaskNames.javadoc.getName(pDepConfig), JavadocTask.class);
    javadocTask.configureFor(pDepConfig);
}
项目:checkstyle-addons    文件:TaskCreator.java   
private void setupCompileTaskForSourceSet(@Nonnull final DependencyConfig pDepConfig,
    @Nonnull final String pSourceSetName, @Nonnull final TaskNames pCompileTaskName,
    @Nonnull final TaskNames pClassesTaskName)
{
    final TaskContainer tasks = project.getTasks();
    final boolean isTest = SourceSet.TEST_SOURCE_SET_NAME.equals(pSourceSetName);

    final SourceSet sourceSet = buildUtil.getSourceSet(pSourceSetName);
    final CompileTask compileTask = tasks.create(pCompileTaskName.getName(pDepConfig), CompileTask.class);
    compileTask.configureFor(pDepConfig, sourceSet, isTest);

    final Task classesTask = tasks.create(pClassesTaskName.getName(pDepConfig));
    classesTask.setDescription(
        buildUtil.getLongName() + ": Assembles '" + pSourceSetName + "' classes for dependency configuration '"
            + pDepConfig.getName() + "'");
    classesTask.setGroup(BasePlugin.BUILD_GROUP);
    classesTask.dependsOn(compileTask, tasks.getByName(sourceSet.getProcessResourcesTaskName()));
}
项目:checkstyle-addons    文件:TaskCreator.java   
/**
 * Assign some standard tasks and tasks created by third-party plugins to their task groups according to the
 * order of things for Checkstyle Addons.
 */
public void adjustTaskGroupAssignments()
{
    final TaskContainer tasks = project.getTasks();
    tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).setGroup(ARTIFACTS_GROUP_NAME);
    tasks.getByName(JavaPlugin.JAR_TASK_NAME).setGroup(ARTIFACTS_GROUP_NAME);

    final SourceSet sqSourceSet = buildUtil.getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME);
    tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).setGroup(BasePlugin.BUILD_GROUP);
    tasks.getByName(sqSourceSet.getCompileJavaTaskName()).setGroup(BasePlugin.BUILD_GROUP);
    tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).setGroup(BasePlugin.BUILD_GROUP);

    for (final FindBugs fbTask : tasks.withType(FindBugs.class)) {
        fbTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
    }
    for (final Checkstyle csTask : tasks.withType(Checkstyle.class)) {
        csTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
    }
    for (final Copy task : tasks.withType(Copy.class)) {
        if (task.getName().startsWith("process") && task.getName().endsWith("Resources")) {
            task.setGroup(LifecycleBasePlugin.BUILD_GROUP);
        }
    }
}
项目:jooby    文件:JoobyProject.java   
public Set<File> classpath() {
  SourceSet sourceSet = sourceSet(project);

  Set<File> cp = new LinkedHashSet<>();
  // conf & public
  sourceSet.getResources().getSrcDirs().forEach(cp::add);

  // classes/main, resources/main + jars
  sourceSet.getRuntimeClasspath().getFiles().forEach(cp::add);

  // provided?
  Configuration provided = project.getConfigurations().findByName("provided");
  if (provided != null) {
    provided.getFiles().forEach(cp::add);
  }

  return cp;
}