jdcasey     2005/04/01 18:17:19

  Modified:    sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean
                        RepositoryCleaner.java
               sandbox/repoclean/src/main/bash repoclean.sh
               sandbox/repoclean/src/main/resources/META-INF/plexus
                        components.xml
               
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover
                        LegacyArtifactDiscoverer.java
               
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest
                        ArtifactDigestVerifier.java ArtifactDigestor.java
  Added:       
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler
                        EarHandler.java RarHandler.java
                        JarDistroHandler.java TldHandler.java
                        ZipDistroHandler.java LegacyPluginHandler.java
                        DtdHandler.java SarHandler.java
                        TgzDistroHandler.java
               
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata
                        ProjectMetadata.java
  Removed:     
sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact
                        TgzDistroHandler.java SarHandler.java
                        LegacyPluginHandler.java ZipDistroHandler.java
                        DtdHandler.java TldHandler.java
                        JarDistroHandler.java EarHandler.java
                        RarHandler.java
  Log:
  o Fixed bash scripts (cygwin option was being tested incorrectly, and 
resulting in no such file: cygpath)
  o Changed POM handling to use ArtifactMetadata API rather than direct 
Artifact construction for POMs
  o Streamlined ArtifactDigestor to avoid use of byte arrays for transfer 
between methods (resulted in a bit of cut-and-paste code, but should run better)
  o Pegged OutOfMemoryError to the ArtifactDigestVerifier/ArtifactDigestor 
combo (motivated the previous change)
  o Cleaned up artifact source-file checking before creating any of the target 
directory structures
  o Maybe works, maybe not...will resume testing tomorrow or the next day
  
  Revision  Changes    Path
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/EarHandler.java
  
  Index: EarHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  import org.apache.maven.artifact.handler.JarHandler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: EarHandler.java,v 1.1 2005/04/02 02:17:19 jdcasey Exp $
   */
  public class EarHandler
      extends JarHandler
  {
      public String directory()
      {
          return "ears";
      }
  
      public String packageGoal()
      {
          return "ear:ear";
      }
  }
  
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/RarHandler.java
  
  Index: RarHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  import org.apache.maven.artifact.handler.JarHandler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: RarHandler.java,v 1.1 2005/04/02 02:17:19 jdcasey Exp $
   */
  public class RarHandler
      extends JarHandler
  {
      public String directory()
      {
          return "rars";
      }
  
      public String packageGoal()
      {
          return "rar:rar";
      }
  }
  
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/JarDistroHandler.java
  
  Index: JarDistroHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may 
not use this file except
   * in compliance with the License. You may obtain a copy of the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software 
distributed under the License
   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
ANY KIND, either express
   * or implied. See the License for the specific language governing 
permissions and limitations under
   * the License.
   */
  
  import org.apache.maven.artifact.handler.AbstractArtifactHandler;
  
  /**
   * @author jdcasey
   */
  public class JarDistroHandler
      extends AbstractArtifactHandler
  {
  
      public String directory()
      {
          return "distributions";
      }
  
  }
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/TldHandler.java
  
  Index: TldHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  import org.apache.maven.artifact.handler.AbstractArtifactHandler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: TldHandler.java,v 1.1 2005/04/02 02:17:19 jdcasey Exp $
   */
  public class TldHandler
      extends AbstractArtifactHandler
  {
      public String directory()
      {
          return "tlds";
      }
  
  //    public String packageGoal()
  //    {
  //        return "ejb:ejb";
  //    }
  }
  
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/ZipDistroHandler.java
  
  Index: ZipDistroHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may 
not use this file except
   * in compliance with the License. You may obtain a copy of the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software 
distributed under the License
   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
ANY KIND, either express
   * or implied. See the License for the specific language governing 
