[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

@ -221,7 +221,7 @@ public class DefaultBidirectionalRepositoryLayout
String filename = pathParts[filenamePos]; String filename = pathParts[filenamePos];
// Now we need to parse the filename to get the artifact version Id. // Now we need to parse the filename to get the artifact version Id.
prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId ); prefs.fileParts = RepositoryLayoutUtils.splitFilename( filename, prefs.artifactId, prefs.baseVersion );
/* If classifier is discovered, see if it deserves to be. /* If classifier is discovered, see if it deserves to be.
* *

View File

@ -51,6 +51,22 @@ public class RepositoryLayoutUtils
*/ */
private static final int CLASSIFIER = 3; 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. * Split the provided filename into 4 String parts.
* *
@ -65,10 +81,13 @@ public class RepositoryLayoutUtils
* @param filename the filename to split. * @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) * (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. * @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 ) ) if ( StringUtils.isBlank( filename ) )
{ {
@ -111,18 +130,33 @@ public class RepositoryLayoutUtils
} }
// Work on version string. // Work on version string.
int mode = ARTIFACTID;
if ( ( possibleArtifactId != null ) && filename.startsWith( possibleArtifactId ) ) if ( startsWith( filename, possibleArtifactId ) )
{ {
parts.artifactId = possibleArtifactId; parts.artifactId = possibleArtifactId;
filestring = filestring.substring( possibleArtifactId.length() + 1 ); 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, '-' ); String fileParts[] = StringUtils.split( filestring, '-' );
int versionStart = -1; int versionStart = -1;
int versionEnd = -1; int versionEnd = -1;
for ( int i = 0; i < fileParts.length; i++ ) for ( int i = 0; i < fileParts.length; i++ )
{ {
String part = fileParts[i]; String part = fileParts[i];
@ -139,7 +173,7 @@ public class RepositoryLayoutUtils
} }
} }
if ( versionStart < 0 ) if ( versionStart < 0 && parts.version == null )
{ {
// Assume rest of string is the version Id. // Assume rest of string is the version Id.
@ -156,7 +190,6 @@ 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++ ) for ( int i = 0; i < fileParts.length; i++ )
{ {
String part = fileParts[i]; String part = fileParts[i];
@ -192,4 +225,20 @@ public class RepositoryLayoutUtils
return parts; 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

@ -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, private void assertFilenameParts( FilenameParts actualParts, String artifactId, String version, String classifier,
String extension ) String extension )
{ {