org.gradle.api.internal.tasks.DefaultSourceSet Java Examples

The following examples show how to use org.gradle.api.internal.tasks.DefaultSourceSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroovyBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 7 votes vote down vote up
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);
        }
    });
}
 
Example #2
Source File: SourcesJarPlugin.java    From gradle-plugins with MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #3
Source File: GroovyBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
        }
    });
}
 
Example #4
Source File: SourcesJarPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {

    project.getLogger().warn("io.freefair.sources-jar is deprecated. Use java.withSourcesJar() instead");

    project.getPluginManager().withPlugin("java", appliedPlugin -> {
        sourcesJar = project.getTasks().register("sourcesJar", Jar.class, sourcesJar -> {
            sourcesJar.setDescription("Assembles a jar archive containing the sources.");
            sourcesJar.getArchiveClassifier().set("sources");
            sourcesJar.setGroup(BasePlugin.BUILD_GROUP);

            sourcesJar.dependsOn(project.getTasks().named(JavaPlugin.CLASSES_TASK_NAME));

            JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourcesJar.from(mainSourceSet.getAllSource());
        });

        project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar);
    });
}
 
Example #5
Source File: GroovyBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
        }
    });
}
 
Example #6
Source File: GroovyBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
        }
    });
}
 
Example #7
Source File: DefaultAspectjSourceSet.java    From gradle-plugins with MIT License 5 votes vote down vote up
public DefaultAspectjSourceSet(ObjectFactory objectFactory, SourceSet sourceSet) {
    super(sourceSet);

    String name = sourceSet.getName();
    String displayName = ((DefaultSourceSet) sourceSet).getDisplayName();

    aspectj = objectFactory.sourceDirectorySet("aspectj", displayName + " AspectJ source");
    aspectj.getFilter().include("**/*.java", "**/*.aj");
    allAspectj = objectFactory.sourceDirectorySet("all" + name, displayName + " AspectJ source");
    allAspectj.source(aspectj);
    allAspectj.getFilter().include("**/*.aj");
}
 
Example #8
Source File: DefaultAspectjSourceSet.java    From gradle-plugins with MIT License 5 votes vote down vote up
public DefaultAspectjSourceSet(ObjectFactory objectFactory, SourceSet sourceSet) {
    super(sourceSet);

    String name = sourceSet.getName();
    String displayName = ((DefaultSourceSet) sourceSet).getDisplayName();

    aspectj = objectFactory.sourceDirectorySet("aspectj", displayName + " AspectJ source");
    aspectj.getFilter().include("**/*.java", "**/*.aj");
    allAspectj = objectFactory.sourceDirectorySet("all" + name, displayName + " AspectJ source");
    allAspectj.source(aspectj);
    allAspectj.getFilter().include("**/*.aj");
}
 
Example #9
Source File: AntlrPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void apply(final ProjectInternal project) {
    project.getPlugins().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.
    Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false)
            .setTransitive(false).setDescription("The Antlr libraries to be used for this project.");
    project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);

    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(), fileResolver);
                    new DslObject(sourceSet).getConvention().getPlugins().put(
                            AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
                    final String srcDir = String.format("src/%s/antlr", sourceSet.getName());
                    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(String.format("Processes the %s Antlr grammars.",
                            sourceSet.getName()));

                    // 3) set up convention mapping for default sources (allows user to not have to specify)
                    antlrTask.setSource(antlrDirectoryDelegate.getAntlr());

                    // 4) set up convention mapping for handling the 'antlr' dependency configuration
                    antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
                        public Object call() throws Exception {
                            return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME).copy()
                                    .setTransitive(true);
                        }
                    });

                    // 5) Set up the Antlr output directory (adding to javac inputs!)
                    final String outputDirectoryName = String.format("%s/generated-src/antlr/%s",
                            project.getBuildDir(), 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);
                }
            });
}
 
Example #10
Source File: AntlrPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void apply(final ProjectInternal project) {
    project.getPlugins().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.
    Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false)
            .setTransitive(false).setDescription("The Antlr libraries to be used for this project.");
    project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);

    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(), fileResolver);
                    new DslObject(sourceSet).getConvention().getPlugins().put(
                            AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
                    final String srcDir = String.format("src/%s/antlr", sourceSet.getName());
                    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(String.format("Processes the %s Antlr grammars.",
                            sourceSet.getName()));

                    // 3) set up convention mapping for default sources (allows user to not have to specify)
                    antlrTask.setSource(antlrDirectoryDelegate.getAntlr());

                    // 4) set up convention mapping for handling the 'antlr' dependency configuration
                    antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
                        public Object call() throws Exception {
                            return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME).copy()
                                    .setTransitive(true);
                        }
                    });

                    // 5) Set up the Antlr output directory (adding to javac inputs!)
                    final String outputDirectoryName = String.format("%s/generated-src/antlr/%s",
                            project.getBuildDir(), 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);
                }
            });
}
 
Example #11
Source File: PlayPluginHelper.java    From playframework with Apache License 2.0 4 votes vote down vote up
public static <T> T createCustomSourceSet(Project project, Class<? extends T> t, String name) {
    SourceSet mainSourceSet = getMainJavaSourceSet(project);
    T customSourceSet = project.getObjects().newInstance(t, name, ((DefaultSourceSet) mainSourceSet).getDisplayName(), project.getObjects());
    new DslObject(mainSourceSet).getConvention().getPlugins().put(name, customSourceSet);
    return customSourceSet;
}
 
Example #12
Source File: AntlrPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void apply(final ProjectInternal project) {
    project.getPlugins().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.
    Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false)
            .setTransitive(false).setDescription("The Antlr libraries to be used for this project.");
    project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);

    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(), fileResolver);
                    new DslObject(sourceSet).getConvention().getPlugins().put(
                            AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
                    final String srcDir = String.format("src/%s/antlr", sourceSet.getName());
                    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(String.format("Processes the %s Antlr grammars.",
                            sourceSet.getName()));

                    // 3) set up convention mapping for default sources (allows user to not have to specify)
                    antlrTask.setSource(antlrDirectoryDelegate.getAntlr());

                    // 4) set up convention mapping for handling the 'antlr' dependency configuration
                    antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
                        public Object call() throws Exception {
                            return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME).copy()
                                    .setTransitive(true);
                        }
                    });

                    // 5) Set up the Antlr output directory (adding to javac inputs!)
                    final String outputDirectoryName = String.format("%s/generated-src/antlr/%s",
                            project.getBuildDir(), 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);
                }
            });
}
 
Example #13
Source File: AntlrPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void apply(final ProjectInternal project) {
    project.getPlugins().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.
    Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false)
            .setTransitive(false).setDescription("The Antlr libraries to be used for this project.");
    project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);

    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(), fileResolver);
                    new DslObject(sourceSet).getConvention().getPlugins().put(
                            AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
                    final String srcDir = String.format("src/%s/antlr", sourceSet.getName());
                    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(String.format("Processes the %s Antlr grammars.",
                            sourceSet.getName()));

                    // 3) set up convention mapping for default sources (allows user to not have to specify)
                    antlrTask.setSource(antlrDirectoryDelegate.getAntlr());

                    // 4) set up convention mapping for handling the 'antlr' dependency configuration
                    antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
                        public Object call() throws Exception {
                            return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME).copy()
                                    .setTransitive(true);
                        }
                    });

                    // 5) Set up the Antlr output directory (adding to javac inputs!)
                    final String outputDirectoryName = String.format("%s/generated-src/antlr/%s",
                            project.getBuildDir(), 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);
                }
            });
}