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