git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@372710 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-0.9-alpha-1
@@ -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 ) |
@@ -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; | |||
/** |
@@ -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> |
@@ -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> |
@@ -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() |
@@ -0,0 +1 @@ | |||
v4 |
@@ -0,0 +1 @@ | |||
v3 |
@@ -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> |
@@ -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> |
@@ -0,0 +1 @@ | |||
unmodified |
@@ -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> |
@@ -0,0 +1,9 @@ | |||
<metadata> | |||
<groupId>test</groupId> | |||
<artifactId>newversion-artifact</artifactId> | |||
<versioning> | |||
<versions> | |||
<version>1.0.0</version> | |||
</versions> | |||
</versioning> | |||
</metadata> |