You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2005/12/30 21:02:35 UTC

svn commit: r360157 - in /maven/repository-manager/trunk: maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/

Author: brett
Date: Fri Dec 30 12:02:27 2005
New Revision: 360157

URL: http://svn.apache.org/viewcvs?rev=360157&view=rev
Log:
more cleaning up

Modified:
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java?rev=360157&r1=360156&r2=360157&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java (original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java Fri Dec 30 12:02:27 2005
@@ -32,14 +32,15 @@
  *
  * @author John Casey
  * @author Brett Porter
- *
  * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="legacy" instantiation-strategy="per-lookup"
  */
 public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
     implements ArtifactDiscoverer
 {
-    /** @plexus.requirement */
+    /**
+     * @plexus.requirement
+     */
     private ArtifactFactory artifactFactory;
 
     public List discoverArtifacts( File repositoryBase, String blacklistedPatterns, boolean includeSnapshots )
@@ -72,255 +73,264 @@
     {
         StringTokenizer tokens = new StringTokenizer( path, "/\\" );
 
+        Artifact result = null;
+
         int numberOfTokens = tokens.countTokens();
 
         if ( numberOfTokens != 3 )
         {
             addKickedOutPath( path );
-
-            return null;
-        }
-
-        String groupId = tokens.nextToken();
-
-        String type = tokens.nextToken();
-
-        if ( !type.endsWith( "s" ) )
-        {
-            addKickedOutPath( path );
-
-            return null;
-        }
-        type = type.substring( 0, type.length() - 1 );
-
-        // contains artifactId, version, classifier, and extension.
-        String avceGlob = tokens.nextToken();
-
-        LinkedList avceTokenList = new LinkedList();
-
-        StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" );
-        while ( avceTokenizer.hasMoreTokens() )
-        {
-            avceTokenList.addLast( avceTokenizer.nextToken() );
-        }
-
-        String lastAvceToken = (String) avceTokenList.removeLast();
-
-        // TODO: share with other discoverer, use artifact handlers instead
-        if ( lastAvceToken.endsWith( ".tar.gz" ) )
-        {
-            type = "distribution-tgz";
-
-            lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() );
-
-            avceTokenList.addLast( lastAvceToken );
-        }
-        else if ( lastAvceToken.endsWith( "sources.jar" ) )
-        {
-            type = "java-source";
-
-            lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".jar".length() );
-
-            avceTokenList.addLast( lastAvceToken );
-        }
-        else if ( lastAvceToken.endsWith( ".zip" ) )
-        {
-            type = "distribution-zip";
-
-            lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() );
-
-            avceTokenList.addLast( lastAvceToken );
         }
         else
         {
-            int extPos = lastAvceToken.lastIndexOf( '.' );
-
-            if ( extPos > 0 )
-            {
-                String ext = lastAvceToken.substring( extPos + 1 );
-                if ( type.equals( ext ) )
-                {
-                    lastAvceToken = lastAvceToken.substring( 0, extPos );
+            String groupId = tokens.nextToken();
 
-                    avceTokenList.addLast( lastAvceToken );
-                }
-                else
-                {
-                    addKickedOutPath( path );
+            String type = tokens.nextToken();
 
-                    return null;
-                }
-            }
-            else
+            if ( !type.endsWith( "s" ) )
             {
-                // no extension
                 addKickedOutPath( path );
-
-                return null;
             }
-        }
-
-        // let's discover the version, and whatever's leftover will be either
-        // a classifier, or part of the artifactId, depending on position.
-        // Since version is at the end, we have to move in from the back.
-        Collections.reverse( avceTokenList );
-
-        // TODO: this is obscene - surely a better way?
-        String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" +
-            "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" +
-            "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" +
-            "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" +
-            "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" +
-            "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" +
-            "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "([AaBb][_.0-9]*)";
-
-        StringBuffer classifierBuffer = new StringBuffer();
-        StringBuffer versionBuffer = new StringBuffer();
-
-        boolean firstVersionTokenEncountered = false;
-        boolean firstToken = true;
-
-        int tokensIterated = 0;
-        for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
-        {
-            String token = (String) it.next();
+            else
+            {
+                type = type.substring( 0, type.length() - 1 );
 
-            boolean tokenIsVersionPart = token.matches( validVersionParts );
+                // contains artifactId, version, classifier, and extension.
+                String avceGlob = tokens.nextToken();
 
-            StringBuffer bufferToUpdate;
+                LinkedList avceTokenList = new LinkedList();
 
-            // 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 ( firstVersionTokenEncountered )
-                {
-                    //noinspection BreakStatement
-                    break;
-                }
-                else
+                StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" );
+                while ( avceTokenizer.hasMoreTokens() )
                 {
-                    bufferToUpdate = classifierBuffer;
+                    avceTokenList.addLast( avceTokenizer.nextToken() );
                 }
-            }
-            else
-            {
-                firstVersionTokenEncountered = true;
-
-                bufferToUpdate = versionBuffer;
-            }
 
-            if ( firstToken )
-            {
-                firstToken = false;
-            }
-            else
-            {
-                bufferToUpdate.insert( 0, '-' );
-            }
-
-            bufferToUpdate.insert( 0, token );
+                String lastAvceToken = (String) avceTokenList.removeLast();
 
-            tokensIterated++;
-        }
+                boolean valid = true;
 
