You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2003/05/30 13:26:54 UTC

cvs commit: maven-new/core/src/java/org/apache/maven/artifact/handlers JarHandler.java

michal      2003/05/30 04:26:53

  Modified:    core/src/java/org/apache/maven/project Dependency.java
                        Project.java
               core/src/java/org/apache/maven MavenConstants.java
               core/src/java/org/apache/maven/artifact/handlers
                        JarHandler.java
  Added:       core/src/test/org/apache/maven/artifact/handlers
                        JarHandlerTest.xml JarHandlerTest.java
  Log:
  Added experimental code for dependecy.kind
  
  Revision  Changes    Path
  1.5       +31 -1     maven-new/core/src/java/org/apache/maven/project/Dependency.java
  
  Index: Dependency.java
  ===================================================================
  RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/project/Dependency.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Dependency.java	29 May 2003 20:26:22 -0000	1.4
  +++ Dependency.java	30 May 2003 11:26:52 -0000	1.5
  @@ -80,6 +80,9 @@
   
       /** The dependency type */
       private String type;
  +    
  +    /** EXPERIMENTAL The dependecy kind (like global, runtime, compile )*/
  +    private String kind;
   
       /** Flag to indicate the artifact is poorly named. */
       //private boolean isPoorlyNamed = false;
  @@ -287,6 +290,33 @@
           this.type = type;
       }
   
  +    /**
  +     * Get the type of the dependency. If no type was set it is
  +     * assumed that is of type <code>jar</code>
  +     *
  +     * @return dependency type such as <code>jar</code> or <code>war</code>
  +     */
  +    public String getKind()
  +    {        
  +        if ( kind  == null || kind.trim().length() == 0 )
  +        {
  +           return "global";
  +        }            
  +        return type;
  +    }
  +
  +    /**
  +     * Sets the dependency type such as "compile" or "test"
  +     *
  +     * @param type The type of dependency.
  +     */
  +    public void setKind( String kind )
  +    {
  +        this.kind = kind;
  +    }
  +    
  +    
  +    
       /**
        * Debug string.
        *
  
  
  
  1.8       +53 -6     maven-new/core/src/java/org/apache/maven/project/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/project/Project.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Project.java	24 May 2003 18:30:26 -0000	1.7
  +++ Project.java	30 May 2003 11:26:52 -0000	1.8
  @@ -56,10 +56,6 @@
    * ====================================================================
    */
   
  -import org.apache.maven.Maven;
  -import org.apache.maven.MavenConstants;
  -import org.apache.plexus.util.StringUtils;
  -
   import java.io.File;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -70,12 +66,17 @@
   import java.util.StringTokenizer;
   import java.util.TreeSet;
   
  +import org.apache.commons.lang.SystemUtils;
  +import org.apache.maven.Maven;
  +import org.apache.maven.MavenConstants;
  +import org.apache.plexus.util.StringUtils;
  +
   /**
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    * @author <a href="mailto:dion@apache.org">dIon Gillard</a>
    * @author <a href="mailto:glennm@apache.org">Glenn McAllister</a>
  - *
  + * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
    * @version $Id$
    *
    * @todo Change the file reference for the source POM to an URL.
  @@ -87,6 +88,7 @@
       private List dependencies;
   
       public static final String CONTEXT_KEY = Project.class.getName();
  +        
   
       /** Repository where this project is stored. */
       private Repository repository;
  @@ -188,6 +190,22 @@
        * be retrieved by id.
        */
       private Map dependencyMap;
  +    
  +    
  +    /**
  +     * E X P E R I M E N T A L
  +     * Classpath Map. There is one classpath for each of supported
  +     * kinds of dependencies
  +     *
  +     *  <dependency>
  +     *    ...
  +     *     <kind>runtime | compile | test | global </kind>
  +     *  <dependency>
  +     *
  +     */
  +    private Map classpathMap;
  +    
  +
   
       /** Artifact list. */
       private List artifactList;
  @@ -629,6 +647,35 @@
       {
           dependencyPaths.put( id, path );
       }
  +    
  +    
  +
  +    /**
  +     * Add entry to given named classpath
  +     *
  +     * @param id Classpath id (like global, test, runtime, compile).
  +     * @param path Classpath for the given dependency.
  +     */
  +    public void addToClassPath( String id, String path )
  +    {
  +        String classpath = getClassPath( id );               
  +        classpath = path + SystemUtils.PATH_SEPARATOR + classpath;
  +        classpathMap.put( id, classpath);
  +    }
  +    
  +    
  +    public String getClassPath( String id )
  +    {
  +        String classpath = ( String ) classpathMap.get( id );
  +        if ( classpath == null )
  +        {
  +           return "";
  +        }
  +        return classpath;
  +    }
  +    
  +    
  +    
   
       /**
        * Get an individual dependencies classpath entry.
  
  
  
  1.1                  maven-new/core/src/test/org/apache/maven/artifact/handlers/JarHandlerTest.xml
  
  Index: JarHandlerTest.xml
  ===================================================================
  <configuration>
    <components>    
      <component>
        <role>org.apache.maven.project.builder.ProjectBuilder</role>
        <implementation>org.apache.maven.project.builder.DefaultProjectBuilder</implementation>
        <configuration/>
      </component>
      <component>
        <role>org.apache.maven.project.builder.ProjectUnmarshaller</role>
        <implementation>org.apache.maven.project.builder.DefaultProjectUnmarshaller</implementation>
        <configuration/>
      </component>
      <component>
        <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
        <implementation>org.apache.maven.artifact.factory.DefaultArtifactFactory</implementation>
        <configuration/>
      </component>
      <component>
        <role>org.apache.maven.artifact.layout.RepositoryLayout</role>
        <implementation>org.apache.maven.artifact.layout.DefaultRepositoryLayout</implementation>
        <configuration/>
      </component>
    </components>
  </configuration>
  
  
  
  1.1                  maven-new/core/src/test/org/apache/maven/artifact/handlers/JarHandlerTest.java
  
  Index: JarHandlerTest.java
  ===================================================================
  package org.apache.maven.artifact.handlers;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  
  
  import java.io.File;
  
  import org.apache.maven.MavenConstants;
  import org.apache.maven.artifact.Artifact;
  import org.apache.maven.artifact.factory.ArtifactFactory;
  import org.apache.maven.project.Project;
  import org.apache.maven.project.builder.ProjectBuilder;
  import org.apache.plexus.PlexusTestCase;
  
  /**
   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 
   * @version $Id: JarHandlerTest.java,v 1.1 2003/05/30 11:26:53 michal Exp $
   */
  public class JarHandlerTest extends PlexusTestCase
  {
  
      private ProjectBuilder projectBuilder = null;
      
      private ArtifactFactory artifactFactory = null;
  
      /**
       * Constructor for DefaultArtifactHandlerManagerTest.
       * @param arg0
       */
      public JarHandlerTest(String testName)
      {
          super(testName);
      }
  
      /*
       * @see TestCase#setUp()
       */
      public void setUp() throws Exception
      {
          super.setUp();
          projectBuilder = (ProjectBuilder) lookup(ProjectBuilder.ROLE);
          ArtifactFactory artifactFactory = ( ArtifactFactory ) lookup( ArtifactFactory.ROLE );
  
      }
  
      /**
           * 
           * @param file
           * @return
           */
      private Project getProject(String file)
      {
  
          Project project = null;
          try
          {
              project = projectBuilder.build(new File( getTestFile(file) ));
          }
          catch (Exception e)
          {
              String msg = "Cannot get project sample: " + e.getMessage();
              fail(msg);
          }
          System.out.println( "project:" + project );
          
          try
          {
              artifactFactory.createArtifacts( project );
          } 
          catch (Exception e)
          {
              String msg =
                  "Cannot build artifact list for a project: " + e.getMessage();
              fail(msg);
          }
  
          return project;
  
      }
  
      public void testProcessing()
      {
  
         Project project = getProject( "src/test-input/project.xml");
         Artifact testA = (Artifact) project.getArtifacts().get(0);
         Artifact testB = (Artifact) project.getArtifacts().get(1);
         
         JarHandler jarHandler = new JarHandler();
         
         
         jarHandler.process( testA, project );
         jarHandler.process( testB, project );
         
         String classpath = project.getClassPath(MavenConstants.GLOBAL_DEPENDENCY_CLASSPATH);       
         System.out.println(  classpath );
         
         boolean hasEntryForA = classpath.indexOf( testA.getPath() ) != -1 ;
         boolean hasEntryForB = classpath.indexOf( testB.getPath() ) != -1 ;
         assertTrue("Classpath does not contain entry for:" + testA, hasEntryForA );
         assertTrue("Classpath does not contain entry for:" + testA, hasEntryForB );
         
  
      }
  
  }
  
  
  
  1.6       +15 -5     maven-new/core/src/java/org/apache/maven/MavenConstants.java
  
  Index: MavenConstants.java
  ===================================================================
  RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/MavenConstants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MavenConstants.java	29 May 2003 20:26:22 -0000	1.5
  +++ MavenConstants.java	30 May 2003 11:26:53 -0000	1.6
  @@ -180,8 +180,19 @@
       /**  Project descriptor file tag. (project.xml) */
       public static final String DESCRIPTOR_FILE = "maven.descriptorFile";
   
  -    /**  Dependency classpath tag. */
  -    public static final String DEPENDENCY_CLASSPATH = "maven.dependency.classpath";
  +    /**  Global Dependency classpath tag. */
  +    public static final String GLOBAL_DEPENDENCY_CLASSPATH = "maven.dependency.classpath";
  +    
  +    
  +    /**  Runtime Dependency classpath tag. */
  +    public static final String RUNTIME_DEPENDENCY_CLASSPATH = "maven.dependency.classpath.runtime";
  +
  +    /**  Test Dependency classpath tag. */
  +    public static final String TEST_DEPENDENCY_CLASSPATH = "maven.dependency.classpath.test";
  +    
  +    /**  Compile Dependency classpath tag. */
  +    public static final String COMPILE_DEPENDENCY_CLASSPATH = "maven.dependency.classpath.compile";
  +
   
       /**  Dependency classpath tag. */
       public static final String SESSION = "maven.session";
  @@ -189,6 +200,5 @@
       /** Layout properties file name */
       public static final String LAYOUT_PROPERTIES = "/layout.properties";
   
  -    /** Artifact Handler configuration file **/
  -    public static String ARTIFACT_HANDLER_PROPERTIES = "/artifact-handler.properties";
  +    
   }
  
  
  
  1.7       +42 -6     maven-new/core/src/java/org/apache/maven/artifact/handlers/JarHandler.java
  
  Index: JarHandler.java
  ===================================================================
  RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/artifact/handlers/JarHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JarHandler.java	29 May 2003 20:26:22 -0000	1.6
  +++ JarHandler.java	30 May 2003 11:26:53 -0000	1.7
  @@ -55,6 +55,7 @@
    */
   package org.apache.maven.artifact.handlers;
   
  +import org.apache.maven.MavenConstants;
   import org.apache.maven.artifact.Artifact;
   import org.apache.maven.project.Project;
   
  @@ -63,21 +64,56 @@
    * artifacts of type like jars, ejb, etc.
    * Artifact path is appended to build class path
    *
  - * @todo implement me!
    *
    * @author Michal Maczka
    * @version $Revision$ $Date$
    */
  -public class JarHandler
  -    implements ArtifactHandler
  +public class JarHandler implements ArtifactHandler
   {
   
       /**
        * @see org.apache.maven.artifact.handlers.ArtifactHandler#process(org.apache.maven.artifact.Artifact, org.apache.maven.project.Project)
        */
  -    public void process( Artifact artifact, Project project )
  +    public void process(Artifact artifact, Project project)
       {
  -        project.setDependencyPath( artifact.getDependency().getId(), artifact.getPath() );
  +        project.setDependencyPath(
  +            artifact.getDependency().getId(),
  +            artifact.getPath());
  +
  +        String kind = artifact.getDependency().getKind();
  +
  +        if (kind.indexOf( "global" ) != -1)
  +        {
  +            project.addToClassPath(
  +                MavenConstants.GLOBAL_DEPENDENCY_CLASSPATH,
  +                artifact.getFile().getAbsolutePath());
  +
  +        }
  +        else
  +        {
  +            if (kind.indexOf( "test" ) != -1)
  +            {
  +                project.addToClassPath(
  +                    MavenConstants.TEST_DEPENDENCY_CLASSPATH,
  +                    artifact.getFile().getAbsolutePath());
  +
  +            }
  +            if (kind.indexOf( "compile" ) != -1)
  +            {
  +                project.addToClassPath(
  +                    MavenConstants.COMPILE_DEPENDENCY_CLASSPATH,
  +                    artifact.getFile().getAbsolutePath());
  +
  +            }
  +            if (kind.indexOf( "runtime" ) != -1)
  +            {
  +                project.addToClassPath(
  +                    MavenConstants.RUNTIME_DEPENDENCY_CLASSPATH,
  +                    artifact.getFile().getAbsolutePath());
  +            }
  +
  +        }
  +
       }
   
   }
  
  
  

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