Browse Source

Allow names to be used as id references

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267638 13f79535-47bb-0310-9956-ffa450edef68
master
Sam Ruby 25 years ago
parent
commit
945b6d36d1
3 changed files with 42 additions and 16 deletions
  1. +8
    -0
      src/main/org/apache/tools/ant/Project.java
  2. +7
    -1
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +27
    -15
      src/main/org/apache/tools/ant/taskdefs/optional/Script.java

+ 8
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -196,6 +196,10 @@ public class Project {
return properties;
}

public Hashtable getUserProperties() {
return userProperties;
}

public void setDefaultTarget(String defaultTarget) {
this.defaultTarget = defaultTarget;
}
@@ -353,6 +357,10 @@ public class Project {
targets.put(targetName, target);
}

public Hashtable getTargets() {
return targets;
}

public Task createTask(String taskType) throws BuildException {
Class c = (Class) taskClassDefinitions.get(taskType);



+ 7
- 1
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -102,9 +102,15 @@ public class ProjectHelper {
throw new BuildException(msg);
}

project.setName(root.getAttribute("name"));
project.setDefaultTarget(root.getAttribute("default"));

String name = root.getAttribute("name");
project.setName(name);
if (name != null) project.addReference(name, project);

String id = root.getAttribute("id");
if (id != null) project.addReference(id, project);

String baseDir = project.getProperty("basedir");
if (baseDir == null) {
baseDir = root.getAttribute("basedir");


+ 27
- 15
src/main/org/apache/tools/ant/taskdefs/optional/Script.java View File

@@ -67,31 +67,43 @@ import com.ibm.bsf.*;
public class Script extends Task {
private String language;
private String script = "";
private Hashtable beans = new Hashtable();
/**
* Add a list of named objects to the list to be exported to the script
*/
private void addBeans(Hashtable dictionary) {
for (Enumeration e=dictionary.keys(); e.hasMoreElements(); ) {
String key = (String)e.nextElement();

boolean isValid = key.length()>0 &&
Character.isJavaIdentifierStart(key.charAt(0));

for (int i=1; isValid && i<key.length(); i++)
isValid = Character.isJavaIdentifierPart(key.charAt(i));

if (isValid) beans.put(key, dictionary.get(key));
}
}

/**
* Do the work.
*
* @exception BuildException if someting goes wrong with the build
*/
public void execute() throws BuildException {
BSFManager manager = new BSFManager ();
try {
// add id references (<task id="foo">)
Hashtable references = project.getReferences();
for (Enumeration e = references.keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement();
Object value = references.get(key);
manager.declareBean(key, value, value.getClass());
}
addBeans(project.getProperties());
addBeans(project.getUserProperties());
addBeans(project.getTargets());
addBeans(project.getReferences());

BSFManager manager = new BSFManager ();

// add properties (<property name="foo">)
Hashtable properties = project.getProperties();
for (Enumeration e = properties.keys() ; e.hasMoreElements() ;) {
for (Enumeration e = beans.keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement();
if (!references.contains(key)) {
Object value = properties.get(key);
manager.declareBean(key, value, value.getClass());
}
Object value = beans.get(key);
manager.declareBean(key, value, value.getClass());
}

// execute the script


Loading…
Cancel
Save