Selaa lähdekoodia

[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
tags/archiva-0.9-alpha-1
Brett Porter 18 vuotta sitten
vanhempi
commit
080a93a597
32 muutettua tiedostoa jossa 987 lisäystä ja 0 poistoa
  1. 41
    0
      maven-repository-converter/pom.xml
  2. 184
    0
      maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
  3. 31
    0
      maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java
  4. 50
    0
      maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java
  5. 6
    0
      maven-repository-converter/src/test/expected-files/converted-artifact-one.pom
  6. 6
    0
      maven-repository-converter/src/test/expected-files/converted-artifact-three.pom
  7. 6
    0
      maven-repository-converter/src/test/expected-files/converted-artifact-two.pom
  8. 22
    0
      maven-repository-converter/src/test/expected-files/converted-v3.pom
  9. 419
    0
      maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java
  10. 56
    0
      maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml
  11. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar
  12. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar
  13. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar
  14. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar
  15. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar
  16. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar
  17. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar.md5
  18. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar
  19. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar
  20. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar
  21. 1
    0
      maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar
  22. 6
    0
      maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom
  23. 6
    0
      maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom
  24. 6
    0
      maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom
  25. 22
    0
      maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom
  26. 22
    0
      maven-repository-converter/src/test/source-repository/test/poms/invalidMd5Artifact-1.0.0.pom
  27. 22
    0
      maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom
  28. 31
    0
      maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom
  29. 6
    0
      maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom
  30. 1
    0
      maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar
  31. 22
    0
      maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom
  32. 11
    0
      pom.xml

+ 41
- 0
maven-repository-converter/pom.xml Näytä tiedosto

@@ -0,0 +1,41 @@
<!--
~ 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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.apache.maven.repository</groupId>
<artifactId>maven-repository-manager</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-repository-converter</artifactId>
<name>Maven Repository Converter</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-converter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.repository</groupId>
<artifactId>maven-repository-reports-standard</artifactId>
</dependency>
</dependencies>
</project>

+ 184
- 0
maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java Näytä tiedosto

@@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @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 );
}
}
}

+ 31
- 0
maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConversionException.java Näytä tiedosto

@@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class RepositoryConversionException
extends Exception
{
public RepositoryConversionException( String message, Throwable cause )
{
super( message, cause );
}
}

+ 50
- 0
maven-repository-converter/src/main/java/org/apache/maven/repository/converter/RepositoryConverter.java Näytä tiedosto

@@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
*/
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;
}

+ 6
- 0
maven-repository-converter/src/test/expected-files/converted-artifact-one.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>artifact-one</artifactId>
<version>1.0.0</version>
</project>

+ 6
- 0
maven-repository-converter/src/test/expected-files/converted-artifact-three.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>artifact-three</artifactId>
<version>1.0.0</version>
</project>

+ 6
- 0
maven-repository-converter/src/test/expected-files/converted-artifact-two.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>artifact-two</artifactId>
<version>1.0.0</version>
</project>

+ 22
- 0
maven-repository-converter/src/test/expected-files/converted-v3.pom Näytä tiedosto

@@ -0,0 +1,22 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>v3artifact</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>

+ 419
- 0
maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java Näytä tiedosto

@@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @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" );
}

}

+ 56
- 0
maven-repository-converter/src/test/resources/org/apache/maven/repository/converter/RepositoryConverterTest.xml Näytä tiedosto

@@ -0,0 +1,56 @@
<!--
~ 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.
-->

