Subversion Repositories DevTools

Rev

Rev 1972 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1972 jgill 1
<project name="using-macrodef">
2
 
3
    <!--	C O P Y R I G H T   N O T I C E
4
			This material is confidential to ERG and may not be disclosed in whole
5
			or in part to any third party nor used in any manner whatsoever other
6
			than for the purposes expressly consented to by ERG in writing.
7
 
8
			This material is also copyright and may not be reproduced, stored in a
9
			retrieval system or transmitted in any form or by any means in whole or
10
			in part without the express written consent of ERG.
11
	-->
12
 
13
 
14
    <!--						BUILD ENVIRONMENT NOTES
15
 
16
		GBE_DPKG_CACHE	=	Global Build Environment DPKG Cache
17
							(This location holds the local set of artefacts acquired from DPKG,
18
							 for use within a build)
19
 
20
		GBE_DPKG		=	Global Build Environment DPKG source
21
 
22
	-->
23
 
24
    <property name="env" environment="env" value="not used" />
25
 
26
 
27
    <macrodef name="using">
28
 
29
        <attribute name="name" />
30
        <attribute name="version" default="$${@{name}}" />
31
        <attribute name="includes" default="" />
32
        <attribute name="from" default="${env.GBE_DPKG}" />
33
        <attribute name="refid" default="@{name}" />
34
        <attribute name="copy" default="true" />
35
 
36
        <element name="using-fileset"
37
                 optional="yes"
38
                 implicit="yes"
39
                 description="Anything you can put in a fileset." />
40
 
41
        <sequential>
42
 
43
            <property name="using.@{name}.version" value="@{version}" />
44
 
45
            <fail message="The 'using' for package @{name} has already been declared as version @{version}"
46
                  status="2">
47
                <condition>
48
                    <and>
49
                        <isset property="using.@{name}.version" />
50
                        <not>
51
                            <equals arg1="${using.@{name}.version}" arg2="@{version}" />
52
                        </not>
53
                    </and>
54
                </condition>
55
            </fail>
56
 
57
            <if>
58
                <isset property="using.@{refid}.basedir" />
59
                <then>
60
                    <echo taskname="using" level="verbose">@{name} has already been defined. Skipping import...</echo>
61
                </then>
62
                <else>
63
                    <if>
64
                        <not>
65
                            <isset property="manifest.prepared" />
66
                        </not>
67
                        <then>
68
                            <delete file="${basedir}/build/pkg/descpkg" quiet="true" />
69
                            <property name="manifest.prepared" value="true" />
70
                        </then>
71
                    </if>
72
 
73
                    <if>
1978 jgill 74
                        <and>
75
                            <equals arg1="@{copy}" arg2="true" />
76
        					<isset property="env.GBE_DPKG_CACHE"/>
77
                            <length string="${env.GBE_DPKG_CACHE}" trim="true" when="greater" length="0"/>
78
                        </and>
1972 jgill 79
                        <then>
80
                            <property name="using.@{refid}.basedir"
81
                                      value="${build.repository}/@{name}/@{version}" />
82
                        </then>
83
                        <else>
84
                            <property name="using.@{refid}.basedir" value="@{from}/@{name}/@{version}" />
85
                        </else>
86
                    </if>
87
 
88
                    <mkdir dir="${basedir}/build/pkg" />
89
                    <!--<manifest file="${basedir}/build/pkg/descpkg" mode="update">
90
						<section name="Build Dependencies">
91
							<attribute name="@{name}" value="@{version}"/>
92
						</section>
93
					</manifest>
94
					-->
95
 
96
                    <echo taskname="using">@{name} version @{version}</echo>
97
                    <if>
98
                        <and>
99
                            <equals arg1="@{copy}" arg2="true" />
100
                            <!-- Only copy from the package archive if the source and target locations are different -->
101
                            <not>
102
                                <equals arg1="@{from}/@{name}/@{version}" arg2="${using.@{refid}.basedir}" />
103
                            </not>
104
                            <!-- Don't copy if the using.nocache property is true. -->
105
                            <isfalse value="${using.nocache}" />
106
                        </and>
107
                        <then>
108
                            <mkdir dir="${using.@{refid}.basedir}" />
109
                            <copy todir="${using.@{refid}.basedir}" verbose="yes">
110
                                <fileset dir="@{from}/@{name}/@{version}" includes="@{includes}">
111
                                    <exclude name="descpkg" />
112
                                    <!--patternset refid="@{name}.patternset-libraries"/-->
113
                                    <using-fileset />
114
                                </fileset>
115
                            </copy>
116
                        </then>
117
                        <else>
118
                            <echo taskname="using">Skipping Copy from ${using.@{refid}.basedir} where Source = Target location</echo>
119
                        </else>
120
                    </if>
121
 
122
                    <path id="using.@{refid}.path">
123
                        <fileset dir="${using.@{refid}.basedir}" includes="@{includes}">
