You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/11/19 13:42:06 UTC
svn commit: r718943 - in /ant/core/trunk/src:
main/org/apache/tools/ant/TargetGroup.java
main/org/apache/tools/ant/helper/ProjectHelper2.java
main/org/apache/tools/ant/taskdefs/AntStructure.java
tests/antunit/core/target-group-test.xml
Author: bodewig
Date: Wed Nov 19 04:42:06 2008
New Revision: 718943
URL: http://svn.apache.org/viewvc?rev=718943&view=rev
Log:
Add target-group, a special target that must be empty and whose dependency list may be extended by other target(-group)s using their (new) target-group attribute
Added:
ant/core/trunk/src/main/org/apache/tools/ant/TargetGroup.java (with props)
ant/core/trunk/src/tests/antunit/core/target-group-test.xml (with props)
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
Added: ant/core/trunk/src/main/org/apache/tools/ant/TargetGroup.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/TargetGroup.java?rev=718943&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/TargetGroup.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/TargetGroup.java Wed Nov 19 04:42:06 2008
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+/**
+ * A special kind of target that must be empty.
+ *
+ * @since Ant 1.8.0
+ */
+public class TargetGroup extends Target {
+
+ // no "clone" constructor since I'm not really sure where it is
+ // used
+
+ private static final String NO_CHILDREN_ALLOWED
+ = "you must not nest child elements into a target-group";
+
+ /**
+ * Throws an exception.
+ */
+ public final void addTask(Task task) {
+ throw new BuildException(NO_CHILDREN_ALLOWED);
+ }
+
+ /**
+ * Throws an exception.
+ */
+ public final void addDataType(RuntimeConfigurable r) {
+ throw new BuildException(NO_CHILDREN_ALLOWED);
+ }
+
+}
\ No newline at end of file
Propchange: ant/core/trunk/src/main/org/apache/tools/ant/TargetGroup.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java?rev=718943&r1=718942&r2=718943&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Wed Nov 19 04:42:06 2008
@@ -24,6 +24,7 @@
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.RuntimeConfigurable;
import org.apache.tools.ant.Target;
+import org.apache.tools.ant.TargetGroup;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.UnknownElement;
import org.apache.tools.ant.util.FileUtils;
@@ -772,18 +773,20 @@
*
* @exception org.xml.sax.SAXParseException if the tag given is not
* <code>"taskdef"</code>, <code>"typedef"</code>,
- * <code>"property"</code>, <code>"target"</code>
+ * <code>"property"</code>, <code>"target"</code>,
+ * <code>"target-group"</code>
* or a data type definition
*/
public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,
AntXMLContext context) throws SAXParseException {
- return name.equals("target") && (uri.equals("") || uri.equals(ANT_CORE_URI))
- ? ProjectHelper2.targetHandler : ProjectHelper2.elementHandler;
+ return (name.equals("target") || name.equals("target-group"))
+ && (uri.equals("") || uri.equals(ANT_CORE_URI))
+ ? ProjectHelper2.targetHandler : ProjectHelper2.elementHandler;
}
}
/**
- * Handler for "target" elements.
+ * Handler for "target" and "target-group" elements.
*/
public static class TargetHandler extends AntHandler {
@@ -811,9 +814,11 @@
AntXMLContext context) throws SAXParseException {
String name = null;
String depends = "";
+ String targetGroup = null;
Project project = context.getProject();
- Target target = new Target();
+ Target target = "target".equals(tag)
+ ? new Target() : new TargetGroup();
target.setProject(project);
target.setLocation(new Location(context.getLocator()));
context.addTarget(target);
@@ -843,6 +848,8 @@
}
} else if (key.equals("description")) {
target.setDescription(value);
+ } else if (key.equals("target-group")) {
+ targetGroup = value;
} else {
throw new SAXParseException("Unexpected attribute \"" + key + "\"", context
.getLocator());
@@ -869,6 +876,9 @@
+ " specify a name attribute");
}
name = prefix + sep + name;
+ if (targetGroup != null) {
+ targetGroup = prefix + sep + targetGroup;
+ }
}
// Check if this target is in the current build file
@@ -910,6 +920,22 @@
context.getCurrentTargets().put(newName, newTarget);
project.addOrReplaceTarget(newName, newTarget);
}
+ if (targetGroup != null) {
+ if (!projectTargets.containsKey(targetGroup)) {
+ throw new BuildException("can't add target "
+ + name + " to target-group "
+ + targetGroup
+ + " because the target-group"
+ + " is unknown.");
+ }
+ Target t = (Target) projectTargets.get(targetGroup);
+ if (!(t instanceof TargetGroup)) {
+ throw new BuildException("referenced target "
+ + targetGroup
+ + " is not a target-group");
+ }
+ t.addDependency(name);
+ }
}
private String getTargetPrefix(AntXMLContext context) {
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java?rev=718943&r1=718942&r2=718943&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java Wed Nov 19 04:42:06 2008
@@ -225,7 +225,7 @@
out.println("");
- out.print("<!ELEMENT project (target | ");
+ out.print("<!ELEMENT project (target | target-group | ");
out.print(TASKS);
out.print(" | ");
out.print(TYPES);
@@ -247,13 +247,24 @@
out.print(TYPES);
out.println(")*>");
out.println("");
+ printTargetAttrs(out, "target");
+ out.println("<!ELEMENT target-group EMPTY>");
+ out.println("");
+ printTargetAttrs(out, "target-group");
+ }
- out.println("<!ATTLIST target");
+ /**
+ * Prints the definition for the target element.
+ */
+ private void printTargetAttrs(PrintWriter out, String tag) {
+ out.print("<!ATTLIST ");
+ out.println(tag);
out.println(" id ID #IMPLIED");
out.println(" name CDATA #REQUIRED");
out.println(" if CDATA #IMPLIED");
out.println(" unless CDATA #IMPLIED");
out.println(" depends CDATA #IMPLIED");
+ out.println(" target-group CDATA #IMPLIED");
out.println(" description CDATA #IMPLIED>");
out.println("");
}
Added: ant/core/trunk/src/tests/antunit/core/target-group-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/core/target-group-test.xml?rev=718943&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/core/target-group-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/core/target-group-test.xml Wed Nov 19 04:42:06 2008
@@ -0,0 +1,86 @@
+<?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 xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+ <import file="../antunit-base.xml"/>
+
+ <target-group name="testTargetGroupWorksLikeTarget"
+ depends="setProperty, assertProperty"/>
+
+ <target name="setProperty">
+ <property name="foo" value="bar"/>
+ </target>
+
+ <target name="assertProperty">
+ <au:assertPropertyEquals name="foo" value="bar"/>
+ </target>
+
+ <target name="testTargetGroupMustBeEmpty">
+ <mkdir dir="${output}"/>
+ <echo file="${output}/build.xml"><![CDATA[
+<project>
+ <target-group name="foo">
+ <echo>bar</echo>
+ </target-group>
+</project>]]></echo>
+ <au:expectfailure
+ expectedMessage="you must not nest child elements into a target-group">
+ <ant dir="${output}"/>
+ </au:expectfailure>
+ </target>
+
+ <target name="testAddToTargetGroup">
+ <mkdir dir="${output}"/>
+ <echo file="${output}/build.xml"><![CDATA[
+<project default="foo">
+ <target-group name="foo"/>
+ <target name="bar" target-group="foo">
+ <echo>In target bar</echo>
+ </target>
+</project>]]></echo>
+ <ant dir="${output}"/>
+ <au:assertLogContains text="In target bar"/>
+ </target>
+
+ <target name="testTargetGroupMustBeKnown">
+ <mkdir dir="${output}"/>
+ <echo file="${output}/build.xml"><![CDATA[
+<project default="foo">
+ <target-group name="bar" target-group="foo"/>
+ <target-group name="foo"/>
+</project>]]></echo>
+ <au:expectfailure
+ expectedMessage="can't add target bar to target-group foo because the target-group is unknown">
+ <ant dir="${output}"/>
+ </au:expectfailure>
+ </target>
+
+ <target name="testCantAddToPlainTarget">
+ <mkdir dir="${output}"/>
+ <echo file="${output}/build.xml"><![CDATA[
+<project default="foo">
+ <target name="foo"/>
+ <target name="bar" target-group="foo"/>
+</project>]]></echo>
+ <au:expectfailure
+ expectedMessage="referenced target foo is not a target-group">
+ <ant dir="${output}"/>
+ </au:expectfailure>
+ </target>
+
+</project>
Propchange: ant/core/trunk/src/tests/antunit/core/target-group-test.xml
------------------------------------------------------------------------------
svn:eol-style = native