Correctly set file permissions on shell scripts.
[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-idp" />
7     <property name="distnameWayf" value="shibboleth-wayf" />
8     <property name="root" value="." />
9     <property name="src" value="${root}/src/" />
10     <property name="tests" value="${root}/tests/" />
11     <property name="approot" value="${root}/webApplication/" />
12     <property name="appconfig" value="${src}/conf/" />
13     <property name="configroot" value="${root}/webAppConfig/" />
14     <property name="build" value="${approot}/WEB-INF/classes/" />
15     <property name="libdir" value="${approot}/WEB-INF/lib/" />
16     <property name="buildlibs" value="${root}/lib/" />
17     <property name="endorsed" value="${root}/endorsed/" />
18     <property name="distlibs" value="${root}/lib/" />
19     <property name="custom" value="${root}/custom/" />
20     <property name="dist" value="${root}/dist/" />
21     <property name="docs" value="${root}/doc/" />
22     <property name="javadocs" value="${docs}/api/" />
23
24     <property name="year" value="2002-2005"/>
25     <property name="copyright" value="Copyright &#169; ${year} UCAID. All Rights Reserved."/>
26
27
28     <!-- antcontrib tasks -->
29     <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${buildlibs}/ant-contrib.jar"/>
30
31
32     <!-- Construct the CLASSPATH -->
33     <path id="build.path">
34         <pathelement path="${classpath}" />
35         <pathelement location="${build}" />
36         <fileset dir="${custom}">
37             <include name="**/*.jar" />
38         </fileset>
39         <fileset dir="${endorsed}">
40             <include name="**/*.jar" />
41         </fileset>
42         <fileset dir="${libdir}">
43             <include name="**/*.jar" />
44         </fileset>
45         <fileset dir="${buildlibs}">
46             <include name="**/*.jar" />
47         </fileset>
48     </path>
49
50
51     <!-- Prepare directory structure for project build-->
52     <target name="init">
53         <mkdir dir="${build}" />
54         <mkdir dir="${dist}" />
55         <property file="build.properties" />
56     </target>
57
58
59     <!-- This target should be run before checking code into the repository -->
60     <target name="pre-checkin" depends="compile, test-all, clean-all" />
61
62
63     <!-- Compile classes and move them to ${build} -->
64     <target name="compile" depends="init"
65         description="Compile source files">
66                 <!-- Compile the shib code into the build path -->
67         <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
68             <classpath refid="build.path" />
69         </javac>
70                 <!-- Compile site-specific code into the build path -->
71         <javac srcdir="${custom}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
72             <classpath refid="build.path" />
73         </javac>
74                 <!-- Copy xml schemas to the build path -->
75         <copy todir="${build}/schemas">
76             <fileset dir="${src}/schemas"/>
77         </copy>
78                 <!-- Copy any site-specific jars to the build path -->
79                 <copy todir="${libdir}">
80                 <fileset dir="${custom}" includes="**/*.jar" />
81         </copy>
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
99     <!-- Build command-line utilities -->
100     <target name="build-util" depends="compile">
101         <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
102     </target>
103
104     
105     <!-- Cleanup after the build, test, and distribution processes -->
106     <target name="clean" depends="clean-all" />
107     <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util" />
108     <target name="clean-build">
109         <delete dir="${build}" />
110     </target>
111     <target name="clean-test">
112         <delete>
113             <fileset dir="${root}">
114                 <include name="**/TEST*.txt" />
115             </fileset>
116         </delete>
117     </target>
118     <target name="clean-dist">
119         <delete dir="${dist}" />
120     </target>
121         <target name="clean-javadocs">
122                 <delete dir="${javadocs}" />
123         </target>
124     <target name="clean-util">
125         <delete>
126             <fileset dir="${buildlibs}">
127                 <include name="shib-util.jar" />
128             </fileset>
129         </delete>
130     </target>
131
132
133         <!-- Add to the classpath for unit tests -->
134    <path id="test.path">
135       <path refid="build.path"/>
136       <pathelement location="${tests}"/>
137     </path>
138
139         <!-- Compile classes needed for unit testing -->
140     <target name="compile-tests" depends="compile">
141         <javac srcdir="${tests}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
142             <classpath refid="build.path" />
143         </javac>
144     </target>
145
146     <!-- Run automated tests on compiled code -->
147     <target name="test-all" depends="test-IdP, test-SP" />
148
149     <target name="test-IdP" depends="compile-tests">
150         <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
151                         <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
152             <classpath refid="test.path" />
153             <formatter type="plain" />
154             <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
155                         <test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
156                         <test name="edu.internet2.middleware.shibboleth.common.CredentialsTests" />
157                         <test name="edu.internet2.middleware.shibboleth.common.provider.NameMapperTests" />
158                         <test name="edu.internet2.middleware.shibboleth.common.TrustTests" />
159                         <test name="edu.internet2.middleware.shibboleth.idp.provider.DNHostNameExtractionTests" />
160                         <test name="edu.internet2.middleware.shibboleth.metadata.MetadataTests" />
161         </junit>
162     </target>
163
164     <target name="test-SP" depends="compile-tests">
165         <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
166                         <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
167             <classpath refid="test.path" />
168             <formatter type="plain" />
169             <test name="edu.internet2.middleware.shibboleth.aap.AAPTests" />
170         </junit>
171     </target>
172
173
174     <!-- Tomcat Management -->
175     <target name="setupTomcatTasks">
176         <path id="tomcat.classpath">
177                     <fileset dir="${tomcat.home}/server/lib" includes="catalina-ant.jar"/>
178             </path>
179
180         <taskdef name="tomcatStart" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.classpath"/>
181         <taskdef name="tomcatStop" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.classpath"/>
182             <taskdef name="tomcatDeploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat.classpath"/>
183         <taskdef name="tomcatUndeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat.classpath"/>
184         </target>
185     
186     <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
187         <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
188     </target>
189
190     <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
191         <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
192     </target>
193
194     <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
195         <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"
196                 war="file:${basedir}/${dist}/${distname}.war"/>
197     </target>
198
199     <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
200         <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
201     </target>
202         
203     
204     <!-- Automated key generation for crypto handles -->
205         <target name="genSecret" depends="compile">
206         <taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
207                 <genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
208         </target>
209
210
211         <!-- Generate salt for use with targetted id -->
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.init">
228         <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}"/>
229         <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}"/>
230     </target>
231
232     <target name="install" depends="init, install.init" description="Install Shibboleth">
233         <if>
234             <xinput type="confirm" defaultvalue="y">Do you want to install the Shibboleth Identity Provider?</xinput>
235             <then>
236                 <input message="What name do you want to use for the Identity Provider web application? [default: ${shib.webapp.name}]" 
237                     addproperty="shib.webapp.name.input" defaultValue="${shib.webapp.name}" />
238                 <var name="shib.webapp.name" value="${shib.webapp.name.input}" />
239
240                 <antcall target="install.idp" />
241             </then>
242         </if>
243     </target>
244
245         <target name="install.idp" depends="init, install.init">
246         <xinput message="Deploying the java web application.  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
247             addproperty="idp.install-type.input" type="menu" casesensitive="no" defaultValue="${idp.install-type}">
248             <xoption>filesystem</xoption>
249             <xoption>manager</xoption>
250         </xinput>
251         <var name="idp.install-type" value="${idp.install-type.input}" />
252         
253         <antcall target="install.idp.${idp.install-type}" />
254     </target>
255
256     <target name="install.idp.filesystem" depends="init, install.init, build-util">
257         <input message="Select an installation base for the Shibboleth Identity Provider [default: ${shib.home}]"
258             addproperty="shib.home.input" defaultvalue="${shib.home}" />
259         <var name="shib.home" value="${shib.home.input}" />
260
261         <input message="Enter tomcat home directory [default: ${tomcat.home}]"
262             addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
263         <var name="tomcat.home" value="${tomcat.home.input}" />
264         
265         <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
266         <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
267         <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
268                 <delete file="${configroot}/idp.xml"/>
269         <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
270
271         <if>
272                         <available file="${shib.home}/etc" />
273             <then>
274                 <if>
275                     <xinput type="confirm">WARNING!! The directory `${shib.home}/etc` already exists.  Do you want to overwrite the existing configuration?</xinput>
276                     <then>
277                         <delete dir="${shib.home}/etc" />
278                         <antcall target="install.idp.filesystem.config" />
279                     </then>
280                 </if>
281             </then>
282             <else>
283                 <antcall target="install.idp.filesystem.config" />
284             </else>
285         </if>
286
287         <copy todir="${shib.home}/lib">
288             <fileset dir="lib" includesfile="conf/idp-lib.include" />
289         </copy>
290
291         <copy todir="${shib.home}/bin">
292             <fileset dir="bin"/>
293         </copy>
294                 <chmod dir="${shib.home}/bin" perm="ug+rx" includes="**/*"/>
295
296         <mkdir dir="${shib.home}/logs" />
297
298         <antcall target="savePropertyFile" />
299     </target>
300
301         <target name="install.idp.filesystem.config" depends="init, install.init">
302         <mkdir dir="${shib.home}/etc" />
303         <copy todir="${shib.home}/etc" overwrite="true">
304             <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
305         </copy>
306                 <copy file="${shib.home}/etc/idp.xml.dist" tofile="${shib.home}/etc/idp.xml" overwrite="true" />
307                 <delete file="${shib.home}/etc/idp.xml.dist"/>
308         <replace file="${shib.home}/etc/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
309     </target>
310
311         <target name="install.idp.manager" depends="init, install.init">
312         <antcall target="setupTomcatTasks" />
313         
314         <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
315         <var name="tomcat.home" value="${tomcat.home.input}" />
316         
317         <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
318         <var name="tomcat.url" value="${tomcat.url.input}" />
319         
320         <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
321         <var name="tomcat.username" value="${tomcat.username.input}" />
322         
323         <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
324         <var name="tomcat.password" value="${tomcat.password.input}" />
325         
326         <antcall target="tomcat.deploy" />
327         <antcall target="savePropertyFile" />
328     </target>
329
330     <target name="savePropertyFile">
331         <propertyfile file="build.properties">
332             <entry key="shib.home" value="${shib.home}" />
333             <entry key="shib.webapp.name" value="${shib.webapp.name}" />
334             <entry key="idp.install-type" value="${idp.install-type}" />
335             <entry key="tomcat.home" value="${tomcat.home}" />
336             <entry key="tomcat.url" value="${tomcat.url}" />
337             <entry key="tomcat.username" value="${tomcat.username}" />
338             <entry key="tomcat.password" value="${tomcat.password}" />
339         </propertyfile>
340     </target>
341
342
343         <!-- Create an IdP war and copy it to the pre-configured tomcat directory -->
344         <target name="copy-IdP" depends="compile" description="Copy shibboleth.war to {tomcat.home}/webapps (Tomcat must be stopped first)">
345                 <!-- This task assumes that a pre-existing properties file has the correct path information -->
346         <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
347         <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
348         <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
349         <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
350                 <delete dir="${tomcat.home}/webapps/${distname}" quiet="yes" />
351         </target>
352
353
354     <!-- Create WAYF and move it to ${dist} -->
355     <target name="package-wayf" depends="compile, clean-build">
356         <war warfile="${dist}/${distnameWayf}.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
357     </target>
358     
359 </project>