-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[MNG-8686] Add SourceRoot.matcher(boolean)
method
#2236
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
Conversation
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
1f5f25d
to
1e1757c
Compare
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.
Does this have/need a JIRA issue?
api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
bb751b8
to
3522863
Compare
JIRA issue created: https://issues.apache.org/jira/browse/MNG-8686 |
SourceRoot.matcher(boolean)
methodSourceRoot.matcher(boolean)
method
We'd need to carefully review the maven-resources-plugins various options and see if they can fit this API. IIRC, there are options such as symlinks following, but there may be others. |
Yes. This is another aspect replaced by standard Java now, with Symbolic links are not handled by the |
api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
Outdated
Show resolved
Hide resolved
@desruisseaux can you rebase or merge master branch to fix the conflict ? |
…), add a `SourceRoot.matcher(boolean)` method. The matcher returned by that method combines the effects of all includes and excludes. When using the Maven syntax, escape the special characters [ ] { } \ before to delegate to the glob syntax. Optimization: omit excludes that are unnecessary because they will never match a file accepted by includes. This is especially useful when the default excludes are added, because there is a lot of them.
1c028ec
to
fe0ca2f
Compare
Rebasing done. |
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.
polish
impl/maven-impl/src/main/java/org/apache/maven/impl/PathSelector.java
Outdated
Show resolved
Hide resolved
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.
consider Migrate JUnit asserts to AssertJ
String s = matcher.toString(); | ||
assertTrue(s.contains("glob:**/*.java")); | ||
assertFalse(s.contains("project.pj")); // Unnecessary exclusion should have been omitted. | ||
assertFalse(s.contains(".DS_Store")); |
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.
assertFalse(s.contains(".DS_Store")); | |
assertThat(s).contains(".DS_Store"); |
new code, already, considered, outdated - therefore increasing technical dept.
to reach next lvl, we need leadership and team up to standardize DOD
.

consider migration to avoid boilerplate API usage.
- [POC] Migrate
JUnit
asserts toAssertJ
- impl #2307 - https://docs.openrewrite.org/recipes/java/testing/assertj/junittoassertj
Still new manual interaction due to bug:
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.
Let's do the refactoring in the other PR related to AssertJ migration.
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.
yes
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.
Co-authored-by: VIP <8830888+Pankraz76@users.noreply.github.com>
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.
warnings
* Note that a prefix or suffix may be the empty string, which match everything. | ||
*/ | ||
final Iterator<String> it = excludes.iterator(); | ||
nextExclude: |
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.
* @return the given array, or a smaller array if some fragments were discarded because redundant | ||
*/ | ||
private static String[] sortByLength(final String[] fragments, final boolean suffix) { | ||
Arrays.sort(fragments, (s1, s2) -> s1.length() - s2.length()); |
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.
* <p><b>Source:</b> this list is copied from {@code plexus-utils-4.0.2} (released in | ||
* September 23, 2024), class {@code org.codehaus.plexus.util.AbstractScanner}.</p> | ||
*/ | ||
private static final List<String> DEFAULT_EXCLUDES = List.of( |
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.
might use simple alphabetical order sorter like in .propertie
files - to get sort and grouping out of the box:
The comments mostly DRY.
private static final List<String> DEFAULT_EXCLUDES = List.of( | |
private static final List<String> DEFAULT_EXCLUDES = List.of( | |
"**/*~", | |
"**/#*#", | |
"**/.#*", | |
"**/%*%", | |
"**/._*", | |
"**/CVS", | |
"**/CVS/**", | |
"**/.cvsignore", | |
"**/RCS", | |
"**/RCS/**", | |
"**/SCCS", | |
"**/SCCS/**", | |
"**/vssver.scc", | |
"**/project.pj", | |
"**/.svn", | |
"**/.svn/**", | |
"**/.arch-ids", | |
"**/.arch-ids/**", | |
"**/.bzr", | |
"**/.bzr/**", | |
"**/.MySCMServerInfo", | |
"**/.DS_Store", | |
"**/.metadata", | |
"**/.metadata/**", | |
"**/.hg", | |
"**/.hg/**", | |
"**/.git", | |
"**/.git/**", | |
"**/.gitignore", | |
"**/BitKeeper", | |
"**/BitKeeper/**", | |
"**/ChangeSet", | |
"**/ChangeSet/**", | |
"**/_darcs", | |
"**/_darcs/**", | |
"**/.darcsrepo", | |
"**/.darcsrepo/**", | |
"**/-darcs-backup*", | |
"**/.darcs-temp-mail" | |
); |
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.
same case: checkstyle/checkstyle#16760 (comment)
if (baseDirectory.equals(directory)) { | ||
return true; | ||
} | ||
directory = baseDirectory.relativize(directory); |
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.
smell
never reassign params as we live in final land.
give dedication method and apply functional programming.
https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#avoidreassigningparameters
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.
public boolean couldHoldSelected(Path directory) {
return baseDirectory.equals(directory) || isABoolean(baseDirectory.relativize(directory));
}
private boolean isABoolean(Path directory) {
return dirIncludes.length == 0 || isMatched(directory, dirIncludes)
&& (dirExcludes.length == 0 || !isMatched(directory, dirExcludes));
}

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.
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.
checkup
leveraging PMD will prevent flaws from being merged. |
this could not compile with help of https://docs.openrewrite.org/recipes/staticanalysis/finalizemethodarguments |
rewrite would make the boilerplate way i would prefer silent PMD. https://adabeat.com/fp/immutability-in-functional-programming/ We make everywhere boilerplate to throw NPE ourselfs. This would really help to make thinks more robust. immutability is/should be the default case. Kotlin is all about being final and avoiding silly NPE. Thats why we want to live in final existence. Trying to reach invinity. |
The matcher returned by that method combines the effects of all includes and excludes. When using the Maven syntax, escape the special characters [ ] { } \ before to delegate to the glob syntax. Optimization: omit excludes that are unnecessary because they will never match a file accepted by includes. This is especially useful when the default excludes are added, because there is a lot of them. --------- Co-authored-by: VIP <8830888+Pankraz76@users.noreply.github.com>
I don't think we want additional reports. Or that would nice as a GitHub action that runs on PRs. |
disagree, its called best practise for reason. agree, with help of rewrite, we can get benefits for free. Enforcing really strong coding guidelines. |
just need to use what we already got: ![]() I see plugin in pom, but not running. So im this should be our SPOT meaning single point of truth. https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html Then we dont have friction about final params. Im sure @desruisseaux very capable of, and would like to, following patterns to avoid bugs. We all want to best for the code. |
Actually, they are available at https://maven.apache.org/ref/4.0.0-rc-3/maven-impl-modules/maven-core/pmd.html but I don't think we'll keep them on the long term. |
yes, rewrite has ability to dominate. |
If the discussion is about avoiding to reassign parameter values, those best practices are guidelines, often improving software but not always. For example, reassigning a parameter with something unrelated is dangerous. In that case, the best practice applies. But reassigning a parameter with a "fixed" (from the perspective of what the method wants to do) value can be good since it guarantees that the potentially broken value is never used. For example, if a method said that it ignores leading and trailing spaces, doing |
yes, will always allow suppression making exception, for good argument. |
Following the revert of includes/excludes filters from
PathMatcher
toString
in #2232, this pull request adds a newSourceRoot.matcher(boolean)
method which provides thePathMatcher
. Contrarily to the previous methods, this new method provides a single matcher combining the work of all includes and all excludes. The default implementation is ported from apache/maven-clean-plugin#243.JIRA issue: MNG-8686