-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutil.xml
More file actions
258 lines (243 loc) · 10.2 KB
/
util.xml
File metadata and controls
258 lines (243 loc) · 10.2 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!-- vim: set ft=ant : -->
<project name="util">
<dirname property="root.dir" file="${ant.file.util}" />
<property name="tools.dir" location="${root.dir}/tools" />
<property name="tools.antcontrib" location="${tools.dir}/ant-contrib-1.0b3.jar" />
<taskdef resource="net/sf/antcontrib/antlib.xml"
classpath="${tools.antcontrib}" />
<macrodef name="link">
<attribute name="overwrite"/>
<attribute name="link"/>
<attribute name="resource"/>
<!-- Convert paths -->
<sequential>
<local name="link"/>
<property name="link" location="@{link}"/>
<local name="resource"/>
<property name="resource" location="@{resource}"/>
<if>
<os family="windows" />
<then>
<if>
<and>
<or>
<istrue value="${overwrite}" />
<not>
<available file="${link}"/>
</not>
</or>
<available file="${resource}"/>
</and>
<then>
<if>
<available file="${resource}" type="dir"/>
<then>
<exec resolveexecutable="true" executable="cmd.exe">
<arg value="/C"/>
<arg value="mklink"/>
<arg value="/J"/>
<arg value="${link}"/>
<arg value="${resource}"/>
</exec>
</then>
<else>
<exec resolveexecutable="true" executable="cmd.exe">
<arg value="/C"/>
<arg value="mklink"/>
<arg value="/H"/>
<arg value="${link}"/>
<arg value="${resource}"/>
</exec>
</else>
</if>
</then>
</if>
</then>
<else>
<symlink overwrite="@{overwrite}" link="${link}" resource="${resource}" />
</else>
</if>
</sequential>
</macrodef>
<macrodef name="jsonpath">
<attribute name="property" />
<attribute name="basedir" default="${basedir}" />
<attribute name="prefix" default="" />
<element name="paths" implicit="true" />
<sequential>
<local name="contents" />
<pathconvert dirsep="/" property="contents" pathsep='", "'>
<paths />
<!-- Relative -->
<map from="@{basedir}/" to="@{prefix}" />
</pathconvert>
<property name="@{property}" value='["${contents}"]' />
</sequential>
</macrodef>
<macrodef name="yuicompress">
<attribute name="type"/>
<attribute name="output"/>
<element name="yuiel" implicit="true"/>
<text name="text"/>
<sequential>
<if>
<not>
<uptodate targetfile="@{output}">
<srcresources>
<resources>
<yuiel />
</resources>
</srcresources>
</uptodate>
</not>
<then>
<local name="input" />
<loadresource property="input">
<concat>
<header trim="true">@{text}</header>
<yuiel />
</concat>
</loadresource>
<local name="output_directory" />
<dirname property="output_directory" file="@{output}" />
<mkdir dir="${output_directory}" />
<echo level="verbose"
message="Writing: ${dest_file}" />
<java inputstring="${input}" jar="${tools.yuicompressor}" fork="true" logError="true" failonerror="true" output="@{output}">
<arg value="--type"/>
<arg value="@{type}"/>
</java>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="htmltemplate">
<attribute name="output" />
<attribute name="input" />
<attribute name="scripts"/>
<attribute name="stylesheets"/>
<element name="variables" optional="true"/>
<sequential>
<parallel>
<sequential>
<var name="html_scripts" value=""/>
<for param="src" list="@{scripts}" delimiter=":">
<sequential>
<var
name="html_scripts"
value="${html_scripts}<script src='@{src}'></script>${line.separator}"
/>
</sequential>
</for>
</sequential>
<sequential>
<var name="html_stylesheets" value=""/>
<for param="src" list="@{stylesheets}" delimiter=":">
<sequential>
<var
name="html_stylesheets"
value="${html_stylesheets}<link rel='stylesheet' type='text/css' href='@{src}' />${line.separator}"
/>
</sequential>
</for>
</sequential>
</parallel>
<copy verbose="true" file="@{input}" tofile="@{output}" overwrite="true">
<filterchain>
<replacetokens>
<token key="scripts" value="${html_scripts}"/>
<token key="stylesheets" value="${html_stylesheets}"/>
<variables />
</replacetokens>
</filterchain>
</copy>
</sequential>
</macrodef>
<macrodef name="rmdir">
<attribute name="dir" />
<sequential>
<if>
<available file="@{dir}" />
<then>
<fail message="Not a directory: @{dir}">
<condition>
<not>
<available type="dir" file="@{dir}" />
</not>
</condition>
</fail>
<if>
<os family="windows" />
<then>
<exec failifexecutionfails="true"
failonerror="true"
resolveexecutable="true"
executable="cmd.exe">
<arg value="/C"/>
<arg value="rmdir"/>
<arg value="@{dir}"/>
<arg value="/s"/>
<arg value="/q"/>
</exec>
</then>
<else>
<delete verbose="true"
includeemptydirs="true" removeNotFollowedSymlinks="true">
<fileset erroronmissingdir="false"
followsymlinks="false" dir="@{dir}" includes="**/*" />
</delete>
<!-- remove broken symlinks -->
<delete dir="@{dir}" verbose="true" includeemptydirs="true"/>
</else>
</if>
</then>
</if>
</sequential>
</macrodef>
<scriptdef name="jstmpl" language="javascript">
<attribute name="output" />
<attribute name="object" />
<element name="fileset" type="fileset"/>
<![CDATA[
var imports = JavaImporter(Packages.java.io, Packages.org.apache.tools.ant.util);
var FileWriter = imports.FileWriter;
var FileReader = imports.FileReader;
var File = imports.File;
var FileUtils = imports.FileUtils;
var br = String(project.getProperty("line.separator"));
function readFile(file) {
var contents = String(new java.lang.String(FileUtils.readFully(new FileReader(file)) || ""));
contents = contents.replace(new RegExp(br, 'g'), '\n');
return contents;
}
function writeFile(file, text) {
text = String(text).replace(/\n/g, br);
var fw = new FileWriter(file);
fw.write(text);
fw.close();
}
function load(file) {
eval(readFile(file));
}
load(FileUtils.translatePath(project.getProperty("tools.underscore")));
var objectName = String(attributes.get("object"));
var outputFile = attributes.get("output");
var filesets = elements.get("fileset");
var src = "/* Generated Template */\n\n"
for (var i = 0; i < filesets.size(); i++) {
var fileset = filesets.get(i);
var basedir = fileset.getDir(project);
var files = fileset.getDirectoryScanner(project).getIncludedFiles();
for (var j = 0; j < files.length; j++) {
var filename = files[j];
var file = new File(basedir, filename);
var contents = readFile(file);
var basename = String(filename).replace(/\\/g, '/').slice(0, -5);
self.log("Compiling " + filename);
src += objectName + "['" + basename + "'] = " + _.template(contents).source + ";" + '\n';
}
}
writeFile(outputFile, src);
]]>
</scriptdef>
</project>