Skip to content

Commit

Permalink
Issue checkstyle#11604: allows 3rd parties to expand module identific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
rnveach committed Oct 27, 2022
1 parent 716ae3d commit 1dafbc1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Definitions.CHECKSTYLE_BUNDLE, getClass(),
private Map<String, Set<String>> generateThirdPartyNameToFullModuleName(ClassLoader loader) {
Map<String, Set<String>> 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())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<?>> getCheckstyleModules(
public static Set<Class<?>> getValidCheckstyleClasses(
Collection<String> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ public void testGenerateThirdPartyNameToFullModuleNameWithException() throws Exc

try (MockedStatic<ModuleReflectionUtil> 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<String, String> nullMap = TestUtil.getInternalState(objectFactory,
Expand Down

0 comments on commit 1dafbc1

Please sign in to comment.