]> source.dussan.org Git - archiva.git/commitdiff
Added reason parameter in kickedOutPaths. Also, added an interface with the kickedOu...
authorEdwin L. Punzalan <epunzalan@apache.org>
Tue, 13 Jun 2006 06:53:38 +0000 (06:53 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Tue, 13 Jun 2006 06:53:38 +0000 (06:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@413818 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java [new file with mode: 0644]
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java [new file with mode: 0644]
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java
maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java

index 22b463ac2ec428f21120f1b8fac7cbc9839fc980..63d916fd6ef20db948e384ece874081d2516805a 100644 (file)
@@ -73,17 +73,19 @@ public abstract class AbstractArtifactDiscoverer
         {
             String path = artifactPaths[i];
 
-            Artifact artifact = buildArtifactFromPath( path, repository );
-            if ( artifact != null )
+            Artifact artifact = null;
+            try
             {
+                artifact = buildArtifactFromPath( path, repository );
+
                 if ( includeSnapshots || !artifact.isSnapshot() )
                 {
                     artifacts.add( artifact );
                 }
             }
-            else
+            catch ( DiscovererException e )
             {
-                addKickedOutPath( path );
+                addKickedOutPath( path, e.getMessage() );
             }
         }
 
@@ -103,14 +105,16 @@ public abstract class AbstractArtifactDiscoverer
         {
             String path = artifactPaths[i];
 
+            String filename = repositoryBase.getAbsolutePath() + "/" + path;
+
             if ( path.toLowerCase().endsWith( POM ) )
             {
-                Artifact pomArtifact = buildArtifactFromPath( path, repository );
-
-                MavenXpp3Reader mavenReader = new MavenXpp3Reader();
-                String filename = repositoryBase.getAbsolutePath() + "/" + path;
                 try
                 {
+                    Artifact pomArtifact = buildArtifactFromPath( path, repository );
+
+                    MavenXpp3Reader mavenReader = new MavenXpp3Reader();
+
                     Model model = mavenReader.read( new FileReader( filename ) );
                     if ( pomArtifact != null && "pom".equals( model.getPackaging() ) )
                     {
@@ -134,6 +138,10 @@ public abstract class AbstractArtifactDiscoverer
                     getLogger().error(
                         "Parse error reading file during POM discovery: " + filename + ": " + e.getMessage() );
                 }
+                catch ( DiscovererException e )
+                {
+                    getLogger().error( e.getMessage() );
+                }
             }
         }
 
@@ -141,6 +149,7 @@ public abstract class AbstractArtifactDiscoverer
     }
 
     public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
+        throws DiscovererException
     {
         Artifact artifact = buildArtifact( path );
 
index 65db8a50d6c9168a9f5726cfc8ff562e9b9b1f0d..3fbc8778889594827e6450031aaddfa8ad1bb858 100644 (file)
@@ -26,6 +26,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * Base class for the artifact and metadata discoverers.
@@ -34,8 +36,9 @@ import java.util.List;
  */
 public abstract class AbstractDiscoverer
     extends AbstractLogEnabled
+    implements Discoverer
 {
-    private List kickedOutPaths = new ArrayList();
+    private Map kickedOutPaths = new HashMap();
 
     /**
      * @plexus.requirement
@@ -50,16 +53,16 @@ public abstract class AbstractDiscoverer
      * Add a path to the list of files that were kicked out due to being invalid.
      *
      * @param path the path to add
-     * @todo add a reason
+     * @param reason the reason why the path is being kicked out
      */
-    protected void addKickedOutPath( String path )
+    protected void addKickedOutPath( String path, String reason )
     {
-        kickedOutPaths.add( path );
+        kickedOutPaths.put( path, reason );
     }
 
     public Iterator getKickedOutPathsIterator()
     {
-        return kickedOutPaths.iterator();
+        return kickedOutPaths.keySet().iterator();
     }
 
     /**
index 52b011b77b4169998f2f4cf367be1e8d31f9af9a..19e008d34d57cc139202f5944360fc0e7eaa44d7 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.maven.repository.discovery;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -29,6 +28,7 @@ import java.util.List;
  * @author Brett Porter
  */
 public interface ArtifactDiscoverer
+    extends Discoverer
 {
     String ROLE = ArtifactDiscoverer.class.getName();
 
@@ -58,20 +58,6 @@ public interface ArtifactDiscoverer
      */
     List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots );
 
-    /**
-     * Get the list of paths kicked out during the discovery process.
-     *
-     * @return the paths as Strings.
-     */
-    Iterator getKickedOutPathsIterator();
-
-    /**
-     * Get the list of paths excluded during the discovery process.
-     *
-     * @return the paths as Strings.
-     */
-    Iterator getExcludedPathsIterator();
-
     /**
      * Build an artifact from a path in the repository
      *
@@ -79,5 +65,6 @@ public interface ArtifactDiscoverer
      * @return the artifact
      * @todo this should be in maven-artifact
      */
-    Artifact buildArtifact( String path );
+    Artifact buildArtifact( String path )
+        throws DiscovererException;
 }
index 4ec84f66d694f66a266c396e19435202d2f0a095..5d7e32a6a7c91cfe0dd5d2c6a484c67e28daaa11 100644 (file)
@@ -35,6 +35,7 @@ public class DefaultArtifactDiscoverer
     extends AbstractArtifactDiscoverer
 {
     public Artifact buildArtifact( String path )
+        throws DiscovererException
     {
         List pathParts = new ArrayList();
         StringTokenizer st = new StringTokenizer( path, "/\\" );
@@ -64,11 +65,7 @@ public class DefaultArtifactDiscoverer
             String groupId = StringUtils.join( pathParts.iterator(), "." );
 
             String remainingFilename = filename;
-            if ( !remainingFilename.startsWith( artifactId + "-" ) )
-            {
-                return null;
-            }
-            else
+            if ( remainingFilename.startsWith( artifactId + "-" ) )
             {
                 remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
 
@@ -97,87 +94,92 @@ public class DefaultArtifactDiscoverer
                 else
                 {
                     int index = remainingFilename.lastIndexOf( "." );
-                    if ( index < 0 )
+                    if ( index >= 0 )
                     {
-                        return null;
+                        type = remainingFilename.substring( index + 1 );
+                        remainingFilename = remainingFilename.substring( 0, index );
                     }
                     else
                     {
-                        type = remainingFilename.substring( index + 1 );
-                        remainingFilename = remainingFilename.substring( 0, index );
+                        throw new DiscovererException( "Path filename does not have an extension" );
                     }
                 }
 
-                if ( type != null )
+                Artifact result;
+                if ( classifier == null )
+                {
+                    result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
+                                                             type );
+                }
+                else
                 {
-                    Artifact result;
+                    result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
+                                                                           classifier );
+                }
 
-                    if ( classifier == null )
+                if ( result.isSnapshot() )
+                {
+                    // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b
+                    int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 );
+                    if ( classifierIndex >= 0 )
                     {
-                        result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
-                                                                 type );
+                        classifier = remainingFilename.substring( classifierIndex + 1 );
+                        remainingFilename = remainingFilename.substring( 0, classifierIndex );
+                        result = artifactFactory.createArtifactWithClassifier( groupId, artifactId,
+                                                                               remainingFilename, type,
+                                                                               classifier );
                     }
                     else
                     {
-                        result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
-                                                                               classifier );
+                        result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename,
+                                                                 Artifact.SCOPE_RUNTIME, type );
                     }
 
-                    if ( result.isSnapshot() )
+                    // poor encapsulation requires we do this to populate base version
+                    if ( !result.isSnapshot() )
                     {
-                        // version is *-SNAPSHOT, filename is *-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
-                        {
-                            artifact = result;
-                        }
+                        throw new DiscovererException( "Failed to create a snapshot artifact" );
                     }
-                    else if ( !remainingFilename.startsWith( version ) )
+                    else if ( !result.getBaseVersion().equals( version ) )
                     {
-                        return null;
+                        throw new DiscovererException( "Built snapshot artifact base version does not match " +
+                                                       "path version" );
                     }
-                    else if ( !remainingFilename.equals( version ) )
+                    else
                     {
-                        if ( remainingFilename.charAt( version.length() ) != '-' )
-                        {
-                            return null;
-                        }
-                        else
-                        {
-                            classifier = remainingFilename.substring( version.length() + 1 );
-                            artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
-                                                                                     classifier );
-                        }
+                        artifact = result;
+                    }
+                }
+                else if ( !remainingFilename.startsWith( version ) )
+                {
+                    throw new DiscovererException( "Built artifact version does not match path version" );
+                }
+                else if ( !remainingFilename.equals( version ) )
+                {
+                    if ( remainingFilename.charAt( version.length() ) == '-' )
+                    {
+                        classifier = remainingFilename.substring( version.length() + 1 );
+                        artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
+                                                                                 classifier );
                     }
                     else
                     {
-                        artifact = result;
+                        throw new DiscovererException( "Path version does not corresspond to an artifact version" );
                     }
                 }
