3b116dc1bd2bb20b08928815f69d9a7f9b59f9bf
[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>
177                             <fileset dir="${custom.libs}">
178                                 <include name="*.jar"/>
179                             </fileset>
180                             <filelist refid="test.path"/>
181                         </classpath>
182                         <formatter type="plain" />
183                         <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
184                         <test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
185                         <test name="edu.internet2.middleware.shibboleth.common.CredentialsTests" />
186                         <test name="edu.internet2.middleware.shibboleth.common.provider.NameMapperTests" />
187                         <test name="edu.internet2.middleware.shibboleth.common.TrustTests" />
188                         <test name="edu.internet2.middleware.shibboleth.idp.provider.DNHostNameExtractionTests" />
189                         <test name="edu.internet2.middleware.shibboleth.metadata.MetadataTests" />
190                 </junit>
191         </target>
192
193         <target name="test-SP" depends="compile-tests">
194                 <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
195                         <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
196                     <classpath>
197                                 <fileset dir="${custom.libs}">
198                                         <include name="*.jar"/>
199                                 </fileset>
200                                 <filelist refid="test.path"/>
201                         </classpath>
202                         <formatter type="plain" />
203                         <test name="edu.internet2.middleware.shibboleth.aap.AAPTests" />
204                 </junit>
205         </target>
206
207
208         <!-- Tomcat Management -->
209         <target name="setupTomcatTasks">
210                 <path id="tomcat.classpath">
211                         <fileset dir="${tomcat.home}/server/lib" includes="catalina-ant.jar"/>
212                 </path>
213
214                 <taskdef name="tomcatStart" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.classpath"/>
215                 <taskdef name="tomcatStop" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.classpath"/>
216                 <taskdef name="tomcatDeploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat.classpath"/>
217                 <taskdef name="tomcatUndeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat.classpath"/>
218         </target>
219
220         <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
221                 <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"/>
222         </target>
223
224         <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
225                 <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"/>
226         </target>
227
228         <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
229                 <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"
230                         war="file:${basedir}/${dist}/${idp.webapp.name}.war"/>
231         </target>
232
233         <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
234                 <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${idp.webapp.name}"/>
235         </target>
236
237
238         <!-- Automated key generation for crypto handles -->
239         <target name="genSecret" depends="compile">
240                 <taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
241                 <genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
242         </target>
243
244
245         <!-- Generate salt for use with targetted id -->
246         <target name="genSalt" depends="compile">
247                 <taskdef name="genSalt" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
248                 <genSalt keyStorePath="${appconfig}/persistent.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
249         </target>
250
251         <target name="exampleCertificates">
252                 <!--
253                 This target provides an example of the generation of
254                 self-signed Certificates for the IdP and SP. You may
255                 change the cn= and use it to generate new identities
256                 when you want to replace "example.org" with your real
257                 organization dns. However,the generated key and 
258                 certificate also have to be defined to the Credentials
259                 of the IdP and SP config files and added to the Metadata.
260                 -->
261                 <genkey alias="tomcat" storepass="exampleorg"
262                         keystore="${tomcat.home}/conf/idp-example.jks"
263                         keyalg="RSA" validity="365"
264                         dname="cn=idp.example.org, o=example.org, c=US"
265                         />
266                 <genkey alias="tomcat" storepass="exampleorg"
267                         keystore="${tomcat.home}/conf/sp-example.jks"
268                         keyalg="RSA" validity="365"
269                         dname="cn=sp.example.org, o=example.org, c=US"
270                         />
271         </target>
272
273
274         <!-- Package Shibboleth -->
275         <target name="package-idp" depends="compile, install.url" description="Creates the IdP war file and moves it to ${dist}">
276                 <!-- copy values to deployment descriptor -->
277                 <copy file="${configroot}/${idp.deployment.descriptor}" tofile="${configroot}/idp.xml" overwrite="true" />
278                 <replace file="${configroot}/idp.xml" token="$IDP_HOME$" value="${idp.home.url}" />
279
280                 <!-- create the war -->
281                 <war warfile="${dist}/${idp.webapp.name}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" duplicate="preserve">
282                         <!-- Grab any custom extension libraries -->
283                         <lib dir="${custom.libs}"/>
284
285                         <!-- Grab any web material from custom extensions -->
286                         <fileset dir="${custom.webapges}"/>
287                 </war>
288
289                 <!-- clean up generated descriptor -->
290                 <delete file="${configroot}/idp.xml"/>
291         </target>
292
293         <target name="package-wayf" depends="compile" description="Creates the WAYF war and moves it to ${dist}">
294                 <war warfile="${dist}/${distnameWayf}.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
295         </target>
296
297         <target name="package-sp" depends="compile, install.url" description="Creates the Java SP war and moves it to ${dist}">
298                 <!-- copy values to deployment descriptor -->
299                 <copy file="${configroot}/${sp.deployment.descriptor}" tofile="${configroot}/sp.xml" overwrite="true" />
300                 <replace file="${configroot}/sp.xml" token="$SP_HOME$" value="${sp.home.url}" />
301
302                 <!-- create the war -->
303                 <war warfile="${dist}/${sp.webapp.name}.war" webxml="${configroot}/sp.xml" basedir="${approot}" update="no">
304                         <!-- Grab any custom extension libraries -->
305                         <lib dir="${custom.libs}"/>
306
307                         <!-- Grab any web material from custom extensions -->
308                         <fileset dir="${custom.webapges}"/>
309                 </war>
310
311                 <!-- clean up generated descriptor -->
312                 <delete file="${configroot}/sp.xml"/>
313         </target>
314
315
316         <!-- Install Shibboleth -->
317         <target name="install.init">
318                 <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}" />
319                 <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}" />
320         </target>
321
322         <target name="install.url">
323                 <taskdef name="urlconvert" classname="edu.internet2.middleware.shibboleth.utils.ant.URLConvert" classpath="${build}"/>
324                 <urlconvert path="${idp.home}" addProperty="idp.home.url"/>
325                 <urlconvert path="${sp.home}" addProperty="sp.home.url"/>
326         </target>
327
328         <target name="install" depends="init, install.init" description="Install Shibboleth">
329                 <if>
330                         <xinput type="confirm" defaultvalue="y">Do you want to install the Shibboleth Identity Provider?</xinput>
331                         <then>
332                                 <input message="What name do you want to use for the Identity Provider web application? [default: ${idp.webapp.name}]" 
333                                         addproperty="idp.webapp.name.input" defaultValue="${idp.webapp.name}" />
334                                 <var name="idp.webapp.name" value="${idp.webapp.name.input}" />
335
336                                 <antcall target="install.idp" />
337                         </then>
338                 </if>
339         </target>
340
341         <target name="install.idp" depends="init, install.init">
342                 <xinput message="Deploying the java web application.  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
343                         addproperty="idp.install-type.input" type="menu" casesensitive="no" defaultValue="${idp.install-type}">
344                         <xoption value="filesystem.prompt">filesystem</xoption>
345                         <xoption>manager</xoption>
346                 </xinput>
347                 <var name="idp.install-type" value="${idp.install-type.input}" />
348
349                 <antcall target="install.idp.${idp.install-type}" />
350         </target>
351
352         <!-- Prompt user for filesystem installation options and save them to build.properties -->
353         <target name="install.idp.filesystem.prompt" depends="init, install.init">
354                 <input message="Select an installation base for the Shibboleth Identity Provider [default: ${idp.home}]"
355                         addproperty="idp.home.input" defaultvalue="${idp.home}" />
356                 <var name="idp.home" value="${idp.home.input}" />
357                 <input message="Enter tomcat home directory [default: ${tomcat.home}]"
358                         addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
359                 <var name="tomcat.home" value="${tomcat.home.input}" />
360
361                 <if>
362                         <available file="${idp.home}/etc" />
363                         <then>
364                                 <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>
365                                 <if>
366                                         <equals arg1="${copy-idp-conf1}" arg2="y" />
367                                         <then>
368                                                 <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>
369                                         </then>
370                                 </if>
371                         </then>
372                         <else>
373                                 <property name="copy-idp-conf" value="y" />
374                         </else>
375                 </if>
376
377                 <antcall target="install.idp.filesystem" />
378                 <antcall target="savePropertyFile" />
379         </target>
380
381         <!-- Install Shibboleth IdP to filesystem using the properties in build.properties -->
382         <target name="install.idp.filesystem" depends="init, install.init, build-util, install.url, package-idp" 
383                 description="Install Shibboleth IdP to filesystem using the properties in build.properties">
384
385                 <!-- Move IdP war to Tomcat deployment directory -->
386                 <copy file="${dist}/${idp.webapp.name}.war" tofile="${tomcat.home}/webapps/${idp.webapp.name}.war" />
387
388                 <!-- copy IdP jars and utilities -->
389                 <copy todir="${idp.home}/lib">
390                         <fileset dir="lib" includesfile="conf/idp-lib.include" />
391                 </copy>
392
393                 <copy todir="${idp.home}/bin">
394                         <fileset dir="bin"/>
395                 </copy>
396                 <chmod dir="${idp.home}/bin" perm="ug+rx" includes="**/*"/>
397
398                 <mkdir dir="${idp.home}/logs" />
399
400                 <!-- copy IdP configuration -->
401                 <if>
402                         <or>
403                                 <equals arg1="${copy-idp-conf}" arg2="y" />
404                                 <not> <available file="${idp.home}/etc" /> </not>
405                         </or>
406                         <then>
407                                 <delete dir="${idp.home}/etc" />
408                                 <antcall target="install.idp.filesystem.config" />
409                         </then>
410                 </if>
411         </target>
412
413         <!-- Install Shibboleth SP to filesystem using the properties in build.properties -->
414         <target name="install.sp.filesystem" depends="init, install.init, build-util, install.url, package-sp" 
415                 description="Install Shibboleth SP to filesystem using the properties in build.properties">
416
417                 <!-- Move SP war to Tomcat deployment directory -->
418                 <copy file="${dist}/${sp.webapp.name}.war" tofile="${tomcat.home}/webapps/${sp.webapp.name}.war" />
419
420                 <!-- copy sp jars and utilities -->
421                 <copy todir="${sp.home}/lib">
422                         <fileset dir="lib" includesfile="conf/idp-lib.include" />
423                 </copy>
424
425                 <copy todir="${sp.home}/bin">
426                         <fileset dir="bin"/>
427                 </copy>
428                 <chmod dir="${sp.home}/bin" perm="ug+rx" includes="**/*"/>
429
430                 <mkdir dir="${sp.home}/logs" />
431
432                 <!-- copy sp configuration -->
433                 <if>
434                         <or>
435                                 <equals arg1="${copy-sp-conf}" arg2="y" />
436                                 <not> <available file="${sp.home}/etc" /> </not>
437                         </or>
438                         <then>
439                                 <delete dir="${sp.home}/etc" />
440                                 <antcall target="install.sp.filesystem.config" />
441                         </then>
442                 </if>
443         </target>
444
445
446         <!-- copy shibboleth configuration to $IDP_HOME/etc, overwriting any existing configuration -->
447         <target name="install.idp.filesystem.config" depends="init, install.init, install.url">
448                 <mkdir dir="${idp.home}/etc" />
449                 <copy todir="${idp.home}/etc" overwrite="true">
450                         <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
451                 </copy>
452                 <move file="${idp.home}/etc/dist.idp.xml" tofile="${idp.home}/etc/idp.xml" overwrite="true" />
453                 <replace file="${idp.home}/etc/idp.xml" token="$IDP_HOME$" value="${idp.home.url}" />
454                 <replace file="${idp.home}/etc/idp.xml" token="$IDP_WEBAPP_NAME$" value="${idp.webapp.name}" />
455         </target>
456
457         <!-- copy SP configuration to $SP_HOME$/etc, overwriting any existing configuration -->
458         <target name="install.sp.filesystem.config" depends="init, install.init">
459                 <mkdir dir="${sp.home}/etc" />
460                 <copy todir="${sp.home}/etc" overwrite="true">
461                         <fileset dir="${src}/conf" includesfile="conf/sp-conf.include"/>
462                 </copy>
463                 <move file="${sp.home}/etc/dist.sp.xml" tofile="${sp.home}/etc/sp.xml" overwrite="true" />
464                 <replace file="${sp.home}/etc/sp.xml" token="$SP_HOME$" value="${sp.home.url}" />
465         </target>
466
467         <!-- install Shibboleth-IdP war using tomcat's manager app -->
468         <target name="install.idp.manager" depends="init, install.init">
469                 <antcall target="setupTomcatTasks" />
470
471                 <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
472                 <var name="tomcat.home" value="${tomcat.home.input}" />
473
474                 <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
475                 <var name="tomcat.url" value="${tomcat.url.input}" />
476
477                 <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
478                 <var name="tomcat.username" value="${tomcat.username.input}" />
479
480                 <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
481                 <var name="tomcat.password" value="${tomcat.password.input}" />
482
483                 <antcall target="tomcat.deploy" />
484                 <antcall target="savePropertyFile" />
485         </target>
486
487         <!-- save configuration to build.properties -->
488         <target name="savePropertyFile">
489                 <propertyfile file="build.properties">
490                         <entry key="idp.home" value="${idp.home}" />
491                         <entry key="sp.home" value="${sp.home}" />
492                         <entry key="idp.webapp.name" value="${idp.webapp.name}" />
493                         <entry key="sp.webapp.name" value="${sp.webapp.name}" />
494                         <entry key="idp.install-type" value="${idp.install-type}" />
495                         <entry key="tomcat.home" value="${tomcat.home}" />
496                         <entry key="tomcat.url" value="${tomcat.url}" />
497                         <entry key="tomcat.username" value="${tomcat.username}" />
498                         <entry key="tomcat.password" value="${tomcat.password}" />
499                 </propertyfile>
500         </target>
501 </project>