Remove Ant extensions
[java-idp.git] / build.xml
1 <!-- Main build configutaion for Shibboleth java components - Walter Hoehn 06/04/2002 -->
2
3 <project name="Shibboleth" default="install" basedir=".">
4
5         <!-- Set global properties for this build -->
6         <property name="distnameWayf" value="shibboleth-wayf" />
7         <property name="root" value="." />
8         <property name="src" value="${root}/src/" />
9         <property name="tests" value="${root}/tests/" />
10         <property name="approot" value="${root}/webApplication/" />
11         <property name="appconfig" value="${src}/conf/" />
12         <property name="configroot" value="${root}/webAppConfig/" />
13         <property name="build" value="${approot}/WEB-INF/classes/" />
14         <property name="libdir" value="${approot}/WEB-INF/lib/" />
15         <property name="buildlibs" value="${root}/lib/" />
16         <property name="endorsed" value="${root}/endorsed/" />
17         <property name="distlibs" value="${root}/lib/" />
18         <property name="custom" value="${root}/custom/" />
19         <property name="custom.libs" value="${custom}/lib"/>
20         <property name="custom.webapges" value="${custom}/web"/>
21         <property name="dist" value="${root}/dist/" />
22         <property name="docs" value="${root}/doc/" />
23         <property name="javadocs" value="${docs}/api/" />
24
25         <property name="year" value="2002-2005"/>
26         <property name="copyright" value="Copyright &#169; ${year} UCAID. All Rights Reserved."/>
27
28         <!-- antcontrib tasks -->
29         <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${buildlibs}/ant-contrib.jar"/>
30
31         <!-- Import the tasks for building custom extensions -->
32         <import file="${custom}/extension-build.xml"/>
33
34         
35         <!-- Construct the CLASSPATH -->
36         <path id="build.path">
37                 <pathelement location="${build}" />
38                 <fileset dir="${endorsed}" includes="**/*.jar" />
39                 <fileset dir="${libdir}" includes="**/*.jar" />
40                 <fileset dir="${buildlibs}" includes="**/*.jar" />
41         </path>
42         
43
44         <!-- Add to the classpath for unit tests -->
45         <path id="test.path">
46                 <path refid="build.path"/>
47                 <pathelement location="${tests}"/>
48         </path>
49
50
51         <!-- Prepare directory structure for project build-->
52         <target name="init">
53                 <mkdir dir="${build}" />
54                 <mkdir dir="${dist}" />
55                 <mkdir dir="${custom.libs}"/>
56                 <mkdir dir="${custom.webapges}"/>
57
58                 <if>
59                         <not> <available file="build.properties" /> </not>
60                         <then>
61                                 <copy file="conf/default.build.properties" tofile="build.properties" />
62                         </then>
63                 </if>
64
65                 <property file="build.properties" />
66         </target>
67
68
69         <!-- This target should be run before checking code into the repository -->
70         <target name="pre-checkin" depends="compile, test, clean-all" />
71
72
73         <!-- Compile classes and move them to ${build} -->
74         <target name="compile" depends="init"
75                 description="Compile source files">
76                 <!-- Compile the shib code into the build path -->
77                 <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
78                         <classpath refid="build.path" />
79                 </javac>
80                 <!-- Copy xml schemas to the build path -->
81                 <copy todir="${build}/schemas">
82                         <fileset dir="${src}/schemas"/>
83                 </copy>
84
85                 <!-- Build extensions -->
86                 <antcall target="ext-invoke">
87                         <param name="exts.dir" value="${custom}"/>
88             <param name="ext.build.function" value="ext-build"/>      
89                 </antcall>
90         </target>
91
92
93         <!-- Generate API docs -->
94         <target name="javadocs">
95                 <mkdir dir="${docs}" />
96                 <mkdir dir="${javadocs}" />
97                 <javadoc packagenames='edu.internet2.middleware.*'
98                         sourcepath='${src}' destdir='${javadocs}'
99                         author='true' version='true'
100                         windowtitle='Shibboleth Java API' doctitle='Shibboleth Java API'
101                         bottom='${copyright}'>
102                         <classpath refid="build.path" />
103                 </javadoc>
104         </target>
105
106
107         <!-- Build command-line utilities -->
108         <target name="build-util" depends="compile">
109                 <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
110         </target>
111
112         
113         <!-- Compile classes needed for unit testing -->
114         <target name="compile-tests" depends="compile">
115                 <javac srcdir="${tests}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
116                         <classpath refid="build.path" />
117                 </javac>
118         </target>
119
120         <target name="test" depends="compile-tests">
121                 <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
122                         <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
123                         <classpath>
124                             <fileset dir="${custom.libs}">
125                                 <include name="*.jar"/>
126                             </fileset>
127                             <path refid="test.path"/>
128                         </classpath>
129                         <formatter type="plain" />
130                         <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
131                         <test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
132                         <test name="edu.internet2.middleware.shibboleth.common.CredentialsTests" />
133                         <test name="edu.internet2.middleware.shibboleth.common.provider.NameMapperTests" />
134                         <test name="edu.internet2.middleware.shibboleth.common.TrustTests" />
135                         <test name="edu.internet2.middleware.shibboleth.idp.provider.DNHostNameExtractionTests" />
136                         <test name="edu.internet2.middleware.shibboleth.metadata.MetadataTests" />
137                         <test name="edu.internet2.middleware.shibboleth.idp.SSOTest" />      
138                         <test name="edu.internet2.middleware.shibboleth.idp.AATest" />    
139                 </junit>
140         </target>
141
142
143         <!-- Tomcat Management -->
144         <target name="setupTomcatTasks" depends="init">
145                 <path id="tomcat.classpath">
146                         <fileset dir="${tomcat.home}/server/lib" includes="catalina-ant.jar"/>
147                 </path>
148
149                 <taskdef name="tomcatStart" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.classpath"/>
150                 <taskdef name="tomcatStop" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.classpath"/>
151                 <taskdef name="tomcatDeploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat.classpath"/>
152                 <taskdef name="tomcatUndeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat.classpath"/>
153         </target>
154
155         <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
156                 <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"/>
157         </target>
158
159         <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
160                 <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"/>
161         </target>
162
163         <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
164                 <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"
165                         war="file:${basedir}/${dist}/${idp.webapp.name}.war"/>
166         </target>
167
168         <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
169                 <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"/>
170         </target>
171
172
173         <!-- Automated key generation for crypto handles -->
174         <target name="genSecret" depends="compile">
175                 <taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
176                 <genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
177         </target>
178
179
180         <!-- Generate salt for use with targetted id -->
181         <target name="genSalt" depends="compile">
182                 <taskdef name="genSalt" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
183                 <genSalt keyStorePath="${appconfig}/persistent.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
184         </target>
185
186         <target name="exampleCertificates">
187                 <!--
188                 This target provides an example of the generation of
189                 self-signed Certificates for the IdP. You may
190                 change the cn= and use it to generate new identities
191                 when you want to replace "example.org" with your real
192                 organization dns. However,the generated key and 
193                 certificate also have to be defined to the Credentials
194                 of the IdP config files and added to the Metadata.
195                 -->
196                 <genkey alias="tomcat" storepass="exampleorg"
197                         keystore="${tomcat.home}/conf/idp-example.jks"
198                         keyalg="RSA" validity="365"
199                         dname="cn=idp.example.org, o=example.org, c=US"
200                         />
201         </target>
202
203
204         <!-- Package Shibboleth -->
205         <target name="package-idp" depends="compile, install.url" description="Creates the IdP war file and moves it to ${dist}">
206                 <!-- copy values to deployment descriptor -->
207                 <copy file="${configroot}/${idp.deployment.descriptor}" tofile="${configroot}/idp.xml" overwrite="true" />
208                 <replace file="${configroot}/idp.xml" token="$IDP_HOME$" value="${idp.home.url}" />
209      
210         <!-- package extensions -->
211         <antcall target="ext-invoke">
212             <param name="exts.dir" value="${custom}"/>
213             <param name="ext.build.function" value="ext-package"/>
214             <param name="ext.filesystem.home" value="${idp.home}"/>
215             <param name="ext.home.token" value="$IDP_HOME$"/>
216         </antcall>
217
218                 <!-- create the war -->
219                 <war warfile="${dist}/${idp.webapp.name}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" duplicate="preserve">
220                         <!-- Grab any custom extension libraries -->
221                         <lib dir="${custom.libs}"/>
222
223                         <!-- Grab any web material from custom extensions -->
224                         <fileset dir="${custom.webapges}"/>
225                 </war>
226
227                 <!-- clean up generated descriptor -->
228                 <delete file="${configroot}/idp.xml"/>
229         </target>
230
231         <!-- Install Shibboleth -->
232         <target name="install.init">
233                 <taskdef name="xinput" classname="edu.internet2.middleware.ant.XInput" classpath="${build}" />
234                 <typedef name="xoption" classname="edu.internet2.middleware.ant.XInputOption" classpath="${build}" />
235         </target>
236
237         <target name="install.url">
238                 <taskdef name="urlconvert" classname="edu.internet2.middleware.ant.URLConvert" classpath="${build}"/>
239         </target>
240
241         <target name="install" depends="init, install.init" description="Install Shibboleth">
242                 <if>
243                         <xinput type="confirm" defaultvalue="y">Do you want to install the Shibboleth Identity Provider?</xinput>
244                         <then>
245                                 <input message="What name do you want to use for the Identity Provider web application? [default: ${idp.webapp.name}]" 
246                                         addproperty="idp.webapp.name.input" defaultValue="${idp.webapp.name}" />
247                                 <var name="idp.webapp.name" value="${idp.webapp.name.input}" />
248
249                                 <antcall target="install.idp" />
250                         </then>
251                 </if>
252         </target>
253
254         <target name="install.idp" depends="init, install.init">
255                 <xinput message="Deploying the java web application.  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
256                         addproperty="idp.install-type.input" type="menu" casesensitive="no" defaultValue="${idp.install-type}">
257                         <xoption value="filesystem.prompt">filesystem</xoption>
258                         <xoption>manager</xoption>
259                 </xinput>
260                 <var name="idp.install-type" value="${idp.install-type.input}" />
261
262                 <antcall target="install.idp.${idp.install-type}" />
263         </target>
264
265         <!-- Prompt user for filesystem installation options and save them to build.properties -->
266         <target name="install.idp.filesystem.prompt" depends="init, install.init">
267                 <input message="Select a home directory for the Shibboleth Identity Provider [default: ${idp.home}]"
268                         addproperty="idp.home.input" defaultvalue="${idp.home}" />
269                 <var name="idp.home" value="${idp.home.input}" />
270                 <input message="Enter tomcat home directory [default: ${tomcat.home}]"
271                         addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
272                 <var name="tomcat.home" value="${tomcat.home.input}" />
273
274                 <if>
275                         <available file="${idp.home}/etc" />
276                         <then>
277                                 <echo>--------------------------------------------------------------------------------------</echo>
278                                 <echo>---</echo>
279                                 <echo>---   NOTE:  Existing Identiity Provider configuration at ${idp.home}/etc ${line.separator}---   will not be overwritten.</echo>
280                                 <echo>---</echo>
281                                 <echo>--------------------------------------------------------------------------------------</echo>
282                                 <property name="copy-idp-conf" value="n" />
283                         </then>
284                         <else>
285                                 <property name="copy-idp-conf" value="y" />
286                         </else>
287                 </if>
288
289                 <antcall target="install.idp.filesystem" />
290                 <antcall target="savePropertyFile" />
291         </target>
292
293         <!-- Install Shibboleth IdP to filesystem using the properties in build.properties -->
294         <target name="install.idp.filesystem" depends="init, install.init, build-util, install.url, package-idp" 
295                 description="Install Shibboleth IdP to filesystem using the properties in build.properties">
296
297                 <!-- Move IdP war to Tomcat deployment directory -->
298                 <copy file="${dist}/${idp.webapp.name}.war" tofile="${tomcat.home}/webapps/${idp.webapp.name}.war" />
299
300                 <!-- copy IdP jars and utilities -->
301                 <copy todir="${idp.home}/lib">
302                         <fileset dir="lib" includesfile="conf/idp-lib.include" />
303                 </copy>
304
305                 <copy todir="${idp.home}/endorsed">
306                         <fileset dir="endorsed" />
307                 </copy>
308
309                 <copy todir="${idp.home}/bin">
310                         <fileset dir="bin"/>
311                 </copy>
312                 <chmod dir="${idp.home}/bin" perm="ug+rx" includes="**/*"/>
313
314                 <mkdir dir="${idp.home}/logs" />
315                 
316                 <!-- Copy necessary files to IDP_HOME -->
317                 <antcall target="install.idp.buildHome" />
318                 
319                 <antcall target="ext-invoke">
320             <param name="exts.dir" value="${custom}"/>
321             <param name="ext.build.function" value="ext-install-filesystem"/>
322             <param name="ext.filesystem.home" value="${idp.home}"/>
323             <param name="ext.home.token" value="$IDP_HOME$"/>
324         </antcall>  
325         
326         </target>
327         
328         <target name="install.idp.buildHome" depends="init, install.init">
329                 <!-- copy IdP configuration -->
330                 <if>
331                         <or>
332                                 <equals arg1="${copy-idp-conf}" arg2="y" />
333                                 <not> <available file="${idp.home}/etc" /> </not>
334                         </or>
335                         <then>
336                                 <delete dir="${idp.home}/etc" />
337                                 <antcall target="install.idp.filesystem.config" />
338                         </then>
339                 </if>
340         </target>
341
342         <!-- copy shibboleth configuration to $IDP_HOME/etc, overwriting any existing configuration -->
343         <target name="install.idp.filesystem.config" depends="init, install.init, install.url">
344                 <mkdir dir="${idp.home}/etc" />
345                 <copy todir="${idp.home}/etc" overwrite="true">
346                         <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
347                 </copy>
348                 <move file="${idp.home}/etc/dist.idp.xml" tofile="${idp.home}/etc/idp.xml" overwrite="true" />
349                 <replace file="${idp.home}/etc/idp.xml" token="$IDP_HOME$" value="${idp.home.url}" />
350                 <replace file="${idp.home}/etc/idp.xml" token="$IDP_WEBAPP_NAME$" value="${idp.webapp.name}" />
351         </target>
352
353         <!-- install Shibboleth-IdP war using tomcat's manager app -->
354         <target name="install.idp.manager" depends="init, install.init">
355                 <antcall target="setupTomcatTasks" />
356
357                 <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
358                 <var name="tomcat.home" value="${tomcat.home.input}" />
359
360                 <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
361                 <var name="tomcat.url" value="${tomcat.url.input}" />
362
363                 <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
364                 <var name="tomcat.username" value="${tomcat.username.input}" />
365
366                 <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
367                 <var name="tomcat.password" value="${tomcat.password.input}" />
368
369                 <antcall target="package-idp" />
370                 <antcall target="tomcat.deploy" />
371                 <antcall target="install.idp.buildHome" />
372                 <antcall target="savePropertyFile" />
373         </target>
374
375         <!-- save configuration to build.properties -->
376         <target name="savePropertyFile">
377                 <propertyfile file="build.properties">
378                         <entry key="idp.home" value="${idp.home}" />
379                         <entry key="idp.webapp.name" value="${idp.webapp.name}" />
380                         <entry key="idp.install-type" value="${idp.install-type}" />
381                         <entry key="tomcat.home" value="${tomcat.home}" />
382                         <entry key="tomcat.url" value="${tomcat.url}" />
383                         <entry key="tomcat.username" value="${tomcat.username}" />
384                         <entry key="tomcat.password" value="${tomcat.password}" />
385                 </propertyfile>
386         </target>
387         
388
389         <!-- Cleanup after the build, test, and distribution processes -->
390         <target name="clean" depends="clean-all" />
391
392     <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util"/>
393         
394     <target name="clean-build">
395                 <delete dir="${build}" />
396                 <delete dir="${custom.libs}"/>
397                 <delete dir="${custom.webapges}"/>
398             <antcall target="ext-invoke">
399                 <param name="exts.dir" value="${custom}"/>
400             <param name="ext.build.function" value="ext-clean-build"/>   
401             </antcall>
402         </target>
403         
404     <target name="clean-test">
405                 <delete>
406                         <fileset dir="${root}">
407                                 <include name="**/TEST*.txt" />
408                         </fileset>
409                 </delete>
410         </target>
411         
412     <target name="clean-dist">
413                 <delete dir="${dist}" />
414         <antcall target="ext-invoke">
415             <param name="exts.dir" value="${custom}"/>
416             <param name="ext.build.function" value="ext-clean-dist"/>   
417         </antcall>   
418         </target>
419         
420     <target name="clean-javadocs">
421                 <delete dir="${javadocs}" />
422         <antcall target="ext-invoke">
423             <param name="exts.dir" value="${custom}"/>
424             <param name="ext.build.function" value="ext-clean-javadocs"/>   
425         </antcall>
426         </target>
427         
428     <target name="clean-util">
429                 <delete>
430                         <fileset dir="${buildlibs}">
431                                 <include name="shib-util.jar" />
432                         </fileset>
433                 </delete>
434         </target>
435         
436         <!-- For IDE development, run this target first to delete all
437         directories generated by the install process before
438         recreating and reinstalling everything. -->
439         <target name="clean-install" depends="init" 
440                 description="Delete old configuration and Tomcat webapp directories.">
441                 <delete dir="${idp.home}" />
442                 <delete dir="${tomcat.home}/webapps/${idp.webapp.name}" />
443         </target>
444         
445 </project>