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