+                else
+                {
+                    artifact = result;
+                }
             }
+            else
+            {
+                throw new DiscovererException( "Path filename does not correspond to an artifact" );
+            }
+        }
+        else
+        {
+            throw new DiscovererException( "Path is too short to build an artifact from" );
         }
 
         return artifact;
index e07cd14d3d4ef78eb79b86679a1f29069663838d..8dd3bf7faff802168aa87dd14c2a9e26a1712ed2 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -67,15 +68,14 @@ public class DefaultMetadataDiscoverer
 
         for ( int i = 0; i < metadataPaths.length; i++ )
         {
-            RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] );
-
-            if ( metadata != null )
+            try
             {
+                RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] );
                 metadataFiles.add( metadata );
             }
-            else
+            catch ( DiscovererException e )
             {
-                addKickedOutPath( metadataPaths[i] );
+                addKickedOutPath( metadataPaths[i], e.getMessage() );
             }
         }
 
@@ -90,6 +90,7 @@ public class DefaultMetadataDiscoverer
      * @return the metadata
      */
     private RepositoryMetadata buildMetadata( String repo, String metadataPath )
+        throws DiscovererException
     {
         Metadata m = null;
         String repoPath = repo + "/" + metadataPath;
@@ -104,23 +105,26 @@ public class DefaultMetadataDiscoverer
         }
         catch ( XmlPullParserException e )
         {
-            getLogger().error( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e );
+            throw new DiscovererException( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e );
         }
         catch ( MalformedURLException e )
         {
             // shouldn't happen
-            getLogger().error( "Error constructing metadata file '" + repoPath + "': " + e.getMessage(), e );
+            throw new DiscovererException( "Error constructing metadata file '" + repoPath + "': " +
+                                           e.getMessage(), e );
         }
         catch ( IOException e )
         {
-            getLogger().error( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e );
+            throw new DiscovererException( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e );
         }
 
