diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java index 930e1fed0d..13c3946628 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java @@ -1,8 +1,8 @@ package org.apache.maven.tools.repoclean; /* - * ==================================================================== Copyright 2001-2004 The - * Apache Software Foundation. + * ==================================================================== + * Copyright 2001-2004 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 @@ -21,13 +21,16 @@ 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.digest.DigestVerifier; import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer; import org.apache.maven.tools.repoclean.index.ArtifactIndexer; import org.apache.maven.tools.repoclean.report.FileReporter; +import org.apache.maven.tools.repoclean.report.PathLister; import org.apache.maven.tools.repoclean.report.ReportWriteException; import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter; +import org.apache.maven.tools.repoclean.transaction.RewriteTransaction; +import org.apache.maven.tools.repoclean.transaction.RollbackException; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.context.Context; @@ -48,6 +51,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -62,7 +66,9 @@ public class RepositoryCleaner public static final String ROLE = RepositoryCleaner.class.getName(); - private ArtifactDigestVerifier artifactDigestVerifier; + private static final String REPORTS_DIR_DATE_FORMAT = "dd-MMM-yyyy_hh.mm.ss"; + + private DigestVerifier digestVerifier; private ArtifactRepositoryLayout bridgingLayout; @@ -77,7 +83,7 @@ public class RepositoryCleaner public void cleanRepository( RepositoryCleanerConfiguration configuration ) throws Exception { - File reportsBase = normalizeReportsBase( configuration.getReportsPath() ); + File reportsBase = formatReportsBase( configuration.getReportsPath() ); File sourceRepositoryBase = normalizeSourceRepositoryBase( configuration.getSourceRepositoryPath() ); @@ -99,6 +105,10 @@ public class RepositoryCleaner ArtifactDiscoverer artifactDiscoverer = null; List artifacts = null; + + PathLister kickoutLister = null; + PathLister excludeLister = null; + try { artifactDiscoverer = (ArtifactDiscoverer) container.lookup( ArtifactDiscoverer.ROLE, configuration @@ -111,8 +121,14 @@ public class RepositoryCleaner try { + File kickoutsList = new File(reportsBase, "kickouts.txt"); + File excludesList = new File(reportsBase, "excludes.txt"); + + kickoutLister = new PathLister(kickoutsList); + excludeLister = new PathLister(excludesList); + artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter, - configuration.getBlacklistedPatterns() ); + configuration.getBlacklistedPatterns(), excludeLister, kickoutLister ); } catch ( Exception e ) { @@ -126,6 +142,9 @@ public class RepositoryCleaner { container.release( artifactDiscoverer ); } + + excludeLister.close(); + kickoutLister.close(); } if ( artifacts != null ) @@ -257,6 +276,8 @@ public class RepositoryCleaner { Artifact artifact = (Artifact) it.next(); + RewriteTransaction transaction = new RewriteTransaction( artifact ); + String artifactReportPath = buildArtifactReportPath( artifact ); FileReporter artifactReporter = null; @@ -269,6 +290,8 @@ public class RepositoryCleaner File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) ); File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) ); + transaction.addFile( artifactTarget ); + artifact.setFile( artifactSource ); boolean targetMissingOrOlder = !artifactTarget.exists() @@ -278,6 +301,8 @@ public class RepositoryCleaner { actualRewriteCount++; + transaction.addFile( artifactTarget ); + try { if ( !configuration.reportOnly() ) @@ -291,6 +316,8 @@ public class RepositoryCleaner File targetParent = artifactTarget.getParentFile(); if ( !targetParent.exists() ) { + transaction.addFile( targetParent ); + targetParent.mkdirs(); } @@ -308,55 +335,64 @@ public class RepositoryCleaner 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; + throw e; } - if ( !errorOccurred ) + if ( logger.isDebugEnabled() ) { - 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 ); - } + logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'" + + artifact.getGroupId() + "\'" ); } - if ( !errorOccurred ) + try { - ArtifactMetadata pom = new ProjectMetadata( artifact ); + digestVerifier.verifyDigest( artifactSource, artifactTarget, transaction, + artifactReporter, configuration.reportOnly() ); + } + catch ( Exception e ) + { + repoReporter.error( "Error verifying digest for artifact[" + artifact.getId() + "]", e ); - artifactPomRewriter = (ArtifactPomRewriter) container.lookup( ArtifactPomRewriter.ROLE, - configuration - .getSourcePomVersion() ); + throw e; + } - File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata( pom ) ); + ArtifactMetadata pom = new ProjectMetadata( artifact ); - File targetPom = new File( targetRepositoryBase, targetRepo.pathOfMetadata( pom ) ); + artifactPomRewriter = (ArtifactPomRewriter) container.lookup( ArtifactPomRewriter.ROLE, + configuration + .getSourcePomVersion() ); - File bridgedTargetPom = new File( targetRepositoryBase, bridgingLayout.pathOfMetadata( pom ) ); + File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata( pom ) ); - try + File targetPom = new File( targetRepositoryBase, targetRepo.pathOfMetadata( pom ) ); + + transaction.addFile( targetPom ); + + File bridgedTargetPom = new File( targetRepositoryBase, bridgingLayout.pathOfMetadata( pom ) ); + + transaction.addFile( bridgedTargetPom ); + + try + { + artifactPomRewriter.rewrite( artifact, sourcePom, targetPom, artifactReporter, + configuration.reportOnly() ); + + boolean wroteBridge = bridgePomLocations( targetPom, bridgedTargetPom, artifactReporter ); + + digestVerifier.verifyDigest( sourcePom, targetPom, transaction, + artifactReporter, configuration.reportOnly() ); + + if(wroteBridge) { - artifactPomRewriter.rewrite( artifact, sourcePom, targetPom, artifactReporter, - configuration.reportOnly() ); - - bridgePomLocations( targetPom, bridgedTargetPom, artifactReporter ); - } - catch ( Exception e ) - { - repoReporter.error( "Error rewriting POM for artifact[" + artifact.getId() - + "] into the target repository.", e ); + digestVerifier.verifyDigest( sourcePom, bridgedTargetPom, transaction, + artifactReporter, configuration.reportOnly() ); } + + } + catch ( Exception e ) + { + repoReporter.error( "Error rewriting POM for artifact[" + artifact.getId() + + "] into the target repository.\n Error message: " + e.getMessage() ); } } @@ -380,6 +416,18 @@ public class RepositoryCleaner } catch ( Exception e ) { + if ( !configuration.force() ) + { + try + { + transaction.rollback(); + } + catch ( RollbackException re ) + { + repoReporter.error( "Error rolling back conversion transaction.", re ); + } + } + artifactReporter.error( "Error while rewriting file or POM for artifact: \'" + artifact.getId() + "\'. See report at: \'" + artifactReportPath + "\'.", e ); } @@ -404,13 +452,15 @@ public class RepositoryCleaner } } - private void bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter ) + private boolean bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter ) throws IOException, ReportWriteException { if ( targetPom.equals( bridgedTargetPom ) ) { reporter.warn( "Cannot create legacy-compatible copy of POM at: " + targetPom + "; legacy-compatible path is the same as the converted POM itself." ); + + return false; } FileInputStream in = null; @@ -428,6 +478,8 @@ public class RepositoryCleaner IOUtil.close( in ); IOUtil.close( out ); } + + return true; } private String buildArtifactReportPath( Artifact artifact ) @@ -522,23 +574,30 @@ public class RepositoryCleaner return sourceRepositoryBase; } - private File normalizeReportsBase( String reportsPath ) + private File formatReportsBase( String reportsPath ) { Logger logger = getLogger(); - File reportsBase = new File( reportsPath ); - if ( !reportsBase.exists() ) - { - logger.info( "Creating reports directory: \'" + reportsBase + "\'" ); + SimpleDateFormat dateFormat = new SimpleDateFormat( REPORTS_DIR_DATE_FORMAT ); - reportsBase.mkdirs(); - } - else if ( !reportsBase.isDirectory() ) + String subdir = dateFormat.format( new Date() ); + + File allReportsBase = new File( reportsPath ); + + File reportsBase = new File( allReportsBase, subdir ); + + if ( reportsBase.exists() && !reportsBase.isDirectory() ) { logger.error( "Cannot write reports to \'" + reportsBase + "\' because it is not a directory." ); reportsBase = null; } + else + { + logger.info( "Creating reports directory: \'" + reportsBase + "\'" ); + + reportsBase.mkdirs(); + } return reportsBase; } diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestException.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestException.java similarity index 85% rename from sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestException.java rename to sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestException.java index 2d1570b0f1..a5fba97a9e 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestException.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestException.java @@ -20,16 +20,16 @@ package org.apache.maven.tools.repoclean.digest; /** * @author jdcasey */ -public class ArtifactDigestException +public class DigestException extends Exception { - public ArtifactDigestException( String message ) + public DigestException( String message ) { super( message ); } - public ArtifactDigestException( String message, Throwable cause ) + public DigestException( String message, Throwable cause ) { super( message, cause ); } diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerificationException.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerificationException.java similarity index 76% rename from sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerificationException.java rename to sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerificationException.java index 40d8ac5198..a78155ef2d 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerificationException.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerificationException.java @@ -20,25 +20,25 @@ package org.apache.maven.tools.repoclean.digest; /** * @author jdcasey */ -public class ArtifactDigestVerificationException +public class DigestVerificationException extends Exception { - public ArtifactDigestVerificationException() + public DigestVerificationException() { } - public ArtifactDigestVerificationException( String message ) + public DigestVerificationException( String message ) { super( message ); } - public ArtifactDigestVerificationException( String message, Throwable cause ) + public DigestVerificationException( String message, Throwable cause ) { super( message, cause ); } - public ArtifactDigestVerificationException( Throwable cause ) + public DigestVerificationException( Throwable cause ) { super( cause ); } diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerifier.java similarity index 68% rename from sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java rename to sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerifier.java index f2d1cce020..7400f6364d 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/DigestVerifier.java @@ -17,9 +17,9 @@ package org.apache.maven.tools.repoclean.digest; * ==================================================================== */ -import org.apache.maven.artifact.Artifact; import org.apache.maven.tools.repoclean.report.ReportWriteException; import org.apache.maven.tools.repoclean.report.Reporter; +import org.apache.maven.tools.repoclean.transaction.RewriteTransaction; import org.codehaus.plexus.util.FileUtils; import java.io.File; @@ -28,35 +28,37 @@ import java.io.IOException; /** * @author jdcasey */ -public class ArtifactDigestVerifier +public class DigestVerifier { - public static final String ROLE = ArtifactDigestVerifier.class.getName(); + public static final String ROLE = DigestVerifier.class.getName(); - private ArtifactDigestor artifactDigestor; + private Digestor artifactDigestor; - public void setArtifactDigestor(ArtifactDigestor artifactDigestor) + public void setArtifactDigestor(Digestor artifactDigestor) { this.artifactDigestor = artifactDigestor; } - public void verifyDigest( Artifact artifact, File artifactTarget, Reporter reporter, boolean reportOnly ) - throws ArtifactDigestException, ReportWriteException, IOException + public void verifyDigest( File source, File target, RewriteTransaction transaction, Reporter reporter, boolean reportOnly ) + throws DigestException, ReportWriteException, IOException { - verifyDigestFile( artifact, artifactTarget, reporter, reportOnly, ".md5", ArtifactDigestor.MD5 ); + verifyDigestFile( source, target, transaction, reporter, reportOnly, ".md5", Digestor.MD5 ); - verifyDigestFile( artifact, artifactTarget, reporter, reportOnly, ".sha1", ArtifactDigestor.SHA ); + verifyDigestFile( source, target, transaction, reporter, reportOnly, ".sha1", Digestor.SHA ); } - private void verifyDigestFile( Artifact artifact, File artifactTarget, Reporter reporter, boolean reportOnly, + private void verifyDigestFile( File artifactSource, File artifactTarget, RewriteTransaction transaction, Reporter reporter, boolean reportOnly, String digestExt, String digestAlgorithm ) - throws ArtifactDigestException, ReportWriteException, IOException + throws DigestException, ReportWriteException, IOException { // create the digest source file from which to copy/verify. - File digestSourceFile = new File( artifact.getFile() + digestExt ); + File digestSourceFile = new File( artifactSource + digestExt ); // create the digest target file from which to copy/create. File digestTargetFile = new File( artifactTarget + digestExt ); + + transaction.addFile( digestTargetFile ); boolean verified = false; @@ -75,7 +77,7 @@ public class ArtifactDigestVerifier } catch ( IOException e ) { - reporter.error( "Cannot copy digest file for artifact[" + artifact.getId() + reporter.error( "Cannot copy digest file for path [" + artifactSource + "] from source to target for digest algorithm: \'" + digestAlgorithm + "\'.", e ); throw e; @@ -84,12 +86,12 @@ public class ArtifactDigestVerifier } else { - reporter.warn( digestExt + " for artifact[" + artifact.getId() + "] in target repository is wrong." ); + reporter.warn( digestExt + " for path [" + artifactSource + "] in target repository is wrong." ); } } else { - reporter.warn( digestExt + " for artifact[" + artifact.getId() + "] is missing in source repository." ); + reporter.warn( digestExt + " for path [" + artifactSource + "] is missing in source repository." ); } // if the .md5 was missing or did not verify correctly, create a new one diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestor.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java similarity index 83% rename from sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestor.java rename to sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java index 9ef350a035..a9455e52ce 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestor.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/Digestor.java @@ -16,17 +16,17 @@ import java.security.NoSuchAlgorithmException; /** * @author jdcasey */ -public class ArtifactDigestor +public class Digestor { - public static final String ROLE = ArtifactDigestor.class.getName(); + public static final String ROLE = Digestor.class.getName(); public static final String MD5 = "MD5"; public static final String SHA = "SHA"; public void createArtifactDigest( File artifactFile, File digestFile, String algorithm ) - throws ArtifactDigestException + throws DigestException { byte[] digestData = generateArtifactDigest( artifactFile, algorithm ); @@ -36,12 +36,12 @@ public class ArtifactDigestor } catch ( IOException e ) { - throw new ArtifactDigestException( "Cannot write digest to file: \'" + digestFile + "\'", e ); + throw new DigestException( "Cannot write digest to file: \'" + digestFile + "\'", e ); } } public boolean verifyArtifactDigest( File artifactFile, File digestFile, String algorithm ) - throws ArtifactDigestException + throws DigestException { if ( artifactFile.exists() && digestFile.exists() ) { @@ -68,7 +68,7 @@ public class ArtifactDigestor } catch ( IOException e ) { - throw new ArtifactDigestException( "Cannot verify digest for artifact file: \'" + artifactFile + throw new DigestException( "Cannot verify digest for artifact file: \'" + artifactFile + "\' against digest file: \'" + digestFile + "\' using algorithm: \'" + algorithm + "\'", e ); } finally @@ -86,7 +86,7 @@ public class ArtifactDigestor } public byte[] generateArtifactDigest( File artifactFile, String algorithm ) - throws ArtifactDigestException + throws DigestException { MessageDigest digest = null; try @@ -95,7 +95,7 @@ public class ArtifactDigestor } catch ( NoSuchAlgorithmException e ) { - throw new ArtifactDigestException( "Cannot load digest algoritm provider.", e ); + throw new DigestException( "Cannot load digest algoritm provider.", e ); } InputStream in = null; @@ -112,7 +112,7 @@ public class ArtifactDigestor } catch ( IOException e ) { - throw new ArtifactDigestException( "Error reading artifact data from: \'" + artifactFile + "\'", e ); + throw new DigestException( "Error reading artifact data from: \'" + artifactFile + "\'", e ); } finally { diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/AbstractArtifactDiscoverer.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/AbstractArtifactDiscoverer.java new file mode 100644 index 0000000000..974b043109 --- /dev/null +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/AbstractArtifactDiscoverer.java @@ -0,0 +1,68 @@ +package org.apache.maven.tools.repoclean.discover; + +import org.apache.maven.tools.repoclean.report.PathLister; +import org.apache.maven.tools.repoclean.report.ReportWriteException; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.DirectoryScanner; + +import java.io.File; + +/* + * 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. + */ + +public abstract class AbstractArtifactDiscoverer + extends AbstractLogEnabled + implements ArtifactDiscoverer +{ + + protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, PathLister excludesLister ) + throws ReportWriteException + { + String[] blacklisted = null; + if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 ) + { + blacklisted = blacklistedPatterns.split( "," ); + } + else + { + blacklisted = new String[0]; + } + + String[] allExcludes = new String[STANDARD_DISCOVERY_EXCLUDES.length + blacklisted.length]; + + System.arraycopy( STANDARD_DISCOVERY_EXCLUDES, 0, allExcludes, 0, STANDARD_DISCOVERY_EXCLUDES.length ); + System.arraycopy( blacklisted, 0, allExcludes, STANDARD_DISCOVERY_EXCLUDES.length, blacklisted.length ); + + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( repositoryBase ); + scanner.setExcludes( allExcludes ); + + scanner.scan(); + + String[] artifactPaths = scanner.getIncludedFiles(); + + String[] excludedPaths = scanner.getExcludedFiles(); + + for ( int i = 0; i < excludedPaths.length; i++ ) + { + String excludedPath = excludedPaths[i]; + excludesLister.addPath( excludedPath ); + } + + return artifactPaths; + } + +} diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java index f2f010a741..ba0af3fd2f 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java @@ -1,6 +1,7 @@ package org.apache.maven.tools.repoclean.discover; -import org.apache.maven.tools.repoclean.report.FileReporter; +import org.apache.maven.tools.repoclean.report.PathLister; +import org.apache.maven.tools.repoclean.report.Reporter; import java.io.File; import java.util.List; @@ -32,6 +33,9 @@ public interface ArtifactDiscoverer ".maven/**", "**/poms/*.pom", "**/*.md5", + "**/*.MD5", + "**/*.sha1", + "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", @@ -39,9 +43,14 @@ public interface ArtifactDiscoverer "**/.htaccess", "**/*.html", "**/*.asc", - "**/*.txt" }; + "**/*.txt", + "**/*.xml", + "**/README*", + "**/CHANGELOG*", + "**/KEYS*" }; - List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns ) + List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns, + PathLister excludeLister, PathLister kickoutLister ) throws Exception; } \ No newline at end of file diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java index 3e682075f4..13414f326c 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java @@ -4,8 +4,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.construction.ArtifactConstructionSupport; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.tools.repoclean.report.FileReporter; -import org.codehaus.plexus.util.DirectoryScanner; +import org.apache.maven.tools.repoclean.report.PathLister; +import org.apache.maven.tools.repoclean.report.Reporter; import org.codehaus.plexus.util.IOUtil; import java.io.File; @@ -31,44 +31,23 @@ import java.util.List; * @author jdcasey */ public class DefaultArtifactDiscoverer - implements ArtifactDiscoverer + extends AbstractArtifactDiscoverer { private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport(); - public List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns ) + public List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns, PathLister excludeLister, PathLister kickoutLister ) throws Exception { List artifacts = new ArrayList(); - String[] blacklisted = null; - if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 ) - { - blacklisted = blacklistedPatterns.split( "," ); - } - else - { - blacklisted = new String[0]; - } - - String[] allExcludes = new String[STANDARD_DISCOVERY_EXCLUDES.length + blacklisted.length]; - - System.arraycopy( STANDARD_DISCOVERY_EXCLUDES, 0, allExcludes, 0, STANDARD_DISCOVERY_EXCLUDES.length ); - System.arraycopy( blacklisted, 0, allExcludes, 0, blacklisted.length ); - - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( repositoryBase ); - scanner.setExcludes( allExcludes ); - - scanner.scan(); - - String[] artifactPaths = scanner.getIncludedFiles(); - + String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns, excludeLister ); + for ( int i = 0; i < artifactPaths.length; i++ ) { String path = artifactPaths[i]; - Artifact artifact = buildArtifact( repositoryBase, path, reporter ); + Artifact artifact = buildArtifact( repositoryBase, path, kickoutLister ); if ( artifact != null ) { @@ -79,7 +58,7 @@ public class DefaultArtifactDiscoverer return artifacts; } - private Artifact buildArtifact( File repositoryBase, String path, FileReporter reporter ) + private Artifact buildArtifact( File repositoryBase, String path, PathLister kickoutLister ) throws Exception { Artifact result = null; @@ -88,8 +67,7 @@ public class DefaultArtifactDiscoverer if ( lastDot < 0 ) { - reporter.error( "Found potential artifact file with invalid name. Path: \'" + path - + "\' doesn't seem to contain a file extension." ); + kickoutLister.addPath(path); } else { @@ -117,8 +95,7 @@ public class DefaultArtifactDiscoverer } else { - reporter.error( "POM not found for potential artifact at \'" + path - + "\'. Cannot create Artifact instance." ); + kickoutLister.addPath(path); } } diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java index df0c00ef45..8ac5ba70b4 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java @@ -16,9 +16,8 @@ package org.apache.maven.tools.repoclean.discover; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.construction.ArtifactConstructionSupport; -import org.apache.maven.tools.repoclean.report.FileReporter; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.DirectoryScanner; +import org.apache.maven.tools.repoclean.report.PathLister; +import org.apache.maven.tools.repoclean.report.Reporter; import java.io.File; import java.util.ArrayList; @@ -32,54 +31,24 @@ import java.util.StringTokenizer; * @author jdcasey */ public class LegacyArtifactDiscoverer - extends AbstractLogEnabled - implements ArtifactDiscoverer + extends AbstractArtifactDiscoverer { private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport(); - public List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns ) + public List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns, + PathLister excludeLister, PathLister kickoutLister ) throws Exception { List artifacts = new ArrayList(); - String[] blacklisted = null; - if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 ) - { - blacklisted = blacklistedPatterns.split( "," ); - } - else - { - blacklisted = new String[0]; - } - - String[] allExcludes = null; - - if ( blacklisted != null && blacklisted.length > 0 ) - { - allExcludes = new String[STANDARD_DISCOVERY_EXCLUDES.length + blacklisted.length ]; - - System.arraycopy( STANDARD_DISCOVERY_EXCLUDES, 0, allExcludes, 0, STANDARD_DISCOVERY_EXCLUDES.length ); - System.arraycopy( blacklisted, 0, allExcludes, STANDARD_DISCOVERY_EXCLUDES.length, blacklisted.length ); - } - else - { - allExcludes = STANDARD_DISCOVERY_EXCLUDES; - } - - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( repositoryBase ); - scanner.setExcludes( allExcludes ); - - scanner.scan(); - - String[] artifactPaths = scanner.getIncludedFiles(); + String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns, excludeLister ); for ( int i = 0; i < artifactPaths.length; i++ ) { String path = artifactPaths[i]; - Artifact artifact = buildArtifact( path, reporter ); + Artifact artifact = buildArtifact( path, kickoutLister ); if ( artifact != null ) { artifacts.add( artifact ); @@ -89,241 +58,257 @@ public class LegacyArtifactDiscoverer return artifacts; } - private Artifact buildArtifact( String path, FileReporter reporter ) + private Artifact buildArtifact( String path, PathLister kickoutLister ) throws Exception { - StringTokenizer tokens = new StringTokenizer( path, "/\\" ); - - int numberOfTokens = tokens.countTokens(); - - if ( numberOfTokens != 3 ) + try { - reporter.warn( "Artifact path: \'" + path - + "\' does not match naming convention. Cannot reliably extract artifact information from path." ); + StringTokenizer tokens = new StringTokenizer( path, "/\\" ); - return null; - } + int numberOfTokens = tokens.countTokens(); - String groupId = tokens.nextToken(); - - String type = tokens.nextToken(); - - if ( type.endsWith( "s" ) ) - { - type = type.substring( 0, type.length() - 1 ); - } - - // contains artifactId, version, classifier, and extension. - String avceGlob = tokens.nextToken(); - - LinkedList avceTokenList = new LinkedList(); - - StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" ); - while ( avceTokenizer.hasMoreTokens() ) - { - avceTokenList.addLast( avceTokenizer.nextToken() ); - } - - String lastAvceToken = (String) avceTokenList.removeLast(); - - if ( lastAvceToken.endsWith( ".tar.gz" ) ) - { - type = "distribution-tgz"; - - lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() ); - - avceTokenList.addLast( lastAvceToken ); - } - else if ( lastAvceToken.endsWith( ".zip" ) ) - { - type = "distribution-zip"; - - lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() ); - - avceTokenList.addLast( lastAvceToken ); - } - else - { - int extPos = lastAvceToken.lastIndexOf( '.' ); - - if ( extPos > 0 ) + if ( numberOfTokens != 3 ) { - String ext = lastAvceToken.substring( extPos + 1 ); - if ( type.equals( ext ) ) - { - lastAvceToken = lastAvceToken.substring( 0, extPos ); + kickoutLister.addPath(path); - avceTokenList.addLast( lastAvceToken ); + return null; + } + + String groupId = tokens.nextToken(); + + String type = tokens.nextToken(); + + if ( type.endsWith( "s" ) ) + { + type = type.substring( 0, type.length() - 1 ); + } + + // contains artifactId, version, classifier, and extension. + String avceGlob = tokens.nextToken(); + + LinkedList avceTokenList = new LinkedList(); + + StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" ); + while ( avceTokenizer.hasMoreTokens() ) + { + avceTokenList.addLast( avceTokenizer.nextToken() ); + } + + String lastAvceToken = (String) avceTokenList.removeLast(); + + if ( lastAvceToken.endsWith( ".tar.gz" ) ) + { + type = "distribution-tgz"; + + lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() ); + + avceTokenList.addLast( lastAvceToken ); + } + else if ( lastAvceToken.endsWith( ".zip" ) ) + { + type = "distribution-zip"; + + lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() ); + + avceTokenList.addLast( lastAvceToken ); + } + else + { + int extPos = lastAvceToken.lastIndexOf( '.' ); + + if ( extPos > 0 ) + { + String ext = lastAvceToken.substring( extPos + 1 ); + if ( type.equals( ext ) ) + { + lastAvceToken = lastAvceToken.substring( 0, extPos ); + + avceTokenList.addLast( lastAvceToken ); + } + else + { + kickoutLister.addPath(path); + + return null; + } + } + } + + 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 + // a classifier, or part of the artifactId, depending on position. + // Since version is at the end, we have to move in from the back. + Collections.reverse( avceTokenList ); + + StringBuffer classifierBuffer = new StringBuffer(); + StringBuffer versionBuffer = new StringBuffer(); + + boolean firstVersionTokenEncountered = false; + boolean firstToken = true; + + int tokensIterated = 0; + for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) + { + String token = (String) it.next(); + + boolean tokenIsVersionPart = token.matches( validVersionParts ); + + StringBuffer bufferToUpdate = null; + + // NOTE: logic in code is reversed, since we're peeling off the back + // Any token after the last versionPart will be in the classifier. + // Any token UP TO first non-versionPart is part of the version. + if ( !tokenIsVersionPart ) + { + if ( firstVersionTokenEncountered ) + { + break; + } + else + { + bufferToUpdate = classifierBuffer; + } } else { - reporter - .warn( "Artifact path: \'" - + path - + "\' does not match naming convention. Cannot reliably extract artifact information from path." ); + firstVersionTokenEncountered = true; - return null; + bufferToUpdate = versionBuffer; } - } - } - 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 - // a classifier, or part of the artifactId, depending on position. - // Since version is at the end, we have to move in from the back. - Collections.reverse( avceTokenList ); - - StringBuffer classifierBuffer = new StringBuffer(); - StringBuffer versionBuffer = new StringBuffer(); - - boolean firstVersionTokenEncountered = false; - boolean firstToken = true; - - int tokensIterated = 0; - for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) - { - String token = (String) it.next(); - - boolean tokenIsVersionPart = token.matches( validVersionParts ); - - StringBuffer bufferToUpdate = null; - - // NOTE: logic in code is reversed, since we're peeling off the back - // Any token after the last versionPart will be in the classifier. - // Any token UP TO first non-versionPart is part of the version. - if ( !tokenIsVersionPart ) - { - if ( firstVersionTokenEncountered ) + if ( firstToken ) { - break; + firstToken = false; } else { - bufferToUpdate = classifierBuffer; + bufferToUpdate.insert( 0, '-' ); } + + bufferToUpdate.insert( 0, token ); + + tokensIterated++; + } + + getLogger().debug( + "After parsing loop, state of buffers:\no Version Buffer: \'" + versionBuffer + + "\'\no Classifier Buffer: \'" + classifierBuffer + + "\'\no Number of Tokens Iterated: " + tokensIterated ); + + // Now, restore the proper ordering so we can build the artifactId. + Collections.reverse( avceTokenList ); + + getLogger().debug( + "Before repairing bad version and/or cleaning up used tokens, avce token list is:\n" + + avceTokenList ); + + // if we didn't find a version, then punt. Use the last token + // as the version, and set the classifier empty. + if ( versionBuffer.length() < 1 ) + { + if ( avceTokenList.size() > 1 ) + { + int lastIdx = avceTokenList.size() - 1; + + versionBuffer.append( avceTokenList.get( lastIdx ) ); + avceTokenList.remove( lastIdx ); + } + else + { + getLogger().warn( "Cannot parse version from artifact path: \'" + path + "\'." ); + getLogger().info( + "artifact-version-classifier-extension remaining tokens is: \'" + avceTokenList + + "\'" ); + } + + classifierBuffer.setLength( 0 ); } else { - firstVersionTokenEncountered = true; + getLogger().debug( "Removing " + tokensIterated + " tokens from avce token list." ); - bufferToUpdate = versionBuffer; + // if everything is kosher, then pop off all the classifier and + // version tokens, leaving the naked artifact id in the list. + avceTokenList = new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - ( tokensIterated ) ) ); } - if ( firstToken ) + getLogger().debug( "Now, remainder of avce token list is:\n" + avceTokenList ); + + StringBuffer artifactIdBuffer = new StringBuffer(); + + firstToken = true; + for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) { - firstToken = false; + String token = (String) it.next(); + + if ( firstToken ) + { + firstToken = false; + } + else + { + artifactIdBuffer.append( '-' ); + } + + artifactIdBuffer.append( token ); + } + + String artifactId = artifactIdBuffer.toString(); + + int lastVersionCharIdx = versionBuffer.length() - 1; + if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' ) + { + versionBuffer.setLength( lastVersionCharIdx ); + } + + String version = versionBuffer.toString(); + + if ( version.length() < 1 ) + { + version = null; + } + + getLogger().debug( + "Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n" + + "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + + "version: \'" + version + "\'\n" + "classifier: \'" + classifierBuffer.toString() + + "\'" ); + + Artifact result = null; + + if ( classifierBuffer.length() > 0 ) + { + getLogger().debug( "Creating artifact with classifier." ); + + result = artifactConstructionSupport.createArtifactWithClassifier( groupId, artifactId, version, + Artifact.SCOPE_RUNTIME, type, + classifierBuffer.toString() ); } else { - bufferToUpdate.insert( 0, '-' ); + result = artifactConstructionSupport.createArtifact( groupId, artifactId, version, + Artifact.SCOPE_RUNTIME, type ); } - bufferToUpdate.insert( 0, token ); + getLogger().debug( + "Resulting artifact is: " + result.getId() + " and has classifier of: " + + result.getClassifier() + "\n\n" ); - tokensIterated++; + return result; } - - getLogger().debug( - "After parsing loop, state of buffers:\no Version Buffer: \'" + versionBuffer - + "\'\no Classifier Buffer: \'" + classifierBuffer - + "\'\no Number of Tokens Iterated: " + tokensIterated ); - - // Now, restore the proper ordering so we can build the artifactId. - Collections.reverse( avceTokenList ); - - getLogger().debug( - "Before repairing bad version and/or cleaning up used tokens, avce token list is:\n" - + avceTokenList ); - - // if we didn't find a version, then punt. Use the last token - // as the version, and set the classifier empty. - if ( versionBuffer.length() < 1 ) + catch ( RuntimeException e ) { - int lastIdx = avceTokenList.size() - 1; + getLogger().error( "While parsing artifact path: \'" + path + "\'...\n\n", e ); - versionBuffer.append( avceTokenList.get( lastIdx ) ); - avceTokenList.remove( lastIdx ); - - classifierBuffer.setLength( 0 ); + throw e; } - else - { - getLogger().debug( "Removing " + tokensIterated + " tokens from avce token list." ); - - // if everything is kosher, then pop off all the classifier and - // version tokens, leaving the naked artifact id in the list. - avceTokenList = new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - ( tokensIterated ) ) ); - } - - getLogger().debug( "Now, remainder of avce token list is:\n" + avceTokenList ); - - StringBuffer artifactIdBuffer = new StringBuffer(); - - firstToken = true; - for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) - { - String token = (String) it.next(); - - if ( firstToken ) - { - firstToken = false; - } - else - { - artifactIdBuffer.append( '-' ); - } - - artifactIdBuffer.append( token ); - } - - String artifactId = artifactIdBuffer.toString(); - - int lastVersionCharIdx = versionBuffer.length() - 1; - if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' ) - { - versionBuffer.setLength( lastVersionCharIdx ); - } - - String version = versionBuffer.toString(); - - if ( version.length() < 1 ) - { - version = null; - } - - getLogger().debug( - "Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n" - + "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + "version: \'" - + version + "\'\n" + "classifier: \'" + classifierBuffer.toString() + "\'" ); - - Artifact result = null; - - if ( classifierBuffer.length() > 0 ) - { - getLogger().debug( "Creating artifact with classifier." ); - - result = artifactConstructionSupport.createArtifactWithClassifier( groupId, artifactId, version, - Artifact.SCOPE_RUNTIME, type, - classifierBuffer.toString() ); - } - else - { - result = artifactConstructionSupport.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, - type ); - } - - getLogger().debug( - "Resulting artifact is: " + result.getId() + " and has classifier of: " - + result.getClassifier() + "\n\n" ); - - return result; } } \ No newline at end of file diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/PathLister.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/PathLister.java new file mode 100644 index 0000000000..9d98b98678 --- /dev/null +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/report/PathLister.java @@ -0,0 +1,86 @@ +package org.apache.maven.tools.repoclean.report; + +import org.codehaus.plexus.util.IOUtil; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; + +/* + * 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. + */ + +public class PathLister +{ + + private final File listFile; + + private Writer writer; + + public PathLister( File listFile ) + { + this.listFile = listFile; + } + + private synchronized void checkOpen() throws ReportWriteException + { + if(writer == null) + { + try + { + writer = new FileWriter(listFile); + } + catch ( IOException e ) + { + throw new ReportWriteException( "Cannot open listFile for writing: " + listFile, e ); + } + } + } + + public void close() + { + IOUtil.close( writer ); + } + + public void addPath( String path ) throws ReportWriteException + { + checkOpen(); + + try + { + writer.write( path + "\n" ); + } + catch ( IOException e ) + { + throw new ReportWriteException( "Cannot write path: " + path + " to listFile: " + listFile, e ); + } + } + + public void addPath( File path ) throws ReportWriteException + { + checkOpen(); + + try + { + writer.write( path + "\n" ); + } + catch ( IOException e ) + { + throw new ReportWriteException( "Cannot write path: " + path + " to listFile: " + listFile, e ); + } + } + +} diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java index e73b27c120..d324f9100b 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java @@ -41,6 +41,13 @@ public class V3PomRewriter public void rewrite( Artifact artifact, File from, File to, FileReporter reporter, boolean reportOnly ) throws Exception { + // should only have to handle this here...v4 repos shouldn't have this + // problem... + String toPath = to.getPath(); + toPath = toPath.replace( '+', '-' ); + + File target = new File( toPath ); + Model v4Model = null; if ( from.exists() ) @@ -60,6 +67,8 @@ public class V3PomRewriter catch ( Exception e ) { reporter.error( "Invalid v3 POM at: \'" + from + "\'. Cannot read.", e ); + + throw e; } if(v3Model != null) @@ -95,7 +104,7 @@ public class V3PomRewriter FileWriter toWriter = null; try { - toWriter = new FileWriter( to ); + toWriter = new FileWriter( target ); MavenXpp3Writer v4Writer = new MavenXpp3Writer(); v4Writer.write( toWriter, v4Model ); } diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/transaction/RewriteTransaction.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/transaction/RewriteTransaction.java new file mode 100644 index 0000000000..0cf006c25f --- /dev/null +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/transaction/RewriteTransaction.java @@ -0,0 +1,57 @@ +package org.apache.maven.tools.repoclean.transaction; + +import org.apache.maven.artifact.Artifact; + +import java.io.File; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/* + * 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. + */ + +public class RewriteTransaction +{ + + private final Artifact artifact; + + private List files = new ArrayList(); + + public RewriteTransaction( Artifact artifact ) + { + this.artifact = artifact; + } + + public void addFile( File file ) + { + this.files.add( file ); + } + + public void rollback() + throws RollbackException + { + for ( Iterator it = files.iterator(); it.hasNext(); ) + { + File file = (File) it.next(); + if ( file.exists() && !file.delete() ) + { + throw new RollbackException( "[rollback] Cannot delete file: " + file + + "\nPart of transaction for artifact: {" + artifact.getId() + "}." ); + } + } + } + +} diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/transaction/RollbackException.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/transaction/RollbackException.java new file mode 100644 index 0000000000..916ce37511 --- /dev/null +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/transaction/RollbackException.java @@ -0,0 +1,33 @@ +package org.apache.maven.tools.repoclean.transaction; + +/* + * 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. + */ + +public class RollbackException + extends Exception +{ + + public RollbackException( String message, Throwable cause ) + { + super( message, cause ); + } + + public RollbackException( String message ) + { + super( message ); + } + +} diff --git a/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml b/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml index f9593cb62a..e67fe12a23 100644 --- a/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml +++ b/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml @@ -1,5 +1,30 @@ + + org.apache.maven.tools.repoclean.RepositoryCleaner + org.apache.maven.tools.repoclean.RepositoryCleaner + + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout + alpha-bridging + bridgingLayout + + + org.apache.maven.tools.repoclean.digest.DigestVerifier + + + org.apache.maven.tools.repoclean.index.ArtifactIndexer + + + org.codehaus.plexus.mailsender.MailSender + + + + org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout alpha-bridging @@ -100,31 +125,6 @@ sar org.apache.maven.tools.repoclean.artifact.handler.SarHandler - - - org.apache.maven.tools.repoclean.RepositoryCleaner - org.apache.maven.tools.repoclean.RepositoryCleaner - - - org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout - alpha-bridging - bridgingLayout - - - org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier - - - org.apache.maven.tools.repoclean.index.ArtifactIndexer - - - org.codehaus.plexus.mailsender.MailSender - - - - org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier - org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier + org.apache.maven.tools.repoclean.digest.DigestVerifier + org.apache.maven.tools.repoclean.digest.DigestVerifier - org.apache.maven.tools.repoclean.digest.ArtifactDigestor + org.apache.maven.tools.repoclean.digest.Digestor @@ -174,8 +174,8 @@ | --> - org.apache.maven.tools.repoclean.digest.ArtifactDigestor - org.apache.maven.tools.repoclean.digest.ArtifactDigestor + org.apache.maven.tools.repoclean.digest.Digestor + org.apache.maven.tools.repoclean.digest.Digestor