Modify the build script to allow multi-layer products.

This commit is contained in:
jeb228 2010-08-03 18:53:55 +00:00
parent 802e5bc1ab
commit e35bce16f0
2 changed files with 239 additions and 214 deletions

View file

@ -5,7 +5,7 @@
<!-- ======================================================================
Build script for the Vitro core webapp.
This can be used on its own, or included into a Product build script.
This can be used on its own, or invoked from a Product build script.
====================================================================== -->
<project name="vitroCore" default="describe">
@ -13,44 +13,40 @@
<!-- - - - - - - - - - - - - - - - - -
properties
- - - - - - - - - - - - - - - - - -->
<!--
The build directory is located under the directory with the top-level
script, so if called from a Product build script, the build directory
will be in the Product directory.
-->
<property name="build.dir" location=".build" />
<property name="webapp.dir" location="." />
<!--
The webapp directory is based on this script, regardless of whether we
run this script alone, or call it from a Product build script.
-->
<dirname property="vitroCore.basedir" file="${ant.file.vitroCore}" />
<property name="webapp.dir" location="${vitroCore.basedir}" />
<property name="war.dir" location="${build.dir}/war" />
<property name="war-webinf.dir" location="${war.dir}/WEB-INF" />
<property name="war-classes.dir" location="${war-webinf.dir}/classes" />
<property name="war-lib.dir" location="${war-webinf.dir}/lib" />
<property name="test-classes.dir" location="${build.dir}/testclasses" />
<property name="servletjars.dir" location="${build.dir}/servletjars" />
<!-- - - - - - - - - - - - - - - - - -
paths: for compiling and running
- - - - - - - - - - - - - - - - - -->
<path id="compile.classpath">
<fileset dir="${webapp.dir}/lib">
<fileset dir="${war-lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${servletjars.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="test.compile.classpath">
<pathelement location="${build.dir}/war/WEB-INF/classes" />
<pathelement location="${war-classes.dir}" />
<path refid="compile.classpath" />
</path>
<path id="test.run.classpath">
<!--
To get the data files and the correct log4j.properties,
this comes before the classes directory
-->
<!-- This holds data files and a special log4j.properties -->
<pathelement location="${webapp.dir}/test" />
<pathelement location="${build.dir}/testclasses" />
<pathelement location="${test-classes.dir}" />
<path refid="test.compile.classpath" />
</path>
@ -64,7 +60,6 @@ all - Runs "clean", then "deploy".
clean - Delete all artifacts so the next build will be from scratch.
compile - Compile the Java source files.
test - Compile and run the JUnit tests.
war - Assemble everything into a deployable WAR file.
deploy - Deploy the application directly into the Tomcat webapps directory.
</echo>
</target>
@ -129,8 +124,90 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
- - - - - - - - - - - - - - - - - -->
<target name="prepare" depends="properties">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dir}/war/WEB-INF/classes" />
<mkdir dir="${build.dir}/testclasses" />
<mkdir dir="${war-classes.dir}" />
<mkdir dir="${test-classes.dir}" />
<!-- copy the themes into the war directory. -->
<copy todir="${war.dir}">
<fileset dir="${webapp.dir}/web">
<!--
If a product doesn't want the core themes, it can
set this property and they will be skipped.
-->
<exclude name="themes/**/*" if="skip.core.themes" />
</fileset>
</copy>
<!-- copy the config files into the war directory. -->
<copy todir="${war-webinf.dir}">
<fileset file="${webapp.dir}/config/web.xml" />
<fileset file="${webapp.dir}/config/dwr.xml" />
</copy>
<!-- copy the ontologies and the submodels into the war directory. -->
<copy todir="${war-webinf.dir}">
<fileset dir="${webapp.dir}" includes="ontologies" />
<fileset dir="${webapp.dir}" includes="ontologies/**/*" />
<fileset dir="${webapp.dir}" includes="submodels" />
<fileset dir="${webapp.dir}" includes="submodels/**/*" />
</copy>
<!-- use the production Log4J properties, unless a debug version exists. -->
<available file="${webapp.dir}/config/debug.log4j.properties"
property="debug.log4j.exists" />
<copy tofile="${war-classes.dir}/log4j.properties" filtering="true" overwrite="true">
<fileset dir="${webapp.dir}/config">
<include name="default.log4j.properties" unless="debug.log4j.exists" />
<include name="debug.log4j.properties" if="debug.log4j.exists" />
</fileset>
<filterchain>
<expandproperties />
</filterchain>
</copy>
<!-- copy the deploy.properties into the war directory -->
<copy todir="${war-classes.dir}">
<fileset file="${deploy.properties.file}" />
</copy>
<!-- copy the custom tag libraries into the war directory -->
<copy todir="${war-webinf.dir}/tlds">
<fileset dir="${webapp.dir}/config/tlds" includes="**/*" excludes="*.LCK" />
</copy>
<!-- TODO Get rid of these webservices files -->
<copy todir="${war-webinf.dir}/lib">
<fileset dir="${webapp.dir}/../services/lib" includes="**/*" excludes="*.LCK" />
</copy>
<copy todir="${build.dir}/war">
<fileset dir="${webapp.dir}/../services/additions" includes="**/*" />
</copy>
<!-- TODO Get rid of these webservices files -->
<!-- copy any xml files from source tree to the war directory -->
<copy todir="${build.dir}/war/WEB-INF/classes">
<fileset dir="${webapp.dir}/src" includes="**/*.xml" />
</copy>
<!-- copy the JARs into the war directory -->
<copy todir="${war-lib.dir}">
<fileset dir="${webapp.dir}/lib">
<!-- these are already in Tomcat: we mustn't conflict. -->
<exclude name="jsp-api.jar" />
<exclude name="servlet-api.jar" />
</fileset>
</copy>
<!-- copy the servlet JARs into their own directory, to compile against. -->
<copy todir="${servletjars.dir}">
<fileset dir="${webapp.dir}/lib">
<include name="jsp-api.jar" />
<include name="servlet-api.jar" />
</fileset>
</copy>
<!-- copy the context file into the war directory -->
<copy file="${webapp.dir}/context.xml" tofile="${war.dir}/META-INF/context.xml" />
</target>
<!-- =================================
@ -139,14 +216,14 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
<target name="compile" depends="prepare" description="--> Compile Java sources">
<!-- deletes all files that depend on changed .java files -->
<depend srcdir="${webapp.dir}/src"
destdir="${build.dir}/war/WEB-INF/classes"
destdir="${war-classes.dir}"
closure="false"
cache="${build.dir}/.depcache">
<classpath refid="compile.classpath" />
</depend>
<javac srcdir="${webapp.dir}/src"
destdir="${build.dir}/war/WEB-INF/classes"
destdir="${war-classes.dir}"
debug="true"
deprecation="true"
optimize="true"
@ -160,7 +237,7 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
================================= -->
<target name="test" depends="compile" unless="skiptests" description="--> Run JUnit tests">
<javac srcdir="${webapp.dir}/test"
destdir="${build.dir}/testclasses"
destdir="${test-classes.dir}"
debug="true"
deprecation="true"
optimize="false"
@ -177,109 +254,16 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
</java>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: copyEtc
- - - - - - - - - - - - - - - - - -->
<target name="copyEtc" depends="test">
<copy todir="${build.dir}/war">
<fileset dir="${webapp.dir}/web">
<!--
If a product doesn't want the core themes, it can
set this property and they will be skipped.
-->
<exclude name="themes/**/*" if="skip.core.themes" />
</fileset>
</copy>
<copy todir="${build.dir}/war/WEB-INF">
<fileset file="${webapp.dir}/config/web.xml" />
<fileset file="${webapp.dir}/config/dwr.xml" />
</copy>
<copy todir="${build.dir}/war/WEB-INF">
<fileset dir="${webapp.dir}" includes="ontologies" />
<fileset dir="${webapp.dir}" includes="ontologies/**/*" />
<fileset dir="${webapp.dir}" includes="submodels" />
<fileset dir="${webapp.dir}" includes="submodels/**/*" />
</copy>
<!-- use the production Log4J properties, unless a debug version exists. -->
<available file="${webapp.dir}/config/debug.log4j.properties"
property="debug.log4j.exists" />
<copy tofile="${build.dir}/war/WEB-INF/classes/log4j.properties"
filtering="true"
overwrite="true">
<fileset dir="${webapp.dir}/config">
<include name="default.log4j.properties" unless="debug.log4j.exists" />
<include name="debug.log4j.properties" if="debug.log4j.exists" />
</fileset>
<filterchain>
<expandproperties />
</filterchain>
</copy>
<copy todir="${build.dir}/war/WEB-INF/classes">
<fileset file="${deploy.properties.file}" />
</copy>
<copy todir="${build.dir}/war/WEB-INF/tlds">
<fileset dir="${webapp.dir}/config/tlds" includes="**/*" excludes="*.LCK" />
</copy>
<!-- TODO Get rid of these webservices files -->
<copy todir="${build.dir}/war/WEB-INF/lib">
<fileset dir="${vitroCore.basedir}/../services/lib" includes="**/*" excludes="*.LCK" />
</copy>
<copy todir="${build.dir}/war">
<fileset dir="${vitroCore.basedir}/../services/additions" includes="**/*" />
</copy>
<!-- TODO Get rid of these webservices files -->
<!-- xml files from src tree -->
<copy todir="${build.dir}/war/WEB-INF/classes">
<fileset dir="${webapp.dir}/src" includes="**/*.xml" />
</copy>
<copy todir="${build.dir}/war/WEB-INF/lib">
<fileset dir="${webapp.dir}/lib">
<!-- these are already in Tomcat: we shouldn't conflict. -->
<exclude name="jsp-api.jar" />
<exclude name="servlet-api.jar" />
</fileset>
</copy>
<copy file="${webapp.dir}/context.xml" tofile="${build.dir}/war/META-INF/context.xml" />
</target>
<!-- =================================
target: deploy
================================= -->
<target name="deploy" depends="copyEtc" description="--> Build the app and install in Tomcat">
<target name="deploy" depends="test" description="--> Build the app and install in Tomcat">
<property name="webapp.deploy.home" value="${tomcat.home}/webapps/${webapp.name}" />
<mkdir dir="${webapp.deploy.home}" />
<copy todir="${webapp.deploy.home}">
<sync todir="${webapp.deploy.home}" includeemptydirs="true">
<fileset dir="${build.dir}/war" />
</copy>
<!-- Discard any ontology files from previous builds. -->
<sync todir="${webapp.deploy.home}/WEB-INF/ontologies"
includeEmptyDirs="true"
failonerror="false">
<fileset dir="${build.dir}/war/WEB-INF/ontologies" includes="**/*" />
</sync>
<!-- Discard any submodel files from previous builds. -->
<sync todir="${webapp.deploy.home}/WEB-INF/submodels"
includeemptydirs="true"
failonerror="false">
<fileset dir="${build.dir}/war/WEB-INF/submodels" includes="**/*" />
</sync>
<!-- Discard any template files from previous builds. -->
<sync todir="${webapp.deploy.home}/themes" includeemptydirs="true" failonerror="false">
<fileset dir="${build.dir}/war/themes" includes="**/*" />
</sync>
</target>