-        getLogger().debug( "After parsing loop, state of buffers:\no  Version Buffer: \'" + versionBuffer +
-            "\'\no  Classifier Buffer: \'" + classifierBuffer + "\'\no Number of Tokens Iterated: " + tokensIterated );
+                // TODO: share with other discoverer, use artifact handlers instead
+                if ( lastAvceToken.endsWith( ".tar.gz" ) )
+                {
+                    type = "distribution-tgz";
 
-        // Now, restore the proper ordering so we can build the artifactId.
-        Collections.reverse( avceTokenList );
+                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() );
 
-        getLogger().debug(
-            "Before repairing bad version and/or cleaning up used tokens, avce token list is:\n" + avceTokenList );
+                    avceTokenList.addLast( lastAvceToken );
+                }
+                else if ( lastAvceToken.endsWith( "sources.jar" ) )
+                {
+                    type = "java-source";
 
-        // 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 )
-        {
-            if ( avceTokenList.size() > 1 )
-            {
-                int lastIdx = avceTokenList.size() - 1;
+                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".jar".length() );
 
-                versionBuffer.append( avceTokenList.get( lastIdx ) );
-                avceTokenList.remove( lastIdx );
-            }
-            else
-            {
-                getLogger().debug( "Cannot parse version from artifact path: \'" + path + "\'." );
-                getLogger().debug(
-                    "artifact-version-classifier-extension remaining tokens is: \'" + avceTokenList + "\'" );
-            }
+                    avceTokenList.addLast( lastAvceToken );
+                }
+                else if ( lastAvceToken.endsWith( ".zip" ) )
+                {
+                    type = "distribution-zip";
 
-            classifierBuffer.setLength( 0 );
-        }
-        else
-        {
-            getLogger().debug( "Removing " + tokensIterated + " tokens from avce token list." );
+                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() );
 
-            // 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 ) );
-        }
+                    avceTokenList.addLast( lastAvceToken );
+                }
+                else
+                {
+                    int extPos = lastAvceToken.lastIndexOf( '.' );
 
-        getLogger().debug( "Now, remainder of avce token list is:\n" + avceTokenList );
+                    if ( extPos > 0 )
+                    {
+                        String ext = lastAvceToken.substring( extPos + 1 );
+                        if ( type.equals( ext ) )
+                        {
+                            lastAvceToken = lastAvceToken.substring( 0, extPos );
+
+                            avceTokenList.addLast( lastAvceToken );
+                        }
+                        else
+                        {
+                            addKickedOutPath( path );
+
+                            valid = false;
+                        }
+                    }
+                    else
+                    {
+                        // no extension
+                        addKickedOutPath( path );
 
-        StringBuffer artifactIdBuffer = new StringBuffer();
+                        valid = false;
+                    }
+                }
 
