diff options
author | Joakim Erdfelt <joakime@apache.org> | 2007-10-04 23:03:37 +0000 |
---|---|---|
committer | Joakim Erdfelt <joakime@apache.org> | 2007-10-04 23:03:37 +0000 |
commit | 13e64dfc3dfcae4bb81b9ef3a3f3bb98bddb86db (patch) | |
tree | e9bda3d9783b9aa3fb2da88476204858d0e885ef /archiva-base/archiva-repository-layer | |
parent | 1ad4bcc6376e75ef9300781a82716fb9b43288d4 (diff) | |
download | archiva-13e64dfc3dfcae4bb81b9ef3a3f3bb98bddb86db.tar.gz archiva-13e64dfc3dfcae4bb81b9ef3a3f3bb98bddb86db.zip |
[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
Diffstat (limited to 'archiva-base/archiva-repository-layer')
3 files changed, 86 insertions, 27 deletions
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java index 311a54704..fae12c68d 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/DefaultBidirectionalRepositoryLayout.java @@ -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 */ diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java index e2b82f36a..00070c661 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtils.java @@ -52,23 +52,42 @@ 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 ) == '-' ); + } } diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java index f3cba9b3f..4059f87a1 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/RepositoryLayoutUtilsTest.java @@ -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 ) { |