-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.xml
459 lines (420 loc) · 18.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
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ papaya CMS
~
~ @copyright 2000-2018 by papayaCMS project - All rights reserved.
~ @link http://www.papaya-cms.com/
~ @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, version 2
~
~ You can redistribute and/or modify this script under the terms of the GNU General Public
~ License (GPL) version 2, provided that the copyright and license notes, including these
~ lines, remain unmodified. papaya 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.
-->
<project name="papaya_cms" default="setup">
<!--
Configuration options
Here are 4 ways to set a property value:
1) Environment Variables
Some properties are initialized from environment variables (if they exists)
* PAPAYA_DATABASE_URI - database URI for setup and export
* PAPAYA_ENVIRONMENT_NAME - target environment for exports
2) create build.properties
build.properties is a local file that will never be committed to the Git repository.
It allows for user specific build options. The properties in the file will not have
the prefix "configuration.".
3) create dist.build.properties
dist.build.properties can be committed to the Git repository. Except for that it
is like build.properties. You can use it for project specific build options.
4) define properties in you build file.
This build file can be imported into you project specific build file.
Define the property before you import it. It allows for additional logic like
reading the option from the environment variables.
WARNING:
This file is part of the papaya CMS core library. Do not attempt to change it directly.
Merge requests or issues for changes are welcome.
-->
<property name="env.PAPAYA_DATABASE_URI" value=""/>
<property name="env.PAPAYA_ENVIRONMENT_NAME" value=""/>
<property environment="env" override="true"/>
<condition
property="configuration.database.uri"
value="sqlite3:./papaya.sqlite"
else="${env.PAPAYA_DATABASE_URI}">
<equals arg1="${env.PAPAYA_DATABASE_URI}" arg2=""/>
</condition>
<property name="configuration.run.host" value="localhost"/>
<property name="configuration.run.port" value="8080"/>
<property name="configuration.directory.document-root" value="htdocs"/>
<property name="configuration.directory.data" value="papaya-data"/>
<property name="configuration.mode.writable" value="0777"/>
<!-- database uri used in the export configuration file -->
<condition
property="configuration.export.database.uri"
value="sqlite3:./papaya.sqlite"
else="${env.PAPAYA_DATABASE_URI}">
<equals arg1="${env.PAPAYA_DATABASE_URI}" arg2=""/>
</condition>
<!-- export target environment name (stage, demo, production, ...) -->
<condition
property="export.environment.name"
value="production"
else="${env.PAPAYA_ENVIRONMENT_NAME}">
<equals arg1="${env.PAPAYA_ENVIRONMENT_NAME}" arg2=""/>
</condition>
<!-- target directory for the deployment build -->
<property name="configuration.export.directory" value="${project.basedir}/build/${export.environment.name}"/>
<!-- archive build as artifact (with version number) -->
<property name="configuration.export.artifacts" value="true"/>
<!-- artifacts directory -->
<property name="configuration.export.artifacts.directory" value="${project.basedir}/build/artifacts"/>
<!-- artifact file title -->
<property name="configuration.export.artifact.name" value="${phing.project.name}"/>
<!-- zip, tgz, directory -->
<property name="configuration.export.artifacts.format" value="zip"/>
<!-- create a 'latest' artifact for zip/tgz -->
<property name="configuration.export.artifacts.latest" value="true"/>
<!-- export env document root -->
<property name="configuration.export.document-root" value="${configuration.directory.document-root}"/>
<property name="configuration.executable.composer" value="composer"/>
<property name="configuration.executable.git" value="git"/>
<target name="setup" depends="dependencies-install,configuration,create-directories" description="Install/Configure"/>
<!--
Install dependencies-install dependencies
-->
<target name="dependencies-install" depends="properties" description="Install dependencies">
<exec executable="${configuration.executable.composer}" passthru="true">
<arg value="-n"/>
<arg value="install"/>
</exec>
<phingcall target="revisions-update"/>
</target>
<!--
Update dependencies-install dependencies
-->
<target name="dependencies-update" depends="properties" description="Update dependencies">
<exec executable="${configuration.executable.composer}" passthru="true">
<arg value="-n"/>
<arg value="update"/>
</exec>
<phingcall target="revisions-update"/>
</target>
<!--
Start PHP built-in webserver for the project
-->
<target name="run" depends="setup" description="Start the PHP built-in webserver">
<delete file="${directory.base}/php-server.log"/>
<delete dir="${directory.base}/papaya-data/cache"/>
<mkdir dir="${directory.base}/papaya-data/cache"/>
<property name="bootstrap" value="${phing.dir.papaya_cms}/server.php"/>
<echo message="Start PHP built-in webserver at http://${configuration.run.host}:${configuration.run.port}"/>
<echo message="Administration-UI available at http://${configuration.run.host}:${configuration.run.port}/papaya/"/>
<exec executable="php">
<arg value="-S"/>
<arg value="${configuration.run.host}:${configuration.run.port}"/>
<arg value="-t"/>
<arg path="${directory.base}/${configuration.directory.document-root}"/>
<arg file="${bootstrap}"/>
<arg value=">"/>
<arg file="${directory.base}/php-server.log"/>
</exec>
</target>
<!--
Delete current configuration and create a new one
-->
<target name="configuration-regenerate" depends="configuration-remove,configuration" description="Delete and recreate configuration"/>
<!--
Build deployment directory and generate artifacts archives
-->
<target name="export" depends="build-export" description="Export project for deployment">
<property name="artifactsDirectory" value="${configuration.export.artifacts.directory}/${export.environment.name}"/>
<property name="artifactName" value="${artifactsDirectory}/${configuration.export.artifact.name}${revision.project.suffix}"/>
<if>
<istrue value="${configuration.export.artifacts}"/>
<then>
<mkdir dir="${artifactsDirectory}"/>
<switch value="${configuration.export.artifacts.format}">
<case value="directory">
<copy todir="${artifactName}">
<fileset dir="${configuration.export.directory}">
<include name="*"/>
</fileset>
</copy>
</case>
<case value="zip">
<zip destfile="${artifactName}.zip">
<fileset dir="${configuration.export.directory}">
<include name="*"/>
</fileset>
</zip>
<if>
<istrue value="${configuration.export.artifacts.latest"/>
<then>
<copy file="${artifactName}.zip" tofile="${artifactsDirectory}/latest.zip">
</copy>
</then>
</if>
</case>
<case value="tgz">
<tar destfile="${artifactName}.tgz" compression="gzip">
<fileset dir="${configuration.export.directory}">
<include name="*"/>
</fileset>
</tar>
<if>
<istrue value="${configuration.export.artifacts.latest"/>
<then>
<copy file="${artifactName}.tgz" tofile="${artifactsDirectory}/latest.tgz">
</copy>
</then>
</if>
</case>
</switch>
</then>
</if>
</target>
<!--
Internal targets and properties, DO NOT CALL DIRECTLY
-->
<property name="phing.dir.papaya_cms" value="${phing.dir}"/>
<property name="directory.base" value="${project.basedir}"/>
<condition property="directory.separator" value="\" else="/">
<os family="windows"/>
</condition>
<!--
Load properties from (dist.)build.properties
-->
<target name="properties" hidden="true">
<property file="dist.build.properties" prefix="configuration" override="true"/>
<property file="build.properties" prefix="configuration" override="true"/>
</target>
<!--
Create papaya.php configuration file
-->
<target name="configuration" depends="properties" description="Generate configuration" hidden="true">
<property name="hasProjectTemplate" value="false"/>
<available property="hasProjectTemplate" file="${directory.base}/dist.papaya.php"/>
<condition
property="configuration.template"
value="${directory.base}/dist.papaya.php"
else="${phing.dir.papaya_cms}/dist.papaya.php">
<istrue value="${hasProjectTemplate}"/>
</condition>
<property name="configuration.file" value="${directory.base}/papaya.php"/>
<property name="papaya.database.uri" value="${configuration.database.uri}"/>
<property name="papaya.development.active" value="(bool)TRUE"/>
<property name="hasConfiguration" value="false"/>
<available file="${configuration.file}" property="hasConfiguration" value="true"/>
<if>
<isfalse value="${hasConfiguration}"/>
<then>
<copy file="${configuration.template}" tofile="${configuration.file}">
<filterchain>
<expandproperties/>
</filterchain>
</copy>
</then>
<else>
<warn message="papaya.php already exists. Skipped."/>
</else>
</if>
</target>
<target name="configuration-remove" depends="properties" description="Remove configuration" hidden="true">
<property name="configuration.file" value="${directory.base}/papaya.php"/>
<delete file="${configuration.file}"/>
</target>
<target name="create-directories" depends="properties" description="Generate directories" hidden="true">
<property name="directory.data" value="${directory.base}${directory.separator}${configuration.directory.data}"/>
<property name="directory.data.cache" value="${directory.data}${directory.separator}cache"/>
<property name="directory.data.media" value="${directory.data}${directory.separator}media"/>
<property name="directory.data.media.files" value="${directory.data.media}${directory.separator}files"/>
<property name="directory.data.media.thumbnails" value="${directory.data.media}${directory.separator}thumbs"/>
<echo message="${directory.data.cache}"/>
<mkdir dir="${directory.data.cache}" mode="${configuration.mode.writable}"/>
<echo message="${directory.data.media.files}"/>
<mkdir dir="${directory.data.media.files}" mode="${configuration.mode.writable}"/>
<echo message="${directory.data.media.thumbnails}"/>
<mkdir dir="${directory.data.media.thumbnails}" mode="${configuration.mode.writable}"/>
</target>
<!--
Fetch revisions and store them in a PHP file
-->
<target name="revisions-update" depends="project-revision,dependency-revisions" hidden="true">
<append
destFile="${directory.base}/${configuration.directory.document-root}/revision.inc.php"
append="false"
overwrite="true"
text="<?php define('PAPAYA_WEBSITE_REVISION', '${revision.project}'); define('PAPAYA_VERSION_STRING', '${revision.papaya}'); define('PAPAYA_DEPENDENCIES', '${revision.dependencies}'); "/>
</target>
<!--
Determine the project code revision from Git metadata
-->
<target name="project-revision" description="Get project revision from git" hidden="true">
<property name="revision.project" value="dev"/>
<trycatch property="vcs.error">
<try>
<property name="isGitRepository" value="false"/>
<available file=".git" type="dir" property="isGitRepository" value="true"/>
<if>
<istrue value="${isGitRepository}"/>
<then>
<exec
executable="${configuration.executable.git}"
returnProperty="git.return"
outputProperty="git.output"
dir="${project.basedir}">
<arg line="describe --tags"/>
</exec>
<if>
<equals arg1="${git.return}" arg2="0"/>
<then>
<property name="revision.project" value="${git.output}" override="true"/>
</then>
</if>
</then>
<else>
</else>
</if>
<echo message="Project revision: ${revision.project}"/>
</try>
<catch>
<echo level="warning">There was an error while reading revision information. Current revision is
unknown.
</echo>
<echo level="warning">Please make sure that the git executable is available.</echo>
<echo level="debug">${vcs.error}</echo>
<property name="revision.project" value="unknown" override="true"/>
</catch>
</trycatch>
<property name="revision.project" value="${revision.project}" override="true"/>
<property name="revision.project.suffix" value="-${revision.project}"/>
</target>
<target name="dependency-revisions" depends="project-revision" hidden="true">
<property name="revision.papaya" value="unknown"/>
<property name="revision.dependencies" value=""/>
<property name="hasComposerLock" value="false"/>
<available property="hasComposerLock" file="${directory.base}/composer.lock"/>
<if>
<istrue value="${hasComposerLock}"/>
<then>
<property name="revision.papaya" value="${revision.project}" override="true"/>
<trycatch property="error">
<try>
<adhoc-task name="composer-version">
<![CDATA[
if (!class_exists('Phing\\Task')) {
class_alias(Task::class, 'Phing\\Task');
}
class PapayaVersionTask extends Phing\Task {
function main() {
$json = json_decode(file_get_contents("composer.lock"));
$dependencies = [];
foreach ($json->packages as $package) {
$dependencies[$package->name] = $package->version.' '.substr(
isset($package->source->reference)
? $package->source->reference : $package->dist->reference,
0,
8
);
if ($package->name === 'papaya/cms-core') {
$this->project->setProperty(
'revision.papaya', $package->version.' '.substr($package->source->reference, 0, 8)
);
}
}
$this->project->setProperty(
'revision.dependencies', json_encode($dependencies)
);
}
}
]]>
</adhoc-task>
<composer-version/>
<echo message="Papaya revision: ${revision.papaya}"/>
</try>
<catch>
<echo level="warning">There was an error while reading papaya core version information.</echo>
<echo level="debug">${error}</echo>
<property name="revision.papaya" value="unknown" override="true"/>
</catch>
</trycatch>
</then>
<else>
<echo level="warning">"composer.lock" not found, please install dependencies.</echo>
</else>
</if>
</target>
<!--
Generate distribution export directories (Copy files)
-->
<target name="build-export" depends="properties,project-revision,dependency-revisions" description="Export distribution" hidden="true">
<property name="targetDirectory" value="${configuration.export.directory}"/>
<echo message="Prepare export directory"/>
<delete dir="${targetDirectory}"/>
<mkdir dir="${targetDirectory}"/>
<echo message="Copy files"/>
<copy todir="${targetDirectory}/${configuration.directory.document-root}">
<fileset id="public" dir="${directory.base}/${configuration.directory.document-root}">
<include name="**"/>
<exclude name="**/.svn/**"/>
<exclude name="**/.git/**"/>
<exclude name="conf.inc.php"/>
<exclude name="papaya/**"/>
</fileset>
</copy>
<copy todir="${targetDirectory}">
<fileset id="source" dir="${directory.base}">
<include name="src/**"/>
<include name="templates/**"/>
<exclude name="**/.svn/**"/>
<exclude name="**/.git/**"/>
</fileset>
<fileset id="dependencies" dir="${directory.base}">
<include name="composer.json"/>
<include name="composer.lock"/>
</fileset>
</copy>
<echo message="Create configuration file"/>
<property name="hasProjectTemplate" value="false"/>
<available property="hasProjectTemplate" file="${directory.base}/dist.papaya.php"/>
<condition
property="configuration.template"
value="${directory.base}/dist.papaya.php"
else="${phing.dir.papaya_cms}/dist.papaya.php">
<istrue value="${hasProjectTemplate}"/>
</condition>
<property name="configuration.file" value="${targetDirectory}/papaya.php"/>
<property name="papaya.database.uri" value="${configuration.export.database.uri}"/>
<property name="papaya.development.active" value="(bool)FALSE"/>
<copy file="${configuration.template}" tofile="${configuration.file}">
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<echo message="Install composer dependencies"/>
<exec executable="${configuration.executable.composer}" passthru="true">
<arg value="install"/>
<arg value="--ignore-platform-reqs"/>
<arg value="--no-interaction"/>
<arg value="--no-dev"/>
<arg value="--no-cache"/>
<arg value="--working-dir"/>
<arg path="${targetDirectory}"/>
</exec>
<append
destFile="${targetDirectory}/${configuration.directory.document-root}/revision.inc.php"
append="false"
overwrite="true"
text="<?php define('PAPAYA_WEBSITE_REVISION', '${revision.project}'); define('PAPAYA_VERSION_STRING', '${revision.papaya}'); define('PAPAYA_DEPENDENCIES', '${revision.dependencies}'); "/>
<if>
<not>
<equals arg1="${configuration.directory.document-root}" arg2="${configuration.export.document-root}"/>
</not>
<then>
<move file="${targetDirectory}/${configuration.directory.document-root}" tofile="${targetDirectory}/${configuration.export.document-root}"/>
<echo message="Changing document root: ${configuration.directory.document-root} -> ${configuration.export.document-root}"/>
</then>
</if>
</target>
</project>