Added deployment descriptor templates for new install tasks.
[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="distname" value="shibboleth" />
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="dist" value="${root}/dist/" />
19     <property name="docs" value="${root}/doc/" />
20     <property name="javadocs" value="${docs}/api/" />
21
22     <property name="year" value="2002-2005"/>
23     <property name="copyright" value="Copyright &#169; ${year} UCAID. All Rights Reserved."/>
24         
25     <!-- antcontrib tasks -->
26     <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${buildlibs}/ant-contrib.jar"/>
27     <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}"/>
28     <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}"/>
29         
30     <!-- Construct the CLASSPATH -->
31     <path id="build.path">
32         <pathelement path="${classpath}" />
33         <pathelement location="${build}" />
34         <fileset dir="${endorsed}">
35             <include name="**/*.jar" />
36         </fileset>
37         <fileset dir="${libdir}">
38             <include name="**/*.jar" />
39         </fileset>
40         <fileset dir="${buildlibs}">
41             <include name="**/*.jar" />
42         </fileset>
43     </path>
44
45
46     <!-- Prepare directory structure for project build-->
47     <target name="init">
48         <mkdir dir="${build}" />
49         <mkdir dir="${dist}" />
50         <var file="build.properties" />
51     </target>
52
53
54     <!-- This target should be run before checking code into the repository -->
55     <target name="pre-checkin" depends="compile, test-all, clean-all" />
56
57
58     <!-- Compile classes and move them to ${build} -->
59     <target name="compile" depends="init"
60         description="Compile source file, combine with schemas and conf directories">
61         <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on" 
62                 target="1.4" source="1.4">
63             <classpath refid="build.path" />
64         </javac>
65         <copy todir="${build}/schemas">
66             <fileset dir="${src}/schemas"/>
67         </copy>
68         <!-- configuration is now stored outside of shibboleth.war
69         <copy todir="${build}/conf">
70             <fileset dir="${src}/conf"/>
71         </copy>
72         -->
73     </target>
74     
75     <target name="compile-tests" depends="compile">
76         <javac srcdir="${tests}" destdir="${build}" includes="**/*.java" debug="on" target="1.4" source="1.4">
77             <classpath refid="build.path" />
78         </javac>
79     </target>
80
81
82         <!-- Generate API docs -->
83         <target name="javadocs">
84                 <mkdir dir="${docs}" />
85                 <mkdir dir="${javadocs}" />
86                 <javadoc packagenames='edu.internet2.middleware.*'
87                         sourcepath='${src}' destdir='${javadocs}'
88                         author='true' version='true'
89                         windowtitle='Shibboleth Java API' doctitle='Shibboleth Java API'
90                         bottom='${copyright}'>
91                 <classpath refid="build.path" />
92         </javadoc>
93         </target>
94
95     <!-- Create various product distributions and move them to ${dist} -->
96
97     <target name="dist-all" depends="compile, test-all, package-all, clean-build" />
98         
99     <target name="package-all">
100         <war warfile="${dist}/${distname}.war" webxml="${configroot}/all.xml" basedir="${approot}" update="no" />
101     </target>
102
103     <target name="dist-IdP-SP" depends="compile, package-IdP-SP, clean-build" 
104         description="Build application from source, create shibboleth.war file for IdP and SP"/>
105     <target name="package-IdP-SP" depends="compile"
106         description="Create shibboleth.war file from build output and IdP-SP deployment descriptor">
107         <war warfile="${dist}/${distname}.war" webxml="${configroot}/IdP-SP.xml" basedir="${approot}" update="no" />
108     </target>
109
110     <target name="dist-wayf" depends="compile, package-wayf, clean-build" />
111     <target name="package-wayf">
112         <war warfile="${dist}/${distname}-wayf.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
113     </target>
114
115     <!-- Build utilities -->
116     <target name="build-util" depends="compile">
117         <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
118     </target>
119
120     
121     <!-- Cleanup after the build, test, and distribution processes -->
122     <target name="clean" depends="clean-all" />
123     <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util" />
124     <target name="clean-build">
125         <delete dir="${build}" />
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
148     <!-- Run automated tests on compiled code -->
149     <target name="test-all" depends="test-IdP" />
150     <target name="test-IdP" depends="compile-tests">
151         <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
152                         <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
153             <classpath refid="build.path" />
154             <formatter type="plain" />
155             <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
156                         <test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
157         </junit>
158     </target>
159     
160     <!-- Tomcat Management -->
161     <target name="setupTomcatTasks">
162         <path id="tomcat.classpath">
163                     <fileset dir="${tomcat.home}/server/lib" includes="catalina-ant.jar"/>
164             </path>
165
166         <taskdef name="tomcatStart" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.classpath"/>
167         <taskdef name="tomcatStop" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.classpath"/>
168             <taskdef name="tomcatDeploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat.classpath"/>
169         <taskdef name="tomcatUndeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat.classpath"/>
170         </target>
171     
172     <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
173         <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
174     </target>
175
176     <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
177         <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
178     </target>
179
180     <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
181         <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"
182                 war="file:${basedir}/${dist}/${distname}.war"/>
183     </target>
184
185     <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
186         <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
187     </target>
188         
189     
190     <!-- Automated key generation -->
191         <target name="genSecret" depends="compile">
192         <taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
193                 <genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
194         </target>
195
196     <target name="genSalt" depends="compile">
197         <taskdef name="genSalt" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
198         <genSalt keyStorePath="${appconfig}/persistent.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
199     </target>
200         
201         <target name="exampleCertificate">
202                 <genkey alias="tomcat" storepass="exampleorg"
203                         keystore="${tomcat.home}/conf/example.jks"
204                         keyalg="RSA" validity="365"
205                         dname="cn=shibboleth.example.org, o=example.org, c=US"
206                 />
207         </target>
208         
209         
210     <!-- Install Shibboleth -->
211     <target name="install" depends="init" description="Install Shibboleth">
212
213         <if>
214             <xinput type="confirm" defaultvalue="y">Do you want to install the Shibboleth Identity Provider?</xinput>
215             <then>
216                 <antcall target="install.idp" />
217             </then>
218         </if>
219     </target>
220
221     <target name="install.idp">
222         <xinput message="Deploying java web application...  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
223             addproperty="idp.install-type" type="menu" casesensitive="no">
224             <xoption>filesystem</xoption>
225             <xoption>manager</xoption>
226         </xinput>
227         
228         <antcall target="install.idp.${idp.install-type}" />
229     </target>
230
231     <target name="install.idp.filesystem">
232         
233         <input message="Enter Shibboleth install directory [default: ${shib.home}]"
234             addproperty="shib.home.input" defaultvalue="${shib.home}" />
235         <var name="shib.home" value="${shib.home.input}" />
236
237         <input message="Enter tomcat home directory [default: ${tomcat.home}]"
238             addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
239         <var name="tomcat.home" value="${tomcat.home.input}" />
240         
241         <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
242         <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
243         <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
244         <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${distname}.war" />
245
246         <if>
247             <available file="${shib.home}" />
248             <then>
249                 <if>
250                     <xinput type="confirm">The directory `${shib.home}` already exists.  Do you want to overwrite the existing configuration?</xinput>
251                     <then>
252                         <delete dir="${shib.home}/etc" />
253                         <antcall target="install.idp.filesystem.config" />
254                     </then>
255                 </if>
256             </then>
257             <else>
258                 <antcall target="install.idp.filesystem.config" />
259             </else>
260         </if>
261
262         <antcall target="savePropertyFile" />
263     </target>
264
265     <target name="install.idp.filesystem.config">
266         <mkdir dir="${shib.home}/etc" />
267         <copy todir="${shib.home}/etc" overwrite="true">
268             <fileset dir="${src}/conf" />
269         </copy>
270         <replace file="${shib.home}/etc/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
271     </target>
272
273     <target name="install.idp.manager">
274         <antcall target="setupTomcatTasks" />
275         
276         <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
277         <var name="tomcat.home" value="${tomcat.home.input}" />
278         
279         <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
280         <var name="tomcat.url" value="${tomcat.url.input}" />
281         
282         <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
283         <var name="tomcat.username" value="${tomcat.username.input}" />
284         
285         <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
286         <var name="tomcat.password" value="${tomcat.password.input}" />
287         
288         <antcall target="tomcat.deploy" />
289         <antcall target="savePropertyFile" />
290     </target>
291
292     <target name="savePropertyFile">
293         <propertyfile file="build.properties">
294             <entry key="shib.home" value="${shib.home}" />
295             <entry key="tomcat.home" value="${tomcat.home}" />
296             <entry key="tomcat.url" value="${tomcat.url}" />
297             <entry key="tomcat.username" value="${tomcat.username}" />
298             <entry key="tomcat.password" value="${tomcat.password}" />
299         </propertyfile>
300     </target>
301     
302 </project>