view fix-ivy.groovy @ 86:da29f9bde0da

groovy script to 'fix' ivy scripts to use standard conventions for configurations
author smith@nwoca.org
date Tue, 14 Feb 2012 15:41:45 -0500
parents
children 9f2ab59a5333
line wrap: on
line source
import groovy.xml.*

def xml = new XmlSlurper()
def ivy = xml.parse( new File('ivy.xml'))

def cfgs =  ivy.configurations

if (cfgs.@defaultconfmapping.size() == 0) {
    println "adding defaultconfmapping"
    cfgs.@defaultconfmapping = '*->default'
}

if (!cfgs.children().find { it.@name == 'default' } ) {
    println "adding default config"
    cfgs.appendNode {
        conf(name:"default")
    }
}

groovy = ivy.dependencies.children().find { it.@org == 'org.codehaus.groovy' && it.@name == 'groovy' }
if (groovy) {
    groovy.@conf = "*->default,optional"
    println "Groovy ${groovy.@rev} conf changed to ${groovy.@conf}"    
}

def sameConfMappings = ivy.dependencies.children().findAll { it.@conf in ['*->@','*->*'] }

println sameConfMappings.each { 
    it.@conf = "default->compile;%->@"
    println "changing conf for ${it.@name} to ${it.@conf}" 
}


def outputBuilder = new StreamingMarkupBuilder()
new File('ivy.xml').write(  XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy }).replaceAll('>','>'))