if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) ||
properties.containsKey( "relocated.version" ) )
{
- String newGroupId = v3Model.getGroupId();
- if ( properties.containsKey( "relocated.groupId" ) )
- {
- newGroupId = properties.getProperty( "relocated.groupId" );
- properties.remove( "relocated.groupId" );
- }
+ String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() );
+ properties.remove( "relocated.groupId" );
- String newArtifactId = v3Model.getArtifactId();
- if ( properties.containsKey( "relocated.artifactId" ) )
- {
- newArtifactId = properties.getProperty( "relocated.artifactId" );
- properties.remove( "relocated.artifactId" );
- }
+ String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() );
+ properties.remove( "relocated.artifactId" );
- String newVersion = v3Model.getVersion();
- if ( properties.containsKey( "relocated.version" ) )
- {
- newVersion = properties.getProperty( "relocated.version" );
- properties.remove( "relocated.version" );
- }
+ String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() );
+ properties.remove( "relocated.version" );
- String message = "";
- if ( properties.containsKey( "relocated.message" ) )
- {
- message = properties.getProperty( "relocated.message" );
- properties.remove( "relocated.message" );
- }
+ String message = properties.getProperty( "relocated.message", "" );
+ properties.remove( "relocated.message" );
if ( properties.isEmpty() )
{
private boolean testChecksums( Artifact artifact, File file, ArtifactReporter reporter )
throws IOException, RepositoryConversionException
{
- boolean result = true;
+ boolean result;
try
{
- File md5 = new File( file.getParentFile(), file.getName() + ".md5" );
- if ( md5.exists() )
- {
- String checksum = FileUtils.fileRead( md5 );
- if ( !digester.verifyChecksum( file, checksum, Digester.MD5 ) )
- {
- reporter.addFailure( artifact, getI18NString( "failure.incorrect.md5" ) );
- result = false;
- }
- }
-
- File sha1 = new File( file.getParentFile(), file.getName() + ".sha1" );
- if ( sha1.exists() )
- {
- String checksum = FileUtils.fileRead( sha1 );
- if ( !digester.verifyChecksum( file, checksum, Digester.SHA1 ) )
- {
- reporter.addFailure( artifact, getI18NString( "failure.incorrect.sha1" ) );
- result = false;
- }
- }
+ result = verifyChecksum( file, file.getName() + ".md5", Digester.MD5, reporter, artifact,
+ "failure.incorrect.md5" );
+ result = result && verifyChecksum( file, file.getName() + ".sha1", Digester.SHA1, reporter, artifact,
+ "failure.incorrect.sha1" );
}
catch ( NoSuchAlgorithmException e )
{
return result;
}
+ private boolean verifyChecksum( File file, String fileName, String algorithm, ArtifactReporter reporter,
+ Artifact artifact, String key )
+ throws IOException, NoSuchAlgorithmException
+ {
+ boolean result = true;
+
+ File md5 = new File( file.getParentFile(), fileName );
+ if ( md5.exists() )
+ {
+ String checksum = FileUtils.fileRead( md5 );
+ if ( !digester.verifyChecksum( file, checksum, algorithm ) )
+ {
+ reporter.addFailure( artifact, getI18NString( key ) );
+ result = false;
+ }
+ }
+ return result;
+ }
+
private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter,
FileTransaction transaction )
throws RepositoryConversionException
// TODO: check 2 warnings (extend and versions) matched on i18n key
}
- public void testV4SnapshotPomConvert()
- throws IOException, RepositoryConversionException
+ private void doTestV4SnapshotPomConvert( String version, String expectedMetadataFileName )
+ throws RepositoryConversionException, IOException
{
// test that it is copied as is
- Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0-SNAPSHOT" );
+ Artifact artifact = createArtifact( "test", "v4artifact", version );
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
File artifactMetadataFile = new File( targetRepository.getBasedir(),
targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
- expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-metadata.xml" );
+ expectedMetadataFile = getTestFile( expectedMetadataFileName );
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
compareFiles( expectedMetadataFile, snapshotMetadataFile );
}
- public void testV4TimestampedSnapshotPomConvert()
+ public void testV4SnapshotPomConvert()
throws IOException, RepositoryConversionException
{
- // test that it is copied as is
-
- Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0-20060111.120115-1" );
- ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
- 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 ) );
- snapshotMetadataFile.delete();
-
- repositoryConverter.convert( artifact, targetRepository, reporter );
- checkSuccess();
-
- 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 );
-
- assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
+ doTestV4SnapshotPomConvert( "1.0.0-SNAPSHOT", "src/test/expected-files/v4-snapshot-metadata.xml" );
- File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-artifact-metadata.xml" );
-
- compareFiles( expectedMetadataFile, artifactMetadataFile );
-
- assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
+ assertTrue( true );
+ }
- expectedMetadataFile = getTestFile( "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" );
+ public void testV4TimestampedSnapshotPomConvert()
+ throws IOException, RepositoryConversionException
+ {
+ doTestV4SnapshotPomConvert( "1.0.0-20060111.120115-1",
+ "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" );
- compareFiles( expectedMetadataFile, snapshotMetadataFile );
+ assertTrue( true );
}
public void testV3TimestampedSnapshotPomConvert()
//group metadata\r
if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )\r
{\r
+ // TODO! use pathOfMetadata\r
is = new FileInputStream(\r
new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ) );\r
repoMetadata = new GroupRepositoryMetadata( groupId );\r
//artifact metadata\r
else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )\r
{\r
+ // TODO! use pathOfMetadata\r
is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +\r
artifactId + "/" + filename ) );\r
repoMetadata =\r
//snapshot/version metadata\r
else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )\r
{\r
+ // TODO! use pathOfMetadata\r
is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +\r
artifactId + "/" + version + "/" + filename ) );\r
repoMetadata = new SnapshotArtifactRepositoryMetadata(\r
{\r
doc.add( Field.Text( FLD_VERSION, "" ) );\r
}\r
+ // TODO! do we need to add all these empty fields?\r
doc.add( Field.Text( FLD_DOCTYPE, METADATA ) );\r
doc.add( Field.Keyword( FLD_PACKAGING, "" ) );\r
doc.add( Field.Text( FLD_SHA1, "" ) );\r
doc.add( Field.Text( FLD_PLUGINS_ALL, "" ) );
}
doc.add( Field.UnIndexed( FLD_DOCTYPE, POM ) );
+ // TODO! do we need to add all these empty fields?
doc.add( Field.Text( FLD_PLUGINPREFIX, "" ) );
doc.add( Field.Text( FLD_LASTUPDATE, "" ) );
doc.add( Field.Text( FLD_NAME, "" ) );
public class ChecksumArtifactReporter
implements ArtifactReportProcessor
{
- /** @plexus.requirement */
+ /**
+ * @plexus.requirement
+ */
private Digester digester;
/**
String path = repository.pathOf( artifact );
File file = new File( repository.getBasedir(), path );
- File md5File = new File( repository.getBasedir(), path + ".md5" );
- if ( md5File.exists() )
- {
- try
- {
- if ( digester.verifyChecksum( file, FileUtils.fileRead( md5File ), Digester.MD5 ) )
- {
- reporter.addSuccess( artifact );
- }
- else
- {
- reporter.addFailure( artifact, "MD5 checksum does not match." );
- }
- }
- catch ( NoSuchAlgorithmException e )
- {
- reporter.addFailure( artifact, "Unable to read MD5: " + e.getMessage() );
- }
- catch ( IOException e )
- {
- reporter.addFailure( artifact, "Unable to read MD5: " + e.getMessage() );
- }
- }
- else
- {
- reporter.addFailure( artifact, "MD5 checksum file does not exist." );
- }
+ verifyChecksum( repository, path + ".md5", file, Digester.MD5, reporter, artifact );
+ verifyChecksum( repository, path + ".sha1", file, Digester.SHA1, reporter, artifact );
+ }
- File sha1File = new File( repository.getBasedir(), path + ".sha1" );
- if ( sha1File.exists() )
+ private void verifyChecksum( ArtifactRepository repository, String path, File file, String checksumAlgorithm,
+ ArtifactReporter reporter, Artifact artifact )
+ {
+ File checksumFile = new File( repository.getBasedir(), path );
+ if ( checksumFile.exists() )
{
try
{
- if ( digester.verifyChecksum( file, FileUtils.fileRead( sha1File ), Digester.SHA1 ) )
+ if ( digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm ) )
{
reporter.addSuccess( artifact );
}
else
{
- reporter.addFailure( artifact, "SHA-1 checksum does not match." );
+ reporter.addFailure( artifact, checksumAlgorithm + " checksum does not match." );
}
}
catch ( NoSuchAlgorithmException e )
{
- reporter.addFailure( artifact, "Unable to read SHA-1: " + e.getMessage() );
+ reporter.addFailure( artifact, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
}
catch ( IOException e )
{
- reporter.addFailure( artifact, "Unable to read SHA-1: " + e.getMessage() );
+ reporter.addFailure( artifact, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
}
}
else
{
- reporter.addFailure( artifact, "SHA-1 checksum file does not exist." );
+ reporter.addFailure( artifact, checksumAlgorithm + " checksum file does not exist." );
}
}
}
public class ChecksumMetadataReporter
implements MetadataReportProcessor
{
- /** @plexus.requirement */
+ /**
+ * @plexus.requirement
+ */
private Digester digester;
/**
String path = repository.pathOfRemoteRepositoryMetadata( metadata );
File file = new File( repository.getBasedir(), path );
- File md5File = new File( repository.getBasedir(), path + ".md5" );
- if ( md5File.exists() )
- {
- try
- {
- if ( digester.verifyChecksum( file, FileUtils.fileRead( md5File ), Digester.MD5 ) )
- {
- reporter.addSuccess( metadata );
- }
- else
- {
- reporter.addFailure( metadata, "MD5 checksum does not match." );
- }
- }
- catch ( NoSuchAlgorithmException e )
- {
- reporter.addFailure( metadata, "Unable to read MD5: " + e.getMessage() );
- }
- catch ( IOException e )
- {
- reporter.addFailure( metadata, "Unable to read MD5: " + e.getMessage() );
- }
- }
- else
- {
- reporter.addFailure( metadata, "MD5 checksum file does not exist." );
- }
+ verifyChecksum( repository, path + ".md5", file, Digester.MD5, reporter, metadata );
+ verifyChecksum( repository, path + ".sha1", file, Digester.SHA1, reporter, metadata );
+
+ }
- File sha1File = new File( repository.getBasedir(), path + ".sha1" );
- if ( sha1File.exists() )
+ private void verifyChecksum( ArtifactRepository repository, String path, File file, String checksumAlgorithm,
+ ArtifactReporter reporter, RepositoryMetadata metadata )
+ {
+ File checksumFile = new File( repository.getBasedir(), path );
+ if ( checksumFile.exists() )
{
try
{
- if ( digester.verifyChecksum( file, FileUtils.fileRead( sha1File ), Digester.SHA1 ) )
+ if ( digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm ) )
{
reporter.addSuccess( metadata );
}
else
{
- reporter.addFailure( metadata, "SHA-1 checksum does not match." );
+ reporter.addFailure( metadata, checksumAlgorithm + " checksum does not match." );
}
}
catch ( NoSuchAlgorithmException e )
{
- reporter.addFailure( metadata, "Unable to read SHA1: " + e.getMessage() );
+ reporter.addFailure( metadata, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
}
catch ( IOException e )
{
- reporter.addFailure( metadata, "Unable to read SHA1: " + e.getMessage() );
+ reporter.addFailure( metadata, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
}
}
else
{
- reporter.addFailure( metadata, "SHA-1 checksum file does not exist." );
+ reporter.addFailure( metadata, checksumAlgorithm + " checksum file does not exist." );
}
-
}
}
/**
* Method that discovers and indexes artifacts, poms and metadata in a default
- * m2 repository structure
+ * m2 repository structure.
*
* @throws MalformedURLException
* @throws RepositoryIndexException
+ * @todo why is this any different from legacy?
*/
protected void executeDiscovererInDefaultRepo()
throws MalformedURLException, RepositoryIndexException