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