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