You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/11/02 15:37:34 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs TaskdefTest.java
bodewig 01/11/02 06:37:34
Modified: src/etc/testcases/taskdefs taskdef.xml
src/main/org/apache/tools/ant Project.java TaskAdapter.java
src/main/org/apache/tools/ant/taskdefs Definer.java
Taskdef.java Typedef.java
src/main/org/apache/tools/ant/types Path.java
src/testcases/org/apache/tools/ant ProjectTest.java
src/testcases/org/apache/tools/ant/taskdefs TaskdefTest.java
Added: src/testcases/org/apache/tools/ant DummyTaskAbstract.java
DummyTaskInterface.java DummyTaskOk.java
DummyTaskOkNonTask.java
DummyTaskWithNonPublicExecute.java
DummyTaskWithNonVoidExecute.java
DummyTaskWithoutDefaultConstructor.java
DummyTaskWithoutExecute.java
DummyTaskWithoutPublicConstructor.java
MockBuildListener.java
Log:
Make sure the class passed into Project.addTaskDefinition is suitable
for a task, that is it is public, non-abstract, has a no-arg
constructor and a public no-arg execute method.
PR: 4163
Submitted by: Ralf Wiebicke <ra...@rw7.de>
Revision Changes Path
1.5 +4 -0 jakarta-ant/src/etc/testcases/taskdefs/taskdef.xml
Index: taskdef.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/taskdef.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- taskdef.xml 2001/07/26 15:38:48 1.4
+++ taskdef.xml 2001/11/02 14:37:33 1.5
@@ -22,6 +22,10 @@
<taskdef name="test" classname="org.apache.tools.ant.Project" />
</target>
+ <target name="test5a">
+ <taskdef name="test" classname="org.apache.tools.ant.taskdefs.Copy" />
+ </target>
+
<target name="test6">
<echo message="${build.test}" />
<taskdef name="test6"
1.78 +31 -0 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.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- Project.java 2001/10/28 21:25:26 1.77
+++ Project.java 2001/11/02 14:37:33 1.78
@@ -62,6 +62,7 @@
import java.util.Properties;
import java.util.Enumeration;
import java.util.Stack;
+import java.lang.reflect.Modifier;
import org.apache.tools.ant.types.FilterSet;
@@ -414,7 +415,37 @@
String msg = " +User task: " + taskName + " " + taskClass.getName();
log(msg, MSG_DEBUG);
+ checkTaskClass(taskClass);
taskClassDefinitions.put(taskName, taskClass);
+ }
+
+ /**
+ * Checks a class, whether it is suitable for serving as ant task.
+ * Throws a BuildException and logs as Project.MSG_ERR for
+ * conditions, that will cause the task execution to fail.
+ */
+ public void checkTaskClass(final Class taskClass) {
+ if(!Modifier.isPublic(taskClass.getModifiers())) {
+ final String message = taskClass + " is not public";
+ log(message, Project.MSG_ERR);
+ throw new BuildException(message);
+ }
+ if(Modifier.isAbstract(taskClass.getModifiers())) {
+ final String message = taskClass + " is abstract";
+ log(message, Project.MSG_ERR);
+ throw new BuildException(message);
+ }
+ try {
+ taskClass.getConstructor( null );
+ // don't have to check for public, since
+ // getConstructor finds public constructors only.
+ } catch(NoSuchMethodException e) {
+ final String message = "No public default constructor in " + taskClass;
+ log(message, Project.MSG_ERR);
+ throw new BuildException(message);
+ }
+ if( !Task.class.isAssignableFrom(taskClass) )
+ TaskAdapter.checkTaskClass(taskClass, this);
}
public Hashtable getTaskDefinitions() {
1.9 +34 -2 jakarta-ant/src/main/org/apache/tools/ant/TaskAdapter.java
Index: TaskAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/TaskAdapter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TaskAdapter.java 2001/10/28 21:25:26 1.8
+++ TaskAdapter.java 2001/11/02 14:37:33 1.9
@@ -55,6 +55,7 @@
package org.apache.tools.ant;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
/**
@@ -68,6 +69,37 @@
Object proxy;
/**
+ * Checks a class, whether it is suitable to be adapted by TaskAdapter.
+ *
+ * Checks conditions only, which are additionally required for a tasks
+ * adapted by TaskAdapter. Thus, this method should be called by
+ * {@link Project.checkTaskClass}.
+ *
+ * Throws a BuildException and logs as Project.MSG_ERR for
+ * conditions, that will cause the task execution to fail.
+ * Logs other suspicious conditions with Project.MSG_WARN.
+ */
+ public static void checkTaskClass(final Class taskClass, final Project project) {
+ // don't have to check for interface, since then
+ // taskClass would be abstract too.
+ try {
+ final Method executeM = taskClass.getMethod( "execute", null );
+ // don't have to check for public, since
+ // getMethod finds public method only.
+ // don't have to check for abstract, since then
+ // taskClass would be abstract too.
+ if(!Void.TYPE.equals(executeM.getReturnType())) {
+ final String message = "return type of execute() should be void but was \""+executeM.getReturnType()+"\" in " + taskClass;
+ project.log(message, Project.MSG_WARN);
+ }
+ } catch(NoSuchMethodException e) {
+ final String message = "No public execute() in " + taskClass;
+ project.log(message, Project.MSG_ERR);
+ throw new BuildException(message);
+ }
+ }
+
+ /**
* Do the execution.
*/
public void execute() throws BuildException {
@@ -94,8 +126,8 @@
Class c=proxy.getClass();
executeM=c.getMethod( "execute", new Class[0] );
if( executeM == null ) {
- log("No execute in " + proxy.getClass(), Project.MSG_ERR);
- throw new BuildException("No execute in " + proxy.getClass());
+ log("No public execute() in " + proxy.getClass(), Project.MSG_ERR);
+ throw new BuildException("No public execute() in " + proxy.getClass());
}
executeM.invoke(proxy, null);
return;
1.9 +2 -1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java
Index: Definer.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Definer.java 2001/10/28 21:26:29 1.8
+++ Definer.java 2001/11/02 14:37:33 1.9
@@ -173,7 +173,8 @@
}
}
- private void addDefinition( ClassLoader al, String name, String value ) {
+ private void addDefinition( ClassLoader al, String name, String value )
+ throws BuildException {
try {
Class c = al.loadClass(value);
AntClassLoader.initializeClass(c);
1.16 +3 -1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Taskdef.java
Index: Taskdef.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Taskdef.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Taskdef.java 2001/06/07 11:42:08 1.15
+++ Taskdef.java 2001/11/02 14:37:33 1.16
@@ -54,13 +54,15 @@
package org.apache.tools.ant.taskdefs;
+import org.apache.tools.ant.BuildException;
+
/**
* Define a new task.
*
* @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class Taskdef extends Definer {
- protected void addDefinition(String name, Class c) {
+ protected void addDefinition(String name, Class c) throws BuildException {
project.addTaskDefinition(name, c);
}
}
1.2 +3 -1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Typedef.java
Index: Typedef.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Typedef.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Typedef.java 2001/06/07 11:42:09 1.1
+++ Typedef.java 2001/11/02 14:37:33 1.2
@@ -54,13 +54,15 @@
package org.apache.tools.ant.taskdefs;
+import org.apache.tools.ant.BuildException;
+
/**
* Define a new data type.
*
* @author <a href="stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class Typedef extends Definer {
- protected void addDefinition(String name, Class c) {
+ protected void addDefinition(String name, Class c) throws BuildException {
project.addDataTypeDefinition(name, c);
}
}
1.24 +2 -2 jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
Index: Path.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Path.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Path.java 2001/10/31 11:50:35 1.23
+++ Path.java 2001/11/02 14:37:33 1.24
@@ -528,7 +528,7 @@
msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages"));
msZipFiles.setIncludes("*.ZIP");
addFileset(msZipFiles);
- } else if(System.getProperty("java.vm.name").equals("Kaffe")) {
+ } else if("Kaffe".equals(System.getProperty("java.vm.name"))) {
FileSet kaffeJarFiles = new FileSet();
kaffeJarFiles.setDir(new File(System.getProperty("java.home")
+ File.separator + "share"
@@ -549,7 +549,7 @@
System.getProperty("java.home")
+ File.separator + "lib"
+ File.separator + "rt.jar"));
- // Just keep the old version as well and let addExistingToPath
+ // Just keep the old version as well and let addExisting
// sort it out.
addExisting(new Path(null,
System.getProperty("java.home")
1.8 +76 -0 jakarta-ant/src/testcases/org/apache/tools/ant/ProjectTest.java
Index: ProjectTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/ProjectTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ProjectTest.java 2001/10/23 10:35:14 1.7
+++ ProjectTest.java 2001/11/02 14:37:33 1.8
@@ -71,6 +71,7 @@
private Project p;
private String root;
+ private MockBuildListener mbl;
public ProjectTest(String name) {
super(name);
@@ -80,6 +81,7 @@
p = new Project();
p.init();
root = new File(File.separator).getAbsolutePath();
+ mbl = new MockBuildListener(p);
}
public void testDataTypes() throws BuildException {
@@ -155,4 +157,78 @@
path = root + path.substring(1);
return path.replace('\\', File.separatorChar).replace('/', File.separatorChar);
}
+
+
+ private void assertTaskDefFails(final Class taskClass,
+ final String message) {
+ final String dummyName = "testTaskDefinitionDummy";
+ try {
+ mbl.addBuildEvent(message, Project.MSG_ERR);
+ p.addTaskDefinition(dummyName, taskClass);
+ fail("expected BuildException(\""+message+"\", Project.MSG_ERR) when adding task " + taskClass);
+ }
+ catch(BuildException e) {
+ assertEquals(message, e.getMessage());
+ mbl.assertEmpty();
+ assertTrue(!p.getTaskDefinitions().containsKey(dummyName));
+ }
+ }
+
+ public void testAddTaskDefinition() {
+ p.addBuildListener(mbl);
+
+ p.addTaskDefinition("Ok", DummyTaskOk.class);
+ assertEquals(DummyTaskOk.class, p.getTaskDefinitions().get("Ok"));
+ p.addTaskDefinition("OkNonTask", DummyTaskOkNonTask.class);
+ assertEquals(DummyTaskOkNonTask.class, p.getTaskDefinitions().get("OkNonTask"));
+ mbl.assertEmpty();
+
+ assertTaskDefFails(DummyTaskPrivate.class, DummyTaskPrivate.class + " is not public");
+
+ if (p.getJavaVersion() != Project.JAVA_1_1) {
+ assertTaskDefFails(DummyTaskProtected.class,
+ DummyTaskProtected.class + " is not public");
+ } else {
+ /*
+ * I don't understand this, but this is what happens with
+ * > java -fullversion
+ * java full version "Linux_JDK_1.1.8_v3_green_threads"
+ */
+ assertTaskDefFails(DummyTaskProtected.class,
+ "No public default constructor in "
+ + DummyTaskProtected.class);
+ }
+
+ assertTaskDefFails(DummyTaskPackage.class, DummyTaskPackage.class + " is not public");
+
+ assertTaskDefFails(DummyTaskAbstract.class, DummyTaskAbstract.class + " is abstract");
+ assertTaskDefFails(DummyTaskInterface.class, DummyTaskInterface.class + " is abstract");
+
+ assertTaskDefFails(DummyTaskWithoutDefaultConstructor.class, "No public default constructor in " + DummyTaskWithoutDefaultConstructor.class);
+ assertTaskDefFails(DummyTaskWithoutPublicConstructor.class, "No public default constructor in " + DummyTaskWithoutPublicConstructor.class);
+
+ assertTaskDefFails(DummyTaskWithoutExecute.class, "No public execute() in " + DummyTaskWithoutExecute.class);
+ assertTaskDefFails(DummyTaskWithNonPublicExecute.class, "No public execute() in " + DummyTaskWithNonPublicExecute.class);
+
+ mbl.addBuildEvent("return type of execute() should be void but was \"int\" in " + DummyTaskWithNonVoidExecute.class, Project.MSG_WARN);
+ p.addTaskDefinition("NonVoidExecute", DummyTaskWithNonVoidExecute.class);
+ mbl.assertEmpty();
+ assertEquals(DummyTaskWithNonVoidExecute.class, p.getTaskDefinitions().get("NonVoidExecute"));
+ }
+
+ private class DummyTaskPrivate extends Task {
+ public DummyTaskPrivate() {}
+ public void execute() {}
+ }
+
+ protected class DummyTaskProtected extends Task {
+ public DummyTaskProtected() {}
+ public void execute() {}
+ }
+
+}
+
+class DummyTaskPackage extends Task {
+ public DummyTaskPackage() {}
+ public void execute() {}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskAbstract.java
Index: DummyTaskAbstract.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", "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;
import org.apache.tools.ant.Task;
public abstract class DummyTaskAbstract extends Task {
public DummyTaskAbstract() {
}
public void execute() {
}
public abstract void abstractDummy();
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskInterface.java
Index: DummyTaskInterface.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", "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;
public interface DummyTaskInterface {
public void execute();
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskOk.java
Index: DummyTaskOk.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", "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;
import org.apache.tools.ant.Task;
public class DummyTaskOk extends Task {
public DummyTaskOk() {
}
public void execute() {
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskOkNonTask.java
Index: DummyTaskOkNonTask.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", "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;
public class DummyTaskOkNonTask {
public DummyTaskOkNonTask() {
}
public void execute() {
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java
Index: DummyTaskWithNonPublicExecute.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", "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;
public class DummyTaskWithNonPublicExecute {
public DummyTaskWithNonPublicExecute() {
}
void execute() {
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java
Index: DummyTaskWithNonVoidExecute.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", "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;
public class DummyTaskWithNonVoidExecute {
public DummyTaskWithNonVoidExecute() {
}
public int execute() {
return 0;
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java
Index: DummyTaskWithoutDefaultConstructor.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", "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;
import org.apache.tools.ant.Task;
public class DummyTaskWithoutDefaultConstructor extends Task {
public DummyTaskWithoutDefaultConstructor(int dummy) {
}
public void execute() {
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskWithoutExecute.java
Index: DummyTaskWithoutExecute.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", "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;
public class DummyTaskWithoutExecute {
public DummyTaskWithoutExecute() {
}
public void execute(String dummy) {
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java
Index: DummyTaskWithoutPublicConstructor.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", "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;
import org.apache.tools.ant.Task;
public class DummyTaskWithoutPublicConstructor extends Task {
DummyTaskWithoutPublicConstructor() {
}
public void execute() {
}
}
1.1 jakarta-ant/src/testcases/org/apache/tools/ant/MockBuildListener.java
Index: MockBuildListener.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", "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;
import java.util.Vector;
import junit.framework.Assert;
public class MockBuildListener extends Assert implements BuildListener {
private final Vector buffer = new Vector();
private final Project project;
public MockBuildListener(final Project project) {
this.project = project;
}
public void buildStarted(BuildEvent event) {}
public void buildFinished(BuildEvent event) {}
public void targetStarted(BuildEvent event) {}
public void targetFinished(BuildEvent event) {}
public void taskStarted(BuildEvent event) {}
public void taskFinished(BuildEvent event) {}
public void messageLogged(final BuildEvent actual) {
if(actual.getPriority()==Project.MSG_DEBUG)
return;
assertTrue("unexpected messageLogged: "+actual.getMessage(), !buffer.isEmpty());
assertEquals("unexpected project ", project, actual.getProject());
BuildEvent expected = (BuildEvent) buffer.elementAt(0);
buffer.removeElementAt(0);
assertEquals("unexpected messageLogged ", expected.getMessage(), actual.getMessage());
assertEquals("unexpected priority ", expected.getPriority(), actual.getPriority());
}
public void assertEmpty() {
assertTrue("MockBuilListener is not empty", buffer.isEmpty());
}
public void addBuildEvent(final String message, final int priority) {
final BuildEvent be = new BuildEvent(project);
be.setMessage(message, priority);
buffer.addElement(be);
}
}
1.4 +7 -1 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TaskdefTest.java
Index: TaskdefTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TaskdefTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TaskdefTest.java 2001/07/26 15:38:48 1.3
+++ TaskdefTest.java 2001/11/02 14:37:34 1.4
@@ -54,6 +54,8 @@
package org.apache.tools.ant.taskdefs;
+import org.apache.tools.ant.Project;
+
/**
* @author Nico Seessle <ni...@seessle.de>
*/
@@ -84,7 +86,11 @@
}
public void test5() {
- executeTarget("test5");
+ expectBuildException("test5", "No public execute() in " + Project.class);
+ }
+
+ public void test5a() {
+ executeTarget("test5a");
}
/* disabled until I know why they fail when run via the junit task --SB
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>