forked from collectionspace/application
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.xml
169 lines (150 loc) · 7.48 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
<project name="app-tenant-mgmt" default="clone-tenant" basedir=".">
<description>Manage Application layer folders and files containing per-tenant configurations</description>
<!-- Location of the 'tenants' directory for this CollectionSpace source code layer. -->
<property environment="env" />
<property name="src.dir" value="${basedir}" />
<property name="resources.dir" value="${src.dir}/tomcat-main/src/main/resources"/>
<property name="tenants.dir" value="${resources.dir}/tenants"/>
<!-- Imports a set of utility routines for managing tenant folders
from a separate Ant buildfile.
See http://wiki.apache.org/ant/NewAntFeaturesInDetail/Import -->
<import file="./tenant-utils-build.xml"/>
<!-- Location of the settings file for the newly-cloned tenant. -->
<property name="settings.file.name" value="settings.xml"/>
<property name="template.settings.file"
value="${tenants.dir}/${template.tenant.shortname}/${settings.file.name}"/>
<property name="tenant.settings.file" value="${tenants.dir}/${tenant.shortname}/${settings.file.name}"/>
<target name="bamboo">
<ant antfile="war-entry/build.xml" target="bamboo" inheritAll="false" />
</target>
<!-- This target inherits from an existing target in the imported
utility routines buildfile, and adds its own behavior specific to this
CollectionSpace source code layer. -->
<target name="clone-other-template-files"
depends="tenant-utils.clone-other-template-files,
clone-tenant-schema-config-file">
</target>
<target name="clone-tenant-schema-config-file">
<copy file="${resources.dir}/${template.tenant.shortname}-tenant.xml"
tofile="${resources.dir}/${tenant.shortname}-tenant.xml"/>
</target>
<!-- This target inherits from an existing target in the imported
utility routines buildfile, and adds its own behavior specific to this
CollectionSpace source code layer. -->
<target name="rename-files-in-cloned-tenant" depends="tenant-utils.rename-files-in-cloned-tenant">
<move todir="${tenants.dir}/${tenant.shortname}" includeemptydirs="false">
<fileset dir="${tenants.dir}/${tenant.shortname}"/>
<mapper type="regexp" from="^(.*?)${template.tenant.shortname}(.*)$" to="\1${tenant.shortname}\2"/>
</move>
</target>
<!-- This target inherits from an (essentially empty) target in the imported
utility routines buildfile, and adds its own behavior specific to this
CollectionSpace source code layer. -->
<target name="update-text-in-cloned-tenant"
depends="tenant-utils.update-text-in-cloned-tenant,
update-text-in-tenant-config,
update-text-in-tenant-settings">
</target>
<target name="update-text-in-tenant-config">
<!-- Update text in the tenant config file. -->
<replaceregexp
file="${resources.dir}/${tenant.shortname}-tenant.xml"
flags="g"
match="(?<!extensions/)${template.tenant.shortname}"
replace="${tenant.shortname}"
/>
<replaceregexp
file="${resources.dir}/${tenant.shortname}-tenant.xml"
flags="g"
match="<tenantid>.*?</tenantid>"
replace="<tenantid>${tenant.id}</tenantid>"
/>
</target>
<target name="update-text-in-tenant-settings"
depends="update-tenant-id-in-tenant-settings,
update-disabled-flag-in-tenant-settings,
update-tenant-internet-domain-in-tenant-settings,
update-tenant-shortname-in-tenant-settings,
update-repository-domain-and-name-in-tenant-settings">
</target>
<target name="update-tenant-id-in-tenant-settings">
<replaceregexp
file="${tenant.settings.file}"
match="<tenant>(.*)</tenant>"
replace="<tenant>${tenant.id}</tenant>">
</replaceregexp>
<replaceregexp
file="${tenant.settings.file}"
match="<id>(.*)</id>"
replace="<id>${tenant.id}</id>">
</replaceregexp>
</target>
<target name="update-disabled-flag-in-tenant-settings">
<!-- Ensure that even if the template tenant is disabled, -->
<!-- the new, cloned tenant will always be created as 'enabled'. -->
<replaceregexp
file="${tenant.settings.file}"
match="<create-disabled>(.*)</create-disabled>"
replace="<create-disabled>false</create-disabled>">
</replaceregexp>
</target>
<target name="extract-template-tenant-internet-domain" depends="tenant-utils.check-template-properties">
<!-- Will retrieve the template tenant's Internet domain from the text node at -->
<!-- XPath /settings/persistence/service/tenant/name and store its value -->
<!-- in a property of the same name, using dots as delimiters rather than slashes -->
<xmlproperty file="${template.settings.file}"/>
<property name="template.internet.domain" value="${settings.persistence.service.tenant.name}"/>
<echo message="template.internet.domain=${template.internet.domain}"/>
</target>
<target name="update-tenant-internet-domain-in-tenant-settings"
depends="extract-template-tenant-internet-domain">
<!-- Note: this text replacement is brute-force and will even replace sub-strings,
if found, so you'll need to ensure that the template tenant's Internet domain is a
unique string: that it won't be inadvertently contained within text elsewhere. -->
<!-- TODO: Perform more nuanced replacements to avoid the problem described above.
(See the Ant ReplaceRegExp task for one potential approach when doing so.) -->
<replace file="${tenant.settings.file}" token="${template.internet.domain}"
value="${tenant.internet.domain}">
</replace>
</target>
<target name="update-tenant-shortname-in-tenant-settings">
<replaceregexp
file="${tenant.settings.file}"
match="(?<!\w)${template.tenant.shortname}(?!\w)"
replace="${tenant.shortname}"
flags="gi">
</replaceregexp>
</target>
<target name="update-repository-domain-and-name-in-tenant-settings">
<replaceregexp
file="${tenant.settings.file}"
match="<repository>\s*<domain>.*?</domain>\s*<name>.*?</name>"
replace="<repository>
				<domain>${tenant.shortname}</domain>
				<name>${tenant.shortname}</name>"
flags="m">
</replaceregexp>
</target>
<!-- This target inherits from an (essentially empty) target in the imported
utility routines buildfile, and adds its own behavior specific to this
CollectionSpace source code layer. -->
<target name="check-tenant-extended-properties"
depends="tenant-utils.check-tenant-extended-properties">
<!-- ID of the new tenant to create -->
<antcall target="check-property-is-defined">
<param name="property-to-check" value="tenant.id"/>
</antcall>
<antcall target="check-property-value-is-not-blank">
<param name="property-to-check" value="tenant.id"/>
<param name="property-to-check-value" value="${tenant.id}"/>
</antcall>
<echo message="tenant.id=${tenant.id}"/>
<!-- Internet domain of the new tenant to create -->
<antcall target="check-property-is-defined">
<param name="property-to-check" value="tenant.internet.domain"/>
</antcall>
<antcall target="check-property-value-is-not-blank">
<param name="property-to-check" value="tenant.internet.domain"/>
<param name="property-to-check-value" value="${tenant.internet.domain}"/>
</antcall>
<echo message="tenant.internet.domain=${tenant.internet.domain}"/>
</target>
</project>