124
                            <using-fileset />
125
                        </fileset>
126
                    </path>
127
 
128
                    <path id="using.@{refid}.classpath">
129
                        <fileset dir="${using.@{refid}.basedir}" includes="**/*.jar">
130
                            <using-fileset />
131
                        </fileset>
132
                    </path>
133
 
134
                    <!-- Look for an ant script in the dependency named [name].xml - if it exists, import it.
135
						 Otherwise, carry on and ignore the fact that it does not exist.
136
						 Don't do this if we're doing "using" on "ant-using" though, as we've already executed
137
						 ant-using.xml by definition!
138
					  -->
139
                    <if>
140
                        <not>
141
                            <equals arg1="@{name}" arg2="ant-using" />
142
                        </not>
143
                        <then>
144
                            <trycatch>
145
                                <try>
146
                                    <import file="${using.@{refid}.basedir}/@{name}.xml" optional="true" />
147
                                </try>
148
                                <catch>
149
                                    <if>
150
                                        <isset property="force.fail.message" />
151
                                        <then>
152
                                            <fail message="${force.fail.message}" />
153
                                        </then>
154
                                        <else>
155
                                            <echo taskname="using"
156
                                                  level="warning"
157
                                                  message="Import ignored when called within target." />
158
                                        </else>
159
                                    </if>
160
                                </catch>
161
                            </trycatch>
162
                        </then>
163
                    </if>
164
 
165
                </else>
166
            </if>
167
 
168
        </sequential>
169
 
170
    </macrodef>
171
 
172
 
173
    <!-- used to remove the need to add a using line in your ant build file for every
174
		package listed in your dependency file. Simply call usingall instead and it
175
		will "detect" all the versions you are using and use them automatically.
176
 
177
		NOTE: This will make a copy of your depends.xml file to determine what
178
				packages to use.
179
 
180
		If for some reason you need to use the include and exclude items for some
181
		pacakges, then don't use this macro.
182
 
183
		In addition, if there are order dependent usings, then list those first, and then
184
		use usingall to load the others (if they are already loaded then it will ignore them).
185
	-->
186
    <macrodef name="usingall">
187
 
188
        <attribute name="dependsFile" default="${ant.project.name}depends.xml" />
189
 
190
        <sequential>
191
            <copy todir="${basedir}/build" overwrite="true">
192
                <fileset dir="${basedir}">
193
                    <include name="@{dependsFile}" />
194
                </fileset>
195
            </copy>
196
 
197
 
198
            <replaceregexp file="${basedir}/build/@{dependsFile}"
199
                           match='project.*name="'
200
                           replace='project name="tmp'
201
                           byline="true" />
202
 
203
            <replaceregexp file="${basedir}/build/@{dependsFile}"
204
                           match='property.*name="'
205
                           replace='property name="use.version.'
206
                           byline="true" />
207
 
208
            <import file="${basedir}/build/@{dependsFile}" />
209
 
210
            <propertyselector property="use.versions"
211
                              delimiter=","
212
                              match="use\.version\.([^\.]*)"
213
                              select="\1"
214
                              casesensitive="false" />
215
 
216
            <for list="${use.versions}" delimiter="," param="use.version">
217
                <sequential>
218
                    <if>
219
                        <and>
220
                            <not>
221
                                <equals arg1="@{use.version}" arg2="packagename" />
222
                            </not>
223
                            <not>
224
                                <equals arg1="@{use.version}" arg2="packageversion" />
225
                            </not>
1978 jgill 226
                            <not>
227
                                <equals arg1="@{use.version}" arg2="releasemanager.releasename" />
228
                            </not>
229
                            <not>
230
                                <equals arg1="@{use.version}" arg2="releasemanager.projectname" />
231
                            </not>
1972 jgill 232
                        </and>
233
                        <then>
234
                            <using name="@{use.version}" />
235
                        </then>
236
                    </if>
237
 
238
                </sequential>
239
            </for>
240
 
241
        </sequential>
242
    </macrodef>
243
 
244
    <!-- 
245
	  - Determine whether the dependency has been imported via the using or usingall macrodefs
246
	  -->
247
    <macrodef name="checkUsing">
248
        <attribute name="name" />
249
        <attribute name="version" default="using.@{name}.version" />
250
 
251
        <sequential>
252
            <if>
253
                <not>
254
                    <isset property="using.@{name}.basedir" />
255
                </not>
256
                <then>
257
                    <fail message="The required package '@{name}' has not been imported with using macro." />
258
                </then>
259
            </if>
260
 
261
            <if>
262
                <not>
263
                    <equals arg1="using.@{name}.version" arg2="@{version}" />
264
                </not>
265
                <then>
266
                    <fail message="The required package '@{name}' is version '${using.@{name}.version}' and not '@{version}' as expected." />
267
                </then>
268
            </if>
269
        </sequential>
270
    </macrodef>
271
 
272
</project>