Renamed sites files to avoid colliding with 1.2, changed providerId to match metadata
[java-idp.git] / build.xml
index bffd13b..256cb9d 100755 (executable)
--- a/build.xml
+++ b/build.xml
 <!-- Main build configutaion for Shibboleth java components - Walter Hoehn 06/04/2002 -->
 
-<project name="Shibboleth" default="dist-all" basedir=".">
-
-       <!-- Set global properties for this build -->
-    <property name="opensaml" value="${root}/../../../opensaml/java/lib" />
-       <property name="distname" value="shibboleth" />
-       <property name="root" value="." />
-       <property name="src" value="${root}/src" />
-    <property name="bld" value="${root}/build" />
-       <property name="approot" value="${root}/webApplication" />
-       <property name="build" value="${approot}/WEB-INF/classes" />
-       <property name="libdir" value="${approot}/WEB-INF/lib" />
-       <property name="lib" value="${root}/lib" />
-       <property name="dist" value="${root}/dist" />
-
-
-       <!-- Construct the CLASSPATH -->
-       <path id="build.path">
-               <pathelement path="${classpath}" />
-               <pathelement location="${build}" />
-        <pathelement location="${bld}" />
-               <fileset dir="${libdir}">
-                       <include name="**/*.jar" />
-               </fileset>
-               <fileset dir="${lib}">
-                       <include name="**/*.jar" />
-               </fileset>
-               <fileset dir="${opensaml}">
-                       <include name="opensaml.jar" />
-               </fileset>
-       </path>
-
-
-       <!-- Prepare directory structure for project build-->
-       <target name="init">
-        <mkdir dir="${bld}" />
-           <mkdir dir="${build}" />
+<project name="Shibboleth" default="install" basedir=".">
+
+    <!-- Set global properties for this build -->
+    <property name="distname" value="shibboleth-idp" />
+    <property name="distnameWayf" value="shibboleth-wayf" />
+    <property name="root" value="." />
+    <property name="src" value="${root}/src/" />
+    <property name="tests" value="${root}/tests/" />
+    <property name="approot" value="${root}/webApplication/" />
+    <property name="appconfig" value="${src}/conf/" />
+    <property name="configroot" value="${root}/webAppConfig/" />
+    <property name="build" value="${approot}/WEB-INF/classes/" />
+    <property name="libdir" value="${approot}/WEB-INF/lib/" />
+    <property name="buildlibs" value="${root}/lib/" />
+    <property name="endorsed" value="${root}/endorsed/" />
+    <property name="distlibs" value="${root}/lib/" />
+    <property name="custom" value="${root}/custom/" />
+    <property name="dist" value="${root}/dist/" />
+    <property name="docs" value="${root}/doc/" />
+    <property name="javadocs" value="${docs}/api/" />
+
+    <property name="year" value="2002-2005"/>
+    <property name="copyright" value="Copyright &#169; ${year} UCAID. All Rights Reserved."/>
+
+
+    <!-- antcontrib tasks -->
+    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${buildlibs}/ant-contrib.jar"/>
+
+
+    <!-- Construct the CLASSPATH -->
+    <path id="build.path">
+        <pathelement path="${classpath}" />
+        <pathelement location="${build}" />
+        <fileset dir="${custom}">
+            <include name="**/*.jar" />
+        </fileset>
+        <fileset dir="${endorsed}">
+            <include name="**/*.jar" />
+        </fileset>
+        <fileset dir="${libdir}">
+            <include name="**/*.jar" />
+        </fileset>
+        <fileset dir="${buildlibs}">
+            <include name="**/*.jar" />
+        </fileset>
+    </path>
+
+
+    <!-- Prepare directory structure for project build-->
+    <target name="init">
+        <mkdir dir="${build}" />
         <mkdir dir="${dist}" />
