git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278339 13f79535-47bb-0310-9956-ffa450edef68master
@@ -141,8 +141,6 @@ Other changes: | |||
* Added preserveLastModified attribute to signjar task. | |||
Bugzilla report 30987. | |||
* Added clone task. Bugzilla report 32631. | |||
* Added <scriptcondition> condition, for inline scripted conditions | |||
* Added <xor> condition for exclusive-or combining of nested conditions. | |||
@@ -1,57 +0,0 @@ | |||
<html> | |||
<head> | |||
<meta http-equiv="Content-Language" content="en-us"> | |||
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css"> | |||
<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 "cloneref" 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> <clone id="foo.txt" cloneref="foo"> | |||
<filename name="**/*.txt"/> | |||
</clone> | |||
<clone id="foo.nontxt" cloneref="foo"> | |||
<filename name="**/*.txt" negate="true"/> | |||
</clone> | |||
</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 © 2005 The Apache Software Foundation. All rights | |||
Reserved.</p> | |||
</body> | |||
</html> | |||
@@ -28,7 +28,6 @@ | |||
<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> | |||
<a href="CoreTasks/conditions.html">Supported conditions</a><br> | |||
@@ -1,65 +0,0 @@ | |||
<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 message="expected $${ganger} = ""; instead was "${ganger}""> | |||
<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,97 +0,0 @@ | |||
/* | |||
* 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, (Object[])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,59 +0,0 @@ | |||
/* | |||
* 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"); | |||
} | |||
} |