From 6babd1476dabed8f484f7e5cf47870b06525f3ef Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Tue, 25 Mar 2008 10:07:15 +0000 Subject: [PATCH] [MRM-659] archiva cannot serve ejb artifacts from a maven1 repository git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@640759 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/ArtifactExtensionMapping.java | 15 ++++++-- .../repository/content/LegacyPathParser.java | 12 +++---- .../ManagedLegacyRepositoryContentTest.java | 5 +-- .../content/RepositoryRequestTest.java | 34 +++++++++++++++++-- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java index 3c28cec2c..17702a192 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java @@ -79,6 +79,12 @@ public class ArtifactExtensionMapping } public static String mapExtensionAndClassifierToType( String classifier, String extension ) + { + return mapExtensionAndClassifierToType( classifier, extension, extension ); + } + + public static String mapExtensionAndClassifierToType( String classifier, String extension, + String defaultExtension ) { if ( "sources".equals( classifier ) ) { @@ -88,10 +94,15 @@ public class ArtifactExtensionMapping { return "javadoc"; } - return mapExtensionToType( extension ); + return mapExtensionToType( extension, defaultExtension ); } public static String mapExtensionToType( String extension ) + { + return mapExtensionToType( extension, extension ); + } + + private static String mapExtensionToType( String extension, String defaultExtension ) { if ( "tar.gz".equals( extension ) ) { @@ -105,6 +116,6 @@ public class ArtifactExtensionMapping { return "distribution-zip"; } - return extension; + return defaultExtension; } } diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java index e62d1516d..0cf3b3997 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/LegacyPathParser.java @@ -178,7 +178,9 @@ public class LegacyPathParser String extension = parser.getExtension(); // Set Type - artifact.setType( ArtifactExtensionMapping.mapExtensionAndClassifierToType( classifier, extension ) ); + String defaultExtension = expectedType.substring( 0, expectedType.length() - 1 ); + artifact.setType( + ArtifactExtensionMapping.mapExtensionAndClassifierToType( classifier, extension, defaultExtension ) ); // Sanity Check: does it have an extension? if ( StringUtils.isEmpty( artifact.getType() ) ) @@ -187,21 +189,19 @@ public class LegacyPathParser } // Special Case with Maven Plugins - if ( StringUtils.equals( "jar", artifact.getType() ) && StringUtils.equals( "plugins", expectedType ) ) + if ( StringUtils.equals( "jar", extension ) && StringUtils.equals( "plugins", expectedType ) ) { artifact.setType( ArtifactExtensionMapping.MAVEN_PLUGIN ); } else { // Sanity Check: does extension match pathType on path? - String trimPathType = expectedType.substring( 0, expectedType.length() - 1 ); - - String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType ); + String expectedExtension = ArtifactExtensionMapping.getExtension( artifact.getType() ); if ( !expectedExtension.equals( extension ) ) { throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension - + "] and layout specified type [" + expectedType + "] (which maps to extension: [" + + "] and layout specified type [" + artifact.getType() + "] (which maps to extension: [" + expectedExtension + "]) on path [" + path + "]" ); } } diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java index 7be024051..2991832b5 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContentTest.java @@ -129,6 +129,8 @@ public class ManagedLegacyRepositoryContentTest "org.apache.maven/java-sources/testing-1.0-sources.jar", "org.apache.maven/jars/testing-1.0-20050611.112233-1.jar", "org.apache.maven/poms/testing-1.0.pom", + "org.apache.maven/distributions/testing-1.0.tar.gz", + "org.apache.maven/distributions/testing-1.0.zip", "org.apache.maven/javadoc.jars/testing-1.0-javadoc.jar" }; StringBuffer relatedDebugString = new StringBuffer(); @@ -140,8 +142,6 @@ public class ManagedLegacyRepositoryContentTest } relatedDebugString.append( "]" ); - assertEquals( "Related <" + relatedDebugString + ">:", expected.length, related.size() ); - for ( String expectedPath : expected ) { boolean found = false; @@ -160,6 +160,7 @@ public class ManagedLegacyRepositoryContentTest + "Related <" + relatedDebugString + ">" ); } } + assertEquals( "Related <" + relatedDebugString + ">:", expected.length, related.size() ); } @Override diff --git a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java index d25075973..6ee6f874a 100644 --- a/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java +++ b/archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java @@ -338,8 +338,38 @@ public class RepositoryRequestTest ManagedRepositoryContent repository = createManagedRepo( "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 ) ); + 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 ) ); + } + + public void testNativePathPomLegacyToLegacy() + throws Exception + { + ManagedRepositoryContent repository = createManagedRepo( "legacy" ); + + // Test (pom) legacy to default + assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", + repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) ); + } + + public void testNativePathPomLegacyToDefaultEjb() + throws Exception + { + ManagedRepositoryContent repository = createManagedRepo( "default" ); + + // Test (pom) legacy to default + assertEquals( "mygroup/myejb/1.0/myejb-1.0.jar", + repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) ); + } + + public void testNativePathPomLegacyToLegacyEjb() + throws Exception + { + ManagedRepositoryContent repository = createManagedRepo( "legacy" ); + + // Test (pom) legacy to default + assertEquals( "mygroup/ejbs/myejb-1.0.jar", + repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) ); } public void testNativePathSupportFileLegacyToDefault() -- 2.39.5