ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types DataType.java
Date Sat, 04 Aug 2001 14:30:36 GMT
conor       01/08/04 07:30:36

  Modified:    src/main/org/apache/tools/ant IntrospectionHelper.java
                        Task.java
               src/main/org/apache/tools/ant/types DataType.java
  Added:       src/main/org/apache/tools/ant ProjectComponent.java
  Log:
  Give data types some of the capabailities of Tasks, namely access
  to the project object and the ability to log messages through that
  project. The IntrospectionHelper cooperates to ensure DataTypes
  created as nested elements are correctly setup
  
  Revision  Changes    Path
  1.20      +10 -2     jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- IntrospectionHelper.java	2001/08/01 11:41:15	1.19
  +++ IntrospectionHelper.java	2001/08/04 14:30:36	1.20
  @@ -322,7 +322,11 @@
               throw new BuildException(msg);
           }
           try {
  -            return nc.create(element);
  +            Object nestedElement = nc.create(element);
  +            if (nestedElement instanceof ProjectComponent) {
  +                ((ProjectComponent)nestedElement).setProject(project);
  +            }
  +            return nestedElement;
           } catch (IllegalAccessException ie) {
               // impossible as getMethods should only return public methods
               throw new BuildException(ie);
  @@ -565,7 +569,11 @@
                                           String value) 
                               throws InvocationTargetException, IllegalAccessException, BuildException
{
                               try {
  -                                m.invoke(parent, new Object[] {c.newInstance(new String[]
{value})});
  +                                Object attribute = c.newInstance(new String[] {value});
  +                                if (attribute instanceof ProjectComponent) {
  +                                    ((ProjectComponent)attribute).setProject(p);
  +                                }
  +                                m.invoke(parent, new Object[] {attribute});
                               } catch (InstantiationException ie) {
                                   throw new BuildException(ie);
                               }
  
  
  
  1.21      +1 -43     jakarta-ant/src/main/org/apache/tools/ant/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Task.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Task.java	2001/08/01 11:41:15	1.20
  +++ Task.java	2001/08/04 14:30:36	1.21
  @@ -60,9 +60,8 @@
    * <p>Use {@link Project#createTask Project.createTask} to create a new Task.
    */
   
  -public abstract class Task {
  +public abstract class Task extends ProjectComponent {
   
  -    protected Project project = null;
       protected Target target = null;
       protected String description=null;
       protected Location location = Location.UNKNOWN_LOCATION;
  @@ -71,27 +70,6 @@
       protected RuntimeConfigurable wrapper;
   
       /**
  -     * Sets the project object of this task. This method is used by
  -     * project when a task is added to it so that the task has
  -     * access to the functions of the project. It should not be used
  -     * for any other purpose.
  -     *
  -     * @param project Project in whose scope this task belongs.
  -     */
  -    public void setProject(Project project) {
  -        this.project = project;
  -    }
  -
  -    /**
  -     * Get the Project to which this task belongs
  -     *
  -     * @return the task's project.
  -     */
  -    public Project getProject() {
  -        return project;
  -    }
  -    
  -    /**
        * Sets the target object of this task.
        *
        * @param target Target in whose scope this task belongs.
  @@ -135,26 +113,6 @@
       void setTaskType(String type) {
           this.taskType = type;
       }
  -
  -    /**
  -     * Log a message with the default (INFO) priority.
  -     *
  -     * @param the message to be logged.
  -     */
  -    public void log(String msg) {
  -        log(msg, Project.MSG_INFO);
  -    }
  -
  -    /**
  -     * Log a mesage with the give priority.
  -     *
  -     * @param the message to be logged.
  -     * @param msgLevel the message priority at which this message is to be logged.
  -     */
  -    public void log(String msg, int msgLevel) {
  -        project.log(this, msg, msgLevel);
  -    }
  -
   
       /** Sets a description of the current action. It will be usefull in commenting
        *  what we are doing.
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/ProjectComponent.java
  
  Index: ProjectComponent.java
  ===================================================================
  /*
   * 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 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", "Ant", 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;
  
  /**
   * Base class for components of a project, including tasks and data types. Provides
   * common facilities.
   *
   * @author <a href="mailto:conor@apache.org">Conor MacNeill</a>
   */
  
  public abstract class ProjectComponent {
  
      protected Project project = null;
  
      /**
       * Sets the project object of this component. This method is used by
       * project when a component is added to it so that the component has
       * access to the functions of the project. It should not be used
       * for any other purpose.
       *
       * @param project Project in whose scope this component belongs.
       */
      public void setProject(Project project) {
          this.project = project;
      }
  
      /**
       * Get the Project to which this component belongs
       *
       * @return the components's project.
       */
      public Project getProject() {
          return project;
      }
      
      /**
       * Log a message with the default (INFO) priority.
       *
       * @param the message to be logged.
       */
      public void log(String msg) {
          log(msg, Project.MSG_INFO);
      }
  
      /**
       * Log a mesage with the give priority.
       *
       * @param the message to be logged.
       * @param msgLevel the message priority at which this message is to be logged.
       */
      public void log(String msg, int msgLevel) {
          if (project != null) {
              project.log(msg, msgLevel);
          }
      }
  }
  
  
  
  
  1.5       +22 -1     jakarta-ant/src/main/org/apache/tools/ant/types/DataType.java
  
  Index: DataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/DataType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DataType.java	2001/01/03 14:18:46	1.4
  +++ DataType.java	2001/08/04 14:30:36	1.5
  @@ -58,6 +58,7 @@
   import java.util.Stack;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.ProjectComponent;
   
   /**
    * Base class for those classes that can appear inside the build file
  @@ -71,7 +72,7 @@
    *
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
    */
  -public abstract class DataType {
  +public abstract class DataType extends ProjectComponent {
       /**
        * The descriptin the user has set.
        */
  @@ -159,6 +160,26 @@
               }
           }
           checked = true;
  +    }
  +
  +    /**
  +     * Performs the check for circular references and returns the
  +     * referenced object.  
  +     */
  +    protected Object getCheckedRef(Class requiredClass, String dataTypeName) {
  +        if (!checked) {
  +            Stack stk = new Stack();
  +            stk.push(this);
  +            dieOnCircularReference(stk, getProject());
  +        }
  +        
  +        Object o = ref.getReferencedObject(getProject());
  +        if (!(requiredClass.isAssignableFrom(o.getClass()))) {
  +            String msg = ref.getRefId()+" doesn\'t denote a " + dataTypeName;
  +            throw new BuildException(msg);
  +        } else {
  +            return o;
  +        }
       }
   
       /**
  
  
  

Mime
View raw message