-       </target>
+        <property file="build.properties" />
+    </target>
 
 
-       <!-- Compile classes and move them to ${build} -->
-       <target name="compile-all" depends="compile-common">
-               <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on">
-            <exclude name="edu/internet2/middleware/shibboleth/aaLocal/**" />
-            <exclude name="edu/internet2/middleware/shibboleth/common/**" />
-            <exclude name="edu/internet2/middleware/shibboleth/eduPerson/**" />
-           <classpath refid="build.path" />
-               </javac>
-       </target>
+    <!-- This target should be run before checking code into the repository -->
+    <target name="pre-checkin" depends="compile, test-all, clean-all" />
 
-       <target name="compile-common" depends="init">
-               <javac srcdir="${src}" destdir="${bld}" debug="on">
-                       <include name="edu/internet2/middleware/eduPerson/*.java" />
-                       <include name="edu/internet2/middleware/shibboleth/common/*.java" />
-                       <classpath refid="build.path" />
-               </javac>
-               <copy todir="${bld}/schemas">
+
+    <!-- Compile classes and move them to ${build} -->
+    <target name="compile" depends="init"
+       description="Compile source files">
+               <!-- Compile the shib code into the build path -->
+        <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
+            <classpath refid="build.path" />
+        </javac>
+               <!-- Compile site-specific code into the build path -->
+        <javac srcdir="${custom}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
+            <classpath refid="build.path" />
+        </javac>
+               <!-- Copy xml schemas to the build path -->
+        <copy todir="${build}/schemas">
             <fileset dir="${src}/schemas"/>
         </copy>
-       </target>
+               <!-- Copy any site-specific jars to the build path -->
+               <copy todir="${libdir}">
+               <fileset dir="${custom}" includes="**/*.jar" />
+        </copy>
+    </target>
 
 
-       <!-- Create various product distributions and move them to ${dist} -->
-       <target name="dist-all" depends="compile-all, package, clean-build" />
-       <target name="dist-origin" depends="compile-all, package, clean-build" />
-       <target name="dist-target" depends="compile-all, package, clean-build" />
-       <target name="dist-wayf" depends="compile-all, package, clean-build" />
+       <!-- Generate API docs -->
+       <target name="javadocs">
+               <mkdir dir="${docs}" />
+               <mkdir dir="${javadocs}" />
+               <javadoc packagenames='edu.internet2.middleware.*'
+                       sourcepath='${src}' destdir='${javadocs}'
+                       author='true' version='true'
+                       windowtitle='Shibboleth Java API' doctitle='Shibboleth Java API'
+                       bottom='${copyright}'>
+                <classpath refid="build.path" />
+        </javadoc>
+       </target>
 
-       <target name="dist-common" depends="clean-common, compile-common, package-common" />
 
-       <target name="package">
-               <war warfile="${dist}/${distname}.war" webxml="${approot}/WEB-INF/web.xml" basedir="${approot}" update="no" />
-       </target>
+    <!-- Build command-line utilities -->
+    <target name="build-util" depends="compile">
+        <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
+    </target>
 
-       <target name="package-common">
-               <jar jarfile="${dist}/${distname}.jar" basedir="${bld}">
-                       <include name="schemas/**" />
-                       <include name="edu/internet2/middleware/shibboleth/common/**" />
-                       <include name="edu/internet2/middleware/eduPerson/**" />
-               </jar>
+    
+    <!-- Cleanup after the build, test, and distribution processes -->
+    <target name="clean" depends="clean-all" />
+    <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util" />
+    <target name="clean-build">
+        <delete dir="${build}" />
+    </target>
+    <target name="clean-test">
+        <delete>
+            <fileset dir="${root}">
+                <include name="**/TEST*.txt" />
+            </fileset>
+        </delete>
+    </target>
+    <target name="clean-dist">
+        <delete dir="${dist}" />
+    </target>
+       <target name="clean-javadocs">
+               <delete dir="${javadocs}" />
        </target>
