brett       2004/01/02 15:16:18

  Modified:    maven-model project.xml
               maven-model/src/java/org/apache/maven/model Dependency.java
               maven-model/src/test/org/apache/maven/model
                        DependencyTest.java
  Added:       maven-model/src/java/org/apache/maven/model/types
                        ArtifactType.java
  Log:
  Dependency code from 1.0 for compatibility
  
  Revision  Changes    Path
  1.5       +11 -1     maven-components/maven-model/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-model/project.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- project.xml       8 Dec 2003 04:22:29 -0000       1.4
  +++ project.xml       2 Jan 2004 23:16:18 -0000       1.5
  @@ -6,7 +6,7 @@
     <groupId>maven</groupId>
     <id>maven-model</id>
     <artifactId>maven-model</artifactId>
  -  <currentVersion>2.0-alpha-2</currentVersion>
  +  <currentVersion>2.0-alpha-3-SNAPSHOT</currentVersion>
     <gumpRepositoryId>jakarta</gumpRepositoryId>
     <description>Maven is a project management and project comprehension tool. Maven 
is based on the concept of a project object model: builds, documentation creation, 
site publication, and distribution publication are all controlled from the project 
object model. Maven also provides tools to create source metrics, change logs based 
directly on source repository, and source cross-references.</description>
     <shortDescription>Java Project Management Tools</shortDescription>
  @@ -23,6 +23,16 @@
         <roles>
           <role>Java Developer</role>
         </roles>
  +    </developer>
  +    <developer>
  +      <name>Brett Porter</name>
  +      <id>brett</id>
  +      <email>[EMAIL PROTECTED]</email>
  +      <organization>f2 network</organization>
  +      <roles>
  +        <role>Java Developer</role>
  +      </roles>
  +      <timezone>+10</timezone>
       </developer>
     </developers>
     
  
  
  
  1.8       +146 -63   
