-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscm.xml
328 lines (308 loc) · 11.7 KB
/
scm.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
<project name="revisions" basedir="./" xmlns:antcontrib="antlib:net.sf.antcontrib">
<propertyset id="sc-properties">
<propertyref prefix="sc.${sc}."/>
</propertyset>
<antcontrib:for list="${toString:sc-properties}" param="prop">
<sequential>
<antcontrib:propertyregex property="scprop"
input="@{prop}"
regexp="sc\..+?\.(.*)="
select="sc.\1"
casesensitive="false" override="true" />
<antcontrib:propertyregex property="scpropval"
input="@{prop}"
regexp=".+?=(.*)"
select="\1"
casesensitive="false" override="true" />
<echo message="${scprop} is ${scpropval} "/>
<antcontrib:var name="${scprop}" value="${scpropval}"/>
</sequential>
</antcontrib:for>
<property name="scm.autobranch" value="false" description="create branch of any local changes" />
<property name="basedir.absolute" location="${basedir}" />
<property name="src.xml.file" value="${basedir.absolute}/src.xml" />
<import file="scm-git.xml"/>
<import file="scm-svn.xml"/>
<import file="scm-cvs.xml"/>
<macrodef name="apply-patch">
<attribute name="patchUrl"/>
<attribute name="patchlevel" default="0" />
<attribute name="patchdir" default="${src.dir}" />
<sequential>
<delete file="${temp.dir.absolute}/patch.txt"/>
<get src="@{patchUrl}" dest="${temp.dir.absolute}/patch.txt" verbose="true" ignoreerrors="false" />
<patch patchfile="${temp.dir.absolute}/patch.txt" strip="@{patchlevel}" dir="@{patchdir}"/>
<echo message="Patch results: ${patch.results}"/>
</sequential>
</macrodef>
<macrodef name="load-src-xml">
<sequential>
<antcontrib:if>
<available file="${src.xml.file}" type="file" property="exists.src.xml"/>
<then>
<tempfile property="temp.all.props.file" prefix="props"/>
<echoproperties destfile="${temp.all.props.file}"/>
<loadfile property="src.xml" srcFile="${src.xml.file}">
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
<param type="token" name="src.dir" value="${src.dir}"/>
<param type="token" name="ext.mappings.dir" value="${ext.mappings.dir}"/>
<param type="token" name="pub.dir" value="${pub.dir}"/>
<param type="token" name="lib.dir" value="${lib.dir}"/>
<param type="token" name="distro.name" value="${distro.name}"/>
<param type="token" name="war.name" value="${war.name}"/>
<param type="token" name="war.target.dir" value="${war.target.dir}"/>
<param type="propertiesfile" value="${temp.all.props.file}" />
</filterreader>
</filterchain>
</loadfile>
<delete file="${temp.all.props.file}"/>
<xmltask destbuffer="src.buff" outputter="simple">
<insert path="/" xml="${src.xml}" position="under" />
</xmltask>
<src-init />
</then>
<else />
</antcontrib:if>
</sequential>
</macrodef>
<macrodef name="scm-export">
<attribute name="dest" />
<attribute name="type" />
<attribute name="uri" />
<attribute name="path" default="" />
<attribute name="tag" default="HEAD" />
<attribute name="user" default="" />
<attribute name="password" default="" />
<sequential>
<antcontrib:switch value="@{type}">
<case value="git">
<git-export repository="@{uri}" dest="@{dest}" path="@{path}" tag="@{tag}"/>
</case>
<case value="svn">
<svn-export uri="@{uri}" dest="@{dest}" />
</case>
</antcontrib:switch>
</sequential>
</macrodef>
<macrodef name="scm-checkout">
<attribute name="dest" />
<attribute name="type" />
<attribute name="uri" />
<attribute name="path" default="" />
<attribute name="tag" default="HEAD" />
<attribute name="branch" default="" />
<attribute name="remote" default="origin" />
<attribute name="user" default="" />
<attribute name="password" default="" />
<sequential>
<antcontrib:switch value="@{type}">
<case value="git">
<git-checkout uri="@{uri}" gitdir="@{dest}" branch="@{branch}" remote="@{remote}"/>
</case>
<case value="svn">
<svn-checkout uri="@{uri}" dest="@{dest}" user="@{user}" password="@{password}"/>
</case>
</antcontrib:switch>
</sequential>
</macrodef>
<target name="exists.src.xml" unless="exists.src.xml">
<available file="${src.xml.file}" type="file"
property="exists.src.xml"/>
<antcontrib:if>
<equals arg1="${exists.src.xml}" arg2="true" />
<then>
<echo message="src file exists : ${src.xml.file} " />
<load-src-xml />
</then>
<else>
<echo message="No src file to import : ${src.xml.file} does not exist." />
<antcontrib:if>
<not><equals arg1="${sc}" arg2="$${sc}" /></not>
<then>
<antcontrib:var name="exists.src.xml" value="true" />
<echo message="Using sc:${sc}"/>
<xmltask destbuffer="src.buff" outputter="simple" failWithoutMatch="true">
<insert path="/">
<![CDATA[<src><project><src branch="${sc.branch}" dest="${sc.dest}" user="${sc.user}" password="${sc.password}"
remote="${sc.remote}" type="${sc.type}" uri="${sc.uri}" scmurl="${sc.scmurl}"/></project></src>]]>
</insert>
</xmltask>
</then>
</antcontrib:if>
</else>
</antcontrib:if>
<property name="src.dir.absolute" location="${src.dir}" />
<antcontrib:var name="src.dir" unset="true" />
<property name="src.dir" location="${src.dir.absolute}" />
</target>
<macrodef name="src-init">
<sequential>
<xmltask sourcebuffer="src.buff">
<call path="src/project/*">
<param name="dest" path="@dest" default="NONE" />
<param name="type" path="@type" default="NONE" />
<param name="uri" path="@uri" default="NONE" />
<param name="path" path="@path" default="" />
<param name="branch" path="@branch" default="master" />
<param name="remote" path="@remote" default="origin" />
<param name="tag" path="@tag" default="HEAD" />
<param name="user" path="@user" default="" />
<param name="password" path="@password" default="" />
<actions>
<antcontrib:if>
<or>
<available file="@{dest}/.@{type}" type="dir"/>
<available file="@{dest}.@{type}" type="dir"/>
</or>
<then>
<echo message="Src dir : @{dest} @{type} exists " />
</then>
<else>
<echo message="Src dir : @{dest} @{type} ain't there, downloading" />
<scm-checkout dest="@{dest}" type="@{type}" uri="@{uri}" branch="@{branch}" remote="@{remote}" path="@{path}" tag="@{tag}" user="@{user}" password="@{password}" />
</else>
</antcontrib:if>
</actions>
</call>
<call path="src/sources/*">
<param name="dest" path="@dest" default="NONE" />
<param name="type" path="@type" default="NONE" />
<param name="uri" path="@uri" default="NONE" />
<param name="path" path="@path" default="" />
<param name="branch" path="@branch" default="master" />
<param name="remote" path="@remote" default="origin" />
<param name="tag" path="@tag" default="HEAD" />
<param name="user" path="@user" default="" />
<param name="password" path="@password" default="" />
<actions>
<antcontrib:if>
<available file="@{dest}" />
<then>
<echo message="Src dir : @{dest} exists " />
</then>
<else>
<echo message="Src dir : @{dest} ain't there, downloading" />
<scm-export dest="@{dest}" type="@{type}" uri="@{uri}" path="@{path}" tag="@{tag}" user="@{user}" password="@{password}" />
</else>
</antcontrib:if>
</actions>
</call>
</xmltask>
</sequential>
</macrodef>
<target name="src.import" depends="exists.src.xml" if="exists.src.xml">
<antcontrib:runtarget target="src.import.svn" />
<antcontrib:runtarget target="src.import.git" />
<antcontrib:runtarget target="src.import.cvs" />
</target>
<target name="check.project.for.newrevision" depends="get.project.src.type" unless="revisions.are.same" if="exists.src.xml">
<antcontrib:if>
<or>
<available file="${project.src.dest}/.${project.src.type}" type="dir"/>
<available file="${project.src.dest}.${project.src.type}" type="dir"/>
</or>
<then>
<antcontrib:runtarget target="check.project.for.newrevision.${project.src.type}" />
</then>
<else>
<echo message="Not there: ${project.src.dest}/.${project.src.type}" />
</else>
</antcontrib:if>
</target>
<target name="project.build.ifnew">
<mkdir dir="${war.target.dir}" />
<property name="testresult.file" value="${war.target.dir}/test.results.html/" />
<sequential>
<antcontrib:runtarget target="project.update" />
<antcontrib:if>
<equals arg1="${revisions.are.same}" arg2="true" />
<then>
<echo message="Revisions are the same, not building" />
</then>
<else>
<echo message="Revisions differ, running build" />
<sequential>
<antcontrib:runtarget target="build" />
</sequential>
</else>
</antcontrib:if>
</sequential>
</target>
<target name="exit.1.if.unchanged">
<mkdir dir="${war.target.dir}" />
<property name="testresult.file" value="${war.target.dir}/test.results.html/" />
<sequential>
<antcontrib:runtarget target="project.update" />
<antcontrib:if>
<or>
<equals arg1="${revisions.are.same}" arg2="false" />
<equals arg1="${revisions.remote.differ}" arg2="true" />
</or>
<then>
<echo message="Revisions differ, exiting with status 0." />
<fail message="<cause>SCM change</cause> <description>SCM change: Revisions differ</description>" status="0"/>
</then>
<else>
<echo message="Revisions are the same, not building" />
<fail message="Revisions are the same, unchanged. Exiting with status 1." status="1"/>
</else>
</antcontrib:if>
</sequential>
</target>
<target name="project.update" depends="check.project.for.newrevision" if="exists.src.xml">
<echo message="${exists.src.xml}" />
<antcontrib:runtarget target="project.update.${project.src.type}" />
</target>
<target name="project.checkout" depends="get.project.src.type" if="exists.src.xml">
<antcontrib:runtarget target="project.checkout.${project.src.type}" />
</target>
<target name="get.project.src.type" depends="exists.src.xml" if="exists.src.xml">
<xmltask sourcebuffer="src.buff">
<call path="src/project/*">
<param name="dest" path="@dest" default="NONE"/>
<param name="type" path="@type" default="NONE"/>
<param name="uri" path="@uri" default="NONE"/>
<param name="remote" path="@remote" default="NONE"/>
<param name="branch" path="@branch" default="NONE"/>
<actions>
<property name="project.src.type" value="@{type}" />
<property name="project.src.dest" value="@{dest}" />
<echo message="Project src type : ${project.src.type} dest: @{dest} @{remote}/@{branch}"/>
</actions>
</call>
</xmltask>
</target>
<antcontrib:if>
<equals arg1="${scm.branch}" arg2="$${scm.branch}" />
<then/>
<else>
<antcontrib:trycatch property="_erredesse">
<try>
<property name="scm.dir" value="${src.dir}" />
<property name="scm.remote" value="origin" />
<git-fetch-from-remote />
<!-- use the system git as jgit has trouble with conflicts -->
<git command="checkout" dir="${scm.dir}">
<args>
<arg value="-f" />
<arg value="${scm.remote}/${scm.branch}" />
</args>
</git>
</try>
<catch>
<echo message="could not check out ${scm.remote}/${scm.branch} for ${scm.dir} (${_erredesse})"/>
</catch>
</antcontrib:trycatch>
</else>
</antcontrib:if>
<antcontrib:if>
<equals arg1="${sc}" arg2="$${sc}" />
<then/>
<else>
<fail message="undefined! sc.type ${sc.type}" unless="sc.type" />
<fail message="undefined! sc.uri ${sc.uri}" unless="sc.uri" />
<fail message="undefined! sc.dest ${sc.dest}" unless="sc.dest" />
</else>
</antcontrib:if>
</project>