Mercurial > public > develkit
comparison fixivy.groovy @ 90:c207cdcaf13e
latest version
author | smith@nwoca.org |
---|---|
date | Tue, 21 Feb 2012 14:50:19 +0000 |
parents | 15f4da8bdbd3 |
children | 90325a10fe95 |
comparison
equal
deleted
inserted
replaced
89:15f4da8bdbd3 | 90:c207cdcaf13e |
---|---|
1 /* | |
2 | |
3 This script is (was) used for 'fixing' early SSDT ivy.xml files created by NetBeans/ivyBeans. | |
4 It's primary goal is to migrate configurations from NetBeans conventions to Maven/Gradle conventions. | |
5 In order to accomplish this, it needs to correct dependencies, excludes and configurations. However, | |
6 it's not able to perfectly correct every ssdt project. Some parts of this script may be commented | |
7 out. Results of this script much be reviewed carefully before committing. | |
8 */ | |
9 | |
1 | 10 |
2 import groovy.xml.QName; | 11 import groovy.xml.QName; |
3 import org.codehaus.groovy.runtime.InvokerHelper; | 12 import org.codehaus.groovy.runtime.InvokerHelper; |
4 | 13 |
5 import java.io.OutputStreamWriter; | 14 import java.io.OutputStreamWriter; |
9 import java.util.Map; | 18 import java.util.Map; |
10 | 19 |
11 import groovy.xml.* | 20 import groovy.xml.* |
12 | 21 |
13 //args = [ '-r'] | 22 //args = [ '-r'] |
14 println args | 23 //println args |
15 | 24 |
16 ant = new AntBuilder() | 25 ant = new AntBuilder() |
17 | 26 |
18 | 27 |
19 if (args.any { it.toUpperCase() == '-R'} ) { | 28 if (args.any { it.toUpperCase() == '-R'} ) { |
59 ivy.dependencies.children().each { dep -> | 68 ivy.dependencies.children().each { dep -> |
60 if ( dep.@conf.text()?.contains('test') ) { | 69 if ( dep.@conf.text()?.contains('test') ) { |
61 dep.@conf = 'compile-test->default(*)' | 70 dep.@conf = 'compile-test->default(*)' |
62 } else if ( dep.@conf.text().contains('castor-ant') ) { | 71 } else if ( dep.@conf.text().contains('castor-ant') ) { |
63 dep.@conf = 'castor-ant->default(*)' | 72 dep.@conf = 'castor-ant->default(*)' |
64 } | 73 } else if (dep.@conf.text() == 'runtime->default' ) { |
65 else { | 74 // preserve |
75 } else{ | |
66 dep.attributes().remove('conf') | 76 dep.attributes().remove('conf') |
67 } | 77 } |
68 } | 78 } |
79 | |
80 // ensure(ivy.dependencies,["org.spockframework:spock-core:0.5-groovy-1.8"]) | |
81 | |
82 // ensure(ivy.dependencies, 'hibernate-validator', ['org.slf4j:slf4j-api:1.5.6','org.slf4j:slf4j-log4j12:1.5.6']) | |
83 // ensure(ivy.dependencies, 'usas.repository', ["org.springframework:org.springframework.test:3.0.5.RELEASE","org.codehaus.groovy:groovy-all:1.8.2"]) | |
84 // ensure(ivy.dependencies, 'usps.repository', ["org.springframework:org.springframework.test:3.0.5.RELEASE","org.codehaus.groovy:groovy-all:1.8.2"]) | |
85 | |
86 | |
87 // ensure(ivy.dependencies, 'spock-core', ["org.springframework:org.springframework.test:3.0.5.RELEASE"]) | |
88 // ensure(ivy.dependencies, 'org.springframework.test', ['org.junit:com.springsource.org.junit:4.9.0']) | |
89 // ensure(ivy.dependencies, 'org.springframework.test', ["org.spockframework:spock-spring:0.5-groovy-1.8"]) | |
90 | |
69 | 91 |
70 // find groovy dependencies (or null) | 92 // find groovy dependencies (or null) |
71 groovy = ivy.dependencies.children().find { it.@org == 'org.codehaus.groovy' && it.@name.text().startsWith('groovy') } | 93 groovy = ivy.dependencies.children().find { it.@org == 'org.codehaus.groovy' && it.@name.text().startsWith('groovy') } |
72 | 94 |
73 if (groovy) { | 95 if (groovy) { |
95 ant.replace(file: template, token: 'org.codehaus.groovy-groovy:major',value:'org.codehaus.groovy-groovy-all:major') | 117 ant.replace(file: template, token: 'org.codehaus.groovy-groovy:major',value:'org.codehaus.groovy-groovy-all:major') |
96 } | 118 } |
97 | 119 |
98 } | 120 } |
99 | 121 |
100 | 122 // resolveJunit(ivy.dependencies) |
101 ensure(ivy.dependencies, 'hibernate-validator', ['org.slf4j:slf4j-api:1.5.6','org.slf4j:slf4j-log4j12:1.5.6']) | |
102 | |
103 ensure(ivy.dependencies, 'org.springframework.test', ['junit:junit:4.8.2']) | |
104 | 123 |
105 // remove exclude for groovy-all | 124 // remove exclude for groovy-all |
106 ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'groovy-all' }.replaceNode {} | 125 ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'groovy-all' }.replaceNode {} |
126 // remove exclude for commons logging | |
127 ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'com.springsource.org.apache.commons.logging' }.replaceNode {} | |
107 | 128 |
108 // Add exclude for regular groovy: | 129 // Add exclude for regular groovy: |
109 ensureExcluded(ivy.dependencies,"org.codehaus.groovy:groovy") | 130 ensureExcluded(ivy.dependencies,"org.codehaus.groovy:groovy") |
110 | 131 |
111 // ensure modules covered by springsource are exluded; | 132 // ensure modules covered by springsource are exluded; |
112 ensureSpringSourceExcludes(ivy.dependencies) | 133 // ensureSpringSourceExcludes(ivy.dependencies) |
113 | 134 /* |
114 ensureConfiguration(ivy.dependencies,'org.springframework.test','compile-test') | 135 ensureConfiguration(ivy.dependencies,'org.springframework.test','compile-test->*') |
115 | 136 ensureConfiguration(ivy.dependencies,'com.springsource.org.junit','compile-test') |
116 //remove bad junit dependencies and excludes | 137 ensureConfiguration(ivy.dependencies,'spock-core','compile-test') |
117 ivy.dependencies.children().find { it.@org == 'org.junit' && it.@module.text() == 'org.junit' }.replaceNode {} | 138 ensureConfiguration(ivy.dependencies,'spock-spring','compile-test') |
118 ivy.dependencies.children().find { it.@org == 'org.junit' && it.@name.text() == 'org.junit' }.replaceNode {} | 139 ensureConfiguration(ivy.dependencies,'httpunit','compile-test->*') |
119 | 140 ensureConfiguration(ivy.dependencies,'org.springframework.aspects','compile->*') |
120 | 141 |
121 cfgs.children().each { it.@visibility = 'public' } // Should be 'private' after initial conversions. | 142 // patch bad junit exludes |
143 ivy.dependencies.children().findAll { | |
144 it.name() == 'exclude' && ("${it.@org}" == 'org.junit' || "${it.@module}" == 'org.junit' ) | |
145 }.each { | |
146 println "replacing ${it.name()} ${it.@org} ${it.@module} as junit:junit" | |
147 it.@org = 'junit' | |
148 it.@module = 'junit' | |
149 } | |
150 */ | |
151 cfgs.children().each { it.@visibility = 'private' } // Should be 'private' after initial conversions. | |
122 | 152 |
123 cfgs.children().find {it.@name == 'runtime' }.@extends = 'compile' | 153 cfgs.children().find {it.@name == 'runtime' }.@extends = 'compile' |
124 cfgs.children().find {it.@name == 'compile-test' }.@extends = 'compile' | 154 cfgs.children().find {it.@name == 'compile-test' }.@extends = 'compile' |
125 cfgs.children().find {it.@name == 'runtime-test' }.@extends = 'runtime,compile-test' | 155 cfgs.children().find {it.@name == 'runtime-test' }.@extends = 'runtime,compile-test' |
156 cfgs.children().find {it.@name == 'runtime-test' }.@visibility = 'public' | |
126 cfgs.children().find {it.@name == 'default' }.@visibility = 'public' | 157 cfgs.children().find {it.@name == 'default' }.@visibility = 'public' |
127 cfgs.children().find {it.@name == 'default' }.@extends = 'runtime' | 158 cfgs.children().find {it.@name == 'default' }.@extends = 'runtime' |
128 | 159 |
129 if (!cfgs.children().any { it.@name == 'archives' } ) { | 160 if (!cfgs.children().any { it.@name == 'archives' } ) { |
130 println "added public 'archives' conf" | 161 println "added public 'archives' conf" |
138 | 169 |
139 def outputBuilder = new StreamingMarkupBuilder() | 170 def outputBuilder = new StreamingMarkupBuilder() |
140 //new File('ivy.xml').write( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy }).replaceAll('>','>')) | 171 //new File('ivy.xml').write( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy }).replaceAll('>','>')) |
141 | 172 |
142 def stringWriter = new StringWriter() | 173 def stringWriter = new StringWriter() |
143 | 174 |
144 | |
145 def node = new XmlParser().parseText( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy })) | 175 def node = new XmlParser().parseText( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy })) |
146 new MyNodePrinter(new IndentPrinter( new PrintWriter(stringWriter))).print(node) | 176 new MyNodePrinter(new IndentPrinter( new PrintWriter(stringWriter))).print(node) |
147 file.write(stringWriter.toString()) | 177 file.write(stringWriter.toString()) |
148 | 178 |
149 } | 179 } |
150 | 180 |
181 def resolveJunit(depends) { | |
182 | |
183 if (depends.children().any { it.@name == 'com.springsource.org.junit' } ) { | |
184 depends.children().findAll { "${it.@name}" == 'junit' || it.@module == 'junit' }.each { it.replaceNode {} } | |
185 } | |
186 | |
187 if (!depends.children().any { | |
188 def name = "${it.@name}" | |
189 name.contains ('junit') || name.contains('spock') } ) { | |
190 ensure(depends,["junit:junit:4.8.2"]) | |
191 depends.children().findAll { it.@module == 'junit' }.each { it.replaceNode {} } | |
192 } | |
193 } | |
194 | |
151 def ensureConfiguration(depends,name,cfg) { | 195 def ensureConfiguration(depends,name,cfg) { |
152 depends.children().findAll { it.name() == 'dependency' && it.@name == name}.each { | 196 depends.children().findAll { it.name() == 'dependency' && it.@name == name}.each { |
153 it.@conf = "$cfg->default(*)" | 197 it.@conf = cfg.contains('->') ? cfg : "$cfg->default(*)" |
154 } | 198 } |
155 } | 199 } |
156 | 200 |
157 def ensureExcluded(depends,excludeModule) { | 201 def ensureExcluded(depends,excludeModule) { |
158 def (o,m) = excludeModule.split(':') | 202 def (o,m) = excludeModule.split(':') |
177 } | 221 } |
178 } | 222 } |
179 } | 223 } |
180 } | 224 } |
181 | 225 |
226 def ensure(depends,requires) { | |
227 | |
228 requires.each { | |
229 def (org,name,rev) = it.split(":") | |
230 if (!depends.children().any { it.@name == name } ) { | |
231 println " adding requirement $org:$name " | |
232 depends.children().findAll { it.name() == 'dependency' }.list().last() + { | |
233 dependency(name: name, org: org, rev: rev) | |
234 } | |
235 } | |
236 } | |
237 } | |
238 | |
182 def ensureSpringSourceExcludes(depends) { | 239 def ensureSpringSourceExcludes(depends) { |
183 def exclusions = [] | 240 |
184 depends.children().findAll { it.name() == 'dependency' && it.@name.text().startsWith('com.springsource.') }.each { | 241 depends.children().findAll { it.name() == 'dependency' && it.@name.text().startsWith('com.springsource.') }.collect { |
185 exclusions << "${it.@org}:${it.@name.text() - 'com.springsource.'}" | 242 "${it.@org}:${it.@name.text() - 'com.springsource.'}" |
186 } | 243 }.each { ensureExcluded(depends,it) } |
187 exclusions.each { ensureExcluded(depends,it) } | 244 |
188 | |
189 } | 245 } |
190 | 246 |
191 /* | 247 /* |
192 The class below is a copy/paste of groovy's XmlNodePrinter customized to order Ivy.xml attributes in | 248 The class below is a copy/paste of groovy's XmlNodePrinter customized to order Ivy.xml attributes in |
193 the desired order and to add some whitespace. | 249 the desired order and to add some whitespace. |