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