jtaylor     2002/11/01 08:52:25

  Modified:    src/java/org/apache/maven/project TestResource.java
                        UnitTest.java
               src/plugins-build/test plugin.jelly
  Added:       src/java/org/apache/maven/project Resource.java
  Log:
  Continuing to clean up the test resource nightmare:
  
   - Added a Resource object to replace Resources
  
   - TestResource is now just a subclass of Resource
  
   - test:test-resources expects build/testResources and/or
     build/unitTest/resources to be collections of Resource,
     and will copy the matched files to target/test-classes
  
  A this point the test resource stuff should align with Jason's proposal
  for resources (and plexus will soon build again). jar-resources will need
  to be updated similarly.
  
  Revision  Changes    Path
  1.2       +8 -76     
jakarta-turbine-maven/src/java/org/apache/maven/project/TestResource.java
  
  Index: TestResource.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/project/TestResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestResource.java 21 Sep 2002 09:52:30 -0000      1.1
  +++ TestResource.java 1 Nov 2002 16:52:25 -0000       1.2
  @@ -59,83 +59,15 @@
   import java.util.List;
   import java.util.ArrayList;
   
  -/** Patterns for including or excluding arbitrary test resources.
  +/** 
  + * Patterns for including or excluding arbitrary test resources.
    *
  - *  @author <a href="mailto:evenisse@;ifrance.com">Emmanuel Venisse</a>
  + * @author <a href="mailto:evenisse@;ifrance.com">Emmanuel Venisse</a>
  + * @author <a href="mailto:james@;jamestaylor.org">James Taylor</a>
  + *
  + * @deprecated Resource is prefered.
    */
  -public class TestResource
  +public class TestResource extends Resource
   {
  -
  -    /** resource directory */
  -    private String dir;
  -
  -    /** Include patterns. */
  -    private List includes;
  -
  -    /** Exclude patterns. */
  -    private List excludes;
  -
  -    /** Construct.
  -     */
  -    public TestResource()
  -    {
  -        this.includes = new ArrayList();
  -        this.excludes = new ArrayList();
  -    }
  -
  -    /**
  -     * Sets the directory attribute of the TestResource object
  -     *
  -     * @param dir the TestResource's directory
  -     */
  -    public void setDirectory(String dir)
  -    {
  -        this.dir = dir;
  -    }
  -
  -    /**
  -     * Gets the directory attribute of the TestResource object
  -     *
  -     * @return the TestResource's directory
  -     */
  -    public String getDirectory()
  -    {
  -        return this.dir;
  -    }
  -
  -    /** Add an include pattern.
  -     *
  -     *  @param pattern The include pattern.
  -     */
  -    public void addInclude(String pattern)
  -    {
  -        this.includes.add(pattern);
  -    }
  -
  -    /** Add an exclude pattern.
  -     *
  -     *  @param pattern The exclude pattern.
  -     */
  -    public void addExclude(String pattern)
  -    {
  -        this.excludes.add(pattern);
  -    }
  -
  -    /** Retrieve a list of include patterns.
  -     *
  -     *  @return The list of include patterns.
  -     */
  -    public List getIncludes()
  -    {
  -        return this.includes;
  -    }
  -
  -    /** Retrieve a list of exclude patterns.
  -     *
  -     *  @return The list of exclude patterns.
  -     */
  -    public List getExcludes()
  -    {
  -        return this.excludes;
  -    }
  +    // Empty, alias for parent class Resource.
   }
  
  
  
  1.4       +12 -18    
