jdcasey     2005/04/20 16:06:04

  Modified:    
maven-artifact/src/main/java/org/apache/maven/artifact/construction
                        ArtifactConstructionSupport.java
               
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover
                        LegacyArtifactDiscoverer.java
  Log:
  o Improved support for classifier parsing and added test artifact to the test 
repository for this.
  
  o Fixed issue in createXXX(..) method for constructing an artifact with a 
classifier...it was not actually calling the constructor that passes in the 
classifier.
  
  PR: MNG-312
  
  Revision  Changes    Path
  1.8       +3 -1      
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java
  
  Index: ArtifactConstructionSupport.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ArtifactConstructionSupport.java  15 Apr 2005 07:31:40 -0000      1.7
  +++ ArtifactConstructionSupport.java  20 Apr 2005 23:06:04 -0000      1.8
  @@ -69,6 +69,8 @@
               desiredScope = Artifact.SCOPE_TEST;
           }
   
  -        return new DefaultArtifact( groupId, artifactId, version, 
desiredScope, type );
  +        DefaultArtifact artifact = new DefaultArtifact( groupId, artifactId, 
version, desiredScope, type, classifier );
  +        
  +        return artifact;
       }
   }
  
  
  
  1.10      +77 -38    
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java
  
  Index: LegacyArtifactDiscoverer.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LegacyArtifactDiscoverer.java     20 Apr 2005 22:10:24 -0000      1.9
  +++ LegacyArtifactDiscoverer.java     20 Apr 2005 23:06:04 -0000      1.10
  @@ -156,65 +156,95 @@
           // Since version is at the end, we have to move in from the back.
           Collections.reverse( avceTokenList );
   
  -        String classifier = null;
  +        StringBuffer classifierBuffer = new StringBuffer();
           StringBuffer versionBuffer = new StringBuffer();
   
  -        boolean inFirstToken = true;
  +        boolean firstVersionTokenEncountered = false;
  +        boolean firstToken = true;
  +
  +        int tokensIterated = 0;
           for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
           {
               String token = (String) it.next();
   
               boolean tokenIsVersionPart = token.matches( validVersionParts );
  -            if ( inFirstToken && !tokenIsVersionPart )
  -            {
  -                classifier = token;
  -            }
  -            else if ( tokenIsVersionPart )
  +
  +            StringBuffer bufferToUpdate = null;
  +
  +            // NOTE: logic in code is reversed, since we're peeling off the 
back
  +            // Any token after the last versionPart will be in the 
classifier.
  +            // Any token UP TO first non-versionPart is part of the version.
  +            if ( !tokenIsVersionPart )
               {
  -                if ( !inFirstToken )
  +                if ( firstVersionTokenEncountered )
                   {
  -                    versionBuffer.insert( 0, '-' );
  +                    break;
  +                }
  +                else
  +                {
  +                    bufferToUpdate = classifierBuffer;
                   }
  -
  -                versionBuffer.insert( 0, token );
               }
               else
               {
  -                // if we didn't find a version, but we did find a 
'classifier', 
  -                // then push that classifier back onto the list...chances 
are, 
  -                // it doesn't have a version or a classifier if this is the 
case.
  -                if ( versionBuffer.length() < 1 && classifier != null )
  -                {
  -                    avceTokenList.addFirst( classifier );
  -                }
  +                firstVersionTokenEncountered = true;
   
  -                // we've discovered all the version parts. break the loop.
  -                break;
  +                bufferToUpdate = versionBuffer;
               }
   
  -            if ( inFirstToken )
  +            if ( firstToken )
               {
  -                inFirstToken = false;
  +                firstToken = false;
               }
  +            else
  +            {
  +                bufferToUpdate.insert( 0, '-' );
  +            }
  +
  +            bufferToUpdate.insert( 0, token );
   
  -            // pop the token off the list so it doesn't appear in the
  -            // artifactId.
  -            it.remove();
  +            tokensIterated++;
           }
  +        
  +        getLogger().debug("After parsing loop, state of buffers:\no  Version 
Buffer: \'" + versionBuffer + "\'\no  Classifier Buffer: \'" + classifierBuffer 
+ "\'\no Number of Tokens Iterated: " + tokensIterated);
   
           // Now, restore the proper ordering so we can build the artifactId.
           Collections.reverse( avceTokenList );
  +        
  +        getLogger().debug("Before repairing bad version and/or cleaning up 
used tokens, avce token list is:\n" + avceTokenList);
  +        
  +        // if we didn't find a version, then punt. Use the last token
  +        // as the version, and set the classifier empty.
  +        if ( versionBuffer.length() < 1 )
  +        {
  +            int lastIdx = avceTokenList.size() - 1;
  +            
  +            versionBuffer.append( avceTokenList.get( lastIdx ) );
  +            avceTokenList.remove( lastIdx );
  +
  +            classifierBuffer.setLength( 0 );
  +        }
  +        else
  +        {
  +            getLogger().debug("Removing " + tokensIterated + " tokens from 
avce token list.");
  +            
  +            // if everything is kosher, then pop off all the classifier and
  +            // version tokens, leaving the naked artifact id in the list.
  +            avceTokenList = new LinkedList( avceTokenList.subList( 0, 
avceTokenList.size() - ( tokensIterated ) ) );
  +        }
  +        
  +        getLogger().debug("Now, remainder of avce token list is:\n" + 
avceTokenList);
   
           StringBuffer artifactIdBuffer = new StringBuffer();
   
  -        inFirstToken = true;
  +        firstToken = true;
           for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
           {
               String token = (String) it.next();
   
  -            if ( inFirstToken )
  +            if ( firstToken )
               {
  -                inFirstToken = false;
  +                firstToken = false;
               }
               else
               {
  @@ -240,20 +270,29 @@
           }
   
           getLogger().debug(
  -                           "Extracted artifact information from path:\n" + 
"groupId: \'" + groupId + "\'\n"
  -                               + "artifactId: \'" + artifactId + "\'\n" + 
"type: \'" + type + "\'\n" + "version: \'"
  -                               + version + "\'\n" + "classifier: \'" + 
classifier + "\'" );
  -
  -        if ( classifier != null )
  -        {
  -            return artifactConstructionSupport.createArtifactWithClassifier( 
groupId, artifactId, version,
  -                                                                             
Artifact.SCOPE_RUNTIME, type, classifier );
  +                          "Extracted artifact information from path:\n" + 
"groupId: \'" + groupId + "\'\n"
  +                              + "artifactId: \'" + artifactId + "\'\n" + 
"type: \'" + type + "\'\n" + "version: \'"
  +                              + version + "\'\n" + "classifier: \'" + 
classifierBuffer.toString() + "\'" );
  +
  +        Artifact result = null;
  +
  +        if ( classifierBuffer.length() > 0 )
  +        {
  +            getLogger().debug("Creating artifact with classifier.");
  +            
  +            result = 
artifactConstructionSupport.createArtifactWithClassifier( groupId, artifactId, 
version,
  +                                                                             
  Artifact.SCOPE_RUNTIME, type,
  +                                                                             
  classifierBuffer.toString() );
           }
           else
           {
  -            return artifactConstructionSupport.createArtifact( groupId, 
artifactId, version, Artifact.SCOPE_RUNTIME,
  -                                                               type );
  +            result = artifactConstructionSupport.createArtifact( groupId, 
artifactId, version, Artifact.SCOPE_RUNTIME,
  +                                                                 type );
           }
  +
  +        getLogger().debug( "Resulting artifact is: " + result.getId() + " 
and has classifier of: " + result.getClassifier() + "\n\n" );
  +
  +        return result;
       }
   
   }
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to