View file

@ -21,15 +21,21 @@
It should be invoked from the build script of a Vivo product.
</fail>
<!-- - - - - - - - - - - - - - - - - -
properties
<fail unless="inner.basedir"
message="The build script for the product must define a value for inner.basedir" />
<!--
The build directory goes in the product directory.
Everything else hangs from the build directory.
-->
<property name="build.dir" location="./.build" />
<property name="war.dir" location="${build.dir}/war" />
<property name="war-webinf.dir" location="${war.dir}/WEB-INF" />
<property name="war-classes.dir" location="${war-webinf.dir}/classes" />
<property name="war-lib.dir" location="${war-webinf.dir}/lib" />
<property name="test-classes.dir" location="${build.dir}/testclasses" />
<property name="servletjars.dir" location="${build.dir}/servletjars" />
File paths are based on this file's parent directory, so we can find
the files even when this script is included into an individual
Product build script.
- - - - - - - - - - - - - - - - - -->
<dirname property="vivoProduct.basedir" file="${ant.file.vivoProduct}" />
<import file="${vivoProduct.basedir}/build.xml" />
<!-- Is there a "src" directory in the product? -->
<property name="product.source.dir" location="./src" />
@ -47,47 +53,34 @@
<property name="product.modifications.dir" location="./modifications" />
<available property="product.modifications.exist" file="${product.modifications.dir}" />
<!-- If there is a WEB-INF/lib in the mods directory, it goes into the compile classpath -->
<!-- Otherwise, use a real directory but disable the "include" in the fileset -->
<available property="product.mods.lib.exists" file="${product.modifications.dir}/WEB-INF/lib" />
<condition property="product.mods.lib.dir"
value="${product.modifications.dir}/WEB-INF/lib"
else="${webapp.dir}/lib">
<available file="${product.modifications.dir}/WEB-INF/lib" />
</condition>
<path id="product.compile.classpath">
<pathelement location="${classes.dir}" />
<!-- These come before the core classpath, so our local mods can override -->
<fileset dir="${product.mods.lib.dir}">
<include name="**/*.jar" if="product.mods.lib.exists" />
<!-- - - - - - - - - - - - - - - - - -
paths: for compiling and running
- - - - - - - - - - - - - - - - - -->
<path id="compile.classpath">
<fileset dir="${war-lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${servletjars.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="test.compile.classpath">
<pathelement location="${war-classes.dir}" />
<path refid="compile.classpath" />
</path>
<path id="product.test.compile.classpath">
<path id="test.run.classpath">
<pathelement location="${test-classes.dir}" />
<path refid="test.compile.classpath" />
</path>
<path id="product.test.run.classpath">
<path refid="test.run.classpath" />
</path>
<!-- =================================
target: describe
================================= -->
<target name="describe" description="--> Describe the targets (this is the default).">
<echo>
all - Runs "clean", then "deploy".
clean - Delete all artifacts so the next build will be from scratch.
compile - Compile the Java source files.
test - Compile and run the JUnit tests.
war - Assemble everything into a deployable WAR file.
deploy - Deploy the application directly into the Tomcat webapps directory.
</echo>
<innercall target="describe" />
</target>
<!-- =================================
@ -98,91 +91,111 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
<!-- =================================
target: clean
================================= -->
<target name="clean" depends="vitroCore.clean" description="--> Delete all artifacts.">
</target>
<!-- =================================
target: compile
================================= -->
<target name="compile"
depends="vitroCore.compile, productCompile"
description="--> Compile Java sources.">
</target>
<!-- =================================
target: test
================================= -->
<target name="test"
depends="vitroCore.test, productTest"
unless="skiptests"
description="--> Run JUnit tests">
</target>
<!-- =================================
target: deploy
================================= -->
<target name="deploy"
depends="productCopy, vitroCore.deploy"
description="--> Build the app and install in Tomcat">
<target name="clean" description="--> Delete all artifacts.">
<innercall target="clean" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: productCopy
target: productPrepare
- - - - - - - - - - - - - - - - - -->
<target name="productCopy" depends="copyEtc, test">
<target name="productPrepare">
<antcall target="prepareThemes" />
<antcall target="prepareModifications" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: prepareThemes
- - - - - - - - - - - - - - - - - -->
<target name="prepareThemes" if="product.themes.exist">
<copy todir="${build.dir}/war/themes" overwrite="true">
<fileset dir="${product.themes.dir}" />
</copy>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: prepareModifications
- - - - - - - - - - - - - - - - - -->
<target name="prepareModifications" if="product.modifications.exist">
<copy todir="${build.dir}/war" overwrite="true">
<fileset dir="${product.modifications.dir}" />
</copy>
</target>
<!-- =================================
target: compile
================================= -->
<target name="compile" description="--> Compile Java sources.">
<innercall target="compile" />
<antcall target="productCompile" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: productCompile
- - - - - - - - - - - - - - - - - -->
<target name="productCompile" depends="vitroCore.compile" if="product.sources.exist">
<!-- deletes all files that depend on changed .java files -->
<depend srcdir="${product.source.dir}"
destdir="${build.dir}/war/WEB-INF/classes"
closure="false"
cache="${build.dir}/.depcache">
<classpath refid="product.compile.classpath" />
</depend>
<target name="productCompile" depends="productPrepare" if="product.sources.exist">
<javac srcdir="${product.source.dir}"
destdir="${build.dir}/war/WEB-INF/classes"
debug="true"
deprecation="true"
optimize="true"
source="1.5">
<classpath refid="product.compile.classpath" />
source="1.6">
<classpath refid="compile.classpath" />
</javac>
</target>
<!-- =================================
target: test
================================= -->
<target name="test" unless="skiptests" description="--> Run JUnit tests">
<innercall target="test" />
<antcall target="productTest" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: productTest
- - - - - - - - - - - - - - - - - -->
<target name="productTest" depends="vitroCore.test" if="product.tests.exist" unless="skiptests">
<target name="productTest" depends="productCompile" if="product.tests.exist" unless="skiptests">
<javac srcdir="${product.test.dir}"
destdir="${test.classes.dir}"
debug="true"
deprecation="true"
optimize="false"
source="1.5">
<classpath refid="product.test.compile.classpath" />
source="1.6">
<classpath refid="test.compile.classpath" />
</javac>
<java classname="edu.cornell.mannlib.vitro.testing.VitroTestRunner"
fork="yes"
failonerror="true">
<classpath refid="product.test.run.classpath" />
<classpath refid="test.run.classpath" />
<arg file="${product.test.dir}" />
<arg value="${testlevel}" />
</java>
</target>
<!-- =================================
target: deploy
================================= -->
<target name="deploy" description="--> Build the app and install in Tomcat">
<!-- the inner "deploy" would just do a sync that will be done by productDeploy -->
<innercall target="test" />
<antcall target="productDeploy" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: productDeploy
- - - - - - - - - - - - - - - - - -->
<target name="productDeploy" depends="productTest">
<property name="webapp.deploy.home" value="${tomcat.home}/webapps/${webapp.name}" />
<mkdir dir="${webapp.deploy.home}" />
<sync todir="${webapp.deploy.home}" includeemptydirs="true">
<fileset dir="${build.dir}/war" />
</sync>
</target>
<!-- =================================
target: licenser
@ -194,15 +207,43 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
================================= -->
<target name="licenser" description="--> Check source files for licensing tags">
<!-- Once for the product... -->
<antcall target="vitroCore.licenser">
<param name="licenser.properties.file" value="${licenser.product.properties.file}" />
<param name="licenser.label" value="${ant.project.name}" />
</antcall>
<innercall target="licenser">
<property name="licenser.properties.file" value="${licenser.product.properties.file}" />
<property name="licenser.label" value="${ant.project.name}" />
</innercall>
<!-- ...and once for the core. -->
<condition property="licenser.properties.file" value="${licenser.core.properties.file}">
<isset property="licenser.core.properties.file" />
</condition>
<antcall target="vitroCore.licenser" />
<innercall target="licenser">
<propertyset>
<propertyref name="licenser.properties.file" />
</propertyset>
</innercall>
</target>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MACROS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--
Call a target in the inner script.
-->
<macrodef name="innercall">
<attribute name="target" />
<element name="additionalProperties" implicit="yes" optional="true" />
<sequential>
<ant dir="${inner.basedir}" inheritall="false">
<!-- pass the properties that are needed. -->
<propertyset>
<propertyref name="build.dir" />
<propertyref name="skip.core.themes" />
<propertyref name="deploy.properties.file" />
</propertyset>
<additionalProperties />
<target name="@{target}" />
</ant>
</sequential>
</macrodef>
</project>