Repository navigation
Expand file tree
/
Copy pathbuild.xml
More file actions
403 lines (362 loc) · 16.2 KB
/
Copy pathbuild.xml
File metadata and controls
403 lines (362 loc) · 16.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
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
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyAntApp" default="package" basedir="."
xmlns:jacoco="antlib:org.jacoco.ant">
<property file="build.properties"/>
<property name="app.name" value="AssignmentTracker"/>
<property name="app.version" value="1.2.1"/>
<property name="main.class" value="Main"/>
<property name="src.dir" value="src"/>
<property name="test.src" value="test"/>
<property name="build.dir" value="build/classes"/>
<property name="test.build" value="build/test-classes"/>
<property name="jar.dir" value="build/jar"/>
<property name="dist.dir" value="dist"/>
<property name="docs.dir" value="build/docs"/>
<property name="junit.jar" value="lib/junit-platform-console-standalone.jar"/>
<property name="junit.url" value="https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/1.11.4/junit-platform-console-standalone-1.11.4.jar"/>
<!-- FlatLaf: modern Look & Feel for Swing. Auto-downloaded like junit.jar. -->
<property name="flatlaf.jar" value="lib/flatlaf-3.5.4.jar"/>
<property name="flatlaf.url" value="https://repo1.maven.org/maven2/com/formdev/flatlaf/3.5.4/flatlaf-3.5.4.jar"/>
<property name="flatlaf-themes.jar" value="lib/flatlaf-intellij-themes-3.5.4.jar"/>
<property name="flatlaf-themes.url" value="https://repo1.maven.org/maven2/com/formdev/flatlaf-intellij-themes/3.5.4/flatlaf-intellij-themes-3.5.4.jar"/>
<!-- Javadoc external API links. Uses the JDK running Ant; no hard-coded Java version. -->
<condition property="javadoc.api.url" value="https://docs.oracle.com/javase/8/docs/api/">
<equals arg1="${java.specification.version}" arg2="1.8"/>
</condition>
<condition property="javadoc.api.url" value="https://docs.oracle.com/en/java/javase/${java.specification.version}/docs/api/">
<not>
<equals arg1="${java.specification.version}" arg2="1.8"/>
</not>
</condition>
<macrodef name="generate-javadoc">
<attribute name="access-level" default="protected"/>
<attribute name="output-subdir"/>
<sequential>
<mkdir dir="${docs.dir}/@{output-subdir}"/>
<javadoc destdir="${docs.dir}/@{output-subdir}"
source="1.8"
encoding="UTF-8"
use="true"
author="true"
version="true"
failonerror="true"
access="@{access-level}">
<fileset dir="${src.dir}" includes="**/*.java"/>
<link href="${javadoc.api.url}"/>
<!-- Uncomment to resolve references in Javadoc comments to lib/ jars. -->
<!--
<classpath>
<pathelement path="${build.dir}"/>
<fileset dir="lib" includes="**/*.jar" erroronmissingdir="false"/>
</classpath>
-->
</javadoc>
</sequential>
</macrodef>
<condition property="isMac">
<os family="mac"/>
</condition>
<condition property="isLinux">
<and>
<os family="unix"/>
<not><os family="mac"/></not>
</and>
</condition>
<condition property="isWindows">
<os family="windows"/>
</condition>
<condition property="icon.file" value="icon.icns">
<isset property="isMac"/>
</condition>
<condition property="icon.file" value="icon.ico">
<and>
<isset property="isWindows"/>
<not><isset property="icon.file"/></not>
</and>
</condition>
<condition property="icon.file" value="icon.png">
<not><isset property="icon.file"/></not>
</condition>
<target name="preflight" description="Print toolchain/OS info">
<echo message="Java: ${java.runtime.name} ${java.runtime.version}"/>
<echo message="Java Vendor: ${java.vendor}"/>
<echo message="Java Home: ${java.home}"/>
<echo message="Java Spec Version: ${java.specification.version}"/>
<echo message="OS: ${os.name} ${os.version} (${os.arch})"/>
</target>
<target name="clean" description="Remove all build and distribution files">
<delete dir="build"/>
<delete dir="${dist.dir}"/>
</target>
<target name="download-flatlaf" description="Download FlatLaf and FlatLaf IntelliJ Themes JARs if not present">
<mkdir dir="lib"/>
<get src="${flatlaf.url}" dest="${flatlaf.jar}" skipexisting="true"/>
<get src="${flatlaf-themes.url}" dest="${flatlaf-themes.jar}" skipexisting="true"/>
</target>
<target name="compile" depends="preflight, download-flatlaf" description="Compile Java source code">
<mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}"
destdir="${build.dir}"
includeantruntime="false"
debug="true">
<classpath>
<pathelement path="${flatlaf.jar}"/>
<pathelement path="${flatlaf-themes.jar}"/>
</classpath>
</javac>
</target>
<!-- Bundle FlatLaf classes into the app JAR so `ant run` and jpackage both
work without needing a separate classpath entry. -->
<target name="jar" depends="compile" description="Package classes into an executable JAR">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${app.name}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Implementation-Version" value="${app.version}"/>
</manifest>
<zipgroupfileset file="${flatlaf.jar}"/>
<zipgroupfileset file="${flatlaf-themes.jar}"/>
</jar>
</target>
<target name="run" depends="jar" description="Run the application from the JAR for testing">
<java jar="${jar.dir}/${app.name}.jar" fork="true"/>
</target>
<target name="javadoc" depends="preflight" description="Generate standard API documentation">
<generate-javadoc access-level="protected" output-subdir="api"/>
</target>
<target name="javadoc-internal" depends="preflight" description="Generate internal documentation (includes private members)">
<generate-javadoc access-level="private" output-subdir="internal"/>
</target>
<target name="javadoc-all" depends="javadoc, javadoc-internal" description="Generate both standard and internal documentation sets"/>
<target name="package" description="Build the native installer for the current OS (DMG, DEB, or MSI)">
<antcall target="dmg"/>
<antcall target="debian"/>
<antcall target="windows"/>
</target>
<target name="dmg" depends="jar" if="isMac" description="[Mac Only] Builds the .dmg installer">
<mkdir dir="${dist.dir}"/>
<exec executable="jpackage" failonerror="true">
<arg value="--input"/><arg value="${jar.dir}"/>
<arg value="--dest"/><arg value="${dist.dir}"/>
<arg value="--name"/><arg value="${app.name}"/>
<arg value="--main-jar"/><arg value="${app.name}.jar"/>
<arg value="--main-class"/><arg value="${main.class}"/>
<arg value="--type"/><arg value="dmg"/>
<arg value="--icon"/><arg value="${icon.file}"/>
<arg value="--app-version"/><arg value="${app.version}"/>
<arg value="--mac-package-name"/><arg value="${app.name}"/>
<arg value="--mac-package-identifier"/><arg value="com.example.${app.name}"/>
</exec>
<move todir="${dist.dir}">
<fileset dir="${dist.dir}">
<include name="${app.name}*.dmg"/>
<exclude name="${app.name}-Installer.dmg"/>
</fileset>
<mapper type="merge" to="${app.name}-Installer.dmg"/>
</move>
<echo message="Success! MacOS Installer: ${dist.dir}/${app.name}-Installer.dmg"/>
</target>
<target name="debian" depends="jar" if="isLinux" description="[Linux Only] Builds the .deb package">
<mkdir dir="${dist.dir}"/>
<exec executable="jpackage" failonerror="true">
<arg value="--input"/><arg value="${jar.dir}"/>
<arg value="--dest"/><arg value="${dist.dir}"/>
<arg value="--name"/><arg value="${app.name}"/>
<arg value="--main-jar"/><arg value="${app.name}.jar"/>
<arg value="--main-class"/><arg value="${main.class}"/>
<arg value="--type"/><arg value="deb"/>
<arg value="--icon"/><arg value="${icon.file}"/>
<arg value="--app-version"/><arg value="${app.version}"/>
<arg value="--linux-shortcut"/>
</exec>
<move todir="${dist.dir}">
<fileset dir="${dist.dir}">
<include name="*.deb"/>
<exclude name="${app.name}-Linux.deb"/>
</fileset>
<mapper type="merge" to="${app.name}-Linux.deb"/>
</move>
<echo message="Success! Debian Package: ${dist.dir}/${app.name}-Linux.deb"/>
</target>
<target name="windows" depends="jar" if="isWindows" description="[Windows Only] Builds the .msi installer">
<mkdir dir="${dist.dir}"/>
<exec executable="jpackage" failonerror="true">
<arg value="--input"/><arg value="${jar.dir}"/>
<arg value="--dest"/><arg value="${dist.dir}"/>
<arg value="--name"/><arg value="${app.name}"/>
<arg value="--main-jar"/><arg value="${app.name}.jar"/>
<arg value="--main-class"/><arg value="${main.class}"/>
<arg value="--type"/><arg value="msi"/>
<arg value="--icon"/><arg value="${icon.file}"/>
<arg value="--app-version"/><arg value="${app.version}"/>
<arg value="--win-upgrade-uuid"/>
<arg value="123e4567-e89b-12d3-a456-426614174000"/>
<arg value="--win-dir-chooser"/>
<arg value="--win-shortcut"/>
<arg value="--win-menu"/>
</exec>
<move todir="${dist.dir}">
<fileset dir="${dist.dir}">
<include name="${app.name}*.msi"/>
<exclude name="${app.name}-Windows.msi"/>
</fileset>
<mapper type="merge" to="${app.name}-Windows.msi"/>
</move>
<echo message="Success! Windows Installer: ${dist.dir}/${app.name}-Windows.msi"/>
</target>
<!-- ======================== Testing ======================== -->
<target name="download-junit" description="Download JUnit JAR if not present">
<mkdir dir="lib"/>
<get src="${junit.url}" dest="${junit.jar}" skipexisting="true"/>
</target>
<target name="test-compile" depends="compile, download-junit" description="Compile test sources">
<mkdir dir="${test.build}"/>
<javac srcdir="${test.src}"
destdir="${test.build}"
includeantruntime="false"
debug="true">
<classpath>
<pathelement path="${build.dir}"/>
<pathelement path="${junit.jar}"/>
<pathelement path="${flatlaf.jar}"/>
<pathelement path="${flatlaf-themes.jar}"/>
</classpath>
</javac>
</target>
<target name="test" depends="test-compile" description="Run JUnit tests">
<java jar="${junit.jar}" fork="true" failonerror="true">
<arg value="execute"/>
<arg value="--class-path"/><arg value="${build.dir}${path.separator}${test.build}${path.separator}${flatlaf.jar}${path.separator}${flatlaf-themes.jar}"/>
<arg value="--scan-class-path=${test.build}"/>
</java>
</target>
<!-- ====================== Quality Tool Definitions ====================== -->
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
classpath="${tool.jars}/checkstyle-13.3.0-all.jar"/>
<path id="pmd.path">
<fileset dir="${pmd.home}/lib">
<include name="*.jar"/>
</fileset>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"
classpathref="pmd.path"/>
<taskdef name="cpd" classname="net.sourceforge.pmd.ant.CPDTask"
classpathref="pmd.path"/>
<taskdef resource="edu/umd/cs/findbugs/anttask/tasks.properties"
classpath="${spotbugs.home}/lib/spotbugs-ant.jar"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${tool.jars}/jacocoant.jar"/>
</taskdef>
<!-- ========================= Quality Targets =========================== -->
<target name="quality" depends="checkstyle,pmd,cpd,spotbugs,test-coverage"
description="Run all quality checks: Checkstyle, PMD, CPD, SpotBugs, JUnit+JaCoCo">
<echo>Quality results in: ${results.dir}/</echo>
</target>
<target name="checkstyle" depends="compile" description="Check coding conventions with Checkstyle">
<mkdir dir="${results.dir}"/>
<echo>Running Checkstyle</echo>
<checkstyle config="${checkstyle.dir}/checkstyle-master.xml"
failureProperty="checkstyle.failure"
failOnViolation="false">
<fileset dir="${src.dir}" includes="**/*.java"/>
<property key="checkstyle.dir" value="${checkstyle.dir}"/>
<property key="checkstyle.suppressions.file"
value="${checkstyle.dir}/${checkstyle.suppressions.file}"/>
<property key="checkstyle.importcontrol.file"
value="${checkstyle.dir}/${checkstyle.importcontrol.file}"/>
<property key="translation.severity" value="${translation.severity}"/>
<formatter type="plain" tofile="${results.dir}/checkstyle_report.txt"/>
<formatter type="xml" tofile="${results.dir}/checkstyle_report.xml"/>
</checkstyle>
<xslt in="${results.dir}/checkstyle_report.xml"
out="${results.dir}/checkstyle_report.html"
style="${checkstyle.dir}/contrib/checkstyle-noframes.xsl"/>
<echo>Checkstyle report: ${results.dir}/checkstyle_report.html</echo>
</target>
<target name="pmd" depends="compile" description="Detect code weaknesses with PMD">
<mkdir dir="${results.dir}"/>
<echo>Running PMD</echo>
<pmd noCache="true">
<ruleset>tools/pmd/ruleset.xml</ruleset>
<formatter type="xml" toFile="${results.dir}/pmd_report.xml"/>
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</pmd>
<xslt in="${results.dir}/pmd_report.xml"
out="${results.dir}/pmd_report.html"
style="${pmd.home}/pmd-report.xsl"/>
<echo>PMD report: ${results.dir}/pmd_report.html</echo>
</target>
<target name="cpd" depends="compile" description="Detect copy-paste duplication with CPD">
<mkdir dir="${results.dir}"/>
<echo>Running CPD</echo>
<cpd minimumTokenCount="100"
outputFile="${results.dir}/cpd.txt"
format="text">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</cpd>
<echo>CPD report: ${results.dir}/cpd.txt</echo>
</target>
<target name="spotbugs" depends="compile" description="Find bugs with SpotBugs">
<mkdir dir="${results.dir}"/>
<echo>Running SpotBugs</echo>
<spotbugs home="${spotbugs.home}"
output="html"
outputFile="${results.dir}/spotbugs.html"
reportLevel="medium"
effort="default">
<auxClasspath>
<pathelement path="${junit.jar}"/>
<pathelement path="${flatlaf.jar}"/>
<pathelement path="${flatlaf.themes.jar}"/>
</auxClasspath>
<sourcePath path="${src.dir}"/>
<class location="${build.dir}"/>
</spotbugs>
<echo>SpotBugs report: ${results.dir}/spotbugs.html</echo>
</target>
<target name="test-coverage" depends="test-compile"
description="Run JUnit tests with JaCoCo coverage measurement">
<mkdir dir="${results.dir}/junit"/>
<mkdir dir="${jacoco.results.dir}"/>
<echo>Running JUnit with JaCoCo coverage</echo>
<jacoco:coverage destfile="${jacoco.exec.file}">
<java classname="org.junit.platform.console.ConsoleLauncher"
fork="true" failonerror="false">
<classpath>
<pathelement location="${build.dir}"/>
<pathelement location="${test.build}"/>
<pathelement location="${junit.jar}"/>
<pathelement path="${flatlaf.jar}"/>
<pathelement path="${flatlaf.themes.jar}"/>
</classpath>
<arg value="execute"/>
<arg value="--scan-classpath=${test.build}"/>
<arg value="--reports-dir=${results.dir}/junit"/>
<arg value="--exclude-engine=junit-vintage"/>
</java>
</jacoco:coverage>
<jacoco:report>
<executiondata>
<file file="${jacoco.exec.file}"/>
</executiondata>
<structure name="${app.name} Test Coverage">
<classfiles>
<fileset dir="${build.dir}">
<exclude name="**/*Test.class"/>
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<html destdir="${jacoco.results.dir}"/>
<csv destfile="${jacoco.results.dir}/jacoco_results.csv"/>
<xml destfile="${jacoco.results.dir}/jacoco_results.xml"/>
</jacoco:report>
<echo>JaCoCo coverage report: ${jacoco.results.dir}/index.html</echo>
</target>
</project>