forked from PhantomBot/PhantomBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
351 lines (305 loc) · 14.4 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
<?xml version="1.0" encoding="UTF-8"?>
<project name="PhantomBot" basedir="." default="dist" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:if="ant:if" xmlns:unless="ant:unless">
<!--
Copyright (C) 2016-2022 phantombot.github.io/PhantomBot
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<!-- To specify a Nightly Build run as ant -Dbuildtype=nightly_build -->
<!-- To specify a Pre-Release Build run as ant -Dbuildtype=prerelease_build -->
<property environment="env" />
<!-- Please see this for version numbers: https://semver.org/ -->
<property name="version" value="3.7.0.0" />
<property name="src" location="source" />
<property name="reference" location="lib" />
<property name="build" location="build" />
<property name="classes" location="${build}/classes" />
<property name="dist" location="dist" />
<property name="version.name" value="${ant.project.name}-${version}" />
<property name="version.folder" location="${dist}/${version.name}" />
<property name="build.dir" location="${dist}/build" />
<property name="res.dir" location="${build.dir}" />
<property name="lib.dir" location="${build.dir}/lib" />
<!-- Apache Ivy properties -->
<property name="ivy.install.version" value="2.5.0"/>
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME"/>
</condition>
<property name="ivy.home" value="${user.home}/.ant"/>
<property name="ivy.jar.dir" value="${ivy.home}/lib"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<tstamp>
<format property="NOW" pattern="MMM dd yyyy HH:mm:ss zzz" timezone="GMT" />
</tstamp>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<condition property="build_type" value="${buildtype}" else="custom">
<and>
<isset property="buildtype" />
<length string="${buildtype}" trim="yes" length="0" when="greater" />
</and>
</condition>
<condition property="rollbar_token" value="${rollbar_token}" else="notoken">
<and>
<isset property="rollbar_token" />
<length string="${rollbar_token}" trim="yes" length="0" when="greater" />
</and>
</condition>
<condition property="rollbar_endpoint" value="${rollbar_endpoint}" else="">
<and>
<isset property="rollbar_endpoint" />
<length string="${rollbar_endpoint}" trim="yes" length="0" when="greater" />
</and>
</condition>
<condition property="isdocker" value="true" else="false">
<isset property="isdocker" />
</condition>
<available file=".git" type="dir" property="git.present"/>
<target name="download-ivy" unless="offline">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="download-ivy">
<!-- try to load Ivy here from Ivy home, in case the user has not already dropped
it into Ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
Ivy is in at least one of Ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="init">
<mkdir dir="${build}" />
<mkdir dir="${classes}" />
<mkdir dir="${dist}" />
<mkdir dir="${version.folder}" />
</target>
<target depends="init-ivy" name="ivy-retrieve">
<ivy:settings file="ivysettings.xml"/>
<ivy:retrieve sync="true"/>
<ivy:report graph="false" todir="resources/licenses/"/>
<exec executable="git" outputproperty="git.ivychange" failifexecutionfails="false" errorproperty="">
<arg value="diff"/>
<arg value="--numstat"/>
<arg value="ivy.xml"/>
</exec>
<exec executable="git" failifexecutionfails="false" errorproperty="" if:blank="${git.ivychange}">
<arg value="checkout"/>
<arg value="resources/licenses/tv.phantombot-phantombot-default.html"/>
</exec>
</target>
<target depends="init-ivy" name="ivy-cleancache">
<ivy:settings file="ivysettings.xml"/>
<ivy:cleancache/>
</target>
<target depends="init-ivy" name="ivy-list-updates">
<ivy:settings file="ivysettings.xml"/>
<ivy:checkdepsupdate/>
</target>
<target name="clearlib">
<delete>
<fileset dir="${reference}" includes="**/*.jar" />
</delete>
</target>
<target depends="clearlib,ivy-cleancache,ivy-retrieve" name="ivy-clean-retrieve" />
<target depends="ivy-retrieve" name="classpaths">
<path id="reference.class.path">
<fileset dir="${reference}">
<include name="*.jar" />
<exclude name="*sources.jar"/>
<exclude name="*javadoc.jar"/>
</fileset>
</path>
<pathconvert property="mf.classpath" pathsep=" ">
<path refid="reference.class.path" />
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="lib/*.jar" />
</chainedmapper>
</mapper>
</pathconvert>
</target>
<target name="git.revision" if="git.present">
<exec executable="git" outputproperty="git.revision" failifexecutionfails="false" errorproperty="">
<arg value="rev-parse"/>
<arg value="--short"/>
<arg value="HEAD"/>
</exec>
<condition property="repository.version" value="${git.revision}" else="unknown">
<and>
<isset property="git.revision"/>
<length string="${git.revision}" trim="yes" length="0" when="greater"/>
</and>
</condition>
</target>
<target depends="init,ivy-retrieve,classpaths,git.revision" name="pre.compile">
<echo>${ant.project.name} Version ${version} (${repository.version}) (${build_type})</echo>
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="repoVersion = "(.*)";"
replace="repoVersion = "${repository.version}";" />
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="buildType = "(.*)";"
replace="buildType = "${build_type}";" />
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="phantomBotVersion = "(.*)";"
replace="phantomBotVersion = "${version}";" />
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="isDocker = false;"
replace="isDocker = ${isdocker};" />
<replaceregexp
file="source/com/gmt2001/RollbarProvider.java"
match="ACCESS_TOKEN = "(.*)";"
replace="ACCESS_TOKEN = "${rollbar_token}";" />
<replaceregexp
file="source/com/gmt2001/RollbarProvider.java"
match="ENDPOINT = "(.*)";"
replace="ENDPOINT = "${rollbar_endpoint}";" />
</target>
<target depends="pre.compile" name="compile.src">
<echo>Compiling with Java Version ${ant.java.version} (${java.version})</echo>
<javac target="11" source="11" debug="on" destdir="${classes}" srcdir="${src}" includeantruntime="false" >
<compilerarg value="-Xlint:unchecked" />
<compilerarg value="-Xlint:-options" />
<compilerarg value="-XDenableSunApiLintControl" />
<compilerarg line="--add-exports java.base/sun.security.x509=ALL-UNNAMED" />
<classpath refid="reference.class.path" />
</javac>
</target>
<target depends="pre.compile" name="clean.build.test">
<delete dir="${build}" />
<mkdir dir="${build}" />
<mkdir dir="${classes}" />
</target>
<target depends="clean.build.test" name="compile.src.test">
<javac target="11" source="11" debug="on" destdir="${classes}" srcdir="${src}" includeantruntime="false" >
<compilerarg value="-Xlint:all" />
<compilerarg value="-Xlint:-options" />
<compilerarg value="-XDenableSunApiLintControl" />
<compilerarg line="--add-exports java.base/sun.security.x509=ALL-UNNAMED" />
<classpath refid="reference.class.path" />
</javac>
</target>
<target name="post.compile">
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="repoVersion = "(.*)";"
replace="repoVersion = "@repository.version@";" />
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="buildType = "(.*)";"
replace="buildType = "@buildtype@";" />
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="phantomBotVersion = "(.*)";"
replace="phantomBotVersion = "@phantombot.version@";" />
<replaceregexp
file="source/tv/phantombot/RepoVersion.java"
match="isDocker = (.*);"
replace="isDocker = false;" />
<replaceregexp
file="source/com/gmt2001/RollbarProvider.java"
match="ACCESS_TOKEN = "(.*)";"
replace="ACCESS_TOKEN = "@access.token@";" />
<replaceregexp
file="source/com/gmt2001/RollbarProvider.java"
match="ENDPOINT = "(.*)";"
replace="ENDPOINT = "@endpoint@";" />
</target>
<target name="copy-javascript" depends="prepare-javascript-true, prepare-javascript-false">
</target>
<target name="prepare-javascript-true" depends="check-compiled" if="${compiled}">
<echo level="info" message="Phantombot ${version} already compiled, copying javascript"/>
<delete dir="${version.folder}/scripts" />
<copy todir="${version.folder}/scripts">
<fileset dir="./javascript-source" />
</copy>
</target>
<target name="prepare-javascript-false" depends="check-compiled" unless="${compiled}">
<echo level="info" message="Phantombot ${version} has not yet been compiled, compiling now"/>
<antcall target="jar"/>
</target>
<target name="check-compiled">
<available file="${version.folder}/PhantomBot.jar" property="compiled"/>
</target>
<target depends="compile.src,post.compile,git.revision" name="jar">
<jar destfile="${build.dir}/${ant.project.name}.jar">
<fileset dir="${classes}" />
<manifest>
<attribute name="Bundle-Name" value="${ant.project.name}" />
<attribute name="Bundle-Version" value="${version}" />
<attribute name="Bundle-Revision" value="${git.revision}" />
<attribute name="Bundle-Date" value="${NOW}" />
<attribute name="Implementation-Title" value="${ant.project.name}" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Implementation-Revision" value="${git.revision}" />
<attribute name="Implementation-URL" value="https://phantombot.github.io/PhantomBot" />
<attribute name="Class-Path" value="${mf.classpath}" />
<attribute name="Main-Class" value="tv.phantombot.PhantomBot" />
</manifest>
</jar>
<mkdir dir="${lib.dir}" />
<echo level="info" message="staging lib folder into build dir." />
<copy todir="${lib.dir}">
<fileset dir="${reference}">
<include name="*.jar" />
<exclude name="*sources.jar"/>
<exclude name="*javadoc.jar"/>
</fileset>
</copy>
<echo level="info" message="staging resources folder into build dir." />
<copy todir="${res.dir}">
<fileset dir="./resources" />
</copy>
<echo level="info" message="staging javascript-source folder into build dir." />
<copy todir="${res.dir}/scripts">
<fileset dir="./javascript-source" />
</copy>
<echo level="info" message="staging files into distribution folder." />
<move todir="${version.folder}">
<fileset dir="${build.dir}" />
</move>
</target>
<target depends="clean-no-post,jar" name="clean-jar"></target>
<target depends="compile.src.test,post.compile" name="test"/>
<target name="run" depends="jar">
<java fork="true" classname="tv.phantombot.PhantomBot" dir="${build.dir}">
<classpath>
<path refid="classpath" />
<path location="${build.dir}/${ant.project.name}.jar" />
</classpath>
</java>
</target>
<target depends="jar" name="dist">
<delete file="${dist}/${version.name}.zip" />
<zip destfile="${dist}/${version.name}.zip" basedir="${dist}" update="false">
<include name="${version.name}/**" />
</zip>
</target>
<target name="clean-no-post" depends="git.revision">
<delete dir="${build}" />
</target>
<target name="clean" depends="clean-no-post,post.compile">
<delete dir="${build}" />
</target>
<target name="distclean" depends="clean">
<delete dir="${dist}" />
</target>
</project>