Browse Source

rolling back Josh's changes until he provides a better patch. :-)

-jon


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268478 13f79535-47bb-0310-9956-ffa450edef68
master
Jon Scott Stevens 24 years ago
parent
commit
adbdf5d6c8
3 changed files with 43 additions and 102 deletions
  1. +2
    -7
      src/main/org/apache/tools/ant/Project.java
  2. +41
    -85
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +0
    -10
      src/main/org/apache/tools/ant/Target.java

+ 2
- 7
src/main/org/apache/tools/ant/Project.java View File

@@ -90,8 +90,8 @@ public class Project {
public static final String JAVA_1_2 = "1.2"; public static final String JAVA_1_2 = "1.2";
public static final String JAVA_1_3 = "1.3"; public static final String JAVA_1_3 = "1.3";


private String TOKEN_START;
private String TOKEN_END;
public static final String TOKEN_START = "@";
public static final String TOKEN_END = "@";


private String name; private String name;


@@ -1028,11 +1028,6 @@ public class Project {
return references; return references;
} }


public void setToken(String token) {
TOKEN_START=token;
TOKEN_END=token;
}

protected void fireBuildStarted() { protected void fireBuildStarted() {
BuildEvent event = new BuildEvent(this); BuildEvent event = new BuildEvent(this);
for (int i = 0; i < listeners.size(); i++) { for (int i = 0; i < listeners.size(); i++) {


+ 41
- 85
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -81,8 +81,7 @@ public class ProjectHelper {
/** /**
* Configures the Project with the contents of the specified XML file. * Configures the Project with the contents of the specified XML file.
*/ */
public static void configureProject(Project project, File buildFile)
throws BuildException {
public static void configureProject(Project project, File buildFile) throws BuildException {
new ProjectHelper(project, buildFile).parse(); new ProjectHelper(project, buildFile).parse();
} }


@@ -109,13 +108,11 @@ public class ProjectHelper {
saxParser.parse(inputStream, new RootHandler()); saxParser.parse(inputStream, new RootHandler());
} }
catch(ParserConfigurationException exc) { catch(ParserConfigurationException exc) {
throw new BuildException("Parser has not been configured " +
"correctly", exc);
throw new BuildException("Parser has not been configured correctly", exc);
} }
catch(SAXParseException exc) { catch(SAXParseException exc) {
Location location = Location location =
new Location(buildFile.toString(), exc.getLineNumber(),
exc.getColumnNumber());
new Location(buildFile.toString(), exc.getLineNumber(), exc.getColumnNumber());


Throwable t = exc.getException(); Throwable t = exc.getException();
if (t instanceof BuildException) { if (t instanceof BuildException) {
@@ -175,19 +172,15 @@ public class ProjectHelper {
parser.setDocumentHandler(this); parser.setDocumentHandler(this);
} }


public void startElement(String tag, AttributeList attrs)
throws SAXParseException {
throw new SAXParseException("Unexpected element \"" + tag + "\"",
locator);
public void startElement(String tag, AttributeList attrs) throws SAXParseException {
throw new SAXParseException("Unexpected element \"" + tag + "\"", locator);
} }


public void characters(char[] buf, int start, int end)
throws SAXParseException {
public void characters(char[] buf, int start, int end) throws SAXParseException {
String s = new String(buf, start, end).trim(); String s = new String(buf, start, end).trim();


if (s.length() > 0) { if (s.length() > 0) {
throw new SAXParseException("Unexpected text \"" + s + "\"",
locator);
throw new SAXParseException("Unexpected text \"" + s + "\"", locator);
} }
} }


@@ -206,8 +199,7 @@ public class ProjectHelper {
} }


/** /**
* Handler for the root element. It's only child must be the "project"
* element.
* Handler for the root element. It's only child must be the "project" element.
*/ */
private class RootHandler extends HandlerBase { private class RootHandler extends HandlerBase {


@@ -235,13 +227,11 @@ public class ProjectHelper {
return null; return null;
} }


public void startElement(String tag, AttributeList attrs)
throws SAXParseException {
public void startElement(String tag, AttributeList attrs) throws SAXParseException {
if (tag.equals("project")) { if (tag.equals("project")) {
new ProjectHandler(this).init(tag, attrs); new ProjectHandler(this).init(tag, attrs);
} else { } else {
throw new SAXParseException("Config file is not of " +
"expected XML type", locator);
throw new SAXParseException("Config file is not of expected XML type", locator);
} }
} }


@@ -258,8 +248,7 @@ public class ProjectHelper {
super(parentHandler); super(parentHandler);
} }


public void init(String tag, AttributeList attrs)
throws SAXParseException {
public void init(String tag, AttributeList attrs) throws SAXParseException {
String def = null; String def = null;
String name = null; String name = null;
String id = null; String id = null;
@@ -278,15 +267,15 @@ public class ProjectHelper {
} else if (key.equals("basedir")) { } else if (key.equals("basedir")) {
baseDir = value; baseDir = value;
} else { } else {
throw new SAXParseException("Unexpected attribute \"" +
attrs.getName(i) + "\"", locator);
throw new SAXParseException("Unexpected attribute \"" + attrs.getName(i) + "\"", locator);
} }
} }


if (def == null) { if (def == null) {
throw new SAXParseException("The default attribute of " +
"project is required", locator);
throw new SAXParseException("The default attribute of project is required",
locator);
} }


project.setDefaultTarget(def); project.setDefaultTarget(def);


@@ -307,17 +296,14 @@ public class ProjectHelper {
if ((new File(baseDir)).isAbsolute()) { if ((new File(baseDir)).isAbsolute()) {
project.setBasedir(baseDir); project.setBasedir(baseDir);
} else { } else {
project.setBasedir((
new File(buildFileParent, baseDir))
.getAbsolutePath());
project.setBasedir((new File(buildFileParent, baseDir)).getAbsolutePath());
} }
} }
} }


} }


