diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java
index ab6f9fa80..97f852a86 100644
--- a/src/main/org/apache/tools/ant/MagicNames.java
+++ b/src/main/org/apache/tools/ant/MagicNames.java
@@ -149,8 +149,7 @@ public final class MagicNames {
public static final String BUILD_JAVAC_SOURCE = "ant.build.javac.source";
/**
- * property that provides the default value for javac's target
- * attribute.
+ * property that provides the default value for javac's target attribute.
* @since Ant 1.7
* Value: {@value}
*/
@@ -175,5 +174,24 @@ public final class MagicNames {
*/
public static final String REFID_PROPERTY_HELPER = "ant.PropertyHelper";
+ /**
+ * Name of JVM system property which provides the name of the ProjectHelper class to use.
+ * Value: {@value}
+ */
+ public static final String PROJECT_HELPER_CLASS = "org.apache.tools.ant.ProjectHelper";
+
+ /**
+ * The service identifier in jars which provide ProjectHelper implementations.
+ * Value: {@value}
+ */
+ public static final String PROJECT_HELPER_SERVICE =
+ "META-INF/services/org.apache.tools.ant.ProjectHelper";
+
+ /**
+ * Name of ProjectHelper reference that we add to a project.
+ * Value: {@value}
+ */
+ public static final String REFID_PROJECT_HELPER = "ant.projectHelper";
+
}
diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java
index ed955b636..f390b9597 100644
--- a/src/main/org/apache/tools/ant/ProjectHelper.java
+++ b/src/main/org/apache/tools/ant/ProjectHelper.java
@@ -15,7 +15,6 @@
* limitations under the License.
*
*/
-
package org.apache.tools.ant;
import java.io.BufferedReader;
@@ -25,9 +24,11 @@ import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
+
+import org.xml.sax.AttributeList;
+
import org.apache.tools.ant.helper.ProjectHelper2;
import org.apache.tools.ant.util.LoaderUtils;
-import org.xml.sax.AttributeList;
/**
* Configures a Project (complete with Targets and Tasks) based on
@@ -64,20 +65,18 @@ public class ProjectHelper {
* Name of JVM system property which provides the name of the
* ProjectHelper class to use.
*/
- public static final String HELPER_PROPERTY =
- "org.apache.tools.ant.ProjectHelper";
+ public static final String HELPER_PROPERTY = MagicNames.PROJECT_HELPER_CLASS;
/**
* The service identifier in jars which provide Project Helper
* implementations.
*/
- public static final String SERVICE_ID =
- "META-INF/services/org.apache.tools.ant.ProjectHelper";
+ public static final String SERVICE_ID = MagicNames.PROJECT_HELPER_SERVICE;
/**
* name of project helper reference that we add to a project
*/
- public static final String PROJECTHELPER_REFERENCE = "ant.projectHelper";
+ public static final String PROJECTHELPER_REFERENCE = MagicNames.REFID_PROJECT_HELPER;
/**
* Configures the project with the contents of the specified XML file.
@@ -86,11 +85,9 @@ public class ProjectHelper {
* @param buildFile An XML file giving the project's configuration.
* Must not be null
.
*
- * @exception BuildException if the configuration is invalid or cannot
- * be read
+ * @exception BuildException if the configuration is invalid or cannot be read
*/
- public static void configureProject(Project project, File buildFile)
- throws BuildException {
+ public static void configureProject(Project project, File buildFile) throws BuildException {
ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference(PROJECTHELPER_REFERENCE, helper);
helper.parse(project, buildFile);
@@ -132,7 +129,6 @@ public class ProjectHelper {
return importStack;
}
-
// -------------------- Parse method --------------------
/**
* Parses the project file, configuring the project as it goes.
@@ -152,7 +148,6 @@ public class ProjectHelper {
+ "in a helper plugin " + this.getClass().getName());
}
-
/**
* Discovers a project helper instance. Uses the same patterns
* as JAXP, commons-logging, etc: a system property, a JDK1.3
@@ -165,8 +160,7 @@ public class ProjectHelper {
* @exception BuildException if a specified helper class cannot
* be loaded/instantiated.
*/
- public static ProjectHelper getProjectHelper()
- throws BuildException {
+ public static ProjectHelper getProjectHelper() throws BuildException {
// Identify the class loader we will be using. Ant may be
// in a webapp or embedded in a different app
ProjectHelper helper = null;
@@ -195,7 +189,6 @@ public class ProjectHelper {
if (is == null) {
is = ClassLoader.getSystemResourceAsStream(SERVICE_ID);
}
-
if (is != null) {
// This code is needed by EBCDIC and other strange systems.
// It's a fix for bugs reported in xerces
@@ -210,23 +203,15 @@ public class ProjectHelper {
String helperClassName = rd.readLine();
rd.close();
- if (helperClassName != null
- && !"".equals(helperClassName)) {
-
+ if (helperClassName != null && !"".equals(helperClassName)) {
helper = newHelper(helperClassName);
}
}
} catch (Exception ex) {
- System.out.println("Unable to load ProjectHelper "
- + "from service \"" + SERVICE_ID);
+ System.out.println("Unable to load ProjectHelper from service " + SERVICE_ID);
}
}
-
- if (helper != null) {
- return helper;
- } else {
- return new ProjectHelper2();
- }
+ return helper == null ? new ProjectHelper2() : helper;
}
/**
@@ -264,8 +249,7 @@ public class ProjectHelper {
}
/**
- * JDK1.1 compatible access to the context class loader.
- * Cut&paste from JAXP.
+ * JDK1.1 compatible access to the context class loader. Cut & paste from JAXP.
*
* @deprecated since 1.6.x.
* Use LoaderUtils.getContextClassLoader()
@@ -274,11 +258,7 @@ public class ProjectHelper {
* if the context class loader is unavailable.
*/
public static ClassLoader getContextClassLoader() {
- if (!LoaderUtils.isContextLoaderAvailable()) {
- return null;
- }
-
- return LoaderUtils.getContextClassLoader();
+ return LoaderUtils.isContextLoaderAvailable() ? LoaderUtils.getContextClassLoader() : null;
}
// -------------------- Static utils, used by most helpers ----------------
@@ -304,18 +284,13 @@ public class ProjectHelper {
if (target instanceof TypeAdapter) {
target = ((TypeAdapter) target).getProxy();
}
-
- IntrospectionHelper ih =
- IntrospectionHelper.getHelper(project, target.getClass());
+ IntrospectionHelper ih = IntrospectionHelper.getHelper(project, target.getClass());
for (int i = 0, length = attrs.getLength(); i < length; i++) {
// reflect these into the target
- String value = replaceProperties(project, attrs.getValue(i),
- project.getProperties());
+ String value = replaceProperties(project, attrs.getValue(i), project.getProperties());
try {
- ih.setAttribute(project, target,
- attrs.getName(i).toLowerCase(Locale.US), value);
-
+ ih.setAttribute(project, target, attrs.getName(i).toLowerCase(Locale.US), value);
} catch (BuildException be) {
// id attribute must be set externally
if (!attrs.getName(i).equals("id")) {
@@ -363,13 +338,10 @@ public class ProjectHelper {
if (text == null) {
return;
}
-
if (target instanceof TypeAdapter) {
target = ((TypeAdapter) target).getProxy();
}
-
- IntrospectionHelper.getHelper(project, target.getClass()).addText(project,
- target, text);
+ IntrospectionHelper.getHelper(project, target.getClass()).addText(project, target, text);
}
/**
@@ -385,10 +357,8 @@ public class ProjectHelper {
* May be null
, in which case
* the child is not stored.
*/
- public static void storeChild(Project project, Object parent,
- Object child, String tag) {
- IntrospectionHelper ih
- = IntrospectionHelper.getHelper(project, parent.getClass());
+ public static void storeChild(Project project, Object parent, Object child, String tag) {
+ IntrospectionHelper ih = IntrospectionHelper.getHelper(project, parent.getClass());
ih.storeElement(project, parent, child, tag);
}
@@ -412,8 +382,7 @@ public class ProjectHelper {
* Use project.replaceProperties().
* @since 1.5
*/
- public static String replaceProperties(Project project, String value)
- throws BuildException {
+ public static String replaceProperties(Project project, String value) throws BuildException {
// needed since project properties are not accessible
return project.replaceProperties(value);
}
@@ -438,8 +407,8 @@ public class ProjectHelper {
* @deprecated since 1.6.x.
* Use PropertyHelper.
*/
- public static String replaceProperties(Project project, String value,
- Hashtable keys) throws BuildException {
+ public static String replaceProperties(Project project, String value, Hashtable keys)
+ throws BuildException {
PropertyHelper ph = PropertyHelper.getPropertyHelper(project);
return ph.replaceProperties(null, value, keys);
}
@@ -460,15 +429,13 @@ public class ProjectHelper {
* @deprecated since 1.6.x.
* Use PropertyHelper.
* @exception BuildException if the string contains an opening
- * ${
without a closing
- * }
+ * ${
without a closing }
*/
- public static void parsePropertyString(String value, Vector fragments,
- Vector propertyRefs)
- throws BuildException {
- PropertyHelper.parsePropertyStringDefault(value, fragments,
- propertyRefs);
+ public static void parsePropertyString(String value, Vector fragments, Vector propertyRefs)
+ throws BuildException {
+ PropertyHelper.parsePropertyStringDefault(value, fragments, propertyRefs);
}
+
/**
* Map a namespaced {uri,name} to an internal string format.
* For BC purposes the names from the ant core uri will be
@@ -526,7 +493,7 @@ public class ProjectHelper {
* did not have a location, just return the build exception
*/
public static BuildException addLocationToBuildException(
- BuildException ex, Location newLocation) {
+ BuildException ex, Location newLocation) {
if (ex.getLocation() == null || ex.getMessage() == null) {
return ex;
}
@@ -537,9 +504,7 @@ public class ProjectHelper {
+ ex.getMessage();
if (newLocation == null) {
return new BuildException(errorMessage, ex);
- } else {
- return new BuildException(
- errorMessage, ex, newLocation);
}
+ return new BuildException(errorMessage, ex, newLocation);
}
}
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
index 426b48e58..494a394b8 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
@@ -15,11 +15,11 @@
* limitations under the License.
*
*/
-
package org.apache.tools.ant.helper;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.RuntimeConfigurable;
@@ -53,6 +53,9 @@ import java.util.Stack;
*
*/
public class ProjectHelper2 extends ProjectHelper {
+ /** Reference holding the (ordered) target Vector */
+ public static final String REFID_TARGETS = "ant.targets";
+
/* Stateless */
// singletons - since all state is in the context
@@ -61,6 +64,9 @@ public class ProjectHelper2 extends ProjectHelper {
private static AntHandler mainHandler = new MainHandler();
private static AntHandler projectHandler = new ProjectHandler();
+ /** Specific to ProjectHelper2 so not a true Ant "magic name:" */
+ private static final String REFID_CONTEXT = "ant.parsing.context";
+
/**
* helper for path -> URI and URI -> path conversions.
*/
@@ -74,8 +80,7 @@ public class ProjectHelper2 extends ProjectHelper {
* @return a configured task
* @exception BuildException if an error occurs
*/
- public UnknownElement parseUnknownElement(Project project, URL source)
- throws BuildException {
+ public UnknownElement parseUnknownElement(Project project, URL source) throws BuildException {
Target dummyTarget = new Target();
dummyTarget.setProject(project);
@@ -83,14 +88,14 @@ public class ProjectHelper2 extends ProjectHelper {
context.addTarget(dummyTarget);
context.setImplicitTarget(dummyTarget);
- parse(context.getProject(), source,
- new RootHandler(context, elementHandler));
+ parse(context.getProject(), source, new RootHandler(context, elementHandler));
Task[] tasks = dummyTarget.getTasks();
if (tasks.length != 1) {
throw new BuildException("No tasks defined");
}
return (UnknownElement) tasks[0];
}
+
/**
* Parse a source xml input.
*
@@ -98,18 +103,14 @@ public class ProjectHelper2 extends ProjectHelper {
* @param source the xml source
* @exception BuildException if an error occurs
*/
- public void parse(Project project, Object source)
- throws BuildException {
+ public void parse(Project project, Object source) throws BuildException {
getImportStack().addElement(source);
- //System.out.println("Adding " + source);
AntXMLContext context = null;
- context = (AntXMLContext) project.getReference("ant.parsing.context");
-// System.out.println("Parsing " + getImportStack().size() + " " +
-// context+ " " + getImportStack() );
+ context = (AntXMLContext) project.getReference(REFID_CONTEXT);
if (context == null) {
context = new AntXMLContext(project);
- project.addReference("ant.parsing.context", context);
- project.addReference("ant.targets", context.getTargets());
+ project.addReference(REFID_CONTEXT, context);
+ project.addReference(REFID_TARGETS, context.getTargets());
}
if (getImportStack().size() > 1) {
@@ -150,8 +151,7 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception BuildException if the configuration is invalid or cannot
* be read
*/
- public void parse(Project project, Object source, RootHandler handler)
- throws BuildException {
+ public void parse(Project project, Object source, RootHandler handler) throws BuildException {
AntXMLContext context = handler.context;
@@ -177,7 +177,6 @@ public class ProjectHelper2 extends ProjectHelper {
InputStream inputStream = null;
InputSource inputSource = null;
-
try {
/**
* SAX 2 style parser used to parse the given file.
@@ -218,29 +217,22 @@ public class ProjectHelper2 extends ProjectHelper {
be.setLocation(location);
}
throw be;
- } else if (t == null) {
- t = exc;
}
-
- throw new BuildException(exc.getMessage(), t, location);
+ throw new BuildException(exc.getMessage(), t == null ? exc : t, location);
} catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
- } else if (t == null) {
- t = exc;
}
- throw new BuildException(exc.getMessage(), t);
+ throw new BuildException(exc.getMessage(), t == null ? exc : t);
} catch (FileNotFoundException exc) {
throw new BuildException(exc);
} catch (UnsupportedEncodingException exc) {
throw new BuildException("Encoding of project file "
- + buildFileName + " is invalid.",
- exc);
+ + buildFileName + " is invalid.", exc);
} catch (IOException exc) {
throw new BuildException("Error reading project file "
- + buildFileName + ": " + exc.getMessage(),
- exc);
+ + buildFileName + ": " + exc.getMessage(), exc);
} finally {
FileUtils.close(inputStream);
}
@@ -310,8 +302,6 @@ public class ProjectHelper2 extends ProjectHelper {
elementHandler = handler;
}
-
-
/**
* The common superclass for all SAX event handlers used to parse
* the configuration file.
@@ -336,10 +326,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException if this method is not overridden, or in
* case of error in an overridden version
*/
- public void onStartElement(String uri, String tag, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public void onStartElement(String uri, String tag, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
}
/**
@@ -359,12 +347,10 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException if this method is not overridden, or in
* case of error in an overridden version
*/
- public AntHandler onStartChild(String uri, String tag, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
throw new SAXParseException("Unexpected element \"" + qname
- + " \"", context.getLocator());
+ + " \"", context.getLocator());
}
/**
@@ -377,8 +363,7 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException if an error occurs
*/
public void onEndChild(String uri, String tag, String qname,
- AntXMLContext context)
- throws SAXParseException {
+ AntXMLContext context) throws SAXParseException {
}
/**
@@ -388,8 +373,7 @@ public class ProjectHelper2 extends ProjectHelper {
* @param tag the element name
* @param context the current context
*/
- public void onEndElement(String uri, String tag,
- AntXMLContext context) {
+ public void onEndElement(String uri, String tag, AntXMLContext context) {
}
/**
@@ -410,19 +394,16 @@ public class ProjectHelper2 extends ProjectHelper {
String s = new String(buf, start, count).trim();
if (s.length() > 0) {
- throw new SAXParseException("Unexpected text \"" + s
- + "\"", context.getLocator());
+ throw new SAXParseException("Unexpected text \"" + s + "\"", context.getLocator());
}
}
/**
* Will be called every time a namespace is reached.
- * It'll verify if the ns was processed, and if not load the task
- * definitions.
+ * It'll verify if the ns was processed, and if not load the task definitions.
* @param uri The namespace uri.
*/
protected void checkNamespace(String uri) {
-
}
}
@@ -466,11 +447,9 @@ public class ProjectHelper2 extends ProjectHelper {
* document. Will not be null
.
* @return an inputsource for this identifier
*/
- public InputSource resolveEntity(String publicId,
- String systemId) {
+ public InputSource resolveEntity(String publicId, String systemId) {
- context.getProject().log("resolving systemId: "
- + systemId, Project.MSG_VERBOSE);
+ context.getProject().log("resolving systemId: " + systemId, Project.MSG_VERBOSE);
if (systemId.startsWith("file:")) {
String path = FILE_UTILS.fromURI(systemId);
@@ -481,24 +460,21 @@ public class ProjectHelper2 extends ProjectHelper {
context.getProject().log(
"Warning: '" + systemId + "' in " + context.getBuildFile()
+ " should be expressed simply as '" + path.replace('\\', '/')
- + "' for compliance with other XML tools",
- Project.MSG_WARN);
+ + "' for compliance with other XML tools", Project.MSG_WARN);
}
context.getProject().log("file=" + file, Project.MSG_DEBUG);
try {
- InputSource inputSource =
- new InputSource(new FileInputStream(file));
+ InputSource inputSource = new InputSource(new FileInputStream(file));
inputSource.setSystemId(FILE_UTILS.toURI(file.getAbsolutePath()));
return inputSource;
} catch (FileNotFoundException fne) {
context.getProject().log(file.getAbsolutePath()
- + " could not be found", Project.MSG_WARN);
+ + " could not be found", Project.MSG_WARN);
}
}
// use default if not file or file not found
- context.getProject().log(
- "could not resolve systemId", Project.MSG_DEBUG);
+ context.getProject().log("could not resolve systemId", Project.MSG_DEBUG);
return null;
}
@@ -518,8 +494,7 @@ public class ProjectHelper2 extends ProjectHelper {
*/
public void startElement(String uri, String tag, String qname, Attributes attrs)
throws SAXParseException {
- AntHandler next
- = currentHandler.onStartChild(uri, tag, qname, attrs, context);
+ AntHandler next = currentHandler.onStartChild(uri, tag, qname, attrs, context);
antHandlers.push(currentHandler);
currentHandler = next;
currentHandler.onStartElement(uri, tag, qname, attrs, context);
@@ -537,17 +512,14 @@ public class ProjectHelper2 extends ProjectHelper {
/**
* Handles the end of an element. Any required clean-up is performed
- * by the onEndElement() method and then the original handler
- * is restored to the parser.
+ * by the onEndElement() method and then the original handler is restored to the parser.
*
* @param uri The namespace URI for this element.
* @param name The name of the element which is ending.
* Will not be null
.
* @param qName The qualified name for this element.
*
- * @exception SAXException in case of error (not thrown in
- * this implementation)
- *
+ * @exception SAXException in case of error (not thrown in this implementation)
*/
public void endElement(String uri, String name, String qName) throws SAXException {
currentHandler.onEndElement(uri, name, context);
@@ -566,8 +538,7 @@ public class ProjectHelper2 extends ProjectHelper {
* @param count The number of characters to read.
* @exception SAXParseException if an error occurs
*/
- public void characters(char[] buf, int start, int count)
- throws SAXParseException {
+ public void characters(char[] buf, int start, int count) throws SAXParseException {
currentHandler.characters(buf, start, count, context);
}
@@ -609,28 +580,23 @@ public class ProjectHelper2 extends ProjectHelper {
* @return The project handler that handles subelements of project
* @exception SAXParseException if the qualified name is not "project".
*/
- public AntHandler onStartChild(String uri, String name, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
if (name.equals("project")
&& (uri.equals("") || uri.equals(ANT_CORE_URI))) {
return ProjectHelper2.projectHandler;
- } else {
-// if (context.importlevel > 0) {
-// // we are in an imported file. Allow top-level .
-// if (qname.equals( "target" ) )
-// return ProjectHelper2.targetHandler;
-// }
- if (name.equals(qname)) {
- throw new SAXParseException("Unexpected element \"{" + uri
- + "}" + name + "\" {" + ANT_CORE_URI + "}" + name,
- context.getLocator());
- } else {
- throw new SAXParseException("Unexpected element \"" + qname
- + "\" " + name, context.getLocator());
- }
}
+// if (context.importlevel > 0) {
+// // we are in an imported file. Allow top-level .
+// if (qname.equals( "target" ) )
+// return ProjectHelper2.targetHandler;
+// }
+ if (name.equals(qname)) {
+ throw new SAXParseException("Unexpected element \"{" + uri
+ + "}" + name + "\" {" + ANT_CORE_URI + "}" + name, context.getLocator());
+ }
+ throw new SAXParseException("Unexpected element \"" + qname
+ + "\" " + name, context.getLocator());
}
}
@@ -658,17 +624,14 @@ public class ProjectHelper2 extends ProjectHelper {
* encountered or if the "default"
attribute
* is missing.
*/
- public void onStartElement(String uri, String tag, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public void onStartElement(String uri, String tag, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
String baseDir = null;
boolean nameAttributeSet = false;
Project project = context.getProject();
// Set the location of the implicit target associated with the project tag
- context.getImplicitTarget().setLocation(
- new Location(context.getLocator()));
+ context.getImplicitTarget().setLocation(new Location(context.getLocator()));
/** XXX I really don't like this - the XML processor is still
* too 'involved' in the processing. A better solution (IMO)
@@ -683,9 +646,7 @@ public class ProjectHelper2 extends ProjectHelper {
for (int i = 0; i < attrs.getLength(); i++) {
String attrUri = attrs.getURI(i);
- if (attrUri != null
- && !attrUri.equals("")
- && !attrUri.equals(uri)) {
+ if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
continue; // Ignore attributes from unknown uris
}
String key = attrs.getLocalName(i);
@@ -729,19 +690,16 @@ public class ProjectHelper2 extends ProjectHelper {
String dup = project.getProperty(antFileProp);
if (dup != null && nameAttributeSet) {
File dupFile = new File(dup);
- if (context.isIgnoringProjectTag()
- && !dupFile.equals(context.getBuildFile())) {
+ if (context.isIgnoringProjectTag() && !dupFile.equals(context.getBuildFile())) {
project.log("Duplicated project name in import. Project "
- + context.getCurrentProjectName() + " defined first in "
- + dup + " and again in " + context.getBuildFile(),
- Project.MSG_WARN);
+ + context.getCurrentProjectName() + " defined first in "
+ + dup + " and again in " + context.getBuildFile(), Project.MSG_WARN);
}
}
if (context.getBuildFile() != null && nameAttributeSet) {
- project.setUserProperty("ant.file."
- + context.getCurrentProjectName(),
- context.getBuildFile().toString());
+ project.setUserProperty(MagicNames.ANT_FILE + "."
+ + context.getCurrentProjectName(), context.getBuildFile().toString());
}
if (context.isIgnoringProjectTag()) {
@@ -789,18 +747,11 @@ public class ProjectHelper2 extends ProjectHelper {
* "property"
, "target"
* or a data type definition
*/
- public AntHandler onStartChild(String uri, String name, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
- if (name.equals("target")
- && (uri.equals("") || uri.equals(ANT_CORE_URI))) {
- return ProjectHelper2.targetHandler;
- } else {
- return ProjectHelper2.elementHandler;
- }
+ 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;
}
-
}
/**
@@ -828,10 +779,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException if an unexpected attribute is encountered
* or if the "name"
attribute is missing.
*/
- public void onStartElement(String uri, String tag, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public void onStartElement(String uri, String tag, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
String name = null;
String depends = "";
@@ -843,9 +792,7 @@ public class ProjectHelper2 extends ProjectHelper {
for (int i = 0; i < attrs.getLength(); i++) {
String attrUri = attrs.getURI(i);
- if (attrUri != null
- && !attrUri.equals("")
- && !attrUri.equals(uri)) {
+ if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
continue; // Ignore attributes from unknown uris
}
String key = attrs.getLocalName(i);
@@ -854,8 +801,7 @@ public class ProjectHelper2 extends ProjectHelper {
if (key.equals("name")) {
name = value;
if ("".equals(name)) {
- throw new BuildException("name attribute must "
- + "not be empty");
+ throw new BuildException("name attribute must " + "not be empty");
}
} else if (key.equals("depends")) {
depends = value;
@@ -871,27 +817,26 @@ public class ProjectHelper2 extends ProjectHelper {
target.setDescription(value);
} else {
throw new SAXParseException("Unexpected attribute \""
- + key + "\"", context.getLocator());
+ + key + "\"", context.getLocator());
}
}
if (name == null) {
- throw new SAXParseException("target element appears without "
- + "a name attribute", context.getLocator());
+ throw new SAXParseException("target element appears without a name attribute",
+ context.getLocator());
}
// Check if this target is in the current build file
if (context.getCurrentTargets().get(name) != null) {
- throw new BuildException(
- "Duplicate target '" + name + "'", target.getLocation());
+ throw new BuildException("Duplicate target '" + name + "'", target.getLocation());
}
Hashtable projectTargets = project.getTargets();
boolean usedTarget = false;
// If the name has not already been defined define it
if (projectTargets.containsKey(name)) {
- project.log("Already defined in main or a previous import, "
- + "ignore " + name, Project.MSG_VERBOSE);
+ project.log("Already defined in main or a previous import, ignore "
+ + name, Project.MSG_VERBOSE);
} else {
target.setName(name);
context.getCurrentTargets().put(name, target);
@@ -907,8 +852,7 @@ public class ProjectHelper2 extends ProjectHelper {
&& context.getCurrentProjectName().length() != 0) {
// In an impored file (and not completely
// ignoring the project tag)
- String newName = context.getCurrentProjectName()
- + "." + name;
+ String newName = context.getCurrentProjectName() + "." + name;
Target newTarget = usedTarget ? new Target(target) : target;
newTarget.setName(newName);
context.getCurrentTargets().put(newName, newTarget);
@@ -931,10 +875,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException if an error occurs when initialising
* the appropriate child handler
*/
- public AntHandler onStartChild(String uri, String name, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public AntHandler onStartChild(String uri, String name, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
return ProjectHelper2.elementHandler;
}
@@ -980,10 +922,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException in case of error (not thrown in
* this implementation)
*/
- public void onStartElement(String uri, String tag, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public void onStartElement(String uri, String tag, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
RuntimeConfigurable parentWrapper = context.currentWrapper();
Object parent = null;
@@ -997,13 +937,11 @@ public class ProjectHelper2 extends ProjectHelper {
task.setProject(context.getProject());
task.setNamespace(uri);
task.setQName(qname);
- task.setTaskType(
- ProjectHelper.genComponentName(task.getNamespace(), tag));
+ task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag));
task.setTaskName(qname);
Location location = new Location(context.getLocator().getSystemId(),
- context.getLocator().getLineNumber(),
- context.getLocator().getColumnNumber());
+ context.getLocator().getLineNumber(), context.getLocator().getColumnNumber());
task.setLocation(location);
task.setOwningTarget(context.getCurrentTarget());
@@ -1020,15 +958,12 @@ public class ProjectHelper2 extends ProjectHelper {
// container.addTask(task);
// This is a nop in UE: task.init();
- RuntimeConfigurable wrapper
- = new RuntimeConfigurable(task, task.getTaskName());
+ RuntimeConfigurable wrapper = new RuntimeConfigurable(task, task.getTaskName());
for (int i = 0; i < attrs.getLength(); i++) {
String name = attrs.getLocalName(i);
String attrUri = attrs.getURI(i);
- if (attrUri != null
- && !attrUri.equals("")
- && !attrUri.equals(uri)) {
+ if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
name = attrUri + ":" + attrs.getQName(i);
}
String value = attrs.getValue(i);
@@ -1036,29 +971,26 @@ public class ProjectHelper2 extends ProjectHelper {
// an ant-type is a component name which can
// be namespaced, need to extract the name
// and convert from qualified name to uri/name
- if (ANT_TYPE.equals(name)
- || (ANT_CORE_URI.equals(attrUri)
+ if (ANT_TYPE.equals(name) || (ANT_CORE_URI.equals(attrUri)
&& ANT_TYPE.equals(attrs.getLocalName(i)))) {
name = ANT_TYPE;
int index = value.indexOf(":");
- if (index != -1) {
+ if (index >= 0) {
String prefix = value.substring(0, index);
String mappedUri = context.getPrefixMapping(prefix);
if (mappedUri == null) {
throw new BuildException(
- "Unable to find XML NS prefix " + prefix);
+ "Unable to find XML NS prefix \"" + prefix + "\"");
}
value = ProjectHelper.genComponentName(
- mappedUri, value.substring(index + 1));
+ mappedUri, value.substring(index + 1));
}
}
wrapper.setAttribute(name, value);
}
-
if (parentWrapper != null) {
parentWrapper.addChild(wrapper);
}
-
context.pushWrapper(wrapper);
}
@@ -1076,8 +1008,7 @@ public class ProjectHelper2 extends ProjectHelper {
* @see ProjectHelper#addText(Project,java.lang.Object,char[],int,int)
*/
public void characters(char[] buf, int start, int count,
- AntXMLContext context)
- throws SAXParseException {
+ AntXMLContext context) throws SAXParseException {
RuntimeConfigurable wrapper = context.currentWrapper();
wrapper.addText(buf, start, count);
}
@@ -1099,10 +1030,8 @@ public class ProjectHelper2 extends ProjectHelper {
* @exception SAXParseException if an error occurs when initialising
* the appropriate child handler
*/
- public AntHandler onStartChild(String uri, String tag, String qname,
- Attributes attrs,
- AntXMLContext context)
- throws SAXParseException {
+ public AntHandler onStartChild(String uri, String tag, String qname, Attributes attrs,
+ AntXMLContext context) throws SAXParseException {
return ProjectHelper2.elementHandler;
}
diff --git a/src/main/org/apache/tools/ant/types/Description.java b/src/main/org/apache/tools/ant/types/Description.java
index e7bff9d7b..27f9cea36 100644
--- a/src/main/org/apache/tools/ant/types/Description.java
+++ b/src/main/org/apache/tools/ant/types/Description.java
@@ -15,11 +15,11 @@
* limitations under the License.
*
*/
-
package org.apache.tools.ant.types;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.helper.ProjectHelper2;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.UnknownElement;
import org.apache.tools.ant.Target;
@@ -73,7 +73,7 @@ public class Description extends DataType {
* the targets.
*/
public static String getDescription(Project project) {
- Vector targets = (Vector) project.getReference("ant.targets");
+ Vector targets = (Vector) project.getReference(ProjectHelper2.REFID_TARGETS);
if (targets == null) {
return null;
}