At 2:12 AM +0200 10/24/00, Nico Seessle wrote:
>It's a quick hack for now and can not do any error-checking regarding
>reqquired arguments and so on, but it works :-)
>
>Task included. I may improve it further, but don't know when. If you find
>some time to improve it feel free to do so :-)
I had to make the following change to Script.java to be able to compile your
code. Should we add this to the tree?
Index: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Script.java,v
retrieving revision 1.3
diff -c -2 -r1.3 Script.java
*** jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
2000/10/12 13:38:15 1.3
--- jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
2000/10/24 00:54:25
***************
*** 70,73 ****
--- 70,85 ----
private Hashtable beans = new Hashtable();
+ private boolean isValidIdentifier(String name) {
+ int length = name.length();
+ if (length > 0 && Character.isJavaIdentifierStart(name.charAt(0))) {
+ for (int i = length - 1; i > 0; --i) {
+ if (!Character.isJavaIdentifierPart(name.charAt(i)))
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
/**
* Add a list of named objects to the list to be exported to the script
***************
*** 76,88 ****
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));
}
}
--- 88,100 ----
for (Enumeration e=dictionary.keys(); e.hasMoreElements(); ) {
String key = (String)e.nextElement();
! if (isValidIdentifier(key)) beans.put(key, dictionary.get(key));
}
+ }
+
+ /**
+ * Add a single named object to the list to be exported to the script.
+ */
+ public void addBean(String name, Object value) {
+ if (isValidIdentifier(name)) beans.put(name, value);
}
--
// Patrick C. Beard
// Java Runtime Enthusiast -- "Will invoke interfaces for food."
// mailto:[EMAIL PROTECTED]