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