Initial code for building custom extensions
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 6 Jul 2005 16:21:31 +0000 (16:21 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 6 Jul 2005 16:21:31 +0000 (16:21 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1685 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

custom/README.txt [new file with mode: 0644]
custom/extension-build.properties [new file with mode: 0644]
custom/extension-build.xml [new file with mode: 0644]

diff --git a/custom/README.txt b/custom/README.txt
new file mode 100644 (file)
index 0000000..12a13f6
--- /dev/null
@@ -0,0 +1,58 @@
+The custom directory contains the information necessary to build 
+extension for the Shibboleth IdP and SP at the same time they are built, and
+have these extensions bundled with their respective war filee.
+
+1. Directory Structure
+    custom
+      /lib - this directory is where an extension and its 
+             libraries are placed after they are built
+      /web - this directory is where an extension's web pages
+             are placed after the extension is built
+      extension-build.properties - this contains default properties 
+                                 needed for the extension build process
+                                 !!! DO NOT EDIT THIS FILE !!!
+      extension-build.xml - the ant build file for building extensions
+                                 !!! DO NOT EDIT THIS FILE !!!
+      README.txt - this document
+                               
+
+2. Using the Extension Build Process
+The extension build process depends on an extension having a specific directory
+structure, so that the extension build file knows where to find everything.  The 
+root directory of you extension can be named anything you with, but it must contain
+the following directories
+    your-extension-directory/
+       etc/ - [Optional] This directory contains anything that isn't java source but still needs 
+              to be on the classpath.  This can include subdirectories, and can be excluded.
+       lib/ - [Optional] any third party jars your extension needs
+       src/ - [REQUIRED] your extension's source
+       tests/ - [Optional] Your extension's JUnit test case source.
+       web/ - [Optional] Any web pages, images, JSPs, etc. that should be included with the war
+       build.properties - [REQUIRED] build properties for your extension 
+                            (see below for required and optional properties)
+  
+2.1 Steps for Using the Extensions Build Process
+I.  Create a directory under the custom directory with the structure mentioned above.  Any 
+extra directories will be ignored so it is safe to bundle additional information with your 
+extension such as documentation.
+
+II. Place your code and other resources in the directory structure you just set up
+
+III. Compile and deploy Shibboleth as normal.
+
+2.2 Build File Properties
+  The build file supports the following properties on a per-extension basis.
+    ext.name - [REQUIRED] The name of your resulting extension jar file (.jar will be appended to the name)
+    gen.ext.docs - [Optional] This controls whether java docs will be generated for your
+                   extension.  A value of "true" will result in them being generated, any other 
+                   value will result in them not being generated, if this property is missing 
+                   the defualt value of "true" is used.
+    test.ext - [Optional] This controls whether the JUnit tests for your extension are run.
+                   A value of "true" will result in them being run, any other value will result 
+                   in them not being skipped, if this property is missing the defualt value of 
+                   "true" is used.
+
+3. Cautionary Note
+DO NOT include libraries, with your extension, that are included with the Shibboleth
+IdP or SP.  If you do, and there are version mismatches between the two jars, you will get 
+unexpected exceptions during runtime as class versions conflict.
\ No newline at end of file
diff --git a/custom/extension-build.properties b/custom/extension-build.properties
new file mode 100644 (file)
index 0000000..5f4ba9e
--- /dev/null
@@ -0,0 +1,14 @@
+# DO NOT EDIT THIS FILE
+
+ext.lib=${ext.root}/lib
+ext.etc=${ext.root}/etc
+ext.src=${ext.root}/src
+ext.test-src=${ext.root}/tests
+ext.webpages=${ext.root}/web
+ext.dist=${ext.root}/dist
+ext.classes=${ext.dist}/classes
+ext.docs=${ext.dist}/docs
+
+# Properties controlling build behavior
+gen.ext.docs=true
+test.ext=true
\ No newline at end of file
diff --git a/custom/extension-build.xml b/custom/extension-build.xml
new file mode 100644 (file)
index 0000000..f13967f
--- /dev/null
@@ -0,0 +1,169 @@
+<!-- 
+  This file is imported in to the main Shibboleth build.xml file and 
+  contains all targets used for building IdP and SP extensions.
+  
+  Chad La Joie
+  July 6, 2005
+-->
+<project name="Shibboleth-Extensions" default="build-exts" basedir=".">
+
+    <!-- Builds the extensions; loops through all the extension directories and builds them -->
+    <target name="build-exts" description="Compiles IdP and/or SP extensions">
+        <for keepgoing="true" param="module-path">
+            <dirset dir="${exts.dir}">
+                <include name="*" />
+                <exclude name="lib" />
+                <exclude name="web" />
+            </dirset>
+            <sequential>
+                <antcall target="standard-ext-build">
+                    <param name="ext.root" value="@{module-path}" />
+                </antcall>
+            </sequential>
+        </for>
+    </target>
+
+    <!-- Builds a single extension, called multiple times by build-exts -->
+    <target name="standard-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" />
+
+        <!-- Generate the java docs if we're supposed to -->
+        <antcall target="gen-ext-docs" />
+
+        <!-- Run unit tests if we're supposed to -->
+        <antcall target="test-ext" />
+
+        <!-- Package everything up -->
+        <echo message="Packaging extension" />
+        <antcall target="package-ext" />
+
+        <!-- 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>
+
+        <!-- Put the webpages where the IdP and SP packaging can pick them up -->
+        <copy todir="${exts.dir}/web">
+            <fileset dir="${ext.web}" includes="*" />
+        </copy>
+        <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.
+        -->
+        <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" />
+
+        <!-- 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">
+        <echo message="Compiling extension source" />
+        <javac srcdir="${ext.src}" destdir="${ext.classes}" includes="**/*.java" debug="on" source="1.4">
+            <!-- Shibboleth Classpath -->
+            <classpath refid="build.path" />
+
+            <!-- Extension libraries -->
+            <classpath>
+                <fileset dir="${ext.lib}">
+                    <include name="**/*.jar" />
+                </fileset>
+            </classpath>
+        </javac>
+
+        <!-- Copy any extra stuff that needs to be on the classpath -->
+        <if>
+            <available file="${ext.etc}" />
+            <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}">
+                        <include name="**" />
+                    </fileset>
+                </copy>
+            </then>
+        </if>
+    </target>
+
+    <!-- Run any unit tests for the extension -->
+    <target name="test-ext" depends="compile-ext" description="Runs extension unit test">
+        <if>
+            <equals arg1="${test.ext}" arg2="true" />
+            <then>
+                <if>
+                    <available file="${ext.test.src}" />
+                    <then>
+                        <echo message="Running tests cases for extension ${ext.name}" />
+                        <junit printsummary="no" fork="yes" haltonerror="true" haltonfailure="true" jvm="${ext.root}">
+                            <jvmarg value="-Djava.endorsed.dirs=${endorsed}" />
+                            <formatter type="plain" />
+                            <batchtest>
+                                <fileset dir="${ext.test.src}" />
+                            </batchtest>
+                        </junit>
+                    </then>
+                </if>
+            </then>
+        </if>
+
+    </target>
+
+    <!-- Generates the Javadocs for the extension -->
+    <target name="gen-ext-docs" description="Generates Javadocs for extension">
+        <if>
+            <equals arg1="${gen.ext.docs}" arg2="true" />
+            <then>
+                <echo message="Generating javadocs for extension ${ext.name}" />
+                <javadoc sourcepath="${ext.src}" destdir="${ext.docs}" />
+            </then>
+        </if>
+    </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>
+
+    <!-- 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>
+
+        <!-- Clean out all the staged libraries from the modules -->
+        <delete dir="${exts.dir}/lib" includeemptydirs="true">
+            <fileset dir="${exts.dir}/lib" includes="**/*" />
+        </delete>
+
+        <!-- Clean out all the staged web pages from the modules -->
+        <delete dir="${exts.dir}/web" includeemptydirs="true">
+            <fileset dir="${exts.dir}/web" includes="**/*" />
+        </delete>
+    </target>
+
+</project>
\ No newline at end of file