o Fixed bash scripts (cygwin option was being tested incorrectly, and resulting in no such file: cygpath)

o Changed POM handling to use ArtifactMetadata API rather than direct Artifact construction for POMs
o Streamlined ArtifactDigestor to avoid use of byte arrays for transfer between methods (resulted in a bit of cut-and-paste code, but should run better)
o Pegged OutOfMemoryError to the ArtifactDigestVerifier/ArtifactDigestor combo (motivated the previous change)
o Cleaned up artifact source-file checking before creating any of the target directory structures
o Maybe works, maybe not...will resume testing tomorrow or the next day


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-04-02 02:17:19 +00:00
parent 97eb92041d
commit dc92832ad2
16 changed files with 226 additions and 159 deletions

View File

@ -15,7 +15,7 @@ case "`uname`" in
CYGWIN*) cygwin=true ;;
esac
if [ $cygwin ]; then
if [ $cygwin == true ]; then
CP=`cygpath -pw $CP`
fi
@ -28,4 +28,4 @@ if [ "$1" == "profile" ]; then
shift
fi
java $JAVA_OPTS -classpath ${CP} org.apache.maven.tools.repoclean.Main $* | tee repoclean-log.txt
nice -n 19 java -Xmx128M -Xms64M -Xincgc $JAVA_OPTS -classpath ${CP} org.apache.maven.tools.repoclean.Main $* | tee repoclean-log.txt

View File

