diff --git a/config/archunit-store/slices_should_be_free_of_cycles_suppressions b/config/archunit-store/slices_should_be_free_of_cycles_suppressions index 08e79e572b6..8abe5682cab 100644 --- a/config/archunit-store/slices_should_be_free_of_cycles_suppressions +++ b/config/archunit-store/slices_should_be_free_of_cycles_suppressions @@ -311,14 +311,13 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:121)\ - Method calls method in (CheckUtil.java:122)\ - Method calls method in (CheckUtil.java:124)\ - - Method references class object in (ModuleReflectionUtil.java:126)\ - Method calls method in (ScopeUtil.java:134)\ - Method calls method in (CheckUtil.java:135)\ - Method calls method in (ScopeUtil.java:136)\ - - Method references class object in (ModuleReflectionUtil.java:137)\ - Method calls method in (ScopeUtil.java:137)\ - Method calls method in (ScopeUtil.java:140)\ - Method calls method in (AnnotationUtil.java:142)\ + - Method references class object in (ModuleReflectionUtil.java:145)\ - Method gets field in (ScopeUtil.java:145)\ - Method calls method in (XpathUtil.java:145)\ - Method calls method in (CheckUtil.java:146)\ @@ -327,13 +326,12 @@ Cycle detected: Slice api -> \ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (CheckUtil.java:148)\ - - Method references class object in (ModuleReflectionUtil.java:148)\ - Method calls method in (AnnotationUtil.java:151)\ + - Method references class object in (ModuleReflectionUtil.java:156)\ - Method calls method in (XpathUtil.java:157)\ - - Method references class object in (ModuleReflectionUtil.java:159)\ + - Method references class object in (ModuleReflectionUtil.java:167)\ - Method calls method in (XpathUtil.java:167)\ - Method calls method in (XpathUtil.java:168)\ - - Method references class object in (ModuleReflectionUtil.java:170)\ - Method calls method in (BlockCommentPosition.java:171)\ - Method calls method in (BlockCommentPosition.java:172)\ - Method calls method in (JavadocUtil.java:173)\ @@ -341,14 +339,16 @@ Cycle detected: Slice api -> \ - Method calls method in (JavadocUtil.java:174)\ - Method calls method in (BlockCommentPosition.java:175)\ - Method calls method in (BlockCommentPosition.java:175)\ - - Method references class object in (ModuleReflectionUtil.java:181)\ + - Method references class object in (ModuleReflectionUtil.java:178)\ - Method calls method in (AnnotationUtil.java:185)\ - Method calls method in (JavadocUtil.java:185)\ - Method calls method in (AnnotationUtil.java:186)\ - Method calls method in (JavadocUtil.java:186)\ - Method calls method in (AnnotationUtil.java:187)\ + - Method references class object in (ModuleReflectionUtil.java:189)\ - Method calls method in (AnnotationUtil.java:190)\ - Method calls constructor (java.lang.String, java.lang.Throwable)> in (XpathUtil.java:198)\ + - Method references class object in (ModuleReflectionUtil.java:200)\ - Method calls method in (JavadocUtil.java:202)\ - Method calls method in (ScopeUtil.java:205)\ - Method calls method in (ScopeUtil.java:207)\ @@ -1330,7 +1330,6 @@ Cycle detected: Slice api -> \ - Method calls method in (ScopeUtil.java:88)\ - Method calls method in (BlockCommentPosition.java:89)\ - Method calls method in (BlockCommentPosition.java:92)\ - - Method references class object in (ModuleReflectionUtil.java:94)\ - Method calls method in (AnnotationUtil.java:95)\ - Method calls method in (CheckUtil.java:95)\ - Method calls method in (CheckUtil.java:96)\ @@ -1347,6 +1346,7 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:108)\ - Method calls method in (ScopeUtil.java:110)\ - Method gets field in (ScopeUtil.java:111)\ + - Method references class object in (ModuleReflectionUtil.java:113)\ - Method calls method in (JavadocUtil.java:114)\ - Method gets field in (ScopeUtil.java:114)\ - Method gets field in (ScopeUtil.java:118)\ @@ -1355,14 +1355,13 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:121)\ - Method calls method in (CheckUtil.java:122)\ - Method calls method in (CheckUtil.java:124)\ - - Method references class object in (ModuleReflectionUtil.java:126)\ - Method calls method in (ScopeUtil.java:134)\ - Method calls method in (CheckUtil.java:135)\ - Method calls method in (ScopeUtil.java:136)\ - - Method references class object in (ModuleReflectionUtil.java:137)\ - Method calls method in (ScopeUtil.java:137)\ - Method calls method in (ScopeUtil.java:140)\ - Method calls method in (AnnotationUtil.java:142)\ + - Method references class object in (ModuleReflectionUtil.java:145)\ - Method gets field in (ScopeUtil.java:145)\ - Method calls method in (XpathUtil.java:145)\ - Method calls method in (CheckUtil.java:146)\ @@ -1371,13 +1370,12 @@ Cycle detected: Slice api -> \ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (CheckUtil.java:148)\ - - Method references class object in (ModuleReflectionUtil.java:148)\ - Method calls method in (AnnotationUtil.java:151)\ + - Method references class object in (ModuleReflectionUtil.java:156)\ - Method calls method in (XpathUtil.java:157)\ - - Method references class object in (ModuleReflectionUtil.java:159)\ + - Method references class object in (ModuleReflectionUtil.java:167)\ - Method calls method in (XpathUtil.java:167)\ - Method calls method in (XpathUtil.java:168)\ - - Method references class object in (ModuleReflectionUtil.java:170)\ - Method calls method in (BlockCommentPosition.java:171)\ - Method calls method in (BlockCommentPosition.java:172)\ - Method calls method in (JavadocUtil.java:173)\ @@ -1385,14 +1383,16 @@ Cycle detected: Slice api -> \ - Method calls method in (JavadocUtil.java:174)\ - Method calls method in (BlockCommentPosition.java:175)\ - Method calls method in (BlockCommentPosition.java:175)\ - - Method references class object in (ModuleReflectionUtil.java:181)\ + - Method references class object in (ModuleReflectionUtil.java:178)\ - Method calls method in (AnnotationUtil.java:185)\ - Method calls method in (JavadocUtil.java:185)\ - Method calls method in (AnnotationUtil.java:186)\ - Method calls method in (JavadocUtil.java:186)\ - Method calls method in (AnnotationUtil.java:187)\ + - Method references class object in (ModuleReflectionUtil.java:189)\ - Method calls method in (AnnotationUtil.java:190)\ - Method calls constructor (java.lang.String, java.lang.Throwable)> in (XpathUtil.java:198)\ + - Method references class object in (ModuleReflectionUtil.java:200)\ - Method calls method in (JavadocUtil.java:202)\ - Method calls method in (ScopeUtil.java:205)\ - Method calls method in (ScopeUtil.java:207)\ diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java b/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java index bec9669bf3f..5da711a217b 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java @@ -303,7 +303,7 @@ Definitions.CHECKSTYLE_BUNDLE, getClass(), private Map> generateThirdPartyNameToFullModuleName(ClassLoader loader) { Map> returnValue; try { - returnValue = ModuleReflectionUtil.getCheckstyleModules(packages, loader).stream() + returnValue = ModuleReflectionUtil.getValidCheckstyleClasses(packages, loader).stream() .collect(Collectors.groupingBy(Class::getSimpleName, Collectors.mapping(Class::getCanonicalName, Collectors.toSet()))); } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java b/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java index c9d4713a1b7..882ee49589d 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java @@ -46,21 +46,21 @@ private ModuleReflectionUtil() { } /** - * Gets checkstyle's modules (directly, not recursively) in the given packages. + * Gets valid checkstyle's classes (directly, not recursively) in the given packages. * * @param packages the collection of package names to use * @param loader the class loader used to load Checkstyle package names - * @return the set of checkstyle's module classes + * @return the set of checkstyle's classes * @throws IOException if the attempt to read class path resources failed * @see #isCheckstyleModule(Class) */ - public static Set> getCheckstyleModules( + public static Set> getValidCheckstyleClasses( Collection packages, ClassLoader loader) throws IOException { final ClassPath classPath = ClassPath.from(loader); return packages.stream() .flatMap(pkg -> classPath.getTopLevelClasses(pkg).stream()) .map(ClassPath.ClassInfo::load) - .filter(ModuleReflectionUtil::isCheckstyleModule) + .filter(ModuleReflectionUtil::isValidCheckstyleClass) .collect(Collectors.toSet()); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java index 8bfe18c23e5..bcc365e8b89 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java @@ -457,8 +457,9 @@ public void testGenerateThirdPartyNameToFullModuleNameWithException() throws Exc try (MockedStatic utilities = mockStatic(ModuleReflectionUtil.class)) { - utilities.when(() -> ModuleReflectionUtil.getCheckstyleModules(packages, classLoader)) - .thenThrow(new IOException("mock exception")); + utilities.when(() -> { + ModuleReflectionUtil.getValidCheckstyleClasses(packages, classLoader); + }).thenThrow(new IOException("mock exception")); final String internalFieldName = "thirdPartyNameToFullModuleNames"; final Map nullMap = TestUtil.getInternalState(objectFactory,