comparison teamcity-common.xml @ 76:84f8c95be7bb

teamcity-common.xml added
author Pavel.Sher
date Fri, 09 Oct 2009 17:15:20 +0400
parents
children 8cc11b0cbbd4
comparison
equal deleted inserted replaced
75:a74563111be4 76:84f8c95be7bb
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project name="TeamCityPluginCommon">
3
4 <!--
5 Tasks:
6 package.teamcity.plugin
7 deploy.teamcity.plugin
8 undeploy.teamcity.plugin
9 unpack.teamcity
10
11 Targets:
12 check.teamcitydistribution
13 -->
14
15 <property name="path.variable.teamcitydistribution" value="${teamcity.distribution}"/>
16
17 <property name="teamcity.internal.default.out" value="dist"/>
18
19
20 <macrodef name="package.teamcity.plugin" description="packages TeamCity plugin">
21 <attribute name="name" description="name of the plugin"/>
22 <attribute name="server.output" default="" description="path to compiled server plugin output"/>
23 <attribute name="agent.output" default="" description="path to compiled agent plugin output"/>
24 <attribute name="common.output" default="" description="path to compiled common plugin output"/>
25 <attribute name="out" default="${teamcity.internal.default.out}" description="directory to put prepared plugin zip into"/>
26 <attribute name="plugin.descriptor.file" default="${basedir}/teamcity-plugin.xml" description="path to teamcity-plugin.xml file"/>
27 <attribute name="common.jar.name" default="@{name}-common.jar" description="name of the shared jar between server and agent"/>
28 <attribute name="out.unpacked" default="@{out}/unpacked"
29 description="name of the directory to store unpacked plugin (not packed into zip)"/>
30
31 <attribute name="server.lib.dir" default="" description="directory to get libs for the server part"/>
32 <attribute name="server.lib.includes" default="none should match" description="includes pattern of the files in the directory"/>
33 <attribute name="plugin.version" default="SNAPSHOT"
34 description="the version of the plugin to put into teamcity-plugin.xml instead of '@version@'"/>
35
36 <element name="additional-files" optional="yes" description="fileset of the files to pack into root of the plugin"/>
37
38 <sequential>
39
40 <antcall target="check.already.defined"/>
41
42 <property name="teamcity.internal.distrib.prep" value="${basedir}/temp/dist_prep"/>
43 <property name="teamcity.internal.distrib.prep.agent" value="${teamcity.internal.distrib.prep}/agent"/>
44 <property name="teamcity.internal.distrib.prep.common" value="${teamcity.internal.distrib.prep}/common"/>
45 <property name="teamcity.internal.distrib.prep.agent.jars" value="${teamcity.internal.distrib.prep.agent}/unpacked"/>
46
47
48 <!-- build jars -->
49
50 <delete dir="@{out.unpacked}" quiet="true"/>
51 <delete dir="${teamcity.internal.distrib.prep}" quiet="true"/>
52
53 <mkdir dir="@{out.unpacked}"/>
54
55 <condition property="common.needed">
56 <length string="@{common.output}" when="greater" length="0"/>
57 </condition>
58 <condition property="server.needed">
59 <length string="@{server.output}" when="greater" length="0"/>
60 </condition>
61 <condition property="agent.needed">
62 <length string="@{agent.output}" when="greater" length="0"/>
63 </condition>
64
65 <condition property="plugin.descriptor.file.needed">
66 <and>
67 <available file="@{plugin.descriptor.file}"/>
68 <length string="@{plugin.descriptor.file}" when="greater" length="0"/>
69 </and>
70 </condition>
71
72 <mkdir dir="${teamcity.internal.distrib.prep.common}"/>
73 <antcall target="prepare.common.part">
74 <param name="common.output" value="@{common.output}"/>
75 <param name="common.jar.path" value="${teamcity.internal.distrib.prep.common}/@{common.jar.name}"/>
76 </antcall>
77
78 <antcall target="prepare.server.part">
79 <param name="out.unpacked" value="@{out.unpacked}"/>
80 <param name="name" value="@{name}"/>
81 <param name="server.output" value="@{server.output}"/>
82 <param name="common.jar.path" value="${teamcity.internal.distrib.prep.common}/@{common.jar.name}"/>
83 <param name="lib.dir" value="@{server.lib.dir}"/>
84 <param name="lib.includes" value="@{server.lib.includes}"/>
85 </antcall>
86
87 <antcall target="prepare.agent.part">
88 <param name="out.unpacked" value="@{out.unpacked}"/>
89 <param name="name" value="@{name}"/>
90 <param name="agent.output" value="@{agent.output}"/>
91 <param name="common.jar.path" value="${teamcity.internal.distrib.prep.common}/@{common.jar.name}"/>
92 </antcall>
93
94 <!-- copy teamcity-plugin.xml -->
95 <antcall target="prepare.plugin.descriptor.file">
96 <param name="source" value="@{plugin.descriptor.file}"/>
97 <param name="dest" value="@{out.unpacked}/teamcity-plugin.xml"/>
98 <param name="plugin.version" value="@{plugin.version}"/>
99 </antcall>
100
101 <!-- copy additional files -->
102 <copy todir="@{out.unpacked}" failonerror="false">
103 <fileset dir="${basedir}" excludes="**/*"/>
104 <additional-files/>
105 </copy>
106
107 <!-- clean -->
108 <echo message="Cleaning..."/>
109 <delete dir="${teamcity.internal.distrib.prep}" quiet="true"/>
110
111 <!-- package in zip -->
112 <echo message="Packaging zip..."/>
113 <delete file="@{out}/@{name}.zip" quiet="true"/>
114 <zip destfile="@{out}/@{name}.zip">
115 <fileset dir="@{out.unpacked}"/>
116 </zip>
117 <echo message="To install the plugin, place '@{out}\@{name}.zip' into '.BuildServer/plugins' directory"/>
118
119 </sequential>
120 </macrodef>
121
122 <target name="check.teamcitydistribution" description="checks whether TeamCity distribution ready to be used by IDEA-generated build">
123 <check.property name="path.variable.teamcitydistribution"
124 fail-message="Please define 'teamcity.distribution' or 'path.variable.teamcitydistribution' property in build.properties file (see build.properties.dist). The property should point to unpacked TeamCity .tar.gz or .exe distribution."
125 />
126
127 <condition property="teamcity.distribution.not.present">
128 <not>
129 <and>
130 <available file="${path.variable.teamcitydistribution}/webapps/ROOT/WEB-INF/lib"/>
131 </and>
132 </not>
133 </condition>
134 <fail if="teamcity.distribution.not.present"
135 message="Cannot find TeamCity distribution at path '${path.variable.teamcitydistribution}'. The property 'teamcity.distribution' or 'path.variable.teamcitydistribution' should point to unpacked TeamCity .tar.gz or .exe distribution."/>
136 </target>
137
138 <macrodef name="deploy.teamcity.plugin">
139 <attribute name="name"/>
140 <attribute name="teamcity.data.path" default="${user.home}/.BuildServer" description="path to .BuildServer"/>
141 <attribute name="out" default="${teamcity.internal.default.out}" description="directory storing prepared plugin zip"/>
142
143 <sequential>
144 <copy file="@{out}/@{name}.zip" todir="@{teamcity.data.path}/plugins" failonerror="true"/>
145 </sequential>
146 </macrodef>
147
148 <macrodef name="undeploy.teamcity.plugin">
149 <attribute name="name"/>
150 <attribute name="teamcity.data.path" default="${user.home}/.BuildServer" description="path to .BuildServer"/>
151
152 <sequential>
153 <delete file="@{teamcity.data.path}/plugins/@{name}.zip" quiet="true"/>
154 </sequential>
155 </macrodef>
156
157
158 <macrodef name="unpack.teamcity" description="TeamCity distribution unpacking">
159 <attribute name="distribution.dir" default="${basedir}/teamcity-dist"
160 description="path to put unpacked TeamCity distribution into. Warning: the content of the directory will be deleted!"/>
161 <attribute name="teamcity.data.path" default="${user.home}/.BuildServer" description="path to .BuildServer"/>
162 <attribute name="teamcity.tar.gz-location" default="${basedir}" description="path where TeamCity-NNNN.tar.gz file resides"/>
163
164 <sequential>
165 <delete dir="@{distribution.dir}" quiet="true"/>
166 <mkdir dir="@{distribution.dir}"/>
167
168 <!-- TODO: issue error if there are several matching files -->
169
170 <untar compression="gzip" dest="@{distribution.dir}">
171 <fileset dir="@{teamcity.tar.gz-location}">
172 <include name="*.tar.gz"/>
173 </fileset>
174 </untar>
175
176 <move todir="@{distribution.dir}">
177 <fileset dir="@{distribution.dir}\TeamCity">
178 <include name="**"/>
179 </fileset>
180 </move>
181 </sequential>
182 </macrodef>
183
184
185 <!-- ** Implementation ** -->
186
187 <macrodef name="check.property">
188 <attribute name="name"/>
189 <attribute name="fail-message" default=""/>
190 <attribute name="check-path" default=""/>
191 <sequential>
192 <condition property="is.configured.@{name}">
193 <not>
194 <and>
195 <isset property="@{name}"/>
196 <length string="${@{name}}" when="greater" length="0"/>
197 </and>
198 </not>
199 </condition>
200 <fail if="is.configured.@{name}"
201 message="Property '@{name}' not defined. @{fail-message}"/>
202 </sequential>
203 </macrodef>
204
205
206 <target name="prepare.common.part" if="common.needed">
207 <jar destfile="${common.jar.path}">
208 <fileset dir="${common.output}"/>
209 </jar>
210 </target>
211
212
213 <target name="prepare.server.part" if="server.needed">
214 <mkdir dir="${out.unpacked}/server"/>
215
216 <jar destfile="${out.unpacked}/server/${name}.jar">
217 <fileset dir="${server.output}"/>
218 </jar>
219
220 <copy todir="${out.unpacked}/server" failonerror="false">
221 <fileset file="${common.jar.path}"/>
222 <fileset dir="${lib.dir}" includes="${lib.includes}"/>
223 </copy>
224 </target>
225
226
227 <target name="prepare.agent.part" if="agent.needed">
228 <!-- prepare.agent.part -->
229 <mkdir dir="${teamcity.internal.distrib.prep.agent}"/>
230 <mkdir dir="${teamcity.internal.distrib.prep.agent.jars}/${name}/lib"/>
231 <mkdir dir="${out.unpacked}/agent"/>
232
233 <jar destfile="${teamcity.internal.distrib.prep.agent.jars}/${name}/lib/${name}.jar">
234 <fileset dir="${agent.output}"/>
235 </jar>
236
237 <copy todir="${teamcity.internal.distrib.prep.agent.jars}/${name}/lib" failonerror="false">
238 <fileset file="${common.jar.path}"/>
239 </copy>
240
241 <zip destfile="${out.unpacked}/agent/${name}.zip">
242 <fileset dir="${teamcity.internal.distrib.prep.agent.jars}"/>
243 </zip>
244 </target>
245
246 <target name="prepare.plugin.descriptor.file" if="plugin.descriptor.file.needed">
247 <echo message="Copying plugin descriptor file '${source}' to '${dest}'."/>
248 <copy file="${source}" tofile="${dest}" failonerror="false"/>
249
250 <echo message="Replacing '@version@' on '${plugin.version}' in the copied plugin descriptor file."/>
251 <replace file="${dest}" value="${plugin.version}">
252 <replacetoken><![CDATA[@version@]]></replacetoken>
253 </replace>
254 </target>
255
256 <target name="check.already.defined">
257 <condition property="already.defined">
258 <isset property="teamcity.internal.distrib.prep"/>
259 </condition>
260 <fail if="already.defined"
261 message="It seems you are trying to use the script several times in the same context. This script does not support such use. Please call this script as a separate Ant process, via 'ant' task."/>
262 </target>
263
264 </project>