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