+    <target name="clean-util">
+        <delete>
+            <fileset dir="${buildlibs}">
+                <include name="shib-util.jar" />
+            </fileset>
+        </delete>
+    </target>
 
 
-       <!-- Cleanup after the build, test, and distribution processes -->
-       <target name="clean-all" depends="clean-build, clean-dist, clean-test" />
-       <target name="clean-build">
-               <delete dir="${build}" />
-        <delete dir="${bld}" />
-       </target>
-       <target name="clean-test">
-               <delete>
-                       <fileset dir="${root}">
-                               <include name="**/TEST*.txt" />
-                       </fileset>
-               </delete>
-       </target>
-       <target name="clean-dist">
-               <delete dir="${dist}" />
+       <!-- Add to the classpath for unit tests -->
+   <path id="test.path">
+      <path refid="build.path"/>
+      <pathelement location="${tests}"/>
+    </path>
+
+       <!-- Compile classes needed for unit testing -->
+    <target name="compile-tests" depends="compile">
+        <javac srcdir="${tests}" destdir="${build}" includes="**/*.java" debug="on" source="1.4">
+            <classpath refid="build.path" />
+        </javac>
+    </target>
+
+    <!-- Run automated tests on compiled code -->
+    <target name="test-all" depends="test-IdP, test-SP" />
+
+    <target name="test-IdP" depends="compile-tests">
+        <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
+                       <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
+            <classpath refid="test.path" />
+            <formatter type="plain" />
+            <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
+                       <test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
+                       <test name="edu.internet2.middleware.shibboleth.common.CredentialsTests" />
+                       <test name="edu.internet2.middleware.shibboleth.common.provider.NameMapperTests" />
+                       <test name="edu.internet2.middleware.shibboleth.common.TrustTests" />
+                       <test name="edu.internet2.middleware.shibboleth.idp.provider.DNHostNameExtractionTests" />
+                       <test name="edu.internet2.middleware.shibboleth.metadata.MetadataTests" />
+        </junit>
+    </target>
+
+    <target name="test-SP" depends="compile-tests">
+        <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
+                       <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
+            <classpath refid="test.path" />
+            <formatter type="plain" />
+            <test name="edu.internet2.middleware.shibboleth.aap.AAPTests" />
+        </junit>
+    </target>
+
+
+    <!-- Tomcat Management -->
+    <target name="setupTomcatTasks">
+       <path id="tomcat.classpath">
+                   <fileset dir="${tomcat.home}/server/lib" includes="catalina-ant.jar"/>
+           </path>
+
+       <taskdef name="tomcatStart" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.classpath"/>
+       <taskdef name="tomcatStop" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.classpath"/>
+           <taskdef name="tomcatDeploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat.classpath"/>
+       <taskdef name="tomcatUndeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat.classpath"/>
        </target>
+    
+    <target name="tomcat.start" depends="setupTomcatTasks" description="Start a deployed webapp using Tomcat manager">
+        <tomcatStart url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
+    </target>
+
+    <target name="tomcat.stop" depends="setupTomcatTasks" description="Stop a deployed webapp using Tomcat manager">
+        <tomcatStop url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
+    </target>
+
+    <target name="tomcat.deploy" depends="setupTomcatTasks" description="Upload and deploy using Tomcat manager">
+        <tomcatDeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"
+               war="file:${basedir}/${dist}/${distname}.war"/>
+    </target>
 
-       <target name="clean-common">
-               <delete dir="${bld}/schemas" />
-               <delete dir="${bld}/edu/internet2/middleware/shibboleth/common" />
-               <delete dir="${bld}/edu/internet2/middleware/eduPerson" />
+    <target name="tomcat.undeploy" depends="setupTomcatTasks" description="Undeploy using Tomcat manager">
+        <tomcatUndeploy url="${tomcat.url}" username="${tomcat.username}" password="${tomcat.password}" path="/${distname}"/>
+    </target>
+       
+    
+    <!-- Automated key generation for crypto handles -->
+       <target name="genSecret" depends="compile">
+       <taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
+               <genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
        </target>
