Updated install process by separating interactive questioning from actuall install.
[java-idp.git] / build.xml
1 <!-- Main build configutaion for Shibboleth java components - Walter Hoehn 06/04/2002 -->
2
3 <project name="Shibboleth" default="install" basedir=".">
4
5     <!-- Set global properties for this build -->
6     <property name="distnameWayf" value="shibboleth-wayf" />
7     <property name="root" value="." />
8     <property name="src" value="${root}/src/" />
9     <property name="tests" value="${root}/tests/" />
10     <property name="approot" value="${root}/webApplication/" />
11     <property name="appconfig" value="${src}/conf/" />
12     <property name="configroot" value="${root}/webAppConfig/" />
13     <property name="build" value="${approot}/WEB-INF/classes/" />
14     <property name="libdir" value="${approot}/WEB-INF/lib/" />
15     <property name="buildlibs" value="${root}/lib/" />
16     <property name="endorsed" value="${root}/endorsed/" />
17     <property name="distlibs" value="${root}/lib/" />
18     <property name="custom" value="${root}/custom/" />
19     <property name="dist" value="${root}/dist/" />
20     <property name="docs" value="${root}/doc/" />
21     <property name="javadocs" value="${docs}/api/" />
22
23     <property name="year" value="2002-2005"/>
24     <property name="copyright" value="Copyright &#169; ${year} UCAID. All Rights Reserved."/>
25
26
27     <!-- antcontrib tasks -->
28     <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${buildlibs}/ant-contrib.jar"/>
29
30
31     <!-- Construct the CLASSPATH -->
32     <path id="build.path">
33         <pathelement path="${classpath}" />
34         <pathelement location="${build}" />
35         <fileset dir="${custom}">
36             <include name="**/*.jar" />
37         </fileset>
38         <fileset dir="${endorsed}">
39             <include name="**/*.jar" />
40         </fileset>
41         <fileset dir="${libdir}">
42             <include name="**/*.jar" />
43         </fileset>
44         <fileset dir="${buildlibs}">
45             <include name="**/*.jar" />
46         </fileset>
47     </path>
48
49
50     <!-- Prepare directory structure for project build-->
51     <target name="init">
52         <mkdir dir="${build}" />
53         <mkdir dir="${dist}" />
54
55         <if>
56             <not> <available file="build.properties" /> </not>
57             <then>
58                 <copy file="conf/default.build.properties" tofile="build.properties" />
59             </then>
60         </if>
61
62         <property file="build.properties" />
63     </target>
64
65
66     <!-- This target should be run before checking code into the repository -->
67     <target name="pre-checkin" depends="compile, test-all, clean-all" />
68
69
70     <!-- Compile classes and move them to ${build} -->
71     <target name="compile" depends="init"
72         description="Compile source files">
73                 <!-- Compile the shib code into the build path -->
74         <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
75             <classpath refid="build.path" />
76         </javac>
77                 <!-- Compile site-specific code into the build path -->
78         <javac srcdir="${custom}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
79             <classpath refid="build.path" />
80         </javac>
81                 <!-- Copy xml schemas to the build path -->
82         <copy todir="${build}/schemas">
83             <fileset dir="${src}/schemas"/>
84         </copy>
85                 <!-- Copy any site-specific jars to the build path -->
86                 <copy todir="${libdir}">
87                 <fileset dir="${custom}" includes="**/*.jar" />
88         </copy>
89     </target>
90
91
92         <!-- Generate API docs -->
93         <target name="javadocs">
94                 <mkdir dir="${docs}" />
95                 <mkdir dir="${javadocs}" />
96                 <javadoc packagenames='edu.internet2.middleware.*'
97                         sourcepath='${src}' destdir='${javadocs}'
98                         author='true' version='true'
99                         windowtitle='Shibboleth Java API' doctitle='Shibboleth Java API'
100                         bottom='${copyright}'>
101                 <classpath refid="build.path" />
102         </javadoc>
103         </target>
104
105
106     <!-- Build command-line utilities -->
107     <target name="build-util" depends="compile">
108         <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
109     </target>
110
111     <!-- Cleanup after the build, test, and distribution processes -->
112     <target name="clean" depends="clean-all" />
113     <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util" />
114     <target name="clean-build">
115         <delete dir="${build}" />
116     </target>
117     <target name="clean-test">
118         <delete>
119             <fileset dir="${root}">
120                 <include name="**/TEST*.txt" />
121             </fileset>
122         </delete>
123     </target>
124     <target name="clean-dist">
125         <delete dir="${dist}" />
126     </target>
127         <target name="clean-javadocs">
128                 <delete dir="${javadocs}" />
129         </target>
130     <target name="clean-util">
131         <delete>
132             <fileset dir="${buildlibs}">
133                 <include name="shib-util.jar" />
134             </fileset>
135         </delete>
136     </target>
137
138
139         <!-- Add to the classpath for unit tests -->
140    <path id="test.path">
141       <path refid="build.path"/>
142       <pathelement location="${tests}"/>
143     </path>
144
145         <!-- Compile classes needed for unit testing -->
146     <target name="compile-tests" depends="compile">
147         <javac srcdir="${tests}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
148             <classpath refid="build.path" />
149         </javac>
150     </target>
151
152     <!-- Run automated tests on compiled code -->
153     <target name="test-all" depends="test-IdP, test-SP" />
154
155     <target name="test-IdP" depends="compile-tests">
156         <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
157                         <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
158             <classpath refid="test.path" />
159             <formatter type="plain" />
160             <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
161                         <test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
162                         <test name="edu.internet2.middleware.shibboleth.common.CredentialsTests" />
163                         <test name="edu.internet2.middleware.shibboleth.common.provider.NameMapperTests" />
164                         <test name="edu.internet2.middleware.shibboleth.common.TrustTests" />
165                         <test name="edu.internet2.middleware.shibboleth.idp.provider.DNHostNameExtractionTests" />
166                         <test name="edu.internet2.middleware.shibboleth.metadata.MetadataTests" />
167         </junit>
168     </target>
169
170     <target name="test-SP" 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.aap.AAPTests" />
176         </junit>
177     </target>
178
179
180     <!-- Tomcat Management -->
181     <target name="setupTomcatTasks">
182         <path id="tomcat.classpath">
183                     <fileset dir="${tomcat.home}/server/lib" includes="catalina-ant.jar"/>
184             </path>
185
186         <taskdef name="tomcatStart" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.classpath"/>
187         <taskdef name="tomcatStop" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.classpath"/>
188             <taskdef name="tomcatDeploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat.classpath"/>
189         <taskdef name="tomcatUndeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat.classpath"/>
190         </target>
191     
192     <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
193         <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"/>
194     </target>
195
196     <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
197         <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"/>
198     </target>
199
200     <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
201         <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"
202                 war="file:${basedir}/${dist}/${shib.webapp.name}.war"/>
203     </target>
204
205     <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
206         <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${shib.webapp.name}"/>
207     </target>
208         
209     
210     <!-- Automated key generation for crypto handles -->
211         <target name="genSecret" depends="compile">
212         <taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
213                 <genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
214         </target>
215
216
217         <!-- Generate salt for use with targetted id -->
218     <target name="genSalt" depends="compile">
219         <taskdef name="genSalt" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
220         <genSalt keyStorePath="${appconfig}/persistent.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
221     </target>
222         
223         <target name="exampleCertificate">
224                 <genkey alias="tomcat" storepass="exampleorg"
225                         keystore="${tomcat.home}/conf/example.jks"
226                         keyalg="RSA" validity="365"
227                         dname="cn=shibboleth.example.org, o=example.org, c=US"
228                 />
229         </target>
230
231
232     <!-- Install Shibboleth -->
233     <target name="install.init">
234         <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}" />
235         <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}" />
236     </target>
237
238     <target name="install" depends="init, install.init" description="Install Shibboleth">
239         <if>
240             <xinput type="confirm" defaultvalue="y">Do you want to install the Shibboleth Identity Provider?</xinput>
241             <then>
242                 <input message="What name do you want to use for the Identity Provider web application? [default: ${shib.webapp.name}]" 
243                     addproperty="shib.webapp.name.input" defaultValue="${shib.webapp.name}" />
244                 <var name="shib.webapp.name" value="${shib.webapp.name.input}" />
245
246                 <antcall target="install.idp" />
247             </then>
248         </if>
249     </target>
250
251         <target name="install.idp" depends="init, install.init">
252         <xinput message="Deploying the java web application.  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
253             addproperty="idp.install-type.input" type="menu" casesensitive="no" defaultValue="${idp.install-type}">
254             <xoption value="filesystem.prompt">filesystem</xoption>
255             <xoption>manager</xoption>
256         </xinput>
257         <var name="idp.install-type" value="${idp.install-type.input}" />
258         
259         <antcall target="install.idp.${idp.install-type}" />
260     </target>
261
262     <!-- Prompt user for filesystem installation options and save them to build.properties -->
263     <target name="install.idp.filesystem.prompt" depends="init, install.init">
264         <input message="Select an installation base for the Shibboleth Identity Provider [default: ${shib.home}]"
265             addproperty="shib.home.input" defaultvalue="${shib.home}" />
266         <var name="shib.home" value="${shib.home.input}" />
267
268         <input message="Enter tomcat home directory [default: ${tomcat.home}]"
269             addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
270         <var name="tomcat.home" value="${tomcat.home.input}" />
271         
272         <if>
273                         <available file="${shib.home}/etc" />
274             <then>
275                 <xinput type="confirm" addproperty="copy-idp-conf">WARNING!! The directory `${shib.home}/etc` already exists.  Do you want to overwrite the existing configuration?</xinput>
276             </then>
277             <else>
278                 <property name="copy-idp-conf" value="y" />
279             </else>
280         </if>
281
282         <antcall target="install.idp.filesystem" />
283         <antcall target="savePropertyFile" />
284     </target>
285
286     <!-- Install Shibboleth IdP to filesystem using the properties in build.properties -->
287     <target name="install.idp.filesystem" depends="init, install.init, build-util" 
288         description="Install Shibboleth IdP to filesystem using the properties in build.properties">
289
290         <!-- copy values to deployment descriptor and create war -->
291         <copy file="${configroot}/dist.idp.xml" tofile="${configroot}/idp.xml" overwrite="true" />
292         <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
293         <war warfile="${dist}/${shib.webapp.name}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
294                 <delete file="${configroot}/idp.xml"/>
295         <copy file="${dist}/${shib.webapp.name}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
296
297         <!-- copy IdP jars and utilities -->
298         <copy todir="${shib.home}/lib">
299             <fileset dir="lib" includesfile="conf/idp-lib.include" />
300         </copy>
301
302         <copy todir="${shib.home}/bin">
303             <fileset dir="bin"/>
304         </copy>
305                 <chmod dir="${shib.home}/bin" perm="ug+rx" includes="**/*"/>
306
307         <mkdir dir="${shib.home}/logs" />
308
309         <!-- copy IdP configuration -->
310         <if>
311             <equals arg1="${copy-idp-conf}" arg2="y" />
312             <then>
313                 <delete dir="${shib.home}/etc" />
314                 <antcall target="install.idp.filesystem.config" />
315             </then>
316         </if>
317     </target>
318
319     <!-- copy shibboleth configuration to $SHIB_HOME/etc, overwriting any existing configuration -->
320         <target name="install.idp.filesystem.config" depends="init, install.init">
321         <mkdir dir="${shib.home}/etc" />
322         <copy todir="${shib.home}/etc" overwrite="true">
323             <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
324         </copy>
325                 <move file="${shib.home}/etc/dist.idp.xml" tofile="${shib.home}/etc/idp.xml" overwrite="true" />
326         <replace file="${shib.home}/etc/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
327     </target>
328
329     <!-- install Shibboleth-IdP war using tomcat's manager app -->
330         <target name="install.idp.manager" depends="init, install.init">
331         <antcall target="setupTomcatTasks" />
332         
333         <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
334         <var name="tomcat.home" value="${tomcat.home.input}" />
335         
336         <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
337         <var name="tomcat.url" value="${tomcat.url.input}" />
338         
339         <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
340         <var name="tomcat.username" value="${tomcat.username.input}" />
341         
342         <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
343         <var name="tomcat.password" value="${tomcat.password.input}" />
344         
345         <antcall target="tomcat.deploy" />
346         <antcall target="savePropertyFile" />
347     </target>
348
349     <!-- save configuration to build.properties -->
350     <target name="savePropertyFile">
351         <propertyfile file="build.properties">
352             <entry key="shib.home" value="${shib.home}" />
353             <entry key="shib.webapp.name" value="${shib.webapp.name}" />
354             <entry key="idp.install-type" value="${idp.install-type}" />
355             <entry key="tomcat.home" value="${tomcat.home}" />
356             <entry key="tomcat.url" value="${tomcat.url}" />
357             <entry key="tomcat.username" value="${tomcat.username}" />
358             <entry key="tomcat.password" value="${tomcat.password}" />
359         </propertyfile>
360     </target>
361
362     <!-- Create WAYF and move it to ${dist} -->
363     <target name="package-wayf" depends="compile, clean-build">
364         <war warfile="${dist}/${distnameWayf}.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
365     </target>
366     
367 </project>