diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java new file mode 100644 index 00000000000..f697a962cc3 --- /dev/null +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/classfile/impl/ClassPathBuilderTest.java @@ -0,0 +1,36 @@ +package edu.umd.cs.findbugs.classfile.impl; + +import edu.umd.cs.findbugs.AppVersion; +import edu.umd.cs.findbugs.BugCollection; +import edu.umd.cs.findbugs.test.SpotBugsRule; +import org.junit.Rule; +import org.junit.Test; + +import java.nio.file.Paths; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class ClassPathBuilderTest { + + @Rule + public SpotBugsRule analyzer = new SpotBugsRule(); + + @Test + public void nestedTraversalDisabled() { + BugCollection results = analyzer.performAnalysis((engine) -> { + engine.setScanNestedArchives(false); + engine.setNoClassOk(true); + }, Paths.get("../spotbugsTestCases/archives/nestedArchive.jar")); + AppVersion appInformation = results.getCurrentAppVersion(); + assertThat(appInformation.getNumClasses(), equalTo(0)); + } + + @Test + public void nestedTraversalEnabled() { + BugCollection results = analyzer.performAnalysis((engine) -> engine.setScanNestedArchives(true), + Paths.get("../spotbugsTestCases/archives/nestedArchive.jar")); + AppVersion appInformation = results.getCurrentAppVersion(); + assertThat(appInformation.getNumClasses(), equalTo(5)); + } +} diff --git a/spotbugsTestCases/archives/nestedArchive.jar b/spotbugsTestCases/archives/nestedArchive.jar new file mode 100644 index 00000000000..49e36070aec Binary files /dev/null and b/spotbugsTestCases/archives/nestedArchive.jar differ diff --git a/test-harness-core/src/main/java/edu/umd/cs/findbugs/test/AnalysisRunner.java b/test-harness-core/src/main/java/edu/umd/cs/findbugs/test/AnalysisRunner.java index b29bc022dbb..6ee5f714254 100644 --- a/test-harness-core/src/main/java/edu/umd/cs/findbugs/test/AnalysisRunner.java +++ b/test-harness-core/src/main/java/edu/umd/cs/findbugs/test/AnalysisRunner.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.function.Consumer; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; @@ -40,7 +41,7 @@ /** *
* This class runs analysis with SpotBugs. The target class files and - * auxClasspathEntries should be specified before you invoke {@link #run(Path...)} + * auxClasspathEntries should be specified before you invoke {@link #run(Consumer, Path...)} * method. *
* @@ -83,7 +84,7 @@ public AnalysisRunner addAuxClasspathEntry(Path path) { } @Nonnull - public BugCollectionBugReporter run(Path... files) { + public BugCollectionBugReporter run(Consumer* 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(Path... paths) { + public BugCollection performAnalysis(Consumer+ * 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); } }