[MRM-517] Some maven 2 requests are treated as maven 1 requests

Applied patch by: nicolas de loof



git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@582024 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-10-04 23:03:37 +00:00
parent 1ad4bcc637
commit 13e64dfc3d
3 changed files with 86 additions and 27 deletions

View File

@ -181,7 +181,7 @@ public class DefaultBidirectionalRepositoryLayout
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 @@ public class DefaultBidirectionalRepositoryLayout
// 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 @@ public class DefaultBidirectionalRepositoryLayout
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
*/

View File

@ -51,24 +51,43 @@ public class RepositoryLayoutUtils
*/
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 @@ public class RepositoryLayoutUtils
}
// 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 @@ public class RepositoryLayoutUtils
}
}
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 @@ public class RepositoryLayoutUtils
}
}
// 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 @@ public class RepositoryLayoutUtils
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 ) == '-' );
}
}

View File

@ -22,7 +22,7 @@ package org.apache.maven.archiva.repository.layout;
import junit.framework.TestCase;
/**
* RepositoryLayoutUtilsTest
* RepositoryLayoutUtilsTest
*
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
@ -34,7 +34,7 @@ public class RepositoryLayoutUtilsTest extends TestCase
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)
@ -215,6 +215,16 @@ public class RepositoryLayoutUtilsTest extends TestCase
}
}
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 )
{