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/01/12 07:43:21 UTC

cvs commit: jakarta-turbine-maven/src/bootstrap/org/apache/maven BootstrapPomParser.java BootstrapTask.java Dependency.java

jvanzyl     2003/01/11 22:43:21

  Modified:    src/bootstrap/org/apache/maven BootstrapPomParser.java
                        BootstrapTask.java Dependency.java
  Log:
  o Updating the bootstrap classes to match the changes in the Dependency
    class. This is what the Dependency class will eventually look like once
    we deprecate the fugly naming scheme.
  
  Revision  Changes    Path
  1.5       +8 -0      jakarta-turbine-maven/src/bootstrap/org/apache/maven/BootstrapPomParser.java
  
  Index: BootstrapPomParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bootstrap/org/apache/maven/BootstrapPomParser.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BootstrapPomParser.java	18 Dec 2002 17:11:01 -0000	1.4
  +++ BootstrapPomParser.java	12 Jan 2003 06:43:21 -0000	1.5
  @@ -152,6 +152,14 @@
           {
               currentDependency.setType(getBodyText());
           }
  +        else if (rawName.equals("groupId") && insideDependency)
  +        {
  +            currentDependency.setGroupId(getBodyText());
  +        }
  +        else if (rawName.equals("artifactId") && insideDependency)
  +        {
  +            currentDependency.setArtifactId(getBodyText());
  +        }
           
           bodyText = new StringBuffer();
       }
  
  
  
  1.13      +1 -8      jakarta-turbine-maven/src/bootstrap/org/apache/maven/BootstrapTask.java
  
  Index: BootstrapTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bootstrap/org/apache/maven/BootstrapTask.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BootstrapTask.java	31 Dec 2002 07:28:17 -0000	1.12
  +++ BootstrapTask.java	12 Jan 2003 06:43:21 -0000	1.13
  @@ -315,14 +315,7 @@
           for (Iterator i = dependencies.iterator(); i.hasNext(); )
           {
               Dependency d = (Dependency) i.next();
  -            
  -            // Don't copy test JARs. In this case the JUnit JAR.
  -            if (d.isTestType())
  -            {
  -                continue;
  -            }                
  -            
  -            String s = d.getProjectId() + "/jars/" + d.getJar();
  +            String s = d.getArtifactDirectory() + "/jars/" + d.getArtifact();
               list.add(s);
           }
           
  
  
  
  1.3       +154 -111  jakarta-turbine-maven/src/bootstrap/org/apache/maven/Dependency.java
  
  Index: Dependency.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/bootstrap/org/apache/maven/Dependency.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Dependency.java	26 Oct 2002 05:15:02 -0000	1.2
  +++ Dependency.java	12 Jan 2003 06:43:21 -0000	1.3
  @@ -62,34 +62,27 @@
    */
   public class Dependency
   {
  -    private String name;
  +    /** Dependency Id. */
       private String id;
   
  -    /**
  -     * Version associated with this dependency
  -     */
  +    /** Version associated with this dependency */
       private String version;
   
  -    /**
  -     * The URL to the dependency's homepage.
  -     */
  +    /** The URL to the dependency's homepage. */
       private String url;
   
  -    /**
  -     * Artifact name
  -     */
  -    private String artifact;
  +    /** Explictly set JAR name */
  +    private String jar;
   
  -    /**
  -     * Project id
  -     */
  -    private String projectId;
  +    /** Artifact name */
  +    private String artifactId;
  +
  +    /** Group id */
  +    private String groupId;
  +
  +    /** The dependency type */
  +    private String type = "jar";
   
  -    /**
  -     * The dependency type
  -     */
  -    private String type;
  -    
       /**
        * Default constructor
        */
  @@ -98,96 +91,129 @@
       }
   
       /**
  -     * Debug string.
  -     */
  -    public String toString()
  -    {
  -        return "Dep[ id:" + getId() + " pid:" + getProjectId() +
  -            " ver:" + getVersion() + " ar:" + getArtifact() + " jar:" +
  -            getJar() + " ]";
  -    }
  -    
  -    /**
        * Set the id for this dependency.
        *
        * @param id for this dependency
        */
  -    public void setId(String id)
  +    public void setId( String id )
       {
           this.id = id;
  -        
  -        int i = id.indexOf("+");
  -        
  -        if (i > 0)
  -        {
  -            // We have something like 'ant+optional' where the
  -            // project id is 'ant' and the artifact name is
  -            // 'ant-optional'.
  -            setProjectId(getId().substring(0,i));
  -        }
  -        else
  -        {
  -            // We have something like 'ant' where the
  -            // the project id is 'ant' and the artifact name
  -            // is 'ant'.
  -            setProjectId(getId());
  -        }
       }
  -    
  +
  +    /**
  +     *
  +     * @return
  +     */
       public String getId()
       {
  +        if (    isValid( getGroupId() )
  +             && isValid( getArtifactId() ) )
  +        {
  +            // We have something like:
  +            //
  +            // <dependency>
  +            //   <groupId>commons-jelly</groupId>
  +            //   <artifactId>commons-jelly-tags-velocity</artifactId>
  +            //   <version>SNAPSHOT</version>
  +            //  </dependency>
  +
  +            return getGroupId() + ":" + getArtifactId();
  +        }
  +
           return id;
       }
  -    
  -    public void setName(String name)
  +
  +    /**
  +     * Set the group id.
  +     *
  +     * @param groupId Group id for the dependency.
  +     */
  +    public void setGroupId( String groupId )
       {
  -        this.name = name;
  +        this.groupId = groupId;
       }
  -    
  -    public String getName()
  -    {
  -        return name;
  -    }        
  -    
  -    public void setProjectId(String projectId)
  +
  +    /**
  +     * Get the group id.
  +     *
  +     * @return The group id for the dependency.
  +     */
  +    public String getGroupId()
       {
  -        this.projectId = projectId;
  -    }        
  -    
  -    public String getProjectId()
  +        return groupId;
  +    }
  +
  +    /**
  +     * Get the directory to place the artifact in. If the groupId has been
  +     * set then use that, otherwise use the id.
  +     *
  +     * @return The artifact directory.
  +     */
  +    public String getArtifactDirectory()
       {
  -        return projectId;
  -    }        
  +        if ( isValid( getGroupId() ) )
  +        {
  +            return getGroupId();
  +        }
  +
  +        return getId();
  +    }
   
  -    public void setArtifact(String artifact)
  +    /**
  +     * Get the artifact id.
  +     *
  +     * @return The artifact id.
  +     */
  +    public String getArtifactId()
       {
  -        this.artifact = artifact;
  -    }        
  +        return artifactId;
  +    }
   
  -    public String getRealId()
  +    /**
  +     * Set the artifact name.
  +     *
  +     * @param artifactId The artifact name of the dependency.
  +     */
  +    public void setArtifactId( String artifactId )
       {
  -        return getId().replace('+','-');
  +        this.artifactId = artifactId;
       }
   
  +    /**
  +     * Gets the artifact name of the dependency. This is always calculated so
  +     * that the version can be changed dynamically using the maven override
  +     * facility.
  +     *
  +     * @return The artifact name.
  +     */
       public String getArtifact()
       {
  -        if (artifact == null)
  +        // If the jar name has been explicty set then use that. This
  +        // is when the <jar/> element is explicity used in the POM.
  +        if ( jar != null)
           {
  -            return getId().replace('+','-') + "-" + getVersion() + ".jar";
  +            return jar;
           }
  +        
  +        if ( isValid( getArtifactId() ) )
  +        {
  +            return getArtifactId() + "-" + getVersion() + "." + getType();
  +        }
  +        else
  +        {
  +            return getId() + "-" + getVersion() + "." + getType();
  +        }
  +    }
   
  -        return artifact;
  -    }        
  -    
       /**
        * Set the version for this dependency.
        *
        * @param version Version for this dependency
        */
  -    public void setVersion(String version)
  +    public void setVersion( String version )
       {
           this.version = version;
  -    }        
  +    }
   
       /**
        * Get the version of this dependency.
  @@ -200,34 +226,41 @@
       }
   
       /**
  -     * Set the name of the JAR if it cannot be synthesized
  -     * from the id and version.
  +     * Set the name of the JAR if it cannot be synthesized from the id and
  +     * version.
        *
        * @param jar Name of the jar
        */
  -    public void setJar(String jar)
  +    public void setJar( String jar )
       {
  -        setArtifact(jar);
  +        // 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 ( jar.trim().length() == 0 )
  +        {
  +            return;
  +        }
  +
  +        this.jar = jar;
       }
   
       /**
  -     * Get the name of the JAR. We will attempt to
  -     * synthesize the name of the JAR from the id and
  -     * version.
  +     * Get the name of the JAR. We will attempt to synthesize the name of the
  +     * JAR from the id and version.
        *
        * @return Name of the jar
        */
       public String getJar()
       {
  -        return getArtifact();
  -    }        
  -    
  +        return jar;
  +    }
  +
       /**
        * Set the name of url for the dependency.
        *
        * @param url the dependency's home page
        */
  -    public void setUrl(String url)
  +    public void setUrl( String url )
       {
           this.url = url;
       }
  @@ -241,46 +274,56 @@
       {
           return url;
       }
  -    
  -    
  +
  +
       /**
  +     * Set the type of the dependency.
  +     *
        * @return dependency type such as "compile" or "test"
        */
  -    public String getType() 
  +    public String getType()
       {
           return type;
       }
  -    
  +
       /**
        * Sets the dependency type such as "compile" or "test"
  +     *
  +     * @param type The type of dependency.
        */
  -    public void setType(String type) 
  +    public void setType( String type )
       {
           this.type = type;
       }
  -    
  +
       /**
  -     * A Helper method which returns true if this dependency is
  -     * for compiling Java source code, which is the default dependency type.
  +     * Debug string.
  +     *
  +     * @return Debugging string.
        */
  -    public boolean isCompileType() 
  +    public String toString()
       {
  -        // lets preserve backwards compatibility where
  -        // 'required' == 'compile'
  -        return type == null || type.length() == 0 
  -            || type.equals( "compile" ) || type.equals( "required" );
  +        return "Dep[ id:" + getId() + " pid:" + getId()
  +            + " ver:" + getVersion() + " ar:" + getArtifact() + " jar:"
  +            + getJar() + " ]";
       }
  -    
  +
       /**
  -     * A Helper method which returns true if this dependency is
  -     * for unit testing. This allows us to seperate out the dependencies required to compile
  -     * a project versus the dependencies required to run the unit tests, 
  -     * which can help avoid circular dependencies.
  +     * Simple check for a value in the POM. Due to the Jelly swizzling
  +     * fields that aren't set come out as empty strings. This will not
  +     * be required when the new lazy evaluation mechanism is put in place.
  +     *
  +     * @param value POM value to test.
  +     * @return Is the value valid.
        */
  -    public boolean isTestType() 
  +    protected boolean isValid( String value )
       {
  -        // lets preserve backwards compatibility where
  -        // 'required' == 'compile'
  -        return type != null && type.equals( "test" );
  +        if (    value != null
  +             && value.trim().equals("") == false )
  +        {
  +            return true;
  +        }
  +
  +        return false;
       }
   }