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