You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/04/19 22:54:28 UTC

svn commit: r530543 - in /maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src: main/java/org/apache/maven/archiva/repository/content/ main/java/org/apache/maven/archiva/repository/layout/ test/java/org/apache...

Author: joakime
Date: Thu Apr 19 13:54:27 2007
New Revision: 530543

URL: http://svn.apache.org/viewvc?view=rev&rev=530543
Log:
Beefing up BidirectionalRepositoryLayout for use in webapp and proxy.


Removed:
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
Modified:
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java
    maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractArtifactExtensionMapping.java Thu Apr 19 13:54:27 2007
@@ -29,7 +29,6 @@
  * @version $Id$
  */
 public abstract class AbstractArtifactExtensionMapping
-    implements ArtifactExtensionMapping
 {
     protected final Map typeToExtensionMap;
 
@@ -41,6 +40,8 @@
         typeToExtensionMap.put( "distribution-tgz", "tar.gz" );
         typeToExtensionMap.put( "distribution-zip", "zip" );
         typeToExtensionMap.put( "java-source", "jar" );
+        typeToExtensionMap.put( "javadoc.jar", "jar" );
+        typeToExtensionMap.put( "javadoc", "jar" );
         typeToExtensionMap.put( "aspect", "jar" );
         typeToExtensionMap.put( "uberjar", "jar" );
         typeToExtensionMap.put( "maven-plugin", "jar" );

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultArtifactExtensionMapping.java Thu Apr 19 13:54:27 2007
@@ -26,12 +26,8 @@
  *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @version $Id$
- * 
- * @plexus.component role="org.apache.maven.archiva.repository.content.ArtifactExtensionMapping"
- *                   role-hint="default"
  */
 public class DefaultArtifactExtensionMapping extends AbstractArtifactExtensionMapping
-    implements ArtifactExtensionMapping
 {
     public DefaultArtifactExtensionMapping()
     {

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyArtifactExtensionMapping.java Thu Apr 19 13:54:27 2007
@@ -26,23 +26,20 @@
  *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @version $Id$
- * 
- * @plexus.component role="org.apache.maven.archiva.repository.content.ArtifactExtensionMapping"
- *                   role-hint="legacy"
  */
-public class LegacyArtifactExtensionMapping extends AbstractArtifactExtensionMapping
-    implements ArtifactExtensionMapping
+public class LegacyArtifactExtensionMapping
+    extends AbstractArtifactExtensionMapping
 {
     public LegacyArtifactExtensionMapping()
     {
         super();
     }
 
-    public String getType( String filename )
+    public String getType( String pathType, String filename )
     {
         if ( StringUtils.isBlank( filename ) )
         {
-            return null;
+            return pathType;
         }
 
         String normalizedName = filename.toLowerCase().trim();
@@ -57,20 +54,15 @@
         }
         else if ( normalizedName.endsWith( "-sources.jar" ) )
         {
-            return "java-source";
+            return "jar";
+        }
+        else if ( normalizedName.endsWith( "-javadoc.jar" ) )
+        {
+            return "jar";
         }
-        // TODO: handle type for -javadoc.jar ?
         else
         {
-            int index = normalizedName.lastIndexOf( '.' );
-            if ( index >= 0 )
-            {
-                return normalizedName.substring( index + 1 );
-            }
-            else
-            {
-                throw new IllegalArgumentException( "Filename " + filename + " does not have an extension." );
-            }
+            return pathType;
         }
     }
 }

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java Thu Apr 19 13:54:27 2007
@@ -25,7 +25,6 @@
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.model.ProjectReference;
 import org.apache.maven.archiva.model.VersionedReference;
-import org.apache.maven.archiva.repository.content.ArtifactExtensionMapping;
 import org.apache.maven.archiva.repository.content.DefaultArtifactExtensionMapping;
 
 /**
@@ -39,6 +38,8 @@
 public class DefaultBidirectionalRepositoryLayout
     implements BidirectionalRepositoryLayout
 {
+    private static final String MAVEN_METADATA = "maven-metadata.xml";
+
     class PathReferences
     {
         public String groupId;
@@ -69,7 +70,7 @@
 
     private static final char ARTIFACT_SEPARATOR = '-';
 
-    private ArtifactExtensionMapping extensionMapper = new DefaultArtifactExtensionMapping();
+    private DefaultArtifactExtensionMapping extensionMapper = new DefaultArtifactExtensionMapping();
 
     public String getId()
     {
@@ -118,17 +119,36 @@
 
     public String toPath( ProjectReference reference )
     {
-        return toPath( reference.getGroupId(), reference.getArtifactId(), null, null, null, null );
+        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 toPath( VersionedReference reference )
     {
-        return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), null, null, null );
+        StringBuffer path = new StringBuffer();
+
+        path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
+        path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
+        path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR );
+        path.append( MAVEN_METADATA );
+
+        return path.toString();
     }
 
     public ProjectReference toProjectReference( String path )
         throws LayoutException
     {
+        if ( !path.endsWith( "/maven-metadata.xml" ) )
+        {
+            throw new LayoutException( "Only paths ending in '/maven-metadata.xml' can be "
+                + "converted to a ProjectReference." );
+        }
+
         PathReferences pathrefs = toPathReferences( path, false );
         ProjectReference reference = new ProjectReference();
         reference.setGroupId( pathrefs.groupId );
@@ -140,6 +160,12 @@
     public VersionedReference toVersionedReference( String path )
         throws LayoutException
     {
+        if ( !path.endsWith( "/maven-metadata.xml" ) )
+        {
+            throw new LayoutException( "Only paths ending in '/maven-metadata.xml' can be "
+                + "converted to a VersionedReference." );
+        }
+
         PathReferences pathrefs = toPathReferences( path, false );
 
         VersionedReference reference = new VersionedReference();
@@ -209,15 +235,30 @@
 
         // Maven 2.x path.
         int partCount = pathParts.length;
+        int filenamePos = partCount - 1;
+        int baseVersionPos = partCount - 2;
+        int artifactIdPos = partCount - 3;
+        int groupIdPos = partCount - 4;
 
         // Second to last is the baseVersion (the directory version)
-        prefs.baseVersion = pathParts[partCount - 2];
+        prefs.baseVersion = pathParts[baseVersionPos];
+
+        if ( "maven-metadata.xml".equals( pathParts[filenamePos] ) ) 
+        {
+            if( !VersionUtil.isVersion( prefs.baseVersion ) )
+            {
+                // We have a simple path without a version identifier.
+                prefs.baseVersion = null;
+                artifactIdPos++;
+                groupIdPos++;
+            }
+        }
 
         // Third to last is the artifact Id.
-        prefs.artifactId = pathParts[partCount - 3];
+        prefs.artifactId = pathParts[artifactIdPos];
 
         // Remaining pieces are the groupId.
-        for ( int i = 0; i <= partCount - 4; i++ )
+        for ( int i = 0; i <= groupIdPos; i++ )
         {
             prefs.appendGroupId( pathParts[i] );
         }
@@ -225,7 +266,7 @@
         try
         {
             // Last part is the filename
-            String filename = pathParts[partCount - 1];
+            String filename = pathParts[filenamePos];
 
             // Now we need to parse the filename to get the artifact version Id. 
             prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId );

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayout.java Thu Apr 19 13:54:27 2007
@@ -24,7 +24,6 @@
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.model.ProjectReference;
 import org.apache.maven.archiva.model.VersionedReference;
-import org.apache.maven.archiva.repository.content.ArtifactExtensionMapping;
 import org.apache.maven.archiva.repository.content.LegacyArtifactExtensionMapping;
 
 import java.util.HashMap;
@@ -41,9 +40,11 @@
 public class LegacyBidirectionalRepositoryLayout
     implements BidirectionalRepositoryLayout
 {
+    private static final String MAVEN_METADATA = "maven-metadata.xml";
+
     private static final String PATH_SEPARATOR = "/";
 
-    private ArtifactExtensionMapping extensionMapper = new LegacyArtifactExtensionMapping();
+    private LegacyArtifactExtensionMapping extensionMapper = new LegacyArtifactExtensionMapping();
 
     private Map typeToDirectoryMap;
 
@@ -62,25 +63,37 @@
 
     public String toPath( ArchivaArtifact artifact )
     {
-        return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact
-            .getClassifier(), artifact.getType() );
+        return toPath( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
+                       artifact.getClassifier(), artifact.getType() );
     }
 
     public String toPath( ProjectReference reference )
     {
-        // TODO: Verify type
-        return toPath( reference.getGroupId(), reference.getArtifactId(), null, null, "metadata-xml" );
+        StringBuffer path = new StringBuffer();
+
+        path.append( reference.getGroupId() ).append( PATH_SEPARATOR );
+        path.append( getDirectory( null, "jar" ) ).append( PATH_SEPARATOR );
+        path.append( MAVEN_METADATA );
+
+        return path.toString();
     }
 
     public String toPath( VersionedReference reference )
     {
-        return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), null, "metadata-xml" );
+        // NOTE: A legacy repository cannot contain a versioned reference to the metadata.
+        StringBuffer path = new StringBuffer();
+
+        path.append( reference.getGroupId() ).append( PATH_SEPARATOR );
+        path.append( getDirectory( null, "jar" ) ).append( PATH_SEPARATOR );
+        path.append( MAVEN_METADATA );
+
+        return path.toString();
     }
 
     public String toPath( ArtifactReference reference )
     {
-        return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(),
-                       reference.getClassifier(), reference.getType() );
+        return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference
+            .getClassifier(), reference.getType() );
     }
 
     private String toPath( String groupId, String artifactId, String version, String classifier, String type )
@@ -107,10 +120,18 @@
 
     private String getDirectory( String classifier, String type )
     {
-        // Special Cases involving classifiers and type.
-        if ( "jar".equals( type ) && "sources".equals( classifier ) )
+        // Special Cases involving type + classifier
+        if ( "jar".equals( type ) && StringUtils.isNotBlank( classifier ) )
         {
-            return "javadoc.jars";
+            if ( "sources".equals( classifier ) )
+            {
+                return "source.jars";
+            }
+
+            if ( "javadoc".equals( classifier ) )
+            {
+                return "javadoc.jars";
+            }
         }
 
         // Special Cases involving only type.
@@ -173,7 +194,20 @@
 
             prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, null );
 
-            prefs.type = extensionMapper.getType( filename );
+            prefs.type = extensionMapper.getType( prefs.pathType, filename );
+
+            // Sanity Checks.
+            if ( StringUtils.isEmpty( prefs.fileParts.extension ) )
+            {
+                throw new LayoutException( "Invalid artifact, no extension." );
+            }
+
+            if ( !prefs.type.equals( prefs.fileParts.extension ) )
+            {
+                throw new LayoutException( "Invalid artifact, mismatch on extension <" + prefs.fileParts.extension
+                    + "> and expected layout specified type <" + prefs.type
+                    + "> (mapped from actual path provided type <" + prefs.pathType + ">)" );
+            }
         }
 
         return prefs;
@@ -194,32 +228,28 @@
                                                         pathrefs.fileParts.version, pathrefs.fileParts.classifier,
                                                         pathrefs.type );
 
-        // Sanity Checks.
-        if ( StringUtils.isEmpty( pathrefs.fileParts.extension ) )
-        {
-            throw new LayoutException( "Invalid artifact, no extension." );
-        }
-
-        if ( !pathrefs.pathType.equals( pathrefs.fileParts.extension + "s" ) )
-        {
-            throw new LayoutException( "Invalid artifact, mismatch on extension <" + pathrefs.fileParts.extension
-                + "> and layout specified type<" + pathrefs.pathType + ">." );
-        }
-
         return artifact;
     }
 
     public ArtifactReference toArtifactReference( String path )
         throws LayoutException
     {
-        // TODO Auto-generated method stub
-        return null;
+        PathReferences pathrefs = toPathReferences( path, true );
+
+        ArtifactReference reference = new ArtifactReference();
+
+        reference.setGroupId( pathrefs.groupId );
+        reference.setArtifactId( pathrefs.fileParts.artifactId );
+        reference.setVersion( pathrefs.fileParts.version );
+        reference.setClassifier( pathrefs.fileParts.classifier );
+        reference.setType( pathrefs.type );
+
+        return reference;
     }
 
     public VersionedReference toVersionedReference( String path )
         throws LayoutException
     {
-        // TODO Auto-generated method stub
         return null;
     }
 

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java Thu Apr 19 13:54:27 2007
@@ -20,9 +20,7 @@
  */
 
 import org.apache.commons.lang.StringUtils;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.apache.maven.archiva.common.utils.VersionUtil;
 
 /**
  * RepositoryLayoutUtils - utility methods common for most BidirectionalRepositoryLayout implementation. 
@@ -39,18 +37,6 @@
     private static final String ComplexExtensions[] = new String[] { "tar.gz", "tar.bz2" };
 
     /**
-     * These are the version patterns found in the filenames of the various artifact's versions IDs.
-     * These patterns are all tackling lowercase version IDs.
-     */
-    private static final String VersionPatterns[] =
-        new String[] { "(snapshot)", "([0-9][_.0-9a-z]*)", "(g?[_.0-9ab]*(pre|rc|g|m)[_.0-9]*)", "(dev[_.0-9]*)",
-            "(alpha[_.0-9]*)", "(beta[_.0-9]*)", "(rc[_.0-9]*)", "(test[_.0-9]*)", "(debug[_.0-9]*)",
-            "(unofficial[_.0-9]*)", "(current)", "(latest)", "(fcs)", "(release[_.0-9]*)", "(nightly)", "(final)",
-            "(incubating)", "(incubator)", "([ab][_.0-9]*)" };
-
-    private static final String VersionMegaPattern = StringUtils.join( VersionPatterns, '|' );
-
-    /**
      * Filename Parsing Mode - Artifact Id.
      */
     private static final int ARTIFACTID = 1;
@@ -137,17 +123,13 @@
         int versionStart = -1;
         int versionEnd = -1;
 
-        Pattern pat = Pattern.compile( VersionMegaPattern, Pattern.CASE_INSENSITIVE );
-        Matcher mat;
-
         for ( int i = 0; i < fileParts.length; i++ )
         {
             String part = fileParts[i];
-            mat = pat.matcher( part );
-
-            if ( mat.matches() )
+            
+            if ( VersionUtil.isSimpleVersionKeyword( part ) )
             {
-                // It is a potential verion part.
+                // It is a potential version part.
                 if ( versionStart < 0 )
                 {
                     versionStart = i;

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayoutTest.java Thu Apr 19 13:54:27 2007
@@ -19,19 +19,15 @@
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.ArtifactReference;
 import org.apache.maven.archiva.model.ProjectReference;
 import org.apache.maven.archiva.model.VersionedReference;
-import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
-import org.apache.maven.archiva.repository.layout.LayoutException;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
 
 /**
  * DefaultBidirectionalRepositoryLayoutTest 
@@ -54,7 +50,11 @@
 
         public String type;
 
-        public String path;
+        public String pathArtifact;
+
+        public String pathVersiond;
+
+        public String pathProjectd;
 
         public LayoutExample( String groupId, String artifactId, String version, String classifier, String type )
         {
@@ -66,6 +66,30 @@
             this.type = type;
         }
 
+        public void setDelimitedPath( String delimPath )
+        {
+            // Silly Test Writer! Don't end the path with a slash!
+            if ( delimPath.endsWith( "/" ) )
+            {
+                delimPath = delimPath.substring( 0, delimPath.length() - 1 );
+            }
+
+            String parts[] = StringUtils.split( delimPath, '|' );
+            switch ( parts.length )
+            {
+                case 3:
+                    this.pathArtifact = parts[0] + "/" + parts[1] + "/" + parts[2];
+                case 2:
+                    this.pathVersiond = parts[0] + "/" + parts[1] + "/maven-metadata.xml";
+                case 1:
+                    this.pathProjectd = parts[0] + "/maven-metadata.xml";
+                    break;
+                default:
+                    fail( "Unknown number of path pieces, expected between 1 and 3, got <" + parts.length + "> on <"
+                        + delimPath + ">" );
+            }
+        }
+
         public boolean isSuitableForArtifactTest()
         {
             return ( this.type != null ) && ( this.classifier != null ) && ( this.version != null );
@@ -108,58 +132,65 @@
         LayoutExample example;
 
         // Artifact References
-        example = new LayoutExample( "com.foo", "foo-tool", "1.0", "", "jar" );
-        example.path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
+        example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" );
+        example.setDelimitedPath( "com/foo/foo-tool|1.0|foo-tool-1.0.jar" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-client", "1.0", "", "ejb-client" );
-        example.path = "com/foo/foo-client/1.0/foo-client-1.0.jar";
+        example = new LayoutExample( "com.foo", "foo-client", "1.0", null, "ejb-client" );
+        example.setDelimitedPath( "com/foo/foo-client|1.0|foo-client-1.0.jar" );
         ret.add( example );
 
         example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "java-source" );
-        example.path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar";
+        example.setDelimitedPath( "com/foo/lib/foo-lib|2.1-alpha-1|foo-lib-2.1-alpha-1-sources.jar" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", "", "jar" );
-        example.path = "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar";
+        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, "jar" );
+        example.setDelimitedPath( "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar" );
         ret.add( example );
 
-        example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", "",
+        example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", null,
                                      "jar" );
-        example.path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
+        example
+            .setDelimitedPath( "org/apache/maven/test/get-metadata-snapshot|1.0-SNAPSHOT|get-metadata-snapshot-1.0-20050831.101112-1.jar" );
         ret.add( example );
 
-        example = new LayoutExample( "commons-lang", "commons-lang", "2.1", "", "jar" );
-        example.path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
+        example = new LayoutExample( "commons-lang", "commons-lang", "2.1", null, "jar" );
+        example.setDelimitedPath( "commons-lang/commons-lang|2.1|commons-lang-2.1.jar" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-tool", "1.0", "", "jar" );
-        example.path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
+        example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" );
+        example.setDelimitedPath( "com/foo/foo-tool|1.0|foo-tool-1.0.jar" );
         ret.add( example );
 
         // Versioned References (done here by setting classifier and type to null)
         example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, null );
-        example.path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar";
+        example.setDelimitedPath( "com/foo/foo-tool|1.0" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, null );
-        example.path = "com/foo/foo-tool/1.0/";
+        example = new LayoutExample( "net.i.have.a.really.long.path.just.for.the.hell.of.it", "a", "1.1-alpha-1", null,
+                                     null );
+        example.setDelimitedPath( "net/i/have/a/really/long/path/just/for/the/hell/of/it/a|1.1-alpha-1" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, null );
-        example.path = "com/foo/foo-tool/1.0";
+        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null );
+        example.setDelimitedPath( "com/foo/foo-connector|2.1-SNAPSHOT" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null );
-        example.path = "com/foo/foo-connector/2.1-SNAPSHOT/foo-connector-2.1-20060822.123456-35.jar";
+        example = new LayoutExample( "com.foo", "foo-connector", "2.1-SNAPSHOT", null, null );
+        example.setDelimitedPath( "com/foo/foo-connector|2.1-SNAPSHOT" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null );
-        example.path = "com/foo/foo-connector/2.1-SNAPSHOT/";
+        // Project References (done here by setting version, classifier, and type to null)
+        example = new LayoutExample( "com.foo", "foo-tool", null, null, null );
+        example.setDelimitedPath( "com/foo/foo-tool/" );
         ret.add( example );
 
-        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, null );
-        example.path = "com/foo/foo-connector/2.1-SNAPSHOT";
+        example = new LayoutExample( "net.i.have.a.really.long.path.just.for.the.hell.of.it", "a", null, null, null );
+        example.setDelimitedPath( "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/" );
+        ret.add( example );
+
+        example = new LayoutExample( "com.foo", "foo-connector", null, null, null );
+        example.setDelimitedPath( "com/foo/foo-connector" );
         ret.add( example );
 
         return ret;
@@ -209,7 +240,7 @@
             {
                 ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version,
                                                            example.classifier, example.type );
-                assertEquals( "Artifact <" + artifact + "> to path:", example.path, layout.toPath( artifact ) );
+                assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, layout.toPath( artifact ) );
             }
         }
     }
@@ -229,7 +260,8 @@
                 reference.setClassifier( example.classifier );
                 reference.setType( example.type );
 
-                assertEquals( "ArtifactReference <" + reference + "> to path:", example.path, layout.toPath( reference ) );
+                assertEquals( "ArtifactReference <" + reference + "> to path:", example.pathArtifact, layout
+                    .toPath( reference ) );
             }
         }
     }
@@ -240,14 +272,14 @@
         while ( it.hasNext() )
         {
             LayoutExample example = (LayoutExample) it.next();
-            if ( example.isSuitableForVersionedTest() && example.isSuitableForArtifactTest() )
+            if ( example.isSuitableForVersionedTest() || example.isSuitableForArtifactTest() )
             {
                 VersionedReference reference = new VersionedReference();
                 reference.setGroupId( example.groupId );
                 reference.setArtifactId( example.artifactId );
                 reference.setVersion( example.version );
 
-                assertEquals( "VersionedReference <" + reference + "> to path:", example.path, layout
+                assertEquals( "VersionedReference <" + reference + "> to path:", example.pathVersiond, layout
                     .toPath( reference ) );
             }
         }
@@ -259,14 +291,15 @@
         while ( it.hasNext() )
         {
             LayoutExample example = (LayoutExample) it.next();
-            if ( example.isSuitableForProjectTest() && example.isSuitableForVersionedTest()
-                && example.isSuitableForArtifactTest() )
+            if ( example.isSuitableForProjectTest() || example.isSuitableForVersionedTest()
+                || example.isSuitableForArtifactTest() )
             {
                 ProjectReference reference = new ProjectReference();
                 reference.setGroupId( example.groupId );
                 reference.setArtifactId( example.artifactId );
 
-                assertEquals( "ProjectReference <" + reference + "> to path:", example.path, layout.toPath( reference ) );
+                assertEquals( "ProjectReference <" + reference + "> to path:", example.pathProjectd, layout
+                    .toPath( reference ) );
             }
         }
     }
@@ -366,14 +399,13 @@
             LayoutExample example = (LayoutExample) it.next();
             if ( example.isSuitableForArtifactTest() )
             {
-                ArchivaArtifact artifact = layout.toArtifact( example.path );
+                ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact );
                 assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier,
                                 example.type );
             }
         }
     }
 
-    /* TODO: Fix layout object to pass test.
     public void testPathToArtifactReference()
         throws LayoutException
     {
@@ -383,15 +415,13 @@
             LayoutExample example = (LayoutExample) it.next();
             if ( example.isSuitableForArtifactTest() )
             {
-                ArtifactReference reference = layout.toArtifactReference( example.path );
+                ArtifactReference reference = layout.toArtifactReference( example.pathArtifact );
                 assertArtifactReference( reference, example.groupId, example.artifactId, example.version,
                                          example.classifier, example.type );
             }
         }
     }
-    */
 
-    /* TODO: Fix layout object to pass test.
     public void testPathToVersionedReference()
         throws LayoutException
     {
@@ -401,13 +431,14 @@
             LayoutExample example = (LayoutExample) it.next();
             if ( example.isSuitableForVersionedTest() )
             {
-                VersionedReference reference = layout.toVersionedReference( example.path );
+                VersionedReference reference = layout.toVersionedReference( example.pathVersiond );
+                
+                String baseVersion = reference.getVersion();
 
-                assertVersionedReference( reference, example.groupId, example.artifactId, example.version );
+                assertVersionedReference( reference, example.groupId, example.artifactId, baseVersion );
             }
         }
     }
-    */
 
     public void testPathToProjectReference()
         throws LayoutException
@@ -418,7 +449,7 @@
             LayoutExample example = (LayoutExample) it.next();
             if ( example.isSuitableForProjectTest() )
             {
-                ProjectReference reference = layout.toProjectReference( example.path );
+                ProjectReference reference = layout.toProjectReference( example.pathProjectd );
 
                 assertProjectReference( reference, example.groupId, example.artifactId );
             }
@@ -437,7 +468,7 @@
                 ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version,
                                                            example.classifier, example.type );
                 String testPath = layout.toPath( artifact );
-                assertEquals( "Artifact <" + artifact + "> to path:", example.path, testPath );
+                assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath );
                 ArchivaArtifact testArtifact = layout.toArtifact( testPath );
                 assertArtifact( testArtifact, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
                                 artifact.getClassifier(), artifact.getType() );
@@ -454,11 +485,11 @@
             LayoutExample example = (LayoutExample) it.next();
             if ( example.isSuitableForArtifactTest() )
             {
-                ArchivaArtifact artifact = layout.toArtifact( example.path );
+                ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact );
                 assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier,
                                 example.type );
                 String testPath = layout.toPath( artifact );
-                assertEquals( "Artifact <" + artifact + "> to path:", example.path, testPath );
+                assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath );
             }
         }
     }

