ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r442287 - in /ant/core/trunk: ./ src/etc/testcases/core/ src/main/org/apache/tools/ant/ src/testcases/org/apache/tools/ant/
Date Mon, 11 Sep 2006 18:53:45 GMT
Author: bodewig
Date: Mon Sep 11 11:53:44 2006
New Revision: 442287

URL: http://svn.apache.org/viewvc?view=rev&rev=442287
Log:
Push setLocation down to ProjectComponent, reflect it into adapted tasks

Added:
    ant/core/trunk/src/etc/testcases/core/location.xml   (with props)
    ant/core/trunk/src/testcases/org/apache/tools/ant/LocationTest.java   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/ProjectComponent.java
    ant/core/trunk/src/main/org/apache/tools/ant/Task.java
    ant/core/trunk/src/main/org/apache/tools/ant/TaskAdapter.java
    ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=442287&r1=442286&r2=442287
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Sep 11 11:53:44 2006
@@ -38,6 +38,10 @@
   Bugzilla report 36772.
 * added searchparents attribute to <available>. Bugzilla report 39549.
 
+* tasks that don't extend Ant's Task class can will now get the build file
+  location reflected into a method of the signature void setLocation(Location)
+  - if such a method exists.
+
 Changes from Ant 1.6.5 to Ant 1.7.0Beta1
 ========================================
 

Added: ant/core/trunk/src/etc/testcases/core/location.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/core/location.xml?view=auto&rev=442287
==============================================================================
--- ant/core/trunk/src/etc/testcases/core/location.xml (added)
+++ ant/core/trunk/src/etc/testcases/core/location.xml Mon Sep 11 11:53:44 2006
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+-->
+<project name="location" default="all">
+  <target name="all">
+    <fail>Only use this build file from within tests</fail>
+  </target>
+
+  <target name="testPlainTask">
+    <echo id="echo">Hello</echo>
+  </target>
+
+  <target name="testStandaloneType">
+    <echo id="echo2">Hello</echo>
+    <fileset id="fs" dir="."/>
+  </target>
+
+  <target name="testConditionTask">
+    <condition property="foo" id="cond">
+      <equals arg1="bar" arg2="baz"/>
+    </condition>
+  </target>
+
+</project>
\ No newline at end of file

Propchange: ant/core/trunk/src/etc/testcases/core/location.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/main/org/apache/tools/ant/ProjectComponent.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ProjectComponent.java?view=diff&rev=442287&r1=442286&r2=442287
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/ProjectComponent.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/ProjectComponent.java Mon Sep 11 11:53:44
2006
@@ -34,6 +34,14 @@
      */
     protected Project project;
 
+    /**
+     * Location within the build file of this task definition.
+     * @deprecated since 1.6.x. 
+     *             You should not be accessing this variable directly.
+     *             Please use the {@link #getLocation()} method.
+     */
+    protected Location location = Location.UNKNOWN_LOCATION;
+
     /** Sole constructor. */
     public ProjectComponent() {
     }
