changeset 90:c207cdcaf13e

latest version
author smith@nwoca.org
date Tue, 21 Feb 2012 14:50:19 +0000
parents 15f4da8bdbd3
children b72ba5cb5c53
files fixivy.groovy
diffstat 1 files changed, 82 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/fixivy.groovy	Fri Feb 17 15:09:35 2012 +0000
+++ b/fixivy.groovy	Tue Feb 21 14:50:19 2012 +0000
@@ -1,3 +1,12 @@
+/*
+
+  This script is (was) used for 'fixing' early SSDT ivy.xml files created by NetBeans/ivyBeans.
+  It's primary goal is to migrate configurations from NetBeans conventions to Maven/Gradle conventions.
+  In order to accomplish this, it needs to correct dependencies, excludes and configurations.  However,
+  it's not able to perfectly correct every ssdt project. Some parts of this script may be commented 
+  out.  Results of this script much be reviewed carefully before committing.
+*/
+
 
 import groovy.xml.QName;
 import org.codehaus.groovy.runtime.InvokerHelper;
@@ -11,7 +20,7 @@
 import groovy.xml.*
 
 //args = [ '-r']
-println args
+//println args
 
 ant = new AntBuilder()
 
@@ -61,11 +70,24 @@
            dep.@conf = 'compile-test->default(*)' 
        } else if ( dep.@conf.text().contains('castor-ant') ) {
             dep.@conf = 'castor-ant->default(*)'
-       }
-       else {
+       } else if (dep.@conf.text() == 'runtime->default' ) {
+        // preserve
+       } else{
            dep.attributes().remove('conf')
        }
     }
+
+//    ensure(ivy.dependencies,["org.spockframework:spock-core:0.5-groovy-1.8"])
+
+//    ensure(ivy.dependencies, 'hibernate-validator', ['org.slf4j:slf4j-api:1.5.6','org.slf4j:slf4j-log4j12:1.5.6'])
+//    ensure(ivy.dependencies, 'usas.repository', ["org.springframework:org.springframework.test:3.0.5.RELEASE","org.codehaus.groovy:groovy-all:1.8.2"])    
+//    ensure(ivy.dependencies, 'usps.repository', ["org.springframework:org.springframework.test:3.0.5.RELEASE","org.codehaus.groovy:groovy-all:1.8.2"])    
+    
+       
+//    ensure(ivy.dependencies, 'spock-core', ["org.springframework:org.springframework.test:3.0.5.RELEASE"])
+//    ensure(ivy.dependencies, 'org.springframework.test', ['org.junit:com.springsource.org.junit:4.9.0'])
+//    ensure(ivy.dependencies, 'org.springframework.test', ["org.spockframework:spock-spring:0.5-groovy-1.8"])
+
     
     // find groovy dependencies (or null)
     groovy = ivy.dependencies.children().find { it.@org == 'org.codehaus.groovy' && it.@name.text().startsWith('groovy') }
@@ -97,32 +119,41 @@
         
     }
     
-    
-    ensure(ivy.dependencies, 'hibernate-validator', ['org.slf4j:slf4j-api:1.5.6','org.slf4j:slf4j-log4j12:1.5.6'])
-    
-    ensure(ivy.dependencies, 'org.springframework.test', ['junit:junit:4.8.2'])
+//    resolveJunit(ivy.dependencies)
     
     // remove exclude for groovy-all
     ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'groovy-all' }.replaceNode {}
+    // remove exclude for commons logging
+    ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() ==  'com.springsource.org.apache.commons.logging' }.replaceNode {}
    
    // Add exclude for regular groovy:
     ensureExcluded(ivy.dependencies,"org.codehaus.groovy:groovy")
     
     // ensure modules covered by springsource are exluded;
