mirror of https://github.com/apache/maven.git
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:
parent
97eb92041d
commit
dc92832ad2
|
@ -15,7 +15,7 @@ case "`uname`" in
|
||||||
CYGWIN*) cygwin=true ;;
|
CYGWIN*) cygwin=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ $cygwin ]; then
|
if [ $cygwin == true ]; then
|
||||||
CP=`cygpath -pw $CP`
|
CP=`cygpath -pw $CP`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -28,4 +28,4 @@ if [ "$1" == "profile" ]; then
|
||||||
shift
|
shift
|
||||||
fi
|
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
|
||||||
|
|
|
@ -17,8 +17,10 @@ package org.apache.maven.tools.repoclean;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
|
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.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
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.digest.ArtifactDigestVerifier;
|
||||||
import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
|
import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
|
||||||
import org.apache.maven.tools.repoclean.report.Reporter;
|
import org.apache.maven.tools.repoclean.report.Reporter;
|
||||||
|
@ -182,6 +184,7 @@ public class RepositoryCleaner
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
logger.info("Rewriting " + artifacts.size() + " artifacts (Should be " + (artifacts.size() * 2) + " rewrites including POMs).");
|
||||||
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
Artifact artifact = (Artifact) it.next();
|
Artifact artifact = (Artifact) it.next();
|
||||||
|
@ -194,101 +197,108 @@ public class RepositoryCleaner
|
||||||
boolean errorOccurred = false;
|
boolean errorOccurred = false;
|
||||||
|
|
||||||
File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) );
|
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() + "\'" );
|
if(logger.isDebugEnabled())
|
||||||
logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" );
|
{
|
||||||
}
|
logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'" );
|
||||||
|
logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" );
|
||||||
|
}
|
||||||
|
|
||||||
File targetParent = artifactTarget.getParentFile();
|
File targetParent = artifactTarget.getParentFile();
|
||||||
if ( !targetParent.exists() )
|
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() )
|
if ( logger.isDebugEnabled() )
|
||||||
{
|
{
|
||||||
logger.debug( "Copying artifact[" + artifact.getId() + "] from \'" + artifactSource
|
logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'"
|
||||||
+ "\' to \'" + artifactTarget + "\'." );
|
+ 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()
|
artifactReporter.error("Cannot find source file for artifact: \'" + artifact.getId() + "\' under path: \'" + artifactSource + "\'");
|
||||||
+ "] 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( "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() )
|
if ( artifactReporter.hasError() )
|
||||||
{
|
{
|
||||||
repoReporter.warn( "Error(s) occurred while rewriting artifact: \'" + artifact.getId()
|
repoReporter.warn( "Error(s) occurred while rewriting artifact: \'" + artifact.getId()
|
||||||
+ "\' or its POM." );
|
+ "\' or its POM." );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( artifactReporter.hasWarning() )
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
repoReporter.info( "Warning(s) occurred while rewriting artifact: \'" + artifact.getId()
|
artifactReporter.error("Error while rewriting file or POM for artifact: \'" + artifact.getId() + "\'", e);
|
||||||
+ "\' or its POM." );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -308,9 +318,11 @@ public class RepositoryCleaner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyArtifact( File artifactSource, File artifactTarget, Reporter reporter )
|
private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
File artifactSource = artifact.getFile();
|
||||||
|
|
||||||
InputStream inStream = null;
|
InputStream inStream = null;
|
||||||
OutputStream outStream = null;
|
OutputStream outStream = null;
|
||||||
try
|
try
|
||||||
|
@ -342,12 +354,6 @@ public class RepositoryCleaner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Artifact buildPomArtifact( Artifact artifact )
|
|
||||||
{
|
|
||||||
return artifactConstructionSupport.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
|
||||||
artifact.getVersion(), artifact.getScope(), "pom" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private File normalizeTargetRepositoryBase( String targetRepositoryPath )
|
private File normalizeTargetRepositoryBase( String targetRepositoryPath )
|
||||||
{
|
{
|
||||||
Logger logger = getLogger();
|
Logger logger = getLogger();
|
||||||
|
|
|
@ -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;
|
import org.apache.maven.artifact.handler.AbstractArtifactHandler;
|
||||||
|
|
|
@ -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;
|
import org.apache.maven.artifact.handler.JarHandler;
|
||||||
|
|
|
@ -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.
|
* Copyright 2001-2005 The Apache Software Foundation.
|
|
@ -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;
|
import org.apache.maven.artifact.handler.AbstractArtifactHandler;
|
||||||
|
|
|
@ -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;
|
import org.apache.maven.artifact.handler.JarHandler;
|
||||||
|
|
|
@ -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;
|
import org.apache.maven.artifact.handler.JarHandler;
|
||||||
|
|
|
@ -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.
|
* Copyright 2001-2005 The Apache Software Foundation.
|
|
@ -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;
|
import org.apache.maven.artifact.handler.AbstractArtifactHandler;
|
||||||
|
|
|
@ -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.
|
* Copyright 2001-2005 The Apache Software Foundation.
|
|
@ -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...
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,17 +42,6 @@ public class ArtifactDigestVerifier
|
||||||
// create the digest target file from which to copy/create.
|
// create the digest target file from which to copy/create.
|
||||||
File digestTargetFile = new File( artifactTarget + ".md5" );
|
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;
|
boolean verified = false;
|
||||||
|
|
||||||
// if the digest source file exists, then verify it.
|
// if the digest source file exists, then verify it.
|
||||||
|
|
|
@ -4,14 +4,14 @@ package org.apache.maven.tools.repoclean.digest;
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jdcasey
|
* @author jdcasey
|
||||||
|
@ -43,40 +43,49 @@ public class ArtifactDigestor
|
||||||
public boolean verifyArtifactDigest( File artifactFile, File digestFile, String algorithm )
|
public boolean verifyArtifactDigest( File artifactFile, File digestFile, String algorithm )
|
||||||
throws ArtifactDigestException
|
throws ArtifactDigestException
|
||||||
{
|
{
|
||||||
boolean result = false;
|
|
||||||
|
|
||||||
if(artifactFile.exists() && digestFile.exists())
|
if(artifactFile.exists() && digestFile.exists())
|
||||||
{
|
{
|
||||||
byte[] generatedDigest = generateArtifactDigest( artifactFile, algorithm );
|
byte[] generatedDigest = generateArtifactDigest( artifactFile, algorithm );
|
||||||
byte[] digestFromFile = null;
|
|
||||||
|
InputStream in = null;
|
||||||
try
|
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);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
result = Arrays.equals( generatedDigest, digestFromFile );
|
{
|
||||||
|
IOUtil.close( in );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] generateArtifactDigest( File artifactFile, String algorithm ) throws ArtifactDigestException
|
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;
|
MessageDigest digest = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -87,14 +96,33 @@ public class ArtifactDigestor
|
||||||
throw new ArtifactDigestException( "Cannot load digest algoritm provider.", e );
|
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();
|
return digest.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDigestFile( File digestFile, byte[] digestData ) throws IOException
|
private void writeDigestFile( File digestFile, byte[] digestData ) throws IOException
|
||||||
{
|
{
|
||||||
FileOutputStream out = null;
|
OutputStream out = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
out = new FileOutputStream( digestFile );
|
out = new FileOutputStream( digestFile );
|
||||||
|
@ -107,27 +135,4 @@ public class ArtifactDigestor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -130,10 +130,11 @@ public class LegacyArtifactDiscoverer
|
||||||
avceTokenList.addLast( lastAvceToken );
|
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]*)|"
|
+ "([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]*)|"
|
+ "([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]*)|"
|
+ "([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])";
|
+ "([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
|
// let's discover the version, and whatever's leftover will be either
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>plugin</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>distribution</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>distribution-tgz</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>distribution-zip</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>tld</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>dtd</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>ear</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>rar</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
|
||||||
<role-hint>sar</role-hint>
|
<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>
|
</component>
|
||||||
<!--
|
<!--
|
||||||
|
|
|
|
||||||
|
|
Loading…
Reference in New Issue