Search in sources :

Example 36 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class SourceFoldersCreator method projectRelativeFolders.

private List<SourceFolder> projectRelativeFolders(Iterable<SourceSet> sourceSets, Function<File, String> provideRelativePath, File defaultOutputDir) {
    String defaultOutputPath = PathUtil.normalizePath(provideRelativePath.apply(defaultOutputDir));
    ArrayList<SourceFolder> entries = Lists.newArrayList();
    List<SourceSet> sortedSourceSets = sortSourceSetsAsPerUsualConvention(sourceSets);
    Map<SourceSet, String> sourceSetOutputPaths = collectSourceSetOutputPaths(sortedSourceSets, defaultOutputPath);
    Multimap<SourceSet, SourceSet> sourceSetUsages = getSourceSetUsages(sortedSourceSets);
    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));
                folder.setOutput(sourceSetOutputPaths.get(sourceSet));
                addScopeAttributes(folder, sourceSet, sourceSetUsages);
                entries.add(folder);
            }
        }
    }
    return entries;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryTree(org.gradle.api.file.DirectoryTree) File(java.io.File)

Example 37 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class SourceFoldersCreator method collectSourceSetOutputPaths.

private Map<SourceSet, String> collectSourceSetOutputPaths(Iterable<SourceSet> sourceSets, String defaultOutputPath) {
    Set<String> existingPaths = Sets.newHashSet(defaultOutputPath);
    Map<SourceSet, String> result = Maps.newHashMap();
    for (SourceSet sourceSet : sourceSets) {
        String path = collectSourceSetOutputPath(sourceSet.getName(), existingPaths, "");
        existingPaths.add(path);
        result.put(sourceSet, path);
    }
    return result;
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet)

Example 38 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class SourceFoldersCreator method getUsingSourceSetNames.

private List<String> getUsingSourceSetNames(SourceSet sourceSet, Multimap<SourceSet, SourceSet> sourceSetUsages) {
    Collection<SourceSet> usingSourceSets = sourceSetUsages.get(sourceSet);
    List<String> usingSourceSetNames = Lists.newArrayList();
    for (SourceSet usingSourceSet : usingSourceSets) {
        usingSourceSetNames.add(sanitizeNameForAttribute(usingSourceSet));
    }
    return usingSourceSetNames;
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet)

Example 39 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class AntlrPlugin method apply.

