openjpa/openjpa-examples/openbooks/build.xml

209 lines
8.5 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!-- ====================================================================== -->
<!-- -->
<!-- Ant build script for OpenBooks -->
<!-- -->
<!-- ====================================================================== -->
<project name="OpenBooks" default="package">
<!-- ================================================================== -->
<property file="build.properties" />
<!-- ================================================================== -->
<property name="jpa.provider" value="openjpa" />
<!-- ================================================================== -->
<property name="build.mode" value="jse"/>
<!-- ================================================================== -->
<!-- root directory of Java Source files -->
<property name="src.dir" value="${basedir}/src/main/java"/>
<!-- ================================================================== -->
<!-- root directory of JSP and other web content files -->
<property name="web.dir" value="${basedir}/web"/>
<!-- ================================================================== -->
<!-- root directory of resource files e.g web.xml or persistence.xml -->
<property name="rsrc.dir" value="${basedir}/src/main/resources"/>
<!-- ================================================================== -->
<!-- JPA configuration file anchored by the persistence unit name -->
<property name="jpa.properties" value="META-INF/persistence.xml#OpenBooks"/>
<!-- ================================================================== -->
<!-- ================================================================== -->
<!-- Root directory of all derived artifacts -->
<property name="target.dir" value="${basedir}/target"/>
<!-- ================================================================== -->
<!-- root directory of compiled class files -->
<property name="classes.dir" value="${target.dir}/classes"/>
<!-- ================================================================== -->
<!-- root directory of generated canonical meta-model source files -->
<property name="generated.src.dir" value="${target.dir}/generated-sources/java"/>
<!-- ================================================================== -->
<!-- root directory of generated html for Java source files -->
<property name="generated.html.dir" value="${target.dir}/source"/>
<!-- ================================================================== -->
<!-- directory for deployable artifacts -->
<property name="deploy.dir" value="${target.dir}/openbooks"/>
<!-- ================================================================== -->
<path id="compile.classpath"
description="Compilation classpath requires OpenJPA specific library because of bytecode enhancement">
<pathelement location="${src.dir}" />
<pathelement location="${classes.dir}" />
<pathelement location="${rsrc.dir}" />
<fileset dir="${openjpa.lib}">
<include name="*.jar" />
</fileset>
</path>
<path id="java2html.classpath"
description="Classpath for generating HTML version of source code using Java2HTML library">
<pathelement location="${rsrc.dir}" />
<fileset dir="${java2html.lib}">
<include name="*.jar" />
</fileset>
</path>
<fileset id="canonical.metamodel" dir="${src.dir}"
description="Set of *.java files generated for static, cannonical domain model">
<include name="**/*_.java"/>
</fileset>
<target name="clean" description="Removes all *.class and generated metamodel source files">
<delete dir="${target.dir}" failonerror="false"/>
<delete>
<fileset refid="canonical.metamodel"/>
</delete>
</target>
<target name="info"
description="Prints environmental variables">
<echo>
Builds OpenBooks demo application.
OpenJPA Library: ${openjpa.lib}
Build mode : ${build.mode}
Deploy Location: ${deploy.dir}
</echo>
</target>
<target name="check-env"
description="Checks if required libraries exist"
depends="info">
<available file="${openjpa.lib}" property="openjpa.exists"/>
<fail unless="openjpa.exists">*** Error:
The directory for OpenJPA libraries can not be located at ${openjpa.lib}.
Make sure openjpa.lib property value is correct in build.properties file.
</fail>
<available file="${java2html.lib}" property="java2html.exists"/>
<fail unless="java2html.exists">*** Error:
The directory for Java2HTML libraries can not be located at ${java2html.lib}.
Make sure java2html.lib property value is correct in build.properties file.
</fail>
<condition property="build.mode.is.valid">
<or>
<equals arg1="${build.mode}" arg2="jse" casesensitive="false" trim="true"/>
<equals arg1="${build.mode}" arg2="jee" casesensitive="false" trim="true"/>
</or>
</condition>
<fail unless="build.mode.is.valid" message="Invalid build.mode ${build.mode}"/>
<condition property="build.mode.is.jse">
<equals arg1="${build.mode}" arg2="jse" casesensitive="true" trim="true"/>
</condition>
<condition property="build.mode.is.jee">
<equals arg1="${build.mode}" arg2="jee" casesensitive="true" trim="true"/>
</condition>
<mkdir dir="${deploy.dir}"/>
</target>
<target name="generate-canonical-model" depends="check-env"
description="Generate canonical meta-model source">
<mkdir dir="${generated.src.dir}" />
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true">
<classpath refid="compile.classpath" />
<include name="openbook/domain/*.java"/>
<compilerarg value="-Aopenjpa.metamodel=true" />
<compilerarg value="-Aopenjpa.log=TRACE" />
<compilerarg value="-s"/>
<compilerarg value="${generated.src.dir}" />
</javac>
</target>
<target name="compile" depends="generate-canonical-model"
description="Compile classes.">
<subant antfile="build.${build.mode}.xml"
target="compile"
inheritrefs="true"
inheritall="true"
buildpath="${basedir}"/>
</target>
<target name="enhance" depends="check-env"
description="Enhance persistent domain classes.">
<java classname="org.apache.openjpa.enhance.PCEnhancer" fork="true">
<arg value="-properties" />
<arg value="${jpa.properties}" />
<classpath refid="compile.classpath" />
</java>
</target>
<target name="package" description="Build and Package based on JSE or JEE mode"
depends="check-env,
clean,
generate-canonical-model,
compile,
enhance,
generate-html-source">
<subant antfile="build.${build.mode}.xml"
target="package"
inheritrefs="true"
inheritall="true"
buildpath="${basedir}"/>
</target>
<target name="generate-html-source" if="java2html.exists"
description="Generates HTML Source Code using Java2HTML utility">
<delete dir="${generated.html.dir}" failonerror="false"/>
<mkdir dir="${generated.html.dir}"/>
<java classname="de.java2html.Java2Html" fork="true">
<classpath refid="java2html.classpath"/>
<arg value="-srcdir"/>
<arg value="${src.dir}"/>
<arg value="-targetdir"/>
<arg value="${generated.html.dir}"/>
<arg value="-style"/>
<arg value="Eclipse"/>
</java>
<java classname="de.java2html.Java2Html" fork="true">
<classpath refid="java2html.classpath"/>
<arg value="-srcdir"/>
<arg value="${generated.src.dir}"/>
<arg value="-targetdir"/>
<arg value="${generated.html.dir}"/>
<arg value="-style"/>
<arg value="Eclipse"/>
</java>
<replace dir="${generated.html.dir}" token="10pt" value="14pt">
</replace>
</target>
</project>