From: Martin Stockhammer Date: Thu, 11 Jun 2020 14:13:53 +0000 (+0200) Subject: Moving request info to new API X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e38eebeaddda7917ea3e72045c8ea3a8361d8e17;p=archiva.git Moving request info to new API --- diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java index 52cfb2c22..e2249370b 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java @@ -32,17 +32,6 @@ import org.apache.archiva.repository.features.RepositoryFeature; public interface RepositoryRequestInfo { - /** - * Returns the artifact reference for a given path. - * Takes an incoming requested path (in "/" format) and gleans the layout - * and ArtifactReference appropriate for that content. - * - * @param requestPath The path of the web request - * @return The artifact reference - * @throws LayoutException - */ - ArtifactReference toArtifactReference( String requestPath ) throws LayoutException; - /** * Returns the item selector that matches the given path. @@ -115,7 +104,7 @@ public interface RepositoryRequestInfo /** * Returns the likely layout type for the given request. * Implementations may only check the path elements for this. To make sure, the path is valid, - * you should call {@link #toArtifactReference(String)} + * you should call {@link #toItemSelector(String)} * * @return */ diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfo.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfo.java index 3a6145567..2f9f95fe6 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfo.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfo.java @@ -18,7 +18,6 @@ package org.apache.archiva.repository.maven.content; * under the License. */ -import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.*; import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.PathParser; @@ -41,48 +40,6 @@ public class MavenRepositoryRequestInfo implements RepositoryRequestInfo this.repository = repository; } - /** - * Takes an incoming requested path (in "/" format) and gleans the layout - * and ArtifactReference appropriate for that content. - * - * @param requestedPath the relative path to the content. - * @return the ArtifactReference for the requestedPath. - * @throws LayoutException if the request path is not layout valid. - */ - public ArtifactReference toArtifactReference( String requestedPath ) - throws LayoutException - { - if ( StringUtils.isBlank( requestedPath ) ) - { - throw new LayoutException( "Blank request path is not a valid." ); - } - - String path = requestedPath; - while ( path.startsWith( "/" ) ) - { - path = path.substring( 1 ); - - // Only slash? that's bad, mmm-kay? - if ( "/".equals( path ) ) - { - throw new LayoutException( "Invalid request path: Slash only." ); - } - } - - if ( isDefault( path ) ) - { - return defaultPathParser.toArtifactReference( path ); - } - else if ( isLegacy( path ) ) - { - throw new LayoutException( "Legacy Maven1 repository not supported anymore." ); - } - else - { - throw new LayoutException( "Not a valid request path layout, too short." ); - } - } - @Override public ItemSelector toItemSelector( String requestPath ) throws LayoutException { @@ -176,7 +133,7 @@ public class MavenRepositoryRequestInfo implements RepositoryRequestInfo *

* NOTE: This does a cursory check on the count of path elements only. A result of * true from this method is not a guarantee that the path sections are valid and - * can be resolved to an artifact reference. use {@link #toArtifactReference(String)} + * can be resolved to an artifact reference. use {@link #toItemSelector(String)} * if you want a more complete analysis of the validity of the path. *

* @@ -231,7 +188,7 @@ public class MavenRepositoryRequestInfo implements RepositoryRequestInfo *

* NOTE: This does a cursory check on the count of path elements only. A result of * true from this method is not a guarantee that the path sections are valid and - * can be resolved to an artifact reference. use {@link #toArtifactReference(String)} + * can be resolved to an artifact reference. Use {@link #toItemSelector(String)} * if you want a more complete analysis of the validity of the path. *

* diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java index e1c61aad2..8c4023dc5 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/metadata/storage/Maven2RepositoryStorage.java @@ -40,6 +40,7 @@ import org.apache.archiva.proxy.model.ProxyConnector; import org.apache.archiva.proxy.model.RepositoryProxyHandler; import org.apache.archiva.repository.*; import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.ContentItem; import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.PathParser; import org.apache.archiva.repository.content.base.ArchivaItemSelector; @@ -786,15 +787,18 @@ public class Maven2RepositoryStorage } String filePath = getFilePath(requestPath, managedRepositoryContent.getRepository()); - - ArtifactReference artifactReference = null; - try { - artifactReference = pathParser.toArtifactReference(filePath); - } catch (LayoutException e) { + Artifact artifact; + try + { + ContentItem item = managedRepositoryContent.toItem( filePath ); + artifact = managedRepositoryContent.getLayout( BaseRepositoryContentLayout.class ).adaptItem( Artifact.class, item ); + } + catch ( LayoutException e ) + { return filePath; } - if (StringUtils.endsWith(artifactReference.getVersion(), VersionUtil.SNAPSHOT)) { + if (VersionUtil.isGenericSnapshot(artifact.getArtifactVersion())) { // read maven metadata to get last timestamp StorageAsset metadataDir = managedRepositoryContent.getRepository().getAsset(filePath).getParent(); if (!metadataDir.exists()) { @@ -826,10 +830,10 @@ public class Maven2RepositoryStorage // -> archiva-checksum-1.4-M4-20130425.081822-1.jar filePath = StringUtils.replace(filePath, // - artifactReference.getArtifactId() // - + "-" + artifactReference.getVersion(), // - artifactReference.getArtifactId() // - + "-" + StringUtils.remove(artifactReference.getVersion(), + artifact.getId() // + + "-" + artifact.getVersion().getId(), // + artifact.getId() // + + "-" + StringUtils.remove(artifact.getArtifactVersion(), "-" + VersionUtil.SNAPSHOT) // + "-" + timestamp // + "-" + buildNumber); diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/DefaultPathParserTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/DefaultPathParserTest.java index 8129144f3..26df1c85a 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/DefaultPathParserTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/DefaultPathParserTest.java @@ -18,10 +18,9 @@ package org.apache.archiva.repository.maven.content; * under the License. */ -import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.PathParser; -import org.apache.archiva.repository.maven.content.DefaultPathParser; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang3.StringUtils; import org.junit.Test; @@ -99,11 +98,12 @@ public class DefaultPathParserTest String groupId = "org.project"; String artifactId = "example-presentation"; String version = "3.2"; + String artifactVersion = "3.2"; String classifier = null; String type = "xml.zip"; String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -113,11 +113,12 @@ public class DefaultPathParserTest String groupId = "org.project"; String artifactId = "example-presentation"; String version = "3.2"; + String artifactVersion = "3.2"; String classifier = "extras"; String type = "xml.zip"; String path = "org/project/example-presentation/3.2/example-presentation-3.2-extras.xml.zip"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -127,11 +128,12 @@ public class DefaultPathParserTest String groupId = "org.project"; String artifactId = "example-distribution"; String version = "1.3"; + String artifactVersion = "1.3"; String classifier = null; String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2 String path = "org/project/example-distribution/1.3/example-distribution-1.3.tar.gz"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -141,11 +143,12 @@ public class DefaultPathParserTest String groupId = "org.project"; String artifactId = "example-distribution"; String version = "1.3"; + String artifactVersion = "1.3"; String classifier = "bin"; String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2 String path = "org/project/example-distribution/1.3/example-distribution-1.3-bin.tar.gz"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -161,11 +164,12 @@ public class DefaultPathParserTest String groupId = "ch.ethz.ganymed"; String artifactId = "ganymed-ssh2"; String version = "build210"; + String artifactVersion = "build210"; String classifier = null; String type = "jar"; String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -181,11 +185,12 @@ public class DefaultPathParserTest String groupId = "javax"; String artifactId = "comm"; String version = "3.0-u1"; + String artifactVersion = "3.0-u1"; String classifier = null; String type = "jar"; String path = "javax/comm/3.0-u1/comm-3.0-u1.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -222,6 +227,7 @@ public class DefaultPathParserTest String groupId = "javax.persistence"; String artifactId = "ejb"; String version = "3.0-public_review"; + String artifactVersion = "3.0-public_review"; String classifier = null; String type = "jar"; String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar"; @@ -233,7 +239,7 @@ public class DefaultPathParserTest * part of the version spec. */ - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -243,11 +249,12 @@ public class DefaultPathParserTest String groupId = "com.foo"; String artifactId = "foo-tool"; String version = "1.0"; + String artifactVersion = "1.0"; String classifier = null; String type = "jar"; String path = "com/foo/foo-tool/1.0/foo-tool-1.0.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -257,11 +264,12 @@ public class DefaultPathParserTest String groupId = "commons-lang"; String artifactId = "commons-lang"; String version = "2.1"; + String artifactVersion = "2.1"; String classifier = null; String type = "jar"; String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -271,11 +279,12 @@ public class DefaultPathParserTest String groupId = "commons-lang"; String artifactId = "commons-lang"; String version = "2.1"; + String artifactVersion = "2.1"; String classifier = null; String type = "jar"; String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -288,11 +297,12 @@ public class DefaultPathParserTest String groupId = "test.maven-arch"; String artifactId = "test-arch"; String version = "2.0.3-SNAPSHOT"; + String artifactVersion = "2.0.3-SNAPSHOT"; String classifier = null; String type = "pom"; String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -305,11 +315,12 @@ public class DefaultPathParserTest String groupId = "com.company.department"; String artifactId = "com.company.department"; String version = "0.2"; + String artifactVersion = "0.2"; String classifier = null; String type = "pom"; String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.pom"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -322,12 +333,13 @@ public class DefaultPathParserTest String groupId = "com.company.department"; String artifactId = "com.company.department.project"; String version = "0.3"; + String artifactVersion = "0.3"; String classifier = null; String type = "pom"; String path = "com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -342,11 +354,12 @@ public class DefaultPathParserTest String groupId = "com.foo.lib"; String artifactId = "foo-lib"; String version = "2.1-alpha-1"; + String artifactVersion = "2.1-alpha-1"; String classifier = "sources"; String type = "java-source"; // oddball type-spec (should result in jar extension) String path = "com/foo/lib/foo-lib/2.1-alpha-1/foo-lib-2.1-alpha-1-sources.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -360,13 +373,14 @@ public class DefaultPathParserTest { String groupId = "org.apache.archiva.test"; String artifactId = "redonkulous"; - String version = "3.1-beta-1-20050831.101112-42"; + String version = "3.1-beta-1-SNAPSHOT"; + String artifactVersion = "3.1-beta-1-20050831.101112-42"; String classifier = null; String type = "jar"; String path = "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -380,12 +394,13 @@ public class DefaultPathParserTest { String groupId = "a.group.id"; String artifactId = "artifact-id"; - String version = "1.0-abc-1.1-20080221.062205-9"; + String version = "1.0-abc-1.1-SNAPSHOT"; + String artifactVersion = "1.0-abc-1.1-20080221.062205-9"; String classifier = null; String type = "pom"; String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -409,12 +424,13 @@ public class DefaultPathParserTest { String groupId = "a.group.id"; String artifactId = "artifact-id"; - String version = "1.0-20070219.171202-34"; + String version = "1.0-SNAPSHOT"; + String artifactVersion = "1.0-20070219.171202-34"; String classifier = "test-sources"; String type = "jar"; String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -428,11 +444,12 @@ public class DefaultPathParserTest String groupId = "maven"; String artifactId = "maven-test-plugin"; String version = "1.8.2"; + String artifactVersion = "1.8.2"; String classifier = null; String type = "pom"; String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -446,11 +463,12 @@ public class DefaultPathParserTest String groupId = "maven"; String artifactId = "maven-test-plugin"; String version = "1.8.2"; + String artifactVersion = "1.8.2"; String classifier = null; String type = "maven-plugin"; String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } /** @@ -463,11 +481,12 @@ public class DefaultPathParserTest String groupId = "org.codehaus.mojo"; String artifactId = "cobertura-maven-plugin"; String version = "2.1"; + String artifactVersion = "2.1"; String classifier = null; String type = "maven-plugin"; String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar"; - assertLayout( path, groupId, artifactId, version, classifier, type ); + assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type ); } @Test @@ -475,7 +494,7 @@ public class DefaultPathParserTest { try { - parser.toArtifactReference( "" ); + parser.toItemSelector( "" ); fail( "Should have failed due to empty path." ); } catch ( LayoutException e ) @@ -489,7 +508,7 @@ public class DefaultPathParserTest { try { - parser.toArtifactReference( null ); + parser.toItemSelector( null ); fail( "Should have failed due to null path." ); } catch ( LayoutException e ) @@ -503,7 +522,7 @@ public class DefaultPathParserTest { try { - parser.toArtifactReference( "" ); + parser.toItemSelector( "" ); fail( "Should have failed due to empty path." ); } catch ( LayoutException e ) @@ -517,7 +536,7 @@ public class DefaultPathParserTest { try { - parser.toArtifactReference( null ); + parser.toItemSelector( null ); fail( "Should have failed due to null path." ); } catch ( LayoutException e ) @@ -529,25 +548,26 @@ public class DefaultPathParserTest /** * Perform a path to artifact reference lookup, and verify the results. */ - private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, + private void assertLayout( String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type ) throws LayoutException { // Path to Artifact Reference. - ArtifactReference testReference = parser.toArtifactReference( path ); - assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); + ItemSelector testReference = parser.toItemSelector( path ); + assertArtifactReference( testReference, groupId, artifactId, version, artifactVersion, classifier, type ); } - private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, - String version, String classifier, String type ) + private void assertArtifactReference( ItemSelector actualReference, String groupId, String artifactId, + String version, String artifactVersion, String classifier, String type ) { String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; assertNotNull( expectedId + " - Should not be null.", actualReference ); - assertEquals( expectedId + " - Group ID", groupId, actualReference.getGroupId() ); + assertEquals( expectedId + " - Group ID", groupId, actualReference.getNamespace() ); assertEquals( expectedId + " - Artifact ID", artifactId, actualReference.getArtifactId() ); + assertEquals( expectedId + " - Artifact Version", artifactVersion, actualReference.getArtifactVersion( ) ); if ( StringUtils.isNotBlank( classifier ) ) { assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() ); @@ -560,7 +580,7 @@ public class DefaultPathParserTest { try { - parser.toArtifactReference( path ); + parser.toItemSelector( path ); fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfoTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfoTest.java index 7317e57f3..e7657af6d 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfoTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/MavenRepositoryRequestInfoTest.java @@ -24,6 +24,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.FileType; import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.LayoutException; @@ -153,7 +154,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210", - null, "jar" ); + "build210", null, "jar" ); } @Test @@ -161,21 +162,21 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", - "ganymed-ssh2", "build210", null, "jar" ); + "ganymed-ssh2", "build210", "build210", null, "jar" ); } @Test( expected = LayoutException.class ) public void testValidLegacyJavaxComm() throws Exception { - assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" ); + assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", "3.0-u1", null, "jar" ); } @Test public void testValidDefaultJavaxComm() throws Exception { - assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" ); + assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", "3.0-u1", null, "jar" ); } @Test( expected = LayoutException.class ) @@ -183,7 +184,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb", - "3.0-public_review", null, "jar" ); + "3.0-public_review", "3.0-public_review", null, "jar" ); } @Test @@ -191,21 +192,21 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb", - "3.0-public_review", null, "jar" ); + "3.0-public_review", "3.0-public_review",null, "jar" ); } @Test( expected = LayoutException.class ) public void testValidLegacyMavenTestPlugin() throws Exception { - assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" ); + assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", "1.8.2",null, "jar" ); } @Test public void testValidDefaultMavenTestPlugin() throws Exception { - assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", "1.8.2", + assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", "1.8.2", "1.8.2", null, "pom" ); } @@ -213,7 +214,7 @@ public class MavenRepositoryRequestInfoTest public void testValidLegacyCommonsLangJavadoc() throws Exception { - assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1", + assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1", "2.1", "javadoc", "javadoc" ); } @@ -222,16 +223,16 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", - "2.1", "javadoc", "javadoc" ); + "2.1", "2.1","javadoc", "javadoc" ); } @Test( expected = LayoutException.class ) public void testValidLegacyDerbyPom() throws Exception { - assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" ); + assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", "10.2.2.0",null, "pom" ); // Starting slash should not prevent detection. - assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, + assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", "10.2.2.0",null, "pom" ); } @@ -239,7 +240,7 @@ public class MavenRepositoryRequestInfoTest public void testValidDefaultDerbyPom() throws Exception { - assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", + assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", "10.2.2.0", null, "pom" ); } @@ -248,7 +249,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs", - "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" ); + "geronimo-ejb_2.1_spec", "1.0.1", "1.0.1",null, "jar" ); } @Test @@ -256,7 +257,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar", - "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" ); + "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", "1.0.1",null, "jar" ); } @Test( expected = LayoutException.class ) @@ -264,7 +265,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients", - "0.9.1-SNAPSHOT", null, "pom" ); + "0.9.1-SNAPSHOT", "0.9.1-SNAPSHOT",null, "pom" ); } @Test @@ -272,7 +273,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom", - "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" ); + "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", "0.9.1-SNAPSHOT",null, "pom" ); } @Test( expected = LayoutException.class ) @@ -280,7 +281,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch", - "2.0.3-SNAPSHOT", null, "pom" ); + "2.0.3-SNAPSHOT", "2.0.3-SNAPSHOT",null, "pom" ); } @Test @@ -288,7 +289,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", - "test-arch", "2.0.3-SNAPSHOT", null, "pom" ); + "test-arch", "2.0.3-SNAPSHOT", "2.0.3-SNAPSHOT",null, "pom" ); } @Test( expected = LayoutException.class ) @@ -296,7 +297,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department", - "com.company.department.project", "0.2", null, "pom" ); + "com.company.department.project", "0.2", "0.2",null, "pom" ); } @Test @@ -304,7 +305,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom", - "com.company.department", "com.company.department.project", "0.2", null, "pom" ); + "com.company.department", "com.company.department.project", "0.2", "0.2",null, "pom" ); } @Test( expected = LayoutException.class ) @@ -312,7 +313,7 @@ public class MavenRepositoryRequestInfoTest throws Exception { assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar", - "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" ); + "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", "3.1-beta-1-20050831.101112-42", null, "jar" ); } @Test @@ -321,7 +322,7 @@ public class MavenRepositoryRequestInfoTest { assertValid( "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar", - "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" ); + "org.apache.archiva.test", "redonkulous", "3.1-beta-1-SNAPSHOT", "3.1-beta-1-20050831.101112-42", null, "jar" ); } @Test @@ -525,7 +526,7 @@ public class MavenRepositoryRequestInfoTest } - private void assertValid( String path, String groupId, String artifactId, String version, String classifier, + private void assertValid( String path, String groupId, String artifactId, String version, String artifactVersion, String classifier, String type ) throws Exception { @@ -533,12 +534,13 @@ public class MavenRepositoryRequestInfoTest "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + ( classifier != null ? classifier + ":" : "" ) + type; - ArtifactReference reference = repoRequest.toArtifactReference( path ); + ItemSelector reference = repoRequest.toItemSelector( path ); assertNotNull( expectedId + " - Should not be null.", reference ); - assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() ); + assertEquals( expectedId + " - Group ID", groupId, reference.getNamespace() ); assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() ); + assertEquals( expectedId + " - Artifact Version", artifactVersion, reference.getArtifactVersion( ) ); if ( StringUtils.isNotBlank( classifier ) ) { assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() ); @@ -551,7 +553,7 @@ public class MavenRepositoryRequestInfoTest { try { - repoRequest.toArtifactReference( path ); + repoRequest.toItemSelector( path ); fail( "Expected a LayoutException on an invalid path [" + path + "]" ); } catch ( LayoutException e ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index 993935519..54bd31501 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -364,7 +364,7 @@ public class ArchivaDavResourceFactoryTest repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( "legacy" ); - expect( repoRequest.toArtifactReference( + expect( repoRequest.toItemSelector( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" @@ -444,7 +444,7 @@ public class ArchivaDavResourceFactoryTest repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( "legacy" ); - expect( repoRequest.toArtifactReference( + expect( repoRequest.toItemSelector( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" @@ -528,7 +528,7 @@ public class ArchivaDavResourceFactoryTest repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( "legacy" ).times( 2 ); - expect( repoRequest.toArtifactReference( + expect( repoRequest.toItemSelector( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 ); expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java index 50071593a..6b135fda2 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java @@ -20,6 +20,8 @@ package org.apache.archiva.metadata.repository.storage; */ import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.repository.LayoutException; +import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.storage.StorageAsset; import java.nio.file.Path; @@ -40,6 +42,7 @@ public interface RepositoryPathTranslator StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion ); + ArtifactMetadata getArtifactForPath( String repoId, String relativePath ); ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,