o Added --force CLI support

o Added blacklistedPatterns to configuration file, to enhance the exclusion filter during artifact discovery with a set of non-copy-able files.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163997 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-04-21 02:17:51 +00:00
parent cf1937a1f1
commit 65b542741b
6 changed files with 162 additions and 66 deletions

View File

@ -30,9 +30,14 @@
*/
public class Main
{
public static final String FORCE_ARG = "--force";
public static void main( String[] args )
{
boolean force = false;
String configFile = null;
if ( args.length < 1 )
{
printUsage();
@ -48,10 +53,36 @@ else if ( "-template".equals( args[0] ) )
printTemplate();
System.exit( 0 );
}
// up the ante, and let's try to see if there's a --force option.
else if ( args.length == 2 )
{
if(FORCE_ARG.equals(args[0]))
{
force = true;
configFile = args[1];
}
else if(FORCE_ARG.equals(args[1]))
{
force = true;
configFile = args[0];
}
else
{
System.out.println("Invalid argument list: \'" + args[0] + " " + args[1]);
printUsage();
System.exit(1);
}
}
else
{
configFile = args[0];
}
try
{
RepositoryCleanerConfiguration config = buildConfig( args[0] );
RepositoryCleanerConfiguration config = buildConfig( configFile );
config.setForce(force);
launch( config );
@ -108,6 +139,7 @@ private static RepositoryCleanerConfiguration buildConfig( String configPath )
config.setTargetRepositoryPath( props.getProperty( "targetRepositoryPath" ) );
config.setTargetRepositoryLayout( props.getProperty( "targetRepositoryLayout", "default" ) );
config.setReportsPath( props.getProperty( "reportsPath" ) );
config.setBlacklistedPatterns( props.getProperty( "blacklistedPatterns" ) );
config.setReportOnly( Boolean.valueOf( props.getProperty( "reportOnly" ) ).booleanValue() );
config.setMailErrorReport( Boolean.valueOf( props.getProperty( "errorReport.mailOnError", "false") ).booleanValue() );

View File

@ -67,9 +67,9 @@ public class RepositoryCleaner
private ArtifactRepositoryLayout bridgingLayout;
private MailSender mailSender;
private ArtifactIndexer artifactIndexer;
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
private PlexusContainer container;
@ -101,9 +101,8 @@ public void cleanRepository( RepositoryCleanerConfiguration configuration )
List artifacts = null;
try
{
artifactDiscoverer = (ArtifactDiscoverer) container.lookup(
ArtifactDiscoverer.ROLE,
configuration.getSourceRepositoryLayout() );
artifactDiscoverer = (ArtifactDiscoverer) container.lookup( ArtifactDiscoverer.ROLE, configuration
.getSourceRepositoryLayout() );
if ( logger.isInfoEnabled() )
{
@ -112,7 +111,8 @@ public void cleanRepository( RepositoryCleanerConfiguration configuration )
try
{
artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter );
artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter,
configuration.getBlacklistedPatterns() );
}
catch ( Exception e )
{
@ -134,16 +134,16 @@ public void cleanRepository( RepositoryCleanerConfiguration configuration )
ArtifactRepositoryLayout targetLayout = null;
try
{
sourceLayout = (ArtifactRepositoryLayout) container.lookup(
ArtifactRepositoryLayout.ROLE,
configuration.getSourceRepositoryLayout() );
sourceLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
configuration
.getSourceRepositoryLayout() );
ArtifactRepository sourceRepo = new ArtifactRepository( "source", "file://"
+ sourceRepositoryBase.getAbsolutePath(), sourceLayout );
targetLayout = (ArtifactRepositoryLayout) container.lookup(
ArtifactRepositoryLayout.ROLE,
configuration.getTargetRepositoryLayout() );
targetLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
configuration
.getTargetRepositoryLayout() );
ArtifactRepository targetRepo = new ArtifactRepository( "target", "file://"
+ targetRepositoryBase.getAbsolutePath(), targetLayout );
@ -154,7 +154,7 @@ public void cleanRepository( RepositoryCleanerConfiguration configuration )
}
artifactIndexer.writeAritfactIndex( artifacts, targetRepositoryBase );
rewriteArtifactsAndPoms( artifacts, sourceRepo, targetRepo, configuration, reportsBase,
sourceRepositoryBase, targetRepositoryBase, repoReporter );
}
@ -179,7 +179,8 @@ public void cleanRepository( RepositoryCleanerConfiguration configuration )
if ( repoReporter.hasWarning() && logger.isWarnEnabled() )
{
logger.warn( "Warning encountered while rewriting one or more artifacts from source repository to target repository." );
logger
.warn( "Warning encountered while rewriting one or more artifacts from source repository to target repository." );
}
if ( repoReporter.hasError() )
@ -245,12 +246,12 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
Logger logger = getLogger();
ArtifactPomRewriter artifactPomRewriter = null;
try
{
logger.info( "Rewriting up to " + artifacts.size() + " artifacts (Should be " + ( artifacts.size() * 2 )
+ " rewrites including POMs)." );
int actualRewriteCount = 0;
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
{
@ -273,10 +274,10 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
boolean targetMissingOrOlder = !artifactTarget.exists()
|| artifactTarget.lastModified() < artifactSource.lastModified();
if ( artifactSource.exists() && targetMissingOrOlder )
if ( artifactSource.exists() && ( configuration.force() || targetMissingOrOlder ) )
{
actualRewriteCount++;
try
{
if ( !configuration.reportOnly() )
@ -334,21 +335,21 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
{
ArtifactMetadata pom = new ProjectMetadata( artifact );
artifactPomRewriter = (ArtifactPomRewriter) container.lookup(
ArtifactPomRewriter.ROLE,
configuration.getSourcePomVersion() );
artifactPomRewriter = (ArtifactPomRewriter) container.lookup( ArtifactPomRewriter.ROLE,
configuration
.getSourcePomVersion() );
File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata( pom ) );
File targetPom = new File( targetRepositoryBase, targetRepo.pathOfMetadata( pom ) );
File bridgedTargetPom = new File( targetRepositoryBase, bridgingLayout.pathOfMetadata( pom ) );
try
{
artifactPomRewriter.rewrite( artifact, sourcePom, targetPom, artifactReporter,
configuration.reportOnly() );
bridgePomLocations( targetPom, bridgedTargetPom, artifactReporter );
}
catch ( Exception e )
@ -359,10 +360,11 @@ private void rewriteArtifactsAndPoms( List artifacts, ArtifactRepository sourceR
}
}
else if( !targetMissingOrOlder )
else if ( !targetMissingOrOlder )
{
artifactReporter.warn( "Target file for artifact is present and not stale. (Artifact: \'" + artifact.getId()
+ "\' in path: \'" + artifactSource + "\' with target path: " + artifactTarget + ")." );
artifactReporter.warn( "Target file for artifact is present and not stale. (Artifact: \'"
+ artifact.getId() + "\' in path: \'" + artifactSource + "\' with target path: "
+ artifactTarget + ")." );
}
else
{
@ -389,8 +391,9 @@ else if( !targetMissingOrOlder )
}
}
}
logger.info("Actual number of artifacts rewritten: " + actualRewriteCount + " (" + (actualRewriteCount * 2) + " including POMs).");
logger.info( "Actual number of artifacts rewritten: " + actualRewriteCount + " ("
+ ( actualRewriteCount * 2 ) + " including POMs)." );
}
finally
{
@ -401,27 +404,29 @@ else if( !targetMissingOrOlder )
}
}
private void bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter ) throws IOException, ReportWriteException
private void bridgePomLocations( File targetPom, File bridgedTargetPom, Reporter reporter )
throws IOException, ReportWriteException
{
if(targetPom.equals(bridgedTargetPom))
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.");
reporter.warn( "Cannot create legacy-compatible copy of POM at: " + targetPom
+ "; legacy-compatible path is the same as the converted POM itself." );
}
FileInputStream in = null;
FileOutputStream out = null;
try
{
in = new FileInputStream(targetPom);
out = new FileOutputStream(bridgedTargetPom);
IOUtil.copy(in, out);
in = new FileInputStream( targetPom );
out = new FileOutputStream( bridgedTargetPom );
IOUtil.copy( in, out );
}
finally
{
IOUtil.close(in);
IOUtil.close(out);
IOUtil.close( in );
IOUtil.close( out );
}
}
@ -538,7 +543,8 @@ else if ( !reportsBase.isDirectory() )
return reportsBase;
}
public void contextualize( Context context ) throws ContextException
public void contextualize( Context context )
throws ContextException
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}

