You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2003/05/23 04:18:44 UTC

cvs commit: maven-new/core/src/java/org/apache/maven/artifact/verify ArtifactVerifier.java

jvanzyl     2003/05/22 19:18:44

  Modified:    core/src/java/org/apache/maven/artifact/verify
                        ArtifactVerifier.java
  Added:       core/src/java/org/apache/maven/artifact/collector
                        ArtifactCollector.java
                        DefaultArtifactCollector.java
  Log:
  o Adding artifact collector stuff.
  
  Revision  Changes    Path
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/collector/ArtifactCollector.java
  
  Index: ArtifactCollector.java
  ===================================================================
  package org.apache.maven.artifact.collector;
  
  import java.util.Map;
  
  /**
   *
   *
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   *
   * @version $Id: ArtifactCollector.java,v 1.1 2003/05/23 02:18:44 jvanzyl Exp $
   */
  public interface ArtifactCollector
  {
      /** Role. */
      static String ROLE = ArtifactCollector.class.getName();
  
      /**
       *
       * @param mavenRepoLocal
       */
      void setMavenRepoLocal( String mavenRepoLocal );
  
      /**
       *
       * @param pom
       */
      void setPom( String pom );
  
      /**
       *
       * @return
       * @throws Exception
       */
      Map getArtifacts()
          throws Exception;
  }
  
  
  
  1.1                  maven-new/core/src/java/org/apache/maven/artifact/collector/DefaultArtifactCollector.java
  
  Index: DefaultArtifactCollector.java
  ===================================================================
  package org.apache.maven.artifact.collector;
  
  import org.apache.maven.project.Project;
  import org.apache.maven.project.builder.DefaultProjectBuilder;
  import org.apache.maven.project.builder.ProjectBuilder;
  import org.apache.maven.artifact.Artifact;
  import org.apache.plexus.logging.AbstractLogEnabled;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  
  import java.io.File;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  // cycles
  // different artifact types
  //
  
  /**
   *  Start with a given POM and resolve all artifacts.
   * 
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   *
   * @version $Id: DefaultArtifactCollector.java,v 1.1 2003/05/23 02:18:44 jvanzyl Exp $
   */
  public class DefaultArtifactCollector
      extends AbstractLogEnabled
      implements Serviceable, ArtifactCollector
  {
      /** Maven repo local. */
      private String mavenRepoLocal;
      /** Initial POM */
      private String pom;
      /** Collected artifacts. */
      private Map artifacts;
      /** Dependency builder. */
      private ProjectBuilder builder;
      /** Non existent POMs. */
      private Map artifactsWithoutPoms;
  
      // ----------------------------------------------------------------------
      // Constructor
      // ----------------------------------------------------------------------
  
      public DefaultArtifactCollector()
      {
      }
  
      // ----------------------------------------------------------------------
      // Accessors
      // ----------------------------------------------------------------------
  
      public String getMavenRepoLocal()
      {
          return mavenRepoLocal;
      }
  
      public void setMavenRepoLocal( String mavenRepoLocal )
      {
          this.mavenRepoLocal = mavenRepoLocal;
      }
  
      public String getPom()
      {
          return pom;
      }
  
      public void setPom( String pom )
      {
          this.pom = pom;
      }
  
      public Map getArtifacts()
          throws Exception
      {
          if ( artifacts == null )
          {
              artifacts = new HashMap();
              artifactsWithoutPoms = new HashMap();
              collectDependencies();
          }
  
          return artifacts;
      }
  
      // ----------------------------------------------------------------------
      // Implementation
      // ----------------------------------------------------------------------
  
      void collectDependencies()
          throws Exception
      {
          Project pom = builder.build( new File ( getPom()) );
          resolveDependencies( pom );
      }
  
      void resolveDependencies( Project pom )
          throws Exception
      {
          for ( Iterator i = pom.getArtifacts().iterator(); i.hasNext(); )
          {
              Artifact artifact = (Artifact) i.next();
  
              // Add the dependency itself
              artifacts.put( artifact.getId(), artifact );
  
              // Now find the artifacts for each of the artifacts.
              Project p = findPom( artifact );
  
              if ( p == null )
              {
                  artifactsWithoutPoms.put( artifact.getId(), artifact );
                  continue;
              }
  
              resolveDependencies( findPom( artifact ) );
          }
      }
  
      Project findPom( Artifact artifact )
          throws Exception
      {
          String pomFileBasename = artifact.getArtifactId() + "-" + artifact.getVersion() + ".pom";
          File pomFile = new File( new File ( new File( mavenRepoLocal, artifact.getGroupId() ), "poms" ), pomFileBasename );
  
          Project pom = null;
  
          if ( pomFile.exists() )
          {
              pom = builder.build( pomFile );
          }
  
          return pom;
      }
  
      // ----------------------------------------------------------------------
      // Lifecylce Management
      // ----------------------------------------------------------------------
  
      /** @see Serviceable#service */
      public void service( ServiceManager serviceManager )
          throws ServiceException
      {
          builder = (ProjectBuilder) serviceManager.lookup( ProjectBuilder.ROLE );
      }
  }
  
  
  
  1.2       +2 -2      maven-new/core/src/java/org/apache/maven/artifact/verify/ArtifactVerifier.java
  
  Index: ArtifactVerifier.java
  ===================================================================
  RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/artifact/verify/ArtifactVerifier.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArtifactVerifier.java	21 May 2003 08:05:25 -0000	1.1
  +++ ArtifactVerifier.java	23 May 2003 02:18:44 -0000	1.2
  @@ -75,7 +75,7 @@
       /**
        *
        * @param artifact the <code>Artifact</code> which will be verified
  -     * @throws ChecksumVerificationException
  +     * @throws org.apache.maven.verifier.ChecksumVerificationException
        */
       void verify( Project project ) throws ChecksumVerificationException;
   }
  
  
  

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