From: Brett Porter Date: Sun, 15 Jan 2006 21:34:03 +0000 (+0000) Subject: [MRM-9] first check in of repository converter X-Git-Tag: archiva-0.9-alpha-1~983 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=080a93a5970b506c3d494a9a19c68485bbb9201d;p=archiva.git [MRM-9] first check in of repository converter git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@369265 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-converter/pom.xml b/maven-repository-converter/pom.xml new file mode 100644 index 000000000..fcb90db1c --- /dev/null +++ b/maven-repository-converter/pom.xml @@ -0,0 +1,41 @@ + + + + + org.apache.maven.repository + maven-repository-manager + 1.0-SNAPSHOT + + 4.0.0 + maven-repository-converter + Maven Repository Converter + + + org.apache.maven + maven-artifact + + + org.apache.maven + maven-model-converter + + + org.apache.maven.repository + maven-repository-reports-standard + + + 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 new file mode 100644 index 000000000..5ee18a4c0 --- /dev/null +++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java @@ -0,0 +1,184 @@ +package org.apache.maven.repository.converter; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.converter.ArtifactPomRewriter; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringReader; +import java.io.Writer; +import java.util.Iterator; +import java.util.List; + +/** + * Implementation of repository conversion class. + * + * @author Brett Porter + * @plexus.component role="org.apache.maven.repository.converter.RepositoryConverter" role-hint="default" + */ +public class DefaultRepositoryConverter + implements RepositoryConverter +{ + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private ArtifactPomRewriter rewriter; + + /** + * @plexus.configuration + */ + private boolean force; + + /** + * @plexus.configuration + */ + private boolean dryrun; + + public void convert( Artifact artifact, ArtifactRepository targetRepository ) + throws RepositoryConversionException + { + copyArtifact( artifact, targetRepository ); + + copyPom( artifact, targetRepository ); + } + + private void copyPom( Artifact artifact, ArtifactRepository targetRepository ) + throws RepositoryConversionException + { + Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion() ); + ArtifactRepository repository = artifact.getRepository(); + File file = new File( repository.getBasedir(), repository.pathOf( pom ) ); + + if ( file.exists() ) + { + // TODO: utility methods in the model converter + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pom ) ); + + String contents; + try + { + contents = FileUtils.fileRead( file ); + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Unable to read source POM: " + e.getMessage(), e ); + } + + if ( contents.indexOf( "modelVersion" ) >= 0 ) + { + // v4 POM + try + { + boolean matching = false; + if ( !force && targetFile.exists() ) + { + String targetContents = FileUtils.fileRead( targetFile ); + matching = targetContents.equals( contents ); + } + if ( force || !matching ) + { + if ( !dryrun ) + { + targetFile.getParentFile().mkdirs(); + FileUtils.fileWrite( targetFile.getAbsolutePath(), contents ); + } + } + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Unable to write target POM: " + e.getMessage(), e ); + } + } + else + { + // v3 POM + StringReader stringReader = new StringReader( contents ); + Writer fileWriter = null; + try + { + fileWriter = new FileWriter( targetFile ); + + // TODO: this api could be improved - is it worth having or go back to modelConverter? + rewriter.rewrite( stringReader, fileWriter, false, artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion(), artifact.getType() ); + + IOUtil.close( fileWriter ); + } + catch ( Exception e ) + { + if ( fileWriter != null ) + { + IOUtil.close( fileWriter ); + targetFile.delete(); + } + throw new RepositoryConversionException( "Unable to write converted POM", e ); + } + } + } + } + + private void copyArtifact( Artifact artifact, ArtifactRepository targetRepository ) + throws RepositoryConversionException + { + File sourceFile = artifact.getFile(); + + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + + try + { + boolean matching = false; + if ( !force && targetFile.exists() ) + { + matching = FileUtils.contentEquals( sourceFile, targetFile ); + } + if ( force || !matching ) + { + if ( !dryrun ) + { + FileUtils.copyFile( sourceFile, targetFile ); + } + } + } + catch ( IOException e ) + { + throw new RepositoryConversionException( "Error copying artifact", e ); + } + } + + public void convert( List artifacts, ArtifactRepository targetRepository ) + throws RepositoryConversionException + { + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + convert( artifact, targetRepository ); + } + } +} diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java new file mode 100644 index 000000000..090cee540 --- /dev/null +++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java @@ -0,0 +1,31 @@ +package org.apache.maven.repository.converter; + +/* + * 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. + */ + +/** + * Exception occuring during repository conversion. + * + * @author Brett Porter + */ +public class RepositoryConversionException + extends Exception +{ + public RepositoryConversionException( String message, Throwable cause ) + { + super( message, cause ); + } +} 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 new file mode 100644 index 000000000..f1cc0cc10 --- /dev/null +++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java @@ -0,0 +1,50 @@ +package org.apache.maven.repository.converter; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +import java.util.List; + +/** + * Copy a set of artifacts from one repository to the other, converting if necessary. + * + * @author Brett Porter + */ +public interface RepositoryConverter +{ + String ROLE = RepositoryConverter.class.getName(); + + /** + * Convert a single artifact, writing it into the target repository. + * + * @param artifact the artifact to convert + * @param targetRepository the target repository + */ + void convert( Artifact artifact, ArtifactRepository targetRepository ) + throws RepositoryConversionException; + + /** + * Convert a set of artifacts, writing them into the target repository. + * + * @param artifacts the set of artifacts to convert + * @param targetRepository the target repository + */ + void convert( List artifacts, ArtifactRepository targetRepository ) + throws RepositoryConversionException; +} diff --git a/maven-repository-converter/src/test/expected-files/converted-artifact-one.pom b/maven-repository-converter/src/test/expected-files/converted-artifact-one.pom new file mode 100644 index 000000000..cd3862d35 --- /dev/null +++ b/maven-repository-converter/src/test/expected-files/converted-artifact-one.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-one + 1.0.0 + diff --git a/maven-repository-converter/src/test/expected-files/converted-artifact-three.pom b/maven-repository-converter/src/test/expected-files/converted-artifact-three.pom new file mode 100644 index 000000000..343291037 --- /dev/null +++ b/maven-repository-converter/src/test/expected-files/converted-artifact-three.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-three + 1.0.0 + diff --git a/maven-repository-converter/src/test/expected-files/converted-artifact-two.pom b/maven-repository-converter/src/test/expected-files/converted-artifact-two.pom new file mode 100644 index 000000000..227470167 --- /dev/null +++ b/maven-repository-converter/src/test/expected-files/converted-artifact-two.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-two + 1.0.0 + diff --git a/maven-repository-converter/src/test/expected-files/converted-v3.pom b/maven-repository-converter/src/test/expected-files/converted-v3.pom new file mode 100644 index 000000000..29ba92771 --- /dev/null +++ b/maven-repository-converter/src/test/expected-files/converted-v3.pom @@ -0,0 +1,22 @@ + + 4.0.0 + test + v3artifact + 1.0.0 + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + test + + + 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 new file mode 100644 index 000000000..8c3c63372 --- /dev/null +++ b/maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java @@ -0,0 +1,419 @@ +package org.apache.maven.repository.converter; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Test the repository converter. + * + * @author Brett Porter + * @todo what about deletions from the source repository? + * @todo use artifact-test instead + * @todo should reject if dependencies are missing - rely on reporting? + */ +public class RepositoryConverterTest + extends PlexusTestCase +{ + private ArtifactRepository sourceRepository; + + private ArtifactRepository targetRepository; + + private RepositoryConverter repositoryConverter; + + private ArtifactFactory artifactFactory; + + protected void setUp() + throws Exception + { + super.setUp(); + + ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + + File sourceBase = getTestFile( "src/test/source-repository" ); + sourceRepository = + factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null ); + + layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + File targetBase = getTestFile( "target/test-target-repository" ); + FileUtils.copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase ); + + targetRepository = + factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null, null ); + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "default" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + } + + public void testV4PomConvert() + throws IOException, RepositoryConversionException + { + // test that it is copied as is + + Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" ); + 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 sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + assertTrue( "Check POM created", pomFile.exists() ); + + String sourceContent = FileUtils.fileRead( sourcePomFile ).trim(); + String targetContent = FileUtils.fileRead( pomFile ).trim(); + assertEquals( "Check POM matches", sourceContent, targetContent ); + } + + public void testV3PomConvert() + throws IOException, RepositoryConversionException + { + // test that the pom is coverted + + Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" ); + 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.pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + String expectedContent = FileUtils.fileRead( expectedPomFile ).trim(); + String targetContent = FileUtils.fileRead( pomFile ).trim(); + assertEquals( "Check POM was converted", expectedContent, targetContent ); + + // TODO: test warnings (separate test?) + } + + public void testNoPomConvert() + throws IOException, RepositoryConversionException + { + // test that a POM is created when there was none at the source + + Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" ); + 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 sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + // TODO: should we fail? Warn? + assertFalse( "Check no POM created", pomFile.exists() ); + assertFalse( "No source POM", sourcePomFile.exists() ); + } + + public void testInvalidSourceChecksumMd5() + throws RepositoryConversionException + { + // test that it fails when the source md5 is not a valid md5 + + Artifact artifact = createArtifact( "test", "invalidMd5Artifact", "1.0.0" ); + repositoryConverter.convert( artifact, targetRepository ); + + // TODO: check for failure + } + + public void testInvalidSourceChecksumSha1() + { + // test that it fails when the source sha1 is not a valid sha1 + + // TODO: using exceptions at this level, or passing in reporter? + } + + public void testIncorrectSourceChecksumMd5() + { + // test that it fails when the source md5 is wrong + + // TODO: using exceptions at this level, or passing in reporter? + } + + public void testIncorrectSourceChecksumSha1() + { + // test that it fails when the source sha1 is wrong + + // TODO: using exceptions at this level, or passing in reporter? + } + + public void testUnmodifiedArtifact() + throws RepositoryConversionException, IOException + { + // test the unmodified artifact is untouched + + Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + assertTrue( "Check target file exists", targetFile.exists() ); + assertTrue( "Check target POM exists", targetPomFile.exists() ); + + sourceFile.setLastModified( System.currentTimeMillis() ); + sourcePomFile.setLastModified( System.currentTimeMillis() ); + + long origTime = targetFile.lastModified(); + long origPomTime = targetPomFile.lastModified(); + + repositoryConverter.convert( artifact, targetRepository ); + + String expectedContent = FileUtils.fileRead( sourceFile ).trim(); + String targetContent = FileUtils.fileRead( targetFile ).trim(); + assertEquals( "Check file matches", expectedContent, targetContent ); + + expectedContent = FileUtils.fileRead( sourcePomFile ).trim(); + targetContent = FileUtils.fileRead( targetPomFile ).trim(); + assertEquals( "Check POM matches", expectedContent, targetContent ); + + assertEquals( "Check unmodified", origTime, targetFile.lastModified() ); + assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() ); + } + + public void testModifedArtifactFails() + { + // test that it fails when the source artifact has changed and is different to the existing artifact in the + // target repository + + // TODO + } + + public void testForcedUnmodifiedArtifact() + throws Exception, IOException + { + // test unmodified artifact is still converted when set to force + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "force-repository-converter" ); + + Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + long origTime = targetFile.lastModified(); + long origPomTime = targetPomFile.lastModified(); + + sourceFile.setLastModified( System.currentTimeMillis() ); + sourcePomFile.setLastModified( System.currentTimeMillis() ); + + repositoryConverter.convert( artifact, targetRepository ); + + String expectedContent = FileUtils.fileRead( sourceFile ).trim(); + String targetContent = FileUtils.fileRead( targetFile ).trim(); + assertEquals( "Check file matches", expectedContent, targetContent ); + + expectedContent = FileUtils.fileRead( sourcePomFile ).trim(); + targetContent = FileUtils.fileRead( targetPomFile ).trim(); + assertEquals( "Check POM matches", expectedContent, targetContent ); + + assertFalse( "Check modified", origTime == targetFile.lastModified() ); + assertFalse( "Check modified", origPomTime == targetPomFile.lastModified() ); + } + + public void testDryRunSuccess() + throws Exception + { + // test dry run does nothing on a run that will be successful, and returns success + + repositoryConverter = (RepositoryConverter) lookup( RepositoryConverter.ROLE, "dryrun-repository-converter" ); + + Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" ); + Artifact pomArtifact = createPomArtifact( artifact ); + + File sourceFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ); + File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( pomArtifact ) ); + File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); + File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); + + repositoryConverter.convert( artifact, targetRepository ); + + assertTrue( "Check source file exists", sourceFile.exists() ); + assertTrue( "Check source POM exists", sourcePomFile.exists() ); + + assertFalse( "Check target file doesn't exist", targetFile.exists() ); + assertFalse( "Check target POM doesn't exist", targetPomFile.exists() ); + } + + public void testDryRunFailure() + { + // test dry run does nothing on a run that will fail, and returns failure + + // TODO + } + + public void testRollbackArtifactCreated() + { + // test rollback can remove a created artifact, including checksums + + // TODO + } + + public void testRollbackArtifactChanged() + { + // test rollback can undo changes to an artifact, including checksums + + // TODO + } + + public void testRollbackMetadataCreated() + { + // test rollback can remove a created artifact's metadata, including checksums + + // TODO + } + + public void testRollbackMetadataChanged() + { + // test rollback can undo changes to an artifact's metadata, including checksums + + // TODO + } + + public void testMultipleArtifacts() + throws RepositoryConversionException, IOException + { + // test multiple artifacts are converted + + List artifacts = new ArrayList(); + artifacts.add( createArtifact( "test", "artifact-one", "1.0.0" ) ); + artifacts.add( createArtifact( "test", "artifact-two", "1.0.0" ) ); + artifacts.add( createArtifact( "test", "artifact-three", "1.0.0" ) ); + repositoryConverter.convert( artifacts, targetRepository ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + + 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-" + artifact.getArtifactId() + ".pom" ); + assertTrue( "Check POM created", pomFile.exists() ); + + String expectedContent = FileUtils.fileRead( expectedPomFile ).trim(); + String targetContent = FileUtils.fileRead( pomFile ).trim(); + assertEquals( "Check POM was converted", expectedContent, targetContent ); + } + } + + public void testInvalidSourceArtifactMetadata() + { + // test artifact is not converted when source metadata is invalid, and returns failure + + // TODO + } + + public void testSnapshotArtifact() + { + // test snapshot artifact is converted + + // TODO + } + + public void testInvalidSourceSnapshotMetadata() + { + // test artifact is not converted when source snapshot metadata is invalid and returns failure + + // TODO + } + + public void testCreateArtifactMetadata() + { + // test artifact level metadata is created when it doesn't exist on successful conversion + + // TODO + } + + public void testCreateSnapshotMetadata() + { + // test snapshot metadata is created when it doesn't exist on successful conversion + + // TODO + } + + public void testMergeArtifactMetadata() + { + // test artifact level metadata is merged when it already exists on successful conversion + + // TODO + } + + public void testMergeSnapshotMetadata() + { + // test snapshot metadata is merged when it already exists on successful conversion + + // TODO + } + + public void testSourceAndTargetRepositoriesMatch() + { + // test that it fails if the same (initially - later we might allow this with extra checks) + + // TODO + } + + private Artifact createArtifact( String groupId, String artifactId, String version ) + { + return createArtifact( groupId, artifactId, version, "jar" ); + } + + private Artifact createArtifact( String groupId, String artifactId, String version, String type ) + { + Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type ); + artifact.setRepository( sourceRepository ); + artifact.setFile( new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) ) ); + return artifact; + } + + private Artifact createPomArtifact( Artifact artifact ) + { + return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "pom" ); + } + +} diff --git a/maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml b/maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml new file mode 100644 index 000000000..383da90db --- /dev/null +++ b/maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml @@ -0,0 +1,56 @@ + + + + + + org.apache.maven.repository.converter.RepositoryConverter + org.apache.maven.repository.converter.DefaultRepositoryConverter + force-repository-converter + + true + + + + org.apache.maven.artifact.factory.ArtifactFactory + artifactFactory + + + org.apache.maven.model.converter.ArtifactPomRewriter + rewriter + + + + + org.apache.maven.repository.converter.RepositoryConverter + org.apache.maven.repository.converter.DefaultRepositoryConverter + dryrun-repository-converter + + true + + + + org.apache.maven.artifact.factory.ArtifactFactory + artifactFactory + + + org.apache.maven.model.converter.ArtifactPomRewriter + rewriter + + + + + \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar new file mode 100644 index 000000000..5626abf0f --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar @@ -0,0 +1 @@ +one diff --git a/maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar new file mode 100644 index 000000000..2bdf67abb --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar @@ -0,0 +1 @@ +three diff --git a/maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar new file mode 100644 index 000000000..f719efd43 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar @@ -0,0 +1 @@ +two diff --git a/maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar new file mode 100644 index 000000000..cbaf024e5 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar @@ -0,0 +1 @@ +existing diff --git a/maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar new file mode 100644 index 000000000..cbaf024e5 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar @@ -0,0 +1 @@ +existing diff --git a/maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar new file mode 100644 index 000000000..4694cadf5 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar @@ -0,0 +1 @@ +invalidMd5 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar.md5 b/maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar.md5 new file mode 100644 index 000000000..29f1ec27a --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar.md5 @@ -0,0 +1 @@ +md5 \ No newline at end of file diff --git a/maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar new file mode 100644 index 000000000..3d27acdcc --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar @@ -0,0 +1 @@ +noPom diff --git a/maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar new file mode 100644 index 000000000..29ef827e8 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar @@ -0,0 +1 @@ +v3 diff --git a/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar new file mode 100644 index 000000000..c694117fd --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar @@ -0,0 +1 @@ +v4 diff --git a/maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom new file mode 100644 index 000000000..cd3862d35 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-one + 1.0.0 + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom new file mode 100644 index 000000000..343291037 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-three + 1.0.0 + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom new file mode 100644 index 000000000..227470167 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + artifact-two + 1.0.0 + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom new file mode 100644 index 000000000..1953c5523 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + dryrun-artifact + test + 1.0.0 + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/invalidMd5Artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/invalidMd5Artifact-1.0.0.pom new file mode 100644 index 000000000..1a7012ee4 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/invalidMd5Artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 3 + invalidMd5Artifact + test + 1.0.0 + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom new file mode 100644 index 000000000..c570979f4 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + unmodified-artifact + test + 1.0.0 + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom new file mode 100644 index 000000000..310b01278 --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom @@ -0,0 +1,31 @@ + + 3 + v3artifact + test + 1.0.0 + + + 1.0 + 1.0 + 1_0 + + + + + groupId + artifactId + version + + + groupId + test-artifactId + version + + test + + + + + scm:cvs:ext:${maven.username}@localhost:/home/cvs + + diff --git a/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom b/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom new file mode 100644 index 000000000..fa6e82b1e --- /dev/null +++ b/maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + test + v4artifact + 1.0.0 + diff --git a/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar b/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar new file mode 100644 index 000000000..27597bc21 --- /dev/null +++ b/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar @@ -0,0 +1 @@ +unmodified diff --git a/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom b/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom new file mode 100644 index 000000000..c570979f4 --- /dev/null +++ b/maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom @@ -0,0 +1,22 @@ + + + + 4.0.0 + unmodified-artifact + test + 1.0.0 + diff --git a/pom.xml b/pom.xml index 5d735f788..fa5cc6e17 100644 --- a/pom.xml +++ b/pom.xml @@ -130,6 +130,7 @@ maven-repository-application + maven-repository-converter maven-repository-discovery maven-repository-reports-standard maven-repository-indexer @@ -198,6 +199,11 @@ maven-artifact-manager 2.0 + + org.apache.maven + maven-model-converter + 2.0.2-SNAPSHOT + org.apache.maven.wagon wagon-provider-api @@ -218,6 +224,11 @@ wagon-http-lightweight 1.0-alpha-5 + + org.apache.maven.repository + maven-repository-reports-standard + ${pom.version} + org.apache.maven.repository maven-repository-discovery