From 4a2ab461c54d6b861d1b78321c224fa6cf1103f3 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Thu, 16 Nov 2006 15:28:07 +0000 Subject: [PATCH] MRM-224 Converting Maven 1.x plugins. We're simply making sure they are copied over with the right extension so that folks using an m2 repository for both m1 and m2 clients have something that works. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@475767 13f79535-47bb-0310-9956-ffa450edef68 --- .../converter/DefaultRepositoryConverter.java | 11 ++++++++ .../expected-files/maven-foo-plugin-1.0.pom | 7 +++++ .../converter/RepositoryConverterTest.java | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 archiva-converter/src/test/expected-files/maven-foo-plugin-1.0.pom diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java index b79c8ad9d..becd5ffb1 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.converter; import org.apache.maven.archiva.converter.transaction.FileTransaction; import org.apache.maven.archiva.reporting.ReportingDatabase; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; @@ -90,6 +91,11 @@ public class DefaultRepositoryConverter */ private ModelConverter translator; + /** + * @plexus.requirement + */ + private ArtifactHandlerManager artifactHandlerManager; + /** * @plexus.configuration default-value="false" */ @@ -666,6 +672,11 @@ public class DefaultRepositoryConverter { File sourceFile = artifact.getFile(); + if ( sourceFile.getAbsolutePath().indexOf( "/plugins/" ) > -1 ) + { + artifact.setArtifactHandler( artifactHandlerManager.getArtifactHandler( "maven-plugin" ) ); + } + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); boolean result = true; diff --git a/archiva-converter/src/test/expected-files/maven-foo-plugin-1.0.pom b/archiva-converter/src/test/expected-files/maven-foo-plugin-1.0.pom new file mode 100644 index 000000000..17095cc57 --- /dev/null +++ b/archiva-converter/src/test/expected-files/maven-foo-plugin-1.0.pom @@ -0,0 +1,7 @@ + + 4.0.0 + org.apache.maven.plugins + maven-foo-plugin + 1.0.0 + maven-plugin + diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java index 3b345d36c..04d696ea4 100644 --- a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java +++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java @@ -39,6 +39,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.regex.Matcher; /** @@ -404,6 +405,31 @@ public class RepositoryConverterTest assertTrue( true ); } + public void testMavenOnePluginConversion() + throws Exception + { + Artifact artifact = createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0", "maven-plugin" ); + artifact.setFile( new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); + // There is a warning but I can't figure out how to look at it. Eyeballing the results it appears + // the plugin is being coverted correctly. + //checkSuccess(); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + /* + The POM isn't needed for Maven 1.x plugins but the raw conversion for + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = getTestFile( "src/test/expected-files/maven-foo-plugin-1.0.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + compareFiles( expectedPomFile, pomFile ); + */ + } + public void testV3TimestampedSnapshotPomConvert() throws IOException, RepositoryConversionException {