maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject cvs commit: maven-components/maven-artifact/src/main/resources/META-INF/plexus components.xml
Date Wed, 23 Mar 2005 04:53:30 GMT
jdcasey     2005/03/22 20:53:30

  Modified:    sandbox/repoclean/src/main/resources/META-INF/plexus
                        components.xml
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest
                        ArtifactDigestor.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate
                        PomV3ToV4Translator.java
               maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout
                        DefaultRepositoryLayout.java
                        AbstractArtifactRepositoryLayout.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean
                        RepositoryCleaner.java Main.java
               sandbox/repoclean pom.xml install.sh
               sandbox/repoclean/src/main/bash repoclean.sh
               maven-artifact/src/main/resources/META-INF/plexus
                        components.xml
  Added:       sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite
                        V4PomRewriter.java ArtifactPomRewriter.java
                        V3PomRewriter.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest
                        ArtifactDigestVerificationException.java
                        ArtifactDigestVerifier.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean
                        RepositoryCleanerConfiguration.java
               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/artifact
                        LegacyPluginHandler.java
  Removed:     sandbox/repoclean/src/main/java/org/apache/maven/model/v4_0_0
                        MailingList.java Developer.java Scm.java
                        Parent.java Plugin.java PluginManagement.java
                        Notifier.java Build.java Contributor.java Goal.java
                        Resource.java Model.java Organization.java
                        PatternSet.java DependencyManagement.java
                        DistributionManagement.java CiManagement.java
                        Repository.java FileSet.java License.java
                        Reports.java Dependency.java Site.java
                        IssueManagement.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/correlate
                        ArtifactPomCorrelator.java
                        ArtifactMd5Correlator.java
               sandbox/repoclean/src/test/java/org/apache/maven/tools/repoclean/patch
                        V4ModelPatcherTest.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/validate
                        V4ModelIndependenceValidator.java
               sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/patch
                        V4ModelPatcher.java
               sandbox/repoclean/src/main/java/org/apache/maven/model/v4_0_0/io/xpp3
                        MavenXpp3Reader.java MavenXpp3Writer.java
  Log:
  o Fixed a configuration issue for the DefaultRepositoryLayout in components.xml...it needed a requirement on the ArtifactHandlerManager.
  o Fixed a formatting issue for the layout in DefaultRepositoryLayout relating to groupId's.
  o Revamped the repoclean tool to use an Artifact-centric approach to converting, cleaning, and reporting on repositories.
  o Added the ability for repoclean to report on the health of an existing v3 or v4 repository, using a DefaultArtifactDiscoverer (Default* being the prefix given to the new repo layout going forward) and a V4PomRewriter implementation.
  o Tested repoclean by converting my local m1 repository to a m2 repository.
  
  Revision  Changes    Path
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V4PomRewriter.java
  
  Index: V4PomRewriter.java
  ===================================================================
  package org.apache.maven.tools.repoclean.rewrite;
  
  /* ====================================================================
   *   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.
   * ====================================================================
   */
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.model.Model;
  import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
  import org.apache.maven.tools.repoclean.report.Reporter;
  import org.codehaus.plexus.util.IOUtil;
  import org.codehaus.plexus.util.StringUtils;
  
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  
  /**
   * @author jdcasey
   */
  public class V4PomRewriter implements ArtifactPomRewriter
  {
      public void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly  ) throws Exception
      {
          Model model = null;
          
          if(from.exists())
          {
              FileReader fromReader = null;
              try
              {
                  fromReader = new FileReader(from);
                  
                  MavenXpp3Reader reader = new MavenXpp3Reader();
                  
                  try
                  {
                      model = reader.read( fromReader );
                  }
                  catch ( Exception e )
                  {
                      reporter.error("Invalid v4 POM at \'" + from + "\'. Cannot read.", e);
                  }
              }
              finally
              {
                  IOUtil.close(fromReader);
              }
          }
          else
          {
              reporter.error( "POM for artifact[" + artifact.getId() + "] does not exist in source repository!" );
          }
          
          if ( model != null )
          {
              validateBasics( model, artifact, reporter );
  
              if ( !reportOnly )
              {
                  File toParent = to.getParentFile();
                  if ( !toParent.exists() )
                  {
                      toParent.mkdirs();
                  }
  
                  FileWriter toWriter = null;
                  try
                  {
                      toWriter = new FileWriter( to );
                      MavenXpp3Writer writer = new MavenXpp3Writer();
                      writer.write( toWriter, model );
                  }
                  finally
                  {
                      IOUtil.close( toWriter );
                  }
              }
              else
              {
                  reporter.info( "Skipping model write to target repository (we're in report-only mode)." );
              }
          }
      }
  
      private void validateBasics( Model model, Artifact artifact, Reporter reporter )
      {
          if(StringUtils.isEmpty( model.getModelVersion() ) )
          {
              reporter.info("Setting modelVersion on v4 model to \'4.0.0\'");
              model.setModelVersion("4.0.0");
          }
          
          if(StringUtils.isEmpty(model.getGroupId()))
          {
              reporter.info("Setting groupId on model using artifact information.");
              model.setGroupId(artifact.getGroupId());
          }
          
          if(StringUtils.isEmpty(model.getArtifactId()))
          {
              reporter.info("Setting artifactId on model using artifact information.");
              model.setArtifactId(artifact.getArtifactId());
          }
          
          if(StringUtils.isEmpty(model.getVersion()))
          {
              reporter.info("Setting version on model using artifact information.");
              model.setVersion(artifact.getVersion());
          }
          
          if(StringUtils.isEmpty(model.getPackaging()))
          {
              reporter.info("Setting packaging on model using artifact type information.");
              model.setPackaging(artifact.getType());
          }
      }
  
  }
  
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/ArtifactPomRewriter.java
  
  Index: ArtifactPomRewriter.java
  ===================================================================
  package org.apache.maven.tools.repoclean.rewrite;
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.tools.repoclean.report.Reporter;
  
  import java.io.File;
  
  /* ====================================================================
   *   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 interface ArtifactPomRewriter
  {
      
      public static final String ROLE = ArtifactPomRewriter.class.getName();
      
      void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly ) throws Exception;
  
  }
  
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/rewrite/V3PomRewriter.java
  
  Index: V3PomRewriter.java
  ===================================================================
  package org.apache.maven.tools.repoclean.rewrite;
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.model.Model;
  import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
  import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader;
  import org.apache.maven.tools.repoclean.report.Reporter;
  import org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator;
  import org.codehaus.plexus.util.IOUtil;
  import org.codehaus.plexus.util.StringUtils;
  
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  
  /* ====================================================================
   *   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 V3PomRewriter
      implements ArtifactPomRewriter
  {
      private PomV3ToV4Translator translator;
  
      public void rewrite( Artifact artifact, File from, File to, Reporter reporter, boolean reportOnly )
          throws Exception
      {
          Model v4Model = null;
  
          if ( from.exists() )
          {
              FileReader fromReader = null;
              try
              {
                  org.apache.maven.model.v3_0_0.Model v3Model = null;
                  try
                  {
                      fromReader = new FileReader( from );
  
                      MavenXpp3Reader v3Reader = new MavenXpp3Reader();
  
                      v3Model = v3Reader.read( fromReader );
                  }
                  catch ( Exception e )
                  {
                      reporter.error( "Invalid v3 POM at: \'" + from + "\'. Cannot read.", e );
                  }
  
                  if(v3Model != null)
                  {
                      v4Model = translator.translate( v3Model, reporter );
                  }
              }
              finally
              {
                  IOUtil.close( fromReader );
              }
          }
          else
          {
              reporter.info( "POM for artifact[" + artifact.getId()
                  + "] does not exist in source repository. We will create a skeletal one here." );
              
              v4Model = new Model();
          }
  
          if(v4Model != null)
          {
              validateV4Basics( v4Model, artifact, reporter );
  
              if ( !reportOnly )
              {
                  File toParent = to.getParentFile();
                  if ( !toParent.exists() )
                  {
                      toParent.mkdirs();
                  }
  
                  FileWriter toWriter = null;
                  try
                  {
                      toWriter = new FileWriter( to );
                      MavenXpp3Writer v4Writer = new MavenXpp3Writer();
                      v4Writer.write( toWriter, v4Model );
                  }
                  finally
                  {
                      IOUtil.close( toWriter );
                  }
              }
              else
              {
                  reporter.info( "Skipping model write to target repository (we're in report-only mode)." );
              }
          }
      }
  
      private void validateV4Basics( Model model, Artifact artifact, Reporter reporter )
      {
          if ( StringUtils.isEmpty( model.getModelVersion() ) )
          {
              reporter.info( "Setting modelVersion on v4 model to \'4.0.0\'" );
              model.setModelVersion( "4.0.0" );
          }
  
          if ( StringUtils.isEmpty( model.getGroupId() ) )
          {
              reporter.info( "Setting groupId on model using artifact information." );
              model.setGroupId( artifact.getGroupId() );
          }
  
          if ( StringUtils.isEmpty( model.getArtifactId() ) )
          {
              reporter.info( "Setting artifactId on model using artifact information." );
              model.setArtifactId( artifact.getArtifactId() );
          }
  
          if ( StringUtils.isEmpty( model.getVersion() ) )
          {
              reporter.info( "Setting version on model using artifact information." );
              model.setVersion( artifact.getVersion() );
          }
  
          if ( StringUtils.isEmpty( model.getPackaging() ) )
          {
              reporter.info( "Setting packaging on model using artifact type information." );
              model.setPackaging( artifact.getType() );
          }
      }
  
  }
  
  
  1.3       +41 -25    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- components.xml	18 Mar 2005 17:06:25 -0000	1.2
  +++ components.xml	23 Mar 2005 04:53:29 -0000	1.3
  @@ -6,23 +6,21 @@
        |
        -->
       <component>
  +      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
  +      <role-hint>plugin</role-hint>
  +      <implementation>org.apache.maven.tools.repoclean.artifact.LegacyPluginHandler</implementation>
  +    </component>
  +    <!--
  +     |
  +     |
  +     |
  +     -->
  +    <component>
         <role>org.apache.maven.tools.repoclean.RepositoryCleaner</role>
         <implementation>org.apache.maven.tools.repoclean.RepositoryCleaner</implementation>
         <requirements>
           <requirement>
  -          <role>org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator</role>
  -        </requirement>
  -        <requirement>
  -          <role>org.apache.maven.tools.repoclean.correlate.ArtifactPomCorrelator</role>
  -        </requirement>
  -        <requirement>
  -          <role>org.apache.maven.tools.repoclean.correlate.ArtifactMd5Correlator</role>
  -        </requirement>
  -        <requirement>
  -		      <role>org.apache.maven.tools.repoclean.validate.V4ModelIndependenceValidator</role>
  -        </requirement>
  -        <requirement>
  -		      <role>org.apache.maven.tools.repoclean.patch.V4ModelPatcher</role>
  +          <role>org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier</role>
           </requirement>
         </requirements>
       </component>
  @@ -32,8 +30,9 @@
        |
        -->
       <component>
  -      <role>org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator</role>
  -      <implementation>org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator</implementation>
  +      <role>org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer</role>
  +      <role-hint>legacy</role-hint>
  +      <implementation>org.apache.maven.tools.repoclean.discover.LegacyArtifactDiscoverer</implementation>
       </component>
       <!--
        |
  @@ -41,8 +40,18 @@
        |
        -->
       <component>
  -      <role>org.apache.maven.tools.repoclean.correlate.ArtifactMd5Correlator</role>
  -      <implementation>org.apache.maven.tools.repoclean.correlate.ArtifactMd5Correlator</implementation>
  +      <role>org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer</role>
  +      <role-hint>default</role-hint>
  +      <implementation>org.apache.maven.tools.repoclean.discover.DefaultArtifactDiscoverer</implementation>
  +    </component>
  +    <!--
  +     |
  +     |
  +     |
  +     -->
  +    <component>
  +      <role>org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier</role>
  +      <implementation>org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier</implementation>
         <requirements>
           <requirement>
             <role>org.apache.maven.tools.repoclean.digest.ArtifactDigestor</role>
  @@ -55,8 +64,8 @@
        |
        -->
       <component>
  -      <role>org.apache.maven.tools.repoclean.correlate.ArtifactPomCorrelator</role>
  -      <implementation>org.apache.maven.tools.repoclean.correlate.ArtifactPomCorrelator</implementation>
  +      <role>org.apache.maven.tools.repoclean.digest.ArtifactDigestor</role>
  +      <implementation>org.apache.maven.tools.repoclean.digest.ArtifactDigestor</implementation>
       </component>
       <!--
        |
  @@ -64,8 +73,14 @@
        |
        -->
       <component>
  -      <role>org.apache.maven.tools.repoclean.validate.V4ModelIndependenceValidator</role>
  -      <implementation>org.apache.maven.tools.repoclean.validate.V4ModelIndependenceValidator</implementation>
  +      <role>org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter</role>
  +      <role-hint>v3</role-hint>
  +      <implementation>org.apache.maven.tools.repoclean.rewrite.V3PomRewriter</implementation>
  +      <requirements>
  +        <requirement>
  +          <role>org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator</role>
  +        </requirement>
  +      </requirements>
       </component>
       <!--
        |
  @@ -73,8 +88,9 @@
        |
        -->
       <component>
  -      <role>org.apache.maven.tools.repoclean.patch.V4ModelPatcher</role>
  -      <implementation>org.apache.maven.tools.repoclean.patch.V4ModelPatcher</implementation>
  +      <role>org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter</role>
  +      <role-hint>v4</role-hint>
  +      <implementation>org.apache.maven.tools.repoclean.rewrite.V4PomRewriter</implementation>
       </component>
       <!--
        |
  @@ -82,8 +98,8 @@
        |
        -->
       <component>
  -      <role>org.apache.maven.tools.repoclean.digest.ArtifactDigestor</role>
  -      <implementation>org.apache.maven.tools.repoclean.digest.ArtifactDigestor</implementation>
  +      <role>org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator</role>
  +      <implementation>org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator</implementation>
       </component>
     </components>
   </component-set>
  
  
  
  1.2       +45 -12    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArtifactDigestor.java	17 Mar 2005 22:56:40 -0000	1.1
  +++ ArtifactDigestor.java	23 Mar 2005 04:53:29 -0000	1.2
  @@ -11,6 +11,7 @@
   import java.io.IOException;
   import java.security.MessageDigest;
   import java.security.NoSuchAlgorithmException;
  +import java.util.Arrays;
   
   /**
    * @author jdcasey
  @@ -27,10 +28,49 @@
       public void createArtifactDigest( File artifactFile, File digestFile, String algorithm )
           throws ArtifactDigestException
       {
  +        byte[] digestData = generateArtifactDigest( artifactFile, algorithm );
  +
  +        try
  +        {
  +            writeDigestFile( digestFile, digestData );
  +        }
  +        catch ( IOException e )
  +        {
  +            throw new ArtifactDigestException( "Cannot write digest to file: \'" + digestFile + "\'", e );
  +        }
  +    }
  +
  +    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;
  +    
  +            try
  +            {
  +                digestFromFile = readFile( digestFile );
  +            }
  +            catch ( Exception e )
  +            {
  +                throw new ArtifactDigestException( "Cannot read digest from file: \'" + digestFile + "\'", e );
  +            }
  +    
  +            result = Arrays.equals( generatedDigest, digestFromFile );
  +        }
  +        
  +        return result;
  +    }
  +    
  +    private byte[] generateArtifactDigest( File artifactFile, String algorithm ) throws ArtifactDigestException
  +    {
           byte[] data = null;
           try
           {
  -            data = readArtifactFile( artifactFile );
  +            data = readFile( artifactFile );
           }
           catch ( IOException e )
           {
  @@ -48,16 +88,8 @@
           }
   
           digest.update( data );
  -        byte[] digestData = digest.digest();
  -
  -        try
  -        {
  -            writeDigestFile( digestFile, digestData );
  -        }
  -        catch ( IOException e )
  -        {
  -            throw new ArtifactDigestException( "Cannot write digest to file: \'" + digestFile + "\'", e );
  -        }
  +        
  +        return digest.digest();
       }
   
       private void writeDigestFile( File digestFile, byte[] digestData ) throws IOException
  @@ -75,7 +107,7 @@
           }
       }
   
  -    private byte[] readArtifactFile( File artifactFile ) throws IOException
  +    private byte[] readFile( File artifactFile ) throws IOException
       {
           BufferedInputStream in = null;
           try
  @@ -97,4 +129,5 @@
               IOUtil.close( in );
           }
       }
  +
   }
  \ No newline at end of file
  
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerificationException.java
  
  Index: ArtifactDigestVerificationException.java
  ===================================================================
  package org.apache.maven.tools.repoclean.digest;
  
  /* ====================================================================
   *   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 ArtifactDigestVerificationException
      extends Exception
  {
  
      public ArtifactDigestVerificationException()
      {
      }
  
      public ArtifactDigestVerificationException( String message )
      {
          super( message );
      }
  
      public ArtifactDigestVerificationException( String message, Throwable cause )
      {
          super( message, cause );
      }
  
      public ArtifactDigestVerificationException( Throwable cause )
      {
          super( cause );
      }
      
  }
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/digest/ArtifactDigestVerifier.java
  
  Index: ArtifactDigestVerifier.java
  ===================================================================
  package org.apache.maven.tools.repoclean.digest;
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.repository.ArtifactRepository;
  import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
  import org.apache.maven.tools.repoclean.report.Reporter;
  import org.codehaus.plexus.util.FileUtils;
  
  import java.io.File;
  import java.io.IOException;
  
  /* ====================================================================
   *   Copyright 2001-2004 The Apache Software Foundation.
   *
   *   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 ArtifactDigestVerifier
  {
  
      public static final String ROLE = ArtifactDigestVerifier.class.getName();
  
      private ArtifactDigestor artifactDigestor;
  
      public void verifyDigest( Artifact artifact, ArtifactRepository sourceRepo, ArtifactRepository targetRepo,
                               Reporter reporter, boolean reportOnly ) throws Exception
      {
          File sourceBase = new File( sourceRepo.getBasedir() );
          File targetBase = new File( targetRepo.getBasedir() );
  
          // create the digest source file from which to copy/verify.
          File digestSourceFile = null;
          try
          {
              digestSourceFile = new File( sourceBase, sourceRepo.pathOf( artifact ) + ".md5" );
          }
          catch ( ArtifactPathFormatException e )
          {
              reporter.error( "Error creating java.io.File of digest source for artifact[" + artifact.getId() + "]", e );
  
              throw e;
          }
  
          // create the digest target file from which to copy/create.
          File digestTargetFile = null;
          try
          {
              digestTargetFile = new File( targetBase, targetRepo.pathOf( artifact ) + ".md5" );
          }
          catch ( ArtifactPathFormatException e )
          {
              reporter.error( "Error creating java.io.File of digest target for artifact[" + artifact.getId() + "]", e );
  
              throw e;
          }
          
          if(!reportOnly)
          {
              File targetParent = digestTargetFile.getParentFile();
  
              if ( !targetParent.exists() )
              {
                  reporter.info( "MD5 parent directory \'" + targetParent + "\' does not exist. Creating..." );
                  targetParent.mkdirs();
              }
          }
  
          // create the artifact file in the target repo to use for generating a new digest.
          File artifactTargetFile = null;
          try
          {
              artifactTargetFile = new File( targetBase, targetRepo.pathOf( artifact ) );
          }
          catch ( ArtifactPathFormatException e )
          {
              reporter.error( "Error creating java.io.File for artifact[" + artifact.getId() + "]", e );
  
              throw e;
          }
  
          boolean verified = false;
  
          // if the digest source file exists, then verify it.
          if ( digestSourceFile.exists() )
          {
              verified = artifactDigestor.verifyArtifactDigest( artifactTargetFile, digestTargetFile,
                                                                ArtifactDigestor.MD5 );
  
              if ( verified )
              {
                  reporter.info( "Source digest file for artifact[" + artifact.getId()
                      + "] is okay, so we'll just copy it." );
  
                  if ( !reportOnly )
                  {
                      try
                      {
                          FileUtils.copyFile( digestSourceFile, digestTargetFile );
                      }
                      catch ( IOException e )
                      {
                          reporter.error( "Cannot copy digest file for artifact[" + artifact.getId()
                              + "] from source to target.", e );
  
                          throw e;
                      }
                  }
                  else
                  {
                      reporter.info( "Skipping transfer of valid MD5 digest file (we're in report-only mode)." );
                  }
              }
              else
              {
                  reporter.warn( ".md5 for artifact[" + artifact.getId() + "] in target repository is wrong." );
              }
          }
          else
          {
              reporter.warn( ".md5 for artifact[" + artifact.getId() + "] is missing in source repository." );
          }
  
          // if the .md5 was missing or did not verify correctly, create a new one
          // in the target repo.
          if ( !verified )
          {
              reporter.info( "Creating .md5 for artifact[" + artifact.getId() + "] in target repository." );
  
              if ( !reportOnly )
              {
                  artifactDigestor.createArtifactDigest( artifactTargetFile, digestTargetFile, ArtifactDigestor.MD5 );
              }
              else
              {
                  reporter.info( "Skipping creation of MD5 digest for artifact (we're in report-only mode)." );
              }
          }
      }
  
  }
  
  
  1.2       +101 -81   maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java
  
  Index: PomV3ToV4Translator.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/translate/PomV3ToV4Translator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PomV3ToV4Translator.java	18 Mar 2005 17:06:26 -0000	1.1
  +++ PomV3ToV4Translator.java	23 Mar 2005 04:53:29 -0000	1.2
  @@ -1,27 +1,28 @@
   package org.apache.maven.tools.repoclean.translate;
   
  -import org.apache.maven.model.v4_0_0.Build;
  -import org.apache.maven.model.v4_0_0.CiManagement;
  -import org.apache.maven.model.v4_0_0.Contributor;
  -import org.apache.maven.model.v4_0_0.Dependency;
  -import org.apache.maven.model.v4_0_0.Developer;
  -import org.apache.maven.model.v4_0_0.DistributionManagement;
  -import org.apache.maven.model.v4_0_0.Goal;
  -import org.apache.maven.model.v4_0_0.IssueManagement;
  -import org.apache.maven.model.v4_0_0.License;
  -import org.apache.maven.model.v4_0_0.MailingList;
  -import org.apache.maven.model.v4_0_0.Model;
  -import org.apache.maven.model.v4_0_0.Notifier;
  -import org.apache.maven.model.v4_0_0.Organization;
  -import org.apache.maven.model.v4_0_0.Plugin;
  -import org.apache.maven.model.v4_0_0.Reports;
  -import org.apache.maven.model.v4_0_0.Repository;
  -import org.apache.maven.model.v4_0_0.Resource;
  -import org.apache.maven.model.v4_0_0.Scm;
  -import org.apache.maven.model.v4_0_0.Site;
  +import org.apache.maven.model.Build;
  +import org.apache.maven.model.CiManagement;
  +import org.apache.maven.model.Contributor;
  +import org.apache.maven.model.Dependency;
  +import org.apache.maven.model.Developer;
  +import org.apache.maven.model.DistributionManagement;
  +import org.apache.maven.model.Goal;
  +import org.apache.maven.model.IssueManagement;
  +import org.apache.maven.model.License;
  +import org.apache.maven.model.MailingList;
  +import org.apache.maven.model.Model;
  +import org.apache.maven.model.Notifier;
  +import org.apache.maven.model.Organization;
  +import org.apache.maven.model.Plugin;
  +import org.apache.maven.model.Reports;
  +import org.apache.maven.model.Repository;
  +import org.apache.maven.model.Resource;
  +import org.apache.maven.model.Scm;
  +import org.apache.maven.model.Site;
   import org.apache.maven.tools.repoclean.report.Reporter;
   import org.codehaus.plexus.logging.AbstractLogEnabled;
   import org.codehaus.plexus.util.StringUtils;
  +import org.codehaus.plexus.util.xml.Xpp3Dom;
   
   import java.util.ArrayList;
   import java.util.Iterator;
  @@ -30,21 +31,19 @@
   import java.util.regex.Matcher;
   import java.util.regex.Pattern;
   
  -/* ====================================================================
  - *   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.
  - * ====================================================================
  +/*
  + * ==================================================================== 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. ====================================================================
    */
   
   /**
  @@ -84,8 +83,11 @@
           PomKey pomKey = new PomKey( groupId, artifactId, version );
   
           StringBuffer logHeader = new StringBuffer();
  -        logHeader.append( "Translation of POM {" ).append( v3Model.getGroupId() ).append( ":" )
  -                 .append( v3Model.getArtifactId() ).append( ":" ).append( version ).append( "}\n" );
  +        logHeader.append( "Translation of POM {" ).append( v3Model.getGroupId() ).append( ":" ).append(
  +                                                                                                        v3Model.getArtifactId() ).append(
  +                                                                                                                                          ":" ).append(
  +                                                                                                                                                        version ).append(
  +                                                                                                                                                                          "}" );
   
           reporter.info( "[START] " + logHeader.toString() );
   
  @@ -258,11 +260,15 @@
   
                   StringBuffer info = new StringBuffer();
   
  -                info.append( "Using some contrived information for report: \'" ).append( reportName ).append( "\'.\n" )
  -                    .append( "\to groupId: \'maven\'\n" ).append( "\to artifactId: \'" ).append( reportPluginName )
  -                    .append( "\'\n" ).append( "\to version: \'1.0-SNAPSHOT\'\n" ).append( "\to goal: \'report\'\n" )
  -                    .append( "\n" )
  -                    .append( "These values were extracted using the v3 report naming convention, but may be wrong." );
  +                info.append( "Using some contrived information for report: \'" ).append( reportName ).append( "\'.\n" ).append(
  +                                                                                                                                "\to groupId: \'maven\'\n" ).append(
  +                                                                                                                                                                     "\to artifactId: \'" ).append(
  +                                                                                                                                                                                                    reportPluginName ).append(
  +                                                                                                                                                                                                                               "\'\n" ).append(
  +                                                                                                                                                                                                                                                "\to version: \'1.0-SNAPSHOT\'\n" ).append(
  +                                                                                                                                                                                                                                                                                            "\to goal: \'report\'\n" ).append(
  +                                                                                                                                                                                                                                                                                                                               "\n" ).append(
  +                                                                                                                                                                                                                                                                                                                                              "These values were extracted using the v3 report naming convention, but may be wrong." );
   
                   reporter.info( info.toString() );
   
  @@ -279,9 +285,9 @@
           return reports;
       }
   
  -    private org.apache.maven.model.v4_0_0.Organization translateOrganization(
  -                                                                             org.apache.maven.model.v3_0_0.Organization v3Organization,
  -                                                                             Reporter reporter )
  +    private org.apache.maven.model.Organization translateOrganization(
  +                                                                      org.apache.maven.model.v3_0_0.Organization v3Organization,
  +                                                                      Reporter reporter )
       {
           Organization organization = null;
   
  @@ -309,8 +315,7 @@
           {
               for ( Iterator it = v3MailingLists.iterator(); it.hasNext(); )
               {
  -                org.apache.maven.model.v3_0_0.MailingList v3List = (org.apache.maven.model.v3_0_0.MailingList) it
  -                                                                                                                 .next();
  +                org.apache.maven.model.v3_0_0.MailingList v3List = (org.apache.maven.model.v3_0_0.MailingList) it.next();
                   MailingList list = new MailingList();
                   list.setArchive( v3List.getArchive() );
                   list.setName( v3List.getName() );
  @@ -420,7 +425,8 @@
                   repository.setName( "Default Repository" );
   
                   repository.setUrl( "file://" + distributionDirectory );
  -                //                throw new Exception( "Missing 'distributionSite': Both distributionSite and distributionDirectory must be set." );
  +                //                throw new Exception( "Missing 'distributionSite': Both distributionSite and
  +                // distributionDirectory must be set." );
               }
           }
           else
  @@ -458,8 +464,7 @@
           {
               for ( Iterator it = v3Developers.iterator(); it.hasNext(); )
               {
  -                org.apache.maven.model.v3_0_0.Developer v3Developer = (org.apache.maven.model.v3_0_0.Developer) it
  -                                                                                                                  .next();
  +                org.apache.maven.model.v3_0_0.Developer v3Developer = (org.apache.maven.model.v3_0_0.Developer) it.next();
   
                   Developer developer = new Developer();
   
  @@ -510,8 +515,7 @@
           {
               for ( Iterator it = v3Contributors.iterator(); it.hasNext(); )
               {
  -                org.apache.maven.model.v3_0_0.Contributor v3Contributor = (org.apache.maven.model.v3_0_0.Contributor) it
  -                                                                                                                        .next();
  +                org.apache.maven.model.v3_0_0.Contributor v3Contributor = (org.apache.maven.model.v3_0_0.Contributor) it.next();
   
                   Contributor contributor = new Contributor();
   
  @@ -560,23 +564,39 @@
                       plugin.setArtifactId( "surefire" );
                       plugin.setVersion( "1.0-SNAPSHOT" );
   
  -                    Properties config = new Properties();
  +                    Xpp3Dom config = new Xpp3Dom( "configuration" );
   
  -                    String includes = pathPatternsToString( testIncludes );
  -
  -                    if ( StringUtils.isNotEmpty( includes ) )
  +                    if ( notEmpty( testIncludes ) )
                       {
  -                        config.setProperty( "includes", includes );
  -                    }
  +                        Xpp3Dom includes = new Xpp3Dom( "includes" );
  +                        for ( Iterator it = testIncludes.iterator(); it.hasNext(); )
  +                        {
  +                            String includePattern = (String) it.next();
  +                            Xpp3Dom include = new Xpp3Dom( "include" );
  +                            include.setValue( includePattern );
   
  -                    String excludes = pathPatternsToString( testExcludes );
  +                            includes.addChild( include );
  +                        }
  +
  +                        config.addChild( includes );
  +                    }
   
  -                    if ( StringUtils.isNotEmpty( excludes ) )
  +                    if ( notEmpty( testExcludes ) )
                       {
  -                        config.setProperty( "excludes", excludes );
  +                        Xpp3Dom excludes = new Xpp3Dom( "excludes" );
  +                        for ( Iterator it = testExcludes.iterator(); it.hasNext(); )
  +                        {
  +                            String excludePattern = (String) it.next();
  +                            Xpp3Dom exclude = new Xpp3Dom( "exclude" );
  +                            exclude.setValue( excludePattern );
  +
  +                            excludes.addChild( exclude );
  +                        }
  +
  +                        config.addChild( excludes );
                       }
   
  -                    if ( !config.isEmpty() )
  +                    if ( config.getChildCount() > 0 )
                       {
                           plugin.setConfiguration( config );
                       }
  @@ -619,8 +639,8 @@
                   Resource resource = new Resource();
   
                   resource.setDirectory( v3Resource.getDirectory() );
  -                resource.setExcludes( pathPatternsToString( v3Resource.getExcludes() ) );
  -                resource.setIncludes( pathPatternsToString( v3Resource.getIncludes() ) );
  +                resource.setExcludes( v3Resource.getExcludes() );
  +                resource.setIncludes( v3Resource.getIncludes() );
                   resource.setTargetPath( v3Resource.getTargetPath() );
   
                   resources.add( resource );
  @@ -630,24 +650,24 @@
           return resources;
       }
   
  -    private String pathPatternsToString( List patterns )
  -    {
  -        StringBuffer result = new StringBuffer();
  -
  -        if ( notEmpty( patterns ) )
  -        {
  -            for ( Iterator it = patterns.iterator(); it.hasNext(); )
  -            {
  -                String pattern = (String) it.next();
  -
  -                result.append( "," ).append( pattern );
  -            }
  -
  -            result.setLength( result.length() - 1 );
  -        }
  -
  -        return result.toString();
  -    }
  +//    private String pathPatternsToString( List patterns )
  +//    {
  +//        StringBuffer result = new StringBuffer();
  +//
  +//        if ( notEmpty( patterns ) )
  +//        {
  +//            for ( Iterator it = patterns.iterator(); it.hasNext(); )
  +//            {
  +//                String pattern = (String) it.next();
  +//
  +//                result.append( "," ).append( pattern );
  +//            }
  +//
  +//            result.setLength( result.length() - 1 );
  +//        }
  +//
  +//        return result.toString();
  +//    }
   
       private boolean notEmpty( List test )
       {
  
  
  
  1.3       +1 -1      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java
  
  Index: DefaultRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultRepositoryLayout.java	23 Mar 2005 03:40:12 -0000	1.2
  +++ DefaultRepositoryLayout.java	23 Mar 2005 04:53:30 -0000	1.3
  @@ -25,7 +25,7 @@
   
       protected String layoutPattern()
       {
  -        return "${groupId}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
  +        return "${groupPath}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${extension}";
       }
   
       protected String groupIdAsPath( String groupId )
  
  
  
  1.4       +2 -0      maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java
  
  Index: AbstractArtifactRepositoryLayout.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/AbstractArtifactRepositoryLayout.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractArtifactRepositoryLayout.java	23 Mar 2005 03:40:12 -0000	1.3
  +++ AbstractArtifactRepositoryLayout.java	23 Mar 2005 04:53:30 -0000	1.4
  @@ -20,12 +20,14 @@
   import org.apache.maven.artifact.handler.ArtifactHandler;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
   import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
  +import org.codehaus.plexus.logging.AbstractLogEnabled;
   import org.codehaus.plexus.util.StringUtils;
   
   /**
    * @author jdcasey
    */
   public abstract class AbstractArtifactRepositoryLayout
  +    extends AbstractLogEnabled
       implements ArtifactRepositoryLayout
   {
   
  
  
  
  1.3       +233 -150  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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RepositoryCleaner.java	18 Mar 2005 17:06:26 -0000	1.2
  +++ RepositoryCleaner.java	23 Mar 2005 04:53:30 -0000	1.3
  @@ -1,176 +1,205 @@
   package org.apache.maven.tools.repoclean;
   
  -/* ====================================================================
  - *   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.
  - * ====================================================================
  +/*
  + * ==================================================================== 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. ====================================================================
    */
   
  -import org.apache.maven.tools.repoclean.correlate.ArtifactMd5Correlator;
  -import org.apache.maven.tools.repoclean.correlate.ArtifactPomCorrelator;
  -import org.apache.maven.tools.repoclean.patch.V4ModelPatcher;
  +import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
  +import org.apache.maven.artifact.repository.ArtifactRepository;
  +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
  +import org.apache.maven.tools.repoclean.digest.ArtifactDigestVerifier;
  +import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
   import org.apache.maven.tools.repoclean.report.Reporter;
  -import org.apache.maven.tools.repoclean.translate.PomV3ToV4Translator;
  -import org.apache.maven.tools.repoclean.validate.V4ModelIndependenceValidator;
  +import org.apache.maven.tools.repoclean.rewrite.ArtifactPomRewriter;
  +import org.codehaus.plexus.PlexusConstants;
  +import org.codehaus.plexus.PlexusContainer;
  +import org.codehaus.plexus.context.Context;
   import org.codehaus.plexus.logging.AbstractLogEnabled;
   import org.codehaus.plexus.logging.Logger;
  -import org.codehaus.plexus.util.DirectoryScanner;
  +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
   import org.codehaus.plexus.util.IOUtil;
   
  +import java.io.BufferedInputStream;
  +import java.io.BufferedOutputStream;
   import java.io.File;
  -import java.io.FileReader;
  -import java.io.FileWriter;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
  +import java.util.Iterator;
  +import java.util.List;
   
   /**
    * @author jdcasey
    */
   public class RepositoryCleaner
       extends AbstractLogEnabled
  +    implements Contextualizable
   {
   
       public static final String ROLE = RepositoryCleaner.class.getName();
   
  -    private ArtifactPomCorrelator artifactPomCorrelator;
  +    private ArtifactDigestVerifier artifactDigestVerifier;
   
  -    private ArtifactMd5Correlator artifactMd5Correlator;
  +    private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
   
  -    private PomV3ToV4Translator pomV3ToV4Translator;
  +    private PlexusContainer container;
   
  -    private V4ModelIndependenceValidator v4ModelIndependenceValidator;
  -
  -    private V4ModelPatcher v4ModelPatcher;
  -
  -    public void cleanRepository( String repositoryPath, String reportsDir, boolean reportOnly )
  +    public void cleanRepository( RepositoryCleanerConfiguration configuration )
  +        throws Exception
       {
  -        Logger logger = getLogger();
  -
  -        File reportsBase = new File( reportsDir );
  -        if ( !reportsBase.exists() )
  -        {
  -            logger.info( "Creating reports directory: \'" + reportsDir + "\'" );
  -            reportsBase.mkdirs();
  -        }
  -        else if ( !reportsBase.isDirectory() )
  -        {
  -            logger.error( "Cannot write reports to \'" + reportsDir + "\' because it is not a directory." );
  -
  -            reportsBase = null;
  -        }
  -
  -        File repositoryBase = new File( repositoryPath );
  -        if ( !repositoryBase.exists() )
  -        {
  -            logger.error( "Cannot clean repository \'" + repositoryPath + "\' because it does not exist." );
  +        File reportsBase = normalizeReportsBase( configuration.getReportsPath() );
   
  -            repositoryBase = null;
  -        }
  -        else if ( !repositoryBase.isDirectory() )
  -        {
  -            logger.error( "Cannot clean repository \'" + repositoryPath + "\' because it is not a directory." );
  +        File sourceRepositoryBase = normalizeSourceRepositoryBase( configuration.getSourceRepositoryPath() );
   
  -            repositoryBase = null;
  -        }
  +        File targetRepositoryBase = normalizeTargetRepositoryBase( configuration.getTargetRepositoryPath() );
   
  -        // do not proceed if we cannot produce reports, or if the repository is 
  +        // do not proceed if we cannot produce reports, or if the repository is
           // invalid.
  -        if ( reportsBase != null && repositoryBase != null )
  +        if ( reportsBase != null && sourceRepositoryBase != null && targetRepositoryBase != null )
           {
  -            logger.info( "Scanning for POMs." );
  -            String[] poms = scanPoms( repositoryPath );
  -
  -            logger.info( "Scanning for artifacts." );
  -            String[] artifacts = scanArtifacts( repositoryPath );
  +            Logger logger = getLogger();
   
               Reporter repoReporter = new Reporter( reportsBase, "repository.report.txt" );
   
  -            logger.info( "Correlating artifacts to POMs." );
  -            artifactPomCorrelator.correlateArtifactsToPoms( poms, artifacts, repoReporter );
  -
  -            logger.info( "Correlating artifacts to MD5 digest files." );
  -            artifactMd5Correlator.correlateArtifactsToMd5( repositoryBase, artifacts, repoReporter, reportOnly );
  +            ArtifactDiscoverer artifactDiscoverer = (ArtifactDiscoverer) container.lookup(
  +                                                                                           ArtifactDiscoverer.ROLE,
  +                                                                                           configuration.getSourceRepositoryLayout() );
   
  -            logger.info( "Translating POMs to V4 format." );
  -            for ( int i = 0; i < poms.length; i++ )
  +            logger.info( "Discovering artifacts." );
  +            List artifacts = null;
  +            try
               {
  -                String pom = poms[i];
  -
  -                Reporter pomReporter = new Reporter( reportsBase, pom + ".report.txt" );
  +                artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase, repoReporter );
  +            }
  +            catch ( Exception e )
  +            {
  +                repoReporter.error( "Error discovering artifacts in source repository.", e );
  +            }
   
  -                logger.info( "Reading POM: \'" + pom + "\'" );
  -                org.apache.maven.model.v3_0_0.Model v3Model = null;
  -                try
  -                {
  -                    v3Model = readV3( repositoryBase, pom );
  -                }
  -                catch ( Exception e )
  -                {
  -                    logger.error( "Error reading POM: \'" + pom + "\'", e );
  -                }
  +            if ( artifacts != null )
  +            {
  +                ArtifactRepositoryLayout sourceLayout = (ArtifactRepositoryLayout) container.lookup(
  +                                                                                                     ArtifactRepositoryLayout.ROLE,
  +                                                                                                     configuration.getSourceRepositoryLayout() );
  +
  +                ArtifactRepository sourceRepo = new ArtifactRepository( "source",
  +                                                                        "file://" + sourceRepositoryBase.getAbsolutePath(),
  +                                                                        sourceLayout );
  +
  +                ArtifactRepositoryLayout targetLayout = (ArtifactRepositoryLayout) container.lookup(
  +                                                                                                     ArtifactRepositoryLayout.ROLE,
  +                                                                                                     configuration.getTargetRepositoryLayout() );
  +
  +                ArtifactRepository targetRepo = new ArtifactRepository( "target",
  +                                                                        "file://" + targetRepositoryBase.getAbsolutePath(),
  +                                                                        targetLayout );
   
  -                if ( v3Model != null )
  +                logger.info( "Rewriting POMs and artifact files." );
  +                for ( Iterator it = artifacts.iterator(); it.hasNext(); )
                   {
  -                    logger.info( "Translating POM: \'" + pom + "\'" );
  -                    org.apache.maven.model.v4_0_0.Model v4Model = pomV3ToV4Translator.translate( v3Model, pomReporter );
  -
  -                    logger.info( "Performing validation on resulting v4 model for POM: \'" + pom + "\'" );
  -                    boolean isValid = v4ModelIndependenceValidator.validate( v4Model, pomReporter, true );
  -
  -                    if ( !isValid )
  +                    Artifact artifact = (Artifact) it.next();
  +                    
  +                    Reporter artifactReporter = new Reporter( reportsBase, artifact.getGroupId() + "_"
  +                                                              + artifact.getArtifactId() + "_" + artifact.getVersion() + ".report.txt" );
  +
  +                    boolean errorOccurred = false;
  +                    
  +                    try
                       {
  -                        logger.info( "Patching v4 model for POM: \'" + pom + "\' using information glean from path." );
  -                        v4ModelPatcher.patchModel( v4Model, pom, pomReporter );
  -
  -                        logger.info( "Re-performing validation on patched v4 model for POM: \'" + pom + "\'" );
  -                        isValid = v4ModelIndependenceValidator.validate( v4Model, pomReporter, false );
  +                        if ( !configuration.reportOnly() )
  +                        {
  +                            logger.debug("sourceRepo basedir is: \'" + sourceRepo.getBasedir() + "\'");
  +                            logger.debug("targetRepo basedir is: \'" + targetRepo.getBasedir() + "\'");
  +                            
  +                            File artifactSource = new File( sourceRepo.getBasedir(), sourceRepo.pathOf( artifact ) );
  +                            File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf( artifact ) );
  +
  +                            File targetParent = artifactTarget.getParentFile();
  +                            if ( !targetParent.exists() )
  +                            {
  +                                targetParent.mkdirs();
  +                            }
  +
  +                            logger.debug( "Copying artifact[" + artifact.getId() + "] from \'"
  +                                + artifactSource + "\' to \'" + artifactTarget + "\'." );
  +                            
  +                            copyArtifact( artifactSource, artifactTarget, artifactReporter );
  +                        }
  +                        else
  +                        {
  +                            artifactReporter.info( "Skipping artifact copy (we're in report-only mode)." );
  +                        }
                       }
  -
  -                    if ( pomReporter.hasError() )
  +                    catch ( Exception e )
                       {
  -                        repoReporter.warn( "Translation of POM: \'" + pom + "\' encountered errors." );
  +                        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 ( !reportOnly )
  +                    if ( !errorOccurred )
                       {
  -                        logger.info( "Writing POM: \'" + pom + "\'" );
  +                        logger.debug( "working on digest for artifact[" + artifact.getId() + "] with groupId: \'"
  +                            + artifact.getGroupId() + "\'" );
   
                           try
                           {
  -                            writeV4( repositoryBase, pom, v4Model );
  +                            artifactDigestVerifier.verifyDigest( artifact, sourceRepo, targetRepo, artifactReporter,
  +                                                                 configuration.reportOnly() );
                           }
                           catch ( Exception e )
                           {
  -                            logger.error( "Error writing POM: \'" + pom + "\'", e );
  +                            repoReporter.error( "Error verifying digest for artifact[" + artifact.getId() + "]", e );
                           }
                       }
  -                    else
  +
  +                    if ( !errorOccurred )
                       {
  -                        logger.info( "NOT writing POM: \'" + pom + "\'; we are in report-only mode." );
  +                        Artifact pomArtifact = buildPomArtifact( artifact );
  +
  +                        ArtifactPomRewriter artifactPomRewriter = (ArtifactPomRewriter) container.lookup(
  +                                                                                                          ArtifactPomRewriter.ROLE,
  +                                                                                                          configuration.getSourcePomVersion() );
  +
  +                        File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOf( pomArtifact ) );
  +
  +                        File targetPom = new File( targetRepositoryBase, targetRepo.pathOf( pomArtifact ) );
  +
  +                        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 );
  +                        }
                       }
  -                }
  -                else
  -                {
  -                    pomReporter.error( "Cannot translate pom. V3 model is null." );
  -                }
   
  -                try
  -                {
  -                    pomReporter.writeReport();
  -                }
  -                catch ( IOException e )
  -                {
  -                    logger.error( "Error writing report for POM: \'" + pom + "\'", e );
  +                    try
  +                    {
  +                        artifactReporter.writeReport();
  +                    }
  +                    catch ( IOException e )
  +                    {
  +                        logger.error( "Error writing report for artifact \'" + artifact.getId() + "\'", e );
  +                    }
                   }
               }
   
  @@ -185,65 +214,119 @@
           }
       }
   
  -    private void writeV4( File repositoryBase, String pom, org.apache.maven.model.v4_0_0.Model model ) throws Exception
  +    private void copyArtifact( File artifactSource, File artifactTarget, Reporter reporter ) throws IOException
       {
  -        FileWriter writer = null;
  +        InputStream inStream = null;
  +        OutputStream outStream = null;
           try
           {
  -            File pomFile = new File( repositoryBase, pom );
  -            writer = new FileWriter( pomFile );
  -
  -            org.apache.maven.model.v4_0_0.io.xpp3.MavenXpp3Writer modelWriter = new org.apache.maven.model.v4_0_0.io.xpp3.MavenXpp3Writer();
  -
  -            modelWriter.write( writer, model );
  +            File targetParent = artifactTarget.getParentFile();
  +            if(!targetParent.exists())
  +            {
  +                reporter.info("Creating directory \'" + targetParent + "\'.");
  +                targetParent.mkdirs();
  +            }
  +            
  +            inStream = new BufferedInputStream(new FileInputStream(artifactSource));
  +            outStream = new BufferedOutputStream(new FileOutputStream(artifactTarget));
  +            
  +            byte[] buffer = new byte[16];
  +            int read = -1;
  +            
  +            while((read = inStream.read(buffer)) > -1)
  +            {
  +                outStream.write(buffer, 0, read);
  +            }
  +            
  +            outStream.flush();
           }
           finally
           {
  -            IOUtil.close( writer );
  +            IOUtil.close(inStream);
  +            IOUtil.close(outStream);
           }
       }
   
  -    private org.apache.maven.model.v3_0_0.Model readV3( File repositoryBase, String pom ) throws Exception
  +    private Artifact buildPomArtifact( Artifact artifact )
  +    {
  +        return artifactConstructionSupport.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
  +                                                           artifact.getVersion(), artifact.getScope(), "pom" );
  +    }
  +
  +    private File normalizeTargetRepositoryBase( String targetRepositoryPath )
       {
  -        org.apache.maven.model.v3_0_0.Model model = null;
  +        Logger logger = getLogger();
   
  -        FileReader reader = null;
  -        try
  +        File targetRepositoryBase = new File( targetRepositoryPath );
  +        
  +        logger.info("Target repository is at: \'" + targetRepositoryBase + "\'");
  +
  +        if ( !targetRepositoryBase.exists() )
           {
  -            File pomFile = new File( repositoryBase, pom );
  -            reader = new FileReader( pomFile );
  +            logger.info( "Creating target repository at: \'" + targetRepositoryBase + "\'." );
   
  -            org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader modelReader = new org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader();
  -            model = modelReader.read( reader );
  +            targetRepositoryBase.mkdirs();
           }
  -        finally
  +        else if ( !targetRepositoryBase.isDirectory() )
           {
  -            IOUtil.close( reader );
  +            logger.error( "Cannot write to target repository \'" + targetRepositoryBase
  +                + "\' because it is not a directory." );
  +
  +            targetRepositoryBase = null;
           }
   
  -        return model;
  +        return targetRepositoryBase;
       }
   
  -    private String[] scanPoms( String repositoryPath )
  +    private File normalizeSourceRepositoryBase( String sourceRepositoryPath )
       {
  -        DirectoryScanner scanner = new DirectoryScanner();
  -        scanner.setBasedir( repositoryPath );
  -        scanner.setIncludes( new String[] { "**/poms/*.pom" } );
  +        Logger logger = getLogger();
  +
  +        File sourceRepositoryBase = new File( sourceRepositoryPath );
  +
  +        logger.info("Source repository is at: \'" + sourceRepositoryBase + "\'");
  +
  +        if ( !sourceRepositoryBase.exists() )
  +        {
  +            logger.error( "Cannot convert repository \'" + sourceRepositoryBase + "\' because it does not exist." );
   
  -        scanner.scan();
  +            sourceRepositoryBase = null;
  +        }
  +        else if ( !sourceRepositoryBase.isDirectory() )
  +        {
  +            logger.error( "Cannot convert repository \'" + sourceRepositoryBase + "\' because it is not a directory." );
  +
  +            sourceRepositoryBase = null;
  +        }
   
  -        return scanner.getIncludedFiles();
  +        return sourceRepositoryBase;
       }
   
  -    private String[] scanArtifacts( String repositoryPath )
  +    private File normalizeReportsBase( String reportsPath )
       {
  -        DirectoryScanner scanner = new DirectoryScanner();
  -        scanner.setBasedir( repositoryPath );
  -        scanner.setExcludes( new String[] { "**/poms/*.pom", "**/*.md5" } );
  +        Logger logger = getLogger();
  +
  +        File reportsBase = new File( reportsPath );
  +        if ( !reportsBase.exists() )
  +        {
  +            logger.info( "Creating reports directory: \'" + reportsBase + "\'" );
  +
  +            reportsBase.mkdirs();
  +        }
  +        else if ( !reportsBase.isDirectory() )
  +        {
  +            logger.error( "Cannot write reports to \'" + reportsBase + "\' because it is not a directory." );
  +
  +            reportsBase = null;
  +        }
   
  -        scanner.scan();
  +        return reportsBase;
  +    }
   
  -        return scanner.getIncludedFiles();
  +    public void contextualize( Context context )
  +        throws Exception
  +    {
  +        this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
       }
   
   }
  \ No newline at end of file
  
  
  
  1.2       +89 -17    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Main.java	17 Mar 2005 22:56:41 -0000	1.1
  +++ Main.java	23 Mar 2005 04:53:30 -0000	1.2
  @@ -19,6 +19,11 @@
   
   import org.codehaus.classworlds.ClassWorld;
   import org.codehaus.plexus.embed.Embedder;
  +import org.codehaus.plexus.util.IOUtil;
  +
  +import java.io.FileInputStream;
  +import java.io.IOException;
  +import java.util.Properties;
   
   /**
    * @author jdcasey
  @@ -26,33 +31,37 @@
   public class Main
   {
   
  -    public static void main( String[] inputArgs )
  +    public static void main( String[] args )
       {
  +        if ( args.length < 1 )
  +        {
  +            printUsage();
  +            System.exit( 0 );
  +        }
  +        else if ( "-h".equals( args[0].toLowerCase() ) )
  +        {
  +            printHelp();
  +            System.exit( 0 );
  +        }
  +        else if( "-template".equals( args[0] ) )
  +        {
  +            printTemplate();
  +            System.exit( 0 );
  +        }
  +
           Embedder embedder = new Embedder();
           try
           {
               embedder.start( new ClassWorld() );
   
  -            String[] args = inputArgs;
  -
  -            if ( args.length < 2 )
  -            {
  -                printUsage();
  -                System.exit( 0 );
  -            }
  -
  -            boolean reportOnly = false;
  -            if ( args.length > 2 )
  -            {
  -                reportOnly = Boolean.valueOf( args[2] ).booleanValue();
  -            }
  +            RepositoryCleanerConfiguration config = buildConfig(args[0]);
   
               RepositoryCleaner cleaner = null;
               try
               {
                   cleaner = (RepositoryCleaner) embedder.lookup( RepositoryCleaner.ROLE );
   
  -                cleaner.cleanRepository( args[0], args[1], reportOnly );
  +                cleaner.cleanRepository( config );
               }
               finally
               {
  @@ -68,11 +77,74 @@
           }
       }
   
  +    private static RepositoryCleanerConfiguration buildConfig( String configPath ) throws IOException
  +    {
  +        Properties props = new Properties();
  +        FileInputStream input = null;
  +        try
  +        {
  +            input = new FileInputStream(configPath);
  +            props.load(input);
  +        }
  +        finally
  +        {
  +            IOUtil.close(input);
  +        }
  +        
  +        RepositoryCleanerConfiguration config = new RepositoryCleanerConfiguration();
  +        config.setSourceRepositoryPath(props.getProperty("sourceRepositoryPath"));
  +        config.setSourceRepositoryLayout(props.getProperty("sourceRepositoryLayout", "legacy"));
  +        config.setSourcePomVersion(props.getProperty("sourcePomVersion", "v3"));
  +        config.setTargetRepositoryPath(props.getProperty("targetRepositoryPath"));
  +        config.setTargetRepositoryLayout(props.getProperty("targetRepositoryLayout", "default"));
  +        config.setReportsPath(props.getProperty("reportsPath"));
  +        config.setReportOnly(Boolean.valueOf(props.getProperty("reportOnly")).booleanValue());
  +        
  +        return config;
  +    }
  +
  +    private static void printHelp()
  +    {
  +        System.out.println("repoclean: Repository Cleaner/Converter.\n\n" +
  +                "Usage: repoclean -h|-template|<configuration-properties-file>\n\n" +
  +                "Where the configuration properfies file can contain the following options:\n" +
  +                "---------------------------------------------------------------------------\n" +
  +                "sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n" +
  +                "sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" +
  +                "sourcePomType=[v3|v4] #[DEFAULT: v3]\n" +
  +                "targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n" +
  +                "targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n" +
  +                "reportsPath=/path/to/reports/directory #[REQUIRED]\n" +
  +                "reportOnly=[true|false] #[REQUIRED]\n" +
  +                "\n");
  +    }
  +
  +    private static void printTemplate()
  +    {
  +        System.out.println(
  +                "# ---------------------------------------------------------------------------\n" +
  +                "# repoclean: Repository Cleaner/Converter.\n" +
  +                "# This configuration auto-generated on: " + new java.util.Date() + "\n" +
  +                "# ---------------------------------------------------------------------------\n\n" +
  +                "# [REQUIRED OPTIONS]\n" +
  +                "sourceRepositoryPath=/path/to/repository/root\n" +
  +                "targetRepositoryPath=/path/to/repository/root\n" +
  +                "reportsPath=/path/to/reports/directory\n" +
  +                "reportOnly=[true|false]\n\n" +
  +                "# [DEFAULT VALUE: legacy]\n" +
  +                "#sourceRepositoryLayout=[legacy|default]\n\n" +
  +                "# [DEFAULT VALUE: v3]\n" +
  +                "#sourcePomType=[v3|v4]\n\n" +
  +                "# [DEFAULT VALUE: default]\n" +
  +                "#targetRepositoryLayout=[legacy|default]\n" +
  +                "\n");
  +    }
  +
       private static void printUsage()
       {
  -        System.out.println( "No repository directory specified.\n\n" + "Usage:\n"
  +        System.out.println( "Required input is missing.\n\n" + "Usage:\n"
               + "--------------------------------------------------\n\n"
  -            + "repoclean <repository-path> <reports-path> [<report-only (use true|false)>]\n" );
  +            + "repoclean -h|-template|<configuration-properties-file>\n" );
       }
   
   }
  \ No newline at end of file
  
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java
  
  Index: RepositoryCleanerConfiguration.java
  ===================================================================
  package org.apache.maven.tools.repoclean;
  
  /* ====================================================================
   *   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 RepositoryCleanerConfiguration
  {
  
      private String sourceRepositoryPath;
  
      private String sourceRepositoryLayout;
  
      private String sourcePomVersion;
  
      private String targetRepositoryPath;
  
      private String targetRepositoryLayout;
  
      private String reportsPath;
  
      private boolean reportOnly;
  
      public void setSourceRepositoryPath( String sourceRepositoryPath )
      {
          this.sourceRepositoryPath = sourceRepositoryPath;
      }
  
      public String getSourceRepositoryPath()
      {
          return sourceRepositoryPath;
      }
  
      public void setSourceRepositoryLayout( String sourceRepositoryLayout )
      {
          this.sourceRepositoryLayout = sourceRepositoryLayout;
      }
  
      public String getSourceRepositoryLayout()
      {
          return sourceRepositoryLayout;
      }
  
      public void setSourcePomVersion( String sourcePomVersion )
      {
          this.sourcePomVersion = sourcePomVersion;
      }
  
      public String getSourcePomVersion()
      {
          return sourcePomVersion;
      }
  
      public void setTargetRepositoryPath( String targetRepositoryPath )
      {
          this.targetRepositoryPath = targetRepositoryPath;
      }
  
      public String getTargetRepositoryPath()
      {
          return targetRepositoryPath;
      }
  
      public void setTargetRepositoryLayout( String targetRepositoryLayout )
      {
          this.targetRepositoryLayout = targetRepositoryLayout;
      }
  
      public String getTargetRepositoryLayout()
      {
          return targetRepositoryLayout;
      }
  
      public void setReportsPath( String reportsPath )
      {
          this.reportsPath = reportsPath;
      }
  
      public String getReportsPath()
      {
          return reportsPath;
      }
  
      public void setReportOnly( boolean reportOnly )
      {
          this.reportOnly = reportOnly;
      }
  
      public boolean reportOnly()
      {
          return reportOnly;
      }
  
  }
  
  
  1.2       +12 -0     maven-components/sandbox/repoclean/pom.xml
  
  Index: pom.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/pom.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- pom.xml	17 Mar 2005 22:56:41 -0000	1.1
  +++ pom.xml	23 Mar 2005 04:53:30 -0000	1.2
  @@ -25,6 +25,18 @@
         <scope>compile</scope>
       </dependency>
       <dependency>
  +      <groupId>maven</groupId>
  +      <artifactId>maven-artifact</artifactId>
  +      <version>2.0-SNAPSHOT</version>
  +      <scope>compile</scope>
  +    </dependency>
  +    <dependency>
  +      <groupId>maven</groupId>
  +      <artifactId>maven-model</artifactId>
  +      <version>2.0-SNAPSHOT</version>
  +      <scope>compile</scope>
  +    </dependency>
  +    <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
  
  
  
  1.2       +21 -11    maven-components/sandbox/repoclean/install.sh
  
  Index: install.sh
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/install.sh,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- install.sh	17 Mar 2005 22:56:41 -0000	1.1
  +++ install.sh	23 Mar 2005 04:53:30 -0000	1.2
  @@ -1,10 +1,15 @@
   #!/bin/sh
   
  -echo ""
  -echo "*******************"
  -echo "* NOTE: Usage for this script is: 'sh ./install.sh /path/to/install/target /path/to/local/repo'"
  -echo "*******************"
  -echo ""
  +if [ $# == 0 ]; then
  +
  +    echo ""
  +    echo "*******************"
  +    echo "* Usage: 'sh ./install.sh /path/to/install/target /path/to/local/repo'"
  +    echo "*******************"
  +    echo ""
  +    
  +    exit 0
  +fi
       
   (
       # First, ensure that the repoclean library has been built.
  @@ -26,20 +31,25 @@
       echo "-----------------------------------------------------------------------"  
       echo ""
   
  -    mkdir -p $1/lib && \
  +    mkdir -p $1/lib
   
       echo "Copying application libraries..."
       echo ""
       
  -    cp target/repoclean-1.0-SNAPSHOT.jar $1/lib && \
  -    cp $2/plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar $1/lib && \
  -    cp $2/plexus/jars/plexus-utils-1.0-alpha-2-SNAPSHOT.jar $1/lib && \
  -    cp $2/classworlds/jars/classworlds-1.1-alpha-1.jar $1/lib && \
  +    cp -f target/repoclean-1.0-SNAPSHOT.jar $1/lib
  +    cp -f $2/plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar $1/lib
  +    cp -f $2/plexus/jars/plexus-utils-1.0-alpha-2-SNAPSHOT.jar $1/lib
  +    cp -f $2/classworlds/jars/classworlds-1.1-alpha-1.jar $1/lib
  +    cp -f $2/maven/jars/maven-artifact-2.0-SNAPSHOT.jar $1/lib
  +    cp -f $2/maven/jars/maven-model-2.0-SNAPSHOT.jar $1/lib
  +    cp -f $2/maven/jars/wagon-provider-api-1.0-alpha-2-SNAPSHOT.jar $1/lib
  +    cp -f $2/maven/jars/wagon-file-1.0-alpha-2-SNAPSHOT.jar $1/lib
  +    cp -f $2/maven/jars/wagon-http-lightweight-1.0-alpha-2-SNAPSHOT.jar $1/lib
   
       echo "Copying startup script, and changing its permissions to '+x'..."
       echo ""
       
  -    cp src/main/bash/repoclean.sh $1 && \
  +    cp -f src/main/bash/repoclean.sh $1
       chmod +x $1/repoclean.sh
       
       ret=$?; if [ $ret != 0 ]; then exit $ret; fi
  
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/DefaultArtifactDiscoverer.java
  
  Index: DefaultArtifactDiscoverer.java
  ===================================================================
  package org.apache.maven.tools.repoclean.discover;
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
  import org.apache.maven.model.Model;
  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
  import org.apache.maven.tools.repoclean.report.Reporter;
  import org.codehaus.plexus.util.DirectoryScanner;
  import org.codehaus.plexus.util.IOUtil;
  
  import java.io.File;
  import java.io.FileReader;
  import java.util.ArrayList;
  import java.util.List;
  
  /* ====================================================================
   *   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 DefaultArtifactDiscoverer
      implements ArtifactDiscoverer
  {
  
      private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
  
      public List discoverArtifacts( File repositoryBase, Reporter reporter ) throws Exception
      {
          List artifacts = new ArrayList();
  
          DirectoryScanner scanner = new DirectoryScanner();
          scanner.setBasedir( repositoryBase );
          scanner.setExcludes( new String[] { "**/*.pom", "**/*.md5" } );
  
          scanner.scan();
  
          String[] artifactPaths = scanner.getIncludedFiles();
  
          for ( int i = 0; i < artifactPaths.length; i++ )
          {
              String path = artifactPaths[i];
  
              Artifact artifact = buildArtifact( repositoryBase, path, reporter );
              
              if(artifact != null)
              {
                  artifacts.add( artifact );
              }
          }
  
          return artifacts;
      }
  
      private Artifact buildArtifact( File repositoryBase, String path, Reporter reporter ) throws Exception
      {
          Artifact result = null;
          
          int lastDot = path.lastIndexOf('.');
          
          if(lastDot < 0)
          {
              reporter.error( "Found potential artifact file with invalid name. Path: \'" + path + "\' doesn't seem to contain a file extension." );
          }
          else
          {
              String pomPath = path.substring(0, lastDot) + ".pom";
              
              File pomFile = new File(repositoryBase, pomPath);
              if(pomFile.exists())
              {
                  FileReader pomReader = null;
                  try
                  {
                      pomReader = new FileReader(pomFile);
                      MavenXpp3Reader modelReader = new MavenXpp3Reader();
                      
                      Model model = modelReader.read(pomReader);
                      
                      result = artifactConstructionSupport.createArtifact( model.getGroupId(), model.getArtifactId(),
                                                                           model.getVersion(), Artifact.SCOPE_RUNTIME,
                                                                           model.getPackaging() );
                  }
                  finally
                  {
                      IOUtil.close(pomReader);
                  }
              }
              else
              {
                  reporter.error( "POM not found for potential artifact at \'" + path
                      + "\'. Cannot create Artifact instance." );
              }
          }
          
          return result;
      }
  
  }
  
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/ArtifactDiscoverer.java
  
  Index: ArtifactDiscoverer.java
  ===================================================================
  package org.apache.maven.tools.repoclean.discover;
  
  import org.apache.maven.tools.repoclean.report.Reporter;
  
  import java.io.File;
  import java.util.List;
  
  /* ====================================================================
   *   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 interface ArtifactDiscoverer
  {
      public static final String ROLE = ArtifactDiscoverer.class.getName();
  
      List discoverArtifacts( File repositoryBase, Reporter reporter ) throws Exception;
      
  }
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/discover/LegacyArtifactDiscoverer.java
  
  Index: LegacyArtifactDiscoverer.java
  ===================================================================
  package org.apache.maven.tools.repoclean.discover;
  
  /*
   * ==================================================================== 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. ====================================================================
   */
  
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
  import org.apache.maven.tools.repoclean.report.Reporter;
  import org.codehaus.plexus.logging.AbstractLogEnabled;
  import org.codehaus.plexus.util.DirectoryScanner;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  /**
   * @author jdcasey
   */
  public class LegacyArtifactDiscoverer
      extends AbstractLogEnabled
      implements ArtifactDiscoverer
  {
  
      private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
  
      public List discoverArtifacts( File repositoryBase, Reporter reporter )
      {
          List artifacts = new ArrayList();
  
          DirectoryScanner scanner = new DirectoryScanner();
          scanner.setBasedir( repositoryBase );
          scanner.setExcludes( new String[] { "**/poms/*.pom", "**/*.md5" } );
  
          scanner.scan();
  
          String[] artifactPaths = scanner.getIncludedFiles();
  
          for ( int i = 0; i < artifactPaths.length; i++ )
          {
              String path = artifactPaths[i];
  
              Artifact artifact = buildArtifact( path, reporter );
              if ( artifact != null )
              {
                  artifacts.add( artifact );
              }
          }
  
          return artifacts;
      }
  
      private Artifact buildArtifact( String path, Reporter reporter )
      {
          Artifact result = null;
  
          // TODO: Need to add more test scenarios to the unit test for this
          // pattern.
          // I'm not convinced that this will catch everything.
          Pattern pathInfoPattern = Pattern.compile( "(.+)\\/(.+)s\\/([-a-zA-Z0-9]+)-([0-9]+[-.0-9a-zA-Z]+)\\..+" );
  
          Matcher matcher = pathInfoPattern.matcher( path );
          if ( !matcher.matches() )
          {
              reporter.info( "Artifact path: \'" + path
                  + "\' does not match naming convention. Cannot reliably extract artifact information from path." );
          }
          else
          {
              String groupId = matcher.group( 1 );
              String type = matcher.group( 2 );
              String artifactId = matcher.group( 3 );
              String version = matcher.group( 4 );
  
              // Commenting this, since the old repo style didn't have a concept 
              // of 'maven-plugin'...I've added an additional artifact handler
              // specifically for this, with just enough functionality to get the
              // pathing right.
              //if ( "plugin".equals( type ) )
              //{
              //    type = "maven-plugin";
              //}
  
              getLogger().debug( "Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n"
                  + "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + "version: \'" + version + "\'" );
  
              result = artifactConstructionSupport.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
                                                                   type );
          }
  
          return result;
      }
  
  }
  
  
  1.1                  maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/artifact/LegacyPluginHandler.java
  
  Index: LegacyPluginHandler.java
  ===================================================================
  package org.apache.maven.tools.repoclean.artifact;
  
  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.2       +5 -0      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- repoclean.sh	17 Mar 2005 22:56:41 -0000	1.1
  +++ repoclean.sh	23 Mar 2005 04:53:30 -0000	1.2
  @@ -4,5 +4,10 @@
   CP=$CP:./lib/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar
   CP=$CP:./lib/plexus-utils-1.0-alpha-2-SNAPSHOT.jar
   CP=$CP:./lib/classworlds-1.1-alpha-1.jar
  +CP=$CP:./lib/maven-artifact-2.0-SNAPSHOT.jar
  +CP=$CP:./lib/maven-model-2.0-SNAPSHOT.jar
  +CP=$CP:./lib/wagon-provider-api-1.0-alpha-2-SNAPSHOT.jar
  +CP=$CP:./lib/wagon-file-1.0-alpha-2-SNAPSHOT.jar
  +CP=$CP:./lib/wagon-http-lightweight-1.0-alpha-2-SNAPSHOT.jar
   
   java -classpath ${CP} org.apache.maven.tools.repoclean.Main $* | tee repoclean-log.txt
  
  
  
  1.11      +5 -0      maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml
  
  Index: components.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-artifact/src/main/resources/META-INF/plexus/components.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- components.xml	21 Mar 2005 08:18:34 -0000	1.10
  +++ components.xml	23 Mar 2005 04:53:30 -0000	1.11
  @@ -71,6 +71,11 @@
         <role>org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout</role>
         <role-hint>default</role-hint>
         <implementation>org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout</implementation>
  +			<requirements>
  +        <requirement>
  +          <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
  +        </requirement>
  +      </requirements>
       </component>
   
       <component>
  
  
  

Mime
View raw message