Search in sources :

Example 1 with SourceSetContainer

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

the class EclipsePlugin method configureJavaClasspath.

private static void configureJavaClasspath(final Project project, GenerateEclipseClasspath task) {
    task.getClasspath().setPlusConfigurations(Lists.newArrayList(project.getConfigurations().getByName("compileClasspath"), project.getConfigurations().getByName("runtimeClasspath"), project.getConfigurations().getByName("testCompileClasspath"), project.getConfigurations().getByName("testRuntimeClasspath")));
    ((IConventionAware) task.getClasspath()).getConventionMapping().map("classFolders", new Callable<List<File>>() {

        @Override
        public List<File> call() {
            SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
            return Lists.newArrayList(Iterables.concat(sourceSets.getByName("main").getOutput().getDirs(), sourceSets.getByName("test").getOutput().getDirs()));
        }
    });
    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
    task.dependsOn(sourceSets.getByName("main").getOutput().getDirs());
    task.dependsOn(sourceSets.getByName("test").getOutput().getDirs());
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) List(java.util.List) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 2 with SourceSetContainer

use of org.gradle.api.tasks.SourceSetContainer in project Entitas-Java by Rubentxu.

the class EntitasGradleProject method getSrcDirs.

@Override
public Set<File> getSrcDirs() {
    SourceSetContainer sourceSets = javaConvention.getSourceSets();
    SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    return mainSourceSet.getAllSource().getSrcDirs();
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 3 with SourceSetContainer

use of org.gradle.api.tasks.SourceSetContainer in project intellij-community by JetBrains.

the class ModuleExtendedModelBuilderImpl method buildAll.

@Nullable
@Override
public Object buildAll(String modelName, Project project) {
    final String moduleName = project.getName();
    final String moduleGroup = project.getGroup().toString();
    final String moduleVersion = project.getVersion().toString();
    final File buildDir = project.getBuildDir();
    String javaSourceCompatibility = null;
    for (Task task : project.getTasks()) {
        if (task instanceof JavaCompile) {
            JavaCompile javaCompile = (JavaCompile) task;
            javaSourceCompatibility = javaCompile.getSourceCompatibility();
            if (task.getName().equals("compileJava"))
                break;
        }
    }
    final ModuleExtendedModelImpl moduleVersionModel = new ModuleExtendedModelImpl(moduleName, moduleGroup, moduleVersion, buildDir, javaSourceCompatibility);
    final List<File> artifacts = new ArrayList<File>();
    for (Task task : project.getTasks()) {
        if (task instanceof Jar) {
            Jar jar = (Jar) task;
            artifacts.add(jar.getArchivePath());
        }
    }
    moduleVersionModel.setArtifacts(artifacts);
    final Set<String> sourceDirectories = new HashSet<String>();
    final Set<String> testDirectories = new HashSet<String>();
    final Set<String> resourceDirectories = new HashSet<String>();
    final Set<String> testResourceDirectories = new HashSet<String>();
    final List<File> testClassesDirs = new ArrayList<File>();
    for (Task task : project.getTasks()) {
        if (task instanceof Test) {
            Test test = (Test) task;
            testClassesDirs.add(test.getTestClassesDir());
            if (test.hasProperty(TEST_SRC_DIRS_PROPERTY)) {
                Object testSrcDirs = test.property(TEST_SRC_DIRS_PROPERTY);
                if (testSrcDirs instanceof Iterable) {
                    for (Object dir : Iterable.class.cast(testSrcDirs)) {
                        addFilePath(testDirectories, dir);
                    }
                }
            }
        }
    }
    IdeaCompilerOutputImpl compilerOutput = new IdeaCompilerOutputImpl();
    if (project.hasProperty(SOURCE_SETS_PROPERTY)) {
        Object sourceSets = project.property(SOURCE_SETS_PROPERTY);
        if (sourceSets instanceof SourceSetContainer) {
            SourceSetContainer sourceSetContainer = (SourceSetContainer) sourceSets;
            for (SourceSet sourceSet : sourceSetContainer) {
                SourceSetOutput output = sourceSet.getOutput();
                if (SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSet.getName())) {
                    compilerOutput.setTestClassesDir(output.getClassesDir());
                    compilerOutput.setTestResourcesDir(output.getResourcesDir());
                }
                if (SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
                    compilerOutput.setMainClassesDir(output.getClassesDir());
                    compilerOutput.setMainResourcesDir(output.getResourcesDir());
                }
                for (File javaSrcDir : sourceSet.getAllJava().getSrcDirs()) {
                    boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
                    addFilePath(isTestDir ? testDirectories : sourceDirectories, javaSrcDir);
                }
                for (File resourcesSrcDir : sourceSet.getResources().getSrcDirs()) {
                    boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
                    addFilePath(isTestDir ? testResourceDirectories : resourceDirectories, resourcesSrcDir);
                }
            }
        }
    }
    File projectDir = project.getProjectDir();
    IdeaContentRootImpl contentRoot = new IdeaContentRootImpl(projectDir);
    final Set<String> ideaSourceDirectories = new HashSet<String>();
    final Set<String> ideaTestDirectories = new HashSet<String>();
    final Set<String> ideaGeneratedDirectories = new HashSet<String>();
    final Set<File> excludeDirectories = new HashSet<File>();
    enrichDataFromIdeaPlugin(project, excludeDirectories, ideaSourceDirectories, ideaTestDirectories, ideaGeneratedDirectories);
    if (ideaSourceDirectories.isEmpty()) {
        sourceDirectories.clear();
        resourceDirectories.clear();
    }
    if (ideaTestDirectories.isEmpty()) {
        testDirectories.clear();
        testResourceDirectories.clear();
    }
    ideaSourceDirectories.removeAll(resourceDirectories);
    sourceDirectories.removeAll(ideaTestDirectories);
    sourceDirectories.addAll(ideaSourceDirectories);
    ideaTestDirectories.removeAll(testResourceDirectories);
    testDirectories.addAll(ideaTestDirectories);
    // ensure disjoint directories with different type
    resourceDirectories.removeAll(sourceDirectories);
    testDirectories.removeAll(sourceDirectories);
    testResourceDirectories.removeAll(testDirectories);
    for (String javaDir : sourceDirectories) {
        contentRoot.addSourceDirectory(new IdeaSourceDirectoryImpl(new File(javaDir), ideaGeneratedDirectories.contains(javaDir)));
    }
    for (String testDir : testDirectories) {
        contentRoot.addTestDirectory(new IdeaSourceDirectoryImpl(new File(testDir), ideaGeneratedDirectories.contains(testDir)));
    }
    for (String resourceDir : resourceDirectories) {
        contentRoot.addResourceDirectory(new IdeaSourceDirectoryImpl(new File(resourceDir)));
    }
    for (String testResourceDir : testResourceDirectories) {
        contentRoot.addTestResourceDirectory(new IdeaSourceDirectoryImpl(new File(testResourceDir)));
    }
    for (File excludeDir : excludeDirectories) {
        contentRoot.addExcludeDirectory(excludeDir);
    }
    moduleVersionModel.setContentRoots(Collections.<ExtIdeaContentRoot>singleton(contentRoot));
    moduleVersionModel.setCompilerOutput(compilerOutput);
    ConfigurationContainer configurations = project.getConfigurations();
    SortedMap<String, Configuration> configurationsByName = configurations.getAsMap();
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<String, Set<File>>();
    for (Map.Entry<String, Configuration> configurationEntry : configurationsByName.entrySet()) {
        Set<File> files = configurationEntry.getValue().getAllArtifacts().getFiles().getFiles();
        artifactsByConfiguration.put(configurationEntry.getKey(), files);
    }
    moduleVersionModel.setArtifactsByConfiguration(artifactsByConfiguration);
    return moduleVersionModel;
}
Also used : Task(org.gradle.api.Task) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) IdeaContentRootImpl(org.jetbrains.plugins.gradle.tooling.internal.IdeaContentRootImpl) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) SourceSetOutput(org.gradle.api.tasks.SourceSetOutput) ModuleExtendedModelImpl(org.jetbrains.plugins.gradle.tooling.internal.ModuleExtendedModelImpl) SourceSet(org.gradle.api.tasks.SourceSet) Test(org.gradle.api.tasks.testing.Test) IdeaSourceDirectoryImpl(org.jetbrains.plugins.gradle.tooling.internal.IdeaSourceDirectoryImpl) IdeaCompilerOutputImpl(org.jetbrains.plugins.gradle.tooling.internal.IdeaCompilerOutputImpl) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Jar(org.gradle.api.tasks.bundling.Jar) File(java.io.File) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with SourceSetContainer

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

