From 78220679408dcb6df9cac03731ef1689f6120c24 Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Sun, 29 Aug 2021 07:59:54 -0700 Subject: [PATCH] Issue #10745: use forbidden api annotation for specific suppression --- pom.xml | 11 +++++++--- .../coding/PackageDeclarationCheckTest.java | 2 ++ .../checkstyle/internal/AllTestsTest.java | 20 ++++++++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 086bf6357d1..d39328c9117 100644 --- a/pom.xml +++ b/pom.xml @@ -221,6 +221,7 @@ 0.14 **/test/resources/**/*,**/it/resources/**/* 5.7.2 + 3.1 @@ -358,6 +359,12 @@ runtime test + + de.thetaphi + forbiddenapis + ${forbiddenapis.version} + test + net.sf.saxon Saxon-HE @@ -1473,7 +1480,7 @@ de.thetaphi forbiddenapis - 3.1 + ${forbiddenapis.version} ${java.version} false @@ -1582,8 +1589,6 @@ **/SuppressWithNearbyCommentFilterTest.class - **/PackageDeclarationCheckTest.class - **/AbstractModuleTestSupport.class **/CommentsIndentationCheckTest.class diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java index 73a58dc6252..1a5b95c61da 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java @@ -28,6 +28,7 @@ import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import com.puppycrawl.tools.checkstyle.utils.CommonUtil; +import de.thetaphi.forbiddenapis.SuppressForbidden; public class PackageDeclarationCheckTest extends AbstractModuleTestSupport { @@ -151,6 +152,7 @@ public void testNoPackage() throws Exception { expected); } + @SuppressForbidden @Test public void testEmptyFile() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(PackageDeclarationCheck.class); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllTestsTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllTestsTest.java index 52ac03ce1bc..1727e1e3486 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllTestsTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/AllTestsTest.java @@ -200,13 +200,7 @@ private static void verifyHasProductionFile(Map> allTests, if (file.isFile()) { final String fileName = file.getName().replace("Test.java", ".java"); - if (!fileName.endsWith("TestSupport.java") - // tests external utility XPathEvaluator - && !"XpathMapper.java".equals(fileName) - // JavadocMetadataScraper and related classes are temporarily hosted in test - && !file.getPath().contains("meta") - // InlineConfigParser is hosted in test - && !file.getPath().contains("bdd")) { + if (isTarget(file, fileName)) { final String path; try { @@ -230,6 +224,18 @@ private static void verifyHasProductionFile(Map> allTests, } } + private static boolean isTarget(File file, String fileName) { + return !fileName.endsWith("TestSupport.java") + // tests external utility XPathEvaluator + && !"XpathMapper.java".equals(fileName) + // JavadocMetadataScraper and related classes are temporarily hosted in test + && !file.getPath().contains("meta") + // InlineConfigParser is hosted in test + && !file.getPath().contains("bdd") + // Annotation to suppress invocation of forbidden apis + && !"SuppressForbiddenApi.java".equals(fileName); + } + private static boolean checkInputMatchCorrectFileStructure(List classes, String folderPath, boolean skipFileNaming, String fileName) { boolean result = false;