Java源码示例:org.gradle.api.internal.tasks.DefaultSourceSet

示例1
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);
        }
    });
}
 
示例2
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);
        }
    });
}
 
示例3
@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);
    });
}
 
示例4
@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);
    });
}
 
示例5
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);
        }
    });
}
 
示例6
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);
        }
    });
}
 
示例7
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");
}
 
示例8
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");
}
 
示例9
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);
                }
            });
}
 
示例10
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);
                }
            });
}
 
示例11
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;
}
 
示例12
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);
                }
            });
}
 
示例13
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);
                }
            });
}