-    ensureSpringSourceExcludes(ivy.dependencies)
-    
-    ensureConfiguration(ivy.dependencies,'org.springframework.test','compile-test')
-
-    //remove bad junit dependencies and excludes
-    ivy.dependencies.children().find { it.@org == 'org.junit' && it.@module.text() == 'org.junit' }.replaceNode {}
-    ivy.dependencies.children().find { it.@org == 'org.junit' && it.@name.text() == 'org.junit' }.replaceNode {}
-
-    
-    cfgs.children().each { it.@visibility = 'public' }  // Should be 'private' after initial conversions.
+//  ensureSpringSourceExcludes(ivy.dependencies)
+/*
+    ensureConfiguration(ivy.dependencies,'org.springframework.test','compile-test->*')
+    ensureConfiguration(ivy.dependencies,'com.springsource.org.junit','compile-test')
+    ensureConfiguration(ivy.dependencies,'spock-core','compile-test')
+    ensureConfiguration(ivy.dependencies,'spock-spring','compile-test')
+    ensureConfiguration(ivy.dependencies,'httpunit','compile-test->*')
+    ensureConfiguration(ivy.dependencies,'org.springframework.aspects','compile->*')
+     
+    // patch bad junit exludes
+    ivy.dependencies.children().findAll { 
+        it.name() == 'exclude' && ("${it.@org}" == 'org.junit' || "${it.@module}" == 'org.junit' )
+    }.each {         
+        println     "replacing ${it.name()} ${it.@org} ${it.@module} as junit:junit"
+        it.@org = 'junit'  
+        it.@module = 'junit'
+    }  
+*/
+    cfgs.children().each { it.@visibility = 'private' }  // Should be 'private' after initial conversions.
         
     cfgs.children().find {it.@name == 'runtime' }.@extends = 'compile'
     cfgs.children().find {it.@name == 'compile-test' }.@extends = 'compile'
     cfgs.children().find {it.@name == 'runtime-test' }.@extends = 'runtime,compile-test'
+    cfgs.children().find {it.@name == 'runtime-test' }.@visibility = 'public'
     cfgs.children().find {it.@name == 'default' }.@visibility = 'public'
     cfgs.children().find {it.@name == 'default' }.@extends = 'runtime'
     
@@ -140,17 +171,30 @@
     //new File('ivy.xml').write(  XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy }).replaceAll('>','>'))
     
     def stringWriter = new StringWriter()
-    
-    
+
     def node = new XmlParser().parseText( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy }))
     new MyNodePrinter(new IndentPrinter( new PrintWriter(stringWriter))).print(node)
     file.write(stringWriter.toString())
     
 }
 
+def resolveJunit(depends) {
+
+    if (depends.children().any { it.@name == 'com.springsource.org.junit' } ) {
+        depends.children().findAll { "${it.@name}" == 'junit' || it.@module == 'junit' }.each { it.replaceNode {} }
+    }
+    
+    if (!depends.children().any { 
+        def name = "${it.@name}"
+        name.contains ('junit') || name.contains('spock') } ) {
+        ensure(depends,["junit:junit:4.8.2"])
+        depends.children().findAll { it.@module == 'junit' }.each { it.replaceNode {} }
+    }
+}
+
 def ensureConfiguration(depends,name,cfg) {
     depends.children().findAll { it.name() == 'dependency' && it.@name == name}.each {
-        it.@conf = "$cfg->default(*)"
+        it.@conf = cfg.contains('->') ? cfg : "$cfg->default(*)"
     }
 }
 
@@ -179,13 +223,25 @@
     }
 }
 
+def ensure(depends,requires) {
+
+    requires.each {
+        def (org,name,rev) = it.split(":")
+        if (!depends.children().any { it.@name == name } ) {   
+            println "  adding requirement $org:$name "
+            depends.children().findAll { it.name() == 'dependency' }.list().last() + {
+                dependency(name: name, org: org, rev: rev)
+            }           
+        }
+    }        
+}
+
 def ensureSpringSourceExcludes(depends) {
-    def exclusions = []
-    depends.children().findAll { it.name() == 'dependency' && it.@name.text().startsWith('com.springsource.') }.each {
-        exclusions << "${it.@org}:${it.@name.text() - 'com.springsource.'}"        
-    }   
-    exclusions.each {  ensureExcluded(depends,it) }        
-
+    
+    depends.children().findAll { it.name() == 'dependency' && it.@name.text().startsWith('com.springsource.') }.collect {
+        "${it.@org}:${it.@name.text() - 'com.springsource.'}"        
+    }.each {  ensureExcluded(depends,it) }        
+    
 }
 
 /*