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