Solving MRM-4. If the source pom doesn't exist, it'll check for the existence of the target pom before writing the skeleton.

It'll always try to verify/patch the MD5/SHA1 for the target pom.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189785 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-09 18:19:21 +00:00
parent 8a257be6fc
commit d1e7f4d5ad
3 changed files with 79 additions and 52 deletions

View File

@ -54,17 +54,27 @@ public class DigestVerifier
throws DigestException, ReportWriteException, IOException
{
// create the digest source file from which to copy/verify.
File digestSourceFile = new File( artifactSource + digestExt );
File digestSourceFile = null;
if ( artifactSource != null )
{
digestSourceFile = new File( artifactSource + digestExt );
}
// create the digest target file from which to copy/create.
File digestTargetFile = new File( artifactTarget + digestExt );
File digestTargetFile = null;
transaction.addFile( digestTargetFile );
if ( artifactTarget != null )
{
digestTargetFile = new File( artifactTarget + digestExt );
transaction.addFile( digestTargetFile );
}
boolean verified = false;
// if the digest source file exists, then verify it.
if ( digestSourceFile.exists() )
if ( digestSourceFile != null && digestSourceFile.exists() )
{
verified = artifactDigestor.verifyArtifactDigest( artifactTarget, digestTargetFile, digestAlgorithm );

View File

@ -28,6 +28,11 @@ public class Digestor
public void createArtifactDigest( File artifactFile, File digestFile, String algorithm )
throws DigestException
{
if ( artifactFile == null || !artifactFile.exists() )
{
throw new DigestException( "Cannot generate digest for missing file: " + artifactFile );
}
byte[] digestData = generateArtifactDigest( artifactFile, algorithm );
try
@ -43,51 +48,53 @@ public class Digestor
public boolean verifyArtifactDigest( File artifactFile, File digestFile, String algorithm )
throws DigestException
{
if ( artifactFile.exists() && digestFile.exists() )
{
byte[] generatedDigest = generateArtifactDigest( artifactFile, algorithm );
InputStream in = null;
try
{
in = new FileInputStream( artifactFile );
int digestLen = generatedDigest.length;
int currentIdx = 0;
boolean matched = true;
int read = -1;
while ( ( read = in.read() ) > -1 )
{
if ( currentIdx >= digestLen || read != generatedDigest[currentIdx] )
{
return false;
}
}
}
catch ( IOException e )
{
throw new DigestException( "Cannot verify digest for artifact file: \'" + artifactFile
+ "\' against digest file: \'" + digestFile + "\' using algorithm: \'" + algorithm + "\'", e );
}
finally
{
IOUtil.close( in );
}
}
else
if ( digestFile == null || !digestFile.exists() || artifactFile == null || !artifactFile.exists() )
{
return false;
}
byte[] generatedDigest = generateArtifactDigest( artifactFile, algorithm );
InputStream in = null;
try
{
in = new FileInputStream( artifactFile );
int digestLen = generatedDigest.length;
int currentIdx = 0;
boolean matched = true;
int read = -1;
while ( ( read = in.read() ) > -1 )
{
if ( currentIdx >= digestLen || read != generatedDigest[currentIdx] )
{
return false;
}
}
}
catch ( IOException e )
{
throw new DigestException( "Cannot verify digest for artifact file: \'" + artifactFile
+ "\' against digest file: \'" + digestFile + "\' using algorithm: \'" + algorithm + "\'", e );
}
finally
{
IOUtil.close( in );
}
return true;
}
public byte[] generateArtifactDigest( File artifactFile, String algorithm )
throws DigestException
{
if ( artifactFile == null || !artifactFile.exists() )
{
throw new DigestException( "Cannot generate digest for missing file: " + artifactFile );
}
MessageDigest digest = null;
try
{

View File

@ -242,7 +242,7 @@ public class RewritePhase
String pomContents = null;
boolean pomNeedsRewriting = true;
boolean shouldRewritePom = true;
if ( sourcePom.exists() )
{
@ -250,13 +250,23 @@ public class RewritePhase
if ( pomContents.indexOf( "modelVersion" ) > -1 )
{
pomNeedsRewriting = false;
shouldRewritePom = false;
freshenSupplementalMetadata( pom, sourcePom, targetPom, transaction, artifactReporter, reportOnly );
}
}
else if( targetPom.exists() )
{
// we have a target pom for this artifact already, and we'll only be making up a new pom.
// let's leave the existing one alone.
shouldRewritePom = false;
}
if ( pomNeedsRewriting )
File bridgedTargetPom = null;
boolean wroteBridge = false;
if ( shouldRewritePom )
{
ArtifactPomRewriter artifactPomRewriter = null;
@ -267,7 +277,7 @@ public class RewritePhase
transaction.addFile( targetPom );
File bridgedTargetPom = new File( targetBase, bridgingLayout.pathOfMetadata( pom ).replace( '+', '-' ) );
bridgedTargetPom = new File( targetBase, bridgingLayout.pathOfMetadata( pom ).replace( '+', '-' ) );
transaction.addFile( bridgedTargetPom );
@ -295,16 +305,8 @@ public class RewritePhase
IOUtil.close( to );
}
boolean wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter,
wroteBridge = bridgePomLocations( pom, targetPom, bridgedTargetPom, artifactReporter,
transaction, reportOnly );
digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
if ( wroteBridge )
{
digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter,
reportOnly );
}
}
finally
{
@ -320,6 +322,14 @@ public class RewritePhase
}
}
}
digestVerifier.verifyDigest( sourcePom, targetPom, transaction, artifactReporter, reportOnly );
if ( wroteBridge )
{
digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, artifactReporter,
reportOnly );
}
}
private void freshenSupplementalMetadata( ArtifactMetadata metadata, File source, File target,