@ -17,8 +17,10 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.tools.repoclean.artifact.metadata.ProjectMetadata;
import org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier;
import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
import org.apache.maven.tools.repoclean.report.Reporter;
@ -182,6 +184,7 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
try
{
logger.info("Rewriting " + artifacts.size() + " artifacts (Should be " + (artifacts.size() * 2) + " rewrites including POMs).");
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
@ -194,101 +197,108 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
boolean errorOccurred = false;
File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) );
File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
artifact.setFile( artifactSource );
try
if(artifactSource.exists())
{
if ( !configuration.reportOnly() )
File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
artifact.setFile( artifactSource );
try
{
if(logger.isDebugEnabled())
if ( !configuration.reportOnly() )
{
logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" );
logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" );
}
if(logger.isDebugEnabled())
{
logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" );
logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" );
}
File targetParent = artifactTarget.getParentFile();
if ( !targetParent.exists() )
File targetParent = artifactTarget.getParentFile();
if ( !targetParent.exists() )
{
targetParent.mkdirs();
}
if ( logger.isDebugEnabled() )
{
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource
+ "\' to \'" + artifactTarget + "\'." );
}
copyArtifact( artifact, artifactTarget, artifactReporter );
}
else
{
targetParent.mkdirs();
artifactReporter.info( "Skipping artifact copy (we're in report-only mode)." );
}
}
catch ( Exception e )
{
repoReporter.error( "Error transferring artifact[" + artifact.getId()
+ "] to the target repository.", e );
// if we can't copy the jar over, then skip the rest.
errorOccurred = true;
}
if ( !errorOccurred )
{
if ( logger.isDebugEnabled() )
{
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource
+ "\' to \'" + artifactTarget + "\'." );
logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'"
+ artifact.getGroupId() + "\'" );
}
copyArtifact( artifactSource, artifactTarget, artifactReporter );
try
{
artifactDigestVerifier.verifyDigest( artifact, artifactTarget, artifactReporter,
configuration.reportOnly() );
}
catch ( Exception e )
{
repoReporter.error( "Error verifying digest for artifact[" + artifact.getId() + "]", e );
}
}
else
if ( !errorOccurred )
{
artifactReporter.info( "Skipping artifact copy (we're in report-only mode)." );
ArtifactMetadata pom = new ProjectMetadata( artifact );
artifactPomRewriter = (ArtifactPomRewriter) container.lookup( ArtifactPomRewriter.ROLE,
configuration.getSourcePomVersion() );
File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata( pom ) );
File targetPom = new File( targetRepositoryBase, targetRepo.pathOfMetadata( pom ) );
try
{
artifactPomRewriter.rewrite( artifact, sourcePom, targetPom, artifactReporter,
configuration.reportOnly() );
}
catch ( Exception e )
{
repoReporter.error( "Error rewriting POM for artifact[" + artifact.getId()
+ "] into the target repository.", e );
}
}
}
catch ( Exception e )
else
{
repoReporter.error( "Error transferring artifact[" + artifact.getId()
+ "] to the target repository.", e );
// if we can't copy the jar over, then skip the rest.
errorOccurred = true;
artifactReporter.error("Cannot find source file for artifact: \'" + artifact.getId() + "\' under path: \'" + artifactSource + "\'");
}
if ( !errorOccurred )
{
if ( logger.isDebugEnabled() )
{
logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'"
+ artifact.getGroupId() + "\'" );
}
try
{
artifactDigestVerifier.verifyDigest( artifact, artifactTarget, artifactReporter,
configuration.reportOnly() );
}
catch ( Exception e )
{
repoReporter.error( "Error verifying digest for artifact[" + artifact.getId() + "]", e );
}
}
if ( !errorOccurred )
{
Artifact pomArtifact = buildPomArtifact( artifact );
artifactPomRewriter = (ArtifactPomRewriter) container.lookup( ArtifactPomRewriter.ROLE,
configuration.getSourcePomVersion() );
File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOf( pomArtifact ) );
File targetPom = new File( targetRepositoryBase, targetRepo.pathOf( pomArtifact ) );
try
{
artifactPomRewriter.rewrite( artifact, sourcePom, targetPom, artifactReporter,
configuration.reportOnly() );
}
catch ( Exception e )
{
repoReporter.error( "Error rewriting POM for artifact[" + artifact.getId()
+ "] into the target repository.", e );
}
}
if ( artifactReporter.hasError() )
{
repoReporter.warn( "Error(s) occurred while rewriting artifact: \'" + artifact.getId()
+ "\' or its POM." );
}
if ( artifactReporter.hasWarning() )
{
repoReporter.info( "Warning(s) occurred while rewriting artifact: \'" + artifact.getId()
+ "\' or its POM." );
}
}
catch(Exception e)
{
artifactReporter.error("Error while rewriting file or POM for artifact: \'" + artifact.getId() + "\'", e);
}
finally
{
@ -308,9 +318,11 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
}
}
private void copyArtifact( File artifactSource, File artifactTarget, Reporter reporter )
private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter )
throws IOException
{
File artifactSource = artifact.getFile();
InputStream inStream = null;
OutputStream outStream = null;
try
@ -342,12 +354,6 @@ private void copyArtifact( File artifactSource, File artifactTarget, Reporter re
}
}
private Artifact buildPomArtifact( Artifact artifact )
{
return artifactConstructionSupport.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getScope(), "pom" );
}
private File normalizeTargetRepositoryBase( String targetRepositoryPath )
{
Logger logger = getLogger();

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
import org.apache.maven.artifact.handler.AbstractArtifactHandler;

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
import org.apache.maven.artifact.handler.JarHandler;

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
/*
* Copyright 2001-2005 The Apache Software Foundation.

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
import org.apache.maven.artifact.handler.AbstractArtifactHandler;

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
import org.apache.maven.artifact.handler.JarHandler;

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
import org.apache.maven.artifact.handler.JarHandler;

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
/*
* Copyright 2001-2005 The Apache Software Foundation.

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
import org.apache.maven.artifact.handler.AbstractArtifactHandler;

View File

@ -1,4 +1,4 @@
package org.apache.maven.tools.repoclean.artifact;
package org.apache.maven.tools.repoclean.artifact.handler;
/*
* Copyright 2001-2005 The Apache Software Foundation.

View File

@ -0,0 +1,66 @@
package org.apache.maven.tools.repoclean.artifact.metadata;
/*
* Copyright 2001-2005 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.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Attach a POM to an artifact.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class ProjectMetadata
implements ArtifactMetadata
{
private final Artifact artifact;
public ProjectMetadata( Artifact artifact)
{
this.artifact = artifact;
}
public Artifact getArtifact()
{
return artifact;
}
public String getFilename()
{
return getArtifact().getArtifactId() + "-" + getArtifact().getVersion() + ".pom";
}
public void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
// not used in repoclean.
}
public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager )
{
// not used - TODO: again indicates bad design?
}
public void setArtifact( Artifact artifact )
{
// this should be immutable...
}
}

View File

@ -42,17 +42,6 @@ public void verifyDigest( Artifact artifact, File artifactTarget, Reporter repor
// create the digest target file from which to copy/create.
File digestTargetFile = new File( artifactTarget + ".md5" );
if(!reportOnly)
{
File targetParent = digestTargetFile.getParentFile();
if ( !targetParent.exists() )
{
reporter.info( "MD5 parent directory \'" + targetParent + "\' does not exist. Creating..." );
targetParent.mkdirs();
}
}
boolean verified = false;
// if the digest source file exists, then verify it.

View File

@ -4,14 +4,14 @@
import org.codehaus.plexus.util.IOUtil;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
/**
* @author jdcasey
@ -43,40 +43,49 @@ public void createArtifactDigest( File artifactFile, File digestFile, String alg
public boolean verifyArtifactDigest( File artifactFile, File digestFile, String algorithm )
throws ArtifactDigestException
{
boolean result = false;
if(artifactFile.exists() && digestFile.exists())
{
byte[] generatedDigest = generateArtifactDigest( artifactFile, algorithm );
byte[] digestFromFile = null;
InputStream in = null;
try
{
digestFromFile = readFile( digestFile );
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 ( Exception e )
catch ( IOException e )
{
throw new ArtifactDigestException( "Cannot read digest from file: \'" + digestFile + "\'", e );
throw new ArtifactDigestException("Cannot verify digest for artifact file: \'" + artifactFile + "\' against digest file: \'" + digestFile + "\' using algorithm: \'" + algorithm + "\'", e);
}
result = Arrays.equals( generatedDigest, digestFromFile );
finally
{
IOUtil.close( in );
}
}
else
{
return false;
}
return result;
return true;
}
private byte[] generateArtifactDigest( File artifactFile, String algorithm ) throws ArtifactDigestException
{
byte[] data = null;
try
{
data = readFile( artifactFile );
}
catch ( IOException e )
{
throw new ArtifactDigestException( "Error reading artifact data from: \'" + artifactFile + "\'", e );
}
MessageDigest digest = null;
try
{
@ -87,14 +96,33 @@ private byte[] generateArtifactDigest( File artifactFile, String algorithm ) thr
throw new ArtifactDigestException( "Cannot load digest algoritm provider.", e );
}
digest.update( data );
InputStream in = null;
try
{
in = new BufferedInputStream( new FileInputStream( artifactFile ) );
byte[] buffer = new byte[16];
int read = -1;
while ( ( read = in.read( buffer ) ) > -1 )
{
digest.update(buffer, 0, read);
}
}
catch ( IOException e )
{
throw new ArtifactDigestException( "Error reading artifact data from: \'" + artifactFile + "\'", e );
}
finally
{
IOUtil.close( in );
}
return digest.digest();
}
private void writeDigestFile( File digestFile, byte[] digestData ) throws IOException
{
FileOutputStream out = null;
OutputStream out = null;
try
{
out = new FileOutputStream( digestFile );
@ -107,27 +135,4 @@ private void writeDigestFile( File digestFile, byte[] digestData ) throws IOExce
}
}
private byte[] readFile( File artifactFile ) throws IOException
{
BufferedInputStream in = null;
try
{
in = new BufferedInputStream( new FileInputStream( artifactFile ) );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[16];
int read = -1;
while ( ( read = in.read( buffer ) ) > -1 )
{
baos.write( buffer, 0, read );
}
return baos.toByteArray();
}
finally
{
IOUtil.close( in );
}
}
}

View File

@ -130,10 +130,11 @@ else if ( lastAvceToken.endsWith( ".zip" ) )
avceTokenList.addLast( lastAvceToken );
}
String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + "([_.0-9ab]+)|"
String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + "([0-9][_.0-9a-zA-Z]*)|"
+ "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" + "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|"
+ "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" + "([Tt][Ee][Ss][Tt][_.0-9]*)|"
+ "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|"
+ "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|"
+ "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" + "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])";
// let's discover the version, and whatever's leftover will be either

View File

@ -8,7 +8,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>plugin</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.LegacyPluginHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.LegacyPluginHandler</implementation>
</component>
<!--
|
@ -18,7 +18,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>distribution</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.JarDistroHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.JarDistroHandler</implementation>
</component>
<!--
|
@ -28,7 +28,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>distribution-tgz</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.TgzDistroHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.TgzDistroHandler</implementation>
</component>
<!--
|
@ -38,7 +38,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>distribution-zip</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.ZipDistroHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.ZipDistroHandler</implementation>
</component>
<!--
|
@ -48,7 +48,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>tld</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.TldHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.TldHandler</implementation>
</component>
<!--
|
@ -58,7 +58,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>dtd</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.DtdHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.DtdHandler</implementation>
</component>
<!--
|
@ -68,7 +68,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ear</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.EarHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.EarHandler</implementation>
</component>
<!--
|
@ -78,7 +78,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>rar</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.RarHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.RarHandler</implementation>
</component>
<!--
|
@ -88,7 +88,7 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>sar</role-hint>
<implementation>org.apache.maven.tools.repoclean.artifact.SarHandler</implementation>
<implementation>org.apache.maven.tools.repoclean.artifact.handler.SarHandler</implementation>
</component>
<!--
|