vitro/webapp/build.xml

405 lines
15 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<!-- ======================================================================
Build script for the Vitro core webapp.
This can be used on its own, or invoked from a Product build script.
====================================================================== -->
<project name="vitroCore" default="describe">
<!-- - - - - - - - - - - - - - - - - -
properties
- - - - - - - - - - - - - - - - - -->
<dirname property="corebase.dir" file="${ant.file.vitroCore}" />
<!-- A product script will override appbase.dir, but not corebase.dir -->
<property name="appbase.dir" location="${corebase.dir}" />
<property name="build.dir" location=".build" />
<property name="deploy.properties.file" location="config/deploy.properties" />
<property name="utilities.base.dir" location="${corebase.dir}/../utilities/buildutils" />
<property name="utilities.source.dir" location="${utilities.base.dir}/src" />
<property name="utilities.lib.dir" location="${utilities.base.dir}/lib" />
<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.resources.dir" location="${war.webinf.dir}/resources" />
<property name="revisionInfo.build.file" location="${war.resources.dir}/revisionInfo.txt" />
<property name="test.classes.dir" location="${build.dir}/testClasses" />
<property name="utility.classes.dir" location="${build.dir}/utilityClasses" />
<property name="javac.deprecation" value="true" />
<!-- - - - - - - - - - - - - - - - - -
paths: for compiling and running
- - - - - - - - - - - - - - - - - -->
<path id="compile.classpath">
<fileset dir="${appbase.dir}/lib" includes="*.jar" />
</path>
<path id="utility.compile.classpath">
<fileset dir="${utilities.lib.dir}" includes="*.jar" />
</path>
<path id="utility.run.classpath">
<pathelement location="${utility.classes.dir}" />
<path refid="utility.compile.classpath" />
</path>
<path id="test.compile.classpath">
<pathelement location="${war.classes.dir}" />
<path refid="compile.classpath" />
</path>
<path id="test.run.classpath">
<pathelement location="${appbase.dir}/test" />
<pathelement location="${test.classes.dir}" />
<path refid="test.compile.classpath" />
<path refid="utility.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 - Create a WAR file to be deployed in a servlet container.
deploy - Deploy the application directly into the Tomcat webapps directory.
</echo>
</target>
<!-- =================================
target: all
================================= -->
<target name="all" depends="clean, deploy" description="--> Run 'clean', then 'deploy'" />
<!-- - - - - - - - - - - - - - - - - -
target: properties
- - - - - - - - - - - - - - - - - -->
<target name="properties">
<fail message="You must create a &quot;${deploy.properties.file}&quot; file.">
<condition>
<not>
<available file="${deploy.properties.file}" />
</not>
</condition>
</fail>
<property file="${deploy.properties.file}" />
<fail unless="tomcat.home"
message="${deploy.properties.file} must contain a value for tomcat.home" />
<fail unless="webapp.name"
message="${deploy.properties.file} must contain a value for webapp.name" />
<fail unless="vitro.home.directory"
message="${deploy.properties.file} must contain a value for vitro.home.directory" />
<fail unless="Vitro.defaultNamespace"
message="${deploy.properties.file} must contain a value for Vitro.defaultNamespace" />
<fail unless="VitroConnection.DataSource.url"
message="${deploy.properties.file} must contain a value for VitroConnection.DataSource.url" />
<fail unless="VitroConnection.DataSource.username"
message="${deploy.properties.file} must contain a value for VitroConnection.DataSource.username" />
<fail unless="VitroConnection.DataSource.password"
message="${deploy.properties.file} must contain a value for VitroConnection.DataSource.password" />
<fail unless="rootUser.emailAddress"
message="${deploy.properties.file} must contain a value for rootUser.emailAddress" />
<fail message="The vitro.home.directory &quot;${vitro.home.directory}&quot; does not exist.">
<condition>
<not>
<available file="${vitro.home.directory}" />
</not>
</condition>
</fail>
<property name="solr.home.dir" location="${vitro.home.directory}/solr" />
</target>
<!-- =================================
target: clean
================================= -->
<target name="clean" depends="properties" description="--> Delete all artifacts.">
<delete dir="${build.dir}" />
<delete dir="${solr.home.dir}" excludes="data/**/*" includeemptydirs="true" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: compileUtilities
- - - - - - - - - - - - - - - - - -->
<target name="compileUtilities">
<mkdir dir="${utility.classes.dir}" />
<javac srcdir="${utilities.source.dir}"
destdir="${utility.classes.dir}"
debug="true"
deprecation="${javac.deprecation}"
encoding="UTF8"
includeantruntime="false"
optimize="false"
source="1.6">
<classpath refid="utility.compile.classpath" />
</javac>
<typedef name="dirDifference"
classname="edu.cornell.mannlib.vitro.utilities.anttasks.DirDifferenceFileSet"
classpathref="utility.run.classpath" />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: prepare
- - - - - - - - - - - - - - - - - -->
<target name="prepare" depends="properties, compileUtilities">
<mkdir dir="${build.dir}" />
<mkdir dir="${war.classes.dir}" />
<mkdir dir="${war.resources.dir}" />
<mkdir dir="${test.classes.dir}" />
<!-- copy all sorts of web stuff into the war directory. -->
<copy todir="${war.dir}">
<fileset dir="${appbase.dir}/web" />
<fileset dir="${appbase.dir}" includes="themes/**/*" />
</copy>
<copy todir="${war.webinf.dir}">
<fileset dir="${appbase.dir}">
<!-- copy the JARs into the war directory -->
<include name="lib/*" />
<!-- these are already in Tomcat: we mustn't conflict. -->
<exclude name="lib/jsp-api.jar" />
<exclude name="lib/servlet-api.jar" />
</fileset>
</copy>
<!-- use the production Log4J properties, unless a debug version exists. -->
<available file="${appbase.dir}/config/debug.log4j.properties"
property="debug.log4j.exists" />
<copy tofile="${war.classes.dir}/log4j.properties" filtering="true" overwrite="true">
<fileset dir="${appbase.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="${war.classes.dir}">
<!-- copy the deploy.properties into the war directory -->
<fileset file="${deploy.properties.file}" />
<!-- copy any xml files from source tree to the war directory -->
<fileset dir="${appbase.dir}/src" includes="**/*.xml" />
</copy>
<!-- copy the context file into the war directory -->
<copy file="${appbase.dir}/context.xml" tofile="${war.dir}/META-INF/context.xml" />
</target>
<!-- =================================
target: compile
================================= -->
<target name="compile" depends="prepare" description="--> Compile Java sources">
<!-- deletes all files that depend on changed .java files -->
<depend srcdir="${appbase.dir}/src"
destdir="${war.classes.dir}"
closure="false"
cache="${build.dir}/.depcache">
<classpath refid="compile.classpath" />
</depend>
<javac srcdir="${appbase.dir}/src"
destdir="${war.classes.dir}"
debug="true"
deprecation="${javac.deprecation}"
encoding="UTF8"
includeantruntime="false"
optimize="true"
source="1.6">
<classpath refid="compile.classpath" />
</javac>
</target>
<!-- =================================
target: test
================================= -->
<target name="test" depends="compile" unless="skiptests" description="--> Run JUnit tests">
<javac srcdir="${appbase.dir}/test"
destdir="${test.classes.dir}"
debug="true"
deprecation="${javac.deprecation}"
encoding="UTF8"
includeantruntime="false"
optimize="false"
source="1.6">
<classpath refid="test.compile.classpath" />
</javac>
<java classname="edu.cornell.mannlib.vitro.utilities.testing.VitroTestRunner"
fork="yes"
failonerror="true">
<classpath refid="test.run.classpath" />
<arg file="${appbase.dir}/test" />
<arg value="${testlevel}" />
</java>
</target>
<!-- =================================
target: jar
================================= -->
<target name="jar" depends="test" description="--> Compile the Java, and build a JAR file">
<jar basedir="${war.classes.dir}" destfile="${build.dir}/${ant.project.name}.jar" />
</target>
<!-- =================================
target: revisionInfo
================================= -->
<target name="revisionInfo"
depends="test"
unless="skipinfo"
description="--> Store revision info in build">
<tstamp>
<format property="revisionInfo.timestamp" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo file="${revisionInfo.build.file}">${revisionInfo.timestamp}
</echo>
<addRevisionInfoLine productName="vitroCore" productCheckoutDir="${corebase.dir}/.." />
</target>
<!-- - - - - - - - - - - - - - - - - -
target: prepareSolr
- - - - - - - - - - - - - - - - - -->
<target name="prepareSolr" depends="properties">
<property name="solr.distrib.dir" location="${corebase.dir}/../solr" />
<property name="solr.example.dir" location="${solr.distrib.dir}/exampleSolr" />
<property name="solr.context.config.example"
location="${solr.distrib.dir}/exampleSolrContext.xml" />
<property name="solr.war" location="${solr.distrib.dir}/apache-solr-3.1.0.war" />
<property name="solr.docbase" location="${solr.home.dir}/solr.war" />
<property name="solr.context.name" value="${webapp.name}solr" />
<property name="solr.context.config" location="${solr.home.dir}/${solr.context.name}.xml" />
<!-- Create and copy the example directory to the solr.home.dir directory. -->
<mkdir dir="${solr.home.dir}" />
<copy todir="${solr.home.dir}">
<fileset dir="${solr.example.dir}" includes="**/*" />
</copy>
<!-- Add the war file. -->
<copy tofile="${solr.docbase}">
<fileset file="${solr.war}" />
</copy>
<war destfile="${solr.docbase}" update="true">
<classes dir="${appbase.dir}/config/solr/" />
</war>
<!-- if no mask is define, go with an unsecured installation. -->
<property name="vitro.local.solr.ipaddress.mask" value=".*" />
<!-- Create the context configuration XML with expanded properties. -->
<copy tofile="${solr.context.config}" filtering="true">
<fileset file="${solr.context.config.example}" />
<filterchain>
<expandproperties />
</filterchain>
</copy>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: deploySolr
- - - - - - - - - - - - - - - - - -->
<target name="deploySolr" depends="prepareSolr" unless="noSolrDeploy">
<unwar src="${solr.docbase}" dest="${tomcat.home}/webapps/${solr.context.name}" />
<copy todir="${tomcat.home}/conf/Catalina/localhost" overwrite="true">
<fileset file="${solr.context.config}" />
</copy>
</target>
<!-- =================================
target: deploy
================================= -->
<target name="deploy"
depends="revisionInfo, deploySolr"
description="--> Build the app and install in Tomcat">
<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: war
================================= -->
<target name="war" depends="revisionInfo" description="--> Build the app and create a WAR file">
<jar basedir="${build.dir}/war" destfile="${build.dir}/${webapp.name}.war" />
</target>
<!-- =================================
target: licenser
In regular use, checks that all appropriate source files have license tags.
At release time, applies license text to source files.
================================= -->
<target name="licenser" description="--> Check source files for licensing tags">
<property name="licenser.properties.file"
location="${corebase.dir}/config/licenser/licenser.properties" />
<runLicenserScript productname="Vitro core" propertiesfile="${licenser.properties.file}" />
</target>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MACROS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--
Run the licenser script.
-->
<macrodef name="runLicenserScript">
<attribute name="productName" />
<attribute name="propertiesFile" />
<sequential>
<echo message="Checking license tags on @{productName}" />
<exec executable="ruby" dir="${corebase.dir}/../utilities/licenser" failonerror="true">
<arg value="licenser.rb" />
<arg value="@{propertiesFile}" />
<redirector outputproperty="licenser.test.output" alwayslog="true" />
</exec>
</sequential>
</macrodef>
<!--
Add a line to the revisionInfo file.
-->
<macrodef name="addRevisionInfoLine">
<attribute name="productName" />
<attribute name="productCheckoutDir" />
<sequential>
<java classname="edu.cornell.mannlib.vitro.utilities.revisioninfo.RevisionInfoBuilder"
fork="no"
failonerror="true">
<classpath refid="utility.run.classpath" />
<arg value="@{productName}" />
<arg file="@{productCheckoutDir}" />
<arg file="${revisionInfo.build.file}" />
</java>
</sequential>
</macrodef>
</project>