Author: epunzalan
Date: Tue Jan 31 01:15:13 2006
New Revision: 373773

URL: http://svn.apache.org/viewcvs?rev=373773&view=rev
Log:
PR: MRM-43

Refactored buildArtifact method from DefaultArtifactDiscoverer.java to a new 
class in maven-repository-utils for use maven-repository-proxy

Added:
    
maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
Modified:
    maven/repository-manager/trunk/maven-repository-discovery/pom.xml
    
maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
    maven/repository-manager/trunk/maven-repository-utils/pom.xml

Modified: maven/repository-manager/trunk/maven-repository-discovery/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/pom.xml?rev=373773&r1=373772&r2=373773&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-discovery/pom.xml Tue Jan 
31 01:15:13 2006
@@ -26,6 +26,10 @@
   <name>Maven Repository Artifact Discovery</name>
   <dependencies>
     <dependency>
+      <groupId>org.apache.maven.repository</groupId>
+      <artifactId>maven-repository-utils</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>

Modified: 
maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java?rev=373773&r1=373772&r2=373773&view=diff
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
 (original)
+++ 
maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
 Tue Jan 31 01:15:13 2006
@@ -19,14 +19,11 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.codehaus.plexus.util.StringUtils;
+import org.apache.maven.repository.ArtifactUtils;
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.StringTokenizer;
 
 /**
  * Artifact discoverer for the new repository layout (Maven 2.0+).
@@ -61,7 +58,7 @@
         {
             String path = artifactPaths[i];
 
-            Artifact artifact = buildArtifact( repositoryBase, path, 
repository );
+            Artifact artifact = ArtifactUtils.buildArtifact( repositoryBase, 
path, repository, artifactFactory );
 
             if ( artifact != null )
             {
@@ -70,165 +67,12 @@
                     artifacts.add( artifact );
                 }
             }
-        }
-
-        return artifacts;
-    }
-
-    private Artifact buildArtifact( File repositoryBase, String path, 
ArtifactRepository repository )
-    {
-        List pathParts = new ArrayList();
-        StringTokenizer st = new StringTokenizer( path, "/\\" );
-        while ( st.hasMoreTokens() )
-        {
-            pathParts.add( st.nextToken() );
-        }
-
-        Collections.reverse( pathParts );
-
-        Artifact finalResult = null;
-        if ( pathParts.size() < 4 )
-        {
-            addKickedOutPath( path );
-        }
-        else
-        {
-            // the actual artifact filename.
-            String filename = (String) pathParts.remove( 0 );
-
-            // the next one is the version.
-            String version = (String) pathParts.remove( 0 );
-
-            // the next one is the artifactId.
-            String artifactId = (String) pathParts.remove( 0 );
-
-            // the remaining are the groupId.
-            Collections.reverse( pathParts );
-            String groupId = StringUtils.join( pathParts.iterator(), "." );
-
-            String remainingFilename = filename;
-            if ( !remainingFilename.startsWith( artifactId + "-" ) )
-            {
-                addKickedOutPath( path );
-            }
             else
             {
-                remainingFilename = remainingFilename.substring( 
artifactId.length() + 1 );
-
-                String classifier = null;
-
-                // TODO: use artifact handler, share with legacy discoverer
-                String type = null;
-                if ( remainingFilename.endsWith( ".tar.gz" ) )
-                {
-                    type = "distribution-tgz";
-                    remainingFilename =
-                        remainingFilename.substring( 0, 
remainingFilename.length() - ".tar.gz".length() );
-                }
-                else if ( remainingFilename.endsWith( ".zip" ) )
-                {
-                    type = "distribution-zip";
-                    remainingFilename = remainingFilename.substring( 0, 
remainingFilename.length() - ".zip".length() );
-                }
-                else if ( remainingFilename.endsWith( "-sources.jar" ) )
-                {
-                    type = "java-source";
-                    classifier = "sources";
-                    remainingFilename =
-                        remainingFilename.substring( 0, 
remainingFilename.length() - "-sources.jar".length() );
-                }
-                else
-                {
-                    int index = remainingFilename.lastIndexOf( "." );
-                    if ( index < 0 )
-                    {
-                        addKickedOutPath( path );
-                    }
-                    else
-                    {
-                        type = remainingFilename.substring( index + 1 );
-                        remainingFilename = remainingFilename.substring( 0, 
index );
-                    }
-                }
-
-                if ( type != null )
-                {
-                    Artifact result;
-
-                    if ( classifier == null )
-                    {
-                        result = artifactFactory.createArtifact( groupId, 
artifactId, version, Artifact.SCOPE_RUNTIME,
-                                                                 type );
-                    }
-                    else
-                    {
-                        result = artifactFactory.createArtifactWithClassifier( 
groupId, artifactId, version, type,
-                                                                               
classifier );
-                    }
-
-                    if ( result.isSnapshot() )
-                    {
-                        // version is XXX-SNAPSHOT, filename is 
XXX-yyyyMMdd.hhmmss-b
-                        int classifierIndex = remainingFilename.indexOf( '-', 
version.length() + 8 );
-                        if ( classifierIndex >= 0 )
-                        {
-                            classifier = remainingFilename.substring( 
classifierIndex + 1 );
-                            remainingFilename = remainingFilename.substring( 
0, classifierIndex );
-                            result = 
artifactFactory.createArtifactWithClassifier( groupId, artifactId,
-                                                                               
    remainingFilename, type,
-                                                                               
    classifier );
-                        }
-                        else
-                        {
-                            result = artifactFactory.createArtifact( groupId, 
artifactId, remainingFilename,
-                                                                     
Artifact.SCOPE_RUNTIME, type );
-                        }
-
-                        // poor encapsulation requires we do this to populate 
base version
-                        if ( !result.isSnapshot() )
-                        {
-                            addKickedOutPath( path );
-                        }
-                        else if ( !result.getBaseVersion().equals( version ) )
-                        {
-                            addKickedOutPath( path );
-                        }
-                        else
-                        {
-                            finalResult = result;
-                        }
-                    }
-                    else if ( !remainingFilename.startsWith( version ) )
-                    {
-                        addKickedOutPath( path );
-                    }
-                    else if ( !remainingFilename.equals( version ) )
-                    {
-                        if ( remainingFilename.charAt( version.length() ) != 
'-' )
-                        {
-                            addKickedOutPath( path );
-                        }
-                        else
-                        {
-                            classifier = remainingFilename.substring( 
version.length() + 1 );
-                            finalResult = 
artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
-                                                                               
         type, classifier );
-                        }
-                    }
-                    else
-                    {
-                        finalResult = result;
-                    }
-                }
+                addKickedOutPath( path );
             }
         }
 
-        if ( finalResult != null )
-        {
-            finalResult.setRepository( repository );
-            finalResult.setFile( new File( repositoryBase, path ) );
-        }
-
-        return finalResult;
+        return artifacts;
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-utils/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/pom.xml?rev=373773&r1=373772&r2=373773&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-utils/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-utils/pom.xml Tue Jan 31 
01:15:13 2006
@@ -29,5 +29,9 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+    </dependency>
   </dependencies>
 </project>

Added: 
maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java?rev=373773&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
 Tue Jan 31 01:15:13 2006
@@ -0,0 +1,188 @@
+package org.apache.maven.repository;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ArtifactUtils
+{
+    public static Artifact buildArtifact( File repositoryBase, String path, 
ArtifactRepository repository,
+                                          ArtifactFactory artifactFactory )
+    {
+        List pathParts = new ArrayList();
+        StringTokenizer st = new StringTokenizer( path, "/\\" );
+        while ( st.hasMoreTokens() )
+        {
+            pathParts.add( st.nextToken() );
+        }
+
+        Collections.reverse( pathParts );
+
+        Artifact finalResult = null;
+        if ( pathParts.size() >= 4 )
+        {
+            // the actual artifact filename.
+            String filename = (String) pathParts.remove( 0 );
+
+            // the next one is the version.
+            String version = (String) pathParts.remove( 0 );
+
+            // the next one is the artifactId.
+            String artifactId = (String) pathParts.remove( 0 );
+
+            // the remaining are the groupId.
+            Collections.reverse( pathParts );
+            String groupId = StringUtils.join( pathParts.iterator(), "." );
+
+            String remainingFilename = filename;
+            if ( !remainingFilename.startsWith( artifactId + "-" ) )
+            {
+                return null;
+            }
+            else
+            {
+                remainingFilename = remainingFilename.substring( 
artifactId.length() + 1 );
+
+                String classifier = null;
+
+                // TODO: use artifact handler, share with legacy discoverer
+                String type;
+                if ( remainingFilename.endsWith( ".tar.gz" ) )
+                {
+                    type = "distribution-tgz";
+                    remainingFilename =
+                        remainingFilename.substring( 0, 
remainingFilename.length() - ".tar.gz".length() );
+                }
+                else if ( remainingFilename.endsWith( ".zip" ) )
+                {
+                    type = "distribution-zip";
+                    remainingFilename = remainingFilename.substring( 0, 
remainingFilename.length() - ".zip".length() );
+                }
+                else if ( remainingFilename.endsWith( "-sources.jar" ) )
+                {
+                    type = "java-source";
+                    classifier = "sources";
+                    remainingFilename =
+                        remainingFilename.substring( 0, 
remainingFilename.length() - "-sources.jar".length() );
+                }
+                else
+                {
+                    int index = remainingFilename.lastIndexOf( "." );
+                    if ( index < 0 )
+                    {
+                        return null;
+                    }
+                    else
+                    {
+                        type = remainingFilename.substring( index + 1 );
+                        remainingFilename = remainingFilename.substring( 0, 
index );
+                    }
+                }
+
+                if ( type != null )
+                {
+                    Artifact result;
+
+                    if ( classifier == null )
+                    {
+                        result = artifactFactory.createArtifact( groupId, 
artifactId, version, Artifact.SCOPE_RUNTIME,
+                                                                 type );
+                    }
+                    else
+                    {
+                        result = artifactFactory.createArtifactWithClassifier( 
groupId, artifactId, version, type,
+                                                                               
classifier );
+                    }
+
+                    if ( result.isSnapshot() )
+                    {
+                        // version is XXX-SNAPSHOT, filename is 
XXX-yyyyMMdd.hhmmss-b
+                        int classifierIndex = remainingFilename.indexOf( '-', 
version.length() + 8 );
+                        if ( classifierIndex >= 0 )
+                        {
+                            classifier = remainingFilename.substring( 
classifierIndex + 1 );
+                            remainingFilename = remainingFilename.substring( 
0, classifierIndex );
+                            result = 
artifactFactory.createArtifactWithClassifier( groupId, artifactId,
+                                                                               
    remainingFilename, type,
+                                                                               
    classifier );
+                        }
+                        else
+                        {
+                            result = artifactFactory.createArtifact( groupId, 
artifactId, remainingFilename,
+                                                                     
Artifact.SCOPE_RUNTIME, type );
+                        }
+
+                        // poor encapsulation requires we do this to populate 
base version
+                        if ( !result.isSnapshot() )
+                        {
+                            return null;
+                        }
+                        else if ( !result.getBaseVersion().equals( version ) )
+                        {
+                            return null;
+                        }
+                        else
+                        {
+                            finalResult = result;
+                        }
+                    }
+                    else if ( !remainingFilename.startsWith( version ) )
+                    {
+                        return null;
+                    }
+                    else if ( !remainingFilename.equals( version ) )
+                    {
+                        if ( remainingFilename.charAt( version.length() ) != 
'-' )
+                        {
+                            return null;
+                        }
+                        else
+                        {
+                            classifier = remainingFilename.substring( 
version.length() + 1 );
+                            finalResult = 
artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
+                                                                               
         type, classifier );
+                        }
+                    }
+                    else
+                    {
+                        finalResult = result;
+                    }
+                }
+            }
+        }
+
+        if ( finalResult != null )
+        {
+            finalResult.setRepository( repository );
+            finalResult.setFile( new File( repositoryBase, path ) );
+        }
+
+        return finalResult;
+    }
+}


Reply via email to