You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jd...@apache.org on 2005/04/21 04:17:51 UTC

cvs commit: maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean RepositoryCleanerConfiguration.java RepositoryCleaner.java Main.java

jdcasey     2005/04/20 19:17:51

  Modified:    sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover
                        DefaultArtifactDiscoverer.java
                        ArtifactDiscoverer.java
                        LegacyArtifactDiscoverer.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean
                        RepositoryCleanerConfiguration.java
                        RepositoryCleaner.java Main.java
  Log:
  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.
  
  Revision  Changes    Path
  1.5       +17 -2     maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java
  
  Index: DefaultArtifactDiscoverer.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultArtifactDiscoverer.java	19 Apr 2005 20:05:15 -0000	1.4
  +++ DefaultArtifactDiscoverer.java	21 Apr 2005 02:17:51 -0000	1.5
  @@ -36,14 +36,29 @@
   
       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();
   
  
  
  
  1.6       +5 -5      maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java
  
  Index: ArtifactDiscoverer.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArtifactDiscoverer.java	20 Apr 2005 22:10:24 -0000	1.5
  +++ ArtifactDiscoverer.java	21 Apr 2005 02:17:51 -0000	1.6
  @@ -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 @@
           "**/.htaccess",
           "**/*.html",
           "**/*.asc",
  -        "**/*.txt"
  -    };
  +        "**/*.txt" };
  +
  +    List discoverArtifacts( File repositoryBase, FileReporter reporter, String blacklistedPatterns )
  +        throws Exception;
   
  -    List discoverArtifacts( File repositoryBase, FileReporter reporter ) throws Exception;
  -    
   }
  \ No newline at end of file
  
  
  
  1.11      +49 -18    maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java
  
  Index: LegacyArtifactDiscoverer.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LegacyArtifactDiscoverer.java	20 Apr 2005 23:06:04 -0000	1.10
  +++ LegacyArtifactDiscoverer.java	21 Apr 2005 02:17:51 -0000	1.11
  @@ -38,14 +38,38 @@
   
       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 @@
   
               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
           {
  -            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 @@
           }
   
           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 @@
                                                                    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;
       }
  
  
  
  1.4       +12 -0     maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java
  
  Index: RepositoryCleanerConfiguration.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RepositoryCleanerConfiguration.java	19 Apr 2005 20:05:15 -0000	1.3
  +++ RepositoryCleanerConfiguration.java	21 Apr 2005 02:17:51 -0000	1.4
  @@ -51,6 +51,8 @@
       
       private boolean force;
   
  +    private String blacklistedPatterns;
  +
       public void setSourceRepositoryPath( String sourceRepositoryPath )
       {
           this.sourceRepositoryPath = sourceRepositoryPath;
  @@ -190,4 +192,14 @@
       {
           this.force = force;
       }
  +
  +    public void setBlacklistedPatterns( String blacklistedPatterns )
  +    {
  +        this.blacklistedPatterns = blacklistedPatterns;
  +    }
  +    
  +    public String getBlacklistedPatterns()
  +    {
  +        return blacklistedPatterns;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.16      +46 -40    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- RepositoryCleaner.java	20 Apr 2005 23:39:30 -0000	1.15
  +++ RepositoryCleaner.java	21 Apr 2005 02:17:51 -0000	1.16
  @@ -67,9 +67,9 @@
       private ArtifactRepositoryLayout bridgingLayout;
   
       private MailSender mailSender;
  -    
  +
       private ArtifactIndexer artifactIndexer;
  -    
  +
       private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
   
       private PlexusContainer container;
  @@ -101,9 +101,8 @@
                   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 @@
   
                       try
                       {
  -                        artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter );
  +                        artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter,
  +                                                                          configuration.getBlacklistedPatterns() );
                       }
                       catch ( Exception e )
                       {
  @@ -134,16 +134,16 @@
                       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 @@
                           }
   
                           artifactIndexer.writeAritfactIndex( artifacts, targetRepositoryBase );
  -                        
  +
                           rewriteArtifactsAndPoms( artifacts, sourceRepo, targetRepo, configuration, reportsBase,
                                                    sourceRepositoryBase, targetRepositoryBase, repoReporter );
                       }
  @@ -179,7 +179,8 @@
   
                   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 @@
           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 @@
                       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 @@
                           {
                               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 @@
                           }
   
                       }
  -                    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 @@
                       }
                   }
               }
  -            
  -            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 @@
           }
       }
   
  -    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 @@
           return reportsBase;
       }
   
  -    public void contextualize( Context context ) throws ContextException
  +    public void contextualize( Context context )
  +        throws ContextException
       {
           this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
       }
  
  
  
  1.7       +33 -1     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Main.java	19 Apr 2005 20:05:15 -0000	1.6
  +++ Main.java	21 Apr 2005 02:17:51 -0000	1.7
  @@ -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 @@
               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 @@
           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() );
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org