Don't ever overwrite IdP configuration files.
[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 a home directory 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                                 <echo>-----------------------------------------------------------------------------------------------------------</echo>
367                                 <echo>---</echo>
368                                 <echo>---   NOTE:  Existing Identiity Provider configuration at ${idp.home}/etc will not be overwritten.</echo>
369                                 <echo>---</echo>
370                                 <echo>-----------------------------------------------------------------------------------------------------------</echo>
371                                 <property name="copy-idp-conf" value="n" />
372                         </then>
373                         <else>
374                                 <property name="copy-idp-conf" value="y" />
375                         </else>
376                 </if>
377
378                 <antcall target="install.idp.filesystem" />
379                 <antcall target="savePropertyFile" />
380         </target>
381
382         <!-- Install Shibboleth IdP to filesystem using the properties in build.properties -->
383         <target name="install.idp.filesystem" depends="init, install.init, build-util, install.url, package-idp" 
384                 description="Install Shibboleth IdP to filesystem using the properties in build.properties">
385
386                 <!-- Move IdP war to Tomcat deployment directory -->
387                 <copy file="${dist}/${idp.webapp.name}.war" tofile="${tomcat.home}/webapps/${idp.webapp.name}.war" />
388
389                 <!-- copy IdP jars and utilities -->
390                 <copy todir="${idp.home}/lib">
391                         <fileset dir="lib" includesfile="conf/idp-lib.include" />
392                 </copy>
393
394                 <copy todir="${idp.home}/bin">
395                         <fileset dir="bin"/>
396                 </copy>
397                 <chmod dir="${idp.home}/bin" perm="ug+rx" includes="**/*"/>
398
399                 <mkdir dir="${idp.home}/logs" />
400
401                 <!-- copy IdP configuration -->
402                 <if>
403                         <or>
404                                 <equals arg1="${copy-idp-conf}" arg2="y" />
405                                 <not> <available file="${idp.home}/etc" /> </not>
406                         </or>
407                         <then>
408                                 <delete dir="${idp.home}/etc" />
409                                 <antcall target="install.idp.filesystem.config" />
410                         </then>
411                 </if>
412
413         <antcall target="ext-invoke">
414             <param name="exts.dir" value="${custom}"/>
415             <param name="ext.build.function" value="ext-install-filesystem"/>
416             <param name="ext.filesystem.home" value="${idp.home}"/>
417             <param name="ext.home.token" value="$IDP_HOME$"/>
418         </antcall>   
419         </target>
420
421         <!-- Install Shibboleth SP to filesystem using the properties in build.properties -->
422         <target name="install.sp.filesystem" depends="init, install.init, build-util, install.url, package-sp" 
423                 description="Install Shibboleth SP to filesystem using the properties in build.properties">
424
425                 <!-- Move SP war to Tomcat deployment directory -->
426                 <copy file="${dist}/${sp.webapp.name}.war" tofile="${tomcat.home}/webapps/${sp.webapp.name}.war" />
427
428                 <!-- copy sp jars and utilities -->
429                 <copy todir="${sp.home}/lib">
430                         <fileset dir="lib" includesfile="conf/idp-lib.include" />
431                 </copy>
432
433                 <copy todir="${sp.home}/bin">
434                         <fileset dir="bin"/>
435                 </copy>
436                 <chmod dir="${sp.home}/bin" perm="ug+rx" includes="**/*"/>
437
438                 <mkdir dir="${sp.home}/logs" />
439
440                 <!-- copy sp configuration -->
441                 <if>
442                         <or>
443                                 <equals arg1="${copy-sp-conf}" arg2="y" />
444                                 <not> <available file="${sp.home}/etc" /> </not>
445                         </or>
446                         <then>
447                                 <delete dir="${sp.home}/etc" />
448                                 <antcall target="install.sp.filesystem.config" />
449                         </then>
450                 </if>
451
452         <antcall target="ext-invoke">
453             <param name="exts.dir" value="${custom}"/>
454             <param name="ext.build.function" value="${ext-install-filesystem}"/>
455             <param name="ext.filesystem.home" value="${sp.home}"/>
456             <param name="ext.home.token" value="$SP_HOME$"/>
457         </antcall>      
458         </target>
459
460
461         <!-- copy shibboleth configuration to $IDP_HOME/etc, overwriting any existing configuration -->
462         <target name="install.idp.filesystem.config" depends="init, install.init, install.url">
463                 <mkdir dir="${idp.home}/etc" />
464                 <copy todir="${idp.home}/etc" overwrite="true">
465                         <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
466                 </copy>
467                 <move file="${idp.home}/etc/dist.idp.xml" tofile="${idp.home}/etc/idp.xml" overwrite="true" />
468                 <replace file="${idp.home}/etc/idp.xml" token="$IDP_HOME$" value="${idp.home.url}" />
469                 <replace file="${idp.home}/etc/idp.xml" token="$IDP_WEBAPP_NAME$" value="${idp.webapp.name}" />
470         </target>
471
472         <!-- copy SP configuration to $SP_HOME$/etc, overwriting any existing configuration -->
473         <target name="install.sp.filesystem.config" depends="init, install.init">
474                 <mkdir dir="${sp.home}/etc" />
475                 <copy todir="${sp.home}/etc" overwrite="true">
476                         <fileset dir="${src}/conf" includesfile="conf/sp-conf.include"/>
477                 </copy>
478                 <move file="${sp.home}/etc/dist.sp.xml" tofile="${sp.home}/etc/sp.xml" overwrite="true" />
479                 <replace file="${sp.home}/etc/sp.xml" token="$SP_HOME$" value="${sp.home.url}" />
480         </target>
481
482         <!-- install Shibboleth-IdP war using tomcat's manager app -->
483         <target name="install.idp.manager" depends="init, install.init">
484                 <antcall target="setupTomcatTasks" />
485
486                 <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
487                 <var name="tomcat.home" value="${tomcat.home.input}" />
488
489                 <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
490                 <var name="tomcat.url" value="${tomcat.url.input}" />
491
492                 <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
493                 <var name="tomcat.username" value="${tomcat.username.input}" />
494
495                 <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
496                 <var name="tomcat.password" value="${tomcat.password.input}" />
497
498                 <antcall target="tomcat.deploy" />
499                 <antcall target="savePropertyFile" />
500         </target>
501
502         <!-- save configuration to build.properties -->
503         <target name="savePropertyFile">
504                 <propertyfile file="build.properties">
505                         <entry key="idp.home" value="${idp.home}" />
506                         <entry key="sp.home" value="${sp.home}" />
507                         <entry key="idp.webapp.name" value="${idp.webapp.name}" />
508                         <entry key="sp.webapp.name" value="${sp.webapp.name}" />
509                         <entry key="idp.install-type" value="${idp.install-type}" />
510                         <entry key="tomcat.home" value="${tomcat.home}" />
511                         <entry key="tomcat.url" value="${tomcat.url}" />
512                         <entry key="tomcat.username" value="${tomcat.username}" />
513                         <entry key="tomcat.password" value="${tomcat.password}" />
514                 </propertyfile>
515         </target>
516 </project>