permissions and limitations under
   * the License.
   */
  
  import org.apache.maven.artifact.handler.AbstractArtifactHandler;
  
  /**
   * @author jdcasey
   */
  public class ZipDistroHandler
      extends AbstractArtifactHandler
  {
  
      public String directory()
      {
          return "distributions";
      }
  
      public String extension()
      {
          return "zip";
      }
  }
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/LegacyPluginHandler.java
  
  Index: LegacyPluginHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  import org.apache.maven.artifact.handler.AbstractArtifactHandler;
  
  /* ====================================================================
   *   Copyright 2001-2004 The Apache Software Foundation.
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *   limitations under the License.
   * ====================================================================
   */
  
  /**
   * @author jdcasey
   */
  public class LegacyPluginHandler
      extends AbstractArtifactHandler
  {
  
      public String directory()
      {
          return "plugins";
      }
      
  }
  
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/DtdHandler.java
  
  Index: DtdHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  import org.apache.maven.artifact.handler.AbstractArtifactHandler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: DtdHandler.java,v 1.1 2005/04/02 02:17:19 jdcasey Exp $
   */
  public class DtdHandler
      extends AbstractArtifactHandler
  {
      public String directory()
      {
          return "dtds";
      }
  
  //    public String packageGoal()
  //    {
  //        return "ejb:ejb";
  //    }
  }
  
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/SarHandler.java
  
  Index: SarHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  import org.apache.maven.artifact.handler.JarHandler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: SarHandler.java,v 1.1 2005/04/02 02:17:19 jdcasey Exp $
   */
  public class SarHandler
      extends JarHandler
  {
      public String directory()
      {
          return "sars";
      }
  
  }
  
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/handler/TgzDistroHandler.java
  
  Index: TgzDistroHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.handler;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may 
not use this file except
   * in compliance with the License. You may obtain a copy of the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software 
distributed under the License
   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
ANY KIND, either express
   * or implied. See the License for the specific language governing 