public void apply(final Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    // set up a configuration named 'antlr' for the user to specify the antlr libs to use in case
    // they want a specific version etc.
    final Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false).setDescription("The Antlr libraries to be used for this project.");
    antlrConfiguration.defaultDependencies(new Action<DependencySet>() {

        @Override
        public void execute(DependencySet dependencies) {
            dependencies.add(project.getDependencies().create("antlr:antlr:2.7.7@jar"));
        }
    });
    project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);
    // Wire the antlr configuration into all antlr tasks
    project.getTasks().withType(AntlrTask.class, new Action<AntlrTask>() {

        public void execute(AntlrTask antlrTask) {
            antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {

                public Object call() throws Exception {
                    return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME);
                }
            });
        }
    });
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {

        public void execute(SourceSet sourceSet) {
            // for each source set we will:
            // 1) Add a new 'antlr' virtual directory mapping
            final AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate = new AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
            new DslObject(sourceSet).getConvention().getPlugins().put(AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
            final String srcDir = "src/" + sourceSet.getName() + "/antlr";
            antlrDirectoryDelegate.getAntlr().srcDir(srcDir);
            sourceSet.getAllSource().source(antlrDirectoryDelegate.getAntlr());
            // 2) create an AntlrTask for this sourceSet following the gradle
            // naming conventions via call to sourceSet.getTaskName()
            final String taskName = sourceSet.getTaskName("generate", "GrammarSource");
            AntlrTask antlrTask = project.getTasks().create(taskName, AntlrTask.class);
            antlrTask.setDescription("Processes the " + sourceSet.getName() + " Antlr grammars.");
            // 3) set up convention mapping for default sources (allows user to not have to specify)
            antlrTask.setSource(antlrDirectoryDelegate.getAntlr());
            // 4) Set up the Antlr output directory (adding to javac inputs!)
            final String outputDirectoryName = project.getBuildDir() + "/generated-src/antlr/" + sourceSet.getName();
            final File outputDirectory = new File(outputDirectoryName);
            antlrTask.setOutputDirectory(outputDirectory);
            sourceSet.getJava().srcDir(outputDirectory);
            // 6) register fact that antlr should be run before compiling
            project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(taskName);
        }
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DslObject(org.gradle.api.internal.plugins.DslObject) DependencySet(org.gradle.api.artifacts.DependencySet) Callable(java.util.concurrent.Callable) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) SourceSet(org.gradle.api.tasks.SourceSet) AntlrSourceVirtualDirectoryImpl(org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) File(java.io.File)

Example 40 with SourceSet

use of org.gradle.api.tasks.SourceSet in project checkstyle-idea by jshiell.

the class CsaccessTestTask method getClasspath.

/**
 * Overriding getClasspath() in order to set the final classpath is an unusual solution, but it was the only
 * solution which included the classpath entries generated by the IntelliJ plugin creation plugin (which, in my
 * humble opinion, should be considered seriously broken).
 *
 * @return the classpath to use to execute the tests
 */
@Override
public FileCollection getClasspath() {
    final FileCollection originalClasspath = super.getClasspath();
    FileCollection effectiveClasspath = null;
    if (originalClasspath != null) {
        final Project project = getProject();
        final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
        final SourceSetContainer sourceSets = javaConvention.getSourceSets();
        final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
        final SourceSet csaccessSourceSet = sourceSets.getByName(CustomSourceSetCreator.CSACCESS_SOURCESET_NAME);
        final SourceSet csaccessTestSrcSet = sourceSets.getByName(CustomSourceSetCreator.CSACCESSTEST_SOURCESET_NAME);
        final Dependency csDep = CheckstyleVersions.createCheckstyleDependency(project, csVersion);
        final ConfigurationContainer configurations = project.getConfigurations();
        final Set<File> csJars = configurations.detachedConfiguration(csDep).getFiles();
        effectiveClasspath = project.files(csaccessTestSrcSet.getOutput().getResourcesDir(), csaccessSourceSet.getOutput().getResourcesDir(), mainSourceSet.getOutput().getResourcesDir()).plus(csaccessTestSrcSet.getOutput().getClassesDirs()).plus(csaccessSourceSet.getOutput().getClassesDirs()).plus(mainSourceSet.getOutput().getClassesDirs()).plus(project.files(csJars)).plus(originalClasspath).minus(testSourceSet.getOutput().getClassesDirs()).minus(project.files(testSourceSet.getOutput().getResourcesDir()));
    // getLogger().lifecycle("--------------------------------------------------------------------------");
    // getLogger().lifecycle("Effective classpath of " + getName() + ":");
    // for (File f : effectiveClasspath) {
    // getLogger().lifecycle("\t- " + f.getAbsolutePath());
    // }
    }
    return effectiveClasspath;
}
Also used : Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Dependency(org.gradle.api.artifacts.Dependency) FileCollection(org.gradle.api.file.FileCollection) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) File(java.io.File)

Aggregations

SourceSet (org.gradle.api.tasks.SourceSet)55 File (java.io.File)28 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)24 Project (org.gradle.api.Project)20 Configuration (org.gradle.api.artifacts.Configuration)19 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)18 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)15 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)14 List (java.util.List)13 Task (org.gradle.api.Task)13 JavaPlugin (org.gradle.api.plugins.JavaPlugin)12 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)12 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 Collections (java.util.Collections)10 Action (org.gradle.api.Action)10 Plugin (org.gradle.api.Plugin)10 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)10 Jar (org.gradle.api.tasks.bundling.Jar)10 HashSet (java.util.HashSet)9