Detect text files for unknown file types
[phorkie.git] / build.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <project name="phorkie" default="zip" basedir=".">
3   <!--
4     phorkie phing build file.
5     This script should provide a one-stop tool for all administrative
6     tasks around phorkie, like creating a release version,
7     tagging a release
8   -->
9   <property file="build.properties" />
10
11   <property name="version-m"  value="0.6" />
12   <property name="version"    value="0.6.1" />
13   <property name="stability"  value="beta" />
14   <property name="releasenotes" value="
15 Version 0.6.1 - 2015-07-15
16 --------------------------
17 * Fix crash when renaming file
18 * Fix jumping to file anchor after file rename
19 " />
20   <property name="libdir"      value="${phing.dir}/lib"/>
21
22   <property name="zipfile"     value="${phing.project.name}-${version}.tar.bz2" />
23   <property name="pharfile"    value="${phing.project.name}-${version}.phar" />
24   <property name="pkgfile"     value="${phing.project.name}-${version}.tgz" />
25
26   <property name="pharpath"    value="${phing.dir}/dist/${pharfile}" />
27   <property name="distfile"    value="dist/${zipfile}" />
28   <property name="distpkgfile" value="dist/pear/${pkgfile}" />
29
30   <property name="sfproject"   value="phorkie" />
31   <property name="sffilepath"  value="p/ph/phorkie/" />
32
33   <fileset id="fs.zip" dir=".">
34    <include name="data/**"/>
35    <include name="scripts/**"/>
36    <include name="src/**"/>
37    <include name="www/**"/>
38
39    <include name="ChangeLog"/>
40    <include name="LICENSE"/>
41    <include name="NEWS.rst"/>
42    <include name="README.rst"/>
43
44    <exclude name="**/.git/"/>
45    <exclude name="**/.gitignore/"/>
46    <exclude name="data/cache/**"/>
47    <exclude name="data/config.php"/>
48    <exclude name="www/**/.phar"/>
49    <exclude name="www/repos"/>
50   </fileset>
51
52   <fileset id="fs.phar" dir="${phing.dir}">
53    <include name="data/**"/>
54    <include name="lib/**"/>
55    <include name="scripts/**"/>
56    <include name="src/**"/>
57    <include name="www/**"/>
58
59    <include name="ChangeLog"/>
60    <include name="README.rst"/>
61
62    <exclude name="**/.git/"/>
63    <exclude name="**/.gitignore/"/>
64    <exclude name="data/cache/**"/>
65    <exclude name="data/config.php"/>
66    <exclude name="www/**/.phar"/>
67    <exclude name="www/repos"/>
68   </fileset>
69
70   <fileset id="fs.doc" dir=".">
71    <include name="README.rst"/>
72    <include name="NEWS.rst"/>
73   </fileset>
74
75   <taskdef name="d51pearpkg2" classname="phing.tasks.ext.d51PearPkg2Task" />
76
77
78   <target name="phar" depends="preparedirs,collectdeps"
79           description="Create phar file for release"
80   >
81    <delete file="${pharpath}"/>
82    <exec command="php scripts/build-rewritemap.php" dir="${phing.dir}"/>
83    <pharpackage basedir="${phing.dir}"
84                 destfile="${pharpath}"
85                 stub="${phing.dir}/src/stub-phar.php"
86                 alias="phorkie.phar"
87    >
88     <fileset refid="fs.phar"/>
89    </pharpackage>
90
91    <exec executable="bzip2" dir="${phing.dir}/dist">
92     <arg value="-kf"/>
93     <arg file="${pharpath}"/>
94    </exec>
95   </target>
96
97
98   <target name="collectdeps" description="Copy package dependencies to lib/">
99    <delete dir="${libdir}"/>
100    <mkdir dir="${libdir}"/>
101
102    <!-- requires phing >= 2.8.0 -->
103    <copy todir="${libdir}">
104     <pearPackageFileset package="pear.php.net/Cache_Lite"/><!-- OpenID -->
105     <pearPackageFileset package="pear.php.net/Console_Getopt"/>
106     <pearPackageFileset package="pear.php.net/Crypt_DiffieHellman"/><!-- OpenID -->
107     <pearPackageFileset package="pear.php.net/Date_HumanDiff"/>
108     <pearPackageFileset package="pear.geshi.org/geshi">
109      <!-- remove files that are probably not needed to save space in the .phar -->
110      <exclude name="geshi/arm.php"/>
111      <exclude name="geshi/autoit.php"/>
112      <exclude name="geshi/thinbasic.php"/>
113     </pearPackageFileset>
114     <pearPackageFileset package="pear.php.net/HTTP2"/>
115     <pearPackageFileset package="pear.php.net/HTTP_Request2"/>
116     <pearPackageFileset package="pear.php.net/MIME_Type"/>
117     <pearPackageFileset package="zustellzentrum.cweiske.de/MIME_Type_PlainDetect"/>
118     <pearPackageFileset package="zustellzentrum.cweiske.de/MIME_Type_PlainDetect" role="data"/>
119     <pearPackageFileset package="pear.michelf.com/Markdown"/>
120     <pearPackageFileset package="pear.php.net/Net_URL2"/>
121     <pearPackageFileset package="pear.php.net/OpenID"/>
122     <pearPackageFileset package="pear.php.net/Pager"/>
123     <pearPackageFileset package="pear.php.net/PEAR">
124      <include name="PEAR/Exception.php"/>
125      <include name="PEAR.php"/>
126      <include name="PEAR5.php"/>
127      <include name="OS/Guess.php"/>
128      <include name="System.php"/>
129     </pearPackageFileset>
130     <pearPackageFileset package="pear.php.net/Services_Libravatar"/>
131     <pearPackageFileset package="pear2.php.net/PEAR2_Services_Linkback"/>
132     <pearPackageFileset package="pear.php.net/Services_Yadis"/>
133     <pearPackageFileset package="pear.php.net/System_Command"/>
134     <pearPackageFileset package="pear.twig-project.org/Twig"/>
135     <pearPackageFileset package="pear.php.net/Validate"/>
136     <pearPackageFileset package="pear.php.net/VersionControl_Git"/>
137    </copy>
138   </target>
139
140
141   <target name="zip" depends="preparedirs"
142    description="Create zip file for release"
143    >
144     <!--
145       The release file is for end users, so it is safe to
146       remove anything developer-related.
147
148       Test your zip with: unzip -l phorkie-0.1.0.zip
149     -->
150     <echo msg="Creating distribution zip for phorkie ${version}"/>
151     <delete file="${distfile}" failonerror="false"/>
152     <tar compression="bzip2" destfile="${distfile}"
153          prefix="${phing.project.name}-${version}/"
154     >
155      <fileset refid="fs.zip"/>
156     </tar>
157   </target>
158
159
160
161   <target name="pear" depends="check"
162    description="Creates the pear package"
163   >
164    <d51pearpkg2 dir="." baseinstalldir="/">
165      <name>phorkie</name>
166      <summary>Self-hosted pastebin software</summary>
167      <description>
168       Self-hosted pastebin software written in PHP.
169       Pastes are editable, may have multiple files and are stored in git repositories.
170      </description>
171      <channel>phorkie.sourceforge.net</channel>
172
173      <lead user="cweiske" name="Christian Weiske" email="cweiske@cweiske.de" />
174      <license>AGPL</license>
175
176      <version   release="${version}"   api="${version}" />
177      <stability release="${stability}" api="${stability}" />
178
179      <notes>${releasenotes}</notes>
180
181      <dependencies>
182        <php minimum_version="5.3.0" />
183        <pear minimum_version="1.9.0" />
184
185        <package name="Date_HumanDiff"
186                 channel="pear.php.net"
187                 minimum_version="0.4.0"
188                 />
189        <package name="HTTP_Request2"
190                 channel="pear.php.net"
191                 minimum_version="2.1.0"
192                 />
193        <package name="OpenID"
194                 channel="pear.php.net"
195                 minimum_version="0.3.3"
196                 />
197        <package name="Pager"
198                 channel="pear.php.net"
199                 minimum_version="2.4.8"
200                 />
201        <package name="PEAR2_Services_Linkback"
202                 channel="pear2.php.net"
203                 minimum_version="0.2.1"
204                 />
205        <package name="Services_Libravatar"
206                 channel="pear.php.net"
207                 minimum_version="0.2.2"
208                 />
209        <package name="VersionControl_Git"
210                 channel="pear.php.net"
211                 minimum_version="0.4.4"
212                 />
213
214        <package name="geshi"
215                 channel="pear.geshi.org/geshi"
216                 minimum_version="1.0.0"
217                 />
218        <package name="Markdown"
219                 channel="pear.michelf.com"
220                 minimum_version="0.0.2"
221                 />
222        <package name="MIME_Type_PlainDetect"
223                 channel="zustellzentrum.cweiske.de"
224                 minimum_version="0.0.2"
225                 />
226        <package name="Twig"
227                 channel="pear.twig-project.org"
228                 minimum_version="1.6.0"
229                 />
230
231      </dependencies>
232
233      <!-- map directory (key) to role -->
234      <dirroles key="data">data</dirroles>
235      <dirroles key="scripts">data</dirroles>
236      <dirroles key="src">php</dirroles>
237      <dirroles key="www">www</dirroles>
238
239      <!-- do not add the following files to the package.
240           copied from excludes above -->
241      <ignore>**/.gitignore</ignore>
242      <ignore>build*</ignore>
243      <ignore>data/config.php</ignore>
244      <ignore>dist/**</ignore>
245      <ignore>*.properties</ignore>
246      <ignore>*.tgz</ignore>
247
248      <replacement path="www/www-header.php"
249       type="pear-config" from="@data_dir@" to="data_dir"
250       />
251
252
253    </d51pearpkg2>
254
255    <!-- time to fix the package.xml file since the task does not
256         allow everything we need:
257         - strip the base directory names like src, data and www
258         - remove that dumb baseinstalldir from files
259         - md5sums are generated automatically when packaging
260    -->
261    <!-- yes, we need to generate a 2nd file and move it back -->
262    <copy file="package.xml" tofile="package2.xml" overwrite="true">
263     <filterchain>
264      <replaceregexp>
265       <!-- remove md5sums -->
266       <regexp
267        pattern="md5sum=&quot;[a-z0-9]{32}&quot; "
268        replace=""
269        />
270       <!-- remove baseinstalldir for files -->
271       <regexp
272        pattern="&lt;file baseinstalldir=&quot;/&quot;"
273        replace="&lt;file"
274        />
275       <!-- install-as for different directories -->
276       <regexp
277        pattern="(&lt;file name=&quot;data/(.+?)&quot;)"
278        replace="\1 install-as=&quot;\2&quot;"
279        />
280       <regexp
281        pattern="(&lt;file name=&quot;doc/(.+?)&quot;)"
282        replace="\1 install-as=&quot;\2&quot;"
283        />
284       <regexp
285        pattern="(&lt;file name=&quot;tests/(.+?)&quot;)"
286        replace="\1 install-as=&quot;\2&quot;"
287        />
288       <regexp
289        pattern="(&lt;file name=&quot;www/(.+?)&quot;)"
290        replace="\1 install-as=&quot;phorkie/\2&quot;"
291        />
292       <regexp
293        pattern="(&lt;file name=&quot;src/(.+?)&quot;)"
294        replace="\1 install-as=&quot;\2&quot;"
295        />
296      </replaceregexp>
297     </filterchain>
298    </copy>
299    <move file="package2.xml" tofile="package.xml" overwrite="true" />
300
301    <!-- package up -->
302    <exec command="pear package" passthru="true" />
303    <move file="${pkgfile}" todir="dist/pear/" />
304
305    <delete file="package.xml" failonerror="true" />
306   </target>
307
308
309   <target name="build-docs" description="render documentation">
310    <rST format="html" uptodate="true">
311     <fileset refid="fs.doc"/>
312     <mapper type="regexp" from="^(.+?).rst$" to="dist/docs/\1.html"/>
313    </rST>
314   </target>
315
316   <target name="clean-docs" description="delete rendered documentation files">
317    <delete dir="dist/docs" includeemptydirs="yes"/>
318   </target>
319
320
321   <target name="release" depends="check,zip,pear,deploy-sf"
322    description="Release the version on sourceforge"
323    >
324    <!-- meta-target -->
325   </target>
326
327
328   <!--
329   /home/frs/project/p/ph/phorkie/phorkie/v0.1/
330   /home/frs/project/p/ph/phorkie/phorkie/v0.1/phorkie-v0.1.0.zip
331   /home/frs/project/p/ph/phorkie/phorkie/v0.1/phorkie-v0.1.1.zip
332   https://sourceforge.net/apps/trac/sourceforge/wiki/Release%20files%20for%20download
333   -->
334   <target name="deploy-sf" depends="check,zip,phar"
335    description="Upload release to sourceforge"
336    >
337     <delete dir="dist/deploy-sf" /><!-- make empty -->
338     <mkdir dir="dist/deploy-sf" />
339     <mkdir dir="dist/deploy-sf/v${version-m}" />
340     <copy file="${distfile}" tofile="dist/deploy-sf/v${version-m}/${zipfile}"/>
341     <copy file="${pharpath}" tofile="dist/deploy-sf/v${version-m}/${pharfile}"/>
342     <!-- test
343     <exec command="rsync -av dist/deploy-sf/ /tmp/test/" escape="false" />
344     -->
345     <exec
346      command="rsync -av -e ssh dist/deploy-sf/ ${sfuser},${sfproject}@frs.sourceforge.net:/home/frs/project/${sffilepath}/${sfproject}/"
347      escape="false" checkreturn="false"
348      />
349     <!-- rsync always returns code 23 on sourceforge releases, so we
350          can't check return values -->
351   </target>
352
353
354   <target name="preparedirs">
355     <mkdir dir="dist" />
356   </target>
357
358   <target name="check" depends="preparedirs"
359    description="Check variables"
360    >
361     <fail unless="version" message="Version not defined!" />
362     <fail unless="sfuser" message="Sourceforge username not defined!" />
363     <fail unless="sfproject" message="Sourceforge project name not defined!" />
364     <fail unless="sffilepath" message="Sourceforge project file path not defined!" />
365   </target>
366
367 </project>