maven-components/maven-model/src/java/org/apache/maven/model/Dependency.java
  
  Index: Dependency.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-model/src/java/org/apache/maven/model/Dependency.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Dependency.java   27 Dec 2003 05:04:20 -0000      1.7
  +++ Dependency.java   2 Jan 2004 23:16:18 -0000       1.8
  @@ -56,40 +56,49 @@
    * ====================================================================
    */
   
  +import org.apache.maven.model.types.ArtifactType;
  +
   import java.io.Serializable;
   import java.util.HashMap;
   import java.util.Map;
   
   /**
  + * Dependency element of the POM.
  + * 
  + * @todo validate method needs to be used after reading POM
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @author <a href="[EMAIL PROTECTED]">Michal Maczka</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
    * @version $Id$
    */
   public class Dependency
       implements Serializable
   {
  -    /** Version associated with this dependency */
  +    /** Version associated with this dependency. */
       private String version;
   
       /** The URL to the dependency's homepage. */
       private String url;
   
  -    /** Explictly set artifact name */
  +    /** Explictly set artifact name. */
       private String artifact;
   
  -    /** Artifact name */
  +    /** Artifact name. */
       private String artifactId;
   
  -    /** Group id */
  +    /** Group id. */
       private String groupId;
   
  -    /** The dependency type */
  -    private String type;
  +    /** The dependency type. */
  +    private ArtifactType type = ArtifactType.DEFAULT;
   
  -    /** EXPERIMENTAL The dependecy kind (like global, runtime, compile )*/
  -    private String kind;
  +    /** EXPERIMENTAL The dependecy kind (like global, runtime, compile). 
  +     * TODO: introduce this for POM v4 in Maven 1.1
  +     */
  +    //private String kind;
   
  -    /** Properties of this dependency */
  +    /** Properties of this dependency. */
       private Map properties;
   
       /**
  @@ -99,10 +108,10 @@
       {
       }
   
  -
       /**
        *  Get Id = <code>"groupId:artifactId:type"<code>
        * @return id of this dependecy
  +     * @todo this is not compatible with 1.0... what are the implications?
        */
       public String getId()
       {
  @@ -115,6 +124,46 @@
           return id.toString();
       }
   
  +    /**
  +     * Set the id for this dependency.
  +     *
  +     * @param id for this dependency
  +     * @deprecated this will be removed in Maven 1.1 / POM v4.
  +     * @todo remove function in POM v4
  +     */
  +    public void setId( String id )
  +    {
  +        // TODO: how to log deprecation?
  +        // LOG.warn( "DEPRECATED: The <id/> element of a dependency should be 
replaced by <groupId/> and <artifactId/>" );
  +
  +        int i = id.indexOf( "+" );
  +        int j = id.indexOf( ":" );
  +
  +        if ( i > 0 )
  +        {
  +            // We have something like 'ant+optional' where the
  +            // group id is 'ant' and the artifact id is
  +            // 'ant-optional'.
  +            setGroupId( id.substring( 0, i ) );
  +            setArtifactId( id.replace( '+', '-' ) );
  +        }
  +        else if ( j > 0 )
  +        {
  +            // We have something like 'ant:my-poorly-name.jar' where the
  +            // group id is 'ant' and the artifact id is
  +            // 'my-poorly-named.jar'.
  +            setGroupId( id.substring( 0, j ) );
  +            setArtifactId( id.substring( j + 1 ) );
  +        }
  +        else
  +        {
  +            // We have something like 'ant' where the
  +            // the project id is 'ant' and the artifact name
  +            // is 'ant'.
  +            setGroupId( id );
  +            setArtifactId( id );
  +        }
  +    }
   
       /**
        * Set the group id.
  @@ -158,20 +207,6 @@
       }
   
       /**
  -     * Get the name of the artifact if expliciltly
  -     * set by user
  -     *
  -     * This is part of artifact overrding mechanism
  -     *
  -     *
  -     * @return The artifact name.
  -     */
  -    public String getArtifact()
  -    {
  -        return artifact;
  -    }
  -
  -    /**
        * Set the version for this dependency.
        *
        * @param version Version for this dependency
  @@ -201,14 +236,6 @@
        */
       public void setArtifact( String artifact )
       {
  -
  -        // This is a check we need because of the jelly interpolation
  -        // process. If we don't check an empty string will be set and
  -        // screw up getArtifact() above.
  -        if ( artifact.trim().length() == 0 )
  -        {
  -            return;
  -        }
           this.artifact = artifact;
       }
   
  @@ -233,57 +260,64 @@
           return url;
       }
   
  -
       /**
  -     * 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>
  +     * @return dependency type such as "jar", "war", etc.
        */
       public String getType()
       {
  -        if ( type == null || type.trim().length() == 0 )
  +        String result = null;
  +
  +        if (this.type != null)
           {
  -            return "jar";
  +            result = this.type.getType();
           }
  -        return type;
  +        return result;
       }
   
       /**
  -     * Sets the dependency type such as "compile" or "test"
  -     *
  -     * @param type The type of dependency.
  +     * @return dependency extension such as "jar", "war", etc.
        */
  -    public void setType( String type )
  +    public String getExtension()
       {
  -        this.type = type;
  -    }
  +        String result = null;
   
  -    /**
  -     * 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> sor <code>war</code>
  -     */
  -    public String getKind()
  -    {
  -        if ( kind == null || kind.trim().length() == 0 )
  +        if (this.type != null)
           {
  -            return "global";
  +            result = this.type.getExtension();
           }
  -        return kind;
  +        return result;
       }
   
       /**
  -     * Sets the dependency type such as "compile" or "test"
  +     * Sets the dependency type such as "jar" or "war"
        *
  -     * @param kind The type of dependency.
  +     * @param type The type of dependency.
        */
  -    public void setKind( String kind )
  +    public void setType( String type )
       {
  -        this.kind = kind;
  +        this.type = ArtifactType.findType( type );
       }
   
  +    /**
  +     * @todo introduce for POM v4
  +     */
  +    //public String getKind()
  +    //{
  +        //if ( kind == null || kind.trim().length() == 0 )
  +        //{
  +            //return "global";
  +        //}
  +        //return kind;
  +    //}
  +
  +    /**
  +     * @todo introduce for POM v4
  +     */
  +    //public void setKind( String kind )
  +    //{
  +        //this.kind = kind;
  +    //}
  +
   
       /**
        *
  @@ -324,6 +358,23 @@
       }
   
       /**
  +     * Gets the artifact name of the dependency. 
  +     * If it has not been set explicitly, return the form
  +     * <code>artifactId-version.ext</code>, or null if
  +     * that form would not be valid
  +     *
  +     * @return The artifact name.
  +     */
  +    public String getArtifact()
  +    {
  +        if ( artifact == null && version != null && artifactId != null && type != 
null )
  +        {
  +            artifact = getArtifactId() + "-" + getVersion() + "." + getExtension();
  +        }
  +        return artifact;
  +    }
  +
  +    /**
        * Gets the "short" id of this dependecy = <code>getGroupId() + ":" + 
getArtifactId()</code>
        * Short id matches POM id of the projects which generarted this dependency.
        * @return short id of this dependecy.
  @@ -332,4 +383,36 @@
       {
           return getGroupId() + ":" + getArtifactId();
       }
  +
  +    /**
  +     * Set the artifact name using the legacy &lt;jar/&gt; tag.
  +     * @deprecated use setArtifact instead
  +     */
  +    public void setJar( String jar )
  +    {
  +        // TODO: how to log deprecation?
  +        //LOG.warn( "DEPRECATED: The <jar/> element has been deprecated, please use 
<artifact/> instead" );
  +        setArtifact( jar );
  +    }
  +
  +    /**
  +     * Validate the POM element.
  +     * @todo throw an exception with a descriptive message of what is invalid
  +     * @return whether the element is valid or not
  +     */
  +    public boolean validate()
  +    {
  +        // check id is valid
  +        if ( groupId == null || artifactId == null || type == null )
  +        {
  +            return false;
  +        }
  +        // check artifact is valid
  +        if ( artifact == null && version == null )
  +        {
  +            return false;
  +        }
  +        return true;
  +    }
   }
  +
  
  
  
  1.1                  
