gnodet commented on code in PR #3554:
URL: https://github.com/apache/maven-surefire/pull/3554#discussion_r4792362641
##########
surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java:
##########
@@ -346,7 +396,17 @@ private boolean matchClassPatter(String testClassFile) {
classPattern = classPattern.replace('/', separatorChar);
}
- if (classPattern.endsWith(WILDCARD_FILENAME_POSTFIX) ||
classPattern.endsWith(CLASS_FILE_EXTENSION)) {
+ if (ResolvedTest.this.ambiguousPackageWildcard) {
+ // The source pattern was ambiguous between a package and a
class name (see
+ // isPackageName); also match the legacy single-class-file
interpretation, so a class
+ // whose name happens to start with a lowercase letter still
matches itself. A pattern
+ // the caller already wrote with a slash is unambiguous and
never reaches this branch.
+ String packagePostfix = WILDCARD_PACKAGE_POSTFIX.replace('/',
separatorChar);
+ String legacyClassPattern = classPattern.substring(0,
classPattern.length() - packagePostfix.length())
+ + WILDCARD_FILENAME_POSTFIX;
+ return of(classPattern,
legacyClassPattern).matches(testClassFile, true);
Review Comment:
**Smart backward compatibility implementation** 👏
The dual-pattern matching here is elegant:
1. Primary match: the package interpretation (`dev/aspectj/*`)
2. Fallback match: the legacy single-class interpretation (`dev/aspectj.*`)
This ensures that:
- The documented package wildcard behavior works correctly
- Pre-existing classes with unconventional lowercase names still match
themselves
- The fix is non-breaking for edge cases
Well thought out!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]