Search in sources :

Example 31 with SourceSet

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

the class JavaPlugin method configureSourceSets.

private void configureSourceSets(JavaPluginConvention pluginConvention, final BuildOutputCleanupRegistry buildOutputCleanupRegistry) {
    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_CLASSPATH_CONFIGURATION_NAME)));
    // Register the project's source set output directories
    pluginConvention.getSourceSets().all(new Action<SourceSet>() {

        @Override
        public void execute(SourceSet sourceSet) {
            buildOutputCleanupRegistry.registerOutputs(sourceSet.getOutput());
        }
    });
}
Also used : Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet)

Example 32 with SourceSet

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

the class ScalaBasePlugin method configureSourceSetDefaults.

private static void configureSourceSetDefaults(final Project project, final SourceDirectorySetFactory sourceDirectorySetFactory) {
    final JavaBasePlugin javaPlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {

        @Override
        public void execute(final SourceSet sourceSet) {
            String displayName = (String) InvokerHelper.invokeMethod(sourceSet, "getDisplayName", null);
            Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
            DefaultScalaSourceSet scalaSourceSet = new DefaultScalaSourceSet(displayName, sourceDirectorySetFactory);
            sourceSetConvention.getPlugins().put("scala", scalaSourceSet);
            final SourceDirectorySet scalaDirectorySet = scalaSourceSet.getScala();
            scalaDirectorySet.srcDir(new Callable<File>() {

                @Override
                public File call() throws Exception {
                    return project.file("src/" + sourceSet.getName() + "/scala");
                }
            });
            sourceSet.getAllJava().source(scalaDirectorySet);
            sourceSet.getAllSource().source(scalaDirectorySet);
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {

                @Override
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return scalaDirectorySet.contains(element.getFile());
                }
            });
            configureScalaCompile(project, javaPlugin, sourceSet);
        }
    });
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ScalaSourceSet(org.gradle.api.tasks.ScalaSourceSet) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) FileTreeElement(org.gradle.api.file.FileTreeElement) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) Spec(org.gradle.api.specs.Spec) Callable(java.util.concurrent.Callable)

Example 33 with SourceSet

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

the class ScalaPlugin method configureScaladoc.

private static void configureScaladoc(final Project project) {
    project.getTasks().withType(ScalaDoc.class, new Action<ScalaDoc>() {

        @Override
        public void execute(ScalaDoc scalaDoc) {
            final SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main");
            scalaDoc.getConventionMapping().map("classpath", new Callable<FileCollection>() {

                @Override
                public FileCollection call() throws Exception {
                    ConfigurableFileCollection files = project.files();
                    files.from(main.getOutput());
                    files.from(main.getCompileClasspath());
                    return files;
                }
            });
            scalaDoc.setSource(InvokerHelper.invokeMethod(main, "getScala", null));
        }
    });
    ScalaDoc scalaDoc = project.getTasks().create(SCALA_DOC_TASK_NAME, ScalaDoc.class);
    scalaDoc.setDescription("Generates Scaladoc for the main source code.");
    scalaDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) ScalaDoc(org.gradle.api.tasks.scala.ScalaDoc) Callable(java.util.concurrent.Callable)

Example 34 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) {
    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;
}
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 35 with SourceSet

use of org.gradle.api.tasks.SourceSet in project spring-boot by spring-projects.

the class RunPluginFeatures method mainClassNameFinder.

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);
            }
        }
    });
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) CreateStartScripts(org.gradle.api.tasks.application.CreateStartScripts)

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