Fixed logic bug in JDBC Data Connector.
[java-idp.git] / custom / extension-build.xml
index da750da..2fe339c 100644 (file)
@@ -5,10 +5,17 @@
   Chad La Joie
   July 6, 2005
 -->
-<project name="Shibboleth-Extensions" default="build-exts" basedir=".">
+<project name="Shibboleth-Extensions" default="ext-invoke" basedir=".">
 
-    <!-- Builds the extensions; loops through all the extension directories and builds them -->
-    <target name="build-exts" description="Compiles IdP and/or SP extensions">
+    <!-- Loops through all the extension directories and executes a particular operation on them -->
+    <!-- 
+        Required parameters
+            exts.dir - the root directory of the extensions (contains all the individual extension directories)
+            ext.build.function - the particular extension build function to invoke, acceptable values
+                   ext-invoke, ext-clean, ext-install-filesystem 
+               (some functions may require additional paramters, see documentation for each function)
+    -->
+    <target name="ext-invoke" description="Invoke operation extensions">
         <for keepgoing="true" param="module-path">
             <dirset dir="${exts.dir}">
                 <include name="*" />
@@ -16,7 +23,7 @@
                 <exclude name="web" />
             </dirset>
             <sequential>
-                <antcall target="standard-ext-build">
+                <antcall target="${ext.build.function}">
                     <param name="ext.root" value="@{module-path}" />
                 </antcall>
             </sequential>
     </target>
 
     <!-- Builds a single extension, called multiple times by build-exts -->
-    <target name="standard-ext-build" depends="ext-build-init" description="Builds the extension">
+    <target name="ext-build" depends="ext-build-init" description="Builds the extension">
         <echo message="--- Starting to build module ${ext.name} in ${ext.root}" />
 
         <!-- Compile the source -->
-        <antcall target="compile-ext" />
+        <antcall target="ext-compile" />
 
         <!-- Copy over non-source files -->
-        <antcall target="copy-etc" />
+        <antcall target="ext-copy-src-conf" />
 
         <!-- Generate the java docs if we're supposed to -->
-        <antcall target="gen-ext-docs" />
+        <antcall target="ext-gen-docs" />
 
         <!-- Run unit tests if we're supposed to -->
-        <antcall target="test-ext" />
+        <antcall target="ext-test" />
 
         <!-- Package everything up -->
-        <antcall target="package-ext" />
+        <antcall target="ext-package" />
 
         <!-- Put the libraries where the IdP and SP packaging can pick them up -->
-        <copy todir="${exts.dir}/lib">
-            <fileset dir="${ext.lib}" includes="*.jar" />
-            <fileset dir="${ext.dist}" includes="*.jar" />
-        </copy>
+        <antcall target="ext-copy-libs" />
 
         <!-- Put the webpages where the IdP and SP packaging can pick them up -->
-        <copy todir="${exts.dir}/web">
-            <fileset dir="${ext.webpages}" includes="*" />
-        </copy>
+        <antcall target="ext-copy-webpages" />
+
         <echo message="--- Extension ${ext.name} built" />
     </target>
 
     <target name="ext-build-init" description="Sets up everything to prepare for the build">
         <echo message="Loading build property files" />
         <!-- 
-          Load extension specific properties if available. We can not set the extension's build.properties 
-          file name in the extension-build.properties file because if we read that file first the extension 
-          build properties won't be able to override properties in it as properties are immutable once set.
-        -->
+               Load extension specific properties if available. We can not set the extension's build.properties 
+               file name in the extension-build.properties file because if we read that file first the extension 
+               build properties won't be able to override properties in it as properties are immutable once set.
+               -->
+        <if>
+            <not>
+                <available file="${ext.root}/build.properties" />
+            </not>
+            <then>
+                <fail message="No build.properties file found for extension in ${ext.root}; this file is required." />
+            </then>
+        </if>
         <property file="${ext.root}/build.properties" />
 
         <!-- Load default properties -->
-        <echo message="Loading build property defaults ${exts-dir}/default-build.properties" />
+        <echo message="Loading build property defaults ${exts.dir}/default-build.properties" />
         <property file="${exts.dir}/extension-build.properties" />
 
+        <fail unless="ext.name" message="The extension ${ext.root} does not contain the required (ext.name) property in its build.properties file." />
+
         <!-- Create needed directories -->
         <mkdir dir="${ext.dist}" />
         <mkdir dir="${ext.classes}" />
     </target>
 
     <!-- Compiles the extension -->
