Mercurial > public > develkit
annotate fixivy.groovy @ 159:0c48cfd1938b
allow projects to override branchName
author | Dave Smith <smith@nwoca.org> |
---|---|
date | Wed, 06 Nov 2013 02:13:31 +0000 |
parents | 90325a10fe95 |
children |
rev | line source |
---|---|
90 | 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 | |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
10 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
11 import groovy.xml.QName; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
12 import org.codehaus.groovy.runtime.InvokerHelper; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
13 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
14 import java.io.OutputStreamWriter; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
15 import java.io.PrintWriter; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
16 import java.util.HashMap; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
17 import java.util.List; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
18 import java.util.Map; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
19 |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
20 import groovy.xml.* |
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
21 |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
22 //args = [ '-r'] |
90 | 23 //println args |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
24 |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
25 ant = new AntBuilder() |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
26 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
27 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
28 if (args.any { it.toUpperCase() == '-R'} ) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
29 |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
30 new File('.').traverse ([ type: groovy.io.FileType.DIRECTORIES, maxDepth: 3 ]) { project -> |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
31 if (new File(project,'ivy.xml').exists() ) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
32 processIvy(new File(project,'ivy.xml')) |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
33 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
34 } |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
35 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
36 } else { |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
37 processIvy(new File('ivy.xml')) |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
38 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
39 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
40 def processIvy(file) { |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
41 println "-" * 60 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
42 println "processing: $file" |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
43 def xml = new XmlSlurper() |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
44 def ivy = xml.parse(file) |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
45 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
46 def cfgs = ivy.configurations |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
47 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
48 // default mapping for most dependencies: |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
49 cfgs.@defaultconfmapping = 'compile->default(*)' |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
50 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
51 // Add default config, if missing: |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
52 if (!cfgs.children().find { it.@name == 'default' } ) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
53 println "adding default config" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
54 cfgs.appendNode { |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
55 conf(name:"default",extends:'compile',visibility:'public') |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
56 } |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
57 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
58 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
59 if (ivy.dependencies.children().find { it.@name == 'org.springframework.web.servlet' } && |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
60 !ivy.dependencies.children().find { it.@name == 'servlet-api' } ) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
61 ivy.dependencies.children().findAll { it.name() == 'dependency' }.list().last() + { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
62 dependency(name:'servlet-api', org: 'javax.servlet', rev: '2.5') |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
63 dependency(name:'jsp-api', org: 'javax.servlet', rev: '2.0') |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
64 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
65 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
66 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
67 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
68 ivy.dependencies.children().each { dep -> |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
69 if ( dep.@conf.text()?.contains('test') ) { |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
70 dep.@conf = 'compile-test->default(*)' |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
71 } else if ( dep.@conf.text().contains('castor-ant') ) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
72 dep.@conf = 'castor-ant->default(*)' |
90 | 73 } else if (dep.@conf.text() == 'runtime->default' ) { |
74 // preserve | |
92 | 75 } else if (dep.@conf.text().contains('groovy') ) { |
76 // preserve | |
90 | 77 } else{ |
92 | 78 // dep.attributes().remove('conf') |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
79 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
80 } |
90 | 81 |
82 // ensure(ivy.dependencies,["org.spockframework:spock-core:0.5-groovy-1.8"]) | |
83 | |
84 // ensure(ivy.dependencies, 'hibernate-validator', ['org.slf4j:slf4j-api:1.5.6','org.slf4j:slf4j-log4j12:1.5.6']) | |
85 // ensure(ivy.dependencies, 'usas.repository', ["org.springframework:org.springframework.test:3.0.5.RELEASE","org.codehaus.groovy:groovy-all:1.8.2"]) | |
86 // ensure(ivy.dependencies, 'usps.repository', ["org.springframework:org.springframework.test:3.0.5.RELEASE","org.codehaus.groovy:groovy-all:1.8.2"]) | |
87 | |
88 | |
89 // ensure(ivy.dependencies, 'spock-core', ["org.springframework:org.springframework.test:3.0.5.RELEASE"]) | |
90 // ensure(ivy.dependencies, 'org.springframework.test', ['org.junit:com.springsource.org.junit:4.9.0']) | |
91 // ensure(ivy.dependencies, 'org.springframework.test', ["org.spockframework:spock-spring:0.5-groovy-1.8"]) | |
92 | |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
93 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
94 // find groovy dependencies (or null) |
92 | 95 /* |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
96 groovy = ivy.dependencies.children().find { it.@org == 'org.codehaus.groovy' && it.@name.text().startsWith('groovy') } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
97 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
98 if (groovy) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
99 // Add a groovy conig for groovy projects: |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
100 if (!cfgs.children().any { it.@name == 'groovy' } ) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
101 println "added private groovy conf" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
102 cfgs.appendNode { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
103 conf(name:'groovy',visibility:'private',transitive: true) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
104 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
105 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
106 // Adjust 'compile' to exend from 'groovy' conf |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
107 cfgs.children().find { it.@name == 'compile' }.@extends = 'groovy' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
108 cfgs.children().find { it.@name == 'groovy' }.@transitive = 'true' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
109 groovy.@conf = "groovy->default" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
110 println "Groovy ${groovy.@rev} conf changed to ${groovy.@conf}" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
111 // Switch project to use groovy-all instead of groovy + deps |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
112 if (groovy.@name == 'groovy') { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
113 println "changed groovy to groovy-all" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
114 groovy.@name = 'groovy-all' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
115 } |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
116 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
117 def template = new File(file.parent ?: ".",'template.mf') |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
118 if (template.exists()) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
119 println "updating groovy in $template" |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
120 ant.replace(file: template, token: 'org.codehaus.groovy-groovy:major',value:'org.codehaus.groovy-groovy-all:major') |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
121 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
122 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
123 } |
92 | 124 */ |
90 | 125 // resolveJunit(ivy.dependencies) |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
126 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
127 // remove exclude for groovy-all |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
128 ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'groovy-all' }.replaceNode {} |
90 | 129 // remove exclude for commons logging |
130 ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'com.springsource.org.apache.commons.logging' }.replaceNode {} | |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
131 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
132 // Add exclude for regular groovy: |
92 | 133 // ensureExcluded(ivy.dependencies,"org.codehaus.groovy:groovy") |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
134 |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
135 // ensure modules covered by springsource are exluded; |
90 | 136 // ensureSpringSourceExcludes(ivy.dependencies) |
137 /* | |
138 ensureConfiguration(ivy.dependencies,'org.springframework.test','compile-test->*') | |
139 ensureConfiguration(ivy.dependencies,'com.springsource.org.junit','compile-test') | |
140 ensureConfiguration(ivy.dependencies,'spock-core','compile-test') | |
141 ensureConfiguration(ivy.dependencies,'spock-spring','compile-test') | |
142 ensureConfiguration(ivy.dependencies,'httpunit','compile-test->*') | |
143 ensureConfiguration(ivy.dependencies,'org.springframework.aspects','compile->*') | |
144 | |
145 // patch bad junit exludes | |
146 ivy.dependencies.children().findAll { | |
147 it.name() == 'exclude' && ("${it.@org}" == 'org.junit' || "${it.@module}" == 'org.junit' ) | |
148 }.each { | |
149 println "replacing ${it.name()} ${it.@org} ${it.@module} as junit:junit" | |
150 it.@org = 'junit' | |
151 it.@module = 'junit' | |
152 } | |
153 */ | |
92 | 154 cfgs.children().each { it.@visibility = 'public' } // Should be 'private' after initial conversions. |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
155 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
156 cfgs.children().find {it.@name == 'runtime' }.@extends = 'compile' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
157 cfgs.children().find {it.@name == 'compile-test' }.@extends = 'compile' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
158 cfgs.children().find {it.@name == 'runtime-test' }.@extends = 'runtime,compile-test' |
90 | 159 cfgs.children().find {it.@name == 'runtime-test' }.@visibility = 'public' |
92 | 160 cfgs.children().find {it.@name == 'compile-test' }.@visibility = 'public' |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
161 cfgs.children().find {it.@name == 'default' }.@visibility = 'public' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
162 cfgs.children().find {it.@name == 'default' }.@extends = 'runtime' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
163 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
164 if (!cfgs.children().any { it.@name == 'archives' } ) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
165 println "added public 'archives' conf" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
166 cfgs.appendNode { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
167 conf(name:'archives',visibility:'public') |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
168 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
169 } |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
170 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
171 cfgs.children().find {it.@name == 'archives' }.@visibility = 'public' |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
172 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
173 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
174 def outputBuilder = new StreamingMarkupBuilder() |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
175 //new File('ivy.xml').write( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy }).replaceAll('>','>')) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
176 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
177 def stringWriter = new StringWriter() |
90 | 178 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
179 def node = new XmlParser().parseText( XmlUtil.serialize( outputBuilder.bind { mkp.yield ivy })) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
180 new MyNodePrinter(new IndentPrinter( new PrintWriter(stringWriter))).print(node) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
181 file.write(stringWriter.toString()) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
182 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
183 } |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
184 |
90 | 185 def resolveJunit(depends) { |
186 | |
187 if (depends.children().any { it.@name == 'com.springsource.org.junit' } ) { | |
188 depends.children().findAll { "${it.@name}" == 'junit' || it.@module == 'junit' }.each { it.replaceNode {} } | |
189 } | |
190 | |
191 if (!depends.children().any { | |
192 def name = "${it.@name}" | |
193 name.contains ('junit') || name.contains('spock') } ) { | |
194 ensure(depends,["junit:junit:4.8.2"]) | |
195 depends.children().findAll { it.@module == 'junit' }.each { it.replaceNode {} } | |
196 } | |
197 } | |
198 | |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
199 def ensureConfiguration(depends,name,cfg) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
200 depends.children().findAll { it.name() == 'dependency' && it.@name == name}.each { |
90 | 201 it.@conf = cfg.contains('->') ? cfg : "$cfg->default(*)" |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
202 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
203 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
204 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
205 def ensureExcluded(depends,excludeModule) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
206 def (o,m) = excludeModule.split(':') |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
207 if (!depends.children().any { it.name() == 'exclude' && it.@module.text() == m}) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
208 depends.appendNode { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
209 println "excluding $o:$m" |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
210 exclude(org: o, module: m) |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
211 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
212 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
213 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
214 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
215 def ensure(depends,exists,requires) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
216 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
217 if (depends.children().any { it.name() == 'dependency' && it.@name == exists } ) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
218 requires.each { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
219 def (org,name,rev) = it.split(":") |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
220 if (!depends.children().any { it.@name == name } ) { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
221 println " adding requirement $org:$name for $exists" |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
222 depends.children().findAll { it.name() == 'dependency' }.list().last() + { |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
223 dependency(name: name, org: org, rev: rev) |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
224 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
225 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
226 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
227 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
228 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
229 |
90 | 230 def ensure(depends,requires) { |
231 | |
232 requires.each { | |
233 def (org,name,rev) = it.split(":") | |
234 if (!depends.children().any { it.@name == name } ) { | |
235 println " adding requirement $org:$name " | |
236 depends.children().findAll { it.name() == 'dependency' }.list().last() + { | |
237 dependency(name: name, org: org, rev: rev) | |
238 } | |
239 } | |
240 } | |
241 } | |
242 | |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
243 def ensureSpringSourceExcludes(depends) { |
90 | 244 |
245 depends.children().findAll { it.name() == 'dependency' && it.@name.text().startsWith('com.springsource.') }.collect { | |
246 "${it.@org}:${it.@name.text() - 'com.springsource.'}" | |
247 }.each { ensureExcluded(depends,it) } | |
248 | |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
249 } |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
250 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
251 /* |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
252 The class below is a copy/paste of groovy's XmlNodePrinter customized to order Ivy.xml attributes in |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
253 the desired order and to add some whitespace. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
254 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
255 class MyNodePrinter { |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
256 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
257 protected void printNameAttributes(Map attributes, ctx) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
258 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
259 if (attributes == null || attributes.isEmpty()) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
260 return; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
261 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
262 def writer = new StringBuffer() |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
263 attributes.entrySet().sort{ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
264 switch (it.key ) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
265 case 'org': |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
266 1 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
267 break |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
268 case 'name': 2 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
269 break |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
270 case 'rev': 3 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
271 break |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
272 case 'extends': 5 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
273 break |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
274 default: 99 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
275 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
276 }.each { p -> |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
277 def tmp = new StringBuffer() |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
278 Map.Entry entry = (Map.Entry) p; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
279 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
280 tmp << " " |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
281 tmp << getName(entry.getKey()) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
282 tmp << "=" |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
283 Object value = entry.getValue(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
284 tmp << quote |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
285 tmp << value |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
286 // if (value instanceof String) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
287 // printEscaped((String) value); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
288 // } else { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
289 // printEscaped(InvokerHelper.toString(value)); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
290 // } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
291 tmp << quote |
89
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
292 def size = entry.getKey() in ['org','name'] ? 35 : 22 |
15f4da8bdbd3
add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents:
88
diff
changeset
|
293 writer << String.format(" %-${size}s",tmp.toString()) |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
294 // printNamespace(entry.getKey(), ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
295 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
296 out.print(" " + writer.toString().trim()) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
297 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
298 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
299 protected final IndentPrinter out; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
300 private String quote; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
301 private boolean namespaceAware = true; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
302 private boolean preserveWhitespace = false; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
303 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
304 public MyNodePrinter(PrintWriter out) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
305 this(out, " "); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
306 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
307 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
308 public MyNodePrinter(PrintWriter out, String indent) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
309 this(out, indent, "\""); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
310 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
311 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
312 public MyNodePrinter(PrintWriter out, String indent, String quote) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
313 this(new IndentPrinter(out, indent), quote); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
314 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
315 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
316 public MyNodePrinter(IndentPrinter out) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
317 this(out, "\""); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
318 } |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
319 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
320 public MyNodePrinter(IndentPrinter out, String quote) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
321 if (out == null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
322 throw new IllegalArgumentException("Argument 'IndentPrinter out' must not be null!"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
323 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
324 this.out = out; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
325 this.quote = quote; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
326 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
327 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
328 public MyNodePrinter() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
329 this(new PrintWriter(new OutputStreamWriter(System.out))); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
330 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
331 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
332 public void print(Node node) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
333 print(node, new NamespaceContext()); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
334 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
335 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
336 /** |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
337 * Check if namespace handling is enabled. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
338 * Defaults to <code>true</code>. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
339 * |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
340 * @return true if namespace handling is enabled |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
341 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
342 public boolean isNamespaceAware() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
343 return namespaceAware; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
344 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
345 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
346 /** |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
347 * Enable and/or disable namespace handling. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
348 * |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
349 * @param namespaceAware the new desired value |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
350 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
351 public void setNamespaceAware(boolean namespaceAware) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
352 this.namespaceAware = namespaceAware; |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
353 } |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
354 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
355 /** |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
356 * Check if whitespace preservation is enabled. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
357 * Defaults to <code>false</code>. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
358 * |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
359 * @return true if whitespaces are honoured when printing simple text nodes |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
360 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
361 public boolean isPreserveWhitespace() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
362 return preserveWhitespace; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
363 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
364 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
365 /** |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
366 * Enable and/or disable preservation of whitespace. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
367 * |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
368 * @param preserveWhitespace the new desired value |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
369 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
370 public void setPreserveWhitespace(boolean preserveWhitespace) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
371 this.preserveWhitespace = preserveWhitespace; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
372 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
373 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
374 /** |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
375 * Get Quote to use when printing attributes. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
376 * |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
377 * @return the quote character |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
378 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
379 public String getQuote() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
380 return quote; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
381 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
382 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
383 /** |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
384 * Set Quote to use when printing attributes. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
385 * |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
386 * @param quote the quote character |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
387 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
388 public void setQuote(String quote) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
389 this.quote = quote; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
390 } |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
391 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
392 protected void print(Node node, NamespaceContext ctx) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
393 /* |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
394 * Handle empty elements like '<br/>', '<img/> or '<hr noshade="noshade"/>. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
395 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
396 if (isEmptyElement(node)) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
397 printLineBegin(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
398 out.print("<"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
399 out.print(getName(node)); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
400 if (ctx != null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
401 printNamespace(node, ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
402 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
403 printNameAttributes(node.attributes(), ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
404 out.print("/>"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
405 printLineEnd(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
406 out.flush(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
407 return; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
408 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
409 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
410 /* |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
411 * Hook for extra processing, e.g. GSP tag element! |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
412 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
413 if (printSpecialNode(node)) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
414 out.flush(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
415 return; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
416 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
417 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
418 /* |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
419 * Handle normal element like <html> ... </html>. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
420 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
421 Object value = node.value(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
422 if (value instanceof List) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
423 printName(node, ctx, true, isListOfSimple((List) value)); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
424 printList((List) value, ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
425 printName(node, ctx, false, isListOfSimple((List) value)); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
426 out.flush(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
427 return; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
428 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
429 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
430 // treat as simple type - probably a String |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
431 printName(node, ctx, true, preserveWhitespace); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
432 printSimpleItemWithIndent(value); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
433 printName(node, ctx, false, preserveWhitespace); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
434 out.flush(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
435 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
436 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
437 private boolean isListOfSimple(List value) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
438 for (Object p : value) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
439 if (p instanceof Node) return false; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
440 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
441 return preserveWhitespace; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
442 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
443 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
444 protected void printLineBegin() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
445 out.printIndent(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
446 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
447 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
448 protected void printLineEnd() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
449 printLineEnd(null); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
450 } |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
451 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
452 protected void printLineEnd(String comment) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
453 if (comment != null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
454 out.print(" <!-- "); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
455 out.print(comment); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
456 out.print(" -->"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
457 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
458 out.println(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
459 out.flush(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
460 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
461 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
462 protected void printList(List list, NamespaceContext ctx) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
463 out.incrementIndent(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
464 for (Object value : list) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
465 NamespaceContext context = new NamespaceContext(ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
466 /* |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
467 * If the current value is a node, recurse into that node. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
468 */ |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
469 if (value instanceof Node) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
470 print((Node) value, context); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
471 continue; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
472 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
473 printSimpleItem(value); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
474 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
475 out.decrementIndent(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
476 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
477 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
478 protected void printSimpleItem(Object value) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
479 if (!preserveWhitespace) printLineBegin(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
480 printEscaped(InvokerHelper.toString(value)); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
481 if (!preserveWhitespace) printLineEnd(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
482 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
483 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
484 protected void printName(Node node, NamespaceContext ctx, boolean begin, boolean preserve) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
485 if (node == null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
486 throw new NullPointerException("Node must not be null."); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
487 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
488 Object name = node.name(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
489 if (name == null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
490 throw new NullPointerException("Name must not be null."); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
491 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
492 if (!preserve || begin) printLineBegin(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
493 out.print("<"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
494 if (!begin) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
495 out.print("/"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
496 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
497 out.print(getName(node)); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
498 if (ctx != null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
499 printNamespace(node, ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
500 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
501 if (begin) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
502 printNameAttributes(node.attributes(), ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
503 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
504 out.print(">"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
505 if (!preserve || !begin) printLineEnd(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
506 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
507 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
508 protected boolean printSpecialNode(Node node) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
509 return false; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
510 } |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
511 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
512 protected void printNamespace(Object object, NamespaceContext ctx) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
513 if (namespaceAware) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
514 if (object instanceof Node) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
515 printNamespace(((Node) object).name(), ctx); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
516 } else if (object instanceof QName) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
517 QName qname = (QName) object; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
518 String namespaceUri = qname.getNamespaceURI(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
519 if (namespaceUri != null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
520 String prefix = qname.getPrefix(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
521 if (!ctx.isPrefixRegistered(prefix, namespaceUri)) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
522 ctx.registerNamespacePrefix(prefix, namespaceUri); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
523 out.print(" "); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
524 out.print("xmlns"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
525 if (prefix.length() > 0) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
526 out.print(":"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
527 out.print(prefix); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
528 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
529 out.print("=" + quote); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
530 out.print(namespaceUri); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
531 out.print(quote); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
532 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
533 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
534 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
535 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
536 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
537 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
538 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
539 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
540 private boolean isEmptyElement(Node node) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
541 if (node == null) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
542 throw new IllegalArgumentException("Node must not be null!"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
543 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
544 if (!node.children().isEmpty()) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
545 return false; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
546 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
547 return node.text().length() == 0; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
548 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
549 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
550 private String getName(Object object) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
551 if (object instanceof String) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
552 return (String) object; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
553 } else if (object instanceof QName) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
554 QName qname = (QName) object; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
555 if (!namespaceAware) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
556 return qname.getLocalPart(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
557 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
558 return qname.getQualifiedName(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
559 } else if (object instanceof Node) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
560 Object name = ((Node) object).name(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
561 return getName(name); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
562 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
563 return object.toString(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
564 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
565 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
566 private void printSimpleItemWithIndent(Object value) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
567 if (!preserveWhitespace) out.incrementIndent(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
568 printSimpleItem(value); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
569 if (!preserveWhitespace) out.decrementIndent(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
570 } |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
571 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
572 // For ' and " we only escape if needed. As far as XML is concerned, |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
573 // we could always escape if we wanted to. |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
574 private void printEscaped(String s) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
575 for (int i = 0; i < s.length(); i++) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
576 char c = s.charAt(i); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
577 switch (c) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
578 case '<': |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
579 out.print("<"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
580 break; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
581 case '>': |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
582 out.print(">"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
583 break; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
584 case '&': |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
585 out.print("&"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
586 break; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
587 case '\'': |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
588 if (quote.equals("'")) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
589 out.print("'"); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
590 else |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
591 out.print(c); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
592 break; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
593 case '"': |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
594 if (quote.equals("\"")) |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
595 out.print("""); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
596 else |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
597 out.print(c); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
598 break; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
599 default: |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
600 out.print(c); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
601 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
602 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
603 } |
86
da29f9bde0da
groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff
changeset
|
604 |
88
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
605 protected class NamespaceContext { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
606 private final Map<String, String> namespaceMap; |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
607 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
608 public NamespaceContext() { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
609 namespaceMap = new HashMap<String, String>(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
610 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
611 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
612 public NamespaceContext(NamespaceContext context) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
613 this(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
614 namespaceMap.putAll(context.namespaceMap); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
615 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
616 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
617 public boolean isPrefixRegistered(String prefix, String uri) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
618 return namespaceMap.containsKey(prefix) && namespaceMap.get(prefix).equals(uri); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
619 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
620 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
621 public void registerNamespacePrefix(String prefix, String uri) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
622 if (!isPrefixRegistered(prefix, uri)) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
623 namespaceMap.put(prefix, uri); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
624 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
625 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
626 |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
627 public String getNamespace(String prefix) { |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
628 Object uri = namespaceMap.get(prefix); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
629 return (uri == null) ? null : uri.toString(); |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
630 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
631 } |
9f2ab59a5333
improve ivy clean up and control order of attribs
smith@nwoca.org
parents:
86
diff
changeset
|
632 } |