/
common.xml
210 lines (192 loc) · 10.6 KB
/
common.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
<?xml version="1.0" encoding="UTF-8"?>
<project name="appserver-io/routlt-project">
<!-- initialize ENV variable -->
<property environment="env" />
<!-- initialize the Rout.Lt specific properties -->
<property name="appserver.webapps.dir" value="${basedir}/webapps" />
<property name="routlt-project.basedir" value="${vendor.dir}/appserver-io/routlt-project" />
<!-- initialize file based properties -->
<property file="${routlt-project.basedir}/common.default.properties"/>
<!-- ==================================================================== -->
<!-- Defines a Script to uppercase a string -->
<!-- ==================================================================== -->
<scriptdef language="javascript" name="upper">
<attribute name="string" />
<attribute name="to" />
<![CDATA[
project.setProperty(attributes.get("to" ), attributes.get("string").toUpperCase());
]]>
</scriptdef>
<!-- ==================================================================== -->
<!-- Defines a Script to lowercase a string -->
<!-- ==================================================================== -->
<scriptdef language="javascript" name="lower">
<attribute name="string" />
<attribute name="to" />
<![CDATA[
project.setProperty(attributes.get("to"), attributes.get("string").toLowerCase());
]]>
</scriptdef>
<!-- ==================================================================== -->
<!-- Defines a Script to uppercase the first character of a string -->
<!-- ==================================================================== -->
<scriptdef language="javascript" name="ucfirst">
<attribute name="string" />
<attribute name="to" />
<![CDATA[
var the_string = attributes.get("string");
project.setProperty(attributes.get("to"), the_string.substr(0,1).toUpperCase() + the_string.substr(1));
]]>
</scriptdef>
<!-- ==================================================================== -->
<!-- Defines a Script to capitalize a strings words (split by a seprator) -->
<!-- ==================================================================== -->
<scriptdef language="javascript" name="capitalize">
<attribute name="string" />
<attribute name="to" />
<attribute name="separator"/>
<![CDATA[
// load the input data
var string = new String(attributes.get("string"));
var separator = new String(attributes.get("separator"));
// split the string into an array
var strArr = new String(string).split(separator);
var newArr = [];
// upper case each word
for (var i = 0 ; i < strArr.length ; i++ ) {
var FirstLetter = strArr[i].charAt(0).toUpperCase();
var restOfWord = strArr[i].slice(1);
newArr[i] = FirstLetter + restOfWord;
}
// set the output property with the capitalized string
project.setProperty(attributes.get("to"), newArr.join(''));
]]>
</scriptdef>
<!-- ==================================================================== -->
<!-- Creates a Rout.Lt 2 project for appserver.io -->
<!-- ==================================================================== -->
<target name="routlt-create-project" description="Creates a Rout.Lt 2 project for appserver.io.">
<!-- query the user for necessary project data -->
<input addproperty="project.type" defaultvalue="default" validargs="default,ionic,foundation-apps" message="Project Type"/>
<input addproperty="admin.email" defaultvalue="${stub.default.admin.email}" message="Administrator E-Mail Address"/>
<input addproperty="vendor.name" defaultvalue="${stub.default.vendor.name}" message="Vendor Name"/>
<input addproperty="application.name" defaultvalue="${stub.default.application.name}" message="Application Name"/>
<input addproperty="installation.dir" defaultvalue="${appserver.webapps.dir}/${application.name}" message="Installation Directory"/>
<input addproperty="composer.name" defaultvalue="${vendor.name}/${application.name}" message="Composer Name"/>
<!-- capitalize application/vendor name for furhter usage -->
<capitalize string="${vendor.name}" to="vendor.name.capitalized" separator="-" />
<capitalize string="${application.name}" to="application.name.capitalized" separator="-" />
<!-- prepare Rout.Lt 2 configuration specific namespaces -->
<property name="composer.namespace" value="${vendor.name.capitalized}\\${application.name.capitalized}"/>
<property name="application.namespace" value="${vendor.name.capitalized}\${application.name.capitalized}"/>
<property name="routlt.action.namespace" value="/${vendor.name.capitalized}/${application.name.capitalized}/Actions"/>
<!-- prepare Rout.Lt 2 application specific namespaces -->
<property name="util.namespace" value="${application.namespace}\Util"/>
<property name="action.namespace" value="${application.namespace}\Actions"/>
<!-- copy the static framework files -->
<copy todir="${installation.dir}">
<fileset dir="${routlt-project.basedir}/templates/${project.type}/static">
<include name="**/*"/>
<exclude name="build.xml"/>
</fileset>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<!-- copy the build.xml file, but ONLY replace the project name -->
<copy file="${routlt-project.basedir}/templates/${project.type}/static/build.xml" todir="${installation.dir}">
<filterchain>
<expandproperties>
<propertyset>
<propertyref name="composer.name" />
</propertyset>
</expandproperties>
</filterchain>
</copy>
<!-- copy the dynamic framework class iles -->
<copy todir="${installation.dir}/WEB-INF/classes/${application.namespace}">
<fileset dir="${routlt-project.basedir}/templates/${project.type}/dynamic/WEB-INF/classes">
<include name="**/*"/>
</fileset>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<!-- copy the dynamic framework test files -->
<copy todir="${installation.dir}/WEB-INF/tests/${application.namespace}">
<fileset dir="${routlt-project.basedir}/templates/${project.type}/dynamic/WEB-INF/tests">
<include name="**/*"/>
</fileset>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<!-- install composer dependencies -->
<exec dir="${installation.dir}" executable="ant">
<arg line="post-install"/>
</exec>
</target>
<!-- ==================================================================== -->
<!-- Wrapper with condition whether to create a virtual-host or not -->
<!-- ==================================================================== -->
<target name="routlt-create-virtual-host-wrapper" if="${virtual-host.create}">
<antcall target="routlt-create-virtual-host"/>
</target>
<!-- ==================================================================== -->
<!-- Creates a Rout.Lt 2 specific virtual host for appserver.io. -->
<!-- ==================================================================== -->
<target name="routlt-create-virtual-host" description="Creates a Rout.Lt 2 specific virtual host for appserver.io.">
<!-- query the user for necessary virtual-host data -->
<input addproperty="application.name" defaultvalue="myapp" message="Application Name"/>
<input addproperty="virtual-host.name" defaultvalue="${application.name}.dev" message="Virtual-Host Name"/>
<!-- print a message with the virtual host name/file -->
<echo message="Now creating virtual-host: ${virtual-host.name} in ${virtual-host.target.file}" />
<!-- load the virtual-host configuration -->
<loadfile
property="virtual-host.src"
srcfile="${virtual-host.source.file}">
<filterchain>
<expandproperties/>
</filterchain>
</loadfile>
<!-- add/replace the virtual host configuration -->
<xmltask source="${virtual-host.target.file}" dest="${virtual-host.target.file}">
<!-- try to remove an existing virtual host -->
<remove path="/:virtualHosts/:virtualHost[@name='${virtual-host.name}']" />
<!-- add the new virtual host for -->
<insert
position="after"
path="/:virtualHosts/:virtualHost[last()]"
xml="${virtual-host.src}">
</insert>
</xmltask>
<!-- create the hosts entry if necessary -->
<antcall target="routlt-create-hosts-entry"/>
</target>
<!-- ==================================================================== -->
<!-- Queries whether the hosts entry in /etc/hosts already exists or not -->
<!-- ==================================================================== -->
<target name="routlt-check-host-entry-exists" description="Queries whether the hosts entry in /etc/hosts already exists or not.">
<loadfile property="hosts-file-content" srcfile="${hosts.file}"/>
<condition property="create-hosts-entry">
<and>
<isfileselected file="${hosts.file}">
<writable />
</isfileselected>
<not>
<contains substring="${virtual-host.name}" string="${hosts-file-content}"/>
</not>
</and>
</condition>
</target>
<!-- ==================================================================== -->
<!-- Creates a new entry in the /etc/hosts file -->
<!-- ==================================================================== -->
<target name="routlt-create-hosts-entry" depends="routlt-check-host-entry-exists" if="create-hosts-entry" description="Creates a new entry in the /etc/hosts file.">
<echo>Now append ${virtual-host.name} ${hosts.file} entry</echo>
<echo file="${hosts.file}" append="true"><![CDATA[
127.0.0.1 ${virtual-host.name}
::1 ${virtual-host.name}
fe80::1%lo0 ${virtual-host.name}]]></echo>
</target>
</project>