edu.umd.cs.findbugs.test.SpotBugsRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-harness-jupiter Show documentation
Show all versions of test-harness-jupiter Show documentation
A test harness library for SpotBugs plugin developers to test on JUnit 5
package edu.umd.cs.findbugs.test;
import java.nio.file.Path;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.IFindBugsEngine;
import edu.umd.cs.findbugs.BugCollection;
/**
*
* A class to execute integration test for SpotBugs. This is basically designed to help SpotBugs plugin developer to
* test their product.
*
*
* @since 3.1
*/
public class SpotBugsRunner {
@Nonnull
private final AnalysisRunner runner = new AnalysisRunner();
/**
*
* Add an entry to aux classpath of SpotBugs analysis.
*
* @param engineCustomization
* A customization of the engine to apply before running engine#execute
* @param path
* A path of the target class file or jar file. Non-null.
* @return callee itself, so caller can chain another method in fluent interface.
*/
// TODO let users specify "groupId:artifactId:packaging:version:classifier" like Grape in Groovy
@Nonnull
public SpotBugsRunner addAuxClasspathEntry(Consumer engineCustomization, Path path) {
if (runner == null) {
throw new IllegalStateException(
"Please call this addAuxClasspathEntry() method in @Before method or test method");
}
runner.addAuxClasspathEntry(path);
return this;
}
/**
*
* Run SpotBugs under given condition, and return its result.
*
* @param engineCustomization
* A customization of the engine to apply before running engine#execute
* @param paths
* Paths of target class files
* @return a {@link BugCollection} which contains all detected bugs.
*/
// TODO let users specify SlashedClassName, then find its file path automatically
@Nonnull
public BugCollection performAnalysis(Consumer engineCustomization, Path... paths) {
if (runner == null) {
throw new IllegalStateException("Please call this performAnalysis() method in test method");
}
return runner.run(engineCustomization, paths).getBugCollection();
}
/**
*
* Run SpotBugs under given condition, and return its result.
*
* @param paths
* Paths of target class files
* @return a {@link BugCollection} which contains all detected bugs.
*/
// TODO let users specify SlashedClassName, then find its file path automatically
@Nonnull
public BugCollection performAnalysis(Path... paths) {
return performAnalysis(e -> {
}, paths);
}
}