the class LinkedResourcesCreator method links.

public Set<Link> links(final Project project) {
    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
    List<SourceFolder> sourceFolders = new SourceFoldersCreator().getExternalSourceFolders(sourceSets, new Function<File, String>() {

        @Override
        public String apply(File dir) {
            return project.relativePath(dir);
        }
    });
    Set<Link> links = Sets.newLinkedHashSetWithExpectedSize(sourceFolders.size());
    for (SourceFolder sourceFolder : sourceFolders) {
        links.add(new Link(sourceFolder.getName(), "2", sourceFolder.getAbsolutePath(), null));
    }
    return links;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) SourceFoldersCreator(org.gradle.plugins.ide.eclipse.model.internal.SourceFoldersCreator) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) File(java.io.File) Link(org.gradle.plugins.ide.eclipse.model.Link)

Example 5 with SourceSetContainer

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

the class IdeaPlugin method configureIdeaModuleForJava.

private void configureIdeaModuleForJava(final Project project) {
    project.getTasks().withType(GenerateIdeaModule.class, new Action<GenerateIdeaModule>() {

        @Override
        public void execute(GenerateIdeaModule ideaModule) {
            // Defaults
            setupScopes(ideaModule);
            // Convention
            ConventionMapping convention = ((IConventionAware) ideaModule.getModule()).getConventionMapping();
            convention.map("sourceDirs", new Callable<Set<File>>() {

                @Override
                public Set<File> call() throws Exception {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    return sourceSets.getByName("main").getAllSource().getSrcDirs();
                }
            });
            convention.map("testSourceDirs", new Callable<Set<File>>() {

                @Override
                public Set<File> call() throws Exception {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    return sourceSets.getByName("test").getAllSource().getSrcDirs();
                }
            });
            convention.map("singleEntryLibraries", new Callable<Map<String, FileCollection>>() {

                @Override
                public Map<String, FileCollection> call() throws Exception {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    LinkedHashMap<String, FileCollection> map = new LinkedHashMap<String, FileCollection>(2);
                    map.put("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
                    map.put("TEST", sourceSets.getByName("test").getOutput().getDirs());
                    return map;
                }
            });
            convention.map("targetBytecodeVersion", new Callable<JavaVersion>() {

                @Override
                public JavaVersion call() throws Exception {
                    JavaVersion moduleTargetBytecodeLevel = project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
                    return includeModuleBytecodeLevelOverride(project.getRootProject(), moduleTargetBytecodeLevel) ? moduleTargetBytecodeLevel : null;
                }
            });
            convention.map("languageLevel", new Callable<IdeaLanguageLevel>() {

                @Override
                public IdeaLanguageLevel call() throws Exception {
                    IdeaLanguageLevel moduleLanguageLevel = new IdeaLanguageLevel(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility());
                    return includeModuleLanguageLevelOverride(project.getRootProject(), moduleLanguageLevel) ? moduleLanguageLevel : null;
                }
            });
            // Dependencies
            ideaModule.dependsOn(new Callable<FileCollection>() {

                @Override
                public FileCollection call() throws Exception {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    return sourceSets.getByName("main").getOutput().getDirs().plus(sourceSets.getByName("test").getOutput().getDirs());
                }
            });
        }
    });
}
Also used : IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) FileCollection(org.gradle.api.file.FileCollection) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) File(java.io.File)

Aggregations

SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)5 File (java.io.File)3 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)3 SourceSet (org.gradle.api.tasks.SourceSet)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 JavaVersion (org.gradle.api.JavaVersion)1 Task (org.gradle.api.Task)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1 FileCollection (org.gradle.api.file.FileCollection)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 SourceSetOutput (org.gradle.api.tasks.SourceSetOutput)1 Jar (org.gradle.api.tasks.bundling.Jar)1 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)1 Test (org.gradle.api.tasks.testing.Test)1 Link (org.gradle.plugins.ide.eclipse.model.Link)1 SourceFolder (org.gradle.plugins.ide.eclipse.model.SourceFolder)1 SourceFoldersCreator (org.gradle.plugins.ide.eclipse.model.internal.SourceFoldersCreator)1