@@ -58,6 +66,32 @@
      */
     public Project getProject() {
         return project;
+    }
+
+    /**
+     * Returns the file/location where this task was defined.
+     *
+     * @return the file/location where this task was defined.
+     *         Should not return <code>null</code>. Location.UNKNOWN_LOCATION
+     *         is used for unknown locations.
+     *
+     * @see Location#UNKNOWN_LOCATION
+     */
+    public Location getLocation() {
+        return location;
+    }
+
+    /**
+     * Sets the file/location where this task was defined.
+     *
+     * @param location The file/location where this task was defined.
+     *                 Should not be <code>null</code>--use
+     *                 Location.UNKNOWN_LOCATION if the location isn't known.
+     *
+     * @see Location#UNKNOWN_LOCATION
+     */
+    public void setLocation(Location location) {
+        this.location = location;
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Task.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Task.java?view=diff&rev=442287&r1=442286&r2=442287
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Task.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Task.java Mon Sep 11 11:53:44 2006
@@ -48,14 +48,6 @@
     protected String description;
 
     /**
-     * Location within the build file of this task definition.
-     * @deprecated since 1.6.x. 
-     *             You should not be accessing this variable directly.
-     *             Please use the {@link #getLocation()} method.
-     */
-    protected Location location = Location.UNKNOWN_LOCATION;
-
-    /**
      * Name of this task to be used for logging purposes.
      * This defaults to the same as the type, but may be
      * overridden by the user. For instance, the name "java"
@@ -188,32 +180,6 @@
      * @exception BuildException if something goes wrong with the build.
      */
     public void execute() throws BuildException {
-    }
-
-    /**
-     * Returns the file/location where this task was defined.
-     *
-     * @return the file/location where this task was defined.
-     *         Should not return <code>null</code>. Location.UNKNOWN_LOCATION
-     *         is used for unknown locations.
-     *
-     * @see Location#UNKNOWN_LOCATION
-     */
-    public Location getLocation() {
-        return location;
-    }
-
-    /**
-     * Sets the file/location where this task was defined.
-     *
-     * @param location The file/location where this task was defined.
-     *                 Should not be <code>null</code>--use
-     *                 Location.UNKNOWN_LOCATION if the location isn't known.
-     *
-     * @see Location#UNKNOWN_LOCATION
-     */
-    public void setLocation(Location location) {
-        this.location = location;
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/TaskAdapter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/TaskAdapter.java?view=diff&rev=442287&r1=442286&r2=442287
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/TaskAdapter.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/TaskAdapter.java Mon Sep 11 11:53:44 2006
@@ -100,9 +100,23 @@
      * or the method could not be executed.
      */
     public void execute() throws BuildException {
-        Method setProjectM = null;
         try {
-            setProjectM = proxy.getClass().getMethod(
+            Method setLocationM = proxy.getClass().getMethod(
+                "setLocation", new Class[] {Location.class});
+            if (setLocationM != null) {
+                setLocationM.invoke(proxy, new Object[] {getLocation()});
+            }
+        } catch (NoSuchMethodException e) {
+            // ignore this if the class being used as a task does not have
+            // a set location method.
+        } catch (Exception ex) {
+            log("Error setting location in " + proxy.getClass(),
+                Project.MSG_ERR);
+            throw new BuildException(ex);
+        }
+
+        try {
+            Method setProjectM = proxy.getClass().getMethod(
                 "setProject", new Class[] {Project.class});
             if (setProjectM != null) {
                 setProjectM.invoke(proxy, new Object[] {getProject()});

Modified: ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java?view=diff&rev=442287&r1=442286&r2=442287
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java Mon Sep 11 11:53:44 2006
@@ -424,6 +424,9 @@
         if (o instanceof Task) {
             ((Task) o).setOwningTarget(getOwningTarget());
         }
+        if (o instanceof ProjectComponent) {
+            ((ProjectComponent) o).setLocation(getLocation());
+        }
         return o;
     }
 
@@ -545,7 +548,9 @@
                 childTask.setRuntimeConfigurableWrapper(childWrapper);
                 childTask.setTaskName(childName);
                 childTask.setTaskType(childName);
-                childTask.setLocation(child.getLocation());
+            }
+            if (realChild instanceof ProjectComponent) {
+                ((ProjectComponent) realChild).setLocation(child.getLocation());
             }
             child.handleChildren(realChild, childWrapper);
             return true;

Added: ant/core/trunk/src/testcases/org/apache/tools/ant/LocationTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/LocationTest.java?view=auto&rev=442287
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/LocationTest.java (added)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/LocationTest.java Mon Sep 11 11:53:44
2006
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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;
+
+import org.apache.tools.ant.taskdefs.ConditionTask;
+import org.apache.tools.ant.taskdefs.Echo;
+import org.apache.tools.ant.types.FileSet;
+
+public class LocationTest extends BuildFileTest {
+
+    public void setUp() {
+        configureProject("src/etc/testcases/core/location.xml");
+    }
+
+    public void testPlainTask() {
+        executeTarget("testPlainTask");
+        Echo e = (Echo) getProject().getReference("echo");
+        assertFalse(e.getLocation() == Location.UNKNOWN_LOCATION);
+        assertFalse(e.getLocation().getLineNumber() == 0);
+    }
+
+    public void testStandaloneType() {
+        executeTarget("testStandaloneType");
+        Echo e = (Echo) getProject().getReference("echo2");
+        FileSet f = (FileSet) getProject().getReference("fs");
+        assertFalse(f.getLocation() == Location.UNKNOWN_LOCATION);
+        assertEquals(e.getLocation().getLineNumber() + 1,
+                     f.getLocation().getLineNumber());
+    }
+
+    public void testConditionTask() {
+        executeTarget("testConditionTask");
+        TaskAdapter ta = (TaskAdapter) getProject().getReference("cond");
+        ConditionTask c = (ConditionTask) ta.getProxy();
+        assertFalse(c.getLocation() == Location.UNKNOWN_LOCATION);
+        assertFalse(c.getLocation().getLineNumber() == 0);
+    }
+}
\ No newline at end of file

Propchange: ant/core/trunk/src/testcases/org/apache/tools/ant/LocationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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


Mime
View raw message