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(), sourceDirectorySetFactory); new DslObject(sourceSet).getConvention().getPlugins().put("groovy", groovySourceSet); groovySourceSet.getGroovy().srcDir("src/" + sourceSet.getName() + "/groovy"); 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("Compiles the " + sourceSet.getName() + " Groovy source."); compile.setSource(groovySourceSet.getGroovy()); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName); } }); }
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); } }); }
public void setUp() throws Exception { super.setUp(); analyzer = new SourceSetAnalyzer(); numOfDirs = 10; directories = new HashSet<File>(numOfDirs); for (int i = 0; i < numOfDirs; i++) { directories.add(new File("dir" + i)); // NOPMD } fakeDirSet = Mockito.spy(new FakeSourceDirectorySet(directories)); fakeSet = Mockito.spy(new FakeSourceSet(fakeDirSet)); analyzer.setObject(fakeSet); realSet = Mockito.spy(new DefaultSourceSet("Real", Mockito.mock(FileResolver.class))); }
@Override public void apply(final Project project) { super.apply(project); getJarTask().setDescription("Assembles a jar archive containing the sources."); project.getPluginManager().withPlugin("java", appliedPlugin -> { getJarTask().dependsOn(project.getTasks().getByName(JavaPlugin.CLASSES_TASK_NAME)); JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); DefaultSourceSet mainSourceSet = (DefaultSourceSet) javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); getJarTask().from(mainSourceSet.getAllSource()); }); }
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); } }); }