- 
                Notifications
    You must be signed in to change notification settings 
- Fork 103
Fix excludePackageNames wildcard handling to correctly match subpackages #1275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|  | @@ -389,13 +389,19 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (String excludePackagename : excludePackagenames) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Usage of wildcard was bad specified and bad implemented, i.e. using String.contains() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // without respecting surrounding context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Following implementation should match requirements as defined in the examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Following implementation should match requirements as aligned with javadoc -exclude behavior: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - A wildcard at the beginning should match one or more directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - Any other wildcard must match exactly one directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pattern p = Pattern.compile(excludePackagename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace(".", regexFileSeparator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replaceFirst("^\\*", ".+") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .replace("*", "[^" + regexFileSeparator + "]+")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - A wildcard at the end should match one or more directories (to include all subpackages) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // - A wildcard in the middle should match exactly one directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String pattern = excludePackagename.replace(".", regexFileSeparator); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Handle leading wildcard: match one or more directory levels | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern = pattern.replaceFirst("^\\*", ".+"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Handle trailing wildcard: match one or more directory levels (for subpackages) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern = pattern.replaceFirst("\\*$", ".+"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Handle wildcards in the middle: match exactly one directory level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern = pattern.replace("*", "[^" + regexFileSeparator + "]+"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
      Comment on lines
    
      +396
     to 
      +402
    
   
     | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String pattern = excludePackagename.replace(".", regexFileSeparator); | |
| // Handle leading wildcard: match one or more directory levels | |
| pattern = pattern.replaceFirst("^\\*", ".+"); | |
| // Handle trailing wildcard: match one or more directory levels (for subpackages) | |
| pattern = pattern.replaceFirst("\\*$", ".+"); | |
| // Handle wildcards in the middle: match exactly one directory level | |
| pattern = pattern.replace("*", "[^" + regexFileSeparator + "]+"); | |
| // Build regex by quoting non-wildcard fragments and inserting wildcard expansions | |
| StringBuilder patternBuilder = new StringBuilder(); | |
| String[] parts = excludePackagename.split("\\*", -1); // -1 to include trailing empty strings | |
| for (int i = 0; i < parts.length; i++) { | |
| if (!parts[i].isEmpty()) { | |
| // Replace '.' with file separator and quote the fragment | |
| patternBuilder.append(Pattern.quote(parts[i].replace(".", regexFileSeparator))); | |
| } | |
| if (i < parts.length - 1) { | |
| // Insert wildcard regex | |
| // If at start or end, use ".+" (one or more directories), else "[^sep]+" | |
| boolean isStart = (i == 0); | |
| boolean isEnd = (i == parts.length - 2 && parts[parts.length - 1].isEmpty()); | |
| if (isStart || isEnd) { | |
| patternBuilder.append(".+"); | |
| } else { | |
| patternBuilder.append("[^").append(regexFileSeparator).append("]+"); | |
| } | |
| } | |
| } | |
| String pattern = patternBuilder.toString(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment suggests full alignment with javadoc -exclude behavior, but the plugin’s documented behavior (and tests) keep bare package names (e.g., org.acme.exclude2) as exact-only (not recursive). Please rephrase to clarify this only aligns trailing wildcards with javadoc, not bare package names.