gnodet commented on a change in pull request #15:
URL:
https://github.com/apache/maven-common-artifact-filters/pull/15#discussion_r563729856
##########
File path:
src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java
##########
@@ -107,322 +147,831 @@ public boolean include( final Artifact artifact )
*/
protected boolean patternMatches( final Artifact artifact )
{
- return positiveMatch( artifact ) == Boolean.TRUE || negativeMatch(
artifact ) == Boolean.FALSE;
+ // Check if the main artifact matches
+ char[][] artifactGatvCharArray = new char[][] {
+ emptyOrChars( artifact.getGroupId() ),
+ emptyOrChars( artifact.getArtifactId() ),
+ emptyOrChars( artifact.getType() ),
+ emptyOrChars( artifact.getBaseVersion() )
+ };
+ Boolean match = match( artifactGatvCharArray );
+ if ( match != null )
+ {
+ return match;
+ }
+
+ if ( actTransitively )
+ {
+ final List<String> depTrail = artifact.getDependencyTrail();
+
+ if ( depTrail != null && depTrail.size() > 1 )
+ {
+ for ( String trailItem : depTrail )
+ {
+ char[][] depGatvCharArray = tokenizeAndSplit( trailItem );
+ match = match( depGatvCharArray );
+ if ( match != null )
+ {
+ return match;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private Boolean match( char[][] gatvCharArray )
+ {
+ if ( simplePatterns != null && simplePatterns.size() > 0 )
+ {
+ // We add the parts one by one to the builder
+ StringBuilder sb = new StringBuilder();
+ for ( int i = 0; i < 4; i++ )
+ {
+ if ( i > 0 )
+ {
+ sb.append( ":" );
+ }
+ sb.append( gatvCharArray[i] );
+ Map<String, Pattern> map = simplePatterns.get( i );
+ if ( map != null )
+ {
+ // Check if one of the pattern matches
+ Pattern p = map.get( sb.toString() );
+ if ( p != null )
+ {
+ patternsTriggered.add( p );
+ return true;
+ }
+ }
+ }
+ }
+ // Check all other patterns
+ for ( Pattern pattern : patterns )
+ {
+ if ( pattern.matches( gatvCharArray ) )
+ {
+ patternsTriggered.add( pattern );
+ return !( pattern instanceof NegativePattern );
+ }
+ }
+
+ return null;
}
/**
- * @param artifactId add artifact to the filtered artifacts list.
+ * @param artifact add artifact to the filtered artifacts list.
*/
- protected void addFilteredArtifactId( final String artifactId )
+ protected void addFilteredArtifactId( final Artifact artifact )
Review comment:
Fixed
##########
File path:
src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java
##########
@@ -42,15 +47,20 @@
public class PatternIncludesArtifactFilter
implements ArtifactFilter, StatisticsReportingArtifactFilter
{
- private final List<String> positivePatterns;
+ /** Holds the set of compiled patterns */
+ private final Set<Pattern> patterns;
- private final List<String> negativePatterns;
+ /** Holds simple patterns: those that can use direct matching */
+ private final Map<Integer, Map<String, Pattern>> simplePatterns;
+ /** Wether the dependency trail should be checked */
Review comment:
Fixed
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]