permissions and limitations under
   * the License.
   */
  
  import org.apache.maven.artifact.handler.AbstractArtifactHandler;
  
  /**
   * @author jdcasey
   */
  public class TgzDistroHandler
      extends AbstractArtifactHandler
  {
  
      public String directory()
      {
          return "distributions";
      }
  
      public String extension()
      {
          return "tar.gz";
      }
  }
  
  
  1.1                  
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/metadata/ProjectMetadata.java
  
  Index: ProjectMetadata.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact.metadata;
  
  /*
   * Copyright 2001-2005 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.manager.WagonManager;
  import org.apache.maven.artifact.metadata.ArtifactMetadata;
  import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
  import org.apache.maven.artifact.repository.ArtifactRepository;
  
  /**
   * Attach a POM to an artifact.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
   * @version $Id: ProjectMetadata.java,v 1.1 2005/04/02 02:17:19 jdcasey Exp $
   */
  public class ProjectMetadata
      implements ArtifactMetadata
  {
      private final Artifact artifact;
  
      public ProjectMetadata( Artifact artifact)
      {
          this.artifact = artifact;
      }
      
      public Artifact getArtifact()
      {
          return artifact;
      }
      
      public String getFilename()
      {
          return getArtifact().getArtifactId() + "-" + 
getArtifact().getVersion() + ".pom";
      }
  
      public void storeInLocalRepository( ArtifactRepository localRepository )
          throws ArtifactMetadataRetrievalException
      {
          // not used in repoclean.
      }
  
      public void retrieveFromRemoteRepository( ArtifactRepository 
remoteRepository, WagonManager wagonManager )
      {
          // not used - TODO: again indicates bad design?
      }
  
      public void setArtifact( Artifact artifact )
      {
          // this should be immutable...
      }
  }
  
  
  
  1.6       +82 -76    
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RepositoryCleaner.java    1 Apr 2005 02:45:05 -0000       1.5
  +++ RepositoryCleaner.java    2 Apr 2005 02:17:19 -0000       1.6
  @@ -17,8 +17,10 @@
   
   import org.apache.maven.artifact.Artifact;
   import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
  +import org.apache.maven.artifact.metadata.ArtifactMetadata;
   import org.apache.maven.artifact.repository.ArtifactRepository;
   import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
  +import org.apache.maven.tools.repoclean.artifact.metadata.ProjectMetadata;
   import org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier;
   import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
   import org.apache.maven.tools.repoclean.report.Reporter;
  @@ -182,6 +184,7 @@
   
           try
           {
  +            logger.info("Rewriting " + artifacts.size() + " artifacts 
(Should be " + (artifacts.size() * 2) + " rewrites including POMs).");
               for ( Iterator it = artifacts.iterator(); it.hasNext(); )
               {
                   Artifact artifact = (Artifact) it.next();
  @@ -194,102 +197,109 @@
                       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(artifactSource.exists())
                       {
  -                        if ( !configuration.reportOnly() )
  +                        File artifactTarget = new File( 
targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
  +
  +                        artifact.setFile( artifactSource );
  +                        
  +                        try
                           {
  -                            if(logger.isDebugEnabled())
  +                            if ( !configuration.reportOnly() )
                               {
  -                                logger.debug( "sourceRepo basedir is: \'" + 
sourceRepo.getBasedir() + "\'" );
  -                                logger.debug( "targetRepo basedir is: \'" + 
targetRepo.getBasedir() + "\'" );
  -                            }
  +                                if(logger.isDebugEnabled())
  +                                {
  +                                    logger.debug( "sourceRepo basedir is: 
\'" + sourceRepo.getBasedir() + "\'" );
  +                                    logger.debug( "targetRepo basedir is: 
\'" + targetRepo.getBasedir() + "\'" );
  +                                }
  +
  +                                File targetParent = 
artifactTarget.getParentFile();
  +                                if ( !targetParent.exists() )
  +                                {
  +                                    targetParent.mkdirs();
  +                                }
  +
  +                                if ( logger.isDebugEnabled() )
  +                                {
  +                                    logger.debug( "Copying artifact[" + 
artifact.getId() + "] from \'" + artifactSource
  +                                        + "\' to \'" + artifactTarget + 
"\'." );
  +                                }
   
  -                            File targetParent = 
artifactTarget.getParentFile();
  -                            if ( !targetParent.exists() )
  -                            {
  -                                targetParent.mkdirs();
  +                                copyArtifact( artifact, artifactTarget, 
artifactReporter );
                               }
  -
  -                            if ( logger.isDebugEnabled() )
  +                            else
                               {
  -                                logger.debug( "Copying artifact[" + 
artifact.getId() + "] from \'" + artifactSource
  -                                    + "\' to \'" + artifactTarget + "\'." );
  +                                artifactReporter.info( "Skipping artifact 
copy (we're in report-only mode)." );
                               }
  -
  -                            copyArtifact( artifactSource, artifactTarget, 
artifactReporter );
                           }
  -                        else
  +                        catch ( Exception e )
                           {
  -                            artifactReporter.info( "Skipping artifact copy 
(we're in report-only mode)." );
  -                        }
  -                    }
  -                    catch ( Exception e )
  -                    {
  -                        repoReporter.error( "Error transferring artifact[" + 
artifact.getId()
  -                            + "] to the target repository.", e );
  +                            repoReporter.error( "Error transferring 
artifact[" + artifact.getId()
  +                                + "] to the target repository.", e );
   
  -                        // if we can't copy the jar over, then skip the rest.
  -                        errorOccurred = true;
  -                    }
  -
  -                    if ( !errorOccurred )
  -                    {
  -                        if ( logger.isDebugEnabled() )
  -                        {
  -                            logger.debug( "working on digest for artifact[" 
+ artifact.getId() + "] with groupId: \'"
  -                                + artifact.getGroupId() + "\'" );
  +                            // if we can't copy the jar over, then skip the 
rest.
  +                            errorOccurred = true;
                           }
   
  -                        try
  -                        {
  -                            artifactDigestVerifier.verifyDigest( artifact, 
artifactTarget, artifactReporter,
  -                                                                 
configuration.reportOnly() );
  -                        }
  -                        catch ( Exception e )
  +                        if ( !errorOccurred )
                           {
  -                            repoReporter.error( "Error verifying digest for 
artifact[" + artifact.getId() + "]", e );
  -                        }
  -                    }
  +                            if ( logger.isDebugEnabled() )
  +                            {
  +                                logger.debug( "working on digest for 
artifact[" + artifact.getId() + "] with groupId: \'"
  +                                    + artifact.getGroupId() + "\'" );
  +                            }
   
  -                    if ( !errorOccurred )
  -                    {
  -                        Artifact pomArtifact = buildPomArtifact( artifact );
  +                            try
  +                            {
  +                                artifactDigestVerifier.verifyDigest( 
artifact, artifactTarget, artifactReporter,
  +                                                                     
configuration.reportOnly() );
  +                            }
  +                            catch ( Exception e )
  +                            {
  +                                repoReporter.error( "Error verifying digest 
for artifact[" + artifact.getId() + "]", e );
  +                            }
  +                        }
   
  -                        artifactPomRewriter = (ArtifactPomRewriter) 
container.lookup( ArtifactPomRewriter.ROLE,
  -                                                                             
         configuration.getSourcePomVersion() );
  +                        if ( !errorOccurred )
  +                        {
  +                            ArtifactMetadata pom = new ProjectMetadata( 
artifact );
  +                            
  +                            artifactPomRewriter = (ArtifactPomRewriter) 
container.lookup( ArtifactPomRewriter.ROLE,
  +                                                                             
             configuration.getSourcePomVersion() );
   
  -                        File sourcePom = new File( sourceRepositoryBase, 
sourceRepo.pathOf( pomArtifact ) );
  +                            File sourcePom = new File( sourceRepositoryBase, 
sourceRepo.pathOfMetadata( pom ) );
   
  -                        File targetPom = new File( targetRepositoryBase, 
targetRepo.pathOf( pomArtifact ) );
  +                            File targetPom = new File( targetRepositoryBase, 
targetRepo.pathOfMetadata( pom ) );
   
  -                        try
  -                        {
  -                            artifactPomRewriter.rewrite( artifact, 
sourcePom, targetPom, artifactReporter,
  -                                                         
configuration.reportOnly() );
  -                        }
  -                        catch ( Exception e )
  -                        {
  -                            repoReporter.error( "Error rewriting POM for 
artifact[" + artifact.getId()
  -                                + "] into the target repository.", e );
  +                            try
  +                            {
  +                                artifactPomRewriter.rewrite( artifact, 
sourcePom, targetPom, artifactReporter,
  +                                                             
configuration.reportOnly() );
  +                            }
  +                            catch ( Exception e )
  +                            {
  +                                repoReporter.error( "Error rewriting POM for 
artifact[" + artifact.getId()
  +                                    + "] into the target repository.", e );
  +                            }
                           }
  -                    }
   
  -                    if ( artifactReporter.hasError() )
  +                    }
  +                    else
                       {
  -                        repoReporter.warn( "Error(s) occurred while 
rewriting artifact: \'" + artifact.getId()
  -                            + "\' or its POM." );
  +                        artifactReporter.error("Cannot find source file for 
artifact: \'" + artifact.getId() + "\' under path: \'" + artifactSource + "\'");
                       }
  -
  -                    if ( artifactReporter.hasWarning() )
  +                    
  +                    if ( artifactReporter.hasError() )
                       {
  -                        repoReporter.info( "Warning(s) occurred while 
rewriting artifact: \'" + artifact.getId()
  +                        repoReporter.warn( "Error(s) occurred while 
rewriting artifact: \'" + artifact.getId()
                               + "\' or its POM." );
                       }
                   }
  +                catch(Exception e)
  +                {
  +                    artifactReporter.error("Error while rewriting file or 
POM for artifact: \'" + artifact.getId() + "\'", e);
  +                }
                   finally
                   {
                       if ( artifactReporter != null )
  @@ -308,9 +318,11 @@
           }
       }
   
  -    private void copyArtifact( File artifactSource, File artifactTarget, 
Reporter reporter )
  +    private void copyArtifact( Artifact artifact, File artifactTarget, 
Reporter reporter )
           throws IOException
       {
  +        File artifactSource = artifact.getFile();
  +        
           InputStream inStream = null;
           OutputStream outStream = null;
           try
  @@ -342,12 +354,6 @@
           }
       }
   
  -    private Artifact buildPomArtifact( Artifact artifact )
  -    {
  -        return artifactConstructionSupport.createArtifact( 
artifact.getGroupId(), artifact.getArtifactId(),
  -                                                           
artifact.getVersion(), artifact.getScope(), "pom" );
  -    }
  -
       private File normalizeTargetRepositoryBase( String targetRepositoryPath )
       {
           Logger logger = getLogger();
  
  
  
  1.5       +2 -2      
maven-components/sandbox/repoclean/src/main/bash/repoclean.sh
  
  Index: repoclean.sh
  ===================================================================
  RCS file: 
/home/cvs/maven-components/sandbox/repoclean/src/main/bash/repoclean.sh,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- repoclean.sh      1 Apr 2005 01:01:20 -0000       1.4
  +++ repoclean.sh      2 Apr 2005 02:17:19 -0000       1.5
  @@ -15,7 +15,7 @@
     CYGWIN*) cygwin=true ;;
   esac
   
  -if [ $cygwin ]; then
  +if [ $cygwin == true ]; then
     CP=`cygpath -pw $CP`
   fi
   
  @@ -28,4 +28,4 @@
     shift
   fi
   
  -java $JAVA_OPTS -classpath ${CP} org.apache.maven.tools.repoclean.Main $* | 
tee repoclean-log.txt
  +nice -n 19 java -Xmx128M -Xms64M -Xincgc $JAVA_OPTS -classpath ${CP} 
org.apache.maven.tools.repoclean.Main $* | tee repoclean-log.txt
  
  
  
  1.5       +9 -9      
maven-components/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml
  
  Index: components.xml
  ===================================================================
  RCS file: 
/home/cvs/maven-components/sandbox/repoclean/src/main/resources/META-INF/plexus/components.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- components.xml    1 Apr 2005 00:24:44 -0000       1.4
  +++ components.xml    2 Apr 2005 02:17:19 -0000       1.5
  @@ -8,7 +8,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>plugin</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.LegacyPluginHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.LegacyPluginHandler</implementation>
       </component>
       <!--
        |
  @@ -18,7 +18,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>distribution</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.JarDistroHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.JarDistroHandler</implementation>
       </component>
       <!--
        |
  @@ -28,7 +28,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>distribution-tgz</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.TgzDistroHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.TgzDistroHandler</implementation>
       </component>
       <!--
        |
  @@ -38,7 +38,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>distribution-zip</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.ZipDistroHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.ZipDistroHandler</implementation>
       </component>
       <!--
        |
  @@ -48,7 +48,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>tld</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.TldHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.TldHandler</implementation>
       </component>
       <!--
        |
  @@ -58,7 +58,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>dtd</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.DtdHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.DtdHandler</implementation>
       </component>
       <!--
        |
  @@ -68,7 +68,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>ear</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.EarHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.EarHandler</implementation>
       </component>
       <!--
        |
  @@ -78,7 +78,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>rar</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.RarHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.RarHandler</implementation>
       </component>
       <!--
        |
  @@ -88,7 +88,7 @@
       <component>
         <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
         <role-hint>sar</role-hint>
  -      
<implementation>org.apache.maven.tools.repoclean.artifact.SarHandler</implementation>
  +      
<implementation>org.apache.maven.tools.repoclean.artifact.handler.SarHandler</implementation>
       </component>
       <!--
        |
  
  
  
  1.5       +2 -1      
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LegacyArtifactDiscoverer.java     1 Apr 2005 01:01:20 -0000       1.4
  +++ LegacyArtifactDiscoverer.java     2 Apr 2005 02:17:19 -0000       1.5
  @@ -130,10 +130,11 @@
               avceTokenList.addLast( lastAvceToken );
           }
   
  -        String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + 
"([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + "([_.0-9ab]+)|"
  +        String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + 
"([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + "([0-9][_.0-9a-zA-Z]*)|"
               + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" 
+ "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|"
               + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" + 
"([Tt][Ee][Ss][Tt][_.0-9]*)|"
               + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + 
"([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|"
  +            + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + 
"([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|"
               + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" + 
"([Nn][Ii][Gg][Hh][Tt][Ll][Yy])";
   
           // let's discover the version, and whatever's leftover will be either
  
  
  
  1.3       +0 -11     
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java
  
  Index: ArtifactDigestVerifier.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArtifactDigestVerifier.java       1 Apr 2005 02:45:05 -0000       1.2
  +++ ArtifactDigestVerifier.java       2 Apr 2005 02:17:19 -0000       1.3
  @@ -42,17 +42,6 @@
           // create the digest target file from which to copy/create.
           File digestTargetFile = new File( artifactTarget + ".md5" );
           
  -        if(!reportOnly)
  -        {
  -            File targetParent = digestTargetFile.getParentFile();
  -
  -            if ( !targetParent.exists() )
  -            {
  -                reporter.info( "MD5 parent directory \'" + targetParent + 
"\' does not exist. Creating..." );
  -                targetParent.mkdirs();
  -            }
  -        }
  -
           boolean verified = false;
   
           // if the digest source file exists, then verify it.
  
  
  
  1.3       +51 -46    
maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestor.java
  
  Index: ArtifactDigestor.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArtifactDigestor.java     23 Mar 2005 04:53:29 -0000      1.2
  +++ ArtifactDigestor.java     2 Apr 2005 02:17:19 -0000       1.3
  @@ -4,14 +4,14 @@
   import org.codehaus.plexus.util.IOUtil;
   
   import java.io.BufferedInputStream;
  -import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
   import java.security.MessageDigest;
   import java.security.NoSuchAlgorithmException;
  -import java.util.Arrays;
   
   /**
    * @author jdcasey
  @@ -43,58 +43,86 @@
       public boolean verifyArtifactDigest( File artifactFile, File digestFile, 
String algorithm )
           throws ArtifactDigestException
       {
  -        boolean result = false;
  -        
           if(artifactFile.exists() && digestFile.exists())
           {
               byte[] generatedDigest = generateArtifactDigest( artifactFile, 
algorithm );
  -            byte[] digestFromFile = null;
  -    
  +            
  +            InputStream in = null;
               try
               {
  -                digestFromFile = readFile( digestFile );
  +                in = new FileInputStream( artifactFile );
  +                
  +                int digestLen = generatedDigest.length;
  +                int currentIdx = 0;
  +                
  +                boolean matched = true;
  +                
  +                int read = -1;
  +                while ( ( read = in.read() ) > -1 )
  +                {
  +                    if(currentIdx >= digestLen || read != 
generatedDigest[currentIdx])
  +                    {
  +                        return false;
  +                    }
  +                }
               }
  -            catch ( Exception e )
  +            catch ( IOException e )
               {
  -                throw new ArtifactDigestException( "Cannot read digest from 
file: \'" + digestFile + "\'", e );
  +                throw new ArtifactDigestException("Cannot verify digest for 
artifact file: \'" + artifactFile + "\' against digest file: \'" + digestFile + 
"\' using algorithm: \'" + algorithm + "\'", e);
               }
  -    
  -            result = Arrays.equals( generatedDigest, digestFromFile );
  +            finally
  +            {
  +                IOUtil.close( in );
  +            }
  +            
  +        }
  +        else
  +        {
  +            return false;
           }
           
  -        return result;
  +        return true;
       }
       
       private byte[] generateArtifactDigest( File artifactFile, String 
algorithm ) throws ArtifactDigestException
       {
  -        byte[] data = null;
  +        MessageDigest digest = null;
           try
           {
  -            data = readFile( artifactFile );
  +            digest = MessageDigest.getInstance( algorithm );
           }
  -        catch ( IOException e )
  +        catch ( NoSuchAlgorithmException e )
           {
  -            throw new ArtifactDigestException( "Error reading artifact data 
from: \'" + artifactFile + "\'", e );
  +            throw new ArtifactDigestException( "Cannot load digest algoritm 
provider.", e );
           }
   
  -        MessageDigest digest = null;
  +        InputStream in = null;
           try
           {
  -            digest = MessageDigest.getInstance( algorithm );
  +            in = new BufferedInputStream( new FileInputStream( artifactFile 
) );
  +
  +            byte[] buffer = new byte[16];
  +            int read = -1;
  +            while ( ( read = in.read( buffer ) ) > -1 )
  +            {
  +                digest.update(buffer, 0, read);
  +            }
           }
  -        catch ( NoSuchAlgorithmException e )
  +        catch ( IOException e )
           {
  -            throw new ArtifactDigestException( "Cannot load digest algoritm 
provider.", e );
  +            throw new ArtifactDigestException( "Error reading artifact data 
from: \'" + artifactFile + "\'", e );
  +        }
  +        finally
  +        {
  +            IOUtil.close( in );
           }
   
  -        digest.update( data );
  -        
           return digest.digest();
       }
   
       private void writeDigestFile( File digestFile, byte[] digestData ) 
throws IOException
       {
  -        FileOutputStream out = null;
  +        OutputStream out = null;
           try
           {
               out = new FileOutputStream( digestFile );
  @@ -107,27 +135,4 @@
           }
       }
   
  -    private byte[] readFile( File artifactFile ) throws IOException
  -    {
  -        BufferedInputStream in = null;
  -        try
  -        {
  -            in = new BufferedInputStream( new FileInputStream( artifactFile 
) );
  -            ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -
  -            byte[] buffer = new byte[16];
  -            int read = -1;
  -            while ( ( read = in.read( buffer ) ) > -1 )
  -            {
  -                baos.write( buffer, 0, read );
  -            }
  -
  -            return baos.toByteArray();
  -        }
  -        finally
  -        {
  -            IOUtil.close( in );
  -        }
  -    }
  -
   }
  \ No newline at end of file
  
  
  

Reply via email to