#!/usr/bin/python2.7
#
# Copyright 2008 James Le Cuirot <chewi@aura-online.co.uk>
# Copyright 2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
#
# $Header: $

import sys
import xml.etree.cElementTree as et

args = sys.argv[1:]
if len(args) == 0:
    args = [ 'build.xml' ]

for file in args:
    tree = et.ElementTree(file=file)
    tags = []

    for elem in tree.getiterator():
        for child in list(elem):
            if child.tag == 'taskdef' and child.get('classname') == 'com.tonicsystems.jarjar.JarJarTask':
                tags.append(child.get('name'))
                elem.remove(child)

    for tag in tags:
        for jarjar in tree.getiterator(tag):
            if jarjar.get('destfile') or jarjar.get('jarfile'):
                jarjar.tag = 'jar'

                if jarjar.get('verbose'):
                    del jarjar.attrib['verbose']

                for child in list(jarjar):
                    if child.tag == 'keep' or child.tag == 'rule' or child.tag == 'zipfileset':
                        jarjar.remove(child)

    f = open(file, 'w')
    tree.write(f)
    f.close()

#set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
