* under the License.
*/
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Matcher;
-
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.archiva.transaction.FileTransaction;
import org.apache.maven.model.converter.ModelConverter;
import org.apache.maven.model.converter.PomTranslationException;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
+import org.codehaus.plexus.digest.Md5Digester;
+import org.codehaus.plexus.digest.Sha1Digester;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
/**
- * LegacyToDefaultConverter
+ * LegacyToDefaultConverter
*
* @version $Id$
- *
- * @plexus.component role="org.apache.maven.archiva.converter.artifact.ArtifactConverter"
- * role-hint="legacy-to-default"
+ * @plexus.component role="org.apache.maven.archiva.converter.artifact.ArtifactConverter"
+ * role-hint="legacy-to-default"
*/
+@Service( "artifactConverter#legacy-to-default" )
public class LegacyToDefaultConverter
implements ArtifactConverter
{
/**
- * {@link List}<{@link Digester}>
- *
- * @plexus.requirement role="org.codehaus.plexus.digest.Digester"
+ * {@link List}<{@link Digester}
+ * plexus.requirement role="org.codehaus.plexus.digest.Digester"
*/
private List<Digester> digesters;
+ @Inject
+ private PlexusSisuBridge plexusSisuBridge;
+
/**
- * @plexus.requirement
+ * plexus.requirement
*/
private ModelConverter translator;
private ArtifactHandlerManager artifactHandlerManager;
/**
- * @plexus.configuration default-value="false"
+ * plexus.configuration default-value="false"
*/
private boolean force;
/**
- * @plexus.configuration default-value="false"
+ * plexus.configuration default-value="false"
*/
private boolean dryrun;
- private Map<Artifact,List<String>> warnings = new HashMap<Artifact,List<String>>();
+ private Map<Artifact, List<String>> warnings = new HashMap<Artifact, List<String>>();
+
+ @PostConstruct
+ public void initialize()
+ throws ComponentLookupException
+ {
+ this.digesters = plexusSisuBridge.lookupList( Digester.class );
+ translator = plexusSisuBridge.lookup( ModelConverter.class );
+ artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class );
+ artifactHandlerManager = plexusSisuBridge.lookup( ArtifactHandlerManager.class );
+ }
public void convert( Artifact artifact, ArtifactRepository targetRepository )
throws ArtifactConversionException
}
catch ( TransactionException e )
{
- throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException( Messages.getString( "transaction.failure", e.getMessage() ),
+ e ); //$NON-NLS-1$
}
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
throws ArtifactConversionException
{
- Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact
- .getVersion() );
+ Artifact pom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion() );
pom.setBaseVersion( artifact.getBaseVersion() );
ArtifactRepository repository = artifact.getRepository();
File file = new File( repository.getBasedir(), repository.pathOf( pom ) );
catch ( IOException e )
{
throw new ArtifactConversionException(
- Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
+ Messages.getString( "unable.to.read.source.pom", e.getMessage() ), e ); //$NON-NLS-1$
}
if ( checksumsValid && contents.indexOf( "modelVersion" ) >= 0 ) //$NON-NLS-1$
}
catch ( IOException e )
{
- throw new ArtifactConversionException( Messages
- .getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException(
+ Messages.getString( "unable.to.write.target.pom", e.getMessage() ), e ); //$NON-NLS-1$
}
}
else
StringWriter writer = null;
try
{
- org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader = new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
+ org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader v3Reader =
+ new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
org.apache.maven.model.v3_0_0.Model v3Model = v3Reader.read( stringReader );
if ( doRelocation( artifact, v3Model, targetRepository, transaction ) )
{
- Artifact relocatedPom = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact
- .getArtifactId(), artifact.getVersion() );
+ Artifact relocatedPom =
+ artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion() );
targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( relocatedPom ) );
}
Model v4Model = translator.translate( v3Model );
- translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(), v3Model
- .getVersion(), v3Model.getPackage() );
+ translator.validateV4Basics( v4Model, v3Model.getGroupId(), v3Model.getArtifactId(),
+ v3Model.getVersion(), v3Model.getPackage() );
writer = new StringWriter();
MavenXpp3Writer Xpp3Writer = new MavenXpp3Writer();
}
catch ( IOException e )
{
- throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException( Messages.getString( "unable.to.write.converted.pom" ),
+ e ); //$NON-NLS-1$
}
catch ( PomTranslationException e )
{
boolean result = true;
for ( Digester digester : digesters )
{
- result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester, //$NON-NLS-1$
- artifact, "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
+ result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester,
+ //$NON-NLS-1$
+ artifact,
+ "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
}
return result;
}
}
catch ( FileNotFoundException e )
{
- throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
+ e ); //$NON-NLS-1$
}
catch ( IOException e )
{
- throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
+ e ); //$NON-NLS-1$
}
catch ( XmlPullParserException e )
{
- throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException( Messages.getString( "error.reading.target.metadata" ),
+ e ); //$NON-NLS-1$
}
finally
{
boolean result = true;
RepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
- File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
+ File file =
+ new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) );
if ( file.exists() )
{
Metadata metadata = readMetadata( file );
return result;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
{
String groupIdKey;
Metadata newMetadata, FileTransaction transaction )
throws ArtifactConversionException
{
- File file = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File file = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
Metadata metadata;
boolean changed;
}
catch ( IOException e )
{
- throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ), e ); //$NON-NLS-1$
+ throw new ArtifactConversionException( Messages.getString( "error.writing.target.metadata" ),
+ e ); //$NON-NLS-1$
}
finally
{
throws IOException
{
Properties properties = v3Model.getProperties();
- if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) //$NON-NLS-1$ //$NON-NLS-2$
+ if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" )
+ //$NON-NLS-1$ //$NON-NLS-2$
|| properties.containsKey( "relocated.version" ) ) //$NON-NLS-1$
{
String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() ); //$NON-NLS-1$
properties.remove( "relocated.groupId" ); //$NON-NLS-1$
- String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
+ String newArtifactId =
+ properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() ); //$NON-NLS-1$
properties.remove( "relocated.artifactId" ); //$NON-NLS-1$
String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() ); //$NON-NLS-1$
{
return warnings;
}
+
+
+ public List<Digester> getDigesters()
+ {
+ return digesters;
+ }
+
+ public void setDigesters( List<Digester> digesters )
+ {
+ this.digesters = digesters;
+ }
+
+ public ModelConverter getTranslator()
+ {
+ return translator;
+ }
+
+ public void setTranslator( ModelConverter translator )
+ {
+ this.translator = translator;
+ }
+
+ public ArtifactFactory getArtifactFactory()
+ {
+ return artifactFactory;
+ }
+
+ public void setArtifactFactory( ArtifactFactory artifactFactory )
+ {
+ this.artifactFactory = artifactFactory;
+ }
+
+ public ArtifactHandlerManager getArtifactHandlerManager()
+ {
+ return artifactHandlerManager;
+ }
+
+ public void setArtifactHandlerManager( ArtifactHandlerManager artifactHandlerManager )
+ {
+ this.artifactHandlerManager = artifactHandlerManager;
+ }
+
+ public boolean isForce()
+ {
+ return force;
+ }
+
+ public void setForce( boolean force )
+ {
+ this.force = force;
+ }
+
+ public boolean isDryrun()
+ {
+ return dryrun;
+ }
+
+ public void setDryrun( boolean dryrun )
+ {
+ this.dryrun = dryrun;
+ }
}
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.regex.Matcher;
-
+import junit.framework.TestCase;
+import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.regex.Matcher;
/**
- * LegacyToDefaultConverterTest
+ * LegacyToDefaultConverterTest
*
* @version $Id$
*/
+@RunWith( SpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class LegacyToDefaultConverterTest
- extends PlexusInSpringTestCase
+ extends TestCase
{
private ArtifactRepository sourceRepository;
private ArtifactFactory artifactFactory;
+ @Inject
+ private PlexusSisuBridge plexusSisuBridge;
+
+ @Inject
+ private ApplicationContext applicationContext;
+
private static final int SLEEP_MILLIS = 100;
- protected void setUp()
+ @Before
+ public void init()
throws Exception
{
super.setUp();
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
- ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
+ ArtifactRepositoryLayout layout =
+ (ArtifactRepositoryLayout) plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" );
File sourceBase = getTestFile( "src/test/source-repository" );
- sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
- null );
+ sourceRepository =
+ factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null );
- layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+ layout = (ArtifactRepositoryLayout) plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
File targetBase = getTestFile( "target/test-target-repository" );
copyDirectoryStructure( getTestFile( "src/test/target-repository" ), targetBase );
- targetRepository = factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null,
- null );
+ targetRepository =
+ factory.createArtifactRepository( "target", targetBase.toURL().toString(), layout, null, null );
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "legacy-to-default" );
+ artifactConverter =
+ applicationContext.getBean( "artifactConverter#legacy-to-default", ArtifactConverter.class );
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ artifactConverter.clearWarnings();
+ artifactFactory = (ArtifactFactory) plexusSisuBridge.lookup( ArtifactFactory.class );
}
- protected void tearDown()
- throws Exception
+ public static File getTestFile( String path )
{
- super.tearDown();
+ return new File( getBasedir(), path );
+ }
+
+ public static String getBasedir()
+ {
+ String basedir = System.getProperty( "basedir" );
+ if ( basedir == null )
+ {
+ basedir = new File( "" ).getAbsolutePath();
+ }
+
+ return basedir;
}
private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory )
{
if ( !destination.exists() && !destination.mkdirs() )
{
- throw new IOException( "Could not create destination directory '"
- + destination.getAbsolutePath() + "'." );
+ throw new IOException(
+ "Could not create destination directory '" + destination.getAbsolutePath() + "'." );
}
copyDirectoryStructure( file, destination );
}
}
}
+ @Test
public void testV4PomConvert()
throws Exception
{
Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ 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 ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
compareFiles( expectedMetadataFile, versionMetadataFile );
}
+ @Test
public void testV3PomConvert()
throws Exception
{
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ 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 ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
compareFiles( expectedMetadataFile, versionMetadataFile );
}
+ @Test
public void testV3PomConvertWithRelocation()
throws Exception
{
Artifact artifact = createArtifact( "test", "relocated-v3artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ 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 ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check if relocated artifact created", artifactFile.exists() );
- assertTrue( "Check if relocated artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
+ assertTrue( "Check if relocated artifact matches",
+ FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
Artifact pomArtifact = createArtifact( "relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom" );
File pomFile = getTestFile( "src/test/expected-files/" + targetRepository.pathOf( pomArtifact ) );
File testFile = getTestFile( "target/test-target-repository/" + targetRepository.pathOf( pomArtifact ) );
compareFiles( artifactFile, testFile );
}
+ @Test
public void testV3PomWarningsOnConvert()
throws Exception
{
Artifact artifact = createArtifact( "test", "v3-warnings-artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ 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 ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
versionMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
Artifact artifact = createArtifact( "test", "v4artifact", version );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
+ @Test
public void testV3SnapshotPomConvert()
throws Exception
{
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-SNAPSHOT" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
+ @Test
public void testV4SnapshotPomConvert()
throws Exception
{
assertTrue( true );
}
+ @Test
public void testV4TimestampedSnapshotPomConvert()
throws Exception
{
assertTrue( true );
}
+ @Test
public void testMavenOnePluginConversion()
throws Exception
{
- Artifact artifact = createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0",
- "maven-plugin" );
- artifact.setFile( new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
+ Artifact artifact =
+ createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0", "maven-plugin" );
+ artifact.setFile(
+ new File( getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) );
artifactConverter.convert( artifact, targetRepository );
// There is a warning but I can't figure out how to look at it. Eyeballing the results it appears
// the plugin is being coverted correctly.
*/
}
+ @Test
public void testV3TimestampedSnapshotPomConvert()
throws Exception
{
Artifact artifact = createArtifact( "test", "v3artifact", "1.0.0-20060105.130101-3" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
artifactMetadataFile.delete();
ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File snapshotMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
+ File snapshotMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
snapshotMetadataFile.delete();
artifactConverter.convert( artifact, targetRepository );
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
+ @Test
public void testNoPomConvert()
throws Exception
{
assertFalse( "No source POM", sourcePomFile.exists() );
}
+ @Test
public void testIncorrectSourceChecksumMd5()
throws Exception
{
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testIncorrectSourceChecksumSha1()
throws Exception
{
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testUnmodifiedArtifact()
throws Exception, InterruptedException
{
assertEquals( "Check POM unmodified", origPomTime, targetPomFile.lastModified() );
}
+ @Test
public void testModifedArtifactFails()
throws Exception
{
assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testForcedUnmodifiedArtifact()
throws Exception
{
// test unmodified artifact is still converted when set to force
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "force-repository-converter" );
+ artifactConverter =
+ applicationContext.getBean( "artifactConverter#force-repository-converter", ArtifactConverter.class );
Artifact artifact = createArtifact( "test", "unmodified-artifact", "1.0.0" );
Artifact pomArtifact = createPomArtifact( artifact );
assertFalse( "Check modified", origTime == targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertTrue( "Check metadata created", metadataFile.exists() );
}
+ @Test
public void testDryRunSuccess()
throws Exception
{
// test dry run does nothing on a run that will be successful, and returns success
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
+ artifactConverter =
+ applicationContext.getBean( "artifactConverter#dryrun-repository-converter", ArtifactConverter.class );
Artifact artifact = createArtifact( "test", "dryrun-artifact", "1.0.0" );
Artifact pomArtifact = createPomArtifact( artifact );
assertFalse( "Check target POM doesn't exist", targetPomFile.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testDryRunFailure()
throws Exception
{
// test dry run does nothing on a run that will fail, and returns failure
- artifactConverter = (ArtifactConverter) lookup( ArtifactConverter.ROLE, "dryrun-repository-converter" );
+ artifactConverter =
+ applicationContext.getBean( "artifactConverter#dryrun-repository-converter", ArtifactConverter.class );
Artifact artifact = createArtifact( "test", "modified-artifact", "1.0.0" );
Artifact pomArtifact = createPomArtifact( artifact );
assertEquals( "Check unmodified", origPomTime, targetPomFile.lastModified() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testRollbackArtifactCreated()
throws Exception
{
Artifact artifact = createArtifact( "test", "rollback-created-artifact", "1.0.0" );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ File artifactMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
FileUtils.deleteDirectory( artifactMetadataFile.getParentFile() );
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
- File versionMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( versionMetadata ) );
+ File versionMetadataFile = new File( targetRepository.getBasedir(),
+ targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) );
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
break;
}
}
-
+
if ( found )
{
break;
assertFalse( "check metadata rolled back", versionMetadataFile.exists() );
}
+ @Test
public void testMultipleArtifacts()
throws Exception
{
artifact = createPomArtifact( artifact );
File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
- File expectedPomFile = getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId()
- + ".pom" );
+ File expectedPomFile =
+ getTestFile( "src/test/expected-files/converted-" + artifact.getArtifactId() + ".pom" );
assertTrue( "Check POM created", pomFile.exists() );
compareFiles( expectedPomFile, pomFile );
}
}
+ @Test
public void testInvalidSourceArtifactMetadata()
throws Exception
{
artifactConverter.convert( artifact, targetRepository );
checkWarnings( artifactConverter, 2 );
- assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.artifactMetadata.versions" ) );
+ assertHasWarningReason( artifactConverter,
+ Messages.getString( "failure.incorrect.artifactMetadata.versions" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testInvalidSourceSnapshotMetadata()
throws Exception
{
artifactConverter.convert( artifact, targetRepository );
checkWarnings( artifactConverter, 2 );
- assertHasWarningReason( artifactConverter, Messages.getString( "failure.incorrect.snapshotMetadata.snapshot" ) );
+ assertHasWarningReason( artifactConverter,
+ Messages.getString( "failure.incorrect.snapshotMetadata.snapshot" ) );
assertFalse( "Check artifact not created", file.exists() );
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
- File metadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( metadata ) );
+ File metadataFile =
+ new File( targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata( metadata ) );
assertFalse( "Check metadata not created", metadataFile.exists() );
}
+ @Test
public void testMergeArtifactMetadata()
throws Exception
{
compareFiles( sourcePomFile, pomFile );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- File artifactMetadataFile = new File( targetRepository.getBasedir(), targetRepository
- .pathOfRemoteRepositoryMetadata( artifactMetadata ) );
+ 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 );
}
+ @Test
public void testSourceAndTargetRepositoriesMatch()
throws Exception
{
// test that it fails if the same
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
- sourceRepository = factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository
- .getLayout(), null, null );
+ sourceRepository =
+ factory.createArtifactRepository( "source", targetRepository.getUrl(), targetRepository.getLayout(), null,
+ null );
Artifact artifact = createArtifact( "test", "repository-artifact", "1.0" );
return createArtifact( groupId, artifactId, baseVersion, version, "jar" );
}
- private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version, String type )
+ private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
+ String type )
{
Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
artifact.setBaseVersion( baseVersion );
private Artifact createPomArtifact( Artifact artifact )
{
- return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(), artifact
- .getVersion(), "pom" );
+ return createArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion(),
+ artifact.getVersion(), "pom" );
}
private static void compareFiles( File expectedPomFile, File pomFile )
throws IOException
{
- String expectedContent = normalizeString( org.apache.commons.io.FileUtils.readFileToString( expectedPomFile, null ) );
+ String expectedContent =
+ normalizeString( org.apache.commons.io.FileUtils.readFileToString( expectedPomFile, null ) );
String targetContent = normalizeString( org.apache.commons.io.FileUtils.readFileToString( pomFile, null ) );
- assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent, targetContent );
+ assertEquals( "Check file match between " + expectedPomFile + " and " + pomFile, expectedContent,
+ targetContent );
}
private static String normalizeString( String path )
{
- return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>", "" ).replaceAll("^\\s+", "");
+ return path.trim().replaceAll( "\r\n", "\n" ).replace( '\r', '\n' ).replaceAll( "<\\?xml .+\\?>",
+ "" ).replaceAll( "^\\s+", "" );
}
private void checkSuccess( ArtifactConverter converter )
/* didn't find it. */
- for ( Map.Entry<Artifact,List<String>> entry : converter.getWarnings().entrySet() )
+ for ( Map.Entry<Artifact, List<String>> entry : converter.getWarnings().entrySet() )
{
Artifact artifact = (Artifact) entry.getKey();
- System.out.println( "-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
- + artifact.getVersion() );
+ System.out.println(
+ "-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() );
List<String> messages = entry.getValue();
for ( String message : messages )
{
private void createModernSourceRepository()
throws Exception
{
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class );
- ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+ ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "default" );
File sourceBase = getTestFile( "src/test/source-modern-repository" );
- sourceRepository = factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null,
- null );
+ sourceRepository =
+ factory.createArtifactRepository( "source", sourceBase.toURL().toString(), layout, null, null );
}
}