-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
205 lines (191 loc) · 8.32 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
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* @author Richard Kuhnt
* @license MIT License (https://r15ch13.mit-license.org/)
*/
-->
<project name="WCF/WBB Package Builder" default="help" basedir=".">
<property file="default.properties" />
<property name="build.dir" value="dist" />
<property name="build.source" value="src" />
<property name="build.compress" value="true" />
<property name="package.xml" value="${build.source}/package.xml" />
<property name="script.version" value="2.0.0" />
<target name="help" description="Displays the available options">
<echo msg="${phing.project.name} ${script.version}" />
<echo msg="------------------" />
<echo msg="Build options" />
<echo msg="------------------" />
<echo msg="$ phing prepare - Creates new build directory" />
<echo msg="$ phing init - Creates basic package structure (language, tar, xml) and package.xml" />
<echo msg="$ phing update-date - Updates the package creation date" />
<echo msg="$ phing update-version - Updates the package version" />
<echo msg="$ phing build - Create new package" />
<echo msg="$ phing help - Displays the available options" />
<echo msg="------------------" />
<echo msg="Package structure:" />
<echo msg="Projectfolder" />
<echo msg="|-- dist # The build package will be saved here ([packagename]_v[version].tar[.gz])" />
<echo msg="|-- src" />
<echo msg="| |-- language # Language-Files (*.xml)" />
<echo msg="| |-- optionals # optional Packages (*.tar | *.tar.gz)" />
<echo msg="| |-- requirements # required Packages (*.tar | *.tar.gz)" />
<echo msg="| |-- sql # SQL-Files (*.sql)" />
<echo msg="| | |-- install.sql" />
<echo msg="| | `-- update.sql" />
<echo msg="| |-- tar # All subfolders will be packed to [foldername].tar" />
<echo msg="| | |-- acptemplates" />
<echo msg="| | |-- files" />
<echo msg="| | |-- templates" />
<echo msg="| | `-- pip" />
<echo msg="| |-- xml # Other XML-Files (*.xml)" />
<echo msg="| `-- package.xml # Plugin package.xml" />
<echo msg="`-- build.xml" />
</target>
<target name="test" depends="load-package-data">
<echo msg="${phing.project.name} ${script.version}" />
<echo msg="${package.version}" />
<echo msg="${package.name}" />
</target>
<target name="init" description="Create basic package folder structure">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.source}" />
<mkdir dir="${build.source}/language" />
<mkdir dir="${build.source}/tar" />
<mkdir dir="${build.source}/tar/files" />
<mkdir dir="${build.source}/tar/templates" />
<mkdir dir="${build.source}/xml" />
<available file="${package.xml}" property="package.exists" value="1" />
<if>
<equals arg1="${package.exists}" arg2="1" />
<then>
<echo msg="package.xml already exists" />
</then>
<else>
<echo msg="Creating template package.xml" />
<input propertyname="init.name" defaultvalue="com.example.packagename">Enter package name</input>
<php expression="chr(10)" returnProperty="LF" />
<php expression="chr(9)" returnProperty="TAB" />
<echo file="${package.xml}" append="false">${package.template}</echo>
<replaceregexp file="${package.xml}" match="\\n" replace="${LF}" />
<replaceregexp file="${package.xml}" match="\\t" replace="${TAB}" />
<replaceregexp file="${package.xml}" match="(com.example.packagename)" replace="${init.name}" />
<phingcall target="update-version" />
<phingcall target="update-date" />
</else>
</if>
</target>
<target name="prepare" depends="load-package-data" description="Creates new build directory and creates tar archives">
<echo msg="Preparing build directory ..." />
<mkdir dir="${build.dir}" />
<echo msg="Creating *.tar archives ..." />
<foreach param="foldername" absparam="absfoldername" target="buildtars">
<fileset dir="." defaultexcludes="true">
<exclude name="${build.source}/tar/*.tar"/>
<include name="${build.source}/tar/*"/>
</fileset>
</foreach>
</target>
<target name="buildtars" description="Creates tar archives for each firstlevel subdirectory">
<available file="${foldername}" property="folder.exists" value="1" />
<if>
<equals arg1="${folder.exists}" arg2="1" />
<then>
<tar destfile="${foldername}.tar" compression="none">
<fileset dir="${foldername}" defaultexcludes="true">
</fileset>
</tar>
</then>
<else>
<echo msg="${foldername} not found." />
</else>
</if>
</target>
<target name="cleanup" description="Deletes previous build tar files">
<delete>
<fileset dir="." defaultexcludes="true">
<include name="${build.source}/tar/*.tar" />
</fileset>
</delete>
</target>
<target name="build" depends="load-package-data">
<available file="${build.dir}/${package.name}_v${package.version}.tar.gz" property="file.exists" value="1" />
<available file="${build.dir}/${package.name}_v${package.version}.tar" property="file.exists" value="1" />
<if>
<equals arg1="${file.exists}" arg2="1" />
<then>
<echo msg="Package with version ${package.version} already exists!" />
<input propertyname="package.override" validargs="y,n" defaultvalue="n">Do you want to override it? </input>
<if>
<equals arg1="${package.override}" arg2="y" />
<then>
<delete file="${build.dir}/${package.name}_v${package.version}.tar.gz" />
<delete file="${build.dir}/${package.name}_v${package.version}.tar" />
<phingcall target="realbuild" />
</then>
</if>
</then>
<else>
<phingcall target="realbuild" />
</else>
</if>
</target>
<target name="realbuild" depends="load-package-data, update-date, cleanup, prepare">
<echo msg="${phing.project.name} ${script.version}" />
<echo msg="Building ${package.name} ..." />
<fileset dir="${build.source}" id="package" defaultexcludes="true">
<include name="language/*.xml" />
<include name="optionals/*.tar" />
<include name="optionals/*.tar.gz" />
<include name="requirements/*.tar" />
<include name="requirements/*.tar.gz" />
<include name="sql/*" />
<include name="tar/*.tar" />
<include name="xml/*" />
<include name="package.xml" />
</fileset>
<if>
<equals arg1="${build.compress}" arg2="1" />
<then>
<echo msg="creating compressed package" />
<tar destfile="${build.dir}/${package.name}_v${package.version}.tar.gz" compression="gzip">
<fileset refid="package" />
</tar>
</then>
<else>
<echo msg="creating uncompressed package" />
<tar destfile="${build.dir}/${package.name}_v${package.version}.tar" compression="none">
<fileset refid="package" />
</tar>
</else>
</if>
</target>
<!-- Loads package version and name from package.xml and saves them to package.version and package.name properties -->
<target name="load-package-data" description="Loads package version and name from package.xml and saves them to package.version and package.name properties">
<loadfile property="package.content" file="${package.xml}" />
<propertyregex property="package.version" subject="${package.content}" pattern="${pattern.version}" match="$1" casesensitive="false" defaultvalue="0.0.1" />
<propertyregex property="package.name" subject="${package.content}" pattern="${pattern.name}" match="$1" casesensitive="false" defaultvalue="CHANGEME" />
<echo msg="Extracted Version: ${package.version}" />
<echo msg="Extracted Packagename: ${package.name}" />
</target>
<target name="update-date" description="Updating the package creation date">
<tstamp>
<format property="date" pattern="%Y-%m-%d" />
</tstamp>
<replaceregexp file="${package.xml}" match="${pattern.date}" replace="<date>${date}</date>" byline="true" />
</target>
<target name="update-version" depends="load-package-data" description="Updating the package version">
<input propertyname="package.newversion" defaultvalue="${package.version}">Enter package version</input>
<if>
<equals arg1="${package.newversion}" arg2="${package.version}" />
<then>
<echo msg="Version has not been changed." />
</then>
<else>
<echo msg="Changing version from v${package.version} to v${package.newversion}." />
<replaceregexp file="${package.xml}" match="${pattern.version}" replace="<version>${package.newversion}</version>" byline="true" />
</else>
</if>
</target>
</project>