-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
356 lines (296 loc) · 15.3 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
<?xml version="1.0"?>
<!--
Copyright (c) 2008-2024, Damon Hart-Davis
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!-- ======================================================================= -->
<!-- Stand-alone 'daemon' app. -->
<!-- ======================================================================= -->
<!-- Use Ant 1.6 or newer. -->
<!-- All code runs under JDK 19. -->
<!--
This builds one command-line app to regenerate Web pages
showing electricity grid current carbon intensity (kgCO2/kWh).
The debug builds are designed for the fastest possible incremental
compilation, but at some slight risk of things not being rebuilt
when they should be; occasionally use the "clean" target to zap
cached state. The debug builds are also as debuggable as possible.
The optimised builds are always from scratch for reliability,
and are configured for run-time speed. They will be
relatively slow to build and difficult to debug.
Expects JUnit 3.8.1 or newer.
-->
<project name="reutils" default="core.jar.opt" basedir=".">
<property name="app.name" value="reutils"/>
<property name="app.version.major" value="1"/>
<property name="app.version.minor" value="4"/>
<property name="app.version.micro" value="1"/>
<property name="app.version" value="${app.version.major}.${app.version.minor}.${app.version.micro}"/>
<!-- Version excluding the "micro" portion, thus reflecting only significant API/functionality changes. -->
<property name="app.version.notmicro" value="${app.version.major}.${app.version.minor}"/>
<property name="dist.jar" value="${app.name}-${app.version}.jar"/>
<!-- Target/minimum JDK/JSE version for build and run. -->
<property name="JDKVER" value="19"/>
<!-- Stub names, used in source and output dirs and package names. -->
<!-- This is core code. -->
<property name="core" value="core"/>
<!-- The base dir of the Java source. -->
<property name="jsrc.base.dir" value="javasrc"/>
<property name="core.src.dir" value="${jsrc.base.dir}"/>
<property name="dirsuffix.dbg" value="_D"/>
<property name="dirsuffix.opt" value="_O"/>
<property name="build.dir.base" value="out"/>
<property name="build.dir.dbg" value="../${build.dir.base}${dirsuffix.dbg}"/>
<property name="build.dir.opt" value="../${build.dir.base}${dirsuffix.opt}"/>
<!-- Build dir for common (non-opt, non-dbg) items. -->
<property name="build.dir.cmn" value="../${build.dir.base}_C"/>
<!-- General temporary work directory. -->
<property name="tmp.workdir" value="work.tmp"/>
<!-- Basic class path we compile against; includes any external libs. -->
<property name="cp.common.basic" value="libs/json-20240205.jar"/>
<!-- Provided in debug/non-debug versions. -->
<!-- Expects cp.J2EEAPI to contain a classpath fragment for the J2EE API. -->
<property name="cp.dbg.basic" value="${cp.common.basic}"/>
<property name="cp.opt.basic" value="${cp.common.basic}"/>
<!-- Class path for libs that may run against; includes any external libs. -->
<property name="cp.common.rt" value="libs/commons-codec.jar"/>
<!--Place where source snapshot is built. -->
<property name="src.snapshot.dir" value="${build.dir.cmn}/snapshot"/>
<!--Name of raw source snapshot archive to include in generated WAR file. -->
<property name="src.snapshot.tar.bz2" value="src.snapshot.tar.bz2"/>
<!--Place where javadoc is built. -->
<property name="javadoc.dir" value="${build.dir.cmn}/javadoc"/>
<!-- ProGuard static optimiser/shrunker. -->
<property name="pg.dir" value="../proguard-7.4.2" />
<taskdef resource="proguard/ant/task.properties"
classpath="${pg.dir}/lib/proguard-ant.jar" />
<!-- General initialisation target. -->
<target name="init">
<tstamp/>
</target>
<!-- =================================================================== -->
<!-- Prepares the core build directories, debug and optimised -->
<!-- =================================================================== -->
<!-- DBG -->
<target name="core.prepare.dbg.testuptodate">
<!-- Claim that the JAR target is up-to-date if its source files are. -->
<uptodate property="core.jar.dbg.uptodate"
targetfile="${build.dir.dbg}/${core.jar}">
<srcfiles dir="${core.src.dir}" includes="**/*.java"/>
<srcfiles dir="${ai.src.dir}" includes="**/*.java"/>
<srcfiles dir="${tp.src.dir}" includes="**/*.java"/>
</uptodate>
</target>
<target name="core.prepare.dbg"
depends="init,core.prepare.dbg.testuptodate"
unless="core.jar.dbg.uptodate">
<delete file="${build.dir.dbg}/${core.jar}" quiet="true"/>
<mkdir dir="${build.dir.dbg}/${tmp.workdir}/${core}"/>
<delete file="${build.dir.dbg}/.tmp.${core.jar}" quiet="true"/>
</target>
<!-- OPT -->
<!-- This is extra strict and cleans everything out before starting. -->
<target name="core.prepare.opt"
depends="init">
<!-- Make sure that the working dir is clear of cached state. -->
<delete dir="${build.dir.opt}" quiet="true"/>
<mkdir dir="${build.dir.opt}/${tmp.workdir}/${core}"/>
<delete file="${build.dir.opt}/.tmp.${core.jar}" quiet="true"/>
</target>
<!-- =================================================================== -->
<!-- Compiles the core source code, debug and optimised -->
<!-- =================================================================== -->
<!-- FOR NOW, the core will include the AI code. -->
<!-- DBG -->
<target name="core.compile.dbg"
depends="core.prepare.dbg"
unless="core.jar.dbg.uptodate">
<javac srcdir="${core.src.dir}"
destdir="${build.dir.dbg}/${tmp.workdir}/${core}"
classpath="${cp.dbg.basic}"
debug="on"
deprecation="on"
optimize="off">
<include name="**/*.java"/>
</javac>
</target>
<!-- OPT -->
<target name="core.compile.opt"
depends="core.prepare.opt">
<javac srcdir="${core.src.dir}"
destdir="${build.dir.opt}/${tmp.workdir}/${core}"
classpath="${cp.opt.basic}"
debug="on"
deprecation="on"
optimize="on">
<include name="**/*.java"/>
</javac>
</target>
<!-- =================================================================== -->
<!-- JARs the core source code, debug and optimised -->
<!-- =================================================================== -->
<!-- DBG -->
<target name="core.jar.dbg"
depends="core.compile.dbg"
unless="core.jar.dbg.uptodate"
description="builds the debug core classes JAR shared by all other app components">
<jar jarfile="${build.dir.dbg}/${core.jar}"
basedir="${build.dir.dbg}/${tmp.workdir}/${core}">
<include name="**/*.class"/>
<manifest>
<attribute name="Main-Class" value="org.hd.d.edh.Main"/>
<!-- <attribute name="Class-Path" value="${cp.common.basic}"/> -->
</manifest>
</jar>
</target>
<!-- OPT -->
<target name="core.jar.opt"
depends="core.compile.opt"
description="builds the optimised/release core classes JAR shared by all other app components">
<jar jarfile="${build.dir.opt}/${dist.jar}"
basedir="${build.dir.opt}/${tmp.workdir}/${core}">
<!-- <zipgroupfileset dir="libs" includes="*.jar" excludes=""/> -->
<include name="**/*.class"/>
<manifest>
<attribute name="Main-Class" value="org.hd.d.edh.Main"/>
<!-- <attribute name="Class-Path" value="${cp.common.basic}"/> -->
</manifest>
</jar>
<echo message="Release JAR now at ${build.dir.opt}/${dist.jar} ..." />
</target>
<!-- Super-optimised and shrunk org.hd.d.edh.Main JAR -->
<target name="core.jar.edhMainsuperopt"
depends="core.jar.opt"
description="builds the shrunk optimised/release org.hd.d.edh.Main JAR">
<proguard
verbose="true">
<!-- -printconfiguration -->
-injars ${build.dir.opt}/${dist.jar}
-outjars ${build.dir.opt}/edhMain.${dist.jar}
-libraryjars ${java.home}/jmods/java.base.jmod(!**.jar;!module-info.class)
-libraryjars ${java.home}/jmods/java.desktop.jmod(!**.jar;!module-info.class)
-libraryjars ${cp.opt.basic}
-libraryjars ${cp.common.rt}
-keep public class org.hd.d.edh.Main {
public *;
}
<!-- Makes the enum handling a little simpler! -->
-keep public class org.hd.d.edh.TrafficLight {
public *;
}
<!-- Build a few times, run many: thus worth extra optimisation effort here... -->
-optimizationpasses 5
-allowaccessmodification
<!-- -dontobfuscate - leave all class/method names etc for easiest debugging -->
-keepattributes SourceFile,LineNumberTable <!-- Keep minimum for exception debugging. -->
</proguard>
<echo message="Release org.hd.d.edh.Main JAR now at ${build.dir.opt}/edhMain.${dist.jar} ..." />
</target>
<!-- =================================================================== -->
<!-- Prepares the raw source snapshot; dbg/opt-independent... -->
<!-- Packages ALL local source files for (usually opt-only) WAR. -->
<!-- =================================================================== -->
<!--Few source suffixes to be excluded, including IDE files and big test data files. -->
<property name="src.snapshot.suffixes.exclude" value="**/*.tmp,*.ipr,*.iws,**/~*,**/*.dat,**.dll,**.so,**/*.ldb,**/*.mdb,**/*.jpg,java.hprof.*,**/_3rdParty**/*"/>
<target name="src.snapshot.testuptodate">
<!-- Claim that the JAR target is up-to-date if its source files/JARs are. -->
<uptodate property="src.snapshot.uptodate"
targetfile="${src.snapshot.dir}/${src.snapshot.tar.bz2}">
<srcfiles dir="." excludes="${src.snapshot.suffixes.exclude}"/>
</uptodate>
</target>
<!-- Makes BZIP2ed tar file for space efficiency,
in own directory for ease of packaging into WAR file.
Files not to be redistributed must be excluded by path and/or suffix.
-->
<target name="src.snapshot"
description="Prepares raw source snapshot to export with the WAR"
depends="src.snapshot.testuptodate"
unless="src.snapshot.uptodate">
<delete dir="${src.snapshot.dir}"/>
<mkdir dir="${src.snapshot.dir}"/>
<tar destfile="${src.snapshot.dir}/${src.snapshot.tar.bz2}"
basedir="."
excludes="${src.snapshot.suffixes.exclude}"
compression="bzip2"
longfile="gnu">
</tar>
</target>
<!-- =================================================================== -->
<!-- Prepares the javadoc snapshot; dbg/opt-independent... -->
<!-- =================================================================== -->
<target name="jar.javadoc.testuptodate">
<!-- Claim that the JAR target is up-to-date if its source files/JARs are. -->
<uptodate property="jar.javadoc.uptodate"
targetfile="${javadoc.dir}/index.html">
<srcfiles dir="${jsrc.base.dir}"/>
</uptodate>
</target>
<!--Build javadoc, identically for debug and optimised; rebuild only if source changes so as to save time. -->
<target name="jar.javadoc"
depends="jar.javadoc.testuptodate"
description="builds a javadoc JAR"
unless="jar.javadoc.uptodate">
<delete dir="${javadoc.dir}" quiet="true"/>
<mkdir dir="${javadoc.dir}"/>
<javadoc
destdir="${javadoc.dir}"
classpath="${cp.opt.basic}"
access="private"
verbose="false"
windowtitle="EDH V${app.version} Javadoc"
overview="${jsrc.base.dir}/javadoc-overview.html"
linksource="true"
>
<fileset dir="${core.src.dir}"/>
<header><![CDATA[
<a href="http://d.hd.org/" target="_top">EDH</a> V${app.version}<br />
]]></header>
<footer>EDH V${app.version}</footer>
<bottom>Copyright (c) 2009-2024, Damon Hart-Davis. All rights reserved.</bottom>
</javadoc>
</target>
<!-- =================================================================== -->
<!-- Builds debug and optimised code from scratch, and tests it. -->
<!-- =================================================================== -->
<target name="all"
depends="clean,core.jar.opt,core.jar.edhMainsuperopt,src.snapshot"
description="cleans, then does optimised/release build and test">
<echo message="Builds and tests complete."/>
</target>
<!-- depends="clean,core.jar.opt,src.snapshot" -->
<!-- depends="clean,core.jar.opt,core.jar.edhMainsuperopt,src.snapshot" -->
<!-- =================================================================== -->
<!-- Cleans up generated intermediate stuff -->
<!-- =================================================================== -->
<target name="clean"
description="cleans up all generated files and cached state">
<echo message="Doing cleanup of all build dirs..."/>
<parallel>
<delete dir="${test.install.cache.dir}" quiet="true"/> <!-- Slowest job first. -->
<delete dir="${build.dir.dbg}" quiet="true"/>
<delete dir="${build.dir.cmn}" quiet="true"/>
<delete dir="${build.dir.opt}" quiet="true"/>
</parallel>
</target>
</project>