Moving request info to new API

This commit is contained in:
Martin Stockhammer 2020-06-11 16:13:53 +02:00
parent 46fd585f40
commit e38eebeadd
7 changed files with 108 additions and 133 deletions

View File

@ -32,17 +32,6 @@ import org.apache.archiva.repository.features.RepositoryFeature;
public interface RepositoryRequestInfo 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. * 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. * 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, * 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 * @return
*/ */

View File

@ -18,7 +18,6 @@ package org.apache.archiva.repository.maven.content;
* under the License. * under the License.
*/ */
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.*; import org.apache.archiva.repository.*;
import org.apache.archiva.repository.content.ItemSelector; import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.PathParser; import org.apache.archiva.repository.content.PathParser;
@ -41,48 +40,6 @@ public class MavenRepositoryRequestInfo implements RepositoryRequestInfo
this.repository = repository; 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 @Override
public ItemSelector toItemSelector( String requestPath ) throws LayoutException public ItemSelector toItemSelector( String requestPath ) throws LayoutException
{ {
@ -176,7 +133,7 @@ public class MavenRepositoryRequestInfo implements RepositoryRequestInfo
* <p> * <p>
* NOTE: This does a cursory check on the count of path elements only. A result of * 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 * 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. * if you want a more complete analysis of the validity of the path.
* </p> * </p>
* *
@ -231,7 +188,7 @@ public class MavenRepositoryRequestInfo implements RepositoryRequestInfo
* <p> * <p>
* NOTE: This does a cursory check on the count of path elements only. A result of * 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 * 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. * if you want a more complete analysis of the validity of the path.
* </p> * </p>
* *

View File

@ -40,6 +40,7 @@ import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyHandler; import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*; import org.apache.archiva.repository.*;
import org.apache.archiva.repository.content.Artifact; 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.ItemSelector;
import org.apache.archiva.repository.content.PathParser; import org.apache.archiva.repository.content.PathParser;
import org.apache.archiva.repository.content.base.ArchivaItemSelector; import org.apache.archiva.repository.content.base.ArchivaItemSelector;
@ -786,15 +787,18 @@ public class Maven2RepositoryStorage
} }
String filePath = getFilePath(requestPath, managedRepositoryContent.getRepository()); String filePath = getFilePath(requestPath, managedRepositoryContent.getRepository());
Artifact artifact;
ArtifactReference artifactReference = null; try
try { {
artifactReference = pathParser.toArtifactReference(filePath); ContentItem item = managedRepositoryContent.toItem( filePath );
} catch (LayoutException e) { artifact = managedRepositoryContent.getLayout( BaseRepositoryContentLayout.class ).adaptItem( Artifact.class, item );
}
catch ( LayoutException e )
{
return filePath; return filePath;
} }
if (StringUtils.endsWith(artifactReference.getVersion(), VersionUtil.SNAPSHOT)) { if (VersionUtil.isGenericSnapshot(artifact.getArtifactVersion())) {
// read maven metadata to get last timestamp // read maven metadata to get last timestamp
StorageAsset metadataDir = managedRepositoryContent.getRepository().getAsset(filePath).getParent(); StorageAsset metadataDir = managedRepositoryContent.getRepository().getAsset(filePath).getParent();
if (!metadataDir.exists()) { if (!metadataDir.exists()) {
@ -826,10 +830,10 @@ public class Maven2RepositoryStorage
// -> archiva-checksum-1.4-M4-20130425.081822-1.jar // -> archiva-checksum-1.4-M4-20130425.081822-1.jar
filePath = StringUtils.replace(filePath, // filePath = StringUtils.replace(filePath, //
artifactReference.getArtifactId() // artifact.getId() //
+ "-" + artifactReference.getVersion(), // + "-" + artifact.getVersion().getId(), //
artifactReference.getArtifactId() // artifact.getId() //
+ "-" + StringUtils.remove(artifactReference.getVersion(), + "-" + StringUtils.remove(artifact.getArtifactVersion(),
"-" + VersionUtil.SNAPSHOT) // "-" + VersionUtil.SNAPSHOT) //
+ "-" + timestamp // + "-" + timestamp //
+ "-" + buildNumber); + "-" + buildNumber);

View File

@ -18,10 +18,9 @@ package org.apache.archiva.repository.maven.content;
* under the License. * under the License.
*/ */
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.LayoutException; 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.content.PathParser;
import org.apache.archiva.repository.maven.content.DefaultPathParser;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Test; import org.junit.Test;
@ -99,11 +98,12 @@ public class DefaultPathParserTest
String groupId = "org.project"; String groupId = "org.project";
String artifactId = "example-presentation"; String artifactId = "example-presentation";
String version = "3.2"; String version = "3.2";
String artifactVersion = "3.2";
String classifier = null; String classifier = null;
String type = "xml.zip"; String type = "xml.zip";
String path = "org/project/example-presentation/3.2/example-presentation-3.2.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 @Test
@ -113,11 +113,12 @@ public class DefaultPathParserTest
String groupId = "org.project"; String groupId = "org.project";
String artifactId = "example-presentation"; String artifactId = "example-presentation";
String version = "3.2"; String version = "3.2";
String artifactVersion = "3.2";
String classifier = "extras"; String classifier = "extras";
String type = "xml.zip"; String type = "xml.zip";
String path = "org/project/example-presentation/3.2/example-presentation-3.2-extras.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 @Test
@ -127,11 +128,12 @@ public class DefaultPathParserTest
String groupId = "org.project"; String groupId = "org.project";
String artifactId = "example-distribution"; String artifactId = "example-distribution";
String version = "1.3"; String version = "1.3";
String artifactVersion = "1.3";
String classifier = null; String classifier = null;
String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2 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"; 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 @Test
@ -141,11 +143,12 @@ public class DefaultPathParserTest
String groupId = "org.project"; String groupId = "org.project";
String artifactId = "example-distribution"; String artifactId = "example-distribution";
String version = "1.3"; String version = "1.3";
String artifactVersion = "1.3";
String classifier = "bin"; String classifier = "bin";
String type = "tar.gz"; // no longer using distribution-tgz / distribution-zip in maven 2 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"; 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 groupId = "ch.ethz.ganymed";
String artifactId = "ganymed-ssh2"; String artifactId = "ganymed-ssh2";
String version = "build210"; String version = "build210";
String artifactVersion = "build210";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.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 groupId = "javax";
String artifactId = "comm"; String artifactId = "comm";
String version = "3.0-u1"; String version = "3.0-u1";
String artifactVersion = "3.0-u1";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "javax/comm/3.0-u1/comm-3.0-u1.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 groupId = "javax.persistence";
String artifactId = "ejb"; String artifactId = "ejb";
String version = "3.0-public_review"; String version = "3.0-public_review";
String artifactVersion = "3.0-public_review";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.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. * part of the version spec.
*/ */
assertLayout( path, groupId, artifactId, version, classifier, type ); assertLayout( path, groupId, artifactId, version, artifactVersion, classifier, type );
} }
@Test @Test
@ -243,11 +249,12 @@ public class DefaultPathParserTest
String groupId = "com.foo"; String groupId = "com.foo";
String artifactId = "foo-tool"; String artifactId = "foo-tool";
String version = "1.0"; String version = "1.0";
String artifactVersion = "1.0";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "com/foo/foo-tool/1.0/foo-tool-1.0.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 @Test
@ -257,11 +264,12 @@ public class DefaultPathParserTest
String groupId = "commons-lang"; String groupId = "commons-lang";
String artifactId = "commons-lang"; String artifactId = "commons-lang";
String version = "2.1"; String version = "2.1";
String artifactVersion = "2.1";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "commons-lang/commons-lang/2.1/commons-lang-2.1.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 @Test
@ -271,11 +279,12 @@ public class DefaultPathParserTest
String groupId = "commons-lang"; String groupId = "commons-lang";
String artifactId = "commons-lang"; String artifactId = "commons-lang";
String version = "2.1"; String version = "2.1";
String artifactVersion = "2.1";
String classifier = null; String classifier = null;
String type = "jar"; String type = "jar";
String path = "commons-lang\\commons-lang/2.1\\commons-lang-2.1.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 groupId = "test.maven-arch";
String artifactId = "test-arch"; String artifactId = "test-arch";
String version = "2.0.3-SNAPSHOT"; String version = "2.0.3-SNAPSHOT";
String artifactVersion = "2.0.3-SNAPSHOT";
String classifier = null; String classifier = null;
String type = "pom"; String type = "pom";
String path = "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.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 groupId = "com.company.department";
String artifactId = "com.company.department"; String artifactId = "com.company.department";
String version = "0.2"; String version = "0.2";
String artifactVersion = "0.2";
String classifier = null; String classifier = null;
String type = "pom"; String type = "pom";
String path = "com/company/department/com.company.department/0.2/com.company.department-0.2.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 groupId = "com.company.department";
String artifactId = "com.company.department.project"; String artifactId = "com.company.department.project";
String version = "0.3"; String version = "0.3";
String artifactVersion = "0.3";
String classifier = null; String classifier = null;
String type = "pom"; String type = "pom";
String path = String path =
"com/company/department/com.company.department.project/0.3/com.company.department.project-0.3.pom"; "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 groupId = "com.foo.lib";
String artifactId = "foo-lib"; String artifactId = "foo-lib";
String version = "2.1-alpha-1"; String version = "2.1-alpha-1";
String artifactVersion = "2.1-alpha-1";
String classifier = "sources"; String classifier = "sources";
String type = "java-source"; // oddball type-spec (should result in jar extension) 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"; 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 groupId = "org.apache.archiva.test";
String artifactId = "redonkulous"; 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 classifier = null;
String type = "jar"; String type = "jar";
String path = String path =
"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-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 groupId = "a.group.id";
String artifactId = "artifact-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 classifier = null;
String type = "pom"; 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"; 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 groupId = "a.group.id";
String artifactId = "artifact-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 classifier = "test-sources";
String type = "jar"; String type = "jar";
String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.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 groupId = "maven";
String artifactId = "maven-test-plugin"; String artifactId = "maven-test-plugin";
String version = "1.8.2"; String version = "1.8.2";
String artifactVersion = "1.8.2";
String classifier = null; String classifier = null;
String type = "pom"; String type = "pom";
String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.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 groupId = "maven";
String artifactId = "maven-test-plugin"; String artifactId = "maven-test-plugin";
String version = "1.8.2"; String version = "1.8.2";
String artifactVersion = "1.8.2";
String classifier = null; String classifier = null;
String type = "maven-plugin"; String type = "maven-plugin";
String path = "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.jar"; 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 groupId = "org.codehaus.mojo";
String artifactId = "cobertura-maven-plugin"; String artifactId = "cobertura-maven-plugin";
String version = "2.1"; String version = "2.1";
String artifactVersion = "2.1";
String classifier = null; String classifier = null;
String type = "maven-plugin"; String type = "maven-plugin";
String path = "org/codehaus/mojo/cobertura-maven-plugin/2.1/cobertura-maven-plugin-2.1.jar"; 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 @Test
@ -475,7 +494,7 @@ public class DefaultPathParserTest
{ {
try try
{ {
parser.toArtifactReference( "" ); parser.toItemSelector( "" );
fail( "Should have failed due to empty path." ); fail( "Should have failed due to empty path." );
} }
catch ( LayoutException e ) catch ( LayoutException e )
@ -489,7 +508,7 @@ public class DefaultPathParserTest
{ {
try try
{ {
parser.toArtifactReference( null ); parser.toItemSelector( null );
fail( "Should have failed due to null path." ); fail( "Should have failed due to null path." );
} }
catch ( LayoutException e ) catch ( LayoutException e )
@ -503,7 +522,7 @@ public class DefaultPathParserTest
{ {
try try
{ {
parser.toArtifactReference( "" ); parser.toItemSelector( "" );
fail( "Should have failed due to empty path." ); fail( "Should have failed due to empty path." );
} }
catch ( LayoutException e ) catch ( LayoutException e )
@ -517,7 +536,7 @@ public class DefaultPathParserTest
{ {
try try
{ {
parser.toArtifactReference( null ); parser.toItemSelector( null );
fail( "Should have failed due to null path." ); fail( "Should have failed due to null path." );
} }
catch ( LayoutException e ) catch ( LayoutException e )
@ -529,25 +548,26 @@ public class DefaultPathParserTest
/** /**
* Perform a path to artifact reference lookup, and verify the results. * 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 ) String type )
throws LayoutException throws LayoutException
{ {
// Path to Artifact Reference. // Path to Artifact Reference.
ArtifactReference testReference = parser.toArtifactReference( path ); ItemSelector testReference = parser.toItemSelector( path );
assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); assertArtifactReference( testReference, groupId, artifactId, version, artifactVersion, classifier, type );
} }
private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, private void assertArtifactReference( ItemSelector actualReference, String groupId, String artifactId,
String version, String classifier, String type ) String version, String artifactVersion, String classifier, String type )
{ {
String expectedId = String expectedId =
"ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type;
assertNotNull( expectedId + " - Should not be null.", actualReference ); 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 ID", artifactId, actualReference.getArtifactId() );
assertEquals( expectedId + " - Artifact Version", artifactVersion, actualReference.getArtifactVersion( ) );
if ( StringUtils.isNotBlank( classifier ) ) if ( StringUtils.isNotBlank( classifier ) )
{ {
assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() ); assertEquals( expectedId + " - Classifier", classifier, actualReference.getClassifier() );
@ -560,7 +580,7 @@ public class DefaultPathParserTest
{ {
try try
{ {
parser.toArtifactReference( path ); parser.toItemSelector( path );
fail( fail(
"Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
} }

View File

@ -24,6 +24,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.FileType; import org.apache.archiva.configuration.FileType;
import org.apache.archiva.configuration.FileTypes; import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.repository.ManagedRepositoryContent; 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.repository.maven.metadata.storage.ArtifactMappingProvider;
import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.LayoutException;
@ -153,7 +154,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210", assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
null, "jar" ); "build210", null, "jar" );
} }
@Test @Test
@ -161,21 +162,21 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", 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 ) @Test( expected = LayoutException.class )
public void testValidLegacyJavaxComm() public void testValidLegacyJavaxComm()
throws Exception 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 @Test
public void testValidDefaultJavaxComm() public void testValidDefaultJavaxComm()
throws Exception 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 ) @Test( expected = LayoutException.class )
@ -183,7 +184,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb", 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 @Test
@ -191,21 +192,21 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb", 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 ) @Test( expected = LayoutException.class )
public void testValidLegacyMavenTestPlugin() public void testValidLegacyMavenTestPlugin()
throws Exception 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 @Test
public void testValidDefaultMavenTestPlugin() public void testValidDefaultMavenTestPlugin()
throws Exception 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" ); null, "pom" );
} }
@ -213,7 +214,7 @@ public class MavenRepositoryRequestInfoTest
public void testValidLegacyCommonsLangJavadoc() public void testValidLegacyCommonsLangJavadoc()
throws Exception 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" ); "javadoc", "javadoc" );
} }
@ -222,16 +223,16 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", 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 ) @Test( expected = LayoutException.class )
public void testValidLegacyDerbyPom() public void testValidLegacyDerbyPom()
throws Exception 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. // 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" ); "pom" );
} }
@ -239,7 +240,7 @@ public class MavenRepositoryRequestInfoTest
public void testValidDefaultDerbyPom() public void testValidDefaultDerbyPom()
throws Exception 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" ); null, "pom" );
} }
@ -248,7 +249,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs", 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 @Test
@ -256,7 +257,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar", 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 ) @Test( expected = LayoutException.class )
@ -264,7 +265,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients", 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 @Test
@ -272,7 +273,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom", 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 ) @Test( expected = LayoutException.class )
@ -280,7 +281,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch", 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 @Test
@ -288,7 +289,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", 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 ) @Test( expected = LayoutException.class )
@ -296,7 +297,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department", 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 @Test
@ -304,7 +305,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom", 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 ) @Test( expected = LayoutException.class )
@ -312,7 +313,7 @@ public class MavenRepositoryRequestInfoTest
throws Exception throws Exception
{ {
assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar", 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 @Test
@ -321,7 +322,7 @@ public class MavenRepositoryRequestInfoTest
{ {
assertValid( 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-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 @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 ) String type )
throws Exception throws Exception
{ {
@ -533,12 +534,13 @@ public class MavenRepositoryRequestInfoTest
"ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + ( classifier != null ? "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + ( classifier != null ?
classifier + ":" : "" ) + type; classifier + ":" : "" ) + type;
ArtifactReference reference = repoRequest.toArtifactReference( path ); ItemSelector reference = repoRequest.toItemSelector( path );
assertNotNull( expectedId + " - Should not be null.", reference ); 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 ID", artifactId, reference.getArtifactId() );
assertEquals( expectedId + " - Artifact Version", artifactVersion, reference.getArtifactVersion( ) );
if ( StringUtils.isNotBlank( classifier ) ) if ( StringUtils.isNotBlank( classifier ) )
{ {
assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() ); assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
@ -551,7 +553,7 @@ public class MavenRepositoryRequestInfoTest
{ {
try try
{ {
repoRequest.toArtifactReference( path ); repoRequest.toItemSelector( path );
fail( "Expected a LayoutException on an invalid path [" + path + "]" ); fail( "Expected a LayoutException on an invalid path [" + path + "]" );
} }
catch ( LayoutException e ) catch ( LayoutException e )

View File

@ -364,7 +364,7 @@ public class ArchivaDavResourceFactoryTest
repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
"legacy" ); "legacy" );
expect( repoRequest.toArtifactReference( expect( repoRequest.toItemSelector(
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); "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" 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( repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
"legacy" ); "legacy" );
expect( repoRequest.toArtifactReference( expect( repoRequest.toItemSelector(
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ); "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" 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( repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
"legacy" ).times( 2 ); "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 ); "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" expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"

View File

@ -20,6 +20,8 @@ package org.apache.archiva.metadata.repository.storage;
*/ */
import org.apache.archiva.metadata.model.ArtifactMetadata; 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 org.apache.archiva.repository.storage.StorageAsset;
import java.nio.file.Path; import java.nio.file.Path;
@ -40,6 +42,7 @@ public interface RepositoryPathTranslator
StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion ); StorageAsset toFile( StorageAsset basedir, String namespace, String projectId, String projectVersion );
ArtifactMetadata getArtifactForPath( String repoId, String relativePath ); ArtifactMetadata getArtifactForPath( String repoId, String relativePath );
ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion, ArtifactMetadata getArtifactFromId( String repoId, String namespace, String projectId, String projectVersion,