View File

@ -51,6 +51,8 @@ public class RepositoryCleanerConfiguration
private boolean force;
private String blacklistedPatterns;
public void setSourceRepositoryPath( String sourceRepositoryPath )
{
this.sourceRepositoryPath = sourceRepositoryPath;
@ -190,4 +192,14 @@ public void setForce( boolean force )
{
this.force = force;
}
public void setBlacklistedPatterns( String blacklistedPatterns )
{
this.blacklistedPatterns = blacklistedPatterns;
}
public String getBlacklistedPatterns()
{
return blacklistedPatterns;
}
}

View File

@ -25,7 +25,7 @@
public interface ArtifactDiscoverer
{
public static final String ROLE = ArtifactDiscoverer.class.getName();
public static final String[] STANDARD_DISCOVERY_EXCLUDES = {
"bin/**",
"reports/**",
@ -39,9 +39,9 @@ public interface ArtifactDiscoverer
"**/.htaccess",
"**/*.html",
"**/*.asc",
"**/*.txt"
};
"**/*.txt" };
List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns )
throws Exception;
List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception;
}

View File

@ -36,14 +36,29 @@ public class DefaultArtifactDiscoverer
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public List discoverArtifacts( File repositoryBase, FileReporter reporter )
public List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns )
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( STANDARD_DISCOVERY_EXCLUDES );
scanner.setExcludes( allExcludes );
scanner.scan();

