Search in sources :

Example 1 with FindBugsReportsImpl

use of org.gradle.api.plugins.quality.internal.FindBugsReportsImpl in project gradle by gradle.

the class FindBugsSpecBuilder method build.

public FindBugsSpec build() {
    ArrayList<String> args = new ArrayList<String>();
    args.add("-pluginList");
    args.add(pluginsList == null ? "" : pluginsList.getAsPath());
    args.add("-sortByClass");
    args.add("-timestampNow");
    args.add("-progress");
    if (reports != null && !reports.getEnabled().isEmpty()) {
        if (reports.getEnabled().size() == 1) {
            FindBugsReportsImpl reportsImpl = (FindBugsReportsImpl) reports;
            String outputArg = "-" + reportsImpl.getFirstEnabled().getName();
            if (reportsImpl.getFirstEnabled() instanceof FindBugsXmlReportImpl) {
                FindBugsXmlReportImpl r = (FindBugsXmlReportImpl) reportsImpl.getFirstEnabled();
                if (r.isWithMessages()) {
                    outputArg += ":withMessages";
                }
            } else if (reportsImpl.getFirstEnabled() instanceof CustomizableHtmlReportImpl) {
                CustomizableHtmlReportImpl r = (CustomizableHtmlReportImpl) reportsImpl.getFirstEnabled();
                if (r.getStylesheet() != null) {
                    outputArg += ':' + r.getStylesheet().asFile().getAbsolutePath();
                }
            }
            args.add(outputArg);
            args.add("-outputFile");
            args.add(reportsImpl.getFirstEnabled().getDestination().getAbsolutePath());
        } else {
            throw new InvalidUserDataException("FindBugs tasks can only have one report enabled, however more than one report was enabled. You need to disable all but one of them.");
        }
    }
    if (has(sources)) {
        args.add("-sourcepath");
        args.add(sources.getAsPath());
    }
    if (has(classpath)) {
        args.add("-auxclasspath");
        // Filter unexisting files as FindBugs can't handle them.
        args.add(classpath.filter(new Spec<File>() {

            public boolean isSatisfiedBy(File element) {
                return element.exists();
            }
        }).getAsPath());
    }
    if (has(effort)) {
        args.add(String.format("-effort:%s", effort));
    }
    if (has(reportLevel)) {
        args.add(String.format("-%s", reportLevel));
    }
    if (has(visitors)) {
        args.add("-visitors");
        args.add(CollectionUtils.join(",", visitors));
    }
    if (has(omitVisitors)) {
        args.add("-omitVisitors");
        args.add(CollectionUtils.join(",", omitVisitors));
    }
    if (has(excludeFilter)) {
        args.add("-exclude");
        args.add(excludeFilter.getPath());
    }
    if (has(includeFilter)) {
        args.add("-include");
        args.add(includeFilter.getPath());
    }
    if (has(excludeBugsFilter)) {
        args.add("-excludeBugs");
        args.add(excludeBugsFilter.getPath());
    }
    if (has(extraArgs)) {
        args.addAll(extraArgs);
    }
    for (File classFile : classes.getFiles()) {
        args.add(classFile.getAbsolutePath());
    }
    return new FindBugsSpec(args, maxHeapSize, debugEnabled);
}
Also used : FindBugsReportsImpl(org.gradle.api.plugins.quality.internal.FindBugsReportsImpl) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArrayList(java.util.ArrayList) CustomizableHtmlReportImpl(org.gradle.api.reporting.internal.CustomizableHtmlReportImpl) File(java.io.File)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 FindBugsReportsImpl (org.gradle.api.plugins.quality.internal.FindBugsReportsImpl)1 CustomizableHtmlReportImpl (org.gradle.api.reporting.internal.CustomizableHtmlReportImpl)1