-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathbuild.xml
494 lines (470 loc) · 21.8 KB
/
build.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
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<?xml version="1.0" encoding="UTF-8"?>
<project name="example" default="compile" xmlns:if="ant:if" xmlns:unless="ant:unless">
<!-- all properties are in build.properties -->
<!--property file="build.properties" /-->
<property environment="env" />
<property name="config.dir" value="config" />
<import file="${basedir}/${config.dir}/properties.xml" />
<import file="${basedir}/${config.dir}/jnlp.xml" />
<condition property="jdk9orlater">
<javaversion atleast="9" />
</condition>
<condition property="have.library">
<available file="${lib.dir}" />
</condition>
<!-- =================================================================== -->
<!-- classpath to use within project -->
<!-- =================================================================== -->
<path id="project.class.path">
<!-- compiled classes directory -->
<pathelement location="${build.dest}" />
<!-- all jars in jar directory -->
<pathelement location="${java.home}/lib/javaws.jar" />
<!-- system property, environment classpath -->
<pathelement path="${java.class.path}" />
<!-- all jars in lib directory -->
<fileset dir="${lib.dir}" includes="*.jar" if:set="have.library" />
</path>
<!-- =================================================================== -->
<!-- Help on usage -->
<!-- =================================================================== -->
<target name="usage">
<echo message="" />
<echo message="" />
<echo message="${Name} Build file" />
<echo message="-------------------------------------------------------------" />
<echo message="" />
<echo message=" available targets are:" />
<echo message="" />
<echo message=" compile - compiles the source code (default)" />
<echo message=" run - execute the example" />
<echo message=" package - generates the example.jar file" />
<echo message=" javadoc - generates the API documentation" />
<echo message=" clean - cleans up the directory" />
<echo message="" />
<echo message=" See the comments inside the build.xml file for more details." />
<echo message="-------------------------------------------------------------" />
<echo message="" />
<echo message="" />
</target>
<!-- =================================================================== -->
<!-- Prepares the build directory -->
<!-- =================================================================== -->
<target name="prepare">
<echo message="----------- ${Name} ${version} [${year}] ------------" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dest}" />
</target>
<!-- =================================================================== -->
<!-- Prepares the source code -->
<!-- =================================================================== -->
<target name="prepare-src" depends="prepare">
<mkdir dir="${build.src}" />
<filter token="title" value="${jnlp.title}" />
<filter token="homepage" value="${jnlp.homepage}" />
<copy todir="${build.src}" filtering="yes"
encoding="${compile.encoding}"
outputencoding="${compile.encoding}">
<fileset dir="${src.dir}" includes="**/*.java" />
</copy>
<copy todir="${build.src}">
<fileset dir="${src.dir}" excludes="**/*.java, **/*.bak" />
</copy>
<copy todir="${build.dest}">
<fileset dir="${src.dir}" excludes="**/*.java, **/*.bak, **/*.utf8" />
</copy>
</target>
<!-- =================================================================== -->
<!-- Compiles the source directory -->
<!-- =================================================================== -->
<target name="compile" depends="prepare-src">
<javac srcdir="${build.src}"
includes="**/*.java"
destdir="${build.dest}"
encoding="${compile.encoding}"
debug="${compile.debug}"
optimize="${compile.optimize}"
deprecation="${compile.deprecation}"
includeAntRuntime="no"
fork="true"
classpathref="project.class.path">
<compilerarg value="-J-Dfile.encoding=${compile.encoding}" />
<compilerarg value="-J-Duser.language=${user.language}" />
<compilerarg value="--add-exports=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="--add-exports=java.desktop/sun.awt.shell=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>
<!-- =================================================================== -->
<!-- Execute the example -->
<!-- =================================================================== -->
<target name="run" depends="compile">
<java classname="${main.class}" classpathref="project.class.path" fork="true">
<jvmarg value="-Dfile.encoding=${compile.encoding}" />
<jvmarg value="-Duser.language=${user.language}" />
<jvmarg value="--add-opens=java.desktop/javax.swing=ALL-UNNAMED" if:set="jdk9orlater" />
<jvmarg value="--add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED" if:set="jdk9orlater" />
<jvmarg value="--add-opens=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED" if:set="jdk9orlater" />
<jvmarg value="--add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED" if:set="jdk9orlater" />
</java>
</target>
<!-- =================================================================== -->
<!-- Creates the class package -->
<!-- =================================================================== -->
<target name="package" depends="compile">
<echo message="Creating the jar file ${build.dir}/${name}.jar" />
<tstamp>
<format property="ts" pattern="yyyyMMdd-HHmmss-z" />
</tstamp>
<jar jarfile="${build.dir}/${name}.jar" basedir="${build.dest}">
<manifest>
<attribute name="Main-Class" value="${main.class}" />
<attribute name="Class-Path" value="${runtime.classpath}" />
<attribute name="Implementation-Title" value="${Name}" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Implementation-Vendor" value="${vendor}" />
<attribute name="Build-Id" value="${ts} (${user.name} [${os.name} ${os.version} ${os.arch}])" />
</manifest>
</jar>
</target>
<!-- =================================================================== -->
<!-- Creates the API documentation -->
<!-- =================================================================== -->
<target name="javadoc" depends="prepare-src">
<mkdir dir="${build.docs}" />
<javadoc packagenames="${javadoc.pkgs}"
sourcepath="${build.src}"
classpathref="project.class.path"
destdir="${build.docs}"
author="true"
version="true"
use="true"
splitindex="true"
noindex="false"
windowtitle="${Name} API"
doctitle="${Name}"
bottom="Copyright © ${year} ${vendor} All Rights Reserved."
encoding="${javadoc.encoding}"
docencoding="${javadoc.docencoding}"
locale="${javadoc.locale}" />
</target>
<!-- =================================================================== -->
<!-- Creates the API documentation, with links to JDK 1.4 classes -->
<!-- We can use linkoffline with a newer Ant and avoid this target -->
<!-- =================================================================== -->
<target name="javadoc-link" depends="prepare-src">
<mkdir dir="${build.docs}" />
<javadoc packagenames="${javadoc.pkgs}"
sourcepath="${build.src}"
classpathref="project.class.path"
destdir="${build.docs}"
author="true"
version="true"
use="true"
splitindex="true"
noindex="false"
windowtitle="${Name} API"
doctitle="${Name}"
bottom="Copyright © ${year} ${vendor} All Rights Reserved."
encoding="${javadoc.encoding}"
docencoding="${javadoc.docencoding}"
locale="${javadoc.locale}">
<link href="${javadoc.link}" />
<classpath refid="project.class.path" />
</javadoc>
</target>
<!-- =================================================================== -->
<!-- Clean targets -->
<!-- =================================================================== -->
<target name="clean">
<delete dir="${build.dir}" />
</target>
<!-- End of file -->
<condition property="have.web">
<available file="${web.dir}" />
</condition>
<target name="prepare-web" depends="prepare" if="have.web">
<filter token="codebase" value="${jnlp.codebase}" />
<filter token="title" value="${jnlp.title}" />
<filter token="homepage" value="${jnlp.homepage}" />
<filter token="vendor" value="${vendor}" />
<filter token="main.class" value="${main.class}" />
<filter token="compile.source" value="${compile.source}" />
<copy todir="${build.dir}" filtering="yes"
encoding="${compile.encoding}"
outputencoding="${compile.encoding}">
<fileset dir="${web.dir}" includes="**/*.jnlp **/*.html" />
</copy>
<copy todir="${build.dir}" filtering="no">
<fileset dir="${web.dir}" excludes="**/*.jnlp **/*.html **/*.bak" />
</copy>
</target>
<target name="dist" depends="package, prepare-web">
<tstamp>
<format property="tstamp" pattern="HHmmss" />
</tstamp>
<mkdir dir="${build.dir}/${tstamp}" />
<filter token="homepage" value="${jnlp.homepage}" />
<filter token="title" value="${jnlp.Name}" />
<copy todir="${build.dir}/${tstamp}/${src.dir}" filtering="yes"
encoding="${compile.encoding}"
outputencoding="${compile.encoding}">
<fileset dir="${src.dir}" includes="**/*.java" />
</copy>
<copy todir="${build.dir}/${tstamp}/${src.dir}">
<fileset dir="${src.dir}" excludes="**/*.java, **/*.bak" />
</copy>
<copy todir="${build.dir}/${tstamp}">
<fileset dir=".">
<include name="build.xml" />
<include name="*.bat" />
<include name="*.sh" />
<include name="${config.dir}/**/*.xml" />
<include name="${web.dir}/*.jnlp" />
<include name="${lib.dir}/*.jar" if:set="have.library" />
</fileset>
</copy>
<zip destfile="${build.dir}/src.zip" basedir="${build.dir}/${tstamp}" includes="**" />
<delete dir="${build.dir}/${tstamp}" />
</target>
<target name="test" depends="compile">
<junit printsummary="yes" haltonfailure="no">
<formatter type="xml" />
<classpath>
<pathelement location="${build.dest}" />
<pathelement path="${java.class.path}" />
</classpath>
<batchtest fork="yes" todir="${build.reports}">
<fileset dir="${src.dir}" includes="**/*Test.java" />
</batchtest>
</junit>
<junitreport todir="${build.reports}">
<fileset dir="${build.reports}" includes="TEST-*.xml" />
<report format="frames" todir="${build.correctreports}" />
</junitreport>
</target>
<!-- static code analysis -->
<property name="sca.dir" value="${user.dir}" />
<target name="errorprone" depends="prepare-src">
<!-- using github.com/google/error-prone-javac is required when running on JDK 8 -->
<property name="javac.jar" location="${env.ERRORPRONE_HOME}/javac-9+181-r4173-1.jar" />
<path id="processorpath.ref">
<fileset dir="${env.ERRORPRONE_HOME}">
<include name="*.jar" />
<exclude name="error_prone_core-2.10.0-with-dependencies.jar" if:set="jdk9orlater" />
<exclude name="javac-9+181-r4173-1.jar" if:set="jdk9orlater" />
<exclude name="jFormatString-3.0.0.jar" if:set="jdk9orlater" />
</fileset>
</path>
<javac srcdir="${build.src}"
destdir="${build.dest}"
encoding="${compile.encoding}"
fork="yes"
includeAntRuntime="no">
<include name="**/*.java" />
<exclude name="**/module-info.java" unless:set="jdk9orlater" />
<compilerarg value="-J-Xbootclasspath/p:${javac.jar}" unless:set="jdk9orlater" />
<compilerarg value="-XDcompilePolicy=simple" />
<compilerarg value="--should-stop=ifError=FLOW" if:set="jdk9orlater" />
<compilerarg value="-processorpath" />
<compilerarg pathref="processorpath.ref" />
<compilerarg value="-Xplugin:ErrorProne -Xep:DeadException:ERROR -Xep:MultipleTopLevelClasses:OFF" />
<compilerarg value="-J-Dfile.encoding=UTF-8" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED" if:set="jdk9orlater" />
<compilerarg value="--add-exports=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED" if:set="jdk9orlater" />
</javac>
</target>
<target name="ecj" depends="prepare-src">
<javac srcdir="${build.src}"
excludes="**/module-info.java"
includes="**/*.java"
destdir="${build.dest}"
encoding="${compile.encoding}"
debug="${compile.debug}"
optimize="${compile.optimize}"
deprecation="${compile.deprecation}"
includeAntRuntime="false"
classpathref="project.class.path">
<compilerclasspath>
<fileset dir="${env.ECJ_HOME}" includes="*.jar" />
</compilerclasspath>
<compilerarg compiler="org.eclipse.jdt.core.JDTCompilerAdapter" line="-warn:-serial,-warningToken" />
<compilerarg value="--add-exports=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED" if:set="jdk9orlater" />
</javac>
</target>
<condition property="have.spotbugs">
<available file="${env.SPOTBUGS_HOME}" />
</condition>
<target name="spotbugs" depends="compile" if="have.spotbugs">
<echo>${env.SPOTBUGS_HOME}</echo>
<path id="spotbugs.classpath">
<fileset dir="${env.SPOTBUGS_HOME}/lib" includes="*-ant.jar" />
</path>
<taskdef resource="edu/umd/cs/findbugs/anttask/tasks.properties" classpathref="spotbugs.classpath" />
<mkdir dir="${build.reports}" />
<spotbugs home="${env.SPOTBUGS_HOME}" effort="max" reportLevel="low"
excludeFilter="${sca.dir}/excludefilter.xml"
output="xml" outputFile="${build.reports}/spotbugs.xml">
<sourcePath path="${src.dir}" />
<class location="${build.dest}" />
</spotbugs>
</target>
<condition property="have.pmd">
<available file="${env.PMD_HOME}" />
</condition>
<target name="pmd" if="have.pmd">
<path id="pmd.classpath">
<fileset dir="${env.PMD_HOME}/lib" includes="*.jar" />
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath" />
<mkdir dir="${build.reports}" />
<pmd rulesetfiles="${sca.dir}/ruleset.xml" cacheLocation="${env.TEMP}/pmd/pmd.cache" encoding="${compile.encoding}">
<classpath refid="project.class.path" />
<formatter type="xml" toFile="${build.reports}/pmd.xml" />
<formatter type="text" toConsole="true" />
<fileset dir="${src.dir}" excludes="**/module-info.java" includes="**/*.java" />
</pmd>
</target>
<condition property="have.checkstyle">
<available file="${env.CHECKSTYLE_HOME}" />
</condition>
<target name="checkstyle" if="have.checkstyle">
<path id="checkstyle.classpath">
<fileset dir="${env.CHECKSTYLE_HOME}">
<include name="*-all.jar" if:set="jdk9orlater" />
<exclude name="checkstyle-9.3-all.jar" if:set="jdk9orlater" />
<include name="checkstyle-9.3-all.jar" unless:set="jdk9orlater" />
</fileset>
</path>
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties" classpathref="checkstyle.classpath" />
<mkdir dir="${build.reports}" />
<property name="checkstyle.config" location="${sca.dir}/checks.xml" unless:set="checkstyle.config" />
<echo message="checkstyle.config: ${checkstyle.config}" />
<checkstyle config="${checkstyle.config}" failOnViolation="false">
<formatter type="plain" />
<formatter type="xml" toFile="${build.reports}/checkstyle-result.xml" />
<fileset dir="${src.dir}">
<exclude name="**/build/**" />
<exclude name="**/target/**" />
<exclude name="**/module-info.java" unless:set="jdk9orlater" />
<include name="**/*.java" />
</fileset>
</checkstyle>
</target>
<target name="reports" depends="clean,spotbugs,pmd,checkstyle">
</target>
<fileset id="ftp.upload.fileset" dir="${build.dir}">
<include name="${name}.*" />
<include name="*.jar" />
<include name="src.zip" />
<include name="*.png" />
<include name="index.html" />
</fileset>
<target name="ftp" depends="dist">
<property name="ftp.userid" value="${env.FTP_USERID}" />
<property name="ftp.server" value="${env.FTP_SERVER}" />
<property name="ftp.remotedir" value="${env.FTP_BASEDIR}${jnlp.name}" />
<property name="ssh.inkey" value="${env.SSH_INKEY}" />
<property name="ssh.in" value="${env.SSH_IN}" />
<exec executable="openssl" outputproperty="ftp.password" failonerror="true">
<arg value="pkeyutl" />
<arg value="-decrypt" />
<arg value="-inkey" />
<arg value="${ssh.inkey}" />
<arg value="-in" />
<arg value="${ssh.in}" />
</exec>
<ftp action="mkdir"
server="${ftp.server}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
useFtps="true"
passive="yes" verbose="yes" />
<ftp server="${ftp.server}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
useFtps="true"
passive="yes" verbose="yes">
<fileset refid="ftp.upload.fileset" />
</ftp>
</target>
<target name="ftps">
<echo message="ftps" />
<property name="ftp.userid" value="${env.FTP_USERID}" />
<property name="ftp.server" value="${env.FTP_SERVER}" />
<property name="ftp.remotedir" value="${env.FTP_BASEDIR}${jnlp.name}" />
<property name="ssh.inkey" value="${env.SSH_INKEY}" />
<property name="ssh.in" value="${env.SSH_IN}" />
<exec executable="openssl" outputproperty="ftp.password" failonerror="true">
<arg value="pkeyutl" />
<arg value="-decrypt" />
<arg value="-inkey" />
<arg value="${ssh.inkey}" />
<arg value="-in" />
<arg value="${ssh.in}" />
</exec>
<ftps server="${ftp.server}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}">
<fileset refid="ftp.upload.fileset" />
</ftps>
</target>
<scriptdef name="ftps" language="javascript">
<attribute name="server" />
<attribute name="remotedir" />
<attribute name="userid" />
<attribute name="password" />
<element name="fileset" type="fileset" />
<![CDATA[
var server = attributes.get("server");
var remotedir = attributes.get("remotedir");
var username = attributes.get("userid");
var password = attributes.get("password");
try {
var ftps = new org.apache.commons.net.ftp.FTPSClient("SSL");
ftps.connect(server);
var reply = ftps.getReplyCode();
if (!org.apache.commons.net.ftp.FTPReply.isPositiveCompletion(reply)) {
ftps.disconnect();
print("FTP server refused connection.");
System.exit(1);
}
// ftps.setBufferSize(1048576);
if (!ftps.login(username, password)) {
print("FTP server refused connection.");
} else {
print("Remote system is " + ftps.getSystemName());
ftps.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
ftps.enterLocalPassiveMode();
ftps.makeDirectory(remotedir);
var filesets = elements.get("fileset");
for (i = 0; i < filesets.size(); i++) {
var fileset = filesets.get(i);
var scanner = fileset.getDirectoryScanner(project);
scanner.scan();
var basedir = fileset.getDir(project);
var files = scanner.getIncludedFiles();
for(j = 0; j < files.length; j++) {
var filename = files[j];
var local = new java.io.File(basedir, filename);
print("file: " + remotedir + "/" + filename);
var input = new java.io.FileInputStream(local);
ftps.storeFile(remotedir + "/" + filename, input);
input.close();
}
}
}
ftps.logout();
} catch (ex) {
ex.printStackTrace();
}
ftps.disconnect();
]]>
</scriptdef>
</project>