-    <target name="compile-ext" depends="ext-build-init" description="Compiles an extension">
+    <target name="ext-compile" description="Compiles an extension">
         <!-- Compile any source that might be out there -->
         <if>
             <available file="${ext.src}" />
             <then>
                 <echo message="Compiling extension source" />
                 <javac srcdir="${ext.src}" destdir="${ext.classes}" includes="**/*.java" debug="on" source="1.4">
-                    <!-- Shibboleth Classpath -->
+                    <!-- Shibboleth Libraries -->
                     <classpath refid="build.path" />
 
+                    <!-- Shibboleth Classes -->
+                    <classpath>
+                        <pathelement location="${build}" />
+                    </classpath>
+
                     <!-- Extension libraries -->
                     <classpath>
                         <fileset dir="${ext.lib}">
     </target>
 
     <!-- Copies files from etc directory to dist directory to be bundled with extension jar -->
-    <target name="copy-etc" depends="ext-build-init" description="Copys non-source files to place where they will be added to jar">
+    <target name="ext-copy-src-conf" depends="ext-build-init" description="Copys non-source files to place where they will be added to jar">
         <!-- Copy any extra stuff that needs to be on the classpath -->
         <if>
-            <available file="${ext.etc}" />
+            <available file="${ext.src.conf}" />
             <then>
                 <echo message="Detected files in the extensions 'etc' directory, ensuring they are bundled with the extension's jar." />
                 <copy todir="${ext.classes}">
-                    <fileset dir="${ext.etc}">
+                    <fileset dir="${ext.src.conf}">
                         <include name="**" />
                     </fileset>
                 </copy>
         </if>
     </target>
 
+    <!-- Move third party libraries to be picked up by the war -->
+    <target name="ext-copy-libs" depends="ext-compile" description="Moves third party libraries to be picked up by the war">
+        <if>
+            <available file="${ext.lib}" />
+            <then>
+                <copy todir="${exts.dir}/lib">
+                    <fileset dir="${ext.lib}" includes="*.jar" />
+                    <fileset dir="${ext.dist}" includes="*.jar" />
+                </copy>
+            </then>
+        </if>
+    </target>
+
+    <!-- Move web resources to be picked up by the war -->
+    <target name="ext-copy-webpages" depends="ext-compile" description="Moves web resources to be picked up by the war">
+        <if>
+            <available file="${ext.webpages}" />
+            <then>
+                <copy todir="${exts.dir}/web">
+                    <fileset dir="${ext.webpages}" />
+                </copy>
+            </then>
+        </if>
+    </target>
+
+
     <!-- Run any unit tests for the extension -->
-    <target name="test-ext" depends="compile-ext" description="Runs extension unit test">
+    <target name="ext-test" depends="ext-compile" description="Runs extension unit test">
         <if>
             <equals arg1="${test.ext}" arg2="true" />
             <then>
     </target>
 
     <!-- Generates the Javadocs for the extension -->
-    <target name="gen-ext-docs" description="Generates Javadocs for extension">
+    <target name="ext-gen-docs" description="Generates Javadocs for extension">
         <if>
             <equals arg1="${gen.ext.docs}" arg2="true" />
             <then>
                 <if>
-                    <available file="${ext.etc}" />
+                    <available file="${ext.src}" />
                     <then>
                         <echo message="Generating javadocs for extension ${ext.name}" />
-                        <javadoc sourcepath="${ext.src}" destdir="${ext.docs}" />
+                        <javadoc sourcepath="${ext.src}" destdir="${ext.docs}" packagenames="*" author="true" version="true" windowtitle="${ext.name} Shibboleth Extension Java API" doctitle="${ext.name} Shibboleth Extension Java API" failonerror="false">
+                            <classpath refid="build.path" />
+                        </javadoc>
                     </then>
                 </if>
             </then>
     </target>
 
     <!-- Jars up the extension -->
-    <target name="package-ext" depends="compile-ext" description="Packages up the extension">
-        <jar jarfile="${ext.dist}/${ext.name}.jar" basedir="${ext.dist}" excludes="${ext.name}.jar" />
+    <target name="ext-package" depends="ext-compile" description="Packages up the extension">
+        <jar jarfile="${ext.dist}/${ext.name}.jar" basedir="${ext.classes}" excludes="${ext.name}.jar" />
     </target>
 
