mirror of https://github.com/apache/maven.git
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:
parent
cf1937a1f1
commit
65b542741b
|
@ -31,8 +31,13 @@ import java.util.Properties;
|
|||
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 @@ public class Main
|
|||
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 @@ public class Main
|
|||
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() );
|
||||
|
|
|
@ -101,9 +101,8 @@ public class RepositoryCleaner
|
|||
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 class RepositoryCleaner
|
|||
|
||||
try
|
||||
{
|
||||
artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter );
|
||||
artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter,
|
||||
configuration.getBlacklistedPatterns() );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
@ -134,16 +134,16 @@ public class RepositoryCleaner
|
|||
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 );
|
||||
|
@ -179,7 +179,8 @@ public class RepositoryCleaner
|
|||
|
||||
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() )
|
||||
|
@ -273,7 +274,7 @@ public class RepositoryCleaner
|
|||
boolean targetMissingOrOlder = !artifactTarget.exists()
|
||||
|| artifactTarget.lastModified() < artifactSource.lastModified();
|
||||
|
||||
if ( artifactSource.exists() && targetMissingOrOlder )
|
||||
if ( artifactSource.exists() && ( configuration.force() || targetMissingOrOlder ) )
|
||||
{
|
||||
actualRewriteCount++;
|
||||
|
||||
|
@ -334,9 +335,9 @@ public class RepositoryCleaner
|
|||
{
|
||||
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 ) );
|
||||
|
||||
|
@ -361,8 +362,9 @@ public class RepositoryCleaner
|
|||
}
|
||||
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
|
||||
{
|
||||
|
@ -390,7 +392,8 @@ public class RepositoryCleaner
|
|||
}
|
||||
}
|
||||
|
||||
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,11 +404,13 @@ public class RepositoryCleaner
|
|||
}
|
||||
}
|
||||
|
||||
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 ) )
|
||||
{
|
||||
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;
|
||||
|
@ -538,7 +543,8 @@ public class RepositoryCleaner
|
|||
return reportsBase;
|
||||
}
|
||||
|
||||
public void contextualize( Context context ) throws ContextException
|
||||
public void contextualize( Context context )
|
||||
throws ContextException
|
||||
{
|
||||
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
|
||||
}
|
||||
|
|
|
@ -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 class RepositoryCleanerConfiguration
|
|||
{
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
public void setBlacklistedPatterns( String blacklistedPatterns )
|
||||
{
|
||||
this.blacklistedPatterns = blacklistedPatterns;
|
||||
}
|
||||
|
||||
public String getBlacklistedPatterns()
|
||||
{
|
||||
return blacklistedPatterns;
|
||||
}
|
||||
}
|
|
@ -39,9 +39,9 @@ public interface ArtifactDiscoverer
|
|||
"**/.htaccess",
|
||||
"**/*.html",
|
||||
"**/*.asc",
|
||||
"**/*.txt"
|
||||
};
|
||||
"**/*.txt" };
|
||||
|
||||
List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception;
|
||||
List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns )
|
||||
throws Exception;
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
@ -206,12 +230,17 @@ public class LegacyArtifactDiscoverer
|
|||
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.
|
||||
|
@ -290,7 +319,9 @@ public class LegacyArtifactDiscoverer
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue