diff options
author | Petteri Räty <betelgeuse@gentoo.org> | 2008-03-25 19:29:44 +0000 |
---|---|---|
committer | Petteri Räty <betelgeuse@gentoo.org> | 2008-03-25 19:29:44 +0000 |
commit | 3efd4816de4fea8003c33a94f1d199579b3ff492 (patch) | |
tree | 23b10109db8e5e2c6c4491bfd8c6cfd3fe2aac60 | |
parent | Reversing refactor of maven-helper. Work now to be done in branch. (diff) | |
download | javatoolkit-3efd4816de4fea8003c33a94f1d199579b3ff492.tar.gz javatoolkit-3efd4816de4fea8003c33a94f1d199579b3ff492.tar.bz2 javatoolkit-3efd4816de4fea8003c33a94f1d199579b3ff492.zip |
Add a cElementTree based build.xml rewriter.
svn path=/projects/javatoolkit/trunk/; revision=6093
-rwxr-xr-x | src/bsfix/build-xml-rewrite | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/bsfix/build-xml-rewrite b/src/bsfix/build-xml-rewrite new file mode 100755 index 0000000..4d78b48 --- /dev/null +++ b/src/bsfix/build-xml-rewrite @@ -0,0 +1,41 @@ +#!/usr/bin/python + +import sys +import xml.etree.cElementTree as et +from optparse import OptionParser + +parser = OptionParser() +parser.add_option('-c', '--changeattributes', dest='change', action="append", nargs=3) +parser.add_option('-g', '--gentooclasspath', dest="gcp", action="store_true", default=False) +parser.add_option('-e', '--encoding', dest="encoding") +(options, args) = parser.parse_args() + +changes = [] +if options.change: + for c in options.change: + changes.append((c[0].split(),c[1], c[2])) + +gcp = options.gcp +gcp_str = '${gentoo.classpath}' +gcp_sub = et.Element('classpath', path=gcp_str) + +for file in args: + tree = et.ElementTree(file=file) + for elem in tree.getiterator(): + for c in changes: + elems, attr, value = c + if elem.tag in elems: + elem.attrib[attr] = value + if elem.tag == 'javac': + if gcp: + elem.attrib['classpath'] = gcp_str + if options.encoding: + elem.attrib['encoding'] = options.encoding + if elem.tag == 'junit': + if gcp: + elem.append(gcp_sub) + elem.attrib['haltonfailure'] = 'true' + + f = open(file, 'w') + tree.write(f) + f.close() |