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;
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 @@ package org.apache.maven.artifact.repository.layout;
* @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 );
}
protected String metadataLayoutPattern()
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() )
{
return "${groupPath}/${artifactId}/${baseVersion}/${metadataFilename}";
path.append( '-' ).append( artifact.getClassifier() );
}
protected String groupIdAsPath( String groupId )
path.append( '.' ).append( artifactHandler.extension() );
return path.toString();
}
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();
}
}

View File

@ -16,26 +16,76 @@ package org.apache.maven.artifact.repository.layout;
* 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 );
}
protected String metadataLayoutPattern()
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() )
{
return "${groupPath}/poms/${metadataFilename}";
path.append('-').append(artifact.getClassifier());
}
protected String groupIdAsPath( String groupId )
path.append('.').append(artifactHandler.extension());
return path.toString();
}
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();
}
}

View File

@ -77,7 +77,8 @@ public class Main
}
}
private static RepositoryCleanerConfiguration buildConfig( String configPath ) throws IOException
private static RepositoryCleanerConfiguration buildConfig( String configPath )
throws IOException
{
Properties props = new Properties();
FileInputStream input = null;
@ -105,39 +106,28 @@ public class Main
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()

View File

@ -193,6 +193,11 @@ public class RepositoryCleaner
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 @@ public class RepositoryCleaner
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 @@ public class RepositoryCleaner
try
{
artifactDigestVerifier.verifyDigest( artifact, sourceRepo, targetRepo, artifactReporter,
artifactDigestVerifier.verifyDigest( artifact, artifactTarget, artifactReporter,
configuration.reportOnly() );
}
catch ( Exception e )

View File

@ -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 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
*/
@ -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 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;
// 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 class ArtifactDigestVerifier
if ( !reportOnly )
{
artifactDigestor.createArtifactDigest( artifactTargetFile, digestTargetFile, ArtifactDigestor.MD5 );
artifactDigestor.createArtifactDigest( artifactTarget, digestTargetFile, ArtifactDigestor.MD5 );
}
else
{

View File

@ -499,8 +499,20 @@ public class PomV3ToV4Translator
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 @@ public class PomV3ToV4Translator
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() );