/** 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 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); } }
static void mutateArgs(Project project, String moduleName, Consumer<String> consumer) { var javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); var testSourceSet = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); var files = testSourceSet.getAllSource().matching(f -> f.include("module-info.test")); if (files.isEmpty()) { LOGGER.debug("File 'module-info.test' is not present in {}", project); return; } var moduleInfoTestPath = files.getSingleFile().toPath(); LOGGER.debug("Using lines of '{}' to patch module {}...", moduleInfoTestPath, moduleName); try (var lines = Files.lines(moduleInfoTestPath)) { lines.map(String::trim) // .filter(line -> !line.isEmpty()) // .filter(line -> !line.startsWith("//")) // .peek(line -> LOGGER.debug(" {}", line)) // .forEach(consumer); } catch (IOException e) { throw new UncheckedIOException("Reading " + moduleInfoTestPath + " failed", e); } } }
private void includeSourcesForTest(Project project) { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourset = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet testSourset = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); FileCollection testClasspath = project .files(mainSourset.getAllSource().getSrcDirs().toArray()) .plus(project.files(testSourset.getAllSource().getSrcDirs().toArray())) .plus(testSourset.getRuntimeClasspath()); testSourset.setRuntimeClasspath(testClasspath); Test test = project.getTasks().withType(Test.class).getByName("test"); test.getSystemProperties().put("gwt.persistentunitcachedir", project.getBuildDir() + "/putnami/test"); }
public void execute(Jar jar) { jar.from(java.getSourceSets().getByName("main").getAllSource()); jar.setClassifier("sources"); jar.with(license); } });
private void includeSourcesToJar(Project project) { Jar jarTask = project.getTasks() .withType(Jar.class) .getByName("jar"); JavaPluginConvention javaConvention = project.getConvention() .getPlugin(JavaPluginConvention.class); SourceSet mainSourset = javaConvention.getSourceSets() .getByName("main"); jarTask.from(mainSourset.getAllSource()); }
private void includeSourcesToJar(Project project) { Jar jarTask = project.getTasks().withType(Jar.class).getByName("jar"); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourset = javaConvention.getSourceSets().getByName("main"); jarTask.from(mainSourset.getAllSource()); }
@Override public void execute(Project project) { JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class); PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); Task sourceJar = project.getTasks().create("sourceJar", Jar.class, jar -> { jar.from(java.getSourceSets().getByName("main").getAllSource()); }); publishing.publications(publications -> { publications.create("mavenJava", MavenPublication.class, publication -> { publication.artifact(sourceJar, artifact -> { artifact.setClassifier("sources"); }); }); }); } }
private void includeSourcesForTest(Project project) { JavaPluginConvention javaConvention = project.getConvention() .getPlugin(JavaPluginConvention.class); SourceSet mainSourset = javaConvention.getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet testSourset = javaConvention.getSourceSets() .getByName(SourceSet.TEST_SOURCE_SET_NAME); FileCollection testClasspath = project.files(mainSourset.getAllSource() .getSrcDirs().toArray()) .plus(project.files(testSourset .getAllSource() .getSrcDirs() .toArray())) .plus(testSourset .getRuntimeClasspath()); testSourset.setRuntimeClasspath(testClasspath); Test test = project.getTasks().withType(Test.class).getByName("test"); test.getSystemProperties() .put("gwt.persistentunitcachedir", project.getBuildDir() + GwtExtension.DIRECTORY + "/test"); }
private void configureDev(Project project, JavaPluginConvention javaConvention) { SourceSet main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet test = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); SourceSet dev = javaConvention.getSourceSets().create(DEV_SOURCE_SET_NAME); dev.setCompileClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(dev.getCompileClasspathConfigurationName()))); dev.setRuntimeClasspath(project.files(dev.getAllSource().getSourceDirectories(), test.getAllSource().getSourceDirectories(), main.getAllSource().getSourceDirectories(), project.getConfigurations().getByName(dev.getRuntimeClasspathConfigurationName()))); Stream.<Function<SourceSet, String>>of(SourceSet::getCompileConfigurationName, SourceSet::getImplementationConfigurationName, SourceSet::getRuntimeConfigurationName, SourceSet::getRuntimeOnlyConfigurationName).forEach(getter -> { Configuration devConf = project.getConfigurations().getByName(getter.apply(dev)); Configuration testConf = project.getConfigurations().getByName(getter.apply(test)); devConf.extendsFrom(testConf); }); project.getTasks().create("clojureRepl", ClojureNRepl.class, task -> { task.setGroup("run"); task.setDescription("Starts an nREPL server."); task.setClasspath(dev.getRuntimeClasspath()); }); } }
private Collection<File> listProjectDepsSrcDirs(Project project) { ConfigurationContainer configs = project.getConfigurations(); Configuration compileConf = configs.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME); DependencySet depSet = compileConf.getAllDependencies(); List<File> result = Lists.newArrayList(); for (Dependency dep : depSet) { if (dep instanceof ProjectDependency) { Project projectDependency = ((ProjectDependency) dep).getDependencyProject(); if (projectDependency.getPlugins().hasPlugin(GwtLibPlugin.class)) { JavaPluginConvention javaConvention = projectDependency.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); result.addAll(mainSourceSet.getAllSource().getSrcDirs()); } } } return result; }
@Override public void apply(final Project project) { project.getPlugins().apply("java"); final CopySpec license = project.copySpec(copy -> copy.from(project.getRootDir()).include("LICENSE")); ((Jar) project.getTasks().getByName("jar")).with(license); final Jar sourcesJar = project.getTasks().create(SOURCES_JAR_TASK, Jar.class, jar -> { jar.from(JavaPluginUtil.getMainSourceSet(project).getAllSource()); jar.setClassifier("sources"); jar.with(license); }); final Task javadocJar = project.getTasks().create(JAVADOC_JAR_TASK, Jar.class, jar -> { jar.from(project.getTasks().getByName("javadoc")); jar.setClassifier("javadoc"); jar.with(license); }); project.getArtifacts().add("archives", sourcesJar); project.getArtifacts().add("archives", javadocJar); } }
private Collection<File> listProjectDepsSrcDirs(Project project) { ConfigurationContainer configs = project.getConfigurations(); Configuration compileConf = configs.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME); DependencySet depSet = compileConf.getAllDependencies(); List<File> result = Lists.newArrayList(); for (Dependency dep : depSet) { if (dep instanceof ProjectDependency) { Project projectDependency = ((ProjectDependency) dep).getDependencyProject(); if (projectDependency.getPlugins().hasPlugin(PwtLibPlugin.class)) { JavaPluginConvention javaConvention = projectDependency.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); result.addAll(mainSourceSet.getAllSource().getSrcDirs()); } } } return result; }
@Override public void apply(final Project project) { project.getPlugins().apply("java"); final CopySpec license = project.copySpec(copy -> copy.from(project.getRootDir()).include("LICENSE")); ((Jar) project.getTasks().getByName("jar")).with(license); final Jar sourcesJar = project.getTasks().create(SOURCES_JAR_TASK, Jar.class, jar -> { jar.from(JavaPluginUtil.getMainSourceSet(project).getAllSource()); jar.setClassifier("sources"); jar.with(license); }); final Task javadocJar = project.getTasks().create(JAVADOC_JAR_TASK, Jar.class, jar -> { jar.from(project.getTasks().getByName("javadoc")); jar.setClassifier("javadoc"); jar.with(license); }); project.getArtifacts().add("archives", sourcesJar); project.getArtifacts().add("archives", javadocJar); } }
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { _project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { GosuSourceSet gosuSourceSet = new DefaultGosuSourceSet(sourceSet.getName(), _sourceDirectorySetFactory); Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention"); sourceSetConvention.getPlugins().put("gosu", gosuSourceSet); gosuSourceSet.getGosu().srcDir("src/" + sourceSet.getName() + "/gosu"); sourceSet.getResources().getFilter().exclude(element -> gosuSourceSet.getGosu().contains(element.getFile())); sourceSet.getAllSource().source(gosuSourceSet.getGosu()); configureGosuCompile(javaBasePlugin, sourceSet, gosuSourceSet); }); }
private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) { _project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all( sourceSet -> { DefaultGosuSourceSet gosuSourceSet = new DefaultGosuSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), _fileResolver); new DslObject(sourceSet).getConvention().getPlugins().put("gosu", gosuSourceSet); gosuSourceSet.getGosu().srcDir("src/" + sourceSet.getName() + "/gosu"); sourceSet.getResources().getFilter().exclude( element -> { return gosuSourceSet.getGosu().contains(element.getFile()); }); sourceSet.getAllSource().source(gosuSourceSet.getGosu()); configureGosuCompile(javaBasePlugin, sourceSet, gosuSourceSet); }); }
private void addSourceSet(ConfigurableFileCollection sources, Project project, String sourceSet) { JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class); if (javaConvention != null) { SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(sourceSet); sources .from(project.files(mainSourceSet.getOutput().getResourcesDir())) .from(project.files(mainSourceSet.getOutput().getClassesDirs())) .from(project.files(mainSourceSet.getAllSource().getSrcDirs())); } }
private void addSourceSet(FileCollection sources, Project project, String sourceSet) { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(sourceSet); sources.add(project.files(mainSourceSet.getOutput().getResourcesDir())) .plus(project.files(mainSourceSet.getOutput().getClassesDirs())) .plus(project.files(mainSourceSet.getAllSource().getSrcDirs())); }
private void configureSourceSetDefaults(Project project, ClojureExtension extension) { project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { ClojureSourceSet clojureSourceSet = new DefaultClojureSourceSet("clojure", sourceDirectorySetFactory); new DslObject(sourceSet).getConvention().getPlugins().put("clojure", clojureSourceSet); clojureSourceSet.getClojure().srcDir(String.format("src/%s/clojure", sourceSet.getName())); // in case the clojure source overlaps with the resources source sourceSet.getResources().getFilter().exclude(element -> clojureSourceSet.getClojure().contains(element.getFile())); sourceSet.getAllSource().source(clojureSourceSet.getClojure()); ClojureBuild build = extension.getBuilds().create(sourceSet.getName()); build.getSourceSet().set(sourceSet); ((DefaultSourceSetOutput) sourceSet.getOutput()).addClassesDir(() -> build.getOutputDir().get().getAsFile()); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(build.getTaskName("compile")); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(build.getTaskName("check")); sourceSet.getOutput().dir(project.provider(() -> { if (build.isCompilerConfigured()) { return clojureSourceSet.getClojure().getSourceDirectories(); } else { return build.getOutputDir(); } })); }); }
private void configureSourceSetDefaults(Project project, ClojureScriptExtension extension) { project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all((SourceSet sourceSet) -> { ClojureScriptSourceSet clojurescriptSourceSet = new DefaultClojureScriptSourceSet("clojurescript", sourceDirectorySetFactory); new DslObject(sourceSet).getConvention().getPlugins().put("clojurescript", clojurescriptSourceSet); clojurescriptSourceSet.getClojureScript().srcDir(String.format("src/%s/clojurescript", sourceSet.getName())); // in case the clojure source overlaps with the resources source sourceSet.getResources().getFilter().exclude(element -> clojurescriptSourceSet.getClojureScript().contains(element.getFile())); sourceSet.getAllSource().source(clojurescriptSourceSet.getClojureScript()); ClojureScriptBuild build = extension.getBuilds().create(sourceSet.getName()); build.getSourceSet().set(sourceSet); sourceSet.getOutput().dir(build.getOutputDir()); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(build.getTaskName("compile")); sourceSet.getOutput().dir(project.provider(() -> { if (build.isCompilerConfigured()) { return clojurescriptSourceSet.getClojureScript().getSourceDirectories(); } else { return build.getOutputDir(); } })); }); }