private Set<File> getTestSrcDirs() { return sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getAllJava().getSrcDirs(); }
private Set<File> getMainSrcDirs() { return sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getAllJava().getSrcDirs(); }
/** 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); } }
SpotBugsTask setSourceSet(SourceSet sourceSet) { this.sourceDirs = sourceSet.getAllJava().getSrcDirs(); setSource(sourceDirs); return this; }
public void validate(SourceSet sourceSet) { Set<File> gradleProperties = PluginUtil.discoverGradlePluginPropertyFiles(sourceSet); sourceDirs = sourceSet.getAllJava().getSrcDirs(); ensureNamingConvention(gradleProperties); }
public void validate(SourceSet sourceSet) { Set<File> gradleProperties = PluginUtil.discoverGradlePluginPropertyFiles(sourceSet); sourceDirs = sourceSet.getAllJava().getSrcDirs(); ensureNamingConvention(gradleProperties); }
private static boolean configureSourceDirsAndJavaClasspath(Project project, Map<String, Object> properties, final boolean addForGroovy) { JavaPluginConvention javaPluginConvention = new DslObject(project).getConvention().getPlugin(JavaPluginConvention.class); SourceSet main = javaPluginConvention.getSourceSets().getAt("main"); List<File> sourceDirectories = nonEmptyOrNull(main.getAllJava().getSrcDirs().stream().filter(File::exists).collect(Collectors.toList())); properties.put(SONAR_SOURCES_PROP, sourceDirectories); SourceSet test = javaPluginConvention.getSourceSets().getAt("test"); List<File> testDirectories = nonEmptyOrNull(test.getAllJava().getSrcDirs().stream().filter(File::exists).collect(Collectors.toList())); properties.put(SONAR_TESTS_PROP, testDirectories); Collection<File> mainClassDirs = getOutputDirs(main); Collection<File> mainLibraries = getLibraries(main); setMainClasspathProps(properties, addForGroovy, mainClassDirs, mainLibraries); Collection<File> testClassDirs = getOutputDirs(test); Collection<File> testLibraries = getLibraries(test); setTestClasspathProps(properties, testClassDirs, testLibraries); return sourceDirectories != null || testDirectories != null; }
private static boolean configureSourceDirsAndJavaClasspath(Project project, Map<String, Object> properties, final boolean addForGroovy) { JavaPluginConvention javaPluginConvention = new DslObject(project).getConvention().getPlugin(JavaPluginConvention.class); SourceSet main = javaPluginConvention.getSourceSets().getAt("main"); List<File> sourceDirectories = nonEmptyOrNull(main.getAllJava().getSrcDirs().stream().filter(File::exists).collect(Collectors.toList())); properties.put(SONAR_SOURCES_PROP, sourceDirectories); SourceSet test = javaPluginConvention.getSourceSets().getAt("test"); List<File> testDirectories = nonEmptyOrNull(test.getAllJava().getSrcDirs().stream().filter(File::exists).collect(Collectors.toList())); properties.put(SONAR_TESTS_PROP, testDirectories); Collection<File> mainClassDirs = getOutputDirs(main); Collection<File> mainLibraries = getLibraries(main); setMainClasspathProps(properties, addForGroovy, mainClassDirs, mainLibraries); Collection<File> testClassDirs = getOutputDirs(test); Collection<File> testLibraries = getLibraries(test); setTestClasspathProps(properties, testClassDirs, testLibraries); return sourceDirectories != null || testDirectories != null; }
private ImmutableBiMap<String, String> getModuleNameIbiTaskName(final Project project, final SourceSetContainer sourceSets) { return sourceSets.stream() .flatMap(ss -> stream(ss.getAllJava().matching(pattern -> pattern.include("**/" + MODULE_INFO_JAVA))) .map(moduleInfoJavaFile -> immutableEntry( ss.getCompileJavaTaskName(), parseModuleName(moduleInfoJavaFile.toPath(), newJavaParser((JavaCompile) project.getTasks().getByName(ss.getCompileJavaTaskName()))) ) ) ) .collect(toImmutableBiMap( Entry::getKey, Entry::getValue )) ; }
return Optional.empty(); Optional<File> moduleInfoSrcDir = main.getAllJava() .getSourceDirectories() .getFiles()
@Override public void apply(final Project project) { Logger logger = project.getLogger(); logger.info("applying jsweet plugin"); if (!project.getPlugins().hasPlugin(JavaPlugin.class) && !project.getPlugins().hasPlugin(WarPlugin.class)) { logger.error("No java or war plugin detected. Enable java or war plugin."); throw new IllegalStateException("No java or war plugin detected. Enable java or war plugin."); } JSweetPluginExtension extension = project.getExtensions().create("jsweet", JSweetPluginExtension.class); JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSetContainer sourceSets = javaPluginConvention.getSourceSets(); SourceSet mainSources = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); JSweetTranspileTask task = project.getTasks().create("jsweet", JSweetTranspileTask.class); task.setConfiguration(extension); task.setSources(mainSources.getAllJava()); task.setClasspath(mainSources.getCompileClasspath()); JSweetCleanTask cleanTask = project.getTasks().create("jsweetClean", JSweetCleanTask.class); cleanTask.setConfiguration(extension); } }
@Override public FileCollection call() throws Exception { final SourceSet mainSourceSet = getMainSourceSet(); return project.files(mainSourceSet.getAllJava().getSrcDirs()).plus(project.files(mainSourceSet.getOutput().getResourcesDir())); }});
@Override protected void configureForSourceSet(SourceSet sourceSet, NoActionVerificationTask task) { task.setSource(sourceSet.getAllJava()); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classes", new Callable<FileCollection>() { @Override public FileCollection call() { return project.fileTree(sourceSet.getOutput().getClassesDir()).builtBy(sourceSet.getOutput()); } }); for (Task classesTask : project.getTasksByName(sourceSet.getClassesTaskName(), false)) { classesTask.finalizedBy(task.getPath()); } }
@Override protected void configureForSourceSet(final SourceSet sourceSet, SpotBugsTask task) { task.setDescription("Run SpotBugs analysis for " + sourceSet.getName() + " classes"); task.setSource(sourceSet.getAllJava()); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classes", new Callable<FileCollection>() { @Override public FileCollection call() { ConfigurableFileTree fileTree = StreamSupport.stream(sourceSet.getOutput().getClassesDirs().spliterator(), false) .map(project::fileTree) .reduce((lhs, rhs) -> { lhs.plus(rhs); return lhs; }).orElseThrow(() -> new InvalidUserDataException("No classes dir configured for source set " + sourceSet.getName()) ); return fileTree.builtBy(sourceSet.getClassesTaskName()); } }); taskMapping.map("classpath", new Callable<FileCollection>() { @Override public FileCollection call() { return sourceSet.getCompileClasspath(); } }); } }
protected void createSourcesJars(final Project project) { final JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); Task sourcesJar = project.getTasks().create("sourcesJar", Jar.class, jar -> { jar.setDescription("Creates a jar with the sources"); jar.setClassifier("sources"); jar.from(javaPluginConvention.getSourceSets().getByName("main").getAllSource()); }); Task javadocJar = project.getTasks().create("javadocJar", Jar.class, jar -> { jar.setDescription("Creates a javadoc jar"); jar.setClassifier("javadoc"); Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME); jar.from(javadoc.getDestinationDir()); jar.dependsOn(javadoc); }); Task testsJar = project.getTasks().create("testsJar", Jar.class, jar -> { jar.setDescription("Creates a jar containing all the source and classes for the tests"); jar.setClassifier("tests"); SourceSet test = javaPluginConvention.getSourceSets().getByName("test"); jar.from(test.getAllJava()); jar.from(test.getOutput()); }); project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, sourcesJar); project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, javadocJar); project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, testsJar); }
public void execute(final SourceSet sourceSet) { FregeSourceSetDirectoryFactory factory = new FregeSourceSetDirectoryFactory((ProjectInternal) project, fileResolver); final DefaultFregeSourceSet fregeSourceSet = new DefaultFregeSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), factory); new DslObject(sourceSet).getConvention().getPlugins().put("frege", fregeSourceSet); final String defaultSourcePath = String.format("src/%s/frege", sourceSet.getName()); fregeSourceSet.getFrege().srcDir(defaultSourcePath); sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() { public boolean isSatisfiedBy(FileTreeElement element) { return fregeSourceSet.getFrege().contains(element.getFile()); } }); sourceSet.getAllJava().source(fregeSourceSet.getFrege()); sourceSet.getAllSource().source(fregeSourceSet.getFrege()); String compileTaskName = sourceSet.getCompileTaskName("frege"); FregeCompile compile = project.getTasks().create(compileTaskName, FregeCompile.class); compile.setModule(project.file(defaultSourcePath).getAbsolutePath()); javaBasePlugin.configureForSourceSet(sourceSet, compile); compile.getConventionMapping().map("fregepath", new Callable() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); compile.dependsOn(sourceSet.getCompileJavaTaskName()); compile.setDescription(String.format("Compiles the %s Frege source.", sourceSet.getName())); compile.setSource(fregeSourceSet.getFrege()); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName); sourceSet.compiledBy(compile); } });
.getSourceSets() .all(sourceSet -> allJavaFiles.from( sourceSet.getAllJava().filter(file -> !file.toString().contains("/generated"))));
FileCollection sources = project.files(mainSourceSet.getAllJava().getSrcDirs()); addClassPath(mainSourceSet.getAllJava().getSrcDirs()); addClassPath(mainSourceSet.getCompileClasspath().getAsPath()); addClassPath(sdmConf.getAsPath());
FileCollection sources = project.files(mainSourceSet.getAllJava().getSrcDirs()); addClassPath(mainSourceSet.getAllJava().getSrcDirs()); addClassPath(mainSourceSet.getCompileClasspath().getAsPath()); addClassPath(sdmConf.getAsPath());
delombok.getEncoding().set(compileTaskProvider.get().getOptions().getEncoding()); delombok.getClasspath().from(sourceSet.getCompileClasspath()); delombok.getInput().from(sourceSet.getAllJava().getSourceDirectories()); }); });