annotate fixivy.groovy @ 89:15f4da8bdbd3

add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
author smith@nwoca.org
date Fri, 17 Feb 2012 15:09:35 +0000
parents fix-ivy.groovy@9f2ab59a5333
children c207cdcaf13e
rev   line source
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
1
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
2 import groovy.xml.QName;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
3 import org.codehaus.groovy.runtime.InvokerHelper;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
4
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
5 import java.io.OutputStreamWriter;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
6 import java.io.PrintWriter;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
7 import java.util.HashMap;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
8 import java.util.List;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
9 import java.util.Map;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
10
86
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
11 import groovy.xml.*
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
12
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
13 //args = [ '-r']
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
14 println args
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
15
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
16 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
17
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
18
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
19 if (args.any { it.toUpperCase() == '-R'} ) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
20
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
21 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
22 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
23 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
24 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
25 }
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
26
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
27 } 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
28 processIvy(new File('ivy.xml'))
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
29 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
30
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
31 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
32 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
33 println "processing: $file"
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
34 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
35 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
36
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
37 def cfgs = ivy.configurations
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 // 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
40 cfgs.@defaultconfmapping = 'compile->default(*)'
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
41
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
42 // Add default config, if missing:
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
43 if (!cfgs.children().find { it.@name == 'default' } ) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
44 println "adding default config"
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
45 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
46 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
47 }
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
48 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
49
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
50 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
51 !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
52 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
53 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
54 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
55 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
56
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
57 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
58
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
59 ivy.dependencies.children().each { dep ->
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
60 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
61 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
62 } 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
63 dep.@conf = 'castor-ant->default(*)'
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 else {
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
66 dep.attributes().remove('conf')
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 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
69
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
70 // find groovy dependencies (or null)
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
71 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
72
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
73 if (groovy) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
74 // Add a groovy conig for groovy projects:
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
75 if (!cfgs.children().any { it.@name == 'groovy' } ) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
76 println "added private groovy conf"
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
77 cfgs.appendNode {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
78 conf(name:'groovy',visibility:'private',transitive: true)
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 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
81 // Adjust 'compile' to exend from 'groovy' conf
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
82 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
83 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
84 groovy.@conf = "groovy->default"
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
85 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
86 // 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
87 if (groovy.@name == 'groovy') {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
88 println "changed groovy to groovy-all"
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
89 groovy.@name = 'groovy-all'
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
90 }
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
91
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
92 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
93 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
94 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
95 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
96 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
97
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
98 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
99
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
100
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
101 ensure(ivy.dependencies, 'hibernate-validator', ['org.slf4j:slf4j-api:1.5.6','org.slf4j:slf4j-log4j12:1.5.6'])
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
102
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
103 ensure(ivy.dependencies, 'org.springframework.test', ['junit:junit:4.8.2'])
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
104
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
105 // 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
106 ivy.dependencies.children().find { it.name() == 'exclude' && it.@module.text() == 'groovy-all' }.replaceNode {}
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
107
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
108 // Add exclude for regular groovy:
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
109 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
110
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
111 // ensure modules covered by springsource are exluded;
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
112 ensureSpringSourceExcludes(ivy.dependencies)
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
113
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
114 ensureConfiguration(ivy.dependencies,'org.springframework.test','compile-test')
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
115
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
116 //remove bad junit dependencies and excludes
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
117 ivy.dependencies.children().find { it.@org == 'org.junit' && it.@module.text() == 'org.junit' }.replaceNode {}
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
118 ivy.dependencies.children().find { it.@org == 'org.junit' && it.@name.text() == 'org.junit' }.replaceNode {}
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
119
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
120
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
121 cfgs.children().each { it.@visibility = 'public' } // Should be 'private' after initial conversions.
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 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
124 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
125 cfgs.children().find {it.@name == 'runtime-test' }.@extends = 'runtime,compile-test'
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
126 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
127 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
128
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
129 if (!cfgs.children().any { it.@name == 'archives' } ) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
130 println "added public 'archives' conf"
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
131 cfgs.appendNode {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
132 conf(name:'archives',visibility:'public')
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
133 }
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
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
136 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
137
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
138
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
139 def outputBuilder = new StreamingMarkupBuilder()
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
140 //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
141
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
142 def stringWriter = new StringWriter()
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
143
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
144
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
145 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
146 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
147 file.write(stringWriter.toString())
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
148
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
149 }
89
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
150
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
151 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
152 depends.children().findAll { it.name() == 'dependency' && it.@name == name}.each {
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
153 it.@conf = "$cfg->default(*)"
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
154 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
155 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
156
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
157 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
158 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
159 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
160 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
161 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
162 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
163 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
164 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
165 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
166
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
167 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
168
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
177 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
178 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
179 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
180 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
181
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
182 def ensureSpringSourceExcludes(depends) {
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
183 def exclusions = []
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
184 depends.children().findAll { it.name() == 'dependency' && it.@name.text().startsWith('com.springsource.') }.each {
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
185 exclusions << "${it.@org}:${it.@name.text() - 'com.springsource.'}"
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
186 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
187 exclusions.each { ensureExcluded(depends,it) }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
188
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
189 }
15f4da8bdbd3 add ability to control order of attributes, whitespace. more cleanup up of dependencies and exclusions
smith@nwoca.org
parents: 88
diff changeset
190
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
191 /*
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
192 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
193 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
194 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
195 class MyNodePrinter {
86
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
196
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
197 protected void printNameAttributes(Map attributes, ctx) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
198
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
199 if (attributes == null || attributes.isEmpty()) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
200 return;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
201 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
202 def writer = new StringBuffer()
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
203 attributes.entrySet().sort{
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
204 switch (it.key ) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
205 case 'org':
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
206 1
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
207 break
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
208 case 'name': 2
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
209 break
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
210 case 'rev': 3
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
211 break
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
212 case 'extends': 5
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
213 break
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
214 default: 99
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
215 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
216 }.each { p ->
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
217 def tmp = new StringBuffer()
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
218 Map.Entry entry = (Map.Entry) p;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
219
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
220 tmp << " "
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
221 tmp << getName(entry.getKey())
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
222 tmp << "="
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
223 Object value = entry.getValue();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
224 tmp << quote
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
225 tmp << value
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
226 // if (value instanceof String) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
227 // printEscaped((String) value);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
228 // } else {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
229 // printEscaped(InvokerHelper.toString(value));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
230 // }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
231 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
232 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
233 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
234 // printNamespace(entry.getKey(), ctx);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
235 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
236 out.print(" " + writer.toString().trim())
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
237 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
238
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
239 protected final IndentPrinter out;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
240 private String quote;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
241 private boolean namespaceAware = true;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
242 private boolean preserveWhitespace = false;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
243
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
244 public MyNodePrinter(PrintWriter out) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
245 this(out, " ");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
246 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
247
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
248 public MyNodePrinter(PrintWriter out, String indent) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
249 this(out, indent, "\"");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
250 }
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 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
253 this(new IndentPrinter(out, indent), quote);
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
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
256 public MyNodePrinter(IndentPrinter out) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
257 this(out, "\"");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
258 }
86
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
259
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
260 public MyNodePrinter(IndentPrinter out, String quote) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
261 if (out == null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
262 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
263 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
264 this.out = out;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
265 this.quote = quote;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
266 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
267
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
268 public MyNodePrinter() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
269 this(new PrintWriter(new OutputStreamWriter(System.out)));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
270 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
271
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
272 public void print(Node node) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
273 print(node, new NamespaceContext());
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
274 }
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 /**
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
277 * Check if namespace handling is enabled.
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
278 * Defaults to <code>true</code>.
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 * @return true if namespace handling is enabled
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
281 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
282 public boolean isNamespaceAware() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
283 return namespaceAware;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
284 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
285
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
286 /**
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
287 * Enable and/or disable namespace handling.
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
288 *
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
289 * @param namespaceAware the new desired 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 public void setNamespaceAware(boolean namespaceAware) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
292 this.namespaceAware = namespaceAware;
86
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
293 }
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
294
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 * Check if whitespace preservation is enabled.
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
297 * Defaults to <code>false</code>.
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 * @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
300 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
301 public boolean isPreserveWhitespace() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
302 return preserveWhitespace;
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
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
305 /**
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
306 * Enable and/or disable preservation of whitespace.
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 * @param preserveWhitespace the new desired value
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
309 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
310 public void setPreserveWhitespace(boolean preserveWhitespace) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
311 this.preserveWhitespace = preserveWhitespace;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
312 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
313
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 * Get Quote to use when printing attributes.
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
316 *
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
317 * @return the quote character
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
318 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
319 public String getQuote() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
320 return quote;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
321 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
322
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 * Set Quote to use when printing attributes.
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
325 *
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
326 * @param quote the quote character
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 void setQuote(String quote) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
329 this.quote = quote;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
330 }
86
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
331
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
332 protected void print(Node node, NamespaceContext ctx) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
333 /*
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
334 * 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
335 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
336 if (isEmptyElement(node)) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
337 printLineBegin();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
338 out.print("<");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
339 out.print(getName(node));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
340 if (ctx != null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
341 printNamespace(node, ctx);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
342 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
343 printNameAttributes(node.attributes(), ctx);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
344 out.print("/>");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
345 printLineEnd();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
346 out.flush();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
347 return;
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
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 * 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
352 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
353 if (printSpecialNode(node)) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
354 out.flush();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
355 return;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
356 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
357
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 * Handle normal element like <html> ... </html>.
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 Object value = node.value();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
362 if (value instanceof List) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
363 printName(node, ctx, true, isListOfSimple((List) value));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
364 printList((List) value, ctx);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
365 printName(node, ctx, false, isListOfSimple((List) value));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
366 out.flush();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
367 return;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
368 }
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 // treat as simple type - probably a String
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
371 printName(node, ctx, true, preserveWhitespace);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
372 printSimpleItemWithIndent(value);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
373 printName(node, ctx, false, preserveWhitespace);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
374 out.flush();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
375 }
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 private boolean isListOfSimple(List value) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
378 for (Object p : value) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
379 if (p instanceof Node) return false;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
380 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
381 return preserveWhitespace;
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 protected void printLineBegin() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
385 out.printIndent();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
386 }
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 protected void printLineEnd() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
389 printLineEnd(null);
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 printLineEnd(String comment) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
393 if (comment != null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
394 out.print(" <!-- ");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
395 out.print(comment);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
396 out.print(" -->");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
397 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
398 out.println();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
399 out.flush();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
400 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
401
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
402 protected void printList(List list, NamespaceContext ctx) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
403 out.incrementIndent();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
404 for (Object value : list) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
405 NamespaceContext context = new NamespaceContext(ctx);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
406 /*
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
407 * 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
408 */
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
409 if (value instanceof Node) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
410 print((Node) value, context);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
411 continue;
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 printSimpleItem(value);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
414 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
415 out.decrementIndent();
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 protected void printSimpleItem(Object value) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
419 if (!preserveWhitespace) printLineBegin();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
420 printEscaped(InvokerHelper.toString(value));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
421 if (!preserveWhitespace) printLineEnd();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
422 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
423
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
424 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
425 if (node == null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
426 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
427 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
428 Object name = node.name();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
429 if (name == null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
430 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
431 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
432 if (!preserve || begin) printLineBegin();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
433 out.print("<");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
434 if (!begin) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
435 out.print("/");
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 out.print(getName(node));
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
438 if (ctx != null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
439 printNamespace(node, ctx);
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 if (begin) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
442 printNameAttributes(node.attributes(), ctx);
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 out.print(">");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
445 if (!preserve || !begin) printLineEnd();
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 boolean printSpecialNode(Node node) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
449 return false;
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 printNamespace(Object object, NamespaceContext ctx) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
453 if (namespaceAware) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
454 if (object instanceof Node) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
455 printNamespace(((Node) object).name(), ctx);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
456 } else if (object instanceof QName) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
457 QName qname = (QName) object;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
458 String namespaceUri = qname.getNamespaceURI();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
459 if (namespaceUri != null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
460 String prefix = qname.getPrefix();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
461 if (!ctx.isPrefixRegistered(prefix, namespaceUri)) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
462 ctx.registerNamespacePrefix(prefix, namespaceUri);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
463 out.print(" ");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
464 out.print("xmlns");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
465 if (prefix.length() > 0) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
466 out.print(":");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
467 out.print(prefix);
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 out.print("=" + quote);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
470 out.print(namespaceUri);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
471 out.print(quote);
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 }
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 }
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
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
479
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
480 private boolean isEmptyElement(Node node) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
481 if (node == null) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
482 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
483 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
484 if (!node.children().isEmpty()) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
485 return false;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
486 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
487 return node.text().length() == 0;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
488 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
489
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
490 private String getName(Object object) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
491 if (object instanceof String) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
492 return (String) object;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
493 } else if (object instanceof QName) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
494 QName qname = (QName) object;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
495 if (!namespaceAware) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
496 return qname.getLocalPart();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
497 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
498 return qname.getQualifiedName();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
499 } else if (object instanceof Node) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
500 Object name = ((Node) object).name();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
501 return getName(name);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
502 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
503 return object.toString();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
504 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
505
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
506 private void printSimpleItemWithIndent(Object value) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
507 if (!preserveWhitespace) out.incrementIndent();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
508 printSimpleItem(value);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
509 if (!preserveWhitespace) out.decrementIndent();
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 // 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
513 // 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
514 private void printEscaped(String s) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
515 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
516 char c = s.charAt(i);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
517 switch (c) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
518 case '<':
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
519 out.print("&lt;");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
520 break;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
521 case '>':
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
522 out.print("&gt;");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
523 break;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
524 case '&':
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
525 out.print("&amp;");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
526 break;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
527 case '\'':
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
528 if (quote.equals("'"))
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
529 out.print("&apos;");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
530 else
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
531 out.print(c);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
532 break;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
533 case '"':
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
534 if (quote.equals("\""))
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
535 out.print("&quot;");
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
536 else
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
537 out.print(c);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
538 break;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
539 default:
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
540 out.print(c);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
541 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
542 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
543 }
86
da29f9bde0da groovy script to 'fix' ivy scripts to use standard conventions for configurations
smith@nwoca.org
parents:
diff changeset
544
88
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
545 protected class NamespaceContext {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
546 private final Map<String, String> namespaceMap;
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
547
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
548 public NamespaceContext() {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
549 namespaceMap = new HashMap<String, String>();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
550 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
551
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
552 public NamespaceContext(NamespaceContext context) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
553 this();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
554 namespaceMap.putAll(context.namespaceMap);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
555 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
556
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
557 public boolean isPrefixRegistered(String prefix, String uri) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
558 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
559 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
560
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
561 public void registerNamespacePrefix(String prefix, String uri) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
562 if (!isPrefixRegistered(prefix, uri)) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
563 namespaceMap.put(prefix, uri);
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
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
567 public String getNamespace(String prefix) {
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
568 Object uri = namespaceMap.get(prefix);
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
569 return (uri == null) ? null : uri.toString();
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
570 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
571 }
9f2ab59a5333 improve ivy clean up and control order of attribs
smith@nwoca.org
parents: 86
diff changeset
572 }