+
+
+       <!-- Generate salt for use with targetted id -->
+    <target name="genSalt" depends="compile">
+        <taskdef name="genSalt" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
+        <genSalt keyStorePath="${appconfig}/persistent.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
+    </target>
        
-       <!-- Run automated tests on compiled code -->
-       <target name="test-all" depends="test-common" />
-       <target name="test-common" depends="compile-all">
-               <junit printsummary="no" fork="no" haltonfailure="yes" haltonerror="no">
-                       <classpath refid="build.path" />
-                       <formatter type="plain" />
-                       <test name="edu.internet2.middleware.shibboleth.common.AQHTest" />
-               </junit>
+       <target name="exampleCertificate">
+               <genkey alias="tomcat" storepass="exampleorg"
+                       keystore="${tomcat.home}/conf/example.jks"
+                       keyalg="RSA" validity="365"
+                       dname="cn=shibboleth.example.org, o=example.org, c=US"
+               />
        </target>
 
-</project>
 
+    <!-- Install Shibboleth -->
+    <target name="install.init">
+       <taskdef name="xinput" classname="edu.internet2.middleware.shibboleth.utils.ant.XInput" classpath="${build}"/>
+       <typedef name="xoption" classname="edu.internet2.middleware.shibboleth.utils.ant.XInputOption" classpath="${build}"/>
+    </target>
+
+    <target name="install" depends="init, install.init" description="Install Shibboleth">
+        <if>
+            <xinput type="confirm" defaultvalue="y">Do you want to install the Shibboleth Identity Provider?</xinput>
+            <then>
+                <input message="What name do you want to use for the Identity Provider web application? [default: ${shib.webapp.name}]" 
+                    addproperty="shib.webapp.name.input" defaultValue="${shib.webapp.name}" />
+                <var name="shib.webapp.name" value="${shib.webapp.name.input}" />
+
+                <antcall target="install.idp" />
+            </then>
+        </if>
+    </target>
+
+       <target name="install.idp" depends="init, install.init">
+        <xinput message="Deploying the java web application.  Do you want to install it directly onto the filesystem or use the tomcat manager application?" 
+            addproperty="idp.install-type.input" type="menu" casesensitive="no" defaultValue="${idp.install-type}">
+            <xoption>filesystem</xoption>
+            <xoption>manager</xoption>
+        </xinput>
+        <var name="idp.install-type" value="${idp.install-type.input}" />
+        
+        <antcall target="install.idp.${idp.install-type}" />
+    </target>
+
+    <target name="install.idp.filesystem" depends="init, install.init, build-util">
+        <input message="Select an installation base for the Shibboleth Identity Provider [default: ${shib.home}]"
+            addproperty="shib.home.input" defaultvalue="${shib.home}" />
+        <var name="shib.home" value="${shib.home.input}" />
+
+        <input message="Enter tomcat home directory [default: ${tomcat.home}]"
+            addproperty="tomcat.home.input" defaultvalue="${tomcat.home}" />
+        <var name="tomcat.home" value="${tomcat.home.input}" />
+        
+        <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
+        <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
+        <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
+               <delete file="${configroot}/idp.xml"/>
+        <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
+
+        <if>
+                       <available file="${shib.home}/etc" />
+            <then>
+                <if>
+                    <xinput type="confirm">WARNING!! The directory `${shib.home}/etc` already exists.  Do you want to overwrite the existing configuration?</xinput>
+                    <then>
+                        <delete dir="${shib.home}/etc" />
+                        <antcall target="install.idp.filesystem.config" />
+                    </then>
+                </if>
+            </then>
+            <else>
+                <antcall target="install.idp.filesystem.config" />
+            </else>
+        </if>
+
+        <copy todir="${shib.home}/lib">
+            <fileset dir="lib" includesfile="conf/idp-lib.include" />
+        </copy>
+
+        <copy todir="${shib.home}/bin">
+            <fileset dir="bin"/>
+        </copy>
+               <chmod dir="${shib.home}/bin" perm="ug+rx" includes="**/*"/>
+
+        <mkdir dir="${shib.home}/logs" />
+
+        <antcall target="savePropertyFile" />
+    </target>
+
+       <target name="install.idp.filesystem.config" depends="init, install.init">
+        <mkdir dir="${shib.home}/etc" />
+        <copy todir="${shib.home}/etc" overwrite="true">
+            <fileset dir="${src}/conf" includesfile="conf/idp-conf.include"/>
+        </copy>
+               <copy file="${shib.home}/etc/idp.xml.dist" tofile="${shib.home}/etc/idp.xml" overwrite="true" />
+               <delete file="${shib.home}/etc/idp.xml.dist"/>
+        <replace file="${shib.home}/etc/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
+    </target>
+
+       <target name="install.idp.manager" depends="init, install.init">
+        <antcall target="setupTomcatTasks" />
+        
+        <input message="Enter local tomcat directory [default: ${tomcat.home}]" addproperty="tomcat.home.input" defaultValue="${tomcat.home}" />
+        <var name="tomcat.home" value="${tomcat.home.input}" />
+        
+        <input message="Enter tomcat url [default: ${tomcat.url}]" addproperty="tomcat.url.input" defaultValue="${tomcat.url}" />
+        <var name="tomcat.url" value="${tomcat.url.input}" />
+        
+        <input message="Enter tomcat username [default: ${tomcat.username}]" addproperty="tomcat.username.input" defaultValue="${tomcat.username}" />
+        <var name="tomcat.username" value="${tomcat.username.input}" />
+        
+        <input message="Enter tomcat password [default: ${tomcat.password}]" addproperty="tomcat.password.input" defaultValue="${tomcat.password}" />
+        <var name="tomcat.password" value="${tomcat.password.input}" />
+        
+        <antcall target="tomcat.deploy" />
+        <antcall target="savePropertyFile" />
+    </target>
+
+    <target name="savePropertyFile">
+        <propertyfile file="build.properties">
+            <entry key="shib.home" value="${shib.home}" />
+            <entry key="shib.webapp.name" value="${shib.webapp.name}" />
+            <entry key="idp.install-type" value="${idp.install-type}" />
+            <entry key="tomcat.home" value="${tomcat.home}" />
+            <entry key="tomcat.url" value="${tomcat.url}" />
+            <entry key="tomcat.username" value="${tomcat.username}" />
+            <entry key="tomcat.password" value="${tomcat.password}" />
+        </propertyfile>
+    </target>
+
+
+       <!-- Create an IdP war and copy it to the pre-configured tomcat directory -->
+       <target name="copy-IdP" depends="compile" description="Copy shibboleth.war to {tomcat.home}/webapps (Tomcat must be stopped first)">
+               <!-- This task assumes that a pre-existing properties file has the correct path information -->
+        <copy file="${configroot}/idp.xml.dist" tofile="${configroot}/idp.xml" overwrite="true" />
+        <replace file="${configroot}/idp.xml" token="$SHIB_HOME$" value="${shib.home}" />
+        <war warfile="${dist}/${distname}.war" webxml="${configroot}/idp.xml" basedir="${approot}" update="no" />
+        <copy file="${dist}/${distname}.war" tofile="${tomcat.home}/webapps/${shib.webapp.name}.war" />
+               <delete dir="${tomcat.home}/webapps/${distname}" quiet="yes" />
+       </target>
+
+
+    <!-- Create WAYF and move it to ${dist} -->
+    <target name="package-wayf" depends="compile, clean-build">
+        <war warfile="${dist}/${distnameWayf}.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
+    </target>
+    
+</project>