git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@442287 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -38,6 +38,10 @@ Other changes: | |||
| 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 | |||
| ======================================== | |||
| @@ -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> | |||
| @@ -34,6 +34,14 @@ public abstract class ProjectComponent { | |||
| */ | |||
| 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() { | |||
| } | |||
| @@ -60,6 +68,32 @@ public abstract class ProjectComponent { | |||
| 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; | |||
| } | |||
| /** | |||
| * Logs a message with the default (INFO) priority. | |||
| * | |||
| @@ -47,14 +47,6 @@ public abstract class Task extends ProjectComponent { | |||
| */ | |||
| 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 | |||
| @@ -190,32 +182,6 @@ public abstract class Task extends ProjectComponent { | |||
| 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; | |||
| } | |||
| /** | |||
| * Returns the wrapper used for runtime configuration. | |||
| * | |||
| @@ -100,9 +100,23 @@ public class TaskAdapter extends Task implements TypeAdapter { | |||
| * 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()}); | |||
| @@ -424,6 +424,9 @@ public class UnknownElement extends Task { | |||
| if (o instanceof Task) { | |||
| ((Task) o).setOwningTarget(getOwningTarget()); | |||
| } | |||
| if (o instanceof ProjectComponent) { | |||
| ((ProjectComponent) o).setLocation(getLocation()); | |||
| } | |||
| return o; | |||
| } | |||
| @@ -545,7 +548,9 @@ public class UnknownElement extends Task { | |||
| 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; | |||
| @@ -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); | |||
| } | |||
| } | |||