jakarta-turbine-maven/src/java/org/apache/maven/project/UnitTest.java
  
  Index: UnitTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/project/UnitTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UnitTest.java     15 Aug 2002 03:33:07 -0000      1.3
  +++ UnitTest.java     1 Nov 2002 16:52:25 -0000       1.4
  @@ -59,37 +59,31 @@
   import java.util.List;
   import java.util.ArrayList;
   
  -/** Collects unit-test include and exclude patterns.
  +/** 
  + * Collects unit-test include and exclude patterns and resources.
    *
  - *  @author <a href="mailto:bob@;eng.werken.com">bob mcwhirter</a>
  - *  @author <a href="mailto:martin@;mvdb.net">Martin van den Bemt</a>
  + * @author <a href="mailto:bob@;eng.werken.com">bob mcwhirter</a>
  + * @author <a href="mailto:martin@;mvdb.net">Martin van den Bemt</a>
  + * @author <a href="mailto:james@;jamestaylor.org">James Taylor</a>
    */
   public class UnitTest extends Resources
   {
  -    private Resources resources;
  -    private List includes;
  -    private List excludes; 
  -    
  -    public UnitTest()
  -    {
  -        this.includes = new ArrayList();
  -        this.excludes = new ArrayList();
  -    }
  -    
  +    private List resources = new ArrayList();
  +
       /**
  -     * Sets the test resources
  -     * @param resources
  +     * Add a test resource.
        */
  -    public void setResources(Resources resources)
  +    public void addResource( Resource resource )
       {
  -        this.resources = resources;
  +        this.resources.add( resource );
       }
       
       /**
        * Gets the resources
  +     *
        * @return Resources patterns for including or excluding arbitrary resources.
        */
  -    public Resources getResources()
  +    public List getResources()
       {
           return this.resources;
       }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/project/Resource.java
  
  Index: Resource.java
  ===================================================================
  package org.apache.maven.project;
  
  /* ====================================================================
   * 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 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/>.
   *
   * ====================================================================
   */
  
  import java.util.List;
  import java.util.ArrayList;
  
  /** 
   * Represents a set of files in a single directory.
   *
   * @author <a href="mailto:james@;jamestaylor.org">James Taylor</a>
   */
  public class Resource
  {
      /** Resource Directory */
      private String dir;
      
      /** Include patterns. */
      private List includes = new ArrayList();
  
      /** Exclude patterns. */
      private List excludes = new ArrayList();
  
      /** 
       * Add an include pattern.
       */
      public void addInclude(String pattern)
      {
          this.includes.add(pattern);
      }
  
      /** 
       * Add an exclude pattern.
       */
      public void addExclude(String pattern)
      {
          this.excludes.add(pattern);
      }
  
      /** 
       * Retrieve a list of include patterns.
       */
      public List getIncludes()
      {
          return this.includes;
      }
  
      /** 
       * Retrieve a list of exclude patterns.
       */
      public List getExcludes()
      {
          return this.excludes;
      }
  
      /**
       * Set the directory where resources are located.
       */
      public void setDirectory(String dir)
      {
          this.dir = dir;
      }
  
      /**
       * Get the directory where resources are located.
       */
      public String getDirectory()
      {
          return this.dir;
      }
  }
  
  
  
  1.22      +41 -32    jakarta-turbine-maven/src/plugins-build/test/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/plugins-build/test/plugin.jelly,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- plugin.jelly      30 Oct 2002 06:07:28 -0000      1.21
  +++ plugin.jelly      1 Nov 2002 16:52:25 -0000       1.22
  @@ -1,7 +1,8 @@
   <?xml version="1.0"?>
   
  -<project xmlns:j="jelly:core" xmlns:u="jelly:util">
  -
  +<project xmlns:j="jelly:core" 
  +         xmlns:u="jelly:util" 
  +         xmlns:define="jelly:define">
     
     <goal name="test" 
           description="Test the application"
  @@ -261,29 +262,45 @@
   
     <goal name="test:test-resources"
           description="Copy any resources that must be present for run tests"
  -        prereqs="test:prepare-filesystem">
  +        prereqs="test:prepare-filesystem"
  +        xmlns:resources="resources">
  +
  +    <j:if test="${unitTestSourcesPresent}">
  +
  +    <define:taglib uri="resources">
  +
  +      <!--
  +        - Copy all the file matched by each provided Resource to 
  +        - the provided destination directory.
  +        -
  +        - @param resources A collection of pom Resource objects
  +        - @param todir Target directory
  +        -->
  +      <define:tag name="copy">
  +        <copy todir="${todir}">
  +            <j:forEach var="res" items="${resources}">
  +            <fileset dir="${res.directory}">
  +              <j:forEach var="inc" items="${res.includes}">
  +                <include name="${inc}"/>
  +              </j:forEach>
  +              <j:forEach var="exc" items="${res.excludes}">
  +                <exclude name="${exc}"/>
  +              </j:forEach>
  +            </fileset>
  +          </j:forEach>
  +        </copy>
  +      </define:tag>
  +
  +    </define:taglib>
   
       <!-- 
         - build.unitTest.resources 
  -      -
  -      - Currently this assumes the resources are in the unitTestSourceDirectory
  -      - which is bad. The directory should be specified as part of the resource
  -      - block. This will be addressed when we move to a unified way to 
  -      - represent resources.
         -->
   
  -    <j:if test="${pom.build.unitTest.resources != null}">
  +    <j:if test="${!pom.build.unitTest.resources.isEmpty()}">
   
  -      <copy todir="${maven.test.dest}">
  -        <fileset dir="${pom.build.unitTestSourceDirectory}">
  -          <j:forEach var="inc" items="${pom.build.unitTest.resources.includes}">
  -            <include name="${inc}"/>
  -          </j:forEach>
  -          <j:forEach var="exc" items="${pom.build.unitTest.resources.excludes}">
  -            <exclude name="${exc}"/>
  -          </j:forEach>
  -        </fileset>
  -      </copy>
  +      <resources:copy resources="${pom.build.unitTest.resources}"
  +                      todir="${maven.test.dest}" />
   
       </j:if>
   
  @@ -292,22 +309,14 @@
         - unitTest.resources is refit to follow the unified form
         -->
   
  -    <j:if test="${pom.build.testResources != null}">
  +    <j:if test="${!pom.build.testResources.isEmpty()}">
   
  -      <j:forEach var="res" items="${pom.build.testResources}">
  +      <echo>TestResources: ${pom.build.testResources}</echo>
   
  -        <copy todir="${maven.test.dest}">
  -          <fileset dir="${res.directory}">
  -            <j:forEach var="inc" items="${res.includes}">
  -              <include name="${inc}"/>
  -            </j:forEach>
  -            <j:forEach var="exc" items="${res.excludes}">
  -              <exclude name="${exc}"/>
  -            </j:forEach>
  -          </fileset>
  -        </copy>
  +      <resources:copy resources="${pom.build.testResources}"
  +                      todir="${maven.test.dest}" />
   
  -      </j:forEach>
  +    </j:if>
   
       </j:if>
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:turbine-maven-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:turbine-maven-dev-help@;jakarta.apache.org>

Reply via email to