-
Notifications
You must be signed in to change notification settings - Fork 3
/
java-xt.xml
198 lines (185 loc) · 8.29 KB
/
java-xt.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version="1.0" encoding="UTF-8"?>
<project
name="ant-hology.taskdefs.java-xt"
basedir="."
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<dirname property="ant-hology.taskdefs.java-xt.dir" file="${ant.file.ant-hology.taskdefs.java-xt}"/>
<import file="${ant-hology.dir}/commonProperties.xml" unless:set="ant-hology.commonProperties.loaded"/>
<import file="${ant-hology.taskdefs.dir}/test.areAllAvailable.xml" unless:set="ant-hology.taskdefs.test.areAllAvailable.loaded"/>
<import file="${ant-hology.pathdefs.dir}/xt.xml" unless:set="ant-hology.pathdefs.xt.loaded"/>
<import file="${ant-hology.pathdefs.dir}/apache-xerces.xml" unless:set="ant-hology.pathdefs.apache-xerces.loaded"/>
<import file="${ant-hology.pathdefs.dir}/apache-commons-xmlresolver.xml" unless:set="ant-hology.pathdefs.apache-commons-xmlresolver.loaded"/>
<import file="${ant-hology.pathdefs.dir}/xmlcatalog.xml" unless:set="ant-hology.pathdefs.xmlcatalog.loaded"/>
<areAllAvailable
property="ant-hology.availableLibraries.xt"
pathRefId="xt.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.apache-xerces"
pathRefId="apache-xerces.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.apache-commons-xmlresolver"
pathRefId="apache-commons-xmlresolver.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.xmlcatalog"
pathRefId="xmlcatalog.required"
/>
<local name="_requiredAvailable"/>
<condition property="_requiredAvailable">
<and>
<isset property="ant-hology.availableLibraries.xt"/>
<isset property="ant-hology.availableLibraries.apache-xerces"/>
<isset property="ant-hology.availableLibraries.apache-commons-xmlresolver"/>
<isset property="ant-hology.availableLibraries.xmlcatalog"/>
</and>
</condition>
<macrodef
name="java-xt"
description="The java-xt macro is an alternative to ant's xslt task that uses xt XSLT processor."
if:set="_requiredAvailable"
>
<attribute
name="xsl"
description="The XSL style sheet."
/>
<attribute
name="srcdir"
default=""
description="Source directory for srcfile."/>
<attribute
name="srcfile"
default=""
description="The source input. This is optional."
/>
<attribute
name="destfile"
default=""
description="The output of the XSL transform. This is optional."
/>
<attribute
name="destdir"
default=""
description="Destination directory for output."/>
<element
name="files"
description="Input files to transform."
optional="true"
/>
<element
name="inputToOutputMapper"
description="Mapper for input file to output file name/path transform."
optional="true"
/>
<!--<element-->
<!--name="parameters"-->
<!--description="Input parameters for the XSL style sheet"-->
<!--optional="true"/>-->
<attribute
name="options"
description="Additional command line options for saxon. For example, stylesheet parameters could be passed."
default=""/>
<attribute name="failonerror" default="true" />
<attribute
name="suppressEcho"
description="Suppress echo if true."
default="false"
/>
<sequential>
<local name="_suppressEcho"/>
<condition property="_suppressEcho">
<equals arg1="@{suppressEcho}" arg2="true"/>
</condition>
<echo unless:set="_suppressEcho">Transforming with xt XSLT processor using apache commons resolver and xmlcatalog</echo>
<pathconvert property="_classpath">
<path refid="xt.classpath"/>
<path refid="apache-xerces.classpath"/>
<path refid="apache-commons-xmlresolver.classpath"/>
<path refid="xmlcatalog.classpath"/>
</pathconvert>
<local name="_filesCount"/>
<local name="_filesEmptyAndHaveSrcAndHaveDest"/>
<resourcecount property="_filesCount">
<resources>
<!--Must wrap in generic resources element because sometimes <files/> is empty-->
<files/>
</resources>
</resourcecount>
<!--<echo>filesCount=${_filesCount} file(s)</echo>-->
<local name="_haveFiles"/>
<condition property="_haveFiles">
<not><equals arg1="${_filesCount}" arg2="0"/></not>
</condition>
<local name="_src"/>
<property name="_src" location="@{srcfile}" if:blank="@{srcdir}" unless:blank="@{srcfile}"/>
<!--Note: _src will not be set if already set, so it does not need to be stated in next case-->
<!--Also: unless:blank intentionally does not have / because the test is whether both are defined-->
<property name="_src" location="@{srcdir}/@{srcfile}" unless:blank="@{srcdir}@{srcfile}"/>
<!--<echo>_src=${_src}</echo>-->
<local name="_isSrcAvailable"/>
<available property="_isSrcAvailable" file="${_src}" type="file" if:set="_src"/>
<local name="_notSrcAvailableAndNoFiles"/>
<condition property="_notSrcAvailableAndNoFiles">
<!--by deMorgan's theorm-->
<!--!_srcAvailable and !_haveFiles == !(_srcAvailable or _haveFiles)-->
<not>
<or>
<isset property="_isSrcAvailable"/>
<isset property="_haveFiles"/>
</or>
</not>
</condition>
<fail if="_notSrcAvailableAndNoFiles" message="Error: <files/> was not defined, and @{srcdir}/@{srcfile} is not set or not available."/>
<local name="_dest"/>
<property name="_dest" location="@{destfile}" if:blank="@{destdir}" unless:blank="@{destfile}"/>
<!--Note: _dest will not be set if already set, so it does not need to be stated in next case-->
<!--Also: unless:blank intentionally does not have / because the test is whether both are defined-->
<property name="_dest" location="@{destdir}/@{destfile}" unless:blank="@{destdir}@{destfile}"/>
<!--<echo>_dest=${_dest}</echo>-->
<!--Note: test ${_dest} inside <sequential if:set="_filesEmptyAndHaveSrcAndHaveDest">-->
<!--This sequential is for the case when user defines <files/>-->
<sequential if:set="_haveFiles">
<!--<echo>Transforming ${_filesCount} file(s).</echo>-->
<apply executable="java" parallel="false" failonerror="@{failonerror}">
<files/>
<inputToOutputMapper/>
<arg value="-cp"/>
<arg value="${_classpath}"/>
<arg value="-Dorg.xml.sax.driver=org.apache.xml.resolver.tools.ResolvingXMLReader"/>
<arg value="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<arg value="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
<arg value="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
<!--Use apache commons resolving parser-->
<arg value="-Dcom.jclark.xsl.sax.parser=org.apache.xml.resolver.tools.ResolvingParser"/>
<arg value="com.jclark.xsl.sax.Driver"/>
<srcfile/>
<arg file="@{xsl}"/>
<targetfile/>
<arg line="@{options}"/>
</apply>
</sequential>
<!--Otherwise there is just a single transform-->
<sequential if:set="_isSrcAvailable" unless:set="_haveFiles">
<exec executable="java" failonerror="@{failonerror}">
<arg value="-cp"/>
<arg value="${_classpath}"/>
<arg value="-Dorg.xml.sax.driver=org.apache.xml.resolver.tools.ResolvingXMLReader"/>
<arg value="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<arg value="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
<arg value="-Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"/>
<!--Use apache commons resolving parser-->
<arg value="-Dcom.jclark.xsl.sax.parser=org.apache.xml.resolver.tools.ResolvingParser"/>
<arg value="com.jclark.xsl.sax.Driver"/>
<arg file="${_src}"/>
<arg file="@{xsl}"/>
<arg file="${_dest}"/>
<arg line="@{options}"/>
</exec>
</sequential>
</sequential>
</macrodef>
<property name="ant-hology.taskdefs.java-xt.loaded" value="true"/>
</project>