maven-components/maven-model/src/java/org/apache/maven/model/types/ArtifactType.java
  
  Index: ArtifactType.java
  ===================================================================
  package org.apache.maven.model.types;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", 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/>.
   *
   * ====================================================================
   */
  
  /**
   * Provides mapping between artifact types and an extension associated
   * with these types.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
   * @version $Id: ArtifactType.java,v 1.1 2004/01/02 23:16:18 brett Exp $
   */
  public class ArtifactType
  {
      /**
       * JAR artifact mapping.
       */
      public static final ArtifactType JAR = new ArtifactType("jar", "jar");
  
      /**
       * EJB artifact mapping.
       */
      public static final ArtifactType EJB = new ArtifactType("ejb", "jar");
  
      /**
       * Plugin artifact mapping.
       */
      public static final ArtifactType PLUGIN = new ArtifactType("plugin", "jar");
  
      /**
       * Reusable AspectJ aspect mapping.
       */
      public static final ArtifactType ASPECT = new ArtifactType("aspect", "jar");
  
      /**
       * Default type (JAR).
       */
      public static final ArtifactType DEFAULT = JAR;
      
      /**
       * Artifact type.
       */
      private String type;
  
      /**
       * Artifact file extension.
       */
      private String extension;
           
      /**
       * @param type the artifact type
       * @param extension the artifact extension
       */
      private ArtifactType(String type, String extension)
      {
          this.type = type;
          this.extension = extension;
      }
  
      /**
       * @return the artifact type
       */
      public String getType()
      {
          return this.type;
      }
  
      /**
       * @return the artifact extension
       */    
      public String getExtension()
      {
          return this.extension;
      }
  
      /**
       * Factory to return the correct [EMAIL PROTECTED] ArtifactType} object.
       * 
       * @param type the artifact type
       * @return the artifact mapping
       */    
      public static ArtifactType findType(String type)
      {
          ArtifactType result;
  
          if (type == null)
          {
              result = null;        
          }
          else if (type.equalsIgnoreCase("jar"))
          {
              result = JAR;
          }
          else if (type.equalsIgnoreCase("ejb"))
          {
              result = EJB;
          }
          else if (type.equalsIgnoreCase("plugin"))
          {
              result = PLUGIN;
          }
          else if (type.equalsIgnoreCase("aspect"))
          {
              result = ASPECT;
          }
          else
          {
              result = new ArtifactType(type, type);
          }
          return result;
      }
  }
  
  
  
  1.2       +21 -13    
maven-components/maven-model/src/test/org/apache/maven/model/DependencyTest.java
  
  Index: DependencyTest.java
  ===================================================================
  RCS file: 
/home/cvs/maven-components/maven-model/src/test/org/apache/maven/model/DependencyTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DependencyTest.java       4 Dec 2003 08:13:41 -0000       1.1
  +++ DependencyTest.java       2 Jan 2004 23:16:18 -0000       1.2
  @@ -19,22 +19,30 @@
           super( name );
       }
   
  -    public void testVersion()
  -        throws Exception
  +    public void testDefaults()
       {
           Dependency d = new Dependency();
   
  -        // Test default values
  -
           assertEquals( "jar", d.getType() );
  +        assertEquals( "jar", d.getExtension() );
   
  -        assertEquals( "global", d.getKind() );
  +        // TODO: for POM v4
  +        // assertEquals( "global", d.getKind() );
   
  -        d.setArtifact( "" );
  -
  -        assertNull( d.getArtifact() );
  +        assertNull( "check default artifact name", d.getArtifact() );
  +        assertNull( "check default artifact id", d.getArtifactId() );
  +        assertNull( "check default group id", d.getGroupId() );
  +        assertNull( "check default version", d.getVersion() );
  +        assertNull( "check default url", d.getUrl() );
  +        assertEquals( "check default properties", 0, d.getProperties().size() );
  +    }
   
  -        // Test set values
  +    /**
  +     * @todo needs some work
  +     */
  +    public void testVersion()
  +    {
  +        Dependency d = new Dependency();
   
           d.setVersion( "version" );
   
  @@ -60,9 +68,9 @@
   
           assertEquals( "type", d.getType() );
   
  -        d.setKind( "kind" );
  +        // d.setKind( "kind" );
   
  -        assertEquals( "kind", d.getKind() );
  +        // assertEquals( "kind", d.getKind() );
   
           d.addProperty( "foo", "bar" );
   
  @@ -82,4 +90,4 @@
   
           assertEquals( 2, d.getProperties().size() );
       }
  -}
  \ No newline at end of file
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to