Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1960 mtynas 1
<project name="using-macrodef">
2
 
3
	<!--	C O P Y R I G H T   N O T I C E
1962 mhunt 4
			This material is confidential to ERG and may not be disclosed in whole
1960 mtynas 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
1962 mhunt 17
							(This location holds the local set of artefacts acquired from DPKG,
1960 mtynas 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"/>
1966 bivey 30
		<attribute name="version"  default="$${@{name}}"/>
1960 mtynas 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" optional="yes" implicit="yes" description="Anything you can put in a fileset."/>
37
 
38
		<sequential>
39
 
40
			<property name="using.@{name}.version" value="@{version}"/>
41
 
42
			<fail message="The 'using' for package @{name} has already been declared as version @{version}" status="2">
43
				<condition>
44
					<and>
45
						<isset	property="using.@{name}.version"/>
46
						<not><equals	arg1="${using.@{name}.version}" arg2="@{version}"/></not>
47
					</and>
48
				</condition>
49
			</fail>
50
 
51
			<if>
52
				<isset property="using.@{refid}.basedir"/>
53
				<then>
54
					<echo taskname="ant-using" level="verbose">@{name} has already been defined. Skipping import...</echo>
55
				</then>
56
				<else>
57
					<if>
58
						<not><isset property="manifest.prepared"/></not>
59
						<then>
60
							<delete file="${basedir}/build/pkg/descpkg" quiet="true"/>
61
							<property name="manifest.prepared" value="true"/>
62
						</then>
63
					</if>
64
 
65
					<if>
66
						<equals arg1="@{copy}" arg2="true"/>
67
						<then>
68
							<property name="using.@{refid}.basedir" value="${build.repository}/@{name}/@{version}"/>
69
						</then>
70
						<else>
71
							<property name="using.@{refid}.basedir" value="@{from}/@{name}/@{version}"/>
72
						</else>
73
					</if>
74
 
75
					<mkdir dir="${basedir}/build/pkg"/>
1968 jgill 76
					<!--<manifest file="${basedir}/build/pkg/descpkg" mode="update">
1960 mtynas 77
						<section name="Build Dependencies">
78
							<attribute name="@{name}" value="@{version}"/>
79
						</section>
80
					</manifest>
1968 jgill 81
					-->
1960 mtynas 82
 
1968 jgill 83
					<echo taskname="using">@{name} version @{version}</echo>
1960 mtynas 84
					<if>
85
						<equals arg1="@{copy}" arg2="true"/>
86
						<then>
87
 
88
							<!-- Only copy from the package archive is the source and target locations are different -->
89
							<if>
90
								<not><equals arg1="@{from}/@{name}/@{version}" arg2="${using.@{refid}.basedir}"/></not>
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
											<exclude name="descpkg"/>
96
											<!--patternset refid="@{name}.patternset-libraries"/-->
97
											<using-fileset/>
98
										</fileset>
99
									</copy>
100
								</then>
101
								<else>
102
									<echo taskname="ant-using">Skipping Copy from ${using.@{refid}.basedir} where Source = Target location</echo>
103
								</else>
104
							</if>
105
 
106
						</then>
107
					</if>
108
 
109
					<path id="using.@{refid}.path">
110
						<fileset dir="${using.@{refid}.basedir}" includes="@{includes}">
111
							<using-fileset/>
112
						</fileset>
113
					</path>
114
 
1962 mhunt 115
					<path id="using.@{refid}.classpath">
116
						<fileset dir="${using.@{refid}.basedir}" includes="**/*.jar">
117
							<using-fileset/>
118
						</fileset>
119
					</path>
120
 
1960 mtynas 121
					<!-- Look for an ant script in the dependency named [name].xml - if it exists, import it.
122
						 Otherwise, carry on and ignore the fact that it does not exist. -->
123
					<trycatch>
124
						<try>
125
							<import file="${using.@{refid}.basedir}/@{name}.xml" optional="true"/>
126
						</try>
127
						<catch>
1966 bivey 128
							<if>
129
								<isset property="force.fail.message"/>
130
								<then>
131
									<fail message="${force.fail.message}"/>
132
								</then>
133
								<else>
134
									<echo taskname="ant-using" level="warning" message="Import ignored when called within target."/>
135
								</else>
136
							</if>
1960 mtynas 137
						</catch>
138
					</trycatch>
139
 
140
 
141
				</else>
142
			</if>
143
 
144
		</sequential>
145
 
146
	</macrodef>
1970 jgill 147
 
148
 
149
	<!-- used to remove the need to add a using line in your ant build file for every
150
		package listed in your dependency file. Simply call usingall instead and it
151
		will "detect" all the versions you are using and use them automatically.
152
 
153
		NOTE: This will make a copy of your depends.xml file to determine what
154
				packages to use.
155
 
156
		If for some reason you need to use the include and exclude items for some 
157
		pacakges, then don't use this macro.
158
 
159
		In addition, if there are order dependent usings, then list those first, and then
160
		use usingall to load the others (if they are already loaded then it will ignore them).
161
	-->
162
	<macrodef name="usingall">
163
 
164
		<attribute name="dependsFile" default="${ant.project.name}depends.xml"/>
165
 
166
		<sequential>
167
			<copy todir="${basedir}/build" overwrite="true">
168
				<fileset dir="${basedir}">
169
					<include name="@{dependsFile}"/>
170
				</fileset>
171
			</copy>
172
 
173
			<replaceregexp file="${basedir}/build/@{dependsFile}"
174
                         match='project.*name="'
175
                         replace='project name="tmp'
176
                         byline="true"/>
177
 
178
			<replaceregexp file="${basedir}/build/@{dependsFile}"
179
                         match='property.*name="'
180
                         replace='property name="use.version.'
181
                         byline="true"/>
182
 
183
			<import file="${basedir}/build/@{dependsFile}"/>
184
 
185
			<propertyselector property="use.versions"
186
                         delimiter=","
187
                         match="use\.version\.([^\.]*)"
188
                         select="\1"
189
                         casesensitive="false" />
190
 
191
			<for list="${use.versions}" delimiter="," param="use.version">
192
				<sequential>
193
					<if>
194
						<and>
195
							<not><equals arg1="@{use.version}" arg2="packagename"/></not>
196
							<not><equals arg1="@{use.version}" arg2="packageversion"/></not>
197
							<not><equals arg1="@{use.version}" arg2="ant-using"/></not>
198
						</and>
199
						<then>
200
							<using name="@{use.version}"/>
201
						</then>
202
					</if>
203
 
204
				</sequential>
205
			</for>
206
 
207
		</sequential>
208
	</macrodef>
1960 mtynas 209
 
210
</project>