-        RepositoryMetadata repositoryMetadata = null;
-        if ( m != null )
+        RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataPath );
+
+        if ( repositoryMetadata == null )
         {
-            repositoryMetadata = buildMetadata( m, metadataPath );
+            throw new DiscovererException( "Unable to build a repository metadata from path" );
         }
+
         return repositoryMetadata;
     }
 
@@ -146,14 +150,8 @@ public class DefaultMetadataDiscoverer
         Iterator it = pathParts.iterator();
         String tmpDir = (String) it.next();
 
-        //ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-        //if( metaVersion != null && !metaVersion.equals( "" ) )
-        //{
-        //   VersionRange version = VersionRange.createFromVersion( metaVersion );
-        //}
-
         Artifact artifact = null;
-        if ( metaVersion != null && !"".equals( metaVersion ) )
+        if ( !StringUtils.isEmpty( metaVersion ) )
         {
             artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" );
         }
diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java
new file mode 100644 (file)
index 0000000..9a9b615
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.maven.repository.discovery;
+
+import java.util.Iterator;
+
+/*
+ * 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 interface Discoverer
+{
+    /**
+     * Get the list of paths kicked out during the discovery process.
+     *
+     * @return the paths as Strings.
+     */
+    Iterator getKickedOutPathsIterator();
+
+    /**
+     * Get the list of paths excluded during the discovery process.
+     *
+     * @return the paths as Strings.
+     */
+    Iterator getExcludedPathsIterator();
+}
diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java
new file mode 100644 (file)
index 0000000..937e178
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.maven.repository.discovery;
+
+/*
+ * 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 DiscovererException
+    extends Exception
+{
+    public DiscovererException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public DiscovererException( String message )
+    {
+        super( message );
+    }
+
+    public DiscovererException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}
index a5092c1bd279412b0d06e2b12b9bd4f12c4434a8..1040d580a9eae28412f937f6bcbc052f4f5769d1 100644 (file)
@@ -38,10 +38,11 @@ public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
 {
     public Artifact buildArtifact( String path )
+        throws DiscovererException
     {
         StringTokenizer tokens = new StringTokenizer( path, "/\\" );
 
-        Artifact result = null;
+        Artifact result;
 
         int numberOfTokens = tokens.countTokens();
 
@@ -69,8 +70,6 @@ public class LegacyArtifactDiscoverer
 
                 String lastAvceToken = (String) avceTokenList.removeLast();
 
-                boolean valid = true;
-
                 // TODO: share with other discoverer, use artifact handlers instead
                 if ( lastAvceToken.endsWith( ".tar.gz" ) )
                 {
@@ -111,157 +110,168 @@ public class LegacyArtifactDiscoverer
                         }
                         else
                         {
-                            //type does not match extension
-                            valid = false;
+                            throw new DiscovererException( "Path type does not match the extension" );
                         }
                     }
                     else
                     {
-                        // no extension
-                        valid = false;
+                        throw new DiscovererException( "Path filename does not have an extension" );
                     }
                 }
 
-                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])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([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();
+                // 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 );
 
-                        boolean tokenIsVersionPart = token.matches( validVersionParts );
+                // 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])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)";
 
-                        StringBuffer bufferToUpdate;
+                StringBuffer classifierBuffer = new StringBuffer();
+                StringBuffer versionBuffer = new StringBuffer();
 
-                        // 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;
+                boolean firstVersionTokenEncountered = false;
+                boolean firstToken = true;
 
-                            bufferToUpdate = versionBuffer;
-                        }
+                int tokensIterated = 0;
+                for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
+                {
+                    String token = (String) it.next();
+
+                    boolean tokenIsVersionPart = token.matches( validVersionParts );
 
-                        if ( firstToken )
+                    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 )
                         {
-                            firstToken = false;
+                            //noinspection BreakStatement
+                            break;
                         }
                         else
                         {
-                            bufferToUpdate.insert( 0, '-' );
+                            bufferToUpdate = classifierBuffer;
                         }
+                    }
+                    else
+                    {
+                        firstVersionTokenEncountered = true;
 
-                        bufferToUpdate.insert( 0, token );
+                        bufferToUpdate = versionBuffer;
+                    }
 
-                        tokensIterated++;
+                    if ( firstToken )
+                    {
+                        firstToken = false;
+                    }
+                    else
+                    {
+                        bufferToUpdate.insert( 0, '-' );
                     }
 
-                    // Now, restore the proper ordering so we can build the artifactId.
-                    Collections.reverse( avceTokenList );
+                    bufferToUpdate.insert( 0, token );
+
+                    tokensIterated++;
+                }
+
+                // Now, restore the proper ordering so we can build the artifactId.
+                Collections.reverse( 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 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 )
                     {
-                        if ( avceTokenList.size() > 1 )
-                        {
-                            int lastIdx = avceTokenList.size() - 1;
+                        int lastIdx = avceTokenList.size() - 1;
 
-                            versionBuffer.append( avceTokenList.get( lastIdx ) );
-                            avceTokenList.remove( lastIdx );
-                        }
+                        versionBuffer.append( avceTokenList.get( lastIdx ) );
+                        avceTokenList.remove( lastIdx );
+                    }
 
-                        classifierBuffer.setLength( 0 );
+                    classifierBuffer.setLength( 0 );
+                }
+                else
+                {
+                    // 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 ) );
+                }
+
+                StringBuffer artifactIdBuffer = new StringBuffer();
+
+                firstToken = true;
+                for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
+                {
+                    String token = (String) it.next();
+
+                    if ( firstToken )
+                    {
+                        firstToken = false;
                     }
                     else
                     {
-                        // 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 ) );
+                        artifactIdBuffer.append( '-' );
                     }
 
-                    StringBuffer artifactIdBuffer = new StringBuffer();
-
-                    firstToken = true;
-                    for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
-                    {
-                        String token = (String) it.next();
+                    artifactIdBuffer.append( token );
+                }
 
-                        if ( firstToken )
-                        {
-                            firstToken = false;
-                        }
-                        else
-                        {
-                            artifactIdBuffer.append( '-' );
-                        }
+                String artifactId = artifactIdBuffer.toString();
 
-                        artifactIdBuffer.append( token );
+                if ( artifactId.length() > 0 )
+                {
+                    int lastVersionCharIdx = versionBuffer.length() - 1;
+                    if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
+                    {
+                        versionBuffer.setLength( lastVersionCharIdx );
                     }
 
-                    String artifactId = artifactIdBuffer.toString();
+                    String version = versionBuffer.toString();
 
-                    if ( artifactId.length() > 0 )
+                    if ( version.length() > 0 )
                     {
-                        int lastVersionCharIdx = versionBuffer.length() - 1;
-                        if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
+                        if ( classifierBuffer.length() > 0 )
                         {
-                            versionBuffer.setLength( lastVersionCharIdx );
+                            result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
+                                                                                   type,
+                                                                                   classifierBuffer.toString() );
                         }
-
-                        String version = versionBuffer.toString();
-
-                        if ( version.length() >= 1 )
+                        else
                         {
-                            if ( classifierBuffer.length() > 0 )
-                            {
-                                result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
-                                                                                       type,
-                                                                                       classifierBuffer.toString() );
-                            }
-                            else
-                            {
-                                result = artifactFactory.createArtifact( groupId, artifactId, version,
-                                                                         Artifact.SCOPE_RUNTIME, type );
-                            }
+                            result = artifactFactory.createArtifact( groupId, artifactId, version,
+                                                                     Artifact.SCOPE_RUNTIME, type );
                         }
                     }
+                    else
+                    {
+                        throw new DiscovererException( "Path filename version is empty" );
+                    }
+                }
+                else
+                {
+                    throw new DiscovererException( "Path filename artifactId is empty" );
                 }
             }
+            else
+            {
+                throw new DiscovererException( "Path artifact type does not corresspond to an artifact type" );
+            }
+        }
+        else
+        {
+            throw new DiscovererException( "Path does not match a legacy repository path for an artifact" );
         }
 
         return result;
index 0eea23b8aa7fb0f54f511b746ead32f6b02abc77..01cedac669e7d999a4347c61bacb707903dc3c6f 100644 (file)
@@ -17,13 +17,13 @@ package org.apache.maven.repository.discovery;
  */
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.List;
 
 /**
  * Interface for discovering metadata files.
  */
 public interface MetadataDiscoverer
+    extends Discoverer
 {
     String ROLE = MetadataDiscoverer.class.getName();
 
@@ -34,18 +34,4 @@ public interface MetadataDiscoverer
      * @param blacklistedPatterns Patterns that are to be excluded from the discovery process.
      */
     List discoverMetadata( File repositoryBase, String blacklistedPatterns );
-
-    /**
-     * Get the list of paths kicked out during the discovery process.
-     *
-     * @return the paths as Strings.
-     */
-    Iterator getKickedOutPathsIterator();
-
-    /**
-     * Get the list of paths excluded during the discovery process.
-     *
-     * @return the paths as Strings.
-     */
-    Iterator getExcludedPathsIterator();
 }
index ea37a7b239871df09c1361816237df129e3c620c..8d62a87909768bbc40e4ddffd87ae63644c5898a 100644 (file)
@@ -565,7 +565,14 @@ public class DefaultArtifactDiscovererTest
 
     private Artifact getArtifactFromPath( String path )
     {
-        return discoverer.buildArtifact( path );
+        try
+        {
+            return discoverer.buildArtifact( path );
+        }
+        catch ( DiscovererException e )
+        {
+            return null;
+        }
     }
 
     private Artifact createArtifact( String groupId, String artifactId, String version )
index 7eb5d1da47b21a27dad55b52b1d3958129ae38a7..1e35aaefab67e18a62dffbf90a00f255b0d4b0d9 100644 (file)
@@ -406,7 +406,14 @@ public class LegacyArtifactDiscovererTest
 
     private Artifact getArtifactFromPath( String path )
     {
-        return discoverer.buildArtifact( path );
+        try
+        {
+            return discoverer.buildArtifact( path );
+        }
+        catch ( DiscovererException e )
+        {
+            return null;
+        }
     }
 
     private Artifact createArtifact( String groupId, String artifactId, String version )
index 5afe0d9b74cff159103b5f6ba183b61f7a3743a4..06e1726696e5fb8b01ec675c7ef772d0faa5b6ae 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.repository.discovery.ArtifactDiscoverer;
+import org.apache.maven.repository.discovery.DiscovererException;
 import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
 import org.apache.maven.repository.proxy.repository.ProxyRepository;
 import org.apache.maven.wagon.ConnectionException;
@@ -150,11 +151,26 @@ public class DefaultProxyManager
         }
         else
         {
-            Artifact artifact = defaultArtifactDiscoverer.buildArtifact( path );
+            Artifact artifact = null;
+            try
+            {
+                artifact = defaultArtifactDiscoverer.buildArtifact( path );
+            }
+            catch ( DiscovererException e )
+            {
+                getLogger().debug( "Failed to build artifact using default layout with message: " + e.getMessage() );
+            }
 
             if ( artifact == null )
             {
-                artifact = legacyArtifactDiscoverer.buildArtifact( path );
+                try
+                {
+                    artifact = legacyArtifactDiscoverer.buildArtifact( path );
+                }
+                catch ( DiscovererException e )
+                {
+                    getLogger().debug( "Failed to build artifact using legacy layout with message: " + e.getMessage() );
+                }
             }
 
             if ( artifact != null )