diff options
author | Brett Porter <brett@apache.org> | 2006-01-27 03:11:04 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2006-01-27 03:11:04 +0000 |
commit | 11b23f1c5c76c5bca49005a35d9645922bef0ad8 (patch) | |
tree | 2cb5599da83600904bdd02a68832f89c4c810f4b /maven-repository-converter | |
parent | 49265d77915a1503c31f35b941c484901107cf28 (diff) | |
download | archiva-11b23f1c5c76c5bca49005a35d9645922bef0ad8.tar.gz archiva-11b23f1c5c76c5bca49005a35d9645922bef0ad8.zip |
[MRM-9] continue with tests
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@372710 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'maven-repository-converter')
12 files changed, 204 insertions, 14 deletions
diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java index 56eefc96c..ce62db609 100644 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java +++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java @@ -38,6 +38,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringReader; import java.io.Writer; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; @@ -71,12 +72,12 @@ public class DefaultRepositoryConverter */ private boolean dryrun; - public void convert( Artifact artifact, ArtifactRepository targetRepository ) + public List convert( Artifact artifact, ArtifactRepository targetRepository ) throws RepositoryConversionException { copyArtifact( artifact, targetRepository ); - copyPom( artifact, targetRepository ); + List warnings = copyPom( artifact, targetRepository ); Metadata metadata = createBaseMetadata( artifact ); Versioning versioning = new Versioning(); @@ -100,6 +101,8 @@ public class DefaultRepositoryConverter // TODO: merge latest/release/snapshot from source instead metadata.setVersioning( versioning ); updateMetadata( new SnapshotArtifactRepositoryMetadata( artifact ), targetRepository, metadata ); + + return warnings; } private static Metadata createBaseMetadata( Artifact artifact ) @@ -172,9 +175,11 @@ public class DefaultRepositoryConverter } } - private void copyPom( Artifact artifact, ArtifactRepository targetRepository ) + private List copyPom( Artifact artifact, ArtifactRepository targetRepository ) throws RepositoryConversionException { + List warnings = new ArrayList(); + Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); pom.setBaseVersion( artifact.getBaseVersion() ); @@ -234,6 +239,8 @@ public class DefaultRepositoryConverter rewriter.rewrite( stringReader, fileWriter, false, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType() ); + warnings = rewriter.getWarnings(); + IOUtil.close( fileWriter ); } catch ( Exception e ) @@ -247,6 +254,7 @@ public class DefaultRepositoryConverter } } } + return warnings; } private void copyArtifact( Artifact artifact, ArtifactRepository targetRepository ) diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java index f1cc0cc10..1fbb38cb3 100644 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java +++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java @@ -35,8 +35,9 @@ public interface RepositoryConverter * * @param artifact the artifact to convert * @param targetRepository the target repository + * @return a list of warnings occuring during the conversion */ - void convert( Artifact artifact, ArtifactRepository targetRepository ) + List convert( Artifact artifact, ArtifactRepository targetRepository ) throws RepositoryConversionException; /** diff --git a/maven-repository-converter/src/test/expected-files/converted-v3-warnings.pom b/maven-repository-converter/src/test/expected-files/converted-v3-warnings.pom new file mode 100644 index 000000000..e07664932 --- /dev/null +++ b/maven-repository-converter/src/test/expected-files/converted-v3-warnings.pom @@ -0,0 +1,22 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>v3-warnings-artifact</artifactId> + <version>1.0.0</version> + <scm> + <connection>scm:cvs:ext:${maven.username}@localhost:/home/cvs</connection> + </scm> + <dependencies> + <dependency> + <groupId>groupId</groupId> + <artifactId>artifactId</artifactId> + <version>version</version> + </dependency> + <dependency> + <groupId>groupId</groupId> + <artifactId>test-artifactId</artifactId> + <version>version</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/maven-repository-converter/src/test/expected-files/newversion-artifact-metadata.xml b/maven-repository-converter/src/test/expected-files/newversion-artifact-metadata.xml new file mode 100644 index 000000000..00456f214 --- /dev/null +++ b/maven-repository-converter/src/test/expected-files/newversion-artifact-metadata.xml @@ -0,0 +1,10 @@ +<metadata> + <groupId>test</groupId> + <artifactId>newversion-artifact</artifactId> + <versioning> + <versions> + <version>1.0.0</version> + <version>1.0.1</version> + </versions> + </versioning> +</metadata>
\ No newline at end of file diff --git a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java index 7cabfcbee..f75fe3103 100644 --- a/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java +++ b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java @@ -42,7 +42,6 @@ import java.util.regex.Matcher; * @todo use artifact-test instead * @todo should reject if dependencies are missing - rely on reporting? * @todo group metadata - * @todo write timestamp into the metadata */ public class RepositoryConverterTest extends PlexusTestCase @@ -96,7 +95,7 @@ public class RepositoryConverterTest ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); versionMetadataFile.delete(); repositoryConverter.convert( artifact, targetRepository ); @@ -138,7 +137,7 @@ public class RepositoryConverterTest ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); File versionMetadataFile = new File( targetRepository.getBasedir(), - targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); versionMetadataFile.delete(); repositoryConverter.convert( artifact, targetRepository ); @@ -168,10 +167,37 @@ public class RepositoryConverterTest } public void testV3PomWarningsOnConvert() + throws RepositoryConversionException, IOException { // test that the pom is converted but that warnings are reported - // TODO + Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" ); + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + artifactMetadataFile.delete(); + + ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact ); + File versionMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); + versionMetadataFile.delete(); + + List warnings = repositoryConverter.convert( artifact, targetRepository ); + + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File expectedPomFile = getTestFile( "src/test/expected-files/converted-v3-warnings.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( expectedPomFile, pomFile ); + + assertEquals( "check number of warnings", 2, warnings.size() ); + + // TODO: check 2 warnings (extend and versions) matched on i18n key } public void testV4SnapshotPomConvert() @@ -572,17 +598,33 @@ public class RepositoryConverterTest } public void testMergeArtifactMetadata() + throws RepositoryConversionException, IOException { // test artifact level metadata is merged when it already exists on successful conversion - // TODO - } + Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" ); - public void testMergeSnapshotMetadata() - { - // test snapshot metadata is merged when it already exists on successful conversion + repositoryConverter.convert( artifact, targetRepository ); - // TODO + File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + assertTrue( "Check artifact created", artifactFile.exists() ); + assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) ); + + artifact = createPomArtifact( artifact ); + File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + assertTrue( "Check POM created", pomFile.exists() ); + + compareFiles( sourcePomFile, pomFile ); + + ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact ); + File artifactMetadataFile = new File( targetRepository.getBasedir(), + targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) ); + assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() ); + + File expectedMetadataFile = getTestFile( "src/test/expected-files/newversion-artifact-metadata.xml" ); + + compareFiles( expectedMetadataFile, artifactMetadataFile ); } public void testSourceAndTargetRepositoriesMatch() diff --git a/maven-repository-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar b/maven-repository-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar new file mode 100644 index 000000000..c694117fd --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/newversion-artifact-1.0.1.jar @@ -0,0 +1 @@ +v4 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/v3-warnings-artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/maven-repository-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom b/maven-repository-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom new file mode 100644 index 000000000..5f24f98c1 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/newversion-artifact-1.0.1.pom @@ -0,0 +1,23 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~ + --> + +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>newversoin-artifact</artifactId> + <version>1.0.1</version> +</project> diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom new file mode 100644 index 000000000..6e56d6956 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/v3-warnings-artifact-1.0.0.pom @@ -0,0 +1,49 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~ + --> + +<project> + <pomVersion>3</pomVersion> + <extend>../project.xml</extend> + <artifactId>v3-warnings-artifact</artifactId> + <groupId>test</groupId> + <currentVersion>1.0.0</currentVersion> + <versions> + <version> + <id>1.0</id> + <name>1.0</name> + <tag>1_0</tag> + </version> + </versions> + <dependencies> + <dependency> + <groupId>groupId</groupId> + <artifactId>artifactId</artifactId> + <version>version</version> + </dependency> + <dependency> + <groupId>groupId</groupId> + <artifactId>test-artifactId</artifactId> + <version>version</version> + <properties> + <scope>test</scope> + </properties> + </dependency> + </dependencies> + <repository> + <connection>scm:cvs:ext:${maven.username}@localhost:/home/cvs</connection> + </repository> +</project> diff --git a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom new file mode 100644 index 000000000..5182dfaf4 --- /dev/null +++ b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/1.0.0/newversion-artifact-1.0.0.pom @@ -0,0 +1,23 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~ + --> + +<project> + <modelVersion>4.0.0</modelVersion> + <artifactId>newversion-artifact</artifactId> + <groupId>test</groupId> + <currentVersion>1.0.0</currentVersion> +</project> diff --git a/maven-repository-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml new file mode 100644 index 000000000..f4d211741 --- /dev/null +++ b/maven-repository-converter/src/test/target-repository/test/newversion-artifact/maven-metadata.xml @@ -0,0 +1,9 @@ +<metadata> + <groupId>test</groupId> + <artifactId>newversion-artifact</artifactId> + <versioning> + <versions> + <version>1.0.0</version> + </versions> + </versioning> +</metadata>
\ No newline at end of file |