diff --git a/.github/workflows/quality-monitor.yml b/.github/workflows/quality-monitor.yml index e9bf58e2..b398fac7 100644 --- a/.github/workflows/quality-monitor.yml +++ b/.github/workflows/quality-monitor.yml @@ -95,7 +95,8 @@ jobs: "tools": [ { "id": "revapi", - "sourcePath": "src/main/java" + "sourcePath": "src/main/java", + "pattern": "**/target/revapi-result.json" } ] }, diff --git a/pom.xml b/pom.xml index c0cce756..8e2a48af 100644 --- a/pom.xml +++ b/pom.xml @@ -981,6 +981,16 @@ ok + + + true + true + java.method.visibilityIncreased + PackageDetectorFactory + createPackageDetectors + Not used yet + + true diff --git a/src/main/java/edu/hm/hafner/util/CSharpNamespaceDetector.java b/src/main/java/edu/hm/hafner/util/CSharpNamespaceDetector.java index 6b2eb2a6..370ec5f9 100644 --- a/src/main/java/edu/hm/hafner/util/CSharpNamespaceDetector.java +++ b/src/main/java/edu/hm/hafner/util/CSharpNamespaceDetector.java @@ -2,6 +2,8 @@ import java.util.regex.Pattern; +import edu.hm.hafner.util.PackageDetectorFactory.FileSystemFacade; + /** * Detects the namespace of a C# workspace file. * diff --git a/src/main/java/edu/hm/hafner/util/JavaPackageDetector.java b/src/main/java/edu/hm/hafner/util/JavaPackageDetector.java index 66a09af2..5ba82168 100644 --- a/src/main/java/edu/hm/hafner/util/JavaPackageDetector.java +++ b/src/main/java/edu/hm/hafner/util/JavaPackageDetector.java @@ -2,6 +2,8 @@ import java.util.regex.Pattern; +import edu.hm.hafner.util.PackageDetectorFactory.FileSystemFacade; + /** * Detects the package name of a Java file. * diff --git a/src/main/java/edu/hm/hafner/util/KotlinPackageDetector.java b/src/main/java/edu/hm/hafner/util/KotlinPackageDetector.java index 45f4222c..4fd7abcb 100644 --- a/src/main/java/edu/hm/hafner/util/KotlinPackageDetector.java +++ b/src/main/java/edu/hm/hafner/util/KotlinPackageDetector.java @@ -2,6 +2,8 @@ import java.util.regex.Pattern; +import edu.hm.hafner.util.PackageDetectorFactory.FileSystemFacade; + /** * Detects the package name of a Kotlin file. * diff --git a/src/main/java/edu/hm/hafner/util/PackageDetector.java b/src/main/java/edu/hm/hafner/util/PackageDetector.java index af0cbd0c..a5650cf6 100644 --- a/src/main/java/edu/hm/hafner/util/PackageDetector.java +++ b/src/main/java/edu/hm/hafner/util/PackageDetector.java @@ -5,9 +5,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; -import java.nio.file.Files; import java.nio.file.InvalidPathException; -import java.nio.file.Paths; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -15,7 +13,7 @@ import org.apache.commons.io.input.BOMInputStream; -import com.google.errorprone.annotations.MustBeClosed; +import edu.hm.hafner.util.PackageDetectorFactory.FileSystemFacade; /** * Base class for package detectors. @@ -96,15 +94,4 @@ private Optional detectPackageName(final Stream lines) { * @return {@code true} if the classifier accepts the specified file for processing. */ abstract boolean accepts(String fileName); - - /** - * Facade for file system operations. May be replaced by stubs in test cases. - */ - @VisibleForTesting - static class FileSystemFacade { - @MustBeClosed - InputStream openFile(final String fileName) throws IOException, InvalidPathException { - return Files.newInputStream(Paths.get(fileName)); - } - } } diff --git a/src/main/java/edu/hm/hafner/util/PackageDetectorFactory.java b/src/main/java/edu/hm/hafner/util/PackageDetectorFactory.java index d5499543..b9f33a4b 100644 --- a/src/main/java/edu/hm/hafner/util/PackageDetectorFactory.java +++ b/src/main/java/edu/hm/hafner/util/PackageDetectorFactory.java @@ -1,6 +1,12 @@ package edu.hm.hafner.util; -import edu.hm.hafner.util.PackageDetector.FileSystemFacade; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Paths; + +import com.google.errorprone.annotations.MustBeClosed; /** * Factory to create package detectors. @@ -17,8 +23,16 @@ public static PackageDetectorRunner createPackageDetectors() { return createPackageDetectors(new FileSystemFacade()); } + /** + * Creates a new package detector runner that uses the detectors for Java, Kotlin, and C#. + * + * @param facade + * the file system facade to use + * + * @return the package detector runner + */ @VisibleForTesting - static PackageDetectorRunner createPackageDetectors(final FileSystemFacade facade) { + public static PackageDetectorRunner createPackageDetectors(final FileSystemFacade facade) { return new PackageDetectorRunner( new JavaPackageDetector(facade), new KotlinPackageDetector(facade), @@ -28,4 +42,27 @@ static PackageDetectorRunner createPackageDetectors(final FileSystemFacade facad private PackageDetectorFactory() { // prevents instantiation } + + /** + * Facade for file system operations. May be replaced by stubs in test cases. + */ + @VisibleForTesting + public static class FileSystemFacade { + /** + * Opens the specified file. + * + * @param fileName + * the name of the file to open + * + * @return the input stream to read the file + * @throws IOException + * if the file could not be opened + * @throws InvalidPathException + * the file name is invalid + */ + @MustBeClosed + public InputStream openFile(final String fileName) throws IOException, InvalidPathException { + return Files.newInputStream(Paths.get(fileName)); + } + } } diff --git a/src/test/java/edu/hm/hafner/util/PackageDetectorRunnerTest.java b/src/test/java/edu/hm/hafner/util/PackageDetectorRunnerTest.java index 73619377..a8b02773 100644 --- a/src/test/java/edu/hm/hafner/util/PackageDetectorRunnerTest.java +++ b/src/test/java/edu/hm/hafner/util/PackageDetectorRunnerTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; -import edu.hm.hafner.util.PackageDetector.FileSystemFacade; +import edu.hm.hafner.util.PackageDetectorFactory.FileSystemFacade; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*;