Unit tests with internal classes now run correctly - Fix bug 421
[java-idp.git] / custom / extension-build.xml
index 2fe339c..698fb52 100644 (file)
@@ -1,20 +1,34 @@
 <!-- 
   This file is imported in to the main Shibboleth build.xml file and 
-  contains all targets used for building IdP and SP extensions.
+  contains all targets used for building IdP and SP extensions.  These
+  targets are not designed to be called by anything other than the main
+  Shibboleth build file.
   
   Chad La Joie
-  July 6, 2005
+  July 25, 2005
 -->
 <project name="Shibboleth-Extensions" default="ext-invoke" basedir=".">
 
+    <path id="ext.path">
+        <!-- Shibboleth Libraries -->
+        <path refid="build.path" />
+
+        <!-- Shibboleth Classes -->
+        <pathelement location="${build}" />
+
+        <!-- Extension libraries -->
+        <fileset dir="${ext.lib}">
+            <include name="**/*.jar" />
+        </fileset>
+
+        <!-- Extension classes -->
+        <pathelement location="${ext.classes}" />
+        
+        <!-- Extension test classes -->
+        <pathelement location="${ext.test.classes}" />
+    </path>
+
     <!-- 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}">
         </for>
     </target>
 
-    <!-- Builds a single extension, called multiple times by build-exts -->
+    <!-- Builds a single 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="ext-compile" />
 
+        <!-- Generate Javadocs -->
+        <antcall target="ext-gen-docs" />
+
         <!-- Copy over non-source files -->
         <antcall target="ext-copy-src-conf" />
 
-        <!-- Generate the java docs if we're supposed to -->
-        <antcall target="ext-gen-docs" />
-
         <!-- Run unit tests if we're supposed to -->
         <antcall target="ext-test" />
 
-        <!-- Package everything up -->
-        <antcall target="ext-package" />
-
         <!-- Put the libraries where the IdP and SP packaging can pick them up -->
         <antcall target="ext-copy-libs" />
 
         <echo message="--- Extension ${ext.name} built" />
     </target>
 
-    <!-- Initialize everything we need. -->
-    <!-- The properties loaded here are scoped to this particular extension build -->
-    <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.
-               -->
+    <target name="ext-load-properties" description="Loads property files needed by build process">
+        <!-- Load extension specific properties. -->
         <if>
             <not>
                 <available file="${ext.root}/build.properties" />
         <property file="${ext.root}/build.properties" />
 
         <!-- Load default 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." />
+    </target>
+
+    <!-- Initialize everything we need. -->
+    <!-- The properties loaded here are scoped to this particular extension build -->
+    <target name="ext-build-init" depends="ext-load-properties" description="Sets up everything to prepare for the build">
 
         <!-- Create needed directories -->
         <mkdir dir="${ext.dist}" />
+        <mkdir dir="${ext.build}" />
         <mkdir dir="${ext.classes}" />
+        <mkdir dir="${ext.test.classes}" />
+        <mkdir dir="${ext.docs}" />
     </target>
 
     <!-- Compiles the extension -->
             <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 Libraries -->
-                    <classpath refid="build.path" />
-
-                    <!-- Shibboleth Classes -->
-                    <classpath>
-                        <pathelement location="${build}" />
-                    </classpath>
-
-                    <!-- Extension libraries -->
-                    <classpath>
-                        <fileset dir="${ext.lib}">
-                            <include name="**/*.jar" />
-                        </fileset>
-                    </classpath>
-                </javac>
+                <javac srcdir="${ext.src}"
+                       destdir="${ext.classes}"
+                       classpathref="ext.path"
+                       includes="**/*.java"
+                       debug="on"
+                       source="1.4"
+                       deprecation="true"/>
             </then>
         </if>
     </target>
 
     <!-- Copies files from etc directory to dist directory to be bundled with extension 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">
+    <target name="ext-copy-src-conf" 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.src.conf}" />
             <then>
-                <echo message="Detected files in the extensions 'etc' directory, ensuring they are bundled with the extension's jar." />
+                <echo message="Detected files in the extensions 'src-conf' directory, ensuring they are bundled with the extension's jar." />
                 <copy todir="${ext.classes}">
                     <fileset dir="${ext.src.conf}">
                         <include name="**" />
     </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">
+    <target name="ext-copy-libs" 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">
+    <target name="ext-copy-webpages" description="Moves web resources to be picked up by the war">
         <if>
             <available file="${ext.webpages}" />
             <then>
 
 
     <!-- Run any unit tests for the extension -->
