From 5f93102e17838c47891084f6f62aa8f4c38cac6b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 2 Nov 2001 14:37:34 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269857 13f79535-47bb-0310-9956-ffa450edef68 --- src/etc/testcases/taskdefs/taskdef.xml | 4 + src/main/org/apache/tools/ant/Project.java | 31 ++++++ .../org/apache/tools/ant/TaskAdapter.java | 36 ++++++- .../apache/tools/ant/taskdefs/Definer.java | 3 +- .../apache/tools/ant/taskdefs/Taskdef.java | 4 +- .../apache/tools/ant/taskdefs/Typedef.java | 4 +- src/main/org/apache/tools/ant/types/Path.java | 4 +- .../apache/tools/ant/DummyTaskAbstract.java | 68 +++++++++++++ .../apache/tools/ant/DummyTaskInterface.java | 61 ++++++++++++ .../org/apache/tools/ant/DummyTaskOk.java | 67 +++++++++++++ .../apache/tools/ant/DummyTaskOkNonTask.java | 65 ++++++++++++ .../ant/DummyTaskWithNonPublicExecute.java | 65 ++++++++++++ .../ant/DummyTaskWithNonVoidExecute.java | 66 +++++++++++++ .../DummyTaskWithoutDefaultConstructor.java | 67 +++++++++++++ .../tools/ant/DummyTaskWithoutExecute.java | 65 ++++++++++++ .../DummyTaskWithoutPublicConstructor.java | 67 +++++++++++++ .../apache/tools/ant/MockBuildListener.java | 99 +++++++++++++++++++ .../org/apache/tools/ant/ProjectTest.java | 76 ++++++++++++++ .../tools/ant/taskdefs/TaskdefTest.java | 8 +- 19 files changed, 852 insertions(+), 8 deletions(-) create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskAbstract.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskInterface.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskOk.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskOkNonTask.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskWithoutExecute.java create mode 100644 src/testcases/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java create mode 100644 src/testcases/org/apache/tools/ant/MockBuildListener.java diff --git a/src/etc/testcases/taskdefs/taskdef.xml b/src/etc/testcases/taskdefs/taskdef.xml index 4ec7fdb50..bbfbba3f0 100644 --- a/src/etc/testcases/taskdefs/taskdef.xml +++ b/src/etc/testcases/taskdefs/taskdef.xml @@ -22,6 +22,10 @@ + + + + Stefan Bodewig */ 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); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Typedef.java b/src/main/org/apache/tools/ant/taskdefs/Typedef.java index 8a389d2c7..25f6a15fd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Typedef.java +++ b/src/main/org/apache/tools/ant/taskdefs/Typedef.java @@ -54,13 +54,15 @@ package org.apache.tools.ant.taskdefs; +import org.apache.tools.ant.BuildException; + /** * Define a new data type. * * @author Stefan Bodewig */ 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); } } diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index 562471f0b..46f9b2ea4 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -528,7 +528,7 @@ public class Path extends DataType implements Cloneable { 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 @@ public class Path extends DataType implements Cloneable { 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") diff --git a/src/testcases/org/apache/tools/ant/DummyTaskAbstract.java b/src/testcases/org/apache/tools/ant/DummyTaskAbstract.java new file mode 100644 index 000000000..1069d193d --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskAbstract.java @@ -0,0 +1,68 @@ +/* + * 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 + * . + */ + +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(); +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskInterface.java b/src/testcases/org/apache/tools/ant/DummyTaskInterface.java new file mode 100644 index 000000000..d31d68486 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskInterface.java @@ -0,0 +1,61 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +public interface DummyTaskInterface { + + public void execute(); + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskOk.java b/src/testcases/org/apache/tools/ant/DummyTaskOk.java new file mode 100644 index 000000000..0fac4e45f --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskOk.java @@ -0,0 +1,67 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public class DummyTaskOk extends Task { + + public DummyTaskOk() { + } + + public void execute() { + } + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskOkNonTask.java b/src/testcases/org/apache/tools/ant/DummyTaskOkNonTask.java new file mode 100644 index 000000000..e9865ca94 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskOkNonTask.java @@ -0,0 +1,65 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +public class DummyTaskOkNonTask { + + public DummyTaskOkNonTask() { + } + + public void execute() { + } + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java b/src/testcases/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java new file mode 100644 index 000000000..211ecdce2 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java @@ -0,0 +1,65 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +public class DummyTaskWithNonPublicExecute { + + public DummyTaskWithNonPublicExecute() { + } + + void execute() { + } + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java b/src/testcases/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java new file mode 100644 index 000000000..0c31873a6 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java @@ -0,0 +1,66 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +public class DummyTaskWithNonVoidExecute { + + public DummyTaskWithNonVoidExecute() { + } + + public int execute() { + return 0; + } + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java b/src/testcases/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java new file mode 100644 index 000000000..0bb157528 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java @@ -0,0 +1,67 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public class DummyTaskWithoutDefaultConstructor extends Task { + + public DummyTaskWithoutDefaultConstructor(int dummy) { + } + + public void execute() { + } + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskWithoutExecute.java b/src/testcases/org/apache/tools/ant/DummyTaskWithoutExecute.java new file mode 100644 index 000000000..14794c00f --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskWithoutExecute.java @@ -0,0 +1,65 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +public class DummyTaskWithoutExecute { + + public DummyTaskWithoutExecute() { + } + + public void execute(String dummy) { + } + +} diff --git a/src/testcases/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java b/src/testcases/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java new file mode 100644 index 000000000..1aad96416 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java @@ -0,0 +1,67 @@ +/* + * 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 + * . + */ + +package org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public class DummyTaskWithoutPublicConstructor extends Task { + + DummyTaskWithoutPublicConstructor() { + } + + public void execute() { + } + +} diff --git a/src/testcases/org/apache/tools/ant/MockBuildListener.java b/src/testcases/org/apache/tools/ant/MockBuildListener.java new file mode 100644 index 000000000..e71f1c46f --- /dev/null +++ b/src/testcases/org/apache/tools/ant/MockBuildListener.java @@ -0,0 +1,99 @@ +/* + * 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 + * . + */ + +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); + } + +} diff --git a/src/testcases/org/apache/tools/ant/ProjectTest.java b/src/testcases/org/apache/tools/ant/ProjectTest.java index d570cfb80..7b73c68cd 100644 --- a/src/testcases/org/apache/tools/ant/ProjectTest.java +++ b/src/testcases/org/apache/tools/ant/ProjectTest.java @@ -71,6 +71,7 @@ public class ProjectTest extends TestCase { private Project p; private String root; + private MockBuildListener mbl; public ProjectTest(String name) { super(name); @@ -80,6 +81,7 @@ public class ProjectTest extends TestCase { p = new Project(); p.init(); root = new File(File.separator).getAbsolutePath(); + mbl = new MockBuildListener(p); } public void testDataTypes() throws BuildException { @@ -155,4 +157,78 @@ public class ProjectTest extends TestCase { 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() {} } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/TaskdefTest.java b/src/testcases/org/apache/tools/ant/taskdefs/TaskdefTest.java index 5db0dd9f9..b8ba83cdd 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/TaskdefTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/TaskdefTest.java @@ -54,6 +54,8 @@ package org.apache.tools.ant.taskdefs; +import org.apache.tools.ant.Project; + /** * @author Nico Seessle */ @@ -84,7 +86,11 @@ public class TaskdefTest extends TaskdefsTest { } 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