Subversion Repositories DevTools

Rev

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