aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@aura-online.co.uk>2008-06-17 10:02:00 +0000
committerJames Le Cuirot <chewi@aura-online.co.uk>2008-06-17 10:02:00 +0000
commit52b86cb78ede56219fad957b9474ffa56d6a7b2c (patch)
treeef44b19e1d1cd08c641ab5f7e27281d2d40a99ba
parentThese tabs got left behind. (diff)
downloadjavatoolkit-52b86cb78ede56219fad957b9474ffa56d6a7b2c.tar.gz
javatoolkit-52b86cb78ede56219fad957b9474ffa56d6a7b2c.tar.bz2
javatoolkit-52b86cb78ede56219fad957b9474ffa56d6a7b2c.zip
New approach to rewriting the classpath. The previous one didn't work very well.
svn path=/projects/javatoolkit/trunk/; revision=6322
-rw-r--r--src/py/javatoolkit/xml/DomRewriter.py70
1 files changed, 17 insertions, 53 deletions
diff --git a/src/py/javatoolkit/xml/DomRewriter.py b/src/py/javatoolkit/xml/DomRewriter.py
index 92844b9..e6ac33d 100644
--- a/src/py/javatoolkit/xml/DomRewriter.py
+++ b/src/py/javatoolkit/xml/DomRewriter.py
@@ -50,59 +50,23 @@ class DomRewriter:
def add_gentoo_classpath(self,document,**kwargs):
- newcp = kwargs.has_key('classpath') and kwargs['classpath'] or "void"
- newcp = newcp.split(":")
- gcp = document.createElement("path")
- for cp in newcp:
- pe = document.createElement("pathelement")
- pe.setAttribute("path",cp)
- gcp.appendChild(pe)
-
-
- # classpath nodes:
- # if no refud:
- # remove inner elems
- # add our gentoo classpath node
- # else
- # rename refid references
- matches = document.getElementsByTagName("classpath")
- handled_refs = set()
- for match in matches:
- if not match.hasAttribute("refid"):
- for node in match.childNodes[:]:
- match.removeChild(node)
- node.unlink()
-
- match.appendChild(gcp.cloneNode(True))
- else:
- refid = match.getAttribute("refid")
- for ref in document.getElementsByTagName("path"):
- id = ref.getAttribute("id")
- if id not in handled_refs and id == refid:
- for node in ref.childNodes[:]:
- ref.removeChild(node)
- node.unlink()
-
- for pathnode in (gcp.cloneNode(deep=True)).childNodes:
- ref.appendChild(pathnode.cloneNode(deep=True))
-
- handled_refs.add(id)
-
- # rewrite javac elements
- matches = document.getElementsByTagName("javac")
- for match in matches:
- classpath = match.getAttribute("classpath")
- if classpath:
- match.removeAttribute("classpath")
-
- for node in match.childNodes[:]:
- if node.nodeName == "classpath":
- match.removeChild(node)
- node.unlink()
-
- classpath = document.createElement("classpath")
- classpath.appendChild(gcp.cloneNode(True))
- match.appendChild(classpath)
+ if not kwargs.has_key('classpath') or not kwargs['classpath']:
+ return
+
+ cp = document.createElement("classpath")
+ cp.setAttribute("path", kwargs['classpath'])
+ last_parent = None
+
+ # Add our classpath element to every node already containing a classpath element.
+ for match in document.getElementsByTagName("classpath"):
+ if last_parent != match.parentNode:
+ match.parentNode.appendChild(cp.cloneNode(True))
+ last_parent = match.parentNode
+
+ # Add our classpath element to every javac node we missed earlier.
+ for match in document.getElementsByTagName("javac"):
+ if not match.getElementsByTagName("classpath"):
+ match.appendChild(cp.cloneNode(True))
def process(self,in_stream,callback=None,*args,**kwargs):