root/trunk/build/buildTools/getJar.xml

Revision 3429 (checked in by douglm, 1 year ago)

Allow spec of alternate repository

Line 
1 <?xml version="1.0"?>
2
3 <!-- ===================================================================
4      Define a macro to fetch jars from the bedework repository or from
5      the generated library in the named project.
6
7      IF a project is named and we cannot locate the named file we try the
8      repository.
9
10      For jars fetched from the archive we have a two step process, first check
11      that a copy in a local cache is up to date, second copy from the local cache
12      into the final destination. This allows the caller to delete and recreate the
13      destination, ensuring that jar version changes don't result in multiple
14      copies of a jar.
15
16      @param name     Name of the jar e.g. junit
17      @param version  optional version for the jar
18      @param src      optional url for the get task
19      @param lib      optional destination for the get task
20      @param libcache optional location of the cache
21      @param property optional name of property to hold location of resulting jar
22      @param project optional project name for local fetch from generated quickstart.
23      =================================================================== -->
24 <project name="getJar" basedir="." default="">
25   <macrodef name="getJar">
26     <attribute name="name"/>
27     <attribute name="version" default="" />
28     <attribute name="src" default="http://dev.bedework.org/downloads/lib"/>
29     <attribute name="lib" default="${lib.dir}"/>
30     <attribute name="libcache" default="${org.bedework.libcache.dir}"/>
31     <attribute name="property" default="" />
32     <attribute name="project" default="" />
33     <attribute name="projectHome" default="" />
34     <sequential>
35       <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
36        
37         <mkdir dir="@{libcache}" />
38
39       <!-- Names are of form
40              <name-part>-<version>.jar   or
41              <name-part>.jar
42         -->
43
44       <if>
45         <equals arg1="@{version}" arg2="" />
46         <then>
47           <var name="org.bedework.getjar.jarname" value="@{name}.jar" />
48         </then>
49         <else>
50           <var name="org.bedework.getjar.jarname" value="@{name}-@{version}.jar" />
51        </else>
52       </if>
53
54       <!-- Ensure projectHome is set to something
55         -->
56
57       <if>
58         <equals arg1="@{projectHome}" arg2="" />
59         <then>
60           <var name="org.bedework.getjar.projecthome"
61                value="${project.home}/../@{project}" />
62         </then>
63         <else>
64           <var name="org.bedework.getjar.projecthome" value="@{projectHome}" />
65        </else>
66       </if>
67
68       <var name="org.bedework.getjar.dest"
69            value="@{lib}/${org.bedework.getjar.jarname}" />
70
71       <var name="org.bedework.getjar.finished" value="false" />
72
73       <!-- If a project or projecthome was specified try to get it from the
74            local file system
75         -->
76       <if>
77         <or>
78           <not>
79             <equals arg1="@{project}" arg2="" />
80           </not>
81           <not>
82             <equals arg1="@{projecthome}" arg2="" />
83           </not>
84         </or>
85         <then>
86           <var name="org.bedework.getjar.project.jar"
87                value="${org.bedework.getjar.projecthome}/dist/${org.bedework.getjar.jarname}" />
88           <noisyMsg message="check ${org.bedework.getjar.project.jar}" />
89                
90           <if>
91             <available file="${org.bedework.getjar.project.jar}" />
92             <then>
93               <!-- Say we found the file -->
94               <var name="org.bedework.getjar.finished" value="true" />
95
96               <if>
97                 <not>
98                   <uptodate srcfile="${org.bedework.getjar.project.jar}"
99                             targetfile="${org.bedework.getjar.dest}" />
100                 </not>
101                 <then>
102                   <noisyMsg message="Fetch ${org.bedework.getjar.jarname} from project @{project}" />
103                   <copy file="${org.bedework.getjar.project.jar}"
104                         todir="@{lib}" overwrite="yes" preservelastmodified="true" />
105                 </then>
106               </if>
107             </then>
108           </if>
109         </then>
110       </if>
111
112       <!-- if org.bedework.getjar.finished is true we found a local file,
113           otherwise we need to check the repository. -->
114
115       <if>
116         <equals arg1="${org.bedework.getjar.finished}" arg2="false" />
117         <then>
118           <if>
119             <equals arg1="${org.bedework.offline.build}" arg2="yes" />
120             <then>
121               <noisyMsg message="Offline: skip check for ${org.bedework.getjar.jarname}" />
122             </then>
123             <else>
124               <!-- Not offline - check repository -->
125               <if>
126                 <isset property="org.bedework.jar.repository.location" />
127                 <then>
128                   <!-- user specified -->
129                   <echo message="Fetch ${org.bedework.getjar.jarname} from archive ${org.bedework.jar.repository.location}" />
130                   <noisyMsg message="Fetch ${org.bedework.getjar.jarname} from archive '${org.bedework.jar.repository.location}'" />
131                   <get src="${org.bedework.jar.repository.location}/${org.bedework.getjar.jarname}"
132                        dest="@{libcache}/${org.bedework.getjar.jarname}"
133                        ignoreerrors="true"
134                        verbose="${org.bedework.getjar.noisy}"
135                        usetimestamp="true"/>
136                 </then>
137                 <else>
138                       <noisyMsg message="Fetch ${org.bedework.getjar.jarname} from archive @{src}" />
139                       <get src="@{src}/${org.bedework.getjar.jarname}"
140                            dest="@{libcache}/${org.bedework.getjar.jarname}"
141                            ignoreerrors="true"
142                            verbose="${org.bedework.getjar.noisy}"
143                            usetimestamp="true"/>
144                 </else>
145               </if>
146             </else>
147           </if>
148
149           <if>
150             <not>
151               <available file="@{libcache}/${org.bedework.getjar.jarname}" />
152             </not>
153             <then>
154               <echo message="******************************************************" />
155               <echo message="File ${org.bedework.getjar.jarname} is not available" />
156               <echo message="******************************************************" />
157             </then>
158             <else>
159               <if>
160                 <isset property="org.bedework.getjar.jar.listfile" />
161                 <then>
162                   <!-- Write the name to the list -->
163                   <echo file="${org.bedework.getjar.jar.listfile}"
164                         append="yes"
165                         message="@{name}" />
166                 </then>
167               </if>
168                
169               <copy file="@{libcache}/${org.bedework.getjar.jarname}"
170                     todir="@{lib}" overwrite="yes" preservelastmodified="true" />
171             </else>
172           </if>
173
174         </then>
175       </if>
176
177       <if>
178         <not>
179           <equals arg1="@{property}" arg2="" />
180         </not>
181         <then>
182           <noisyMsg message="set property @{property} to ${org.bedework.getjar.dest}" />
183
184           <property name="@{property}" location="${org.bedework.getjar.dest}" />
185         </then>
186         <elseif>
187           <isset property="org.bedework.getjar.property.prefix" />
188           <then>
189             <noisyMsg message="set property ${org.bedework.getjar.property.prefix}.@{name} to ${org.bedework.getjar.dest}" />
190
191             <property name="${org.bedework.getjar.property.prefix}.@{name}"
192                       location="${org.bedework.getjar.dest}" />
193           </then>
194         </elseif>
195         <else>
196           <noisyMsg message="set property org.bedework.getjar.jarloc.@{name} to ${org.bedework.getjar.dest}" />
197
198           <property name="org.bedework.getjar.jarloc.@{name}"
199                     location="${org.bedework.getjar.dest}" />
200         </else>
201       </if>
202     </sequential>
203   </macrodef>
204 </project>
Note: See TracBrowser for help on using the browser.