def ns1 = new groovy.xml.Namespace("http://www.netbeans.org/ns/project/1") def ns2 = new groovy.xml.Namespace("http://www.netbeans.org/ns/nb-module-project/2") def ns3 = new groovy.xml.Namespace("http://www.netbeans.org/ns/nb-module-project/3") def command = ['/space/hg/cloc-1.06.pl', '--no3', '-xml'] def HGROOT = new File(args[0]) def OUTDIR = new File(args[1]) OUTDIR.mkdirs() println "args " + args int n2 = 0 int n3 = 0 HGROOT.listFiles().sort().each { file -> File xml = new File(file, "nbproject/project.xml") if (xml?.exists()) { println "processing ${file.name} ..." //add common source root if (new File(file, "src")?.exists()) { command << new File(file, "src") } //add extra source roots def pxml = new XmlParser().parse(xml)[ns1.configuration] findPackageRoots(pxml, ns2).each() { def f = new File(file, it) if (f?.exists()) { command << f println f } } findPackageRoots(pxml, ns3).each { def f = new File(file, it) if (f?.exists()) { command << f println f } } /* def p = (command + "").execute() Writer w1 = new BufferedWritter(new FWriter(new File(OUTDIR, file.name + ".xml").newWriter())) p.in.eachLine { w1 << it } w1.close() */ } } println "ns2: " + n2 println "ns3: " + n3 def findPackageRoots(element, namespace) { if (ns2.eqauls(namespace)) { n2++ } else { n3++ } List roots = [] element[namespace.data][namespace.'extra-compilation-unit']?.each { roots << it[namespace.'package-root'].text() } roots } class FWriter extends FilterWriter { private String txt; private String unique; private String ignored; private boolean written = false; public FWriter(BufferedWriter w) { super(w); } public void write(String str, int off, int len) { if (!written && str.contains("results")) { String s = ""; out.write(s, off, s.length()); out.newLine(); written = true; return; } if (str.contains("<")) { out.write(str, off, len); out.newLine(); return; } if (str.contains("text files")) { String x = str.trim(); txt = x.substring(0, x.length() - 11).trim(); return } else if (str.contains("unique files")) { String x = str.trim(); unique = x.substring(0, x.length() - 13).trim(); return; } else if (str.contains("files ignored")) { String x = str.trim(); ignored = x.substring(0, x.length() - 14).trim(); } } }