-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.xml
211 lines (196 loc) · 9.37 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
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xdb="http://exist-db.org/ant" xmlns:if="ant:if" default="build-xar" name="ediarum.db">
<property name="project.app" value="ediarum.db"/>
<property name="build.dir" value="build"/>
<property name="archive.dir" value="temp"/>
<property file="project.properties"/>
<property file="build.properties"/>
<property name="project.version" value="${build.major.number}.${build.minor.number}.${build.patch.number}"/>
<path id="classpath.core">
<fileset dir="${exist.dir}/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${exist.dir}/exist-core-5.1.0.jar"/>
<!-- <pathelement path="${exist.dir}/exist-optional.jar"/> -->
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant.contrib.jar}"/>
</classpath>
</taskdef>
<target name="show-version" description="Shows the current version number">
<echo>Current version: ${project.version}</echo>
<echo>Current build number: ${build.build.number}</echo>
<exec executable="git" outputproperty="git.branch" failifexecutionfails="false">
<arg line="rev-parse --abbrev-ref HEAD"/>
</exec>
<echo message="Current branch: ${git.branch}"/>
</target>
<target name="increase-build-number">
<propertyfile file="build.properties">
<entry key="build.build.number" type="int" operation="+" value="1" pattern="0"/>
</propertyfile>
<var name="build.build.number" unset="true"/>
<property file="build.properties"/>
</target>
<target name="increase-patch-number" description="Increases the patch number">
<propertyfile file="build.properties">
<entry key="build.patch.number" type="int" operation="+" value="1" pattern="0"/>
</propertyfile>
</target>
<target name="increase-minor-version" description="Increases the minor version">
<propertyfile file="build.properties">
<entry key="build.minor.number" type="int" operation="+" value="1" pattern="0"/>
<entry key="build.patch.number" type="int" operation="=" value="0" pattern="0"/>
</propertyfile>
</target>
<target name="increase-major-version" description="Increases the major version">
<propertyfile file="build.properties">
<entry key="build.major.number" type="int" operation="+" value="1" pattern="0"/>
<entry key="build.minor.number" type="int" operation="=" value="0" pattern="0"/>
<entry key="build.patch.number" type="int" operation="=" value="0" pattern="0"/>
</propertyfile>
</target>
<!-- Replace all ant filters in ant-files -->
<target name="use-filters" depends="increase-build-number">
<var name="project.version" unset="true"/>
<tstamp>
<format property="build.date" pattern="YYYY-MM-dd"/>
</tstamp>
<exec executable="git" outputproperty="git.branch" failifexecutionfails="false">
<arg line="rev-parse --abbrev-ref HEAD"/>
</exec>
<condition property="project.version"
value="${build.major.number}.${build.minor.number}.${build.patch.number}"
else="${build.major.number}.${build.minor.number}.${build.patch.number}.${git.branch}.${build.build.number}">
<or>
<equals arg1="${git.branch}" arg2="main"/>
<equals arg1="${git.branch}" arg2="HEAD"/>
<equals arg1="${git.branch}" arg2="develop"/>
</or>
</condition>
<delete>
<fileset dir="">
<include name="expath-pkg.xml"/>
<include name="CITATION.cff"/>
</fileset>
</delete>
<copy todir=".">
<fileset dir="">
<include name="expath-pkg.xml.ant"/>
<include name="CITATION.cff.ant"/>
</fileset>
<globmapper from="*.ant" to="*"/>
<filterset>
<filter token="VERSION" value="${project.version}"/>
<filter token="DATE" value="${build.date}"/>
</filterset>
</copy>
</target>
<target name="build-xar" depends="use-filters" description="Build a xar-package and increase build number">
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
<zip basedir="." destfile="${build.dir}/${project.app}-${project.version}.xar" excludes="${build.dir}/*, ${archive.dir}/**/*, lib/**/*, expath-pkg.xml.ant, *.properties"/>
</target>
<target name="deploy-local">
<echo message="Deploying app to local eXist-db."/>
<property file="deploy-local.properties"/>
<condition property="ediarum_app_exists">
<xdb:exist user="${deploy.user}" password="${deploy.password}" uri="${deploy.uri}"/>
</condition>
<xdb:remove if:set="ediarum_app_exists" uri="${deploy.uri}" user="${deploy.user}" password="${deploy.password}" collection="."/>
<!-- Generating zip files from the data -->
<!--
<zip destfile="data/pub.zip" basedir="data/pub/" excludes="dont*.*"/>
<zip destfile="data/doc.zip" basedir="data/doc/" excludes="dont*.*"/>
-->
<!--zip destfile="data.zip" basedir="data/" excludes="dont*.*"/-->
<xdb:store uri="${deploy.uri}" createcollection="true" createsubcollections="true" user="${deploy.user}" password="${deploy.password}" permissions="rwxr-xr-x">
<fileset dir=".">
<include name="**/*.xql"/>
<exclude name="temp/"/>
</fileset>
</xdb:store>
<xdb:store uri="${deploy.uri}" createcollection="true" createsubcollections="true" user="${deploy.user}" password="${deploy.password}">
<fileset dir=".">
<include name="**/*.*"/>
<exclude name="**/*.xql"/>
<exclude name="temp/"/>
<exclude name="build/"/>
<exclude name="modules/admin.xqm"/>
<exclude name="**/*.properties"/>
<exclude name="**/*.tmpl"/>
<exclude name="**/*.md"/>
<exclude name="*.xpr"/>
<exclude name="**/.gitignore"/>
</fileset>
</xdb:store>
<!--delete file="data.zip"/-->
</target>
<target name="copy-files-to-docu" description="Copy the .md files to the documention.">
<copy todir="${docu.dir}" overwrite="true">
<fileset dir="">
<include name="**/*.md"/>
</fileset>
<packagemapper from="*" to="*"/>
</copy>
</target>
<scriptdef name="package-links" language="javascript">
<element name="fileset" type="fileset"/>
<![CDATA[
filesets = elements.get("fileset");
for (i = 0; i < filesets.size(); ++i) {
//project.log("fileset " + i + " basedir = " + filesets.get(i).getDir(project));
// Get the files (array) of that fileset
fs = filesets.get(i)
ds = fs.getDirectoryScanner(project);
srcFiles = ds.getIncludedFiles();
// iterate over that array
for (i = 0; i < srcFiles.length; i++) {
// get the values via Java API
var basedir = fs.getDir(project);
var filename = srcFiles[i];
var file = new java.io.File(basedir, filename);
var fileTemp = new java.io.File(basedir, filename+'.temp');
var filenameWithoutExtr = filename.substring(0, filename.lastIndexOf('.'))
var currentDir = filenameWithoutExtr.substring(0, filenameWithoutExtr.lastIndexOf('.')+1)
//project.log(currentDir)
//var size = file.length();
//project.log(filename + ": " + size + " byte");
fr = new java.io.FileReader(file);
br = new java.io.BufferedReader(fr);
fw = new java.io.FileWriter(fileTemp);
bw = new java.io.BufferedWriter(fw);
line = null;
while((line=br.readLine()) != null) {
pattern = java.util.regex.Pattern.compile("(\\[[^]]*\\])\\(([^:)]*)\\)");
matcher = pattern.matcher(line);
var sb = new java.lang.StringBuffer();
// check all occurance
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group(1)+"("+currentDir+matcher.group(2).replaceAll("/",".")+")");
}
matcher.appendTail(sb);
line = sb.toString();
bw.write(line);
bw.write("\n");
}
bw.close();
br.close();
file.delete();
fileTemp.renameTo(file);
}
}
]]>
</scriptdef>
<target depends="copy-files-to-docu" name="make-docu">
<package-links>
<fileset dir="${docu.dir}">
<include name="*.md"/>
</fileset>
</package-links>
</target>
</project>