View File

@ -38,14 +38,38 @@ public class LegacyArtifactDiscoverer
private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
public List discoverArtifacts( File repositoryBase, FileReporter reporter )
public List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns )
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( STANDARD_DISCOVERY_EXCLUDES );
scanner.setExcludes( allExcludes );
scanner.scan();
@ -205,20 +229,25 @@ else if ( lastAvceToken.endsWith( ".zip" ) )
tokensIterated++;
}
getLogger().debug("After parsing loop, state of buffers:\no Version Buffer: \'" + versionBuffer + "\'\no Classifier Buffer: \'" + classifierBuffer + "\'\no Number of Tokens Iterated: " + 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);
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 )
{
int lastIdx = avceTokenList.size() - 1;
versionBuffer.append( avceTokenList.get( lastIdx ) );
avceTokenList.remove( lastIdx );
@ -226,14 +255,14 @@ else if ( lastAvceToken.endsWith( ".zip" ) )
}
else
{
getLogger().debug("Removing " + tokensIterated + " tokens from avce token list.");
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);
getLogger().debug( "Now, remainder of avce token list is:\n" + avceTokenList );
StringBuffer artifactIdBuffer = new StringBuffer();
@ -270,16 +299,16 @@ else if ( lastAvceToken.endsWith( ".zip" ) )
}
getLogger().debug(
"Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n"
+ "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + "version: \'"
+ version + "\'\n" + "classifier: \'" + classifierBuffer.toString() + "\'" );
"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.");
getLogger().debug( "Creating artifact with classifier." );
result = artifactConstructionSupport.createArtifactWithClassifier( groupId, artifactId, version,
Artifact.SCOPE_RUNTIME, type,
classifierBuffer.toString() );
@ -290,7 +319,9 @@ else if ( lastAvceToken.endsWith( ".zip" ) )
type );
}
getLogger().debug( "Resulting artifact is: " + result.getId() + " and has classifier of: " + result.getClassifier() + "\n\n" );
getLogger().debug(
"Resulting artifact is: " + result.getId() + " and has classifier of: "
+ result.getClassifier() + "\n\n" );
return result;
}