jdcasey 2005/03/31 18:45:05
Modified:
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest
ArtifactDigestVerifier.java
maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout
LegacyRepositoryLayout.java
DefaultRepositoryLayout.java
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean
RepositoryCleaner.java Main.java
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate
PomV3ToV4Translator.java
Log:
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.
Revision Changes Path
1.2 +12 -51
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java
Index: ArtifactDigestVerifier.java
===================================================================
RCS file:
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArtifactDigestVerifier.java 23 Mar 2005 04:53:29 -0000 1.1
+++ ArtifactDigestVerifier.java 1 Apr 2005 02:45:05 -0000 1.2
@@ -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 @@
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 @@
}
}
- // 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 @@
if ( !reportOnly )
{
- artifactDigestor.createArtifactDigest( artifactTargetFile,
digestTargetFile, ArtifactDigestor.MD5 );
+ artifactDigestor.createArtifactDigest( artifactTarget,
digestTargetFile, ArtifactDigestor.MD5 );
}
else
{
1.7 +59 -9
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java
Index: LegacyRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/LegacyRepositoryLayout.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LegacyRepositoryLayout.java 29 Mar 2005 15:44:28 -0000 1.6
+++ LegacyRepositoryLayout.java 1 Apr 2005 02:45:05 -0000 1.7
@@ -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()
- {
- return
"${groupPath}/${directory}/${artifactId}-${version}-${classifier}.${extension}";
- }
+ private ArtifactHandlerManager artifactHandlerManager;
- protected String metadataLayoutPattern()
+ public String pathOf( Artifact artifact )
+ throws ArtifactPathFormatException
{
- return "${groupPath}/poms/${metadataFilename}";
+ 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 groupIdAsPath( String groupId )
+ public String pathOfMetadata( ArtifactMetadata metadata )
+ throws ArtifactPathFormatException
{
- 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
1.7 +62 -9
maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
Index: DefaultRepositoryLayout.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultRepositoryLayout.java 29 Mar 2005 15:44:28 -0000 1.6
+++ DefaultRepositoryLayout.java 1 Apr 2005 02:45:05 -0000 1.7
@@ -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()
- {
- return
"${groupPath}/${artifactId}/${baseVersion}/${artifactId}-${version}-${classifier}.${extension}";
- }
+ private ArtifactHandlerManager artifactHandlerManager;
- protected String metadataLayoutPattern()
+ public String pathOf( Artifact artifact )
+ throws ArtifactPathFormatException
{
- return
"${groupPath}/${artifactId}/${baseVersion}/${metadataFilename}";
+ 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 groupIdAsPath( String groupId )
+ public String pathOfMetadata( ArtifactMetadata metadata )
+ throws ArtifactPathFormatException
{
- return groupId.replace( '.', '/' );
+ 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().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
1.5 +6 -4
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
Index: RepositoryCleaner.java
===================================================================
RCS file:
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RepositoryCleaner.java 1 Apr 2005 00:24:44 -0000 1.4
+++ RepositoryCleaner.java 1 Apr 2005 02:45:05 -0000 1.5
@@ -193,6 +193,11 @@
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 @@
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 @@
try
{
- artifactDigestVerifier.verifyDigest( artifact,
sourceRepo, targetRepo, artifactReporter,
+ artifactDigestVerifier.verifyDigest( artifact,
artifactTarget, artifactReporter,
configuration.reportOnly() );
}
catch ( Exception e )
1.4 +34 -44
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java
Index: Main.java
===================================================================
RCS file:
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Main.java 1 Apr 2005 00:24:44 -0000 1.3
+++ Main.java 1 Apr 2005 02:45:05 -0000 1.4
@@ -43,7 +43,7 @@
printHelp();
System.exit( 0 );
}
- else if( "-template".equals( args[0] ) )
+ else if ( "-template".equals( args[0] ) )
{
printTemplate();
System.exit( 0 );
@@ -54,7 +54,7 @@
{
embedder.start( new ClassWorld() );
- RepositoryCleanerConfiguration config = buildConfig(args[0]);
+ RepositoryCleanerConfiguration config = buildConfig( args[0] );
RepositoryCleaner cleaner = null;
try
@@ -77,67 +77,57 @@
}
}
- 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|<configuration-properties-file>\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|<configuration-properties-file>\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()
1.4 +20 -3
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java
Index: PomV3ToV4Translator.java
===================================================================
RCS file:
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PomV3ToV4Translator.java 1 Apr 2005 00:24:45 -0000 1.3
+++ PomV3ToV4Translator.java 1 Apr 2005 02:45:05 -0000 1.4
@@ -499,8 +499,20 @@
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 @@
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() );