-    <target name="ext-test" depends="ext-compile" description="Runs extension unit test">
+    <target name="ext-test" description="Runs extension unit test">
         <if>
             <equals arg1="${test.ext}" arg2="true" />
             <then>
                 <if>
                     <available file="${ext.test.src}" />
                     <then>
+                        <echo message="Compiling extension test source" />
+                        <javac srcdir="${ext.test.src}"
+                               destdir="${ext.test.classes}"
+                               classpathref="ext.path"
+                               includes="**/*.java"
+                               debug="on"
+                               source="1.4"
+                               deprecation="true"/>
+
                         <echo message="Running tests cases for extension ${ext.name}" />
-                        <junit printsummary="no" fork="yes" haltonerror="true" haltonfailure="true" jvm="${ext.root}">
+                        <junit printsummary="no" fork="yes" haltonerror="true" haltonfailure="true" dir="${ext.root}">
                             <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
+                            <classpath refid="ext.path"/>
                             <formatter type="plain" />
-                            <batchtest>
+                            <batchtest todir="${ext.root}">
                                 <fileset dir="${ext.test.src}" />
                             </batchtest>
                         </junit>
                 </if>
             </then>
         </if>
-
     </target>
 
     <!-- Generates the Javadocs for the extension -->
                         <echo message="Generating javadocs for extension ${ext.name}" />
                         <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" />
+                            <link href="http://java.sun.com/j2se/1.5.0/docs/api/" />
                         </javadoc>
                     </then>
                 </if>
     </target>
 
     <!-- Jars up the extension -->
-    <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" />
+    <!-- 
+        Required parameters
+            exts.dir - the root directory of the extensions (contains all the individual extension directories)
+            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, in config files, to replace with the path to the IdP/SP home
+    -->
+    <target name="ext-package" depends="ext-load-properties" description="Packages up the extension">
+        <if>
+            <available file="${ext.classes}" />
+            <then>
+                <replace dir="${ext.classes}" token="${ext.home.token}" value="${ext.filesystem.home}" excludes="*.class" />
+                <replace dir="${ext.classes}" token="$EXTENSION_NAME$" value="${ext.name}" excludes="*.class" />
+                <jar jarfile="${ext.dist}/${ext.name}.jar" basedir="${ext.classes}" update="false" />
+                <copy file="${ext.dist}/${ext.name}.jar" todir="${exts.dir}/lib" />
+                <delete dir="${ext.classes}" />
+            </then>
+        </if>
     </target>
 
     <!-- Install extension files (configuration, scripts, etc) on to the filesystem -->
                 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}"/>
-        
+        <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>
+        <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>
 
         <!-- Copy anything in the bin directory to the extension's installation point bin directory -->
         <if>
                         <include name="*" />
                     </fileset>
                 </copy>
-                <chmod dir="${ext.filesystem.home}/bin" perm="ug+rx" includes="**/*"/>
+                <chmod dir="${ext.filesystem.home}/bin" perm="ug+rx" includes="**/*" />
             </then>
         </if>
 
                 </copy>
             </then>
         </if>
-        
+
         <!-- Copy the extension jar to the extension's installation point lib directory -->
         <if>
-            <available file="${ext.dist}/${ext.name}.jar"/>
+            <available file="${ext.dist}/${ext.name}.jar" />
             <then>
-                <copy file="${ext.dist}/${ext.name}.jar" todir="${ext.filesystem.home}/lib"/>
+                <copy file="${ext.dist}/${ext.name}.jar" todir="${ext.filesystem.home}/lib" />
             </then>
         </if>
     </target>
 
-    <!-- Cleans up build generated resources -->
-    <target name="ext-clean" description="Cleans up any build created resources">
-        <delete dir="${ext.root}/dist" failonerror="false" />
+    <!-- Cleans up classes files -->
+    <target name="ext-clean-build" depends="ext-load-properties" description="Cleans up any build created resources">
+        <delete dir="${ext.build}" failonerror="false" />
+    </target>
+
+    <!-- Cleans up java docs -->
+    <target name="ext-clean-javadocs" depends="ext-load-properties" description="Deletes generated javadocs">
+        <delete dir="${ext.docs}" failonerror="false" />
+    </target>
+
+    <!-- Cleans up distribution files -->
+    <target name="ext-clean-dist" depends="ext-load-properties" description="Deletes distribution generated files">
+        <delete dir="${ext.dist}" failonerror="false" />
     </target>
 </project>