From 678173ca42972b644f69399ebead4eba3c03d0ac Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Mon, 10 Dec 2007 14:58:14 +0000 Subject: [PATCH] MRM-594 convert PathParsers to a plexus component, so that it can access the archivaConfiguration and read custom legacyPath 2 artifact references. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@602922 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractDefaultRepositoryContent.java | 19 ++++-- .../AbstractLegacyRepositoryContent.java | 9 ++- .../content/ArtifactExtensionMapping.java | 6 +- .../repository/content/DefaultPathParser.java | 25 +++---- .../repository/content/LegacyPathParser.java | 49 ++++++++++--- .../repository/content/PathParser.java | 19 ++++++ .../repository/content/RepositoryRequest.java | 68 +++++++++++-------- ...stractLegacyRepositoryContentTestCase.java | 6 +- .../content/DefaultPathParserTest.java | 50 +++++++------- .../content/LegacyPathParserTest.java | 46 +++++++++++-- .../content/RepositoryRequestTest.java | 50 +++++++------- 11 files changed, 227 insertions(+), 120 deletions(-) create mode 100644 archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java index a1b4d78e7..920cf8ed5 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractDefaultRepositoryContent.java @@ -28,7 +28,7 @@ import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.layout.LayoutException; /** - * AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout. + * AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout. * * @author Joakim Erdfelt * @version $Id$ @@ -43,27 +43,32 @@ public abstract class AbstractDefaultRepositoryContent protected static final char ARTIFACT_SEPARATOR = '-'; + /** + * @plexus.requirement role-hint="default" + */ + private PathParser defaultPathParser; + public ArtifactReference toArtifactReference( String path ) throws LayoutException { - return DefaultPathParser.toArtifactReference( path ); + return defaultPathParser.toArtifactReference( path ); } public String toMetadataPath( ProjectReference reference ) { StringBuffer path = new StringBuffer(); - + path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); path.append( MAVEN_METADATA ); - + return path.toString(); } public String toMetadataPath( VersionedReference reference ) { StringBuffer path = new StringBuffer(); - + path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR ); path.append( reference.getArtifactId() ).append( PATH_SEPARATOR ); if ( reference.getVersion() != null ) @@ -72,10 +77,10 @@ public abstract class AbstractDefaultRepositoryContent path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR ); } path.append( MAVEN_METADATA ); - + return path.toString(); } - + public String toPath( ArchivaArtifact reference ) { if ( reference == null ) diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java index 1a1d5b70d..018d86e4f 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java @@ -28,7 +28,7 @@ import java.util.HashMap; import java.util.Map; /** - * AbstractLegacyRepositoryContent + * AbstractLegacyRepositoryContent * * @author Joakim Erdfelt * @version $Id$ @@ -49,10 +49,15 @@ public abstract class AbstractLegacyRepositoryContent typeToDirectoryMap.put( "javadoc", "javadoc.jar" ); } + /** + * @plexus.requirement role-hint="legacy" + */ + private PathParser legacyPathParser; + public ArtifactReference toArtifactReference( String path ) throws LayoutException { - return LegacyPathParser.toArtifactReference( path ); + return legacyPathParser.toArtifactReference( path ); } public String toPath( ArchivaArtifact reference ) diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java index c509e51b6..9edf48891 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java @@ -37,7 +37,7 @@ public class ArtifactExtensionMapping public static final String MAVEN_ARCHETYPE = "maven-archetype"; public static final String MAVEN_PLUGIN = "maven-plugin"; - + private static final Map typeToExtensionMap; private static final Pattern mavenPluginPattern = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" ); @@ -115,10 +115,10 @@ public class ArtifactExtensionMapping return normalizedName.substring( idx + 1 ); } } - + /** * Determine if a given artifact Id conforms to the naming scheme for a maven plugin. - * + * * @param artifactId the artifactId to test. * @return true if this artifactId conforms to the naming scheme for a maven plugin. */ diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java index 6df3aafdc..88d6dd244 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java @@ -25,25 +25,22 @@ import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.layout.LayoutException; /** - * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference. + * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference. * * @author Joakim Erdfelt * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.repository.content.DefaultPathParser" + * + * @plexus.component role="org.apache.maven.archiva.repository.content.PathParser" role-hint="default" */ -public class DefaultPathParser +public class DefaultPathParser implements PathParser { private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: "; /** - * Convert a path to an ArtifactReference. - * - * @param path - * @return - * @throws LayoutException + * {@inheritDoc} + * @see org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String) */ - protected static ArtifactReference toArtifactReference( String path ) + public ArtifactReference toArtifactReference( String path ) throws LayoutException { if ( StringUtils.isBlank( path ) ) @@ -148,7 +145,7 @@ public class DefaultPathParser case '-': // Definately a classifier. artifact.setClassifier( parser.remaining() ); - + // Set the type. artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) ); break; @@ -162,9 +159,9 @@ public class DefaultPathParser artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) ); break; } - + // Special case for maven plugins - if ( StringUtils.equals( "jar", artifact.getType() ) && + if ( StringUtils.equals( "jar", artifact.getType() ) && ArtifactExtensionMapping.isMavenPlugin( artifact.getArtifactId() ) ) { artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); @@ -201,5 +198,5 @@ public class DefaultPathParser return artifact; } - + } diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java index 5c8746501..aceef26c1 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java @@ -19,23 +19,54 @@ package org.apache.maven.archiva.repository.content; * under the License. */ +import java.util.Collection; +import java.util.Iterator; +import java.util.Properties; + import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.LegacyArtifactPath; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.layout.LayoutException; /** - * LegacyPathParser is a parser for maven 1 (legacy layout) paths to ArtifactReference. + * LegacyPathParser is a parser for maven 1 (legacy layout) paths to + * ArtifactReference. * * @author Joakim Erdfelt * @version $Id$ + * @plexus.component role="org.apache.maven.archiva.repository.content.PathParser" + * role-hint="legacy" */ public class LegacyPathParser + implements PathParser { private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: "; - protected static ArtifactReference toArtifactReference( String path ) + /** + * @plexus.requirement + */ + protected ArchivaConfiguration configuration; + + /** + * {@inheritDoc} + * + * @see org.apache.maven.archiva.repository.content.PathParser#toArtifactReference(java.lang.String) + */ + public ArtifactReference toArtifactReference( String path ) throws LayoutException { + // First, look if a custom resolution rule has been set for this artifact + Collection legacy = configuration.getConfiguration().getLegacyArtifactPaths(); + for ( Iterator iterator = legacy.iterator(); iterator.hasNext(); ) + { + LegacyArtifactPath legacyPath = (LegacyArtifactPath) iterator.next(); + if ( legacyPath.match( path ) ) + { + return legacyPath.getArtifactReference(); + } + } + ArtifactReference artifact = new ArtifactReference(); String normalizedPath = StringUtils.replace( path, "\\", "/" ); @@ -54,8 +85,8 @@ public class LegacyPathParser { // Illegal Path Parts Length. throw new LayoutException( INVALID_ARTIFACT_PATH - + "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found " - + pathParts.length + " instead." ); + + "legacy paths should only have 3 parts [groupId]/[type]s/[artifactId]-[version].[type], found " + + pathParts.length + " instead." ); } // The Group ID. @@ -68,7 +99,7 @@ public class LegacyPathParser if ( !expectedType.endsWith( "s" ) ) { throw new LayoutException( INVALID_ARTIFACT_PATH - + "legacy paths should have an expected type ending in [s] in the second part of the path." ); + + "legacy paths should have an expected type ending in [s] in the second part of the path." ); } // The Filename. @@ -88,7 +119,7 @@ public class LegacyPathParser parser.reset(); // Take the first section regardless of content. String artifactId = parser.next(); - + // Is there anything more that is considered not a version id? String moreArtifactId = parser.nextNonVersion(); if ( StringUtils.isNotBlank( moreArtifactId ) ) @@ -129,7 +160,7 @@ public class LegacyPathParser // Set Type artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) ); - + // Sanity Check: does it have an extension? if ( StringUtils.isEmpty( artifact.getType() ) ) { @@ -145,10 +176,10 @@ public class LegacyPathParser { // Sanity Check: does extension match pathType on path? String trimPathType = expectedType.substring( 0, expectedType.length() - 1 ); - + String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType ); String actualExtension = parser.getExtension(); - + if ( !expectedExtension.equals( actualExtension ) ) { throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + actualExtension diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java new file mode 100644 index 000000000..88fff1e43 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/PathParser.java @@ -0,0 +1,19 @@ +/** + * + */ +package org.apache.maven.archiva.repository.content; + +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.repository.layout.LayoutException; + +/** + * @author ndeloof + * + */ +public interface PathParser +{ + + public ArtifactReference toArtifactReference( String path ) + throws LayoutException; + +} diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java index 7a67cf75f..d473c16d0 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java @@ -38,12 +38,12 @@ import java.util.List; /** * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate - * ArtifactReference. + * ArtifactReference. * * @author Joakim Erdfelt * @version $Id$ - * - * @plexus.component + * + * @plexus.component * role="org.apache.maven.archiva.repository.content.RepositoryRequest" */ public class RepositoryRequest @@ -59,11 +59,21 @@ public class RepositoryRequest */ private ArchivaConfiguration archivaConfiguration; + /** + * @plexus.requirement role-hint="default" + */ + private PathParser defaultPathParser; + + /** + * @plexus.requirement role-hint="legacy" + */ + private PathParser legacyPathParser; + private List artifactPatterns; /** * Test path to see if it is an artifact being requested (or not). - * + * * @param requestedPath the path to test. * @return true if it is an artifact being requested. */ @@ -91,10 +101,10 @@ public class RepositoryRequest /** * 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. + * @throws LayoutException if the request path is not layout valid. */ public ArtifactReference toArtifactReference( String requestedPath ) throws LayoutException @@ -103,7 +113,7 @@ public class RepositoryRequest { throw new LayoutException( "Blank request path is not a valid." ); } - + String path = requestedPath; while ( path.startsWith( "/" ) ) { @@ -118,18 +128,18 @@ public class RepositoryRequest if ( isDefault( path ) ) { - return DefaultPathParser.toArtifactReference( path ); + return defaultPathParser.toArtifactReference( path ); } else if ( isLegacy( path ) ) { - return LegacyPathParser.toArtifactReference( path ); + return legacyPathParser.toArtifactReference( path ); } else { throw new LayoutException( "Not a valid request path layout, too short." ); } } - + /** *

* Tests the path to see if it conforms to the expectations of a metadata request. @@ -138,8 +148,8 @@ public class RepositoryRequest * NOTE: This does a cursory check on the path's last element. A result of true * from this method is not a guarantee that the metadata is in a valid format, or * that it even contains data. - *

- * + *

+ * * @param requestedPath the path to test. * @return true if the requestedPath is likely a metadata request. */ @@ -147,7 +157,7 @@ public class RepositoryRequest { return requestedPath.endsWith( "/" + MetadataTools.MAVEN_METADATA ); } - + /** *

* Tests the path to see if it conforms to the expectations of a support file request. @@ -159,8 +169,8 @@ public class RepositoryRequest * NOTE: This does a cursory check on the path's extension only. A result of true * from this method is not a guarantee that the support resource is in a valid format, or * that it even contains data. - *

- * + *

+ * * @param requestedPath the path to test. * @return true if the requestedPath is likely that of a support file request. */ @@ -175,7 +185,7 @@ public class RepositoryRequest String ext = requestedPath.substring( idx ); return ( ".sha1".equals( ext ) || ".md5".equals( ext ) || ".asc".equals( ext ) || ".pgp".equals( ext ) ); } - + /** *

* Tests the path to see if it conforms to the expectations of a default layout request. @@ -183,10 +193,10 @@ public class RepositoryRequest *

* 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 #toArtifactReference(String)} * if you want a more complete analysis of the validity of the path. *

- * + * * @param requestedPath the path to test. * @return true if the requestedPath is likely that of a default layout request. */ @@ -196,11 +206,11 @@ public class RepositoryRequest { return false; } - + String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' ); return pathParts.length > 3; } - + /** *

* Tests the path to see if it conforms to the expectations of a legacy layout request. @@ -208,10 +218,10 @@ public class RepositoryRequest *

* 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 #toArtifactReference(String)} * if you want a more complete analysis of the validity of the path. *

- * + * * @param requestedPath the path to test. * @return true if the requestedPath is likely that of a legacy layout request. */ @@ -221,18 +231,18 @@ public class RepositoryRequest { return false; } - + String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' ); return pathParts.length == 3; } - + /** * Adjust the requestedPath to conform to the native layout of the provided {@link ManagedRepositoryContent}. - * + * * @param requestedPath the incoming requested path. * @param repository the repository to adjust to. * @return the adjusted (to native) path. - * @throws LayoutException if the path cannot be parsed. + * @throws LayoutException if the path cannot be parsed. */ public String toNativePath( String requestedPath, ManagedRepositoryContent repository ) throws LayoutException { @@ -240,11 +250,11 @@ public class RepositoryRequest { throw new LayoutException( "Request Path is blank." ); } - + String referencedResource = requestedPath; // No checksum by default. String supportfile = ""; - + // Figure out support file, and actual referencedResource. if( isSupportFile( requestedPath ) ) { @@ -259,7 +269,7 @@ public class RepositoryRequest { throw new LayoutException( "Cannot translate metadata request to legacy layout." ); } - + /* Nothing to translate. * Default layout is the only layout that can contain maven-metadata.xml files, and * if the managedRepository is layout legacy, this request would never occur. diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java index ce6af3240..998eea827 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContentTestCase.java @@ -24,7 +24,7 @@ import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; /** - * AbstractLegacyRepositoryContentTestCase + * AbstractLegacyRepositoryContentTestCase * * @author Joakim Erdfelt * @version $Id$ @@ -58,10 +58,10 @@ public abstract class AbstractLegacyRepositoryContentTestCase assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" ); } - /** + /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. - * @throws LayoutException + * @throws LayoutException */ public void testGoodButOddVersionSpecGanymedSsh2() throws LayoutException diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java index 23535e784..9d13bd104 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java @@ -6,7 +6,7 @@ import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; /** - * DefaultPathParserTest + * DefaultPathParserTest * * @author Joakim Erdfelt * @version $Id$ @@ -14,6 +14,8 @@ import org.apache.maven.archiva.repository.layout.LayoutException; public class DefaultPathParserTest extends AbstractRepositoryLayerTestCase { + private PathParser parser = new DefaultPathParser(); + public void testBadPathMissingType() { assertBadPath( "invalid/invalid/1/invalid-1", "missing type" ); @@ -51,8 +53,8 @@ public class DefaultPathParserTest "wrong artifact id" ); } - /** - * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error + /** + * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ public void testGoodButDualExtensions() throws LayoutException @@ -66,11 +68,11 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } - - /** + + /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. - * @throws LayoutException + * @throws LayoutException */ public void testGoodButOddVersionSpecGanymedSsh2() throws LayoutException @@ -85,10 +87,10 @@ public class DefaultPathParserTest assertLayout( path, groupId, artifactId, version, classifier, type ); } - /** + /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. - * @throws LayoutException + * @throws LayoutException */ public void testGoodButOddVersionSpecJavaxComm() throws LayoutException @@ -105,11 +107,11 @@ public class DefaultPathParserTest /** * Test the ejb-client type spec. - * Type specs are not a 1 to 1 map to the extension. + * Type specs are not a 1 to 1 map to the extension. * This tests that effect. - * @throws LayoutException + * @throws LayoutException */ - /* TODO: Re-enabled in the future. + /* TODO: Re-enabled in the future. public void testGoodFooEjbClient() throws LayoutException { @@ -124,10 +126,10 @@ public class DefaultPathParserTest } */ - /** + /** * [MRM-432] Oddball version spec. * Example of an oddball / unusual version spec. - * @throws LayoutException + * @throws LayoutException */ public void testGoodButOddVersionSpecJavaxPersistence() throws LayoutException @@ -139,11 +141,11 @@ public class DefaultPathParserTest String type = "jar"; String path = "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar"; - /* + /* * The version id of "public_review" can cause problems. is it part of * the version spec? or the classifier? * Since the path spec below shows it in the path, then it is really - * part of the version spec. + * part of the version spec. */ assertLayout( path, groupId, artifactId, version, classifier, type ); @@ -225,7 +227,7 @@ public class DefaultPathParserTest /** * Test the classifier, and java-source type spec. - * @throws LayoutException + * @throws LayoutException */ public void testGoodFooLibSources() throws LayoutException @@ -242,7 +244,7 @@ public class DefaultPathParserTest /** * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory. - * @throws LayoutException + * @throws LayoutException */ public void testGoodSnapshotMavenTest() throws LayoutException @@ -311,7 +313,7 @@ public class DefaultPathParserTest { try { - DefaultPathParser.toArtifactReference( "" ); + parser.toArtifactReference( "" ); fail( "Should have failed due to empty path." ); } catch ( LayoutException e ) @@ -324,7 +326,7 @@ public class DefaultPathParserTest { try { - DefaultPathParser.toArtifactReference( null ); + parser.toArtifactReference( null ); fail( "Should have failed due to null path." ); } catch ( LayoutException e ) @@ -337,7 +339,7 @@ public class DefaultPathParserTest { try { - DefaultPathParser.toArtifactReference( "" ); + parser.toArtifactReference( "" ); fail( "Should have failed due to empty path." ); } catch ( LayoutException e ) @@ -350,7 +352,7 @@ public class DefaultPathParserTest { try { - DefaultPathParser.toArtifactReference( null ); + parser.toArtifactReference( null ); fail( "Should have failed due to null path." ); } catch ( LayoutException e ) @@ -360,14 +362,14 @@ 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, String type ) throws LayoutException { // Path to Artifact Reference. - ArtifactReference testReference = DefaultPathParser.toArtifactReference( path ); + ArtifactReference testReference = parser.toArtifactReference( path ); assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); } @@ -393,7 +395,7 @@ public class DefaultPathParserTest { try { - DefaultPathParser.toArtifactReference( path ); + parser.toArtifactReference( path ); fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); } catch ( LayoutException e ) diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java index df8fd91a8..fd8782772 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java @@ -20,6 +20,9 @@ package org.apache.maven.archiva.repository.content; */ +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.DefaultArchivaConfiguration; +import org.apache.maven.archiva.configuration.LegacyArtifactPath; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase; import org.apache.maven.archiva.repository.layout.LayoutException; @@ -33,6 +36,26 @@ import org.apache.maven.archiva.repository.layout.LayoutException; public class LegacyPathParserTest extends AbstractRepositoryLayerTestCase { + private LegacyPathParser parser = new LegacyPathParser(); + + /** + * Configure the ArchivaConfiguration + * {@inheritDoc} + * @see org.codehaus.plexus.PlexusTestCase#setUp() + */ + protected void setUp() + throws Exception + { + super.setUp(); + ArchivaConfiguration config = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); + LegacyArtifactPath jaxen = new LegacyArtifactPath(); + jaxen.setPath( "jaxen/jars/jaxen-1.0-FCS-full.jar" ); + jaxen.setArtifact( "jaxen:jaxen:1.0-FCS:full:jar" ); + config.getConfiguration().addLegacyArtifactPath( jaxen ); + parser.configuration = config; + } + + public void testBadPathArtifactIdMissingA() { assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" ); @@ -338,22 +361,37 @@ public class LegacyPathParserTest assertLayout( path, groupId, artifactId, version, null, type ); } + /** + * [MRM-594] add some hook in LegacyPathParser to allow exceptions in artifact resolution + */ + public void testCustomExceptionsInArtifactResolution() + throws LayoutException + { + String groupId = "jaxen"; + String artifactId = "jaxen"; + String version = "1.0-FCS"; + String type = "jar"; + String classifier = "full"; + String path = "jaxen/jars/jaxen-1.0-FCS-full.jar"; + + assertLayout( path, groupId, artifactId, version, classifier, type ); + } + /** * Perform a path to artifact reference lookup, and verify the results. - * @param classifier TODO */ private void assertLayout( String path, String groupId, String artifactId, String version, String classifier, String type ) throws LayoutException { // Path to Artifact Reference. - ArtifactReference testReference = LegacyPathParser.toArtifactReference( path ); + ArtifactReference testReference = parser.toArtifactReference( path ); assertArtifactReference( testReference, groupId, artifactId, version, classifier, type ); } private void assertArtifactReference( ArtifactReference actualReference, String groupId, String artifactId, String version, String classifier, String type ) { - String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + type; + String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + classifier + ":" + type; assertNotNull( expectedId + " - Should not be null.", actualReference ); @@ -368,7 +406,7 @@ public class LegacyPathParserTest { try { - LegacyPathParser.toArtifactReference( path ); + parser.toArtifactReference( path ); fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" ); } catch ( LayoutException e ) diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java index 9b3b4784d..d25075973 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java @@ -130,7 +130,7 @@ public class RepositoryRequestTest // 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, "pom" ); } - + public void testValidDefaultDerbyPom() throws Exception { @@ -214,7 +214,7 @@ public class RepositoryRequestTest assertTrue( repoRequest.isArtifact( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); assertTrue( repoRequest.isArtifact( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertTrue( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); - + assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) ); assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) ); assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) ); @@ -222,7 +222,7 @@ public class RepositoryRequestTest assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); assertFalse( repoRequest.isArtifact( "org/apache/derby/derby/maven-metadata.xml" ) ); } - + public void testIsSupportFile() { assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) ); @@ -231,7 +231,7 @@ public class RepositoryRequestTest assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) ); - + assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); assertFalse( repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); @@ -239,12 +239,12 @@ public class RepositoryRequestTest assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) ); assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) ); } - + public void testIsMetadata() { assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" )); assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" )); - + assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); assertFalse( repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); @@ -252,49 +252,49 @@ public class RepositoryRequestTest assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); } - + public void testIsDefault() { assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); assertFalse( repoRequest.isDefault( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) ); assertFalse( repoRequest.isDefault( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) ); - + assertTrue( repoRequest.isDefault( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertTrue( repoRequest.isDefault( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); - + assertFalse( repoRequest.isDefault( null ) ); assertFalse( repoRequest.isDefault( "" ) ); assertFalse( repoRequest.isDefault( "foo" ) ); assertFalse( repoRequest.isDefault( "some.short/path" ) ); } - + public void testIsLegacy() { assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) ); assertTrue( repoRequest.isLegacy( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) ); assertTrue( repoRequest.isLegacy( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) ); - + assertFalse( repoRequest.isLegacy( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) ); assertFalse( repoRequest.isLegacy( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) ); assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) ); assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) ); assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) ); - + assertFalse( repoRequest.isLegacy( null ) ); assertFalse( repoRequest.isLegacy( "" ) ); assertFalse( repoRequest.isLegacy( "some.short/path" ) ); } - + private ManagedRepositoryContent createManagedRepo( String layout ) throws Exception { File repoRoot = getTestFile( "target/test-repo" ); return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout ); } - + /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ @@ -307,7 +307,7 @@ public class RepositoryRequestTest assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest .toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) ); } - + /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ @@ -321,7 +321,7 @@ public class RepositoryRequestTest assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest .toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) ); } - + public void testToNativePathMetadataDefaultToDefault() throws Exception { @@ -337,7 +337,7 @@ public class RepositoryRequestTest { ManagedRepositoryContent repository = createManagedRepo( "default" ); - // Test (pom) legacy to default + // Test (pom) legacy to default assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repoRequest .toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) ); } @@ -368,7 +368,7 @@ public class RepositoryRequestTest // expected path. } } - + public void testNativePathBadRequestBlank() throws Exception { @@ -385,7 +385,7 @@ public class RepositoryRequestTest // expected path. } } - + public void testNativePathBadRequestNull() throws Exception { @@ -402,7 +402,7 @@ public class RepositoryRequestTest // expected path. } } - + public void testNativePathBadRequestUnknownType() throws Exception { @@ -419,14 +419,14 @@ public class RepositoryRequestTest // expected path. } } - + public void testToNativePathLegacyMetadataDefaultToLegacy() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "legacy" ); // Test (metadata) default to legacy - + // Special Case: This direction is not supported, should throw a LayoutException. try { @@ -438,7 +438,7 @@ public class RepositoryRequestTest // expected path. } } - + public void testNativePathPomDefaultToLegacy() throws Exception { @@ -448,13 +448,13 @@ public class RepositoryRequestTest assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", repoRequest .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) ); } - + public void testNativePathSupportFileDefaultToLegacy() throws Exception { ManagedRepositoryContent repository = createManagedRepo( "legacy" ); - // Test (supportfile) default to legacy + // Test (supportfile) default to legacy assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repoRequest .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repository ) ); } -- 2.39.5