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/10/05 01:03:38 UTC

svn commit: r582024 - in /maven/archiva/trunk/archiva-base/archiva-repository-layer/src: main/java/org/apache/maven/archiva/repository/layout/ test/java/org/apache/maven/archiva/repository/layout/

Author: joakime
Date: Thu Oct  4 16:03:37 2007
New Revision: 582024

URL: http://svn.apache.org/viewvc?rev=582024&view=rev
Log:
[MRM-517] Some maven 2 requests are treated as maven 1 requests
Applied patch by: nicolas de loof


Modified:
    maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
    maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java
    maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java

Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java?rev=582024&r1=582023&r2=582024&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java Thu Oct  4 16:03:37 2007
@@ -181,7 +181,7 @@
         String pathParts[] = StringUtils.split( normalizedPath, '/' );
 
         /* Minimum parts.
-         * 
+         *
          *   path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar"
          *   path[0] = "commons-lang";        // The Group ID
          *   path[1] = "commons-lang";        // The Artifact ID
@@ -220,23 +220,23 @@
             // Last part is the filename
             String filename = pathParts[filenamePos];
 
-            // Now we need to parse the filename to get the artifact version Id. 
-            prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId );
+            // Now we need to parse the filename to get the artifact version Id.
+            prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId, prefs.baseVersion );
 
             /* If classifier is discovered, see if it deserves to be.
-             * 
+             *
              * Filenames like "comm-3.0-u1.jar" might be identified as having a version of "3.0"
              * and a classifier of "u1".
-             * 
-             * This routine will take the version + classifier and compare it to the prefs.baseVersion and 
+             *
+             * This routine will take the version + classifier and compare it to the prefs.baseVersion and
              * move the classifierensure that
-             * 
+             *
              * javax/comm/3.0-u1/comm-3.0-u1.jar
              */
             if ( StringUtils.isNotBlank( prefs.fileParts.classifier ) )
             {
-                String conjoinedVersion = prefs.fileParts.version + "-" + prefs.fileParts.classifier; 
-                
+                String conjoinedVersion = prefs.fileParts.version + "-" + prefs.fileParts.classifier;
+
                 if( StringUtils.equals( prefs.baseVersion, conjoinedVersion ) )
                 {
                     prefs.fileParts.version = conjoinedVersion;
@@ -255,10 +255,10 @@
         if ( prefs.fileParts != null )
         {
             /* Compare artifact version to path baseversion.
-             * 
+             *
              * Version naming in the wild can be strange at times.
              * Sometimes what is seen as a classifier is actually part of the version id.
-             * 
+             *
              * To compensate for this, the path is checked against the artifact.version and
              *  the concatenation of the artifact.version + "-" + artifact.classifier
              */

Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java?rev=582024&r1=582023&r2=582024&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java Thu Oct  4 16:03:37 2007
@@ -52,23 +52,42 @@
     private static final int CLASSIFIER = 3;
 
     /**
+     * Split the provided filename into 4 String parts. Simply delegate to 
+     * splitFilename( filename, possibleArtifactId, possibleVersion ) with no possibleVersion
+     * proposal.
+     *
+     * @param filename the filename to split.
+     * @param possibleArtifactId the optional artifactId to aide in splitting the filename.
+     *                  (null to allow algorithm to calculate one)
+     * @return the parts of the filename.
+     * @throws LayoutException
+     */
+    public static FilenameParts splitFilename( String filename, String possibleArtifactId ) throws LayoutException
+    {
+        return splitFilename( filename, possibleArtifactId, null );
+    }
+
+    /**
      * Split the provided filename into 4 String parts.
-     * 
+     *
      * <pre>
      * String part[] = splitFilename( filename );
      * artifactId = part[0];
-     * version    = part[1];
+     * version = part[1];
      * classifier = part[2];
-     * extension  = part[3];
+     * extension = part[3];
      * </pre>
-     * 
+     *
      * @param filename the filename to split.
-     * @param possibleArtifactId the optional artifactId to aide in splitting the filename. 
+     * @param possibleArtifactId the optional artifactId to aide in splitting the filename.
+     *                  (null to allow algorithm to calculate one)
+     * @param possibleVersion the optional version to aide in splitting the filename.
      *                  (null to allow algorithm to calculate one)
      * @return the parts of the filename.
-     * @throws LayoutException 
+     * @throws LayoutException
      */
-    public static FilenameParts splitFilename( String filename, String possibleArtifactId ) throws LayoutException
+    public static FilenameParts splitFilename( String filename, String possibleArtifactId,
+                                               String possibleVersion ) throws LayoutException
     {
         if ( StringUtils.isBlank( filename ) )
         {
@@ -111,22 +130,37 @@
         }
 
         // Work on version string.
+        int mode = ARTIFACTID;
 
-        if ( ( possibleArtifactId != null ) && filename.startsWith( possibleArtifactId ) )
+        if ( startsWith( filename, possibleArtifactId ) )
         {
             parts.artifactId = possibleArtifactId;
             filestring = filestring.substring( possibleArtifactId.length() + 1 );
+            mode = VERSION;
+        }
+
+        if ( startsWith( filestring, possibleVersion ) )
+        {
+            if ( filestring.length() > possibleVersion.length() )
+            {
+                filestring = filestring.substring( possibleVersion.length() );
+            }
+            else
+            {
+                filestring = "";
+            }
+            parts.version = possibleVersion;
+            mode = CLASSIFIER;
         }
 
         String fileParts[] = StringUtils.split( filestring, '-' );
 
         int versionStart = -1;
         int versionEnd = -1;
-
         for ( int i = 0; i < fileParts.length; i++ )
         {
             String part = fileParts[i];
-            
+
             if ( VersionUtil.isSimpleVersionKeyword( part ) )
             {
                 // It is a potential version part.
@@ -139,10 +173,10 @@
             }
         }
 
-        if ( versionStart < 0 )
+        if ( versionStart < 0 && parts.version == null )
         {
             // Assume rest of string is the version Id.
-            
+
             if ( fileParts.length > 0 )
             {
                 versionStart = 0;
@@ -154,9 +188,8 @@
             }
         }
 
-        // Gather up the ArtifactID - Version - Classifier pieces found. 
+        // Gather up the ArtifactID - Version - Classifier pieces found.
 
-        int mode = ARTIFACTID;
         for ( int i = 0; i < fileParts.length; i++ )
         {
             String part = fileParts[i];
@@ -192,4 +225,20 @@
         return parts;
     }
 
+    /**
+     * Check if the string starts with the proposed token, with no more char
+     * expeect the '-' separator.
+     * @param string string to test
+     * @param possible proposed startOf
+     * @return true if the possible matches
+     */
+    private static boolean startsWith( String string, String possible )
+    {
+        if (possible == null)
+        {
+            return false;
+        }
+        int length = possible.length();
+        return string.startsWith( possible ) && ( string.length() == length || string.charAt( length ) == '-' );
+    }
 }

Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java?rev=582024&r1=582023&r2=582024&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java Thu Oct  4 16:03:37 2007
@@ -22,7 +22,7 @@
 import junit.framework.TestCase;
 
 /**
- * RepositoryLayoutUtilsTest 
+ * RepositoryLayoutUtilsTest
  *
  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @version $Id$
@@ -34,7 +34,7 @@
         assertFilenameParts( RepositoryLayoutUtils.splitFilename( "commons-lang-2.1.jar", "commons-lang" ),
                              "commons-lang", "2.1", null, "jar" );
     }
-    
+
     public void testSplitFilenameMavenTestPlugin() throws LayoutException
     {
         // Using maven 2 logic (artifactId is present in full path)
@@ -214,6 +214,16 @@
             /* Expected Path */
         }
     }
+
+    public void testSplitFilenameWithProposedVersion() throws LayoutException
+    {
+        assertFilenameParts( RepositoryLayoutUtils.splitFilename( "jtidy-r8-21122004.jar", "jtidy", "r8-21122004" ),
+                             "jtidy", "r8-21122004", null, "jar" );
+
+        assertFilenameParts( RepositoryLayoutUtils.splitFilename( "jtidy-r8-21122004-sources.jar", "jtidy", "r8-21122004" ),
+            "jtidy", "r8-21122004", "sources", "jar" );
+    }
+
 
     private void assertFilenameParts( FilenameParts actualParts, String artifactId, String version, String classifier,
                                       String extension )