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
This commit is contained in:
John Dennis Casey 2005-04-01 02:45:05 +00:00
parent 89423d23de
commit 5b5a124caa
6 changed files with 194 additions and 121 deletions

View File

@ -1,5 +1,11 @@
package org.apache.maven.artifact.repository.layout; 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. * Copyright 2001-2005 The Apache Software Foundation.
* *
@ -20,22 +26,69 @@ package org.apache.maven.artifact.repository.layout;
* @author jdcasey * @author jdcasey
*/ */
public class DefaultRepositoryLayout 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 ) ArtifactHandler artifactHandler = null;
{
return groupId.replace( '.', '/' ); 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();
} }
} }

View File

@ -16,26 +16,76 @@ package org.apache.maven.artifact.repository.layout;
* limitations under the License. * 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 * @author jdcasey
*/ */
public class LegacyRepositoryLayout 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}"; Artifact artifact = metadata.getArtifact();
}
ArtifactHandler artifactHandler = null;
protected String groupIdAsPath( String groupId )
{ try
return groupId; {
// 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();
} }
} }

View File

@ -43,7 +43,7 @@ public class Main
printHelp(); printHelp();
System.exit( 0 ); System.exit( 0 );
} }
else if( "-template".equals( args[0] ) ) else if ( "-template".equals( args[0] ) )
{ {
printTemplate(); printTemplate();
System.exit( 0 ); System.exit( 0 );
@ -54,7 +54,7 @@ public class Main
{ {
embedder.start( new ClassWorld() ); embedder.start( new ClassWorld() );
RepositoryCleanerConfiguration config = buildConfig(args[0]); RepositoryCleanerConfiguration config = buildConfig( args[0] );
RepositoryCleaner cleaner = null; RepositoryCleaner cleaner = null;
try try
@ -77,67 +77,57 @@ public class Main
} }
} }
private static RepositoryCleanerConfiguration buildConfig( String configPath ) throws IOException private static RepositoryCleanerConfiguration buildConfig( String configPath )
throws IOException
{ {
Properties props = new Properties(); Properties props = new Properties();
FileInputStream input = null; FileInputStream input = null;
try try
{ {
input = new FileInputStream(configPath); input = new FileInputStream( configPath );
props.load(input); props.load( input );
} }
finally finally
{ {
IOUtil.close(input); IOUtil.close( input );
} }
RepositoryCleanerConfiguration config = new RepositoryCleanerConfiguration(); RepositoryCleanerConfiguration config = new RepositoryCleanerConfiguration();
config.setSourceRepositoryPath(props.getProperty("sourceRepositoryPath")); config.setSourceRepositoryPath( props.getProperty( "sourceRepositoryPath" ) );
config.setSourceRepositoryLayout(props.getProperty("sourceRepositoryLayout", "legacy")); config.setSourceRepositoryLayout( props.getProperty( "sourceRepositoryLayout", "legacy" ) );
config.setSourcePomVersion(props.getProperty("sourcePomVersion", "v3")); config.setSourcePomVersion( props.getProperty( "sourcePomVersion", "v3" ) );
config.setTargetRepositoryPath(props.getProperty("targetRepositoryPath")); config.setTargetRepositoryPath( props.getProperty( "targetRepositoryPath" ) );
config.setTargetRepositoryLayout(props.getProperty("targetRepositoryLayout", "default")); config.setTargetRepositoryLayout( props.getProperty( "targetRepositoryLayout", "default" ) );
config.setReportsPath(props.getProperty("reportsPath")); config.setReportsPath( props.getProperty( "reportsPath" ) );
config.setReportOnly(Boolean.valueOf(props.getProperty("reportOnly")).booleanValue()); config.setReportOnly( Boolean.valueOf( props.getProperty( "reportOnly" ) ).booleanValue() );
return config; return config;
} }
private static void printHelp() private static void printHelp()
{ {
System.out.println("repoclean: Repository Cleaner/Converter.\n\n" + System.out.println( "repoclean: Repository Cleaner/Converter.\n\n"
"Usage: repoclean -h|-template|<configuration-properties-file>\n\n" + + "Usage: repoclean -h|-template|<configuration-properties-file>\n\n"
"Where the configuration properfies file can contain the following options:\n" + + "Where the configuration properfies file can contain the following options:\n"
"---------------------------------------------------------------------------\n" + + "---------------------------------------------------------------------------\n"
"sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n" + + "sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n"
"sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" + + "sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" + "sourcePomType=[v3|v4] #[DEFAULT: v3]\n"
"sourcePomType=[v3|v4] #[DEFAULT: v3]\n" + + "targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n"
"targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n" + + "targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n"
"targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n" + + "reportsPath=/path/to/reports/directory #[REQUIRED]\n" + "reportOnly=[true|false] #[REQUIRED]\n" + "\n" );
"reportsPath=/path/to/reports/directory #[REQUIRED]\n" +
"reportOnly=[true|false] #[REQUIRED]\n" +
"\n");
} }
private static void printTemplate() private static void printTemplate()
{ {
System.out.println( System.out.println( "# ---------------------------------------------------------------------------\n"
"# ---------------------------------------------------------------------------\n" + + "# repoclean: Repository Cleaner/Converter.\n" + "# This configuration auto-generated on: "
"# repoclean: Repository Cleaner/Converter.\n" + + new java.util.Date() + "\n"
"# This configuration auto-generated on: " + new java.util.Date() + "\n" + + "# ---------------------------------------------------------------------------\n\n"
"# ---------------------------------------------------------------------------\n\n" + + "# [REQUIRED OPTIONS]\n" + "sourceRepositoryPath=/path/to/repository/root\n"
"# [REQUIRED OPTIONS]\n" + + "targetRepositoryPath=/path/to/repository/root\n" + "reportsPath=/path/to/reports/directory\n"
"sourceRepositoryPath=/path/to/repository/root\n" + + "reportOnly=[true|false]\n\n" + "# [DEFAULT VALUE: legacy]\n"
"targetRepositoryPath=/path/to/repository/root\n" + + "#sourceRepositoryLayout=[legacy|default]\n\n" + "# [DEFAULT VALUE: v3]\n" + "#sourcePomType=[v3|v4]\n\n"
"reportsPath=/path/to/reports/directory\n" + + "# [DEFAULT VALUE: default]\n" + "#targetRepositoryLayout=[legacy|default]\n" + "\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() private static void printUsage()

View File

@ -193,6 +193,11 @@ public class RepositoryCleaner
boolean errorOccurred = false; 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 try
{ {
if ( !configuration.reportOnly() ) if ( !configuration.reportOnly() )
@ -203,9 +208,6 @@ public class RepositoryCleaner
logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'" ); 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(); File targetParent = artifactTarget.getParentFile();
if ( !targetParent.exists() ) if ( !targetParent.exists() )
{ {
@ -244,7 +246,7 @@ public class RepositoryCleaner
try try
{ {
artifactDigestVerifier.verifyDigest( artifact, sourceRepo, targetRepo, artifactReporter, artifactDigestVerifier.verifyDigest( artifact, artifactTarget, artifactReporter,
configuration.reportOnly() ); configuration.reportOnly() );
} }
catch ( Exception e ) catch ( Exception e )

View File

@ -1,14 +1,5 @@
package org.apache.maven.tools.repoclean.digest; 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. * Copyright 2001-2004 The Apache Software Foundation.
* *
@ -26,6 +17,13 @@ import java.io.IOException;
* ==================================================================== * ====================================================================
*/ */
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 * @author jdcasey
*/ */
@ -36,37 +34,13 @@ public class ArtifactDigestVerifier
private ArtifactDigestor artifactDigestor; private ArtifactDigestor artifactDigestor;
public void verifyDigest( Artifact artifact, ArtifactRepository sourceRepo, ArtifactRepository targetRepo, public void verifyDigest( Artifact artifact, File artifactTarget, Reporter reporter, boolean reportOnly ) throws Exception
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. // create the digest source file from which to copy/verify.
File digestSourceFile = null; File digestSourceFile = new File( artifact.getFile() + ".md5" );
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;
}
// create the digest target file from which to copy/create. // create the digest target file from which to copy/create.
File digestTargetFile = null; File digestTargetFile = new File( artifactTarget + ".md5" );
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;
}
if(!reportOnly) if(!reportOnly)
{ {
@ -79,25 +53,12 @@ public class ArtifactDigestVerifier
} }
} }
// 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; boolean verified = false;
// if the digest source file exists, then verify it. // if the digest source file exists, then verify it.
if ( digestSourceFile.exists() ) if ( digestSourceFile.exists() )
{ {
verified = artifactDigestor.verifyArtifactDigest( artifactTargetFile, digestTargetFile, verified = artifactDigestor.verifyArtifactDigest( artifactTarget, digestTargetFile,
ArtifactDigestor.MD5 ); ArtifactDigestor.MD5 );
if ( verified ) if ( verified )
@ -142,7 +103,7 @@ public class ArtifactDigestVerifier
if ( !reportOnly ) if ( !reportOnly )
{ {
artifactDigestor.createArtifactDigest( artifactTargetFile, digestTargetFile, ArtifactDigestor.MD5 ); artifactDigestor.createArtifactDigest( artifactTarget, digestTargetFile, ArtifactDigestor.MD5 );
} }
else else
{ {

View File

@ -499,8 +499,20 @@ public class PomV3ToV4Translator
Dependency dep = new Dependency(); Dependency dep = new Dependency();
dep.setArtifactId( v3Dep.getArtifactId() ); String artifactId = v3Dep.getArtifactId();
dep.setGroupId( v3Dep.getGroupId() ); 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.setVersion( v3Dep.getVersion() );
dep.setType( v3Dep.getType() ); dep.setType( v3Dep.getType() );
@ -645,7 +657,12 @@ public class PomV3ToV4Translator
Resource resource = new Resource(); Resource resource = new Resource();
resource.setDirectory( v3Resource.getDirectory() ); 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.setIncludes( v3Resource.getIncludes() );
resource.setTargetPath( v3Resource.getTargetPath() ); resource.setTargetPath( v3Resource.getTargetPath() );