Modified: maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java?view=diff&rev=530543&r1=530542&r2=530543
==============================================================================
--- maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java (original)
+++ maven/archiva/branches/archiva-jpox-database-refactor/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java Thu Apr 19 13:54:27 2007
@@ -19,8 +19,15 @@
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.ProjectReference;
+import org.apache.maven.archiva.model.VersionedReference;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * LegacyBidirectionalRepositoryLayoutTest 
@@ -28,129 +35,477 @@
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @version $Id$
  */
-public class LegacyBidirectionalRepositoryLayoutTest extends AbstractBidirectionalRepositoryLayoutTestCase
+public class LegacyBidirectionalRepositoryLayoutTest
+    extends AbstractBidirectionalRepositoryLayoutTestCase
 {
-    private BidirectionalRepositoryLayout layout;
-
-    protected void setUp() throws Exception
+    class LayoutExample
     {
-        super.setUp();
+        public String groupId;
 
-        layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" );
-    }
+        public String artifactId;
 
-    public void testToPathBasic()
-    {
-        ArchivaArtifact artifact = createArtifact( "com.foo", "foo-tool", "1.0", "", "jar" );
+        public String version;
+
+        public String classifier;
+
+        public String type;
+
+        public String pathArtifact;
+
+        public String pathVersiond;
+
+        public String pathProjectd;
+
+        public LayoutExample( String groupId, String artifactId, String version, String classifier, String type )
+        {
+            super();
+            this.groupId = groupId;
+            this.artifactId = artifactId;
+            this.version = version;
+            this.classifier = classifier;
+            this.type = type;
+        }
+
+        public void setDelimitedPath( String delimPath )
+        {
+            // Silly Test Writer! Don't end the path with a slash!
+            if ( delimPath.endsWith( "/" ) )
+            {
+                delimPath = delimPath.substring( 0, delimPath.length() - 1 );
+            }
+
+            String parts[] = StringUtils.split( delimPath, '|' );
+            switch ( parts.length )
+            {
+                case 3:
+                    this.pathArtifact = parts[0] + "/" + parts[1] + "/" + parts[2];
+                case 2:
+                    this.pathVersiond = parts[0] + "/jars/maven-metadata.xml";
+                case 1:
+                    this.pathProjectd = parts[0] + "/jars/maven-metadata.xml";
+                    break;
+                default:
+                    fail( "Unknown number of path pieces, expected between 1 and 3, got <" + parts.length + "> on <"
+                        + delimPath + ">" );
+            }
+        }
+
+        public boolean isSuitableForArtifactTest()
+        {
+            return ( this.type != null ) && ( this.classifier != null ) && ( this.version != null );
+        }
+
+        public boolean isSuitableForVersionedTest()
+        {
+            return ( this.type == null ) && ( this.classifier == null ) && ( this.version != null );
+        }
 
-        assertEquals( "com.foo/jars/foo-tool-1.0.jar", layout.toPath( artifact ) );
+        public boolean isSuitableForProjectTest()
+        {
+            return ( this.type == null ) && ( this.classifier == null ) && ( this.version == null );
+        }
     }
 
-    public void testToPathEjbClient()
+    class InvalidExample
     {
-        ArchivaArtifact artifact = createArtifact( "com.foo", "foo-client", "1.0", "", "ejb-client" );
+        public String path;
+
+        public String reason;
 
-        assertEquals( "com.foo/ejbs/foo-client-1.0.jar", layout.toPath( artifact ) );
+        public boolean suitableForArtifactTests = true;
+        public boolean suitableForVersionedTests = false;
+        public boolean suitableForProjectTests = false;
+
+        public InvalidExample( String path, String reason )
+        {
+            super();
+            this.path = path;
+            this.reason = reason;
+        }
     }
 
-    public void testToPathWithClassifier()
+    private BidirectionalRepositoryLayout layout;
+
+    protected void setUp()
+        throws Exception
     {
-        ArchivaArtifact artifact = createArtifact( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" );
+        super.setUp();
 
-        assertEquals( "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-sources.jar", layout.toPath( artifact ) );
+        layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" );
     }
 
-    public void testToPathUsingUniqueSnapshot()
+    public List /*<LayoutExample>*/getGoodExamples()
     {
-        ArchivaArtifact artifact = createArtifact( "com.foo", "foo-connector", "2.1-20060822.123456-35", "", "jar" );
+        List ret = new ArrayList();
+
+        LayoutExample example;
 
-        assertEquals( "com.foo/jars/foo-connector-2.1-20060822.123456-35.jar", layout.toPath( artifact ) );
+        // Artifact References
+        example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" );
+        example.setDelimitedPath( "com.foo|jars|foo-tool-1.0.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "com.foo", "foo-client", "1.0", null, "ejb-client" );
+        example.setDelimitedPath( "com.foo|ejbs|foo-client-1.0.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" );
+        example.setDelimitedPath( "com.foo.lib|source.jars|foo-lib-2.1-alpha-1-sources.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "javadoc", "jar" );
+        example.setDelimitedPath( "com.foo.lib|javadoc.jars|foo-lib-2.1-alpha-1-javadoc.jar" );
+        ret.add( example );
+        
+        example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, "jar" );
+        example.setDelimitedPath( "com.foo|jars|foo-connector-2.1-20060822.123456-35.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", null,
+                                     "jar" );
+        example.setDelimitedPath( "org.apache.maven.test|jars|get-metadata-snapshot-1.0-20050831.101112-1.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "commons-lang", "commons-lang", "2.1", null, "jar" );
+        example.setDelimitedPath( "commons-lang|jars|commons-lang-2.1.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "org.apache.derby", "derby", "10.2.2.0", null, "jar" );
+        example.setDelimitedPath( "org.apache.derby|jars|derby-10.2.2.0.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
+        example.setDelimitedPath( "org.apache.geronimo.specs|jars|geronimo-ejb_2.1_spec-1.0.1.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "org.apache.beehive", "beehive-ejb-control", "1.0.1", null, "jar" );
+        example.setDelimitedPath( "org.apache.beehive|jars|beehive-ejb-control-1.0.1.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "commons-lang", "commons-lang", "2.3", "sources", "jar" );
+        example.setDelimitedPath( "commons-lang|source.jars|commons-lang-2.3-sources.jar" );
+        ret.add( example );
+
+        example = new LayoutExample( "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
+        example.setDelimitedPath( "directory-clients|poms|ldap-clients-0.9.1-SNAPSHOT.pom" );
+        ret.add( example );
+
+        // Versioned References (done here by setting classifier and type to null)
+        
+        // TODO: Not sure how to represent a VersionedReference as a legacy path.
+
+        // Project References (done here by setting version, classifier, and type to null)
+        
+        // TODO: Not sure how to represent a ProjectReference as a legacy path.
+
+        return ret;
     }
+    
+    public List /*<InvalidExample>*/getInvalidPaths()
+    {
+        List ret = new ArrayList();
 
-    public void testToArtifactBasicSimpleGroupId() throws LayoutException
+        InvalidExample example;
+
+        example = new InvalidExample( "invalid/invalid/1/invalid-1", "missing type" );
+        example.suitableForArtifactTests = true;
+        example.suitableForVersionedTests = false;
+        example.suitableForProjectTests = true;
+        ret.add( example );
+
+        example = new InvalidExample( "org.apache.maven.test/jars/artifactId-1.0.jar.md5", "wrong package extension" );
+        example.suitableForArtifactTests = true;
+        example.suitableForVersionedTests = false;
+        example.suitableForProjectTests = false;
+        ret.add( example );
+
+        example = new InvalidExample( "groupId/jars/-1.0.jar", "artifactId is missing" );
+        example.suitableForArtifactTests = true;
+        example.suitableForVersionedTests = false;
+        example.suitableForProjectTests = true;
+        ret.add( example );
+
+        example = new InvalidExample( "groupId/jars/1.0.jar", "artifactId is missing" );
+        example.suitableForArtifactTests = true;
+        example.suitableForVersionedTests = false;
+        example.suitableForProjectTests = true;
+        ret.add( example );
+
+        return ret;
+    }
+    
+    public void testArtifactToPath()
     {
-        ArchivaArtifact artifact = layout.toArtifact( "commons-lang/jars/commons-lang-2.1.jar" );
-        assertArtifact( artifact, "commons-lang", "commons-lang", "2.1", "", "jar" );
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
+        {
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForArtifactTest() )
+            {
+                ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version,
+                                                           example.classifier, example.type );
+                assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, layout.toPath( artifact ) );
+            }
+        }
     }
 
-    public void testToArtifactBasicLongGroupId() throws LayoutException
+    public void testArtifactReferenceToPath()
     {
-        ArchivaArtifact artifact = layout.toArtifact( "org.apache.derby/jars/derby-10.2.2.0.jar" );
-        assertArtifact( artifact, "org.apache.derby", "derby", "10.2.2.0", "", "jar" );
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
+        {
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForArtifactTest() )
+            {
+                ArtifactReference reference = new ArtifactReference();
+                reference.setGroupId( example.groupId );
+                reference.setArtifactId( example.artifactId );
+                reference.setVersion( example.version );
+                reference.setClassifier( example.classifier );
+                reference.setType( example.type );
+
+                assertEquals( "ArtifactReference <" + reference + "> to path:", example.pathArtifact, layout
+                    .toPath( reference ) );
+            }
+        }
     }
 
-    public void testToArtifactLongGroupId() throws LayoutException
+    public void testVersionedReferenceToPath()
     {
-        ArchivaArtifact artifact = layout.toArtifact( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar" );
-        assertArtifact( artifact, "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", "", "jar" );
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
+        {
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForVersionedTest() || example.isSuitableForArtifactTest() )
+            {
+                VersionedReference reference = new VersionedReference();
+                reference.setGroupId( example.groupId );
+                reference.setArtifactId( example.artifactId );
+                reference.setVersion( example.version );
+
+                assertEquals( "VersionedReference <" + reference + "> to path:", example.pathVersiond, layout
+                    .toPath( reference ) );
+            }
+        }
     }
 
-    public void testToArtifactEjbClient() throws LayoutException
+    public void testProjectReferenceToPath()
     {
-        ArchivaArtifact artifact = layout.toArtifact( "org.apache.beehive/jars/beehive-ejb-control-1.0.1.jar" );
-        // The type is correct. as we cannot possibly know this is an ejb client without parsing the pom
-        assertArtifact( artifact, "org.apache.beehive", "beehive-ejb-control", "1.0.1", "", "jar" );
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
+        {
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForProjectTest() || example.isSuitableForVersionedTest()
+                || example.isSuitableForArtifactTest() )
+            {
+                ProjectReference reference = new ProjectReference();
+                reference.setGroupId( example.groupId );
+                reference.setArtifactId( example.artifactId );
+
+                assertEquals( "ProjectReference <" + reference + "> to path:", example.pathProjectd, layout
+                    .toPath( reference ) );
+            }
+        }
     }
 
-    public void testToArtifactWithClassifier() throws LayoutException
+    public void testInvalidPathToArtifact()
     {
-        ArchivaArtifact artifact = layout.toArtifact( "commons-lang/jars/commons-lang-2.3-sources.jar" );
-        // The 'java-source' type is correct.  You might be thinking of extension, which we are not testing here.
-        assertArtifact( artifact, "commons-lang", "commons-lang", "2.3", "sources", "java-source" );
+        Iterator it = getInvalidPaths().iterator();
+        while ( it.hasNext() )
+        {
+            InvalidExample example = (InvalidExample) it.next();
+
+            try
+            {
+                layout.toArtifact( example.path );
+                fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of ["
+                    + example.reason + "]" );
+            }
+            catch ( LayoutException e )
+            {
+                /* expected path */
+            }
+        }
     }
 
-    public void testToArtifactSnapshot() throws LayoutException
+    public void testInvalidPathToArtifactReference()
     {
-        ArchivaArtifact artifact = layout.toArtifact( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" );
-        assertSnapshotArtifact( artifact, "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", "", "pom" );
+        Iterator it = getInvalidPaths().iterator();
+        while ( it.hasNext() )
+        {
+            InvalidExample example = (InvalidExample) it.next();
+            
+            if( !example.suitableForArtifactTests )
+            {
+                continue;
+            }
+
+            try
+            {
+                layout.toArtifactReference( example.path );
+                fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of ["
+                    + example.reason + "]" );
+            }
+            catch ( LayoutException e )
+            {
+                /* expected path */
+            }
+        }
     }
-    
-    public void testInvalidNoType()
+
+    public void testInvalidPathToVersionedReference()
     {
-        try
+        Iterator it = getInvalidPaths().iterator();
+        while ( it.hasNext() )
         {
-            layout.toArtifact( "invalid/invalid/1/invalid-1" );
-            fail( "Should have detected no type." );
+            InvalidExample example = (InvalidExample) it.next();
+
+            if( !example.suitableForVersionedTests )
+            {
+                continue;
+            }
+
+            try
+            {
+                layout.toVersionedReference( example.path );
+                fail( "Should have thrown a LayoutException on the invalid path [" + example.path
+                    + "] because of [" + example.reason + "]" );
+            }
+            catch ( LayoutException e )
+            {
+                /* expected path */
+            }
         }
-        catch ( LayoutException e )
+    }
+
+    public void testInvalidPathToProjectReference()
+    {
+        Iterator it = getInvalidPaths().iterator();
+        while ( it.hasNext() )
         {
-            /* expected path */
+            InvalidExample example = (InvalidExample) it.next();
+
+            if( !example.suitableForProjectTests )
+            {
+                continue;
+            }
+
+            try
+            {
+                layout.toProjectReference( example.path );
+                fail( "Should have thrown a LayoutException on the invalid path [" + example.path
+                    + "] because of [" + example.reason + "]" );
+            }
+            catch ( LayoutException e )
+            {
+                /* expected path */
+            }
         }
     }
-    
-    public void testInvalidArtifactPackaging()
+
+    public void testPathToArtifact()
+        throws LayoutException
     {
-        try
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
         {
-            layout.toArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" );
-            fail( "Should have detected wrong package extension." );
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForArtifactTest() )
+            {
+                ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact );
+                assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier,
+                                example.type );
+            }
         }
-        catch ( LayoutException e )
+    }
+
+    public void testPathToArtifactReference()
+        throws LayoutException
+    {
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
         {
-            /* expected path */
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForArtifactTest() )
+            {
+                ArtifactReference reference = layout.toArtifactReference( example.pathArtifact );
+                assertArtifactReference( reference, example.groupId, example.artifactId, example.version,
+                                         example.classifier, example.type );
+            }
         }
     }
-    
-    public void testInvalidNoArtifactId()
+
+    public void testPathToVersionedReference()
+        throws LayoutException
     {
-        try
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
         {
-            layout.toArtifact( "groupId/jars/-1.0.jar" );
-            fail( "Should have detected artifactId is missing" );
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForVersionedTest() )
+            {
+                VersionedReference reference = layout.toVersionedReference( example.pathVersiond );
+                
+                String baseVersion = reference.getVersion();
+
+                assertVersionedReference( reference, example.groupId, example.artifactId, baseVersion );
+            }
         }
-        catch ( LayoutException e )
+    }
+
+    public void testPathToProjectReference()
+        throws LayoutException
+    {
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
         {
-            /* expected path */
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForProjectTest() )
+            {
+                ProjectReference reference = layout.toProjectReference( example.pathProjectd );
+
+                assertProjectReference( reference, example.groupId, example.artifactId );
+            }
         }
-        
-        try
+    }
+
+    public void testRoundtripArtifactToPathToArtifact()
+        throws LayoutException
+    {
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
         {
-            layout.toArtifact( "groupId/jars/1.0.jar" );
-            fail( "Should have detected artifactId is missing" );
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForArtifactTest() )
+            {
+                ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version,
+                                                           example.classifier, example.type );
+                String testPath = layout.toPath( artifact );
+                assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath );
+                ArchivaArtifact testArtifact = layout.toArtifact( testPath );
+                assertArtifact( testArtifact, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
+                                artifact.getClassifier(), artifact.getType() );
+            }
         }
-        catch ( LayoutException e )
+    }
+
+    public void testRoundtripPathToArtifactToPath()
+        throws LayoutException
+    {
+        Iterator it = getGoodExamples().iterator();
+        while ( it.hasNext() )
         {
-            /* expected path */
+            LayoutExample example = (LayoutExample) it.next();
+            if ( example.isSuitableForArtifactTest() )
+            {
+                ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact );
+                assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier,
+                                example.type );
+                String testPath = layout.toPath( artifact );
+                assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath );
+            }
         }
     }
+
+
 }