You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2005/01/07 22:57:00 UTC

cvs commit: ant/docs/manual/CoreTasks clone.html

mbenson     2005/01/07 13:57:00

  Modified:    .        WHATSNEW
               docs/manual coretasklist.html
               src/main/org/apache/tools/ant RuntimeConfigurable.java
                        UnknownElement.java
               src/main/org/apache/tools/ant/taskdefs defaults.properties
  Added:       src/main/org/apache/tools/ant/taskdefs Clone.java
               src/testcases/org/apache/tools/ant/taskdefs CloneTest.java
               src/etc/testcases/taskdefs clone.xml
               docs/manual/CoreTasks clone.html
  Log:
  Add clone task.
  PR: 32631
  
  Revision  Changes    Path
  1.705     +2 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.704
  retrieving revision 1.705
  diff -u -r1.704 -r1.705
  --- WHATSNEW	4 Jan 2005 22:20:44 -0000	1.704
  +++ WHATSNEW	7 Jan 2005 21:56:59 -0000	1.705
  @@ -112,6 +112,8 @@
   
   * Added length task to get strings' and files' lengths.
   
  +* Added clone task.
  +
   Changes from Ant 1.6.2 to current Ant 1.6 CVS version
   =====================================================
   
  
  
  
  1.56      +1 -0      ant/docs/manual/coretasklist.html
  
  Index: coretasklist.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/coretasklist.html,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- coretasklist.html	4 Jan 2005 22:20:44 -0000	1.55
  +++ coretasklist.html	7 Jan 2005 21:56:59 -0000	1.56
  @@ -27,6 +27,7 @@
   <a href="CoreTasks/pack.html">BZip2</a><br>
   <a href="CoreTasks/checksum.html">Checksum</a><br>
   <a href="CoreTasks/chmod.html">Chmod</a><br>
  +<a href="CoreTasks/clone.html">Clone</a><br>
   <a href="CoreTasks/concat.html">Concat</a><br>
   <a href="CoreTasks/condition.html">Condition</a><br>
   &nbsp;&nbsp;<a href="CoreTasks/conditions.html">Supported conditions</a><br>
  
  
  
  1.59      +64 -50    ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
  
  Index: RuntimeConfigurable.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- RuntimeConfigurable.java	16 Dec 2004 21:10:32 -0000	1.58
  +++ RuntimeConfigurable.java	7 Jan 2005 21:56:59 -0000	1.59
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2000-2004 The Apache Software Foundation
  + * Copyright  2000-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -89,11 +89,10 @@
        *
        * @param proxy The element to configure. Must not be <code>null</code>.
        * @param elementTag The tag name generating this element.
  -     *                   Should not be <code>null</code>.
        */
       public RuntimeConfigurable(Object proxy, String elementTag) {
           setProxy(proxy);
  -        this.elementTag = elementTag;
  +        setElementTag(elementTag);
           // Most likely an UnknownElement
           if (proxy instanceof Task) {
               ((Task) proxy).setRuntimeConfigurableWrapper(this);
  @@ -105,7 +104,7 @@
        *
        * @param proxy The element to configure. Must not be <code>null</code>.
        */
  -    public void setProxy(Object proxy) {
  +    public synchronized void setProxy(Object proxy) {
           wrappedObject = proxy;
           proxyConfigured = false;
       }
  @@ -116,7 +115,7 @@
        *
        * @param creator the creator object.
        */
  -    void setCreator(IntrospectionHelper.Creator creator) {
  +    synchronized void setCreator(IntrospectionHelper.Creator creator) {
           this.creator = creator;
       }
   
  @@ -126,7 +125,7 @@
        *
        * @return the object whose configure is held by this instance.
        */
  -    public Object getProxy() {
  +    public synchronized Object getProxy() {
           return wrappedObject;
       }
   
  @@ -134,7 +133,7 @@
        * Get the polymorphic type for this element.
        * @return the ant component type name, null if not set.
        */
  -    public String getPolyType() {
  +    public synchronized String getPolyType() {
           return polyType;
       }
   
  @@ -142,7 +141,7 @@
        * Set the polymorphic type for this element.
        * @param polyType the ant component type name, null if not set.
        */
  -    public void setPolyType(String polyType) {
  +    public synchronized void setPolyType(String polyType) {
           this.polyType = polyType;
       }
   
  @@ -153,7 +152,7 @@
        * @param attributes List of attributes defined in the XML for this
        *                   element. May be <code>null</code>.
        */
  -    public void setAttributes(AttributeList attributes) {
  +    public synchronized void setAttributes(AttributeList attributes) {
           this.attributes = new AttributeListImpl(attributes);
           for (int i = 0; i < attributes.getLength(); i++) {
               setAttribute(attributes.getName(i), attributes.getValue(i));
  @@ -166,7 +165,7 @@
        * @param name the name of the attribute.
        * @param value the attribute's value.
        */
  -    public void setAttribute(String name, String value) {
  +    public synchronized void setAttribute(String name, String value) {
           if (name.equalsIgnoreCase(ProjectHelper.ANT_TYPE)) {
               this.polyType = value;
           } else {
  @@ -180,12 +179,21 @@
       }
   
       /**
  +     * Delete an attribute.  Not for the faint of heart.
  +     * @param name the name of the attribute to be removed.
  +     */
  +    public synchronized void removeAttribute(String name) {
  +        attributeNames.remove(name);
  +        attributeMap.remove(name);
  +    }
  +
  +    /**
        * Return the attribute map.
        *
        * @return Attribute name to attribute value map.
        * @since Ant 1.6
        */
  -    public Hashtable getAttributeMap() {
  +    public synchronized Hashtable getAttributeMap() {
           return (attributeMap == null)
               ? EMPTY_HASHTABLE : new Hashtable(attributeMap);
       }
  @@ -197,7 +205,7 @@
        * @return An AttributeList representing the attributes defined in the
        *         XML for this element. May be <code>null</code>.
        */
  -    public AttributeList getAttributes() {
  +    public synchronized AttributeList getAttributes() {
           return attributes;
       }
   
  @@ -207,7 +215,7 @@
        * @param child The child element wrapper to add to this one.
        *              Must not be <code>null</code>.
        */
  -    public void addChild(RuntimeConfigurable child) {
  +    public synchronized void addChild(RuntimeConfigurable child) {
           children = (children == null) ? new ArrayList() : children;
           children.add(child);
       }
  @@ -220,7 +228,7 @@
        * @return The child wrapper at position <code>index</code> within the
        *         list.
        */
  -    RuntimeConfigurable getChild(int index) {
  +    synchronized RuntimeConfigurable getChild(int index) {
           return (RuntimeConfigurable) children.get(index);
       }
   
  @@ -229,7 +237,7 @@
        * @return an enumeration of the child wrappers.
        * @since Ant 1.6
        */
  -    public Enumeration getChildren() {
  +    public synchronized Enumeration getChildren() {
           return (children == null) ? new CollectionUtils.EmptyEnumeration()
               : Collections.enumeration(children);
       }
  @@ -240,7 +248,10 @@
        * @param data Text to add to the wrapped element.
        *        Should not be <code>null</code>.
        */
  -    public void addText(String data) {
  +    public synchronized void addText(String data) {
  +        if (data.length() == 0) {
  +            return;
  +        }
           characters = (characters == null)
               ? new StringBuffer(data) : characters.append(data);
       }
  @@ -254,14 +265,12 @@
        * @param count The number of characters to read from the array.
        *
        */
  -    public void addText(char[] buf, int start, int count) {
  +    public synchronized void addText(char[] buf, int start, int count) {
           if (count == 0) {
               return;
           }
  -        if (characters == null) {
  -            characters = new StringBuffer(count);
  -        }
  -        characters.append(buf, start, count);
  +        characters = ((characters == null)
  +            ? new StringBuffer(count) : characters).append(buf, start, count);
       }
   
       /**
  @@ -272,12 +281,16 @@
        * @return the text content of this element.
        * @since Ant 1.6
        */
  -    public StringBuffer getText() {
  -        if (characters != null) {
  -            return characters;
  -        } else {
  -            return new StringBuffer(0);
  -        }
  +    public synchronized StringBuffer getText() {
  +        return (characters == null) ? new StringBuffer(0) : characters;
  +    }
  +
  +    /**
  +     * Set the element tag.
  +     * @param elementTag The tag name generating this element.
  +     */
  +    public synchronized void setElementTag(String elementTag) {
  +        this.elementTag = elementTag;
       }
   
       /**
  @@ -286,7 +299,7 @@
        * @return The tag name of the wrapped element. This is unlikely
        *         to be <code>null</code>, but may be.
        */
  -    public String getElementTag() {
  +    public synchronized String getElementTag() {
           return elementTag;
       }
   
  @@ -330,7 +343,7 @@
        *            to invalid attributes or children, or text being added to
        *            an element which doesn't accept it.
        */
  -    public void maybeConfigure(Project p, boolean configureChildren)
  +    public synchronized void maybeConfigure(Project p, boolean configureChildren)
           throws BuildException {
           String id = null;
   
  @@ -384,27 +397,28 @@
           Enumeration e = getChildren();
           while (e.hasMoreElements()) {
               RuntimeConfigurable child = (RuntimeConfigurable) e.nextElement();
  -            if (child.wrappedObject instanceof Task) {
  -                Task childTask = (Task) child.wrappedObject;
  -                childTask.setRuntimeConfigurableWrapper(child);
  -            }
  -
  -            if ((child.creator != null) && configureChildren) {
  -                child.maybeConfigure(p);
  -                child.creator.store();
  -                continue;
  -            }
  -            /*
  -             * backwards compatibility - element names of nested
  -             * elements have been all lower-case in Ant, except for
  -             * tasks in TaskContainers.
  -             *
  -             * For TaskContainers, we simply skip configuration here.
  -             */
  -            String tag = child.getElementTag().toLowerCase(Locale.US);
  -            if (configureChildren && ih.supportsNestedElement(tag)) {
  -                child.maybeConfigure(p);
  -                ProjectHelper.storeChild(p, target, child.wrappedObject, tag);
  +            synchronized (child) {
  +                if (child.wrappedObject instanceof Task) {
  +                    Task childTask = (Task) child.wrappedObject;
  +                    childTask.setRuntimeConfigurableWrapper(child);
  +                }
  +                if ((child.creator != null) && configureChildren) {
  +                    child.maybeConfigure(p);
  +                    child.creator.store();
  +                    continue;
  +                }
  +                /*
  +                 * backwards compatibility - element names of nested
  +                 * elements have been all lower-case in Ant, except for
  +                 * tasks in TaskContainers.
  +                 *
  +                 * For TaskContainers, we simply skip configuration here.
  +                 */
  +                String tag = child.getElementTag().toLowerCase(Locale.US);
  +                if (configureChildren && ih.supportsNestedElement(tag)) {
  +                    child.maybeConfigure(p);
  +                    ProjectHelper.storeChild(p, target, child.wrappedObject, tag);
  +                }
               }
           }
   
  
  
  
  1.84      +6 -8      ant/src/main/org/apache/tools/ant/UnknownElement.java
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- UnknownElement.java	27 Sep 2004 09:03:17 -0000	1.83
  +++ UnknownElement.java	7 Jan 2005 21:56:59 -0000	1.84
  @@ -1,5 +1,5 @@
   /*
  - * Copyright  2000-2004 The Apache Software Foundation
  + * Copyright  2000-2005 The Apache Software Foundation
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
  @@ -401,7 +401,6 @@
           if (o == null) {
               throw getNotFoundException("task or type", name);
           }
  -
           if (o instanceof PreSetDef.PreSetDefinition) {
               PreSetDef.PreSetDefinition def = (PreSetDef.PreSetDefinition) o;
               o = def.createObject(ue.getProject());
  @@ -412,7 +411,9 @@
                   task.setTaskName(ue.getTaskName());
               }
           }
  -
  +        if (o instanceof UnknownElement) {
  +            o = ((UnknownElement) o).makeObject((UnknownElement) o, w);
  +        }
           if (o instanceof Task) {
               Task task = (Task) o;
               task.setOwningTarget(getOwningTarget());
  @@ -639,10 +640,7 @@
           return true;
       }
   
  -    private boolean equalsString(String a, String b) {
  -        if (a == null) {
  -            return b == null;
  -        }
  -        return a.equals(b);
  +    private static boolean equalsString(String a, String b) {
  +        return (a == null) ? (a == b) : a.equals(b);
       }
   }
  
  
  
  1.164     +1 -0      ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.163
  retrieving revision 1.164
  diff -u -r1.163 -r1.164
  --- defaults.properties	4 Jan 2005 22:20:44 -0000	1.163
  +++ defaults.properties	7 Jan 2005 21:56:59 -0000	1.164
  @@ -82,6 +82,7 @@
   nice=org.apache.tools.ant.taskdefs.Nice
   libraries=org.apache.tools.ant.taskdefs.repository.Libraries
   length=org.apache.tools.ant.taskdefs.Length
  +clone=org.apache.tools.ant.taskdefs.Clone
   
   # optional tasks
   image=org.apache.tools.ant.taskdefs.optional.image.Image
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/Clone.java
  
  Index: Clone.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import java.lang.reflect.Method;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.UnknownElement;
  import org.apache.tools.ant.RuntimeConfigurable;
  
  /**
   * Clone an Object from a reference.
   * @since Ant 1.7
   */
  public class Clone extends UnknownElement {
      /** Task name. */
      public static final String TASK_NAME = "clone";
  
      /** Clone reference attribute ID. */
      public static final String CLONE_REF = "cloneref";
  
      private static final Class[] NO_ARGS = new Class[] {};
  
      /**
       * Create a new instance of the Clone task.
       */
      public Clone() {
          super(TASK_NAME);
      }
  
      /**
       * Creates a named task or data type. If the real object is a task,
       * it is configured up to the init() stage.
       *
       * @param ue The UnknownElement to create the real object for.
       *           Not used in this implementation.
       * @param w  The RuntimeConfigurable containing the configuration
       *           information to pass to the cloned Object.
       *
       * @return the task or data type represented by the given unknown element.
       */
      protected Object makeObject(UnknownElement ue, RuntimeConfigurable w) {
          String cloneref = (String) (w.getAttributeMap().get(CLONE_REF));
          if (cloneref == null) {
              throw new BuildException("cloneref attribute not set");
          }
          Object ob = getProject().getReference(cloneref);
          if (ob == null) {
              throw new BuildException(
                  "reference \"" + cloneref + "\" not found");
          }
          try {
              log("Attempting to clone " + ob.toString() + " \""
                  + cloneref + "\"", Project.MSG_VERBOSE);
              Method m = ob.getClass().getMethod("clone", NO_ARGS);
              try {
                  Object bo = m.invoke(ob, NO_ARGS);
                  if (bo == null) {
                      throw new BuildException(m.toString() + " returned null");
                  }
                  w.removeAttribute(CLONE_REF);
                  w.setProxy(bo);
                  w.setElementTag(null);
                  setRuntimeConfigurableWrapper(w);
                  if (bo instanceof Task) {
                      ((Task) bo).setOwningTarget(getOwningTarget());
                      ((Task) bo).init();
                  }
                  return bo;
              } catch (Exception e) {
                  throw new BuildException(e);
              }
          } catch (NoSuchMethodException e) {
              throw new BuildException(
                  "Unable to locate public clone method for object \""
                  + cloneref + "\"");
          }
      }
  
  }
  
  
  
  1.1                  ant/src/testcases/org/apache/tools/ant/taskdefs/CloneTest.java
  
  Index: CloneTest.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.BuildFileTest;
  
  public class CloneTest extends BuildFileTest {
  
      public CloneTest(String name) {
          super(name);
      }
  
      public void setUp() {
          configureProject("src/etc/testcases/taskdefs/clone.xml");
      }
  
      public void testClone1() {
          executeTarget("testClone1");
      }
  
      public void testClone2() {
          executeTarget("testClone2");
      }
  
      public void testClone3() {
          executeTarget("testClone3");
      }
  
      public void testNoClone() {
          expectBuildExceptionContaining("testNoClone",
              "should fail because Object cannot be cloned", "public clone method");
      }
  
      public void testNoAttr() {
          expectSpecificBuildException("testNoAttr",
              "cloneref attribute not set", "cloneref attribute not set");
      }
  
      public void testNoRef() {
          expectSpecificBuildException("testNoRef", "reference does not exist",
          "reference \"thisreferencehasnotbeensetinthecurrentproject\" not found");
      }
  
  }
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/clone.xml
  
  Index: clone.xml
  ===================================================================
  <project name="clone">
  
    <target name="testClone1">
      <fileset id="doppel" file="${ant.file}" />
      <clone id="ganger" cloneref="doppel">
        <not>
          <size value="0" when="less" />
        </not>
      </clone>
      <pathconvert property="doppel" pathsep="" refid="doppel" />
      <pathconvert property="ganger" pathsep="" refid="ganger" />
      <fail>
        <condition>
          <not>
            <equals arg1="${doppel}" arg2="${ganger}" />
          </not>
        </condition>
      </fail>
    </target>
  
    <target name="testClone2">
      <fileset id="doppel" file="${ant.file}" />
      <clone id="ganger" cloneref="doppel">
        <size value="0" when="less" />
      </clone>
      <pathconvert property="ganger" pathsep="" refid="ganger" />
      <fail>
        <condition>
          <not>
            <equals arg1="" arg2="${ganger}" />
          </not>
        </condition>
      </fail>
    </target>
  
    <target name="testClone3">
      <fileset id="doppel" file="${ant.file}" />
      <basename file="${ant.file}" property="ant.base" />
      <clone id="ganger" cloneref="doppel" excludes="${ant.base}" />
      <pathconvert property="ganger" pathsep="" refid="ganger" />
      <fail>
        <condition>
          <not>
            <equals arg1="" arg2="${ganger}" />
          </not>
        </condition>
      </fail>
    </target>
  
    <target name="testNoClone">
      <typedef name="object" classname="java.lang.Object" />
      <object id="foo" />
      <clone id="bar" cloneref="foo" />
    </target>
  
    <target name="testNoAttr">
      <clone id="none" />
    </target>
  
    <target name="testNoRef">
      <clone id="none"
             cloneref="thisreferencehasnotbeensetinthecurrentproject" />
    </target>
  
  </project>
  
  
  
  1.1                  ant/docs/manual/CoreTasks/clone.html
  
  Index: clone.html
  ===================================================================
  <html>
  
  <head>
  <meta http-equiv="Content-Language" content="en-us">
  <title>Clone Task</title>
  </head>
  
  <body>
  
  <h2>Clone</h2>
  <h3>Description</h3>
  <p>Clone a project reference (presumably for augmentation).</p>
  <h3>Parameters</h3>
  <table border="1" cellpadding="2" cellspacing="0">
    <tr>
      <td valign="top"><b>Attribute</b></td>
      <td valign="top"><b>Description</b></td>
      <td align="center" valign="top"><b>Required</b></td>
    </tr>
    <tr>
      <td valign="top">cloneref</td>
      <td valign="top">What to clone, given as a
        <a href="../using.html#references">reference</a> to an
          object with a publicly accessible clone() implementation.
      </td>
      <td valign="top" align="center">Yes</td>
    </tr>
  </table>
  <p>
  Assuming the clone operation is successful, the clone invocation supports
  any attributes and nested elements supported by the cloned type
  (the obvious exception is the &quot;cloneref&quot; attribute).
  <b>Please note that modifications to cloned objects may yield
  unpredictable results depending on the internals of the cloned class.</b>
  </p>
  <h3>Examples</h3>
  <p>
  Given a fileset <i>foo</i>:
  <pre>  &lt;clone id="foo.txt" cloneref=&quot;foo&quot;&gt;
      &lt;filename name="**/*.txt" />
    &lt;/clone&gt;
    &lt;clone id="foo.nontxt" cloneref=&quot;foo&quot;&gt;
      &lt;filename name="**/*.txt" negate="true" />
    &lt;/clone&gt;
  </pre>
  Creates filesets <i>foo.txt</i> and <i>foo.nontxt</i>, which could be
  put to such uses as filtering some files and not others when copying.
  </p>
  <hr>
  
  <p align="center">Copyright &copy; 2005 The Apache Software Foundation. All rights
  Reserved.</p>
  
  </body>
  </html>
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org