Subversion Repositories DevTools

Rev

Rev 1978 | Go to most recent revision | Details | 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>
74
                        <equals arg1="@{copy}" arg2="true" />
75
                        <then>
76
                            <property name="using.@{refid}.basedir"
77
                                      value="${build.repository}/@{name}/@{version}" />
78
                        </then>
79
                        <else>
80
                            <property name="using.@{refid}.basedir" value="@{from}/@{name}/@{version}" />
81
                        </else>
82
                    </if>
83
 
84
                    <mkdir dir="${basedir}/build/pkg" />
85
                    <!--<manifest file="${basedir}/build/pkg/descpkg" mode="update">
86
						<section name="Build Dependencies">
87
							<attribute name="@{name}" value="@{version}"/>
88
						</section>
89
					</manifest>
90
					-->
91
 
92
                    <echo taskname="using">@{name} version @{version}</echo>
93
                    <if>
94
                        <and>
95
                            <equals arg1="@{copy}" arg2="true" />
96
                            <!-- Only copy from the package archive if the source and target locations are different -->
97
                            <not>
98
                                <equals arg1="@{from}/@{name}/@{version}" arg2="${using.@{refid}.basedir}" />
99
                            </not>
100
                            <!-- Don't copy if the using.nocache property is true. -->
101
                            <isfalse value="${using.nocache}" />
102
                        </and>
103
                        <then>
104
                            <mkdir dir="${using.@{refid}.basedir}" />
105
                            <copy todir="${using.@{refid}.basedir}" verbose="yes">
106
                                <fileset dir="@{from}/@{name}/@{version}" includes="@{includes}">
107
                                    <exclude name="descpkg" />
108
                                    <!--patternset refid="@{name}.patternset-libraries"/-->
109
                                    <using-fileset />
110
                                </fileset>
111
                            </copy>
112
                        </then>
113
                        <else>
114
                            <echo taskname="using">Skipping Copy from ${using.@{refid}.basedir} where Source = Target location</echo>
115
                        </else>
116
                    </if>
117
 
118
                    <path id="using.@{refid}.path">
119
                        <fileset dir="${using.@{refid}.basedir}" includes="@{includes}">
120
                            <using-fileset />
121
                        </fileset>
122
                    </path>
123
 
124
                    <path id="using.@{refid}.classpath">
125
                        <fileset dir="${using.@{refid}.basedir}" includes="**/*.jar">
126
                            <using-fileset />
127
                        </fileset>
128
                    </path>
129
 
130
                    <!-- Look for an ant script in the dependency named [name].xml - if it exists, import it.
131
						 Otherwise, carry on and ignore the fact that it does not exist.
132
						 Don't do this if we're doing "using" on "ant-using" though, as we've already executed
133
						 ant-using.xml by definition!
134
					  -->
135
                    <if>
136
                        <not>
137
                            <equals arg1="@{name}" arg2="ant-using" />
138
                        </not>
139
                        <then>
140
                            <trycatch>
141
                                <try>
142
                                    <import file="${using.@{refid}.basedir}/@{name}.xml" optional="true" />
143
                                </try>
144
                                <catch>
145
                                    <if>
146
                                        <isset property="force.fail.message" />
147
                                        <then>
148
                                            <fail message="${force.fail.message}" />
149
                                        </then>
150
                                        <else>
151
                                            <echo taskname="using"
152
                                                  level="warning"
153
                                                  message="Import ignored when called within target." />
154
                                        </else>
155
                                    </if>
156
                                </catch>
157
                            </trycatch>
158
                        </then>
159
                    </if>
160
 
161
                </else>
162
            </if>
163
 
164
        </sequential>
165
 
166
    </macrodef>
167
 
168
 
169
    <!-- used to remove the need to add a using line in your ant build file for every
170
		package listed in your dependency file. Simply call usingall instead and it
171
		will "detect" all the versions you are using and use them automatically.
172
 
173
		NOTE: This will make a copy of your depends.xml file to determine what
174
				packages to use.
175
 
176
		If for some reason you need to use the include and exclude items for some
177
		pacakges, then don't use this macro.
178
 
179
		In addition, if there are order dependent usings, then list those first, and then
180
		use usingall to load the others (if they are already loaded then it will ignore them).
181
	-->
182
    <macrodef name="usingall">
183
 
184
        <attribute name="dependsFile" default="${ant.project.name}depends.xml" />
185
 
186
        <sequential>
187
            <copy todir="${basedir}/build" overwrite="true">
188
                <fileset dir="${basedir}">
189
                    <include name="@{dependsFile}" />
190
                </fileset>
191
            </copy>
192
 
193
 
194
            <replaceregexp file="${basedir}/build/@{dependsFile}"
195
                           match='project.*name="'
196
                           replace='project name="tmp'
197
                           byline="true" />
198
 
199
            <replaceregexp file="${basedir}/build/@{dependsFile}"
200
                           match='property.*name="'
201
                           replace='property name="use.version.'
202
                           byline="true" />
203
 
204
            <import file="${basedir}/build/@{dependsFile}" />
205
 
206
            <propertyselector property="use.versions"
207
                              delimiter=","
208
                              match="use\.version\.([^\.]*)"
209
                              select="\1"
210
                              casesensitive="false" />
211
 
212
            <for list="${use.versions}" delimiter="," param="use.version">
213
                <sequential>
214
                    <if>
215
                        <and>
216
                            <not>
217
                                <equals arg1="@{use.version}" arg2="packagename" />
218
                            </not>
219
                            <not>
220
                                <equals arg1="@{use.version}" arg2="packageversion" />
221
                            </not>
222
                        </and>
223
                        <then>
224
                            <using name="@{use.version}" />
225
                        </then>
226
                    </if>
227
 
228
                </sequential>
229
            </for>
230
 
231
        </sequential>
232
    </macrodef>
233
 
234
    <!-- 
235
	  - Determine whether the dependency has been imported via the using or usingall macrodefs
236
	  -->
237
    <macrodef name="checkUsing">
238
        <attribute name="name" />
239
        <attribute name="version" default="using.@{name}.version" />
240
 
241
        <sequential>
242
            <if>
243
                <not>
244
                    <isset property="using.@{name}.basedir" />
245
                </not>
246
                <then>
247
                    <fail message="The required package '@{name}' has not been imported with using macro." />
248
                </then>
249
            </if>
250
 
251
            <if>
252
                <not>
253
                    <equals arg1="using.@{name}.version" arg2="@{version}" />
254
                </not>
255
                <then>
256
                    <fail message="The required package '@{name}' is version '${using.@{name}.version}' and not '@{version}' as expected." />
257
                </then>
258
            </if>
259
        </sequential>
260
    </macrodef>
261
 
262
</project>