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