Skip to content

Commit

Permalink
Issue #11604: allows 3rd parties to expand module identification
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Oct 27, 2022
1 parent 716ae3d commit a5e57bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .ci/pitest-suppressions/pitest-utils-suppressions.xml
Expand Up @@ -633,10 +633,10 @@
<mutation unstable="false">
<sourceFile>ModuleReflectionUtil.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil</mutatedClass>
<mutatedMethod>getCheckstyleModules</mutatedMethod>
<mutatedMethod>getValidCheckstyleClasses</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to java/util/stream/Stream::filter with receiver</description>
<lineContent>.filter(ModuleReflectionUtil::isCheckstyleModule)</lineContent>
<lineContent>.filter(ModuleReflectionUtil::isValidCheckstyleClass)</lineContent>
</mutation>

<mutation unstable="false">
Expand Down
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
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
Expand Up @@ -441,7 +441,7 @@ public void testGetShortFromFullModuleNamesThirdParty() {
* to initialize private field {@code PackageObjectFactory.thirdPartyNameToFullModuleNames}.
* Since the method and the field both are private, the {@link TestUtil} is required to ensure
* that the field is changed. Also, the expected exception should be thrown from the static
* method {@link ModuleReflectionUtil#getCheckstyleModules}, so {@link Mockito#mockStatic}
* method {@link ModuleReflectionUtil#getValidCheckstyleClasses}, so {@link Mockito#mockStatic}
* is required to mock this exception.
*
* @throws Exception when the code tested throws an exception
Expand All @@ -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 a5e57bc

Please sign in to comment.