ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant ProjectTest.java AllJUnitTests.java
Date Mon, 04 Sep 2000 12:20:13 GMT
bodewig     00/09/04 05:20:13

  Modified:    .        build.xml
               src/main/org/apache/tools/ant Project.java
               src/testcases/org/apache/tools/ant AllJUnitTests.java
  Added:       src/main/org/apache/tools/ant/types defaults.properties
               src/testcases/org/apache/tools/ant ProjectTest.java
  Log:
  Added infrastructure to create data types independent of tasks.
  
  Revision  Changes    Path
  1.64      +1 -0      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- build.xml	2000/08/30 14:57:43	1.63
  +++ build.xml	2000/09/04 12:20:09	1.64
  @@ -285,6 +285,7 @@
         <exclude name="**/PathTest.java" unless="junit.present" />
         <exclude name="**/CommandlineTest.java" unless="junit.present" />
         <exclude name="**/CommandlineJavaTest.java" unless="junit.present" />
  +      <exclude name="**/ProjectTest.java" unless="junit.present" />
       </javac>
      </target>
   
  
  
  
  1.35      +83 -7     jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- Project.java	2000/08/10 08:42:29	1.34
  +++ Project.java	2000/09/04 12:20:10	1.35
  @@ -98,6 +98,7 @@
       private Hashtable userProperties = new Hashtable();
       private Hashtable references = new Hashtable();
       private String defaultTarget;
  +    private Hashtable dataClassDefinitions = new Hashtable();
       private Hashtable taskClassDefinitions = new Hashtable();
       private Hashtable targets = new Hashtable();
       private Hashtable filters = new Hashtable();
  @@ -160,17 +161,42 @@
                       // ignore...
                   }
               }
  +        } catch (IOException ioe) {
  +            throw new BuildException("Can't load default task list");
  +        }
  +
  +        String dataDefs = "/org/apache/tools/ant/types/defaults.properties";
  +
  +        try{
  +            Properties props = new Properties();
  +            InputStream in = this.getClass().getResourceAsStream(dataDefs);
  +            props.load(in);
  +            in.close();
   
  -            Properties systemP = System.getProperties();
  -            Enumeration e = systemP.keys();
  -            while (e.hasMoreElements()) {
  -                String name = (String) e.nextElement();
  -                String value = (String) systemP.get(name);
  -                this.setProperty(name, value);
  +            Enumeration enum = props.propertyNames();
  +            while (enum.hasMoreElements()) {
  +                String key = (String) enum.nextElement();
  +                String value = props.getProperty(key);
  +                try {
  +                    Class dataClass = Class.forName(value);
  +                    addDataTypeDefinition(key, dataClass);
  +                } catch (NoClassDefFoundError ncdfe) {
  +                    // ignore...
  +                } catch (ClassNotFoundException cnfe) {
  +                    // ignore...
  +                }
               }
           } catch (IOException ioe) {
  -            throw new BuildException("Can't load default task list");
  +            throw new BuildException("Can't load default datatype list");
           }
  +
  +        Properties systemP = System.getProperties();
  +        Enumeration e = systemP.keys();
  +        while (e.hasMoreElements()) {
  +            String name = (String) e.nextElement();
  +            String value = (String) systemP.get(name);
  +            this.setProperty(name, value);
  +        }
       }
   
       public void addBuildListener(BuildListener listener) {
  @@ -326,6 +352,16 @@
           return taskClassDefinitions;
       }
   
  +    public void addDataTypeDefinition(String typeName, Class typeClass) {
  +        String msg = " +User datatype: " + typeName + "     " + typeClass.getName();
  +        log(msg, MSG_VERBOSE);
  +        dataClassDefinitions.put(typeName, typeClass);
  +    }
  +
  +    public Hashtable getDataTypeDefinitions() {
  +        return dataClassDefinitions;
  +    }
  +
       /**
        * This call expects to add a <em>new</em> Target.
        * @param target is the Target to be added to the current
  @@ -415,6 +451,46 @@
               String msg = "Could not create task of type: "
                    + taskType + " due to " + e;
               throw new BuildException(msg);
  +        }
  +    }
  +
  +    public Object createDataType(String typeName) throws BuildException {
  +        Class c = (Class) dataClassDefinitions.get(typeName);
  +
  +	if (c == null)
  +            return null;
  +
  +        try {
  +            java.lang.reflect.Constructor ctor = null;
  +            boolean noArg = false;
  +            // DataType can have a "no arg" constructor or take a single 
  +            // Project argument.
  +            try {
  +                ctor = c.getConstructor(new Class[0]);
  +                noArg = true;
  +            } catch (NoSuchMethodException nse) {
  +                ctor = c.getConstructor(new Class[] {getClass()});
  +                noArg = false;
  +            }
  +
  +            Object o = null;
  +            if (noArg) {
  +                 o = ctor.newInstance(new Object[0]);
  +            } else {
  +                 o = ctor.newInstance(new Object[] {this});
  +            }
  +            String msg = "   +DataType: " + typeName;
  +            log (msg, MSG_VERBOSE);
  +            return o;
  +        } catch (java.lang.reflect.InvocationTargetException ite) {
  +            Throwable t = ite.getTargetException();
  +            String msg = "Could not create datatype of type: "
  +                 + typeName + " due to " + t;
  +            throw new BuildException(msg, t);
  +        } catch (Throwable t) {
  +            String msg = "Could not create datatype of type: "
  +                 + typeName + " due to " + t;
  +            throw new BuildException(msg, t);
           }
       }
   
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/types/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  path=org.apache.tools.ant.types.Path
  fileset=org.apache.tools.ant.types.FileSet
  patternset=org.apache.tools.ant.types.PatternSet
  
  
  
  1.5       +1 -0      jakarta-ant/src/testcases/org/apache/tools/ant/AllJUnitTests.java
  
  Index: AllJUnitTests.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/AllJUnitTests.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AllJUnitTests.java	2000/07/25 08:44:09	1.4
  +++ AllJUnitTests.java	2000/09/04 12:20:12	1.5
  @@ -71,6 +71,7 @@
   
       public static Test suite() {
           TestSuite suite = new TestSuite(IntrospectionHelperTest.class);
  +	suite.addTest(new TestSuite(org.apache.tools.ant.ProjectTest.class));
   	suite.addTest(org.apache.tools.ant.types.AllJUnitTests.suite());
           return suite;
      }
  
  
  
  1.1                  jakarta-ant/src/testcases/org/apache/tools/ant/ProjectTest.java
  
  Index: ProjectTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" 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"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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/>.
   */
  
  package org.apache.tools.ant;
  
  import org.apache.tools.ant.types.*;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * Very limited test class for Project. Waiting to be extended.
   *
   * @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a>

   */
  public class ProjectTest extends TestCase {
  
      private Project p;
  
      public ProjectTest(String name) {
          super(name);
      }
  
      public void setUp() {
          p = new Project();
          p.init();
      }
  
      public void testDataTypes() throws BuildException {
          assertNull("dummy is not a known data type", 
                     p.createDataType("dummy"));
          Object o = p.createDataType("fileset");
          assertNotNull("fileset is a known type", o);
          assert("fileset creates FileSet", o instanceof FileSet);
          assert("PatternSet", 
                 p.createDataType("patternset") instanceof PatternSet);
          assert("Path", p.createDataType("path") instanceof Path);
      }
  }
  
  
  

Mime
View raw message