<component-set>
<components>
<component>
<role>org.apache.maven.repository.converter.RepositoryConverter</role>
<implementation>org.apache.maven.repository.converter.DefaultRepositoryConverter</implementation>
<role-hint>force-repository-converter</role-hint>
<configuration>
<force>true</force>
</configuration>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<field-name>artifactFactory</field-name>
</requirement>
<requirement>
<role>org.apache.maven.model.converter.ArtifactPomRewriter</role>
<field-name>rewriter</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.repository.converter.RepositoryConverter</role>
<implementation>org.apache.maven.repository.converter.DefaultRepositoryConverter</implementation>
<role-hint>dryrun-repository-converter</role-hint>
<configuration>
<dryrun>true</dryrun>
</configuration>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<field-name>artifactFactory</field-name>
</requirement>
<requirement>
<role>org.apache.maven.model.converter.ArtifactPomRewriter</role>
<field-name>rewriter</field-name>
</requirement>
</requirements>
</component>
</components>
</component-set>

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/artifact-one-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
one

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/artifact-three-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
three

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/artifact-two-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
two

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/dryrun-artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
existing

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/existing-artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
existing

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
invalidMd5

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/invalidMd5Artifact-1.0.0.jar.md5 Näytä tiedosto

@@ -0,0 +1 @@
md5

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/noPomArtifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
noPom

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/unmodified-artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
unmodified

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/v3artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
v3

+ 1
- 0
maven-repository-converter/src/test/source-repository/test/jars/v4artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
v4

+ 6
- 0
maven-repository-converter/src/test/source-repository/test/poms/artifact-one-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>artifact-one</artifactId>
<version>1.0.0</version>
</project>

+ 6
- 0
maven-repository-converter/src/test/source-repository/test/poms/artifact-three-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>artifact-three</artifactId>
<version>1.0.0</version>
</project>

+ 6
- 0
maven-repository-converter/src/test/source-repository/test/poms/artifact-two-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>artifact-two</artifactId>
<version>1.0.0</version>
</project>

+ 22
- 0
maven-repository-converter/src/test/source-repository/test/poms/dryrun-artifact-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,22 @@
<!--
~ 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>dryrun-artifact</artifactId>
<groupId>test</groupId>
<currentVersion>1.0.0</currentVersion>
</project>

+ 22
- 0
maven-repository-converter/src/test/source-repository/test/poms/invalidMd5Artifact-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,22 @@
<!--
~ 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>
<artifactId>invalidMd5Artifact</artifactId>
<groupId>test</groupId>
<currentVersion>1.0.0</currentVersion>
</project>

+ 22
- 0
maven-repository-converter/src/test/source-repository/test/poms/unmodified-artifact-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,22 @@
<!--
~ 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>unmodified-artifact</artifactId>
<groupId>test</groupId>
<currentVersion>1.0.0</currentVersion>
</project>

+ 31
- 0
maven-repository-converter/src/test/source-repository/test/poms/v3artifact-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,31 @@
<project>
<pomVersion>3</pomVersion>
<artifactId>v3artifact</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>

+ 6
- 0
maven-repository-converter/src/test/source-repository/test/poms/v4artifact-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>v4artifact</artifactId>
<version>1.0.0</version>
</project>

+ 1
- 0
maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.jar Näytä tiedosto

@@ -0,0 +1 @@
unmodified

+ 22
- 0
maven-repository-converter/src/test/target-repository/test/unmodified-artifact/1.0.0/unmodified-artifact-1.0.0.pom Näytä tiedosto

@@ -0,0 +1,22 @@
<!--
~ 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>unmodified-artifact</artifactId>
<groupId>test</groupId>
<currentVersion>1.0.0</currentVersion>
</project>

+ 11
- 0
pom.xml Näytä tiedosto

@@ -130,6 +130,7 @@
</build>
<modules>
<module>maven-repository-application</module>
<module>maven-repository-converter</module>
<module>maven-repository-discovery</module>
<module>maven-repository-reports-standard</module>
<module>maven-repository-indexer</module>
@@ -198,6 +199,11 @@
<artifactId>maven-artifact-manager</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-converter</artifactId>
<version>2.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
@@ -218,6 +224,11 @@
<artifactId>wagon-http-lightweight</artifactId>
<version>1.0-alpha-5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.repository</groupId>
<artifactId>maven-repository-reports-standard</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.repository</groupId>
<artifactId>maven-repository-discovery</artifactId>

Loading…
Peruuta
Tallenna