public void apply(final Project project) { project.getPluginManager().apply(JavaBasePlugin.class); final OsgiPluginConvention osgiConvention = new OsgiPluginConvention((ProjectInternal) project); project.getConvention().getPlugins().put("osgi", osgiConvention); project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() { @Override public void execute(JavaPlugin javaPlugin) { OsgiManifest osgiManifest = osgiConvention.osgiManifest(); osgiManifest.setClassesDir(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main").getOutput().getClassesDir()); osgiManifest.setClasspath(project.getConfigurations().getByName("runtime")); Jar jarTask = (Jar) project.getTasks().getByName("jar"); jarTask.setManifest(osgiManifest); } }); }
private static void configureScaladoc(final Project project, final ScalaRuntime scalaRuntime) { project.getTasks().withType(ScalaDoc.class, new Action<ScalaDoc>() { @Override public void execute(final ScalaDoc scalaDoc) { scalaDoc.getConventionMapping().map("destinationDir", new Callable<File>() { @Override public File call() throws Exception { File docsDir = project.getConvention().getPlugin(JavaPluginConvention.class).getDocsDir(); return project.file(docsDir.getPath() + "/scaladoc"); } }); scalaDoc.getConventionMapping().map("title", new Callable<String>() { @Override public String call() throws Exception { return project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle(); } }); scalaDoc.getConventionMapping().map("scalaClasspath", new Callable<FileCollection>() { @Override public FileCollection call() throws Exception { return scalaRuntime.inferScalaClasspath(scalaDoc.getClasspath()); } }); } }); }
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()); }); }
public void registerInSourceSets(String ...sourceSetNames) { if (sourceSetNames == null || sourceSetNames.length == 0) return; try { JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class); if (javaPlugin == null) { throw new GradleException("You must apply the java plugin if you're using 'registerInSourceSets' functionality."); } for (String sourceSet : sourceSetNames) { javaPlugin.getSourceSets().getByName(sourceSet).getOutput().dir( Collections.singletonMap("builtBy", this), getOutDir() ); } } catch (Exception e) { throw new GradleException("You must apply the java plugin if you're using 'registerInSourceSets' functionality."); } }
@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.setGroup("generate"); task.dependsOn(JavaPlugin.COMPILE_JAVA_TASK_NAME); task.setConfiguration(extension); task.setSources(mainSources.getAllJava()); task.setClasspath(mainSources.getCompileClasspath()); JSweetCleanTask cleanTask = project.getTasks().create("jsweetClean", JSweetCleanTask.class); cleanTask.setConfiguration(extension); }
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; }
public EnunciateTask() { log = getLogger(); classpathConfigName = getProject().getObjects().property(String.class); classpathConfigName.set("compileClasspath"); javaPluginConvention = getProject().getConvention().findPlugin(JavaPluginConvention.class); dependsOn(getProject().getTasks().getByName("classes")); mainSourceSet = javaPluginConvention.getSourceSets().findByName("main"); sourcePath = getProject().files(); getInputs().files(lazyGetMatchingSourceFiles()); getInputs().file(lazyGetConfigFile()); getOutputs().dir(lazyGetBuildDir()); }
private List<String> buildCompilerArgs(JavaPluginConvention javaPluginConvention) { TaskCollection<JavaCompile> javaCompilers = getProject().getTasks().withType(JavaCompile.class); CompileOptions firstCompilerOptions = javaCompilers.isEmpty() ? null : javaCompilers.iterator().next().getOptions(); List<String> args = new ArrayList<>(Arrays.asList("-source", javaPluginConvention.getSourceCompatibility().toString(), "-target", javaPluginConvention.getTargetCompatibility().toString(), "-encoding", getDefaultOrCompilerEncoding(firstCompilerOptions))); if (firstCompilerOptions != null) { FileCollection bootClasspath = firstCompilerOptions.getBootstrapClasspath(); if (bootClasspath != null) { args.add("-bootclasspath"); args.add(bootClasspath.getAsPath()); } } return args; }
/** 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 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; } // LicenseHeaderStep completely blows apart package-info.java - this common-sense check ensures that // it skips package-info.java. See https://github.com/diffplug/spotless/issues/1 steps.replaceAll(step -> { if (LicenseHeaderStep.name().equals(step.getName())) { return step.filterByFile(SerializableFileFilter.skipFilesNamed("package-info.java")); } else { return step; } }); 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); }
@Override public void configureFor(@Nonnull final DependencyConfig pDepConfig) { final Project project = getProject(); final JavaVersion javaLevel = pDepConfig.getJavaLevel(); setDescription( buildUtil.getLongName() + ": Generate Javadoc API documentation for dependency configuration '" + pDepConfig .getName() + "' (Java level: " + javaLevel + ")"); dependsOn(buildUtil.getTask(TaskNames.compileJava, pDepConfig)); final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); setDestinationDir(new File(javaConvention.getDocsDir(), getName())); configureJavadocTask(this, pDepConfig); final JavaLevelUtil javaLevelUtil = new JavaLevelUtil(project); if (javaLevelUtil.isOlderSupportedJava(javaLevel)) { setExecutable(javaLevelUtil.getJavadocExecutable(javaLevel)); } }
public void establishSonarQubeSourceSet() { final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); final SourceSetContainer sourceSets = javaConvention.getSourceSets(); final ConfigurationContainer configs = project.getConfigurations(); final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME); final SourceSet sqSourceSet = sourceSets.create(BuildUtil.SONARQUBE_SOURCE_SET_NAME); configs.getByName(testSourceSet.getImplementationConfigurationName()).extendsFrom( configs.getByName(sqSourceSet.getImplementationConfigurationName())); configs.getByName(testSourceSet.getRuntimeOnlyConfigurationName()).extendsFrom( configs.getByName(sqSourceSet.getRuntimeOnlyConfigurationName())); final TaskContainer tasks = project.getTasks(); tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).dependsOn( tasks.getByName(sqSourceSet.getClassesTaskName())); final FileCollection sqOutputs = sqSourceSet.getOutput().getClassesDirs().plus( project.files(sqSourceSet.getOutput().getResourcesDir())); testSourceSet.setCompileClasspath(testSourceSet.getCompileClasspath().plus(sqOutputs)); testSourceSet.setRuntimeClasspath(testSourceSet.getRuntimeClasspath().plus(sqOutputs)); }
private void configureWithJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention, PluginContainer plugins) { plugins.withType(JavaPlugin.class, new Action<JavaPlugin>() { public void execute(JavaPlugin javaPlugin) { final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class); SourceSet sourceSet = javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); sourceSet.getResources().srcDir(new Callable() { public Object call() throws Exception { return earPluginConvention.getAppDirName(); } }); project.getTasks().withType(Ear.class, new Action<Ear>() { public void execute(final Ear task) { task.dependsOn(new Callable<FileCollection>() { public FileCollection call() throws Exception { return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME) .getRuntimeClasspath(); } }); task.from(new Callable<FileCollection>() { public FileCollection call() throws Exception { return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput(); } }); } }); } }); }
private static void configureSourceSetDefaults(final Project project, final SourceDirectorySetFactory sourceDirectorySetFactory) { final JavaBasePlugin javaPlugin = project.getPlugins().getPlugin(JavaBasePlugin.class); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() { @Override public void execute(final SourceSet sourceSet) { String displayName = (String) InvokerHelper.invokeMethod(sourceSet, "getDisplayName", null); Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention"); DefaultScalaSourceSet scalaSourceSet = new DefaultScalaSourceSet(displayName, sourceDirectorySetFactory); sourceSetConvention.getPlugins().put("scala", scalaSourceSet); final SourceDirectorySet scalaDirectorySet = scalaSourceSet.getScala(); scalaDirectorySet.srcDir(new Callable<File>() { @Override public File call() throws Exception { return project.file("src/" + sourceSet.getName() + "/scala"); } }); sourceSet.getAllJava().source(scalaDirectorySet); sourceSet.getAllSource().source(scalaDirectorySet); sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() { @Override public boolean isSatisfiedBy(FileTreeElement element) { return scalaDirectorySet.contains(element.getFile()); } }); configureScalaCompile(project, javaPlugin, sourceSet); } }); }
private void addDefaultReportTask(final JacocoPluginExtension extension, final Test task) { final JacocoReport reportTask = project.getTasks().create("jacoco" + StringUtils.capitalise(task.getName()) + "Report", JacocoReport.class); reportTask.executionData(task); reportTask.sourceSets(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main")); ConventionMapping taskMapping = ((IConventionAware) reportTask).getConventionMapping(); taskMapping.getConventionValue(reportTask.getReports(), "reports", false).all(new Action<Report>() { @Override public void execute(final Report report) { ConventionMapping reportMapping = ((IConventionAware) report).getConventionMapping(); // reportMapping.map('enabled', Callables.returning(true)); if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) { reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), task.getName() + "/" + report.getName()); } }); } else { reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), task.getName() + "/" + reportTask.getName() + "." + report.getName()); } }); } } }); }
private void configureTaskPropertiesValidation(Project project) { ValidateTaskProperties validator = project.getTasks().create(VALIDATE_TASK_PROPERTIES_TASK_NAME, ValidateTaskProperties.class); File reportsDir = new File(project.getBuildDir(), "reports"); File validatorReportsDir = new File(reportsDir, "task-properties"); validator.setOutputFile(new File(validatorReportsDir, "report.txt")); SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); validator.setClasspath(mainSourceSet.getCompileClasspath()); validator.setClassesDir(mainSourceSet.getOutput().getClassesDir()); validator.dependsOn(mainSourceSet.getOutput()); project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(validator); }
private void appendModule(Map<String, DefaultIdeaModule> modules, IdeaModule ideaModule, DefaultIdeaProject ideaProject, DefaultGradleProject rootGradleProject) { DefaultIdeaContentRoot contentRoot = new DefaultIdeaContentRoot() .setRootDirectory(ideaModule.getContentRoot()) .setSourceDirectories(srcDirs(ideaModule.getSourceDirs(), ideaModule.getGeneratedSourceDirs())) .setTestDirectories(srcDirs(ideaModule.getTestSourceDirs(), ideaModule.getGeneratedSourceDirs())) .setExcludeDirectories(ideaModule.getExcludeDirs()); Project project = ideaModule.getProject(); DefaultIdeaModule defaultIdeaModule = new DefaultIdeaModule() .setName(ideaModule.getName()) .setParent(ideaProject) .setGradleProject(rootGradleProject.findByPath(ideaModule.getProject().getPath())) .setContentRoots(Collections.singletonList(contentRoot)) .setCompilerOutput(new DefaultIdeaCompilerOutput() .setInheritOutputDirs(ideaModule.getInheritOutputDirs() != null ? ideaModule.getInheritOutputDirs() : false) .setOutputDir(ideaModule.getOutputDir()) .setTestOutputDir(ideaModule.getTestOutputDir())); JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class); if (javaPluginConvention != null) { final IdeaLanguageLevel ideaModuleLanguageLevel = ideaModule.getLanguageLevel(); JavaVersion moduleSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(ideaModuleLanguageLevel); JavaVersion moduleTargetBytecodeVersion = ideaModule.getTargetBytecodeVersion(); defaultIdeaModule.setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings() .setSourceLanguageLevel(moduleSourceLanguageLevel) .setTargetBytecodeVersion(moduleTargetBytecodeVersion)); } modules.put(ideaModule.getName(), defaultIdeaModule); }
private void configureSourceSetDefaults(Project project) { 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, exclude any clojure code // from resources sourceSet.getResources().getFilter().exclude(element -> clojureSourceSet.getClojure().contains(element.getFile())); sourceSet.getAllSource().source(clojureSourceSet.getClojure()); String compileTaskName = sourceSet.getCompileTaskName("clojure"); ClojureCompile compile = project.getTasks().create(compileTaskName, ClojureCompile.class); compile.setDescription(String.format("Compiles the %s Clojure source.", sourceSet.getName())); compile.setSource(clojureSourceSet.getClojure()); // TODO presumably at some point this will allow providers, so we should switch to that // instead of convention mapping compile.getConventionMapping().map("classpath", () -> { return sourceSet.getCompileClasspath() .plus(project.files(sourceSet.getJava().getOutputDir())) .plus(project.files(sourceSet.getOutput().getResourcesDir())); }); // TODO switch to provider compile.getConventionMapping().map("namespaces", compile::findNamespaces); SourceSetUtil.configureOutputDirectoryForSourceSet(sourceSet, clojureSourceSet.getClojure(), compile, project); compile.dependsOn(project.getTasks().getByName(sourceSet.getCompileJavaTaskName())); compile.dependsOn(project.getTasks().getByName(sourceSet.getProcessResourcesTaskName())); project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compile); }); }
@Override public void apply(Project project) { project.getPlugins().apply(ClojureBasePlugin.class); project.getPlugins().apply(JavaPlugin.class); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); configureTest(project, javaConvention); configureDev(project, javaConvention); }
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); }
@Override public void apply(Project project) { jSassBasePlugin = project.getPlugins().apply(JSassBasePlugin.class); project.getPlugins().apply(JavaPlugin.class); project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> { String taskName = sourceSet.getTaskName("compile", "Sass"); Set<File> srcDirs = sourceSet.getResources().getSrcDirs(); int i = 1; for (File srcDir : srcDirs) { SassCompile sassCompile = project.getTasks().create(i == 1 ? taskName : taskName + i, SassCompile.class); i++; sassCompile.setGroup(BasePlugin.BUILD_GROUP); sassCompile.setDescription("Compile sass and scss files for the " + sourceSet.getName() + " source set"); sassCompile.setSourceDir(srcDir); Copy processResources = (Copy) project.getTasks().getByName(sourceSet.getProcessResourcesTaskName()); sassCompile.getConventionMapping().map("destinationDir", () -> { if (jSassBasePlugin.getExtension().isInplace()) { return srcDir; } else { return processResources.getDestinationDir(); } }); processResources.dependsOn(sassCompile); } }); }
@Override public void apply(Project project) { project.getExtensions().create("web", WebExtension.class); project.getPlugins().apply(NodePlugin.class); project.getPlugins().apply(JavaLibraryPlugin.class); JavaPluginConvention java = project.getConvention().getPlugin(JavaPluginConvention.class); java.getSourceSets() .getByName(SourceSet.MAIN_SOURCE_SET_NAME) .getOutput() .dir(ImmutableMap.of("builtBy", "copyWeb"), "build/javaweb"); CacheableYarnTask buildWeb = project.getTasks().create("buildWeb", CacheableYarnTask.class); buildWeb.dependsOn(project.getRootProject().getTasks().findByName("yarn")); buildWeb.setArgs(ImmutableList.of("run", "build")); buildWeb.getInputs().dir("app"); buildWeb.getInputs().dir("internals"); // We assume the yarn task correctly handles up-to-date checks for node_modules, so only // need to look at yarn.lock here. buildWeb.getInputs().file(project.getRootProject().file("yarn.lock")); buildWeb.getOutputs().dir("build"); Copy copyWeb = project.getTasks().create("copyWeb", Copy.class); copyWeb.dependsOn(buildWeb); copyWeb.from("build/web"); project.afterEvaluate( p -> { ImmutableWebExtension web = project.getExtensions().getByType(WebExtension.class); copyWeb.into("build/javaweb/" + web.javaPackage().replace('.', '/')); }); }
private void addJavaDescription(final Project project, final ProjectDescriptor projectDescriptor) { project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() { @Override public void execute(JavaPlugin javaPlugin) { JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); projectDescriptor.setJavaProject(new JavaProjectDescriptor(javaConvention.getSourceCompatibility().toString(), javaConvention.getTargetCompatibility().toString())); } }); }
@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()); }); }
/** * Finalize tasks because of {@link JavaPlugin} interference * * @param tasks Task model * @param javaConvention Java conventions */ @Finalize public void finalizeIntegrationTask(ModelMap<Test> tasks, JavaPluginConvention javaConvention) { SourceSet source = javaConvention.getSourceSets().getByName(INTEGRATION_SOURCE_SET_NAME); tasks.named(INTEGRATION_SOURCE_SET_NAME, t -> { t.setClasspath(source.getRuntimeClasspath()); t.setTestClassesDirs(source.getOutput().getClassesDirs()); }); }
/** * Configure integration tests */ protected void configureIntegrationTests() { JavaPluginConvention javaConvention = getProject().getConvention().getPlugin(JavaPluginConvention.class); SourceSet integrationSources = javaConvention.getSourceSets().create(INTEGRATION_SOURCE_SET_NAME); SourceSet mainSources = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); @SuppressWarnings("deprecation") Configuration compile = getProject().getConfigurations() .getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME); @SuppressWarnings("deprecation") Configuration runtime = getProject().getConfigurations() .getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME); Configuration implementation = getProject().getConfigurations() .getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME); Configuration runtimeOnly = getProject().getConfigurations() .getByName(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME); Configuration integrationCompileClasspath = getProject().getConfigurations() .getByName(INTEGRATION_COMPILE_CLASSPATH_CONFIGURATION); Configuration integrationRuntimeClasspath = getProject().getConfigurations() .getByName(INTEGRATION_RUNTIME_CLASSPATH_CONFIGURATION); Configuration integrationImplementation = getProject().getConfigurations() .getByName(INTEGRATION_IMPLEMENTATION_CONFIGURATION); Configuration integrationCompile = getProject().getConfigurations() .getByName(INTEGRATION_COMPILE_CONFIGURATION); Configuration integrationRuntime = getProject().getConfigurations() .getByName(INTEGRATION_RUNTIME_CONFIGURATION); Configuration integrationRuntimeOnly = getProject().getConfigurations() .getByName(INTEGRATION_RUNTIME_ONLY_CONFIGURATION); integrationCompile.extendsFrom(compile); integrationImplementation.extendsFrom(implementation); integrationRuntime.extendsFrom(runtime); integrationRuntimeOnly.extendsFrom(runtimeOnly); integrationSources .setCompileClasspath(getProject().files(mainSources.getOutput(), integrationCompileClasspath)); integrationSources.setRuntimeClasspath(getProject().files(integrationSources.getOutput(), mainSources.getOutput(), integrationSources.getOutput(), integrationRuntimeClasspath)); }
private void addBootRunTask(final Project project) { final JavaPluginConvention javaConvention = project.getConvention() .getPlugin(JavaPluginConvention.class); BootRunTask run = project.getTasks().create(RUN_APP_TASK_NAME, BootRunTask.class); run.setDescription("Run the project with support for " + "auto-detecting main class and reloading static resources"); run.setGroup("application"); run.setClasspath( javaConvention.getSourceSets().findByName("main").getRuntimeClasspath()); run.getConventionMapping().map("main", new Callable<Object>() { @Override public Object call() throws Exception { if (project.hasProperty("mainClassName") && project.property("mainClassName") != null) { return project.property("mainClassName"); } ExtraPropertiesExtension extraPropertiesExtension = (ExtraPropertiesExtension) project .getExtensions().getByName("ext"); if (extraPropertiesExtension.has("mainClassName") && extraPropertiesExtension.get("mainClassName") != null) { return extraPropertiesExtension.get("mainClassName"); } return null; } }); run.getConventionMapping().map("jvmArgs", new Callable<Object>() { @Override public Object call() throws Exception { if (project.hasProperty("applicationDefaultJvmArgs")) { return project.property("applicationDefaultJvmArgs"); } return Collections.emptyList(); } }); }
private static Iterable<SourceSet> getJavaSourceSets(Project project) { JavaPluginConvention plugin = project.getConvention() .getPlugin(JavaPluginConvention.class); if (plugin == null) { return Collections.emptyList(); } return plugin.getSourceSets(); }
/** * Add Minecraft dependencies to compile time */ protected void configureCompile() { JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java"); SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); SourceSet test = javaModule.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); main.setCompileClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES))); test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES))); main.setRuntimeClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES))); test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES))); Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME); javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath())); }
public EntitasGradleProject(Project gradleProject) { this.project = gradleProject; //this.project.getPlugins().apply(JavaPlugin.class); javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); extension = project.getExtensions().findByType(CodeGenerationPluginExtension.class); if (extension == null) { extension = new CodeGenerationPluginExtension(); } }
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 configure(final Project project, final PutnamiExtension extention) { final CompilerOption options = extention.getCompile(); options.init(getProject()); options.setLocalWorkers(evalWorkers(options)); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); final FileCollection sources = getProject() .files(project.files(mainSourceSet.getOutput().getResourcesDir())) .plus(project.files(mainSourceSet.getOutput().getClassesDirs())) .plus(getProject().files(mainSourceSet.getAllSource().getSrcDirs())); ConventionMapping mapping = ((IConventionAware) this).getConventionMapping(); mapping.map("modules", new Callable<List<String>>() { @Override public List<String> call() { return extention.getModule(); } }); mapping.map("war", new Callable<File>() { @Override public File call() { return options.getWar(); } }); mapping.map("src", new Callable<FileCollection>() { @Override public FileCollection call() { return sources; } }); }
public void configure(final Project project, final PutnamiExtension extention) { final CompilerOption options = extention.getCompile(); options.init(getProject()); JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); final FileCollection sources = getProject() .files(project.files(mainSourceSet.getOutput().getResourcesDir())) .plus(project.files(mainSourceSet.getOutput().getClassesDirs())) .plus(getProject().files(mainSourceSet.getAllSource().getSrcDirs())); ConventionMapping mapping = ((IConventionAware) this).getConventionMapping(); mapping.map("modules", new Callable<List<String>>() { @Override public List<String> call() { return extention.getModule(); } }); mapping.map("war", new Callable<File>() { @Override public File call() { return new File(getProject().getBuildDir(), "out"); } }); mapping.map("src", new Callable<FileCollection>() { @Override public FileCollection call() { return sources; } }); }
@Override protected void applyOnce(Project proj) { BndManifestExtension extension = proj.getExtensions().create(BndManifestExtension.NAME, BndManifestExtension.class); proj.afterEvaluate(project -> { // find the file that the user would like us to copy to (if any) Optional<File> copyTo = Optional.ofNullable(extension.copyTo).map(proj::file); ProjectPlugin.getPlugin(project, JavaPlugin.class); Jar jarTask = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME); jarTask.deleteAllActions(); jarTask.getInputs().properties(jarTask.getManifest().getEffectiveManifest().getAttributes()); jarTask.getOutputs().file(jarTask.getArchivePath()); copyTo.ifPresent(jarTask.getOutputs()::file); jarTask.doLast(Errors.rethrow().wrap(unused -> { // find the location of the manifest in the output resources directory JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSet main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); Path outputManifest = main.getOutput().getResourcesDir().toPath().resolve("META-INF/MANIFEST.MF"); // if we don't want to merge, then delete the existing manifest so that bnd doesn't merge with it if (!extension.mergeWithExisting) { Files.deleteIfExists(outputManifest); } // take the bnd action takeBndAction(project, jar -> { // write out the jar file createParents(jarTask.getArchivePath()); jar.write(jarTask.getArchivePath()); // write out the manifest to the resources output directory for the test task (and others) writeFile(outputManifest.toFile(), jar::writeManifest); // write the manifest to copyTo, if we're supposed to if (copyTo.isPresent()) { writeFile(copyTo.get(), jar::writeManifest); } }); })::accept); }); }