public void startElement(String name, AttributeList attrs)
throws SAXParseException {
public void startElement(String name, AttributeList attrs) throws SAXParseException {
if (name.equals("taskdef")) { if (name.equals("taskdef")) {
handleTaskdef(name, attrs); handleTaskdef(name, attrs);
} else if (name.equals("property")) { } else if (name.equals("property")) {
@@ -327,28 +313,23 @@ public class ProjectHelper {
} else if (project.getDataTypeDefinitions().get(name) != null) { } else if (project.getDataTypeDefinitions().get(name) != null) {
handleDataType(name, attrs); handleDataType(name, attrs);
} else { } else {
throw new SAXParseException("Unexpected element \"" + name +
"\"", locator);
throw new SAXParseException("Unexpected element \"" + name + "\"", locator);
} }
} }


private void handleTaskdef(String name, AttributeList attrs)
throws SAXParseException {
private void handleTaskdef(String name, AttributeList attrs) throws SAXParseException {
(new TaskHandler(this, null)).init(name, attrs); (new TaskHandler(this, null)).init(name, attrs);
} }


private void handleProperty(String name, AttributeList attrs)
throws SAXParseException {
private void handleProperty(String name, AttributeList attrs) throws SAXParseException {
(new TaskHandler(this, null)).init(name, attrs); (new TaskHandler(this, null)).init(name, attrs);
} }


private void handleTarget(String tag, AttributeList attrs)
throws SAXParseException {
private void handleTarget(String tag, AttributeList attrs) throws SAXParseException {
new TargetHandler(this).init(tag, attrs); new TargetHandler(this).init(tag, attrs);
} }


private void handleDataType(String name, AttributeList attrs)
throws SAXParseException {
private void handleDataType(String name, AttributeList attrs) throws SAXParseException {
new DataTypeHandler(this).init(name, attrs); new DataTypeHandler(this).init(name, attrs);
} }


@@ -364,15 +345,13 @@ public class ProjectHelper {
super(parentHandler); super(parentHandler);
} }


public void init(String tag, AttributeList attrs)
throws SAXParseException {
public void init(String tag, AttributeList attrs) throws SAXParseException {
String name = null; String name = null;
String depends = ""; String depends = "";
String ifCond = null; String ifCond = null;
String unlessCond = null; String unlessCond = null;
String id = null; String id = null;
String description = null; String description = null;
String token = null;


for (int i = 0; i < attrs.getLength(); i++) { for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getName(i); String key = attrs.getName(i);
@@ -390,17 +369,13 @@ public class ProjectHelper {
id = value; id = value;
} else if (key.equals("description")) { } else if (key.equals("description")) {
description = value; description = value;
} else if (key.equals("token")) {
token = value;
} else { } else {
throw new SAXParseException("Unexpected attribute \"" +
key + "\"", locator);
throw new SAXParseException("Unexpected attribute \"" + key + "\"", locator);
} }
} }


if (name == null) { if (name == null) {
throw new SAXParseException("target element appears without " +
"a name attribute", locator);
throw new SAXParseException("target element appears without a name attribute", locator);
} }


target = new Target(); target = new Target();
@@ -408,11 +383,6 @@ public class ProjectHelper {
target.setIf(ifCond); target.setIf(ifCond);
target.setUnless(unlessCond); target.setUnless(unlessCond);
target.setDescription(description); target.setDescription(description);
if (token == null) {
target.setToken("@");
}
else
target.setToken(token);
project.addTarget(name, target); project.addTarget(name, target);


if (id != null && !id.equals("")) if (id != null && !id.equals(""))
@@ -429,8 +399,7 @@ public class ProjectHelper {
} }
} }


public void startElement(String name, AttributeList attrs)
throws SAXParseException {
public void startElement(String name, AttributeList attrs) throws SAXParseException {
new TaskHandler(this, target).init(name, attrs); new TaskHandler(this, target).init(name, attrs);
} }
} }
@@ -449,8 +418,7 @@ public class ProjectHelper {
this.target = target; this.target = target;
} }


public void init(String tag, AttributeList attrs)
throws SAXParseException {
public void init(String tag, AttributeList attrs) throws SAXParseException {
try { try {
task = project.createTask(tag); task = project.createTask(tag);
} catch (BuildException e) { } catch (BuildException e) {
@@ -463,8 +431,7 @@ public class ProjectHelper {
task.setProject(project); task.setProject(project);
} }


task.setLocation(new Location(buildFile.toString(),
locator.getLineNumber(), locator.getColumnNumber()));
task.setLocation(new Location(buildFile.toString(), locator.getLineNumber(), locator.getColumnNumber()));
configureId(task, attrs); configureId(task, attrs);


// Top level tasks don't have associated targets // Top level tasks don't have associated targets
@@ -486,8 +453,7 @@ public class ProjectHelper {
} }
} }


public void characters(char[] buf, int start, int end)
throws SAXParseException {
public void characters(char[] buf, int start, int end) throws SAXParseException {
if (wrapper == null) { if (wrapper == null) {
try { try {
addText(task, buf, start, end); addText(task, buf, start, end);
@@ -499,8 +465,7 @@ public class ProjectHelper {
} }
} }


public void startElement(String name, AttributeList attrs)
throws SAXParseException {
public void startElement(String name, AttributeList attrs) throws SAXParseException {
new NestedElementHandler(this, task, wrapper).init(name, attrs); new NestedElementHandler(this, task, wrapper).init(name, attrs);
} }
} }
@@ -527,8 +492,7 @@ public class ProjectHelper {
this.parentWrapper = parentWrapper; this.parentWrapper = parentWrapper;
} }


public void init(String propType, AttributeList attrs)
throws SAXParseException {
public void init(String propType, AttributeList attrs) throws SAXParseException {
Class targetClass = target.getClass(); Class targetClass = target.getClass();
IntrospectionHelper ih = IntrospectionHelper ih =
IntrospectionHelper.getHelper(targetClass); IntrospectionHelper.getHelper(targetClass);
@@ -555,8 +519,7 @@ public class ProjectHelper {
} }
} }


