ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional Script.java
Date Sun, 19 Mar 2000 20:27:45 GMT
rubys       00/03/19 12:27:44

  Modified:    src/main/org/apache/tools/ant Project.java
                        ProjectHelper.java
               src/main/org/apache/tools/ant/taskdefs/optional Script.java
  Log:
  Allow names to be used as id references
  
  Revision  Changes    Path
  1.15      +8 -0      jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Project.java	2000/03/19 03:35:47	1.14
  +++ Project.java	2000/03/19 20:27:44	1.15
  @@ -196,6 +196,10 @@
           return properties;
       }
   
  +    public Hashtable getUserProperties() {
  +        return userProperties;
  +    }
  +
       public void setDefaultTarget(String defaultTarget) {
           this.defaultTarget = defaultTarget;
       }
  @@ -351,6 +355,10 @@
           log(msg, MSG_VERBOSE);
           target.setProject(this);
           targets.put(targetName, target);
  +    }
  +
  +    public Hashtable getTargets() {
  +        return targets;
       }
   
       public Task createTask(String taskType) throws BuildException {
  
  
  
  1.9       +7 -1      jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProjectHelper.java	2000/03/19 03:35:47	1.8
  +++ ProjectHelper.java	2000/03/19 20:27:44	1.9
  @@ -102,8 +102,14 @@
               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) {
  
  
  
  1.2       +27 -15    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
  
  Index: Script.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Script.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Script.java	2000/03/19 03:35:48	1.1
  +++ Script.java	2000/03/19 20:27:44	1.2
  @@ -67,31 +67,43 @@
   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());
   
  -            // add properties (<property name="foo">)
  -            Hashtable properties = project.getProperties();
  -            for (Enumeration e = properties.keys() ; e.hasMoreElements() ;) {
  +            BSFManager manager = new BSFManager ();
  +
  +            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
  
  
  

Mime
View raw message