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