public void characters(char[] buf, int start, int end)
throws SAXParseException {
public void characters(char[] buf, int start, int end) throws SAXParseException {
if (parentWrapper == null) { if (parentWrapper == null) {
try { try {
addText(child, buf, start, end); addText(child, buf, start, end);
@@ -568,10 +531,8 @@ public class ProjectHelper {
} }
} }


public void startElement(String name, AttributeList attrs)
throws SAXParseException {
new NestedElementHandler(this, child, childWrapper)
.init(name, attrs);
public void startElement(String name, AttributeList attrs) throws SAXParseException {
new NestedElementHandler(this, child, childWrapper).init(name, attrs);
} }
} }


@@ -585,8 +546,7 @@ public class ProjectHelper {
super(parentHandler); super(parentHandler);
} }


public void init(String propType, AttributeList attrs)
throws SAXParseException {
public void init(String propType, AttributeList attrs) throws SAXParseException {
try { try {
element = project.createDataType(propType); element = project.createDataType(propType);
if (element == null) { if (element == null) {
@@ -600,8 +560,7 @@ public class ProjectHelper {
} }
} }


public void characters(char[] buf, int start, int end)
throws SAXParseException {
public void characters(char[] buf, int start, int end) throws SAXParseException {
try { try {
addText(element, buf, start, end); addText(element, buf, start, end);
} catch (BuildException exc) { } catch (BuildException exc) {
@@ -609,8 +568,7 @@ public class ProjectHelper {
} }
} }


public void startElement(String name, AttributeList attrs)
throws SAXParseException {
public void startElement(String name, AttributeList attrs) throws SAXParseException {
new NestedElementHandler(this, element, null).init(name, attrs); new NestedElementHandler(this, element, null).init(name, attrs);
} }
} }
@@ -667,8 +625,7 @@ public class ProjectHelper {


/** Replace ${NAME} with the property value /** Replace ${NAME} with the property value
*/ */
public static String replaceProperties(Project project, String value,
Hashtable keys )
public static String replaceProperties(Project project, String value, Hashtable keys )
throws BuildException throws BuildException
{ {
// XXX use Map instead of proj, it's too heavy // XXX use Map instead of proj, it's too heavy
@@ -698,12 +655,10 @@ public class ProjectHelper {
} }
String n=value.substring( pos+2, endName ); String n=value.substring( pos+2, endName );
if (!keys.containsKey(n)) { if (!keys.containsKey(n)) {
project.log("Property ${" + n + "} has not been set",
Project.MSG_VERBOSE);
project.log("Property ${" + n + "} has not been set", Project.MSG_VERBOSE);
} }
String v = (keys.containsKey(n)) ?
(String) keys.get(n) : "${"+n+"}";
String v = (keys.containsKey(n)) ? (String) keys.get(n) : "${"+n+"}";
//System.out.println("N: " + n + " " + " V:" + v); //System.out.println("N: " + n + " " + " V:" + v);
sb.append( v ); sb.append( v );
@@ -737,4 +692,5 @@ public class ProjectHelper {
project.addReference(id, target); project.addReference(id, target);
} }
} }

} }

+ 0
- 10
src/main/org/apache/tools/ant/Target.java View File

@@ -71,7 +71,6 @@ public class Target {
private Vector tasks = new Vector(5); private Vector tasks = new Vector(5);
private Project project; private Project project;
private String description = null; private String description = null;
private String token = null;


public void setProject(Project project) { public void setProject(Project project) {
this.project = project; this.project = project;
@@ -81,14 +80,6 @@ public class Target {
return project; return project;
} }


public void setToken(String token) {
this.token = token;
}

public String getToken() {
return token;
}

public void setDepends(String depS) { public void setDepends(String depS) {
if (depS.length() > 0) { if (depS.length() > 0) {
StringTokenizer tok = StringTokenizer tok =
@@ -152,7 +143,6 @@ public class Target {


public void execute() throws BuildException { public void execute() throws BuildException {
if (testIfCondition() && testUnlessCondition()) { if (testIfCondition() && testUnlessCondition()) {
project.setToken(token);
Enumeration enum = tasks.elements(); Enumeration enum = tasks.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Task task = (Task) enum.nextElement(); Task task = (Task) enum.nextElement();


Loading…
Cancel
Save