-    <!-- Cleans up build generated resources -->
-    <target name="clean-ext" description="Cleans up any build created resources">
-        <!-- Clean up all the modules -->
-        <for keepgoing="true" param="module-path">
-            <dirset dir="${exts.dir}">
-                <include name="*" />
-                <exclude name="lib" />
-                <exclude name="web" />
-            </dirset>
-            <sequential>
-                <delete dir="${ext.dist}" />
-            </sequential>
-        </for>
+    <!-- Install extension files (configuration, scripts, etc) on to the filesystem -->
+    <!--
+        Required Paramter
+            ext.filesystem.home - the path on the filesystem that the extension will be installed
+                expected subdirectories are 'bin, 'etc', and 'lib'
+            ext.home.token - the token that represents the extensions installation point within
+                the various configuration files (those in the extensions 'etc' and 'src-conf' directories)
+    -->
+    <target name="ext-install-filesystem" depends="ext-build-init" description="Installs extension files on to the filesystem">
+        <echo message="Installing extension ${ext.name} to ${ext.filesystem.home}"/>
+        
+        <!-- Copy anything in the etc directory to the extension's installation point etc directory -->
+               <if>
+                       <available file="${ext.etc}" />
+                       <then>
+                               <if>
+                                       <available file="${ext.filesystem.home}/etc/${ext.name}" />
+                                       <then>
+                                               <echo>--------------------------------------------------------------------------------------</echo>
+                                               <echo>---</echo>
+                                               <echo>---   NOTE:  Existing Shibboleth extension module configuration at ${line.separator}---   ${ext.filesystem.home}/etc/${ext.name} will not be overwritten.</echo>
+                                               <echo>---</echo>
+                                               <echo>--------------------------------------------------------------------------------------</echo>
+                                       </then>
+                                       <else>
+                                               <mkdir dir="${ext.filesystem.home}/etc/${ext.name}" />
+                                               <copy todir="${ext.filesystem.home}/etc/${ext.name}">
+                                                       <fileset dir="${ext.etc}">
+                                                               <include name="*" />
+                                                       </fileset>
+                                               </copy>
+                                               <replace dir="${ext.filesystem.home}/etc/${ext.name}" 
+                                                       token="${ext.home.token}" 
+                                                       value="${ext.filesystem.home}"/>
+                                               <replace dir="${ext.filesystem.home}/etc/${ext.name}" 
+                                                       token="$EXTENSION_NAME$" 
+                                                       value="${ext.name}"/>
+                                       </else>
+                               </if>
+                       </then>
+               </if>
 
-        <!-- Clean out all the staged libraries from the modules -->
-        <delete dir="${exts.dir}/lib" includeemptydirs="true">
-            <fileset dir="${exts.dir}/lib" includes="**/*" />
-        </delete>
+        <!-- Copy anything in the bin directory to the extension's installation point bin directory -->
+        <if>
+            <available file="${ext.bin}" />
+            <then>
+                <copy todir="${ext.filesystem.home}/bin">
+                    <fileset dir="${ext.bin}">
+                        <include name="*" />
+                    </fileset>
+                </copy>
+                <chmod dir="${ext.filesystem.home}/bin" perm="ug+rx" includes="**/*"/>
+            </then>
+        </if>
 
-        <!-- Clean out all the staged web pages from the modules -->
-        <delete dir="${exts.dir}/web" includeemptydirs="true">
-            <fileset dir="${exts.dir}/web" includes="**/*" />
-        </delete>
+        <!-- Copy anything in the lib directory to the extension's installation point lib directory -->
+        <if>
+            <available file="${ext.lib}" />
+            <then>
+                <copy todir="${ext.filesystem.home}/lib">
+                    <fileset dir="${ext.lib}">
+                        <include name="*" />
+                    </fileset>
+                </copy>
+            </then>
+        </if>
+        
+        <!-- Copy the extension jar to the extension's installation point lib directory -->
+        <if>
+            <available file="${ext.dist}/${ext.name}.jar"/>
+            <then>
+                <copy file="${ext.dist}/${ext.name}.jar" todir="${ext.filesystem.home}/lib"/>
+            </then>
+        </if>
     </target>
 
-</project>
\ No newline at end of file
+    <!-- Cleans up build generated resources -->
+    <target name="ext-clean" description="Cleans up any build created resources">
+        <delete dir="${ext.root}/dist" failonerror="false" />
+    </target>
+</project>