private SourceSet sourceSet(final Project project) { return getJavaConvention(project).getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); }
public JvmTarget( Project project, String name, String aptConfigurationName, String testAptConfigurationName) { super(project, name); this.aptConfigurationName = aptConfigurationName; this.testAptConfigurationName = testAptConfigurationName; sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); isKotlin = project.getPlugins().stream().anyMatch(plugin -> plugin instanceof KotlinBasePluginWrapper); Optional<Task> compileTask = project.getTasks().stream().filter(it -> it instanceof AbstractCompile).findFirst(); if (compileTask.isPresent()) { fakeCompile = (AbstractCompile) compileTask.get(); } else { fakeCompile = null; } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".kt") || name.endsWith(".kts"); })); } target = union; } super.setupTask(task); } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".scala") || name.endsWith(".sc"); })); } target = union; } super.setupTask(task); } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ @Override protected void setupTask(SpotlessTask task) { if (target == null) { JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must apply the java plugin before the spotless plugin if you are using the java extension."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllJava()); } target = union; } steps.replaceAll(step -> { if (LicenseHeaderStep.name().equals(step.getName())) { return step.filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter()); } else { return step; } }); super.setupTask(task); } }
for (SourceSet sourceSet : convention.getSourceSets()) { GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class); if (excludeJava) {
public static void configureDevSource(JavaPluginConvention javaConvention, Function<SourceSet, SourceDirectorySet> languageMapper) { SourceSet main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet test = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); SourceSet dev = javaConvention.getSourceSets().getByName(DEV_SOURCE_SET_NAME); languageMapper.apply(dev).source(languageMapper.apply(test)); languageMapper.apply(dev).source(languageMapper.apply(main)); } }
private String sourceDirsPath() { final JavaPluginConvention javaPlugin = project.getConvention().getPlugin(JavaPluginConvention.class); final SourceSetContainer sourceSets = javaPlugin.getSourceSets(); return sourceSets.stream() .filter(ss -> "test".equals(ss.getName())) .peek(sourceSet -> LOGGER.debug("finding source dir for sourceSet " + sourceSet.getName())) .map(SourceSet::getJava) .map(SourceDirectorySet::getSrcDirs) .flatMap(Set::stream) .map(srcDir -> srcDir.toPath().toAbsolutePath().toString()) .collect(Collectors.joining(":")); }
private FileCollection getRuntimeClasspath() { return getPlugin(JavaPluginConvention.class) .getSourceSets() .getByName(dropwizard.classpath) .getRuntimeClasspath(); }
private void configureTest(Project project, JavaPluginConvention javaConvention) { SourceSet sourceSet = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); ClojureCompile compile = (ClojureCompile) project.getTasks().getByName(sourceSet.getCompileTaskName("clojure")); compile.getOptions().setAotCompile(true); Callable<?> namespaces = () -> { List<String> nses = new ArrayList<>(); nses.add("gradle-clojure.tools.clojure-test-junit4"); nses.addAll(compile.findNamespaces()); return nses; }; compile.getConventionMapping().map("namespaces", namespaces); }
private static String getHydraConfigFolderFromTask(Project project, ScalaCompile scalaCompile) { SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); String hydraConfigFolder = "main"; for (SourceSet set : sourceSets) { if (set.getCompileTaskName("scala").equals(scalaCompile.getName())) { hydraConfigFolder = set.getName(); } } return hydraConfigFolder; }
private void configureForSpotbugs(JavaPluginConvention javaPluginConvention) { lombokExtension.getConfig().put("lombok.extern.findbugs.addSuppressFBWarnings", "true"); CodeQualityExtension spotbugsExtension = (CodeQualityExtension) project.getExtensions().getByName("spotbugs"); javaPluginConvention.getSourceSets().all(sourceSet -> project.getDependencies().add( sourceSet.getCompileOnlyConfigurationName(), "com.github.spotbugs:spotbugs-annotations:" + spotbugsExtension.getToolVersion() )); }
private void configureForFindbugs(JavaPluginConvention javaPluginConvention) { lombokExtension.getConfig().put("lombok.extern.findbugs.addSuppressFBWarnings", "true"); FindBugsExtension findBugsExtension = project.getExtensions().getByType(FindBugsExtension.class); javaPluginConvention.getSourceSets().all(sourceSet -> project.getDependencies().add( sourceSet.getCompileOnlyConfigurationName(), "com.google.code.findbugs:findbugs:" + findBugsExtension.getToolVersion() )); }
@Override public void apply(Project project) { project.getPluginManager().apply( "java" ); final SnifferExtension snifferExtension = Helper.maybeCreateExtension( project ); final GenerateTask generateTask = project.getTasks().create( GenerateTask.STANDARD_NAME, GenerateTask.class ); final String compileTaskName = project.getConvention().getPlugin( JavaPluginConvention.class ) .getSourceSets() .getByName( "main" ) .getClassesTaskName(); generateTask.dependsOn( project.getTasks().getByName( compileTaskName ) ); } }
@Override public void apply(final Project project) { final TodoOutputTask task = this.makeTask(project); task.setInput(((JavaPluginConvention) project.getConvention().getPlugins().get("java")) .getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getJava()); }
private void createJavaDirTask(Project project) { Task createJavaDir = project.getTasks().create("createJavaDir"); createJavaDir.setGroup(Task_Group_Nuke); createJavaDir.getActions().add(task -> { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSetContainer sourceSets = javaConvention.getSourceSets(); sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getJava().getSrcDirs().forEach(this::createIfNotExist); sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getResources().getSrcDirs().forEach(this::createIfNotExist); sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getJava().getSrcDirs().forEach(this::createIfNotExist); sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getResources().getSrcDirs().forEach(this::createIfNotExist); }); }
private FileCollection getOutputClassDir(Project project) { return project.getConvention() .getPlugin(JavaPluginConvention.class) .getSourceSets() .getByName("main") .getOutput() .getClassesDirs(); }
public ServiceLoaderTask() throws IOException { super.setDescription("Generate META-INF/services manifests for use with ServiceLoaders"); super.setGroup("Source Generation"); javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); this.main = javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSetOutput mainOutput = main.getOutput(); classesOutput = mainOutput.getClassesDirs(); outputDirectory = new File(mainOutput.getResourcesDir(), "META-INF/services"); }
private void configureLibPropertiesTask(PropertiesTask thin, Project project) { thin.setConfiguration(findRuntimeClasspath(project)); SourceSetContainer sourceSets = project.getConvention() .getPlugin(JavaPluginConvention.class).getSourceSets(); File resourcesDir = sourceSets.getByName("main").getOutput().getResourcesDir(); thin.setOutput(new File(resourcesDir, "META-INF")); }
private void configureGosuDoc( final Project project ) { GosuDoc gosuDoc = project.getTasks().create(GOSUDOC_TASK_NAME, GosuDoc.class); gosuDoc.setDescription("Generates Gosudoc API documentation for the main source code."); gosuDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP); JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); gosuDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath())); Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention"); GosuSourceSet gosuSourceSet = sourceSetConvention.getPlugin(GosuSourceSet.class); gosuDoc.setSource((Object) gosuSourceSet.getGosu()); // Gradle 4.0 overloads setSource; must upcast to Object for backwards compatibility }