private void configureReportsConventionMapping(JDepend task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", new Callable<Boolean>() { @Override public Boolean call() { return report.getName().equals("xml"); } }); reportMapping.map("destination", new Callable<File>() { @Override public File call() { final String fileSuffix = report.getName().equals("text") ? "txt" : report.getName(); return new File(extension.getReportsDir(), baseName + "." + fileSuffix); } }); } }); }
private void configureReportsConventionMapping(FindBugs task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", new Callable<Boolean>() { @Override public Boolean call() { return report.getName().equals("xml"); } }); reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), baseName + "." + report.getName()); } }); } }); }
@Override protected void configureForSourceSet(final SourceSet sourceSet, FindBugs task) { task.setDescription("Run FindBugs analysis for " + sourceSet.getName() + " classes"); task.setSource(sourceSet.getAllJava()); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classes", new Callable<FileCollection>() { @Override public FileCollection call() { // the simple "classes = sourceSet.output" may lead to non-existing resources directory // being passed to FindBugs Ant task, resulting in an error return project.fileTree(sourceSet.getOutput().getClassesDir()).builtBy(sourceSet.getOutput()); } }); taskMapping.map("classpath", new Callable<FileCollection>() { @Override public FileCollection call() { return sourceSet.getCompileClasspath(); } }); }
private void configureExtensionRule() { final ConventionMapping extensionMapping = conventionMappingOf(extension); extensionMapping.map("sourceSets", Callables.returning(new ArrayList())); extensionMapping.map("reportsDir", new Callable<File>() { @Override public File call() { return project.getExtensions().getByType(ReportingExtension.class).file(getReportName()); } }); withBasePlugin(new Action<Plugin>() { @Override public void execute(Plugin plugin) { extensionMapping.map("sourceSets", new Callable<SourceSetContainer>() { @Override public SourceSetContainer call() { return getJavaPluginConvention().getSourceSets(); } }); } }); }
private void configureReportsConventionMapping(CodeNarc task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = AbstractCodeQualityPlugin.conventionMappingOf(report); reportMapping.map("enabled", new Callable<Boolean>() { @Override public Boolean call() { return report.getName().equals(extension.getReportFormat()); } }); reportMapping.map("destination", new Callable<File>() { @Override public File call() { String fileSuffix = report.getName().equals("text") ? "txt" : report.getName(); return new File(extension.getReportsDir(), baseName + "." + fileSuffix); } }); } }); }
private OsgiManifest createDefaultOsgiManifest(final ProjectInternal project) { OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver()); ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping(); final OsgiHelper osgiHelper = new OsgiHelper(); mapping.map("version", new Callable<Object>() { public Object call() throws Exception { return osgiHelper.getVersion(project.getVersion().toString()); } }); mapping.map("name", new Callable<Object>() { public Object call() throws Exception { return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName(); } }); mapping.map("symbolicName", new Callable<Object>() { public Object call() throws Exception { return osgiHelper.getBundleSymbolicName(project); } }); return osgiManifest; }
private void configureJacocoReportDefaults(final JacocoPluginExtension extension, final JacocoReport reportTask) { reportTask.getReports().all(new Action<Report>() { @Override public void execute(final Report report) { ConventionMapping mapping = ((IConventionAware) report).getConventionMapping(); mapping.map("enabled", Callables.returning(report.getName().equals("html"))); if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) { mapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), reportTask.getName() + "/" + report.getName()); } }); } else { mapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), reportTask.getName() + "/" + reportTask.getName() + "." + report.getName()); } }); } } }); }
/** * Adds conventions to the given spec, using this settings object's default signatory and signature type as the default signatory and signature type for the spec. */ protected void addSignatureSpecConventions(SignatureSpec spec) { if (!(spec instanceof IConventionAware)) { throw new InvalidUserDataException("Cannot add conventions to signature spec \'" + String.valueOf(spec) + "\' as it is not convention aware"); } ConventionMapping conventionMapping = ((IConventionAware) spec).getConventionMapping(); conventionMapping.map("signatory", new Callable<Signatory>() { public Signatory call() { return getSignatory(); } }); conventionMapping.map("signatureType", new Callable<SignatureType>() { public SignatureType call() { return getSignatureType(); } }); conventionMapping.map("required", new Callable<Boolean>() { public Boolean call() { return isRequired(); } }); }
private void createCompileJavaTaskForBinary(final SourceSet sourceSet, SourceDirectorySet javaSourceSet, Project target) { JavaCompile compileTask = target.getTasks().create(sourceSet.getCompileJavaTaskName(), JavaCompile.class); compileTask.setDescription("Compiles " + javaSourceSet + "."); compileTask.setSource(javaSourceSet); ConventionMapping conventionMapping = compileTask.getConventionMapping(); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getOutput().getClassesDir(); } }); }
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) { ConventionMapping conventionMapping; compile.setDescription("Compiles the " + sourceSet.getJava() + "."); conventionMapping = compile.getConventionMapping(); compile.setSource(sourceSet.getJava()); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getOutput().getClassesDir(); } }); }
@Override public void apply(Project project) { this.extension = project.getExtensions().create("jSass", JSassExtension.class); project.getTasks().withType(SassCompile.class, compileSass -> { ConventionMapping conventionMapping = compileSass.getConventionMapping(); conventionMapping.map("indent", () -> extension.getIndent()); conventionMapping.map("linefeed", () -> extension.getLinefeed()); conventionMapping.map("omitSourceMapUrl", () -> extension.isOmitSourceMapUrl()); conventionMapping.map("outputStyle", () -> extension.getOutputStyle()); conventionMapping.map("precision", () -> extension.getPrecision()); conventionMapping.map("sourceComments", () -> extension.isSourceComments()); conventionMapping.map("sourceMapContents", () -> extension.isSourceMapContents()); conventionMapping.map("sourceMapEmbed", () -> extension.isSourceMapEmbed()); conventionMapping.map("sourceMapEnabled", () -> extension.isSourceMapEnabled()); }); }
/** * Create Eclipse annotations tasks * * @param tasks Task container * @param configurations Container to access configurations * @param buildDir Build directory */ @Mutate public void createEclipseAnnotationsTasks(ModelMap<Task> tasks, ConfigurationContainer configurations, @Path("buildDir") File buildDir) { tasks.create("eclipseAnnotations", EclipseAnnotationsTask.class, t -> { t.setDescription("Generates external nullability annotations for dependencies."); t.setGroup("IDE"); ConventionMapping parameters = t.getConventionMapping(); parameters.map("jars", () -> { Set<File> jars = configurations.stream() .filter(c -> c.isCanBeResolved() && !c.getName().equals(JavaConfigPlugin.ANNOTATIONS_CONFIGURATION)) .map(c -> c.getResolvedConfiguration().getLenientConfiguration()) .flatMap(c -> c.getArtifacts().stream().filter( a -> !(a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) && a.getType().equals("jar")) .map(a -> a.getFile())) .collect(Collectors.toSet()); return jars; }); }); }
@Override protected void configureForVariant(final BaseVariant variant, FindBugs task) { task.setDescription("Run FindBugs analysis for " + variant.getName() + " classes"); task.setSource(getAllJava(variant)); task.dependsOn(variant.getJavaCompile()); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classes", () -> { // the simple "classes = sourceSet.output" may lead to non-existing resources directory // being passed to FindBugs Ant task, resulting in an error List<String> generatedClasses = new LinkedList<>(); variant.getJavaCompile().getSource().visit(fileVisitDetails -> { if (!fileVisitDetails.isDirectory() && fileVisitDetails.getPath().endsWith(".java") && fileVisitDetails.getFile().getAbsolutePath().startsWith(project.getBuildDir().getAbsolutePath())) { generatedClasses.add(fileVisitDetails.getPath().replace(".java", "")); } }); return getOutput(variant) .filter(file -> generatedClasses.parallelStream().noneMatch(generatedClass -> file.getAbsolutePath().endsWith(generatedClass + ".class") || file.getAbsolutePath().contains(generatedClass + "$"))); }); taskMapping.map("classpath", () -> getCompileClasspath(variant)); }
private void createGeneratePomTask(CollectionBuilder<Task> tasks, final MavenPublicationInternal publication, String publicationName) { String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName)); tasks.create(descriptorTaskName, GenerateMavenPom.class, new Action<GenerateMavenPom>() { public void execute(final GenerateMavenPom generatePomTask) { generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName())); generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); generatePomTask.setPom(publication.getPom()); ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping(); descriptorTaskConventionMapping.map("destination", new Callable<Object>() { public Object call() throws Exception { return new File(generatePomTask.getProject().getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml"); } }); // Wire the generated pom into the publication. publication.setPomFile(generatePomTask.getOutputs().getFiles()); } }); }
/** * Preconfigures the specified compile task based on the specified source set and class directory binary. * * @param compile the compile task to be preconfigured * @param sourceSet the source set for the compile task * @param binary the binary for the compile task */ public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinarySpec binary) { compile.setDescription(String.format("Compiles %s.", sourceSet)); compile.setSource(sourceSet.getSource()); compile.dependsOn(sourceSet); ConventionMapping conventionMapping = compile.getConventionMapping(); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath().getFiles(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return binary.getClassesDir(); } }); }
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) { ConventionMapping conventionMapping; compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava())); conventionMapping = compile.getConventionMapping(); compile.setSource(sourceSet.getJava()); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getOutput().getClassesDir(); } }); }
private void createGeneratePomTask(final MavenPublicationInternal publication, String publicationName) { String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName)); GenerateMavenPom generatePomTask = project.getTasks().create(descriptorTaskName, GenerateMavenPom.class); generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName())); generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); generatePomTask.setPom(publication.getPom()); ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping(); descriptorTaskConventionMapping.map("destination", new Callable<Object>() { public Object call() throws Exception { return new File(project.getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml"); } }); // Wire the generated pom into the publication. publication.setPomFile(generatePomTask.getOutputs().getFiles()); }
/** * Preconfigures the specified compile task based on the specified source set and class directory binary. * * @param compile the compile task to be preconfigured * @param sourceSet the source set for the compile task * @param binary the binary for the compile task */ public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinary binary) { compile.setDescription(String.format("Compiles %s.", sourceSet)); compile.setSource(sourceSet.getSource()); compile.dependsOn(sourceSet); ConventionMapping conventionMapping = compile.getConventionMapping(); conventionMapping.map("classpath", new Callable<Object>() { public Object call() throws Exception { return sourceSet.getCompileClasspath().getFiles(); } }); conventionMapping.map("destinationDir", new Callable<Object>() { public Object call() throws Exception { return binary.getClassesDir(); } }); }
private void configureDefaultReportTask( final Test test, JGivenReportTask reportTask, final ReportingExtension reportingExtension ) { ConventionMapping mapping = ( (IConventionAware) reportTask ).getConventionMapping(); mapping.map( "results", new Callable<File>() { @Override public File call() { return test.getExtensions().getByType( JGivenTaskExtension.class ).getResultsDir(); } } ); mapping.getConventionValue( reportTask.getReports(), "reports", false ).all( new Action<Report>() { @Override public void execute( final Report report ) { ConventionMapping reportMapping = ( (IConventionAware) report ).getConventionMapping(); reportMapping.map( "destination", new Callable<File>() { @Override public File call() { return reportingExtension.file( "jgiven" + "/" + test.getName() + "/" + report.getName() ); } } ); } } ); }
private void configureJoobyAssets(final Project project) { project.getTasks() .withType(AssetTask.class, task -> { ConventionMapping mapping = task.getConventionMapping(); mapping.map("env", () -> "dist"); mapping.map("maxAge", () -> "365d"); mapping.map("mainClassName", () -> project.getProperties().get("mainClassName")); mapping.map("output", () -> new JoobyProject(project).classes()); mapping.map("assemblyOutput", () -> new File(project.getBuildDir(), "__public_")); }); Map<String, Object> options = new HashMap<>(); options.put(Task.TASK_TYPE, AssetTask.class); options.put(Task.TASK_DEPENDS_ON, "classes"); options.put(Task.TASK_NAME, "joobyAssets"); options.put(Task.TASK_DESCRIPTION, "Process, optimize and compress static files"); options.put(Task.TASK_GROUP, "jooby"); project.getTasks().create(options); }
private void configureJoobySpec(final Project project) { project.getTasks() .withType(SpecTask.class, task -> { ConventionMapping mapping = task.getConventionMapping(); mapping.map("mainClassName", () -> project.getProperties().get("mainClassName")); mapping.map("source", () -> new JoobyProject(project).javaSrc()); }); Map<String, Object> options = new HashMap<>(); options.put(Task.TASK_TYPE, SpecTask.class); options.put(Task.TASK_DEPENDS_ON, "classes"); options.put(Task.TASK_NAME, "joobySpec"); options.put(Task.TASK_DESCRIPTION, "Export your API/microservices outside a Jooby application"); options.put(Task.TASK_GROUP, "jooby"); project.getTasks().create(options); }
private void configureApiTool(final Project project) { project.getTasks() .withType(ApiToolTask.class, task -> { ConventionMapping mapping = task.getConventionMapping(); mapping.map("mainClassName", () -> project.getProperties().get("mainClassName")); }); Map<String, Object> options = new HashMap<>(); options.put(Task.TASK_TYPE, ApiToolTask.class); options.put(Task.TASK_DEPENDS_ON, "classes"); options.put(Task.TASK_NAME, "joobyApiTool"); options .put(Task.TASK_DESCRIPTION, "Export your HTTP API to open standards like Swagger and RAML"); options.put(Task.TASK_GROUP, "jooby"); project.getTasks().create(options); }
public void apply(final Project project) { project.getPluginManager().apply(ReportingBasePlugin.class); final GenerateBuildDashboard buildDashboardTask = project.getTasks().create(BUILD_DASHBOARD_TASK_NAME, GenerateBuildDashboard.class); buildDashboardTask.setDescription("Generates a dashboard of all the reports produced by this build."); buildDashboardTask.setGroup("reporting"); DirectoryReport htmlReport = buildDashboardTask.getReports().getHtml(); ConventionMapping htmlReportConventionMapping = new DslObject(htmlReport).getConventionMapping(); htmlReportConventionMapping.map("destination", new Callable<Object>() { public Object call() throws Exception { return project.getExtensions().getByType(ReportingExtension.class).file("buildDashboard"); } }); Action<Task> captureReportingTasks = new Action<Task>() { public void execute(Task task) { if (!(task instanceof Reporting)) { return; } Reporting reporting = (Reporting) task; buildDashboardTask.aggregate(reporting); if (!task.equals(buildDashboardTask)) { task.finalizedBy(buildDashboardTask); } } }; for (Project aProject : project.getAllprojects()) { aProject.getTasks().all(captureReportingTasks); } }
private void configureReportsConventionMapping(Pmd task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = AbstractCodeQualityPlugin.conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), baseName + "." + report.getName()); } }); } }); }
@Override protected void configureForSourceSet(final SourceSet sourceSet, final Pmd task) { task.setDescription("Run PMD analysis for " + sourceSet.getName() + " classes"); task.setSource(sourceSet.getAllJava()); ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("classpath", new Callable<FileCollection>() { @Override public FileCollection call() throws Exception { return sourceSet.getOutput().plus(sourceSet.getCompileClasspath()); } }); }
private void configureTaskConventionMapping(Configuration configuration, Checkstyle task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("checkstyleClasspath", Callables.returning(configuration)); taskMapping.map("config", new Callable<TextResource>() { @Override public TextResource call() { return extension.getConfig(); } }); taskMapping.map("configProperties", new Callable<Map<String, Object>>() { @Override public Map<String, Object> call() { return extension.getConfigProperties(); } }); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); taskMapping.map("showViolations", new Callable<Boolean>() { @Override public Boolean call() { return extension.isShowViolations(); } }); }
private void configureReportsConventionMapping(Checkstyle task, final String baseName) { task.getReports().all(new Action<SingleFileReport>() { @Override public void execute(final SingleFileReport report) { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", new Callable<File>() { @Override public File call() { return new File(extension.getReportsDir(), baseName + "." + report.getName()); } }); } }); }
private void configureTaskConventionMapping(Configuration configuration, CodeNarc task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("codenarcClasspath", Callables.returning(configuration)); taskMapping.map("config", new Callable<TextResource>() { @Override public TextResource call() { return extension.getConfig(); } }); taskMapping.map("maxPriority1Violations", new Callable<Integer>() { @Override public Integer call() { return extension.getMaxPriority1Violations(); } }); taskMapping.map("maxPriority2Violations", new Callable<Integer>() { @Override public Integer call() { return extension.getMaxPriority2Violations(); } }); taskMapping.map("maxPriority3Violations", new Callable<Integer>() { @Override public Integer call() { return extension.getMaxPriority3Violations(); } }); taskMapping.map("ignoreFailures", new Callable<Boolean>() { @Override public Boolean call() { return extension.isIgnoreFailures(); } }); }
public void apply(Project project) { project.getPluginManager().apply(JavaScriptBasePlugin.class); JavaScriptExtension jsExtension = project.getExtensions().findByType(JavaScriptExtension.class); final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().create(RhinoExtension.NAME, RhinoExtension.class); final Configuration configuration = addClasspathConfiguration(project.getConfigurations()); configureDefaultRhinoDependency(configuration, project.getDependencies(), rhinoExtension); ConventionMapping conventionMapping = ((IConventionAware) rhinoExtension).getConventionMapping(); conventionMapping.map("classpath", new Callable<Configuration>() { public Configuration call() { return configuration; } }); conventionMapping.map("version", new Callable<String>() { public String call() { return RhinoExtension.DEFAULT_RHINO_DEPENDENCY_VERSION; } }); project.getTasks().withType(RhinoShellExec.class, new Action<RhinoShellExec>() { public void execute(RhinoShellExec task) { task.getConventionMapping().map("classpath", new Callable<FileCollection>() { public FileCollection call() { return rhinoExtension.getClasspath(); } }); task.getConventionMapping().map("main", new Callable<String>() { public String call() { return RhinoExtension.RHINO_SHELL_MAIN; } }); task.setClasspath(rhinoExtension.getClasspath()); } }); }
public void apply(final Project project) { project.getPluginManager().apply(RhinoPlugin.class); project.getPluginManager().apply(ReportingBasePlugin.class); JavaScriptExtension jsExtension = project.getExtensions().getByType(JavaScriptExtension.class); final EnvJsExtension envJsExtension = ((ExtensionAware) jsExtension).getExtensions().create(EnvJsExtension.NAME, EnvJsExtension.class); final Configuration configuration = addConfiguration(project.getConfigurations(), project.getDependencies(), envJsExtension); final ConventionMapping conventionMapping = ((IConventionAware) envJsExtension).getConventionMapping(); conventionMapping.map("js", new Callable<Configuration>() { public Configuration call() { return configuration; } }); conventionMapping.map("version", new Callable<String>() { public String call() { return EnvJsExtension.DEFAULT_DEPENDENCY_VERSION; } }); final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().getByType(RhinoExtension.class); project.getTasks().withType(BrowserEvaluate.class, new Action<BrowserEvaluate>() { public void execute(BrowserEvaluate task) { ((IConventionAware) task).getConventionMapping().map("evaluator", new Callable<EnvJsBrowserEvaluator>() { public EnvJsBrowserEvaluator call() { RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(workerProcessBuilderFactory); File workDir = project.getProjectDir(); Factory<File> envJsFactory = new Factory<File>() { public File create() { return envJsExtension.getJs().getSingleFile(); } }; return new EnvJsBrowserEvaluator(handleFactory, rhinoExtension.getClasspath(), envJsFactory, project.getGradle().getStartParameter().getLogLevel(), workDir); } }); } }); }
public Object configureDefaultOutputPathForJacocoMerge() { return project.getTasks().withType(JacocoMerge.class, new Action<JacocoMerge>() { @Override public void execute(final JacocoMerge task) { ConventionMapping mapping = ((IConventionAware) task).getConventionMapping(); mapping.map("destinationFile", new Callable<File>() { @Override public File call() { return new File(project.getBuildDir(), "/jacoco/" + task.getName() + ".exec"); } }); } }); }
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 configureArchiveDefaults(final Project project, final BasePluginConvention pluginConvention) { project.getTasks().withType(AbstractArchiveTask.class, new Action<AbstractArchiveTask>() { public void execute(AbstractArchiveTask task) { ConventionMapping taskConventionMapping = task.getConventionMapping(); Callable<File> destinationDir; if (task instanceof Jar) { destinationDir = new Callable<File>() { public File call() throws Exception { return pluginConvention.getLibsDir(); } }; } else { destinationDir = new Callable<File>() { public File call() throws Exception { return pluginConvention.getDistsDir(); } }; } taskConventionMapping.map("destinationDir", destinationDir); taskConventionMapping.map("version", new Callable<String>() { public String call() throws Exception { return project.getVersion() == Project.DEFAULT_VERSION ? null : project.getVersion().toString(); } }); taskConventionMapping.map("baseName", new Callable<String>() { public String call() throws Exception { return pluginConvention.getArchivesBaseName(); } }); } }); }
private BridgedBinaries configureSourceSetDefaults(final JavaPluginConvention pluginConvention) { final Project project = pluginConvention.getProject(); final List<ClassDirectoryBinarySpecInternal> binaries = Lists.newArrayList(); pluginConvention.getSourceSets().all(new Action<SourceSet>() { public void execute(final SourceSet sourceSet) { ConventionMapping outputConventionMapping = ((IConventionAware) sourceSet.getOutput()).getConventionMapping(); ConfigurationContainer configurations = project.getConfigurations(); defineConfigurationsForSourceSet(sourceSet, configurations); definePathsForSourceSet(sourceSet, outputConventionMapping, project); createProcessResourcesTaskForBinary(sourceSet, sourceSet.getResources(), project); createCompileJavaTaskForBinary(sourceSet, sourceSet.getJava(), project); createBinaryLifecycleTask(sourceSet, project); DefaultComponentSpecIdentifier binaryId = new DefaultComponentSpecIdentifier(project.getPath(), sourceSet.getName()); ClassDirectoryBinarySpecInternal binary = instantiator.newInstance(DefaultClassDirectoryBinarySpec.class, binaryId, sourceSet, javaToolChain, DefaultJavaPlatform.current(), instantiator, taskFactory); Classpath compileClasspath = new SourceSetCompileClasspath(sourceSet); DefaultJavaSourceSet javaSourceSet = instantiator.newInstance(DefaultJavaSourceSet.class, binaryId.child("java"), sourceSet.getJava(), compileClasspath); JvmResourceSet resourceSet = instantiator.newInstance(DefaultJvmResourceSet.class, binaryId.child("resources"), sourceSet.getResources()); binary.addSourceSet(javaSourceSet); binary.addSourceSet(resourceSet); attachTasksToBinary(binary, sourceSet, project); binaries.add(binary); } }); return new BridgedBinaries(binaries); }
/** * Create task to update readme file from template * * @param tasks Task container to create new tasks * @param projectConfig Project configuration * @param projectContext Project context * @param extensions Extension container */ @Mutate public void createReadmeUpdateTasks(ModelMap<Task> tasks, ProjectConfig projectConfig, ProjectContext projectContext, ExtensionContainer extensions) { // Create task to update the README Map<String, Object> context = new HashMap<>(); extensions.getExtraProperties().getProperties().forEach((name, value) -> { context.put(name, value); }); context.put("project", projectContext); context.put("projectConfig", projectConfig); tasks.create("readmeUpdate", Copy.class, t -> { t.setDescription("Update README from template."); t.setGroup("documentation"); t.from("src/doc/templates"); t.include("README.template.md"); t.rename(n -> n.replace(".template.", ".")); t.expand(context); ConventionMapping parameters = t.getConventionMapping(); parameters.map("destinationDir", () -> projectContext.getProjectDir()); }); tasks.named("assemble", t -> { t.dependsOn("readmeUpdate"); }); }
private void configureTaskConventionMapping(Configuration configuration, Pmd task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("pmdClasspath", Callables.returning(configuration)); taskMapping.map("ruleSets", () -> extension.getRuleSets()); taskMapping.map("ruleSetConfig", () -> extension.getRuleSetConfig()); taskMapping.map("ruleSetFiles", () -> extension.getRuleSetFiles()); taskMapping.map("ignoreFailures", () -> extension.isIgnoreFailures()); taskMapping.map("rulePriority", () -> extension.getRulePriority()); taskMapping.map("consoleOutput", () -> extension.isConsoleOutput()); taskMapping.map("targetJdk", () -> extension.getTargetJdk()); }
private void configureReportsConventionMapping(Pmd task, final String baseName) { task.getReports().all(report -> { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", Callables.returning(true)); reportMapping.map("destination", () -> new File(extension.getReportsDir(), baseName + "." + report.getName())); }); }