From 5b5a124caa068d8cd6d3076046c7e3a2d51c4aa1 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 1 Apr 2005 02:45:05 +0000 Subject: [PATCH] o Updated the repo layout classes to use direct string concatenation rather than StringUtils.replace() which is not useful because the layout is non-varying. o Repoclean still not working with the new artifact/artifactmetadata stuff...the above modifications to the repo layout classes was primarily meant to improve performance when using repoclean. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163736 13f79535-47bb-0310-9956-ffa450edef68 --- .../layout/DefaultRepositoryLayout.java | 71 ++++++++++++++--- .../layout/LegacyRepositoryLayout.java | 70 ++++++++++++++--- .../apache/maven/tools/repoclean/Main.java | 78 ++++++++----------- .../tools/repoclean/RepositoryCleaner.java | 10 ++- .../digest/ArtifactDigestVerifier.java | 63 +++------------ .../translate/PomV3ToV4Translator.java | 23 +++++- 6 files changed, 194 insertions(+), 121 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java index fa0f20e814..65727ad89c 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java @@ -1,5 +1,11 @@ package org.apache.maven.artifact.repository.layout; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; +import org.apache.maven.artifact.metadata.ArtifactMetadata; + /* * Copyright 2001-2005 The Apache Software Foundation. * @@ -20,22 +26,69 @@ * @author jdcasey */ public class DefaultRepositoryLayout - extends AbstractArtifactRepositoryLayout + implements ArtifactRepositoryLayout { - protected String layoutPattern() + private ArtifactHandlerManager artifactHandlerManager; + + public String pathOf( Artifact artifact ) + throws ArtifactPathFormatException { - return "${groupPath}/${artifactId}/${baseVersion}/${artifactId}-${version}-${classifier}.${extension}"; + ArtifactHandler artifactHandler = null; + try + { + // TODO: this is a poor excuse to have this method throwing an exception. Validate the artifact first, perhaps associate the handler with it + artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + } + catch ( ArtifactHandlerNotFoundException e ) + { + throw new ArtifactPathFormatException( "Cannot find ArtifactHandler for artifact: \'" + artifact.getId() + + "\'.", e ); + } + + StringBuffer path = new StringBuffer(); + + path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' ); + path.append( artifact.getArtifactId() ).append( '/' ); + path.append( artifact.getBaseVersion() ).append( '/' ); + path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); + + if ( artifact.hasClassifier() ) + { + path.append( '-' ).append( artifact.getClassifier() ); + } + + path.append( '.' ).append( artifactHandler.extension() ); + + return path.toString(); } - protected String metadataLayoutPattern() + public String pathOfMetadata( ArtifactMetadata metadata ) + throws ArtifactPathFormatException { - return "${groupPath}/${artifactId}/${baseVersion}/${metadataFilename}"; - } + Artifact artifact = metadata.getArtifact(); - protected String groupIdAsPath( String groupId ) - { - return groupId.replace( '.', '/' ); + ArtifactHandler artifactHandler = null; + + try + { + // TODO: this is a poor excuse to have this method throwing an exception. Validate the artifact first, perhaps associate the handler with it + artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + } + catch ( ArtifactHandlerNotFoundException e ) + { + throw new ArtifactPathFormatException( "Cannot find ArtifactHandler for artifact: \'" + artifact.getId() + + "\'.", e ); + } + + StringBuffer path = new StringBuffer(); + + path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' ); + path.append( artifact.getArtifactId() ).append( '/' ); + path.append( artifact.getBaseVersion() ).append( '/' ); + path.append( metadata.getFilename() ); + + return path.toString(); } } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java index 0b320b7ffd..d10295c275 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java @@ -16,26 +16,76 @@ * limitations under the License. */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; +import org.apache.maven.artifact.metadata.ArtifactMetadata; + /** * @author jdcasey */ public class LegacyRepositoryLayout - extends AbstractArtifactRepositoryLayout + implements ArtifactRepositoryLayout { - protected String layoutPattern() + private ArtifactHandlerManager artifactHandlerManager; + + public String pathOf( Artifact artifact ) + throws ArtifactPathFormatException { - return "${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}"; + ArtifactHandler artifactHandler = null; + try + { + // TODO: this is a poor excuse to have this method throwing an exception. Validate the artifact first, perhaps associate the handler with it + artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + } + catch ( ArtifactHandlerNotFoundException e ) + { + throw new ArtifactPathFormatException( "Cannot find ArtifactHandler for artifact: \'" + artifact.getId() + + "\'.", e ); + } + + StringBuffer path = new StringBuffer(); + + path.append(artifact.getGroupId()).append('/'); + path.append(artifactHandler.directory()).append('/'); + path.append(artifact.getArtifactId()).append('-').append(artifact.getVersion()); + + if ( artifact.hasClassifier() ) + { + path.append('-').append(artifact.getClassifier()); + } + + path.append('.').append(artifactHandler.extension()); + + return path.toString(); } - protected String metadataLayoutPattern() + public String pathOfMetadata( ArtifactMetadata metadata ) + throws ArtifactPathFormatException { - return "${groupPath}/poms/${metadataFilename}"; - } - - protected String groupIdAsPath( String groupId ) - { - return groupId; + Artifact artifact = metadata.getArtifact(); + + ArtifactHandler artifactHandler = null; + + try + { + // TODO: this is a poor excuse to have this method throwing an exception. Validate the artifact first, perhaps associate the handler with it + artifactHandler = artifactHandlerManager.getArtifactHandler( artifact.getType() ); + } + catch ( ArtifactHandlerNotFoundException e ) + { + throw new ArtifactPathFormatException( "Cannot find ArtifactHandler for artifact: \'" + artifact.getId() + + "\'.", e ); + } + + StringBuffer path = new StringBuffer(); + + path.append(artifact.getGroupId()).append("/poms/"); + path.append(metadata.getFilename()); + + return path.toString(); } } \ No newline at end of file diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java index 40d5d83e46..f52b02c354 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java @@ -43,7 +43,7 @@ else if ( "-h".equals( args[0].toLowerCase() ) ) printHelp(); System.exit( 0 ); } - else if( "-template".equals( args[0] ) ) + else if ( "-template".equals( args[0] ) ) { printTemplate(); System.exit( 0 ); @@ -54,7 +54,7 @@ else if( "-template".equals( args[0] ) ) { embedder.start( new ClassWorld() ); - RepositoryCleanerConfiguration config = buildConfig(args[0]); + RepositoryCleanerConfiguration config = buildConfig( args[0] ); RepositoryCleaner cleaner = null; try @@ -77,67 +77,57 @@ else if( "-template".equals( args[0] ) ) } } - private static RepositoryCleanerConfiguration buildConfig( String configPath ) throws IOException + private static RepositoryCleanerConfiguration buildConfig( String configPath ) + throws IOException { Properties props = new Properties(); FileInputStream input = null; try { - input = new FileInputStream(configPath); - props.load(input); + input = new FileInputStream( configPath ); + props.load( input ); } finally { - IOUtil.close(input); + IOUtil.close( input ); } - + RepositoryCleanerConfiguration config = new RepositoryCleanerConfiguration(); - config.setSourceRepositoryPath(props.getProperty("sourceRepositoryPath")); - config.setSourceRepositoryLayout(props.getProperty("sourceRepositoryLayout", "legacy")); - config.setSourcePomVersion(props.getProperty("sourcePomVersion", "v3")); - config.setTargetRepositoryPath(props.getProperty("targetRepositoryPath")); - config.setTargetRepositoryLayout(props.getProperty("targetRepositoryLayout", "default")); - config.setReportsPath(props.getProperty("reportsPath")); - config.setReportOnly(Boolean.valueOf(props.getProperty("reportOnly")).booleanValue()); - + config.setSourceRepositoryPath( props.getProperty( "sourceRepositoryPath" ) ); + config.setSourceRepositoryLayout( props.getProperty( "sourceRepositoryLayout", "legacy" ) ); + config.setSourcePomVersion( props.getProperty( "sourcePomVersion", "v3" ) ); + config.setTargetRepositoryPath( props.getProperty( "targetRepositoryPath" ) ); + config.setTargetRepositoryLayout( props.getProperty( "targetRepositoryLayout", "default" ) ); + config.setReportsPath( props.getProperty( "reportsPath" ) ); + config.setReportOnly( Boolean.valueOf( props.getProperty( "reportOnly" ) ).booleanValue() ); + return config; } private static void printHelp() { - System.out.println("repoclean: Repository Cleaner/Converter.\n\n" + - "Usage: repoclean -h|-template|\n\n" + - "Where the configuration properfies file can contain the following options:\n" + - "---------------------------------------------------------------------------\n" + - "sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n" + - "sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" + - "sourcePomType=[v3|v4] #[DEFAULT: v3]\n" + - "targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n" + - "targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n" + - "reportsPath=/path/to/reports/directory #[REQUIRED]\n" + - "reportOnly=[true|false] #[REQUIRED]\n" + - "\n"); + System.out.println( "repoclean: Repository Cleaner/Converter.\n\n" + + "Usage: repoclean -h|-template|\n\n" + + "Where the configuration properfies file can contain the following options:\n" + + "---------------------------------------------------------------------------\n" + + "sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n" + + "sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" + "sourcePomType=[v3|v4] #[DEFAULT: v3]\n" + + "targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n" + + "targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n" + + "reportsPath=/path/to/reports/directory #[REQUIRED]\n" + "reportOnly=[true|false] #[REQUIRED]\n" + "\n" ); } private static void printTemplate() { - System.out.println( - "# ---------------------------------------------------------------------------\n" + - "# repoclean: Repository Cleaner/Converter.\n" + - "# This configuration auto-generated on: " + new java.util.Date() + "\n" + - "# ---------------------------------------------------------------------------\n\n" + - "# [REQUIRED OPTIONS]\n" + - "sourceRepositoryPath=/path/to/repository/root\n" + - "targetRepositoryPath=/path/to/repository/root\n" + - "reportsPath=/path/to/reports/directory\n" + - "reportOnly=[true|false]\n\n" + - "# [DEFAULT VALUE: legacy]\n" + - "#sourceRepositoryLayout=[legacy|default]\n\n" + - "# [DEFAULT VALUE: v3]\n" + - "#sourcePomType=[v3|v4]\n\n" + - "# [DEFAULT VALUE: default]\n" + - "#targetRepositoryLayout=[legacy|default]\n" + - "\n"); + System.out.println( "# ---------------------------------------------------------------------------\n" + + "# repoclean: Repository Cleaner/Converter.\n" + "# This configuration auto-generated on: " + + new java.util.Date() + "\n" + + "# ---------------------------------------------------------------------------\n\n" + + "# [REQUIRED OPTIONS]\n" + "sourceRepositoryPath=/path/to/repository/root\n" + + "targetRepositoryPath=/path/to/repository/root\n" + "reportsPath=/path/to/reports/directory\n" + + "reportOnly=[true|false]\n\n" + "# [DEFAULT VALUE: legacy]\n" + + "#sourceRepositoryLayout=[legacy|default]\n\n" + "# [DEFAULT VALUE: v3]\n" + "#sourcePomType=[v3|v4]\n\n" + + "# [DEFAULT VALUE: default]\n" + "#targetRepositoryLayout=[legacy|default]\n" + "\n" ); } private static void printUsage() 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 8c321f0b6a..09b7bd3896 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 @@ -193,6 +193,11 @@ 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 ( !configuration.reportOnly() ) @@ -203,9 +208,6 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" ); } - File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) ); - File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) ); - File targetParent = artifactTarget.getParentFile(); if ( !targetParent.exists() ) { @@ -244,7 +246,7 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR try { - artifactDigestVerifier.verifyDigest( artifact, sourceRepo, targetRepo, artifactReporter, + artifactDigestVerifier.verifyDigest( artifact, artifactTarget, artifactReporter, configuration.reportOnly() ); } catch ( Exception e ) 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/ArtifactDigestVerifier.java index c9a162babb..805651606d 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/ArtifactDigestVerifier.java @@ -1,14 +1,5 @@ package org.apache.maven.tools.repoclean.digest; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; -import org.apache.maven.tools.repoclean.report.Reporter; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; - /* ==================================================================== * Copyright 2001-2004 The Apache Software Foundation. * @@ -26,6 +17,13 @@ * ==================================================================== */ +import org.apache.maven.artifact.Artifact; +import org.apache.maven.tools.repoclean.report.Reporter; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + /** * @author jdcasey */ @@ -36,37 +34,13 @@ public class ArtifactDigestVerifier private ArtifactDigestor artifactDigestor; - public void verifyDigest( Artifact artifact, ArtifactRepository sourceRepo, ArtifactRepository targetRepo, - Reporter reporter, boolean reportOnly ) throws Exception + public void verifyDigest( Artifact artifact, File artifactTarget, Reporter reporter, boolean reportOnly ) throws Exception { - File sourceBase = new File( sourceRepo.getBasedir() ); - File targetBase = new File( targetRepo.getBasedir() ); - // create the digest source file from which to copy/verify. - File digestSourceFile = null; - try - { - digestSourceFile = new File( sourceBase, sourceRepo.pathOf( artifact ) + ".md5" ); - } - catch ( ArtifactPathFormatException e ) - { - reporter.error( "Error creating java.io.File of digest source for artifact[" + artifact.getId() + "]", e ); - - throw e; - } + File digestSourceFile = new File( artifact.getFile() + ".md5" ); // create the digest target file from which to copy/create. - File digestTargetFile = null; - try - { - digestTargetFile = new File( targetBase, targetRepo.pathOf( artifact ) + ".md5" ); - } - catch ( ArtifactPathFormatException e ) - { - reporter.error( "Error creating java.io.File of digest target for artifact[" + artifact.getId() + "]", e ); - - throw e; - } + File digestTargetFile = new File( artifactTarget + ".md5" ); if(!reportOnly) { @@ -79,25 +53,12 @@ public void verifyDigest( Artifact artifact, ArtifactRepository sourceRepo, Arti } } - // create the artifact file in the target repo to use for generating a new digest. - File artifactTargetFile = null; - try - { - artifactTargetFile = new File( targetBase, targetRepo.pathOf( artifact ) ); - } - catch ( ArtifactPathFormatException e ) - { - reporter.error( "Error creating java.io.File for artifact[" + artifact.getId() + "]", e ); - - throw e; - } - boolean verified = false; // if the digest source file exists, then verify it. if ( digestSourceFile.exists() ) { - verified = artifactDigestor.verifyArtifactDigest( artifactTargetFile, digestTargetFile, + verified = artifactDigestor.verifyArtifactDigest( artifactTarget, digestTargetFile, ArtifactDigestor.MD5 ); if ( verified ) @@ -142,7 +103,7 @@ public void verifyDigest( Artifact artifact, ArtifactRepository sourceRepo, Arti if ( !reportOnly ) { - artifactDigestor.createArtifactDigest( artifactTargetFile, digestTargetFile, ArtifactDigestor.MD5 ); + artifactDigestor.createArtifactDigest( artifactTarget, digestTargetFile, ArtifactDigestor.MD5 ); } else { diff --git a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java index 20462c746a..6f6c40a320 100644 --- a/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java +++ b/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java @@ -499,8 +499,20 @@ private List translateDependencies( List v3Deps ) Dependency dep = new Dependency(); - dep.setArtifactId( v3Dep.getArtifactId() ); - dep.setGroupId( v3Dep.getGroupId() ); + String artifactId = v3Dep.getArtifactId(); + String groupId = v3Dep.getGroupId(); + + if(StringUtils.isNotEmpty(artifactId) && StringUtils.isNotEmpty(groupId)) + { + dep.setGroupId(groupId); + dep.setArtifactId(artifactId); + } + else + { + dep.setGroupId(v3Dep.getId()); + dep.setArtifactId(v3Dep.getId()); + } + dep.setVersion( v3Dep.getVersion() ); dep.setType( v3Dep.getType() ); @@ -645,7 +657,12 @@ private List translateResources( List v3Resources ) Resource resource = new Resource(); resource.setDirectory( v3Resource.getDirectory() ); - resource.setExcludes( v3Resource.getExcludes() ); + + List excludes = new ArrayList(v3Resource.getExcludes()); + excludes.removeAll(v3Resource.getDefaultExcludes()); + + resource.setExcludes( excludes ); + resource.setIncludes( v3Resource.getIncludes() ); resource.setTargetPath( v3Resource.getTargetPath() );