You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/06/11 10:39:11 UTC

[GitHub] [maven-common-artifact-filters] cstamas commented on a diff in pull request #26: [MSHARED-1077] Bugfix for classifier in pattern

cstamas commented on code in PR #26:
URL: https://github.com/apache/maven-common-artifact-filters/pull/26#discussion_r895007591


##########
src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java:
##########
@@ -255,540 +183,319 @@ public void reportMissedCriteria( final Logger logger )
 
                 for ( Pattern pattern : missed )
                 {
-                    buffer.append( "\no  '" ).append( pattern ).append( "'" );
+                    buffer.append( SEP ) .append( "o  '" ).append( pattern ).append( "'" );
                 }
 
-                buffer.append( "\n" );
+                buffer.append( SEP );
 
                 logger.warn( buffer.toString() );
             }
         }
     }
 
-    /** {@inheritDoc} */
     @Override
     public String toString()
     {
         return "Includes filter:" + getPatternsAsString();
     }
 
-    /**
-     * <p>getPatternsAsString.</p>
-     *
-     * @return pattern as a string.
-     */
     protected String getPatternsAsString()
     {
         final StringBuilder buffer = new StringBuilder();
         for ( Pattern pattern : patterns )
         {
-            buffer.append( "\no '" ).append( pattern ).append( "'" );
+            buffer.append( SEP ).append( "o '" ).append( pattern ).append( "'" );
         }
 
         return buffer.toString();
     }
 
-    /**
-     * <p>getFilterDescription.</p>
-     *
-     * @return description.
-     */
     protected String getFilterDescription()
     {
         return "artifact inclusion filter";
     }
 
-    /** {@inheritDoc} */
+    @Override
     public void reportFilteredArtifacts( final Logger logger )
     {
         if ( !filteredArtifact.isEmpty() && logger.isDebugEnabled() )
         {
-            final StringBuilder buffer =
-                new StringBuilder( "The following artifacts were removed by this " + getFilterDescription() + ": " );
+            final StringBuilder buffer = new StringBuilder(
+                    "The following artifacts were removed by this " + getFilterDescription() + ": " );
 
             for ( Artifact artifactId : filteredArtifact )
             {
-                buffer.append( '\n' ).append( artifactId.getId() );
+                buffer.append( SEP ).append( artifactId.getId() );
             }
 
             logger.debug( buffer.toString() );
         }
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * @return a boolean.
-     */
+    @Override
     public boolean hasMissedCriteria()
     {
         // if there are no patterns, there is nothing to report.
         if ( !patterns.isEmpty() )
         {
             final List<Pattern> missed = new ArrayList<>( patterns );
             missed.removeAll( patternsTriggered );
-
             return !missed.isEmpty();
         }
 
         return false;
     }
 
-    private static final char[] EMPTY = new char[0];
-
-    private static final char[] ANY = new char[] { '*' };
-
-    static char[] emptyOrChars( String str )
+    private enum Coordinate
     {
-        return str != null && str.length() > 0 ? str.toCharArray() : EMPTY;
+        GROUP_ID, ARTIFACT_ID, TYPE, CLASSIFIER, BASE_VERSION
     }
 
-    static char[] anyOrChars( char[] str )
+    private interface Artifactoid
     {
-        return str.length > 1 || ( str.length == 1 && str[0] != '*' ) ? str : ANY;
-    }
-
-    static char[][] tokenizeAndSplit( String pattern )
-    {
-        String[] stokens = pattern.split( ":" );
-        char[][] tokens = new char[ stokens.length ][];
-        for ( int i = 0; i < stokens.length; i++ )
-        {
-            tokens[i] = emptyOrChars( stokens[i] );
-        }
-        return tokens;
+        String getCoordinate( Coordinate coordinate );
     }
 
-    @SuppressWarnings( "InnerAssignment" )
-    static boolean match( char[] patArr, char[] strArr, boolean isVersion )
+    private static Artifactoid adapt( final Artifact artifact )
     {
-        int patIdxStart = 0;
-        int patIdxEnd = patArr.length - 1;
-        int strIdxStart = 0;
-        int strIdxEnd = strArr.length - 1;
-        char ch;
-
-        boolean containsStar = false;
-        for ( char aPatArr : patArr )
-        {
-            if ( aPatArr == '*' )
-            {
-                containsStar = true;
-                break;
-            }
-        }
-
-        if ( !containsStar )
-        {
-            if ( isVersion && ( patArr[0] == '[' || patArr[0] == '(' ) )
-            {
-                return isVersionIncludedInRange( String.valueOf( strArr ), String.valueOf( patArr ) );
-            }
-            // No '*'s, so we make a shortcut
-            if ( patIdxEnd != strIdxEnd )
-            {
-                return false; // Pattern and string do not have the same size
-            }
-            for ( int i = 0; i <= patIdxEnd; i++ )
-            {
-                ch = patArr[i];
-                if ( ch != '?' && ch != strArr[i] )
-                {
-                    return false; // Character mismatch
-                }
-            }
-            return true; // String matches against pattern
-        }
-
-        if ( patIdxEnd == 0 )
-        {
-            return true; // Pattern contains only '*', which matches anything
-        }
-
-        // Process characters before first star
-        while ( ( ch = patArr[patIdxStart] ) != '*' && strIdxStart <= strIdxEnd )
-        {
-            if ( ch != '?' && ch != strArr[strIdxStart] )
-            {
-                return false; // Character mismatch
-            }
-            patIdxStart++;
-            strIdxStart++;
-        }
-        if ( strIdxStart > strIdxEnd )
+        requireNonNull( artifact );
+        return coordinate ->
         {
-            // All characters in the string are used. Check if only '*'s are
-            // left in the pattern. If so, we succeeded. Otherwise failure.
-            for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+            requireNonNull( coordinate );
+            switch ( coordinate )
             {
-                if ( patArr[i] != '*' )
-                {
-                    return false;
-                }
+                case GROUP_ID:
+                    return artifact.getGroupId();
+                case ARTIFACT_ID:
+                    return artifact.getArtifactId();
+                case BASE_VERSION:
+                    return artifact.getBaseVersion();
+                case CLASSIFIER:
+                    return artifact.hasClassifier() ? artifact.getClassifier() : null;
+                case TYPE:
+                    return artifact.getType();
+                default:
             }
-            return true;
-        }
+            throw new IllegalArgumentException( "unknown coordinate: " + coordinate );
+        };
+    }
 
-        // Process characters after last star
-        while ( ( ch = patArr[patIdxEnd] ) != '*' && strIdxStart <= strIdxEnd )
+    private static Artifactoid adapt( final String depTrailString )
+    {
+        requireNonNull( depTrailString );
+        // G:A:T:C:V

Review Comment:
   You want me to document `org.apache.maven.artifact.Artifact#getDependencyTrail()` method here?



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org