@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)); }
/** * Assign some standard tasks and tasks created by third-party plugins to their task groups according to the * order of things for Checkstyle Addons. */ public void adjustTaskGroupAssignments() { final TaskContainer tasks = project.getTasks(); tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).setGroup(ARTIFACTS_GROUP_NAME); tasks.getByName(JavaPlugin.JAR_TASK_NAME).setGroup(ARTIFACTS_GROUP_NAME); final SourceSet sqSourceSet = buildUtil.getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME); tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).setGroup(BasePlugin.BUILD_GROUP); tasks.getByName(sqSourceSet.getCompileJavaTaskName()).setGroup(BasePlugin.BUILD_GROUP); tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).setGroup(BasePlugin.BUILD_GROUP); for (final FindBugs fbTask : tasks.withType(FindBugs.class)) { fbTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); } for (final Checkstyle csTask : tasks.withType(Checkstyle.class)) { csTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP); } for (final Copy task : tasks.withType(Copy.class)) { if (task.getName().startsWith("process") && task.getName().endsWith("Resources")) { task.setGroup(LifecycleBasePlugin.BUILD_GROUP); } } }
@Override public void apply(Project rootProject) { final String circleReportsDir = System.getenv("CIRCLE_TEST_REPORTS"); if (circleReportsDir == null) { return; } configureBuildFailureFinalizer(rootProject, circleReportsDir); final StyleTaskTimer timer = new StyleTaskTimer(); rootProject.getGradle().addListener(timer); rootProject.allprojects(new Action<Project>() { @Override public void execute(final Project project) { project.getTasks().withType(Checkstyle.class, new Action<Checkstyle>() { @Override public void execute(Checkstyle checkstyleTask) { configureCheckstyleTask(project, checkstyleTask, circleReportsDir, timer); } }); project.getTasks().withType(FindBugs.class, new Action<FindBugs>() { @Override public void execute(FindBugs findbugsTask) { configureFindbugsTask(project, findbugsTask, circleReportsDir, timer); } }); } }); }
private void configureFindbugsTask( final Project project, final FindBugs findbugsTask, final String circleReportsDir, final StyleTaskTimer timer) { // Ensure XML output is enabled findbugsTask.doFirst(new Action<Task>() { @Override public void execute(Task task) { for (SingleFileReport report : findbugsTask.getReports()) { report.setEnabled(false); } FindBugsXmlReport xmlReport = (FindBugsXmlReport) findbugsTask.getReports().findByName("xml"); xmlReport.setEnabled(true); xmlReport.setWithMessages(true); } }); // Configure the finalizer task CircleStyleFinalizer finalizer = createTask( project.getTasks(), findbugsTask.getName() + "CircleFinalizer", CircleStyleFinalizer.class); if (finalizer == null) { // Already registered (happens if the user applies us to the root project and subprojects) return; } finalizer.setReportParser(FindBugsReportHandler.PARSER); finalizer.setStyleTask(findbugsTask); finalizer.setReporting(findbugsTask); finalizer.setStyleTaskTimer(timer); finalizer.setTargetFile(new File( new File(circleReportsDir, "findbugs"), project.getName() + "-" + findbugsTask.getName() + ".xml")); findbugsTask.finalizedBy(finalizer); }
@Override protected void configureTaskDefaults(FindBugs task, String baseName) { task.setPluginClasspath(project.getConfigurations().getAt("findbugsPlugins")); Configuration configuration = project.getConfigurations().getAt("findbugs"); configureDefaultDependencies(configuration); configureTaskConventionMapping(configuration, task); configureReportsConventionMapping(task, baseName); }
private void configureTaskConventionMapping(Configuration configuration, FindBugs task) { ConventionMapping taskMapping = task.getConventionMapping(); taskMapping.map("findbugsClasspath", Callables.returning(configuration)); taskMapping.map("ignoreFailures", () -> extension.isIgnoreFailures()); taskMapping.map("effort", () -> extension.getEffort()); taskMapping.map("reportLevel", () -> extension.getReportLevel()); taskMapping.map("visitors", () -> extension.getVisitors()); taskMapping.map("omitVisitors", () -> extension.getOmitVisitors()); taskMapping.map("excludeFilterConfig", () -> extension.getExcludeFilterConfig()); taskMapping.map("includeFilterConfig", () -> extension.getIncludeFilterConfig()); taskMapping.map("excludeBugsFilterConfig", () -> extension.getExcludeBugsFilterConfig()); taskMapping.map("extraArgs", () -> extension.getExtraArgs()); }
private void configureReportsConventionMapping(FindBugs task, final String baseName) { task.getReports().all(report -> { ConventionMapping reportMapping = conventionMappingOf(report); reportMapping.map("enabled", () -> report.getName().equals("xml")); reportMapping.map("destination", () -> new File(extension.getReportsDir(), baseName + "." + report.getName())); }); }
public static boolean isStyleTask(Task task) { return task instanceof Checkstyle || task instanceof FindBugs; }
@Override protected Class<FindBugs> getTaskType() { return FindBugs.class; }