-        firstToken = true;
-        for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
-        {
-            String token = (String) it.next();
+                if ( valid )
+                {
+                    // let's discover the version, and whatever's leftover will be either
+                    // a classifier, or part of the artifactId, depending on position.
+                    // Since version is at the end, we have to move in from the back.
+                    Collections.reverse( avceTokenList );
+
+                    // TODO: this is obscene - surely a better way?
+                    String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" +
+                        "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" +
+                        "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" +
+                        "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" +
+                        "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" +
+                        "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" +
+                        "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "([AaBb][_.0-9]*)";
+
+                    StringBuffer classifierBuffer = new StringBuffer();
+                    StringBuffer versionBuffer = new StringBuffer();
+
+                    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 );
+
+                        StringBuffer bufferToUpdate;
+
+                        // 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 ( firstVersionTokenEncountered )
+                            {
+                                //noinspection BreakStatement
+                                break;
+                            }
+                            else
+                            {
+                                bufferToUpdate = classifierBuffer;
+                            }
+                        }
+                        else
+                        {
+                            firstVersionTokenEncountered = true;
+
+                            bufferToUpdate = versionBuffer;
+                        }
+
+                        if ( firstToken )
+                        {
+                            firstToken = false;
+                        }
+                        else
+                        {
+                            bufferToUpdate.insert( 0, '-' );
+                        }
+
+                        bufferToUpdate.insert( 0, token );
+
+                        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 )
+                    {
+                        if ( avceTokenList.size() > 1 )
+                        {
+                            int lastIdx = avceTokenList.size() - 1;
+
+                            versionBuffer.append( avceTokenList.get( lastIdx ) );
+                            avceTokenList.remove( lastIdx );
+                        }
+                        else
+                        {
+                            getLogger().debug( "Cannot parse version from artifact path: \'" + path + "\'." );
+                            getLogger().debug( "artifact-version-classifier-extension remaining tokens is: \'" +
+                                avceTokenList + "\'" );
+                        }
+
+                        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();
+
+                    firstToken = true;
+                    for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
+                    {
+                        String token = (String) it.next();
+
+                        if ( firstToken )
+                        {
+                            firstToken = false;
+                        }
+                        else
+                        {
+                            artifactIdBuffer.append( '-' );
+                        }
+
+                        artifactIdBuffer.append( token );
+                    }
+
+                    String artifactId = artifactIdBuffer.toString();
+
+                    int lastVersionCharIdx = versionBuffer.length() - 1;
+                    if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
+                    {
+                        versionBuffer.setLength( lastVersionCharIdx );
+                    }
+
+                    String version = versionBuffer.toString();
+
+                    if ( version.length() < 1 )
+                    {
+                        addKickedOutPath( path );
+                    }
+                    else
+                    {
+                        getLogger().debug( "Extracted artifact information from path:\n" + "groupId: \'" + groupId +
+                            "\'\n" + "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" +
+                            "version: \'" + version + "\'\n" + "classifier: \'" + classifierBuffer + "\'" );
+
+                        if ( classifierBuffer.length() > 0 )
+                        {
+                            getLogger().debug( "Creating artifact with classifier." );
+
+                            result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
+                                                                                   classifierBuffer.toString() );
+                        }
+                        else
+                        {
+                            result = artifactFactory.createArtifact( groupId, artifactId, version,
+                                                                     Artifact.SCOPE_RUNTIME, type );
+                        }
 
-            if ( firstToken )
-            {
-                firstToken = false;
-            }
-            else
-            {
-                artifactIdBuffer.append( '-' );
+                        result.setFile( new File( path ) );
+                    }
+                }
             }
-
-            artifactIdBuffer.append( token );
         }
-
-        String artifactId = artifactIdBuffer.toString();
-
-        int lastVersionCharIdx = versionBuffer.length() - 1;
-        if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
-        {
-            versionBuffer.setLength( lastVersionCharIdx );
-        }
-
-        String version = versionBuffer.toString();
-
-        if ( version.length() < 1 )
-        {
-            addKickedOutPath( path );
-
-            return null;
-        }
-
-        getLogger().debug( "Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n" +
-            "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + "version: \'" + version + "\'\n" +
-            "classifier: \'" + classifierBuffer + "\'" );
-
-        Artifact result = null;
-
-        if ( classifierBuffer.length() > 0 )
-        {
-            getLogger().debug( "Creating artifact with classifier." );
-
-            result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
-                                                                   classifierBuffer.toString() );
-        }
-        else
-        {
-            result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type );
-        }
-
-        result.setFile( new File( path ) );
-
         return result;
     }
 

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java?rev=360157&r1=360156&r2=360157&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java Fri Dec 30 12:02:27 2005
@@ -203,7 +203,7 @@
      * @param filename The name of the artifact whose MD5 Checksum file will be retrieved.
      * @todo fix this erroneous object state
      */
-    public boolean getMD5File( String filename )
+    private boolean getMD5File( String filename )
     {
         try
         {
@@ -232,7 +232,7 @@
      * @param filename The name of the artifact whose SHA-1 Checksum file will be retrieved.
      * @todo fix this erroneous object state
      */
-    public boolean getSHA1File( String filename )
+    private boolean getSHA1File( String filename )
     {
         try
         {
@@ -278,7 +278,7 @@
 
                 //read the md5 file
                 File f = new File( fileUrl + ext );
-                InputStream is = null;
+                InputStream is;
 
                 //check whether the file is located locally or remotely
                 if ( isLocal )
@@ -319,7 +319,7 @@
      * @throws IOException
      * @todo move to utility class
      */
-    protected byte[] createChecksum( String filename, String algo )
+    private byte[] createChecksum( String filename, String algo )
         throws FileNotFoundException, NoSuchAlgorithmException, IOException
     {
         InputStream fis;
@@ -362,16 +362,14 @@
     public static String byteArrayToHexStr( byte[] data )
     {
         String output = "";
-        String tempStr = "";
-        int tempInt = 0;
 
         for ( int cnt = 0; cnt < data.length; cnt++ )
         {
             //Deposit a byte into the 8 lsb of an int.
-            tempInt = data[cnt] & BYTE_MASK;
+            int tempInt = data[cnt] & BYTE_MASK;
 
             //Get hex representation of the int as a string.
-            tempStr = Integer.toHexString( tempInt );
+            String tempStr = Integer.toHexString( tempInt );
 
             //Append a leading 0 if necessary so that each hex string will contain 2 characters.
             if ( tempStr.length() == 1 )