Author: nicolas
Date: Mon Dec 10 06:58:14 2007
New Revision: 602922

URL: http://svn.apache.org/viewvc?rev=602922&view=rev
Log:
MRM-594 convert PathParsers to a plexus component, so that it can access the 
archivaConfiguration and read custom legacyPath 2 artifact references.

Added:
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java
Modified:
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java
    
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java
 Mon Dec 10 06:58:14 2007
@@ -28,7 +28,7 @@
 import org.apache.maven.archiva.repository.layout.LayoutException;
 
 /**
- * AbstractDefaultRepositoryContent - common methods for working with default 
(maven 2) layout. 
+ * AbstractDefaultRepositoryContent - common methods for working with default 
(maven 2) layout.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
@@ -43,27 +43,32 @@
 
     protected static final char ARTIFACT_SEPARATOR = '-';
 
+    /**
+     * @plexus.requirement role-hint="default"
+     */
+    private PathParser defaultPathParser;
+
     public ArtifactReference toArtifactReference( String path )
         throws LayoutException
     {
-        return DefaultPathParser.toArtifactReference( path );
+        return defaultPathParser.toArtifactReference( path );
     }
 
     public String toMetadataPath( ProjectReference reference )
     {
         StringBuffer path = new StringBuffer();
-    
+
         path.append( formatAsDirectory( reference.getGroupId() ) ).append( 
PATH_SEPARATOR );
         path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
         path.append( MAVEN_METADATA );
-    
+
         return path.toString();
     }
 
     public String toMetadataPath( VersionedReference reference )
     {
         StringBuffer path = new StringBuffer();
-    
+
         path.append( formatAsDirectory( reference.getGroupId() ) ).append( 
PATH_SEPARATOR );
         path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
         if ( reference.getVersion() != null )
@@ -72,10 +77,10 @@
             path.append( VersionUtil.getBaseVersion( reference.getVersion() ) 
).append( PATH_SEPARATOR );
         }
         path.append( MAVEN_METADATA );
-    
+
         return path.toString();
     }
-    
+
     public String toPath( ArchivaArtifact reference )
     {
         if ( reference == null )

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java
 Mon Dec 10 06:58:14 2007
@@ -28,7 +28,7 @@
 import java.util.Map;
 
 /**
- * AbstractLegacyRepositoryContent 
+ * AbstractLegacyRepositoryContent
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
@@ -49,10 +49,15 @@
         typeToDirectoryMap.put( "javadoc", "javadoc.jar" );
     }
 
+    /**
+     * @plexus.requirement role-hint="legacy"
+     */
+    private PathParser legacyPathParser;
+
     public ArtifactReference toArtifactReference( String path )
         throws LayoutException
     {
-        return LegacyPathParser.toArtifactReference( path );
+        return legacyPathParser.toArtifactReference( path );
     }
 
     public String toPath( ArchivaArtifact reference )

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
 Mon Dec 10 06:58:14 2007
@@ -37,7 +37,7 @@
     public static final String MAVEN_ARCHETYPE = "maven-archetype";
 
     public static final String MAVEN_PLUGIN = "maven-plugin";
-    
+
     private static final Map<String, String> typeToExtensionMap;
 
     private static final Pattern mavenPluginPattern = Pattern.compile( 
"^(maven-.*-plugin)|(.*-maven-plugin)$" );
@@ -115,10 +115,10 @@
             return normalizedName.substring( idx + 1 );
         }
     }
-    
+
     /**
      * Determine if a given artifact Id conforms to the naming scheme for a 
maven plugin.
-     * 
+     *
      * @param artifactId the artifactId to test.
      * @return true if this artifactId conforms to the naming scheme for a 
maven plugin.
      */

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
 Mon Dec 10 06:58:14 2007
@@ -25,25 +25,22 @@
 import org.apache.maven.archiva.repository.layout.LayoutException;
 
 /**
- * DefaultPathParser is a parser for maven 2 (default layout) paths to 
ArtifactReference. 
+ * DefaultPathParser is a parser for maven 2 (default layout) paths to 
ArtifactReference.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
- * 
- * @plexus.component 
role="org.apache.maven.archiva.repository.content.DefaultPathParser"
+ *
+ * @plexus.component 
role="org.apache.maven.archiva.repository.content.PathParser" 
role-hint="default"
  */
-public class DefaultPathParser
+public class DefaultPathParser implements PathParser
 {
     private static final String INVALID_ARTIFACT_PATH = "Invalid path to 
Artifact: ";
 
     /**
-     * Convert a path to an ArtifactReference. 
-     * 
-     * @param path
-     * @return
-     * @throws LayoutException
+     * [EMAIL PROTECTED]
+     * @see 
org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String)
      */
-    protected static ArtifactReference toArtifactReference( String path )
+    public ArtifactReference toArtifactReference( String path )
         throws LayoutException
     {
         if ( StringUtils.isBlank( path ) )
@@ -148,7 +145,7 @@
                 case '-':
                     // Definately a classifier.
                     artifact.setClassifier( parser.remaining() );
-                    
+
                     // Set the type.
                     artifact.setType( 
ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
                     break;
@@ -162,9 +159,9 @@
                     artifact.setType( 
ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
                     break;
             }
-            
+
             // Special case for maven plugins
-            if ( StringUtils.equals( "jar", artifact.getType() ) && 
+            if ( StringUtils.equals( "jar", artifact.getType() ) &&
                  ArtifactExtensionMapping.isMavenPlugin( 
artifact.getArtifactId() ) )
             {
                 artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN );
@@ -201,5 +198,5 @@
 
         return artifact;
     }
-    
+
 }

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java
 Mon Dec 10 06:58:14 2007
@@ -19,23 +19,54 @@
  * under the License.
  */
 
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
 import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.LegacyArtifactPath;
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.repository.layout.LayoutException;
 
 /**
- * LegacyPathParser is a parser for maven 1 (legacy layout) paths to 
ArtifactReference. 
+ * LegacyPathParser is a parser for maven 1 (legacy layout) paths to
+ * ArtifactReference.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
+ * @plexus.component 
role="org.apache.maven.archiva.repository.content.PathParser"
+ * role-hint="legacy"
  */
 public class LegacyPathParser
+    implements PathParser
 {
     private static final String INVALID_ARTIFACT_PATH = "Invalid path to 
Artifact: ";
 
-    protected static ArtifactReference toArtifactReference( String path )
+    /**
+     * @plexus.requirement
+     */
+    protected ArchivaConfiguration configuration;
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see 
org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String)
+     */
+    public ArtifactReference toArtifactReference( String path )
         throws LayoutException
     {
+        // First, look if a custom resolution rule has been set for this 
artifact
+        Collection legacy = 
configuration.getConfiguration().getLegacyArtifactPaths();
+        for ( Iterator iterator = legacy.iterator(); iterator.hasNext(); )
+        {
+            LegacyArtifactPath legacyPath = (LegacyArtifactPath) 
iterator.next();
+            if ( legacyPath.match( path ) )
+            {
+                return legacyPath.getArtifactReference();
+            }
+        }
+
         ArtifactReference artifact = new ArtifactReference();
 
         String normalizedPath = StringUtils.replace( path, "\\", "/" );
@@ -54,8 +85,8 @@
         {
             // Illegal Path Parts Length.
             throw new LayoutException( INVALID_ARTIFACT_PATH
-                + "legacy paths should only have 3 parts 
[groupId]/[type]s/[artifactId]-[version].[type], found "
-                + pathParts.length + " instead." );
+                    + "legacy paths should only have 3 parts 
[groupId]/[type]s/[artifactId]-[version].[type], found "
+                    + pathParts.length + " instead." );
         }
 
         // The Group ID.
@@ -68,7 +99,7 @@
         if ( !expectedType.endsWith( "s" ) )
         {
             throw new LayoutException( INVALID_ARTIFACT_PATH
-                + "legacy paths should have an expected type ending in [s] in 
the second part of the path." );
+                    + "legacy paths should have an expected type ending in [s] 
in the second part of the path." );
         }
 
         // The Filename.
@@ -88,7 +119,7 @@
                 parser.reset();
                 // Take the first section regardless of content.
                 String artifactId = parser.next();
-                
+
                 // Is there anything more that is considered not a version id?
                 String moreArtifactId = parser.nextNonVersion();
                 if ( StringUtils.isNotBlank( moreArtifactId ) )
@@ -129,7 +160,7 @@
 
         // Set Type
         artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( 
filename ) );
-        
+
         // Sanity Check: does it have an extension?
         if ( StringUtils.isEmpty( artifact.getType() ) )
         {
@@ -145,10 +176,10 @@
         {
             // Sanity Check: does extension match pathType on path?
             String trimPathType = expectedType.substring( 0, 
expectedType.length() - 1 );
-    
+
             String expectedExtension = ArtifactExtensionMapping.getExtension( 
trimPathType );
             String actualExtension = parser.getExtension();
-    
+
             if ( !expectedExtension.equals( actualExtension ) )
             {
                 throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch 
on extension [" + actualExtension

Added: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java?rev=602922&view=auto
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java
 (added)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java
 Mon Dec 10 06:58:14 2007
@@ -0,0 +1,19 @@
+/**
+ *
+ */
+package org.apache.maven.archiva.repository.content;
+
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * @author ndeloof
+ *
+ */
+public interface PathParser
+{
+
+    public ArtifactReference toArtifactReference( String path )
+        throws LayoutException;
+
+}

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
 Mon Dec 10 06:58:14 2007
@@ -38,12 +38,12 @@
 
 /**
  * RepositoryRequest is used to determine the type of request that is 
incoming, and convert it to an appropriate
- * ArtifactReference.  
+ * ArtifactReference.
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
- * 
- * @plexus.component 
+ *
+ * @plexus.component
  *      role="org.apache.maven.archiva.repository.content.RepositoryRequest"
  */
 public class RepositoryRequest
@@ -59,11 +59,21 @@
      */
     private ArchivaConfiguration archivaConfiguration;
 
+    /**
+     * @plexus.requirement role-hint="default"
+     */
+    private PathParser defaultPathParser;
+
+    /**
+     * @plexus.requirement role-hint="legacy"
+     */
+    private PathParser legacyPathParser;
+
     private List<String> artifactPatterns;
 
     /**
      * Test path to see if it is an artifact being requested (or not).
-     * 
+     *
      * @param requestedPath the path to test.
      * @return true if it is an artifact being requested.
      */
@@ -91,10 +101,10 @@
     /**
      * Takes an incoming requested path (in "/" format) and gleans the layout
      * and ArtifactReference appropriate for that content.
-     * 
+     *
      * @param requestedPath the relative path to the content.
      * @return the ArtifactReference for the requestedPath.
-     * @throws LayoutException if the request path is not layout valid. 
+     * @throws LayoutException if the request path is not layout valid.
      */
     public ArtifactReference toArtifactReference( String requestedPath )
         throws LayoutException
@@ -103,7 +113,7 @@
         {
             throw new LayoutException( "Blank request path is not a valid." );
         }
-        
+
         String path = requestedPath;
         while ( path.startsWith( "/" ) )
         {
@@ -118,18 +128,18 @@
 
         if ( isDefault( path ) )
         {
-            return DefaultPathParser.toArtifactReference( path );
+            return defaultPathParser.toArtifactReference( path );
         }
         else if ( isLegacy( path ) )
         {
-            return LegacyPathParser.toArtifactReference( path );
+            return legacyPathParser.toArtifactReference( path );
         }
         else
         {
             throw new LayoutException( "Not a valid request path layout, too 
short." );
         }
     }
-    
+
     /**
      * <p>
      * Tests the path to see if it conforms to the expectations of a metadata 
request.
@@ -138,8 +148,8 @@
      * NOTE: This does a cursory check on the path's last element.  A result 
of true
      * from this method is not a guarantee that the metadata is in a valid 
format, or
      * that it even contains data.
-     * </p> 
-     * 
+     * </p>
+     *
      * @param requestedPath the path to test.
      * @return true if the requestedPath is likely a metadata request.
      */
@@ -147,7 +157,7 @@
     {
         return requestedPath.endsWith( "/" + MetadataTools.MAVEN_METADATA );
     }
-    
+
     /**
      * <p>
      * Tests the path to see if it conforms to the expectations of a support 
file request.
@@ -159,8 +169,8 @@
      * NOTE: This does a cursory check on the path's extension only.  A result 
of true
      * from this method is not a guarantee that the support resource is in a 
valid format, or
      * that it even contains data.
-     * </p> 
-     * 
+     * </p>
+     *
      * @param requestedPath the path to test.
      * @return true if the requestedPath is likely that of a support file 
request.
      */
@@ -175,7 +185,7 @@
         String ext = requestedPath.substring( idx );
         return ( ".sha1".equals( ext ) || ".md5".equals( ext ) || 
".asc".equals( ext ) || ".pgp".equals( ext ) );
     }
-    
+
     /**
      * <p>
      * Tests the path to see if it conforms to the expectations of a default 
layout request.
@@ -183,10 +193,10 @@
      * <p>
      * NOTE: This does a cursory check on the count of path elements only.  A 
result of
      * true from this method is not a guarantee that the path sections are 
valid and
-     * can be resolved to an artifact reference.  use [EMAIL PROTECTED] 
#toArtifactReference(String)} 
+     * can be resolved to an artifact reference.  use [EMAIL PROTECTED] 
#toArtifactReference(String)}
      * if you want a more complete analysis of the validity of the path.
      * </p>
-     * 
+     *
      * @param requestedPath the path to test.
      * @return true if the requestedPath is likely that of a default layout 
request.
      */
@@ -196,11 +206,11 @@
         {
             return false;
         }
-        
+
         String pathParts[] = StringUtils.splitPreserveAllTokens( 
requestedPath, '/' );
         return pathParts.length > 3;
     }
-    
+
     /**
      * <p>
      * Tests the path to see if it conforms to the expectations of a legacy 
layout request.
@@ -208,10 +218,10 @@
      * <p>
      * NOTE: This does a cursory check on the count of path elements only.  A 
result of
      * true from this method is not a guarantee that the path sections are 
valid and
-     * can be resolved to an artifact reference.  use [EMAIL PROTECTED] 
#toArtifactReference(String)} 
+     * can be resolved to an artifact reference.  use [EMAIL PROTECTED] 
#toArtifactReference(String)}
      * if you want a more complete analysis of the validity of the path.
      * </p>
-     * 
+     *
      * @param requestedPath the path to test.
      * @return true if the requestedPath is likely that of a legacy layout 
request.
      */
@@ -221,18 +231,18 @@
         {
             return false;
         }
-        
+
         String pathParts[] = StringUtils.splitPreserveAllTokens( 
requestedPath, '/' );
         return pathParts.length == 3;
     }
-    
+
     /**
      * Adjust the requestedPath to conform to the native layout of the 
provided [EMAIL PROTECTED] ManagedRepositoryContent}.
-     * 
+     *
      * @param requestedPath the incoming requested path.
      * @param repository the repository to adjust to.
      * @return the adjusted (to native) path.
-     * @throws LayoutException if the path cannot be parsed. 
+     * @throws LayoutException if the path cannot be parsed.
      */
     public String toNativePath( String requestedPath, ManagedRepositoryContent 
repository ) throws LayoutException
     {
@@ -240,11 +250,11 @@
         {
             throw new LayoutException( "Request Path is blank." );
         }
-        
+
         String referencedResource = requestedPath;
         // No checksum by default.
         String supportfile = "";
-        
+
         // Figure out support file, and actual referencedResource.
         if( isSupportFile( requestedPath ) )
         {
@@ -259,7 +269,7 @@
             {
                 throw new LayoutException( "Cannot translate metadata request 
to legacy layout." );
             }
-            
+
             /* Nothing to translate.
              * Default layout is the only layout that can contain 
maven-metadata.xml files, and
              * if the managedRepository is layout legacy, this request would 
never occur.

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java
 Mon Dec 10 06:58:14 2007
@@ -24,7 +24,7 @@
 import org.apache.maven.archiva.repository.layout.LayoutException;
 
 /**
- * AbstractLegacyRepositoryContentTestCase 
+ * AbstractLegacyRepositoryContentTestCase
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
@@ -58,10 +58,10 @@
         assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong 
package extension" );
     }
 
-    /** 
+    /**
      * [MRM-432] Oddball version spec.
      * Example of an oddball / unusual version spec.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
     public void testGoodButOddVersionSpecGanymedSsh2()
         throws LayoutException

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java
 Mon Dec 10 06:58:14 2007
@@ -6,7 +6,7 @@
 import org.apache.maven.archiva.repository.layout.LayoutException;
 
 /**
- * DefaultPathParserTest 
+ * DefaultPathParserTest
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Joakim Erdfelt</a>
  * @version $Id$
@@ -14,6 +14,8 @@
 public class DefaultPathParserTest
     extends AbstractRepositoryLayerTestCase
 {
+    private PathParser parser = new DefaultPathParser();
+
     public void testBadPathMissingType()
     {
         assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
@@ -51,8 +53,8 @@
                        "wrong artifact id" );
     }
 
-    /** 
-     * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 
Error 
+    /**
+     * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 
Error
      */
     public void testGoodButDualExtensions()
         throws LayoutException
@@ -66,11 +68,11 @@
 
         assertLayout( path, groupId, artifactId, version, classifier, type );
     }
-    
-    /** 
+
+    /**
      * [MRM-432] Oddball version spec.
      * Example of an oddball / unusual version spec.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
     public void testGoodButOddVersionSpecGanymedSsh2()
         throws LayoutException
@@ -85,10 +87,10 @@
         assertLayout( path, groupId, artifactId, version, classifier, type );
     }
 
-    /** 
+    /**
      * [MRM-432] Oddball version spec.
      * Example of an oddball / unusual version spec.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
     public void testGoodButOddVersionSpecJavaxComm()
         throws LayoutException
@@ -105,11 +107,11 @@
 
     /**
      * Test the ejb-client type spec.
-     * Type specs are not a 1 to 1 map to the extension. 
+     * Type specs are not a 1 to 1 map to the extension.
      * This tests that effect.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
-    /* TODO: Re-enabled in the future. 
+    /* TODO: Re-enabled in the future.
     public void testGoodFooEjbClient()
         throws LayoutException
     {
@@ -124,10 +126,10 @@
     }
     */
 
-    /** 
+    /**
      * [MRM-432] Oddball version spec.
      * Example of an oddball / unusual version spec.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
     public void testGoodButOddVersionSpecJavaxPersistence()
         throws LayoutException
@@ -139,11 +141,11 @@
         String type = "jar";
         String path = 
"javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar";
 
-        /* 
+        /*
          * The version id of "public_review" can cause problems. is it part of
          * the version spec? or the classifier?
          * Since the path spec below shows it in the path, then it is really
-         * part of the version spec. 
+         * part of the version spec.
          */
 
         assertLayout( path, groupId, artifactId, version, classifier, type );
@@ -225,7 +227,7 @@
 
     /**
      * Test the classifier, and java-source type spec.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
     public void testGoodFooLibSources()
         throws LayoutException
@@ -242,7 +244,7 @@
 
     /**
      * A timestamped versioned artifact, should reside in a SNAPSHOT 
baseversion directory.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
     public void testGoodSnapshotMavenTest()
         throws LayoutException
@@ -311,7 +313,7 @@
     {
         try
         {
-            DefaultPathParser.toArtifactReference( "" );
+            parser.toArtifactReference( "" );
             fail( "Should have failed due to empty path." );
         }
         catch ( LayoutException e )
@@ -324,7 +326,7 @@
     {
         try
         {
-            DefaultPathParser.toArtifactReference( null );
+            parser.toArtifactReference( null );
             fail( "Should have failed due to null path." );
         }
         catch ( LayoutException e )
@@ -337,7 +339,7 @@
     {
         try
         {
-            DefaultPathParser.toArtifactReference( "" );
+            parser.toArtifactReference( "" );
             fail( "Should have failed due to empty path." );
         }
         catch ( LayoutException e )
@@ -350,7 +352,7 @@
     {
         try
         {
-            DefaultPathParser.toArtifactReference( null );
+            parser.toArtifactReference( null );
             fail( "Should have failed due to null path." );
         }
         catch ( LayoutException e )
@@ -360,14 +362,14 @@
     }
 
     /**
-     * Perform a path to artifact reference lookup, and verify the results. 
+     * Perform a path to artifact reference lookup, and verify the results.
      */
     private void assertLayout( String path, String groupId, String artifactId, 
String version, String classifier,
                                String type )
         throws LayoutException
     {
         // Path to Artifact Reference.
-        ArtifactReference testReference = 
DefaultPathParser.toArtifactReference( path );
+        ArtifactReference testReference = parser.toArtifactReference( path );
         assertArtifactReference( testReference, groupId, artifactId, version, 
classifier, type );
     }
 
@@ -393,7 +395,7 @@
     {
         try
         {
-            DefaultPathParser.toArtifactReference( path );
+            parser.toArtifactReference( path );
             fail( "Should have thrown a LayoutException on the invalid path [" 
+ path + "] because of [" + reason + "]" );
         }
         catch ( LayoutException e )

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java
 Mon Dec 10 06:58:14 2007
@@ -20,6 +20,9 @@
  */
 
 
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.DefaultArchivaConfiguration;
+import org.apache.maven.archiva.configuration.LegacyArtifactPath;
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
 import org.apache.maven.archiva.repository.layout.LayoutException;
@@ -33,6 +36,26 @@
 public class LegacyPathParserTest
     extends AbstractRepositoryLayerTestCase
 {
+    private LegacyPathParser parser = new LegacyPathParser();
+
+    /**
+     * Configure the ArchivaConfiguration
+     * [EMAIL PROTECTED]
+     * @see org.codehaus.plexus.PlexusTestCase#setUp()
+     */
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        ArchivaConfiguration config = (ArchivaConfiguration) lookup( 
ArchivaConfiguration.class );
+        LegacyArtifactPath jaxen = new LegacyArtifactPath();
+        jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" );
+        jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" );
+        config.getConfiguration().addLegacyArtifactPath( jaxen );
+        parser.configuration = config;
+    }
+
+
     public void testBadPathArtifactIdMissingA()
     {
         assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
@@ -339,21 +362,36 @@
     }
 
     /**
+     * [MRM-594] add some hook in LegacyPathParser to allow exceptions in 
artifact resolution
+     */
+    public void testCustomExceptionsInArtifactResolution()
+        throws LayoutException
+    {
+        String groupId = "jaxen";
+        String artifactId = "jaxen";
+        String version = "1.0-FCS";
+        String type = "jar";
+        String classifier = "full";
+        String path = "jaxen/jars/jaxen-1.0-FCS-full.jar";
+
+        assertLayout( path, groupId, artifactId, version, classifier, type );
+    }
+
+    /**
      * Perform a path to artifact reference lookup, and verify the results.
-     * @param classifier TODO
      */
     private void assertLayout( String path, String groupId, String artifactId, 
String version, String classifier, String type )
         throws LayoutException
     {
         // Path to Artifact Reference.
-        ArtifactReference testReference = 
LegacyPathParser.toArtifactReference( path );
+        ArtifactReference testReference = parser.toArtifactReference( path );
         assertArtifactReference( testReference, groupId, artifactId, version, 
classifier, type );
     }
 
     private void assertArtifactReference( ArtifactReference actualReference, 
String groupId, String artifactId,
                                           String version, String classifier, 
String type )
     {
-        String expectedId = "ArtifactReference - " + groupId + ":" + 
artifactId + ":" + version + ":" + type;
+        String expectedId = "ArtifactReference - " + groupId + ":" + 
artifactId + ":" + version + ":" + classifier + ":" + type;
 
         assertNotNull( expectedId + " - Should not be null.", actualReference 
);
 
@@ -368,7 +406,7 @@
     {
         try
         {
-            LegacyPathParser.toArtifactReference( path );
+            parser.toArtifactReference( path );
             fail( "Should have thrown a LayoutException on the invalid path [" 
+ path + "] because of [" + reason + "]" );
         }
         catch ( LayoutException e )

Modified: 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java?rev=602922&r1=602921&r2=602922&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
 (original)
+++ 
maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
 Mon Dec 10 06:58:14 2007
@@ -130,7 +130,7 @@
         // Starting slash should not prevent detection.
         assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", 
"org.apache.derby", "derby", "10.2.2.0", null, "pom" );
     }
-    
+
     public void testValidDefaultDerbyPom()
         throws Exception
     {
@@ -214,7 +214,7 @@
         assertTrue( repoRequest.isArtifact( 
"test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
         assertTrue( repoRequest.isArtifact( 
"test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
         assertTrue( repoRequest.isArtifact( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
-        
+
         assertFalse( repoRequest.isArtifact( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
         assertFalse( repoRequest.isArtifact( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
         assertFalse( repoRequest.isArtifact( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
@@ -222,7 +222,7 @@
         assertFalse( repoRequest.isArtifact( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
         assertFalse( repoRequest.isArtifact( 
"org/apache/derby/derby/maven-metadata.xml" ) );
     }
-    
+
     public void testIsSupportFile()
     {
         assertTrue( repoRequest.isSupportFile( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
@@ -231,7 +231,7 @@
         assertTrue( repoRequest.isSupportFile( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
         assertTrue( repoRequest.isSupportFile( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
         assertTrue( repoRequest.isSupportFile( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
-        
+
         assertFalse( repoRequest.isSupportFile( 
"test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
         assertFalse( repoRequest.isSupportFile( 
"test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
         assertFalse( repoRequest.isSupportFile( 
"org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
@@ -239,12 +239,12 @@
         assertFalse( repoRequest.isSupportFile( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
         assertFalse( repoRequest.isSupportFile( 
"org/apache/derby/derby/maven-metadata.xml" ) );
     }
-    
+
     public void testIsMetadata()
     {
         assertTrue( repoRequest.isMetadata( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
         assertTrue( repoRequest.isMetadata( 
"org/apache/derby/derby/maven-metadata.xml" ));
-        
+
         assertFalse( repoRequest.isMetadata( 
"test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
         assertFalse( repoRequest.isMetadata( 
"test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
         assertFalse( repoRequest.isMetadata( 
"org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
@@ -252,49 +252,49 @@
         assertFalse( repoRequest.isMetadata( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
         assertFalse( repoRequest.isMetadata( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
     }
-    
+
     public void testIsDefault()
     {
         assertFalse( repoRequest.isDefault( 
"test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
         assertFalse( repoRequest.isDefault( 
"directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
         assertFalse( repoRequest.isDefault( 
"commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
-        
+
         assertTrue( repoRequest.isDefault( 
"test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
         assertTrue( repoRequest.isDefault( 
"org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
         assertTrue( repoRequest.isDefault( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
         assertTrue( repoRequest.isDefault( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
         assertTrue( repoRequest.isDefault( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-        
+
         assertFalse( repoRequest.isDefault( null ) );
         assertFalse( repoRequest.isDefault( "" ) );
         assertFalse( repoRequest.isDefault( "foo" ) );
         assertFalse( repoRequest.isDefault( "some.short/path" ) );
     }
-    
+
     public void testIsLegacy()
     {
         assertTrue( repoRequest.isLegacy( 
"test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
         assertTrue( repoRequest.isLegacy( 
"directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
         assertTrue( repoRequest.isLegacy( 
"commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
-        
+
         assertFalse( repoRequest.isLegacy( 
"test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
         assertFalse( repoRequest.isLegacy( 
"org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
         assertFalse( repoRequest.isLegacy( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
         assertFalse( repoRequest.isLegacy( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
         assertFalse( repoRequest.isLegacy( 
"org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
-        
+
         assertFalse( repoRequest.isLegacy( null ) );
         assertFalse( repoRequest.isLegacy( "" ) );
         assertFalse( repoRequest.isLegacy( "some.short/path" ) );
     }
-    
+
     private ManagedRepositoryContent createManagedRepo( String layout )
         throws Exception
     {
         File repoRoot = getTestFile( "target/test-repo" );
         return createManagedRepositoryContent( "test-internal", "Internal Test 
Repo", repoRoot, layout );
     }
-    
+
     /**
      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 
Error
      */
@@ -307,7 +307,7 @@
         assertEquals( 
"org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", 
repoRequest
             .toNativePath( 
"org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", 
repository ) );
     }
-    
+
     /**
      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 
Error
      */
@@ -321,7 +321,7 @@
         assertEquals( 
"org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", 
repoRequest
             .toNativePath( 
"org.project/zips/example-presentation-3.2.xml.zip", repository ) );
     }
-    
+
     public void testToNativePathMetadataDefaultToDefault()
         throws Exception
     {
@@ -337,7 +337,7 @@
     {
         ManagedRepositoryContent repository = createManagedRepo( "default" );
 
-        // Test (pom) legacy to default 
+        // Test (pom) legacy to default
         assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", 
repoRequest
             .toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", 
repository ) );
     }
@@ -368,7 +368,7 @@
             // expected path.
         }
     }
-    
+
     public void testNativePathBadRequestBlank()
         throws Exception
     {
@@ -385,7 +385,7 @@
             // expected path.
         }
     }
-    
+
     public void testNativePathBadRequestNull()
         throws Exception
     {
@@ -402,7 +402,7 @@
             // expected path.
         }
     }
-    
+
     public void testNativePathBadRequestUnknownType()
         throws Exception
     {
@@ -419,14 +419,14 @@
             // expected path.
         }
     }
-    
+
     public void testToNativePathLegacyMetadataDefaultToLegacy()
         throws Exception
     {
         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
 
         // Test (metadata) default to legacy
-        
+
         // Special Case: This direction is not supported, should throw a 
LayoutException.
         try
         {
@@ -438,7 +438,7 @@
             // expected path.
         }
     }
-    
+
     public void testNativePathPomDefaultToLegacy()
         throws Exception
     {
@@ -448,13 +448,13 @@
         assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", repoRequest
             .toNativePath( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) );
     }
-    
+
     public void testNativePathSupportFileDefaultToLegacy()
         throws Exception
     {
         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
 
-        // Test (supportfile) default to legacy 
+        // Test (supportfile) default to legacy
         assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", 
repoRequest
             .toNativePath( 
"org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repository ) );
     }


Reply via email to