I have been using and popularizing Maven since many yeras. This week I am on some kind vacations so I decided to spend a day coding and contribute a little bit. I wanted to implement a "wildcard dependency exclusions feature" (MNG-3832). I have never browsed the Maven source code before, but after getting acquinted with the project structure, running and debugging it from eclipse I found the potential class to change. It was ExcludesArtifactFilter in the maven-artifact project.
The fix version of the feature was 2.x -> so I have checked out the code from the newest 2.2.x branch, since the trunk folder contains 3.x version.
I wanted the modification to be self-contained thus I have only changed the ExcludesArtifactFilter class. I have also created a test case (ExcludesArtifactFilterTest) encompassing 21 unit tests which proves the correctnes of the implemented approach.
I have extended the requested functionality a little bit. Right now, filter constructs literal java regular expression for every pattern which is contained by the list passed to the filter constructor. Include method matches given artifact against all patterns. Since it is an exlcusion filter - if artifact is matched at least once it will not be included. Filter defines "*" (star) as a wild-card character - a character that may be substituted for any other character(s). It is implemented in such a way, that every occurrence of a "*" (star) in the exclusion pattern is replaced with the ".*" expression during the construction of the literal java regex. Exclusion pattern can contain wild-card character zero or more times in any place in the groupId or artifactId;
Patch file is included as an external file to this issue.
Examples:
DEFINITION:
<exclusion>
<groupId>*</groupId>
</exclusion>
SEMANTICS: All artifacts are excluded.
LITERAL_JAVA_REGEX: .*:.* (optimized by excludeAll flag)
DEFINITION:
<exclusion>
<artifactId>*</artifactId>
</exclusion>
SEMANTICS: All artifacts are excluded.
LITERAL_JAVA_REGEX: .*:.* (optimized by excludeAll flag)
DEFINITION:
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
SEMANTICS: All artifacts are excluded.
LITERAL_JAVA_REGEX: .*:.* (optimized by excludeAll flag)
DEFINITION:
<exclusion>
<groupId>*</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
SEMANTICS: Artifacts with any groupId and with the artifactId equal to "commons-lang" will be excluded.
LITERAL_JAVA_REGEX: .*:commons-lang
DEFINITION:
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>*</artifactId>
</exclusion>
SEMANTICS: Artifacts with groupId "org.springframework" will be excluded.
LITERAL_JAVA_REGEX: org\.springframework:.*
MATCHING_ARTIFACT_EXAMPLES: org.springframework:spring-ws
NOT_MATCHING_ARTIFACT_EXAMPLES: org.springframework.snapshot:spring-ws
DEFINITION:
<exclusion>
<groupId>org.springframework.*</groupId>
<artifactId>*</artifactId>
</exclusion>
SEMANTICS: Artifacts with groupId beginning with "org.springframework." will be excluded.
LITERAL_JAVA_REGEX: org\.springframework\..*:.*
MATCHING_ARTIFACT_EXAMPLES: org.springframework.snapshot:spring-ws
NOT_MATCHING_ARTIFACT_EXAMPLES: org.springframeworksnapshot:spring-ws
DEFINITION:
<exclusion>
<groupId>org.springframework*</groupId>
<artifactId>*</artifactId>
</exclusion>
SEMANTICS: Artifacts with groupId beginning with "org.springframework" will be excluded.
LITERAL_JAVA_REGEX: org\.springframework.*:.*
MATCHING_ARTIFACT_EXAMPLES: org.springframework.snapshot:spring-ws, org.springframeworksnapshot:spring-ws
NOT_MATCHING_ARTIFACT_EXAMPLES: org.spring.snapshot:spring-ws
DEFINITION:
<exclusion>
<groupId>org.*.test</groupId>
<artifactId>*</artifactId>
</exclusion>
SEMANTICS: Artifacts with groupId beginning with "org." and ending with ".test" will be excluded.
LITERAL_JAVA_REGEX: org\..*\.test*:.*
MATCHING_ARTIFACT_EXAMPLES: org.apache.test:test-library, org.apache.snapshot.test:test-library
NOT_MATCHING_ARTIFACT_EXAMPLES: orgapachetest:test-library
I would like to see this as well, any news on this topic?