-
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
base: master
Are you sure you want to change the base?
Conversation
The matcher returned by that method combines the effects of all includes and excludes.
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
Outdated
Show resolved
Hide resolved
@@ -144,13 +143,15 @@ public DefaultSourceRoot(final ProjectScope scope, final Language language, fina | |||
* @param scope scope of source code (main or test) | |||
* @param language language of the source code | |||
* @param directory directory of the source code | |||
* @param includes list of patterns for the files to include, or {@code null} if unspecified |
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.
unspecified or nothing to include?
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.
Unspecified. The default is plugin-dependent. For example, the compiler plugin will default to the *.java
includes. Other plugins may have different default.
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.
Effective Java suggests returning empty lists instead of nulls as a general practice.
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.
Actually this "null or empty" (will update the documentation). This is a parameter rather than a return value, accepting both for convenience.
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
*/ | ||
@Override | ||
public String toString() { | ||
var buffer = new StringBuilder(); |
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.
personally I dislike var. Not sure if there's a project setting on this
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.
I do not know if there is a Maven policy. Personally, I use it when it is redundant with what we can read on the same line with no possibility of different result (e.g., the result of new
), but generally avoid it for the return value of a method call for example, as it is not obvious by reading the line.
impl/maven-impl/src/test/java/org/apache/maven/impl/PathSelectorTest.java
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
@@ -144,13 +143,15 @@ public DefaultSourceRoot(final ProjectScope scope, final Language language, fina | |||
* @param scope scope of source code (main or test) | |||
* @param language language of the source code | |||
* @param directory directory of the source code | |||
* @param includes list of patterns for the files to include, or {@code null} if unspecified |
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.
Effective Java suggests returning empty lists instead of nulls as a general practice.
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
* | ||
* @param path the path to test | ||
*/ | ||
private void assertContains(String path) { |
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.
I think this method would be clearer inlined. It's just one line.
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.
That line has some degrees of freedom (the collection, the base directory, the message in case of failure), even if I agree that there is not much (yet) real freedom because there is only one collection and one directory. A purpose of using a method is that, when many calls to assertContains
are repeated, we know that those things are the same for every lines without having to paid a closer look to the lines.
I will rename as assertFilteredFilesContains
for more clarity.
bb751b8
to
3522863
Compare
by `PathMatcher matcher(Collection, boolean)`.
…more because of the introduction or more argument to the `matcher` method in previous commit.
…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.
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 |
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.