aboutsummaryrefslogtreecommitdiff
blob: f839615ac752d6f4e2141857fec72ea8c9cedf8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3

import sys, os
import xml.etree.cElementTree as et
from optparse import OptionParser


def main():
    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:
        if os.path.getsize(file) == 0 : continue
        tree = et.ElementTree(file=file)
        if gcp or options.encoding:
            for javac in tree.getiterator('javac'):
                if gcp:
                    javac.attrib['classpath'] = gcp_str
                if options.encoding:
                    javac.attrib['encoding'] = options.encoding
                for javadoc in tree.getiterator('javadoc'):
                    if gcp:
                        javadoc.attrib['classpath'] = gcp_str
                        if options.encoding:
                            javadoc.attrib['encoding'] = options.encoding
        for c in changes:
            elems, attr, value = c
            for elem in elems:
                for e in tree.getiterator(elem):
                    e.attrib[attr] = value
        for junit in tree.getiterator('junit'):
            if gcp:
                junit.append(gcp_sub)
                junit.attrib['haltonfailure'] = 'true'

        with open(file, 'wb') as f:
            tree.write(f)


if __name__ == '__main__':
    main()