blob: 1dac549b0bba417ed8ab3290410074d66c840582 [file] [log] [blame] [edit]
<!--/*******************************************************************************
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Ant naming conventions:
* - regardless of the actual OS platform,'/' is the directory separator
* (Ant will convert as appropriate).
* - multi-word properties use periods '.'
* - properties ending in .jar define jarfile names only (no path)
* - properties ending in .lib are fully qualified jars (path and filename)
* - properties ending in .dir are directory paths
* - properties ending in .path are path refid names (classpath fragments)
* - multi-word targets use hyphens '-'
* - targets beginning with test- are reserved for high level test targets,
* and are used in test results parsing
* - targets typically use the form <action>-<object>-<type> (ie. package-bundle-zip)
* - multi-word macros use underscores '_'
* - multi-word macro attributes are concatenated
* e.g. 'runpathref'
* - multi-word tasks (taskdef) names are concatenated
* e.g. 'validateconnection'
* - OS environment variables are in ALLCAPS and have 'env' as a prefix
* e.g. ${env.XXX}.
* - Ant properties are lower case.
*
* Contributors:
* egwin - initial API and implementation
#******************************************************************************/-->
<!---
For each oracle project
Find out if current checkin is latest hash
find current hash
find checked in hash
compare hash if != mark for build
if build=true
set build arguments
build
checkin results
-->
<project name="oraclebuild" default="build" basedir=".">
<!-- Default ant target, compiles and translates resources, does not run tests. -->
<target name="build" depends="clean-oracle, build-oracle, build-nosql"/>
<target name="process-control" depends="build, commit-oracle, commit-nosql, validate-commits"/>
<target name="init">
<!-- The following variables should be passed from Hudson:
env.JAVA_HOME - JAVA_HOME as defined by Hudson
git.exec - fully qualified path to git executable
hudson.workspace- WORKSPACE as defined by the Hudson slave
M2_HOME - location of Maven3 install (on build server)
branch - name of Git branch (master, 2.3, 2.4, 2.5, etc)
However, just in case default values are set:
-->
<property name="git.exec" value="/usr/bin/git"/>
<property name="branch" value="2.5"/>
<echo message=" "/>
<echo message="os.name = '${os.name}'"/>
<echo message="os.arch = '${os.arch}'"/>
<echo message="os.version = '${os.version}'"/>
<echo message=" ---"/>
<echo message="env.JAVA_HOME = '${env.JAVA_HOME}'"/>
<echo message="git.exec = '${git.exec}'"/>
<echo message="hudson.workspace= '${hudson.workspace}'"/>
<echo message="M2_HOME = '${M2_HOME}'"/>
<echo message="branch = '${branch}'"/>
<echo message=" ---"/>
<tstamp>
<format property="oraclebuild.build.date" pattern="yyyyMMdd"/>
<format property="oraclebuild.build.time" pattern="HHmm"/>
</tstamp>
<echo message="oraclebuild.build.date = '${oraclebuild.build.date}'"/>
<echo message="oraclebuild.build.time = '${oraclebuild.build.time}'"/>
<echo message=" ---"/>
<!-- Convert basedir to *nix format to avoid pathing issues with certain commands -->
<dirname property="oraclebuild.build.location_temp" file="${ant.file.oraclebuild}"/>
<pathconvert targetos="unix" property="oraclebuild.build.location">
<path>
<pathelement location="${oraclebuild.build.location_temp}"/>
</path>
</pathconvert>
<!-- oraclelibs.2.base.dir needs to be explicit (not relative) for antcall usage -->
<property name="oraclebuild.2.base.dir" value="${oraclebuild.build.location}"/>
<property name="oraclebuild.2.buildsystem.dir" value="${oraclebuild.build.location}/buildsystem"/>
<property name="oraclebuild.2.common.plugins.dir" value="${oraclebuild.2.base.dir}/plugins"/>
<property name="oraclebuild.2.nosql.dir" value="${oraclebuild.2.base.dir}/foundation/org.eclipse.persistence.nosql"/>
<property name="oraclebuild.2.oracle.dir" value="${oraclebuild.2.base.dir}/foundation/org.eclipse.persistence.oracle"/>
<property name="oraclebuild.2.oracle.nosql.dir" value="${oraclebuild.2.base.dir}/foundation/org.eclipse.persistence.oracle.nosql"/>
<echo message="ant.project.name = '${ant.project.name}'"/>
<echo message="basedir = '${basedir}'"/>
<echo message="oraclebuild.build.location = '${oraclebuild.build.location}'"/>
<echo message="oraclebuild.2.base.dir = '${oraclebuild.2.base.dir}'"/>
<echo message="oraclebuild.2.common.plugins.dir= '${oraclebuild.2.common.plugins.dir}'"/>
<echo message="oraclebuild.2.nosql.dir = '${oraclebuild.2.nosql.dir}'"/>
<echo message="oraclebuild.2.oracle.dir = '${oraclebuild.2.oracle.dir}'"/>
<echo message="oraclebuild.2.oracle.nosql.dir = '${oraclebuild.2.oracle.nosql.dir}'"/>
<echo message=" ---"/>
<condition property="custom.properties.message" value="Loading user defined properties from: '${user.home}/build.properties'"
else="No custom properties file at '${user.home}/build.properties'. Continuing build using defaults.">
<available file="${user.home}/build.properties"/>
</condition>
<echo message="${custom.properties.message}"/>
<property file="${user.home}/build.properties"/>
<echo message=" "/>
<property file="${oraclebuild.2.base.dir}/antbuild.properties"/>
<property name="oraclebuild.target" value="build-oracle-extension"/>
<!-- Sets default for all extensions.depend dir locations to static paths -->
<property name="oracle.extensions.depend.dir" value="${oraclebuild.2.base.dir}/../extension.oracle.lib.external"/>
<echo message="oracle.extensions.depend.dir = '${oracle.extensions.depend.dir}'"/>
<!-- This HAS to be defined after allowing user redefinitions (which will cause the condition not to set anything) -->
<!-- This tests to make sure the extensions dir exists, if not sets to a existant dummy location -->
<condition property="extensions.depend.dir" value="${oraclebuild.2.base.dir}/../extension.lib.external"
else="${oraclebuild.build.location}">
<available file="${oraclebuild.2.base.dir}/../extension.lib.external" type="dir"/>
</condition>
<echo message="extensions.depend.dir = '${extensions.depend.dir}'"/>
<!-- Custom task definitions -->
<property name="custom.tasks.lib" value="${oraclebuild.2.buildsystem.dir}/ant_customizations.jar"/>
<property name="custom.echo.task.class" value="org.eclipse.persistence.buildtools.ant.taskdefs.Say"/>
<property name="custom.selectbundle.task.class" value="org.eclipse.persistence.buildtools.ant.taskdefs.SelectBundle"/>
<echo message="custom.tasks.lib ='${custom.tasks.lib}'"/>
<echo message="custom.echo.task.class ='${custom.echo.task.class}'"/>
<echo message="custom.selectbundle.task.class ='${custom.selectbundle.task.class}'"/>
<echo message=" ---"/>
<taskdef name="say" classname="${custom.echo.task.class}" classpath="${custom.tasks.lib}"/>
<taskdef name="selectbundle" classname="${custom.selectbundle.task.class}" classpath="${custom.tasks.lib}"/>
<!-- Feature Dependency variables -->
<property name="oracle.ext.prefix" value="org.eclipse.persistence.oracle"/>
<property name="oracle.ext.criteria" value="[0.0.1,9.0.0)"/>
<property name="oracle.nosql.prefix" value="org.eclipse.persistence.oracle.nosql"/>
<property name="oracle.nosql.criteria" value="[0.0.1,9.0.0)"/>
<condition property="windows.os" value="true">
<contains string="${os.name}" substring="Win"/>
</condition>
<say message="Windows OS detected. Command-line Git tools will likely not run properly." if="windows.os"/>
<say message=" To build manually use:" if="windows.os"/>
<say message=" ant -f antbuild.xml -Doracle.target=&lt;target&gt; ${oraclebuild.target}" if="windows.os"/>
<say message=" " if="windows.os"/>
<say message="Aborting...." if="windows.os"/>
<fail message="This buildfile should be used with a *nix or OS X operating system." if="windows.os"/>
<!-- Verify validity of 'git.exec' value -->
<available file="${git.exec}" property="git.exec.exist"/>
<fail message="Cannot find: ${git.exec}" unless="git.exec.exist"/>
</target>
<target name="establish-baseline" if="git.exec" depends="init">
<!-- Determine starting hash values -->
<get_git_hash githashproperty="prebuild.git.hash" repoprojectdir="${oraclebuild.2.base.dir}"/>
<get_git_hash githashproperty="prebuild.ext.hash" repoprojectdir="${oraclebuild.2.oracle.dir}"/>
<get_git_hash githashproperty="prebuild.nosql.hash" repoprojectdir="${oraclebuild.2.oracle.nosql.dir}"/>
<!-- Report results -->
<say message="prebuild.git.hash = '${prebuild.git.hash}'" if="prebuild.git.hash"/>
<say message="prebuild.ext.hash = '${prebuild.ext.hash}'" if="prebuild.ext.hash"/>
<say message="prebuild.nosql.hash = '${prebuild.nosql.hash}'" if="prebuild.nosql.hash"/>
<say message="prebuild.git.hash = undefined" unless="prebuild.git.hash"/>
<say message="prebuild.ext.hash = undefined" unless="prebuild.ext.hash"/>
<say message="prebuild.nosql.hash = undefined" unless="prebuild.nosql.hash"/>
<!-- Determine existing bundle versions -->
<selectbundle basename="${oracle.ext.prefix}" directory="${oraclebuild.2.common.plugins.dir}"
criterion="${oracle.ext.criteria}" property="prebuild.oracle.ext.version" versiononly="true"
/>
<selectbundle basename="${oracle.nosql.prefix}" directory="${oraclebuild.2.common.plugins.dir}"
criterion="${oracle.nosql.criteria}" property="prebuild.oracle.nosql.version" versiononly="true"
/>
<!-- Report results -->
<say message="prebuild.oracle.ext.version = '${prebuild.oracle.ext.version}'" if="prebuild.oracle.ext.version"/>
<say message="prebuild.oracle.nosql.version = '${prebuild.oracle.nosql.version}'" if="prebuild.oracle.nosql.version"/>
<say message="prebuild.oracle.ext.version = '${oracle.ext.prefix}_*.jar' bundle not found." unless="prebuild.oracle.ext.version"/>
<say message="prebuild.oracle.nosql.version = '${oracle.nosql.prefix}_*.jar' bundle not found." unless="prebuild.oracle.nosql.version"/>
<echo message=" ---"/>
<!-- Validate we have what we need to proceed -->
<condition property="missing.hash" value="true">
<or>
<not> <isset property="prebuild.git.hash"/> </not>
<not> <isset property="prebuild.ext.hash"/> </not>
<not> <isset property="prebuild.nosql.hash"/> </not>
</or>
</condition>
<fail message="Cannot determine repository state (one or more hashes undefined). Aborting..." if="missing.hash"/>
</target>
<target name="set-build-required" depends="establish-baseline">
<!-- This could get increadibly complex: To compile both bundles together, not only do I need to determine if both bundles -->
<!-- should be built, but I need to figure out if the qualifiers are the same (based upon the hash of the project itself). -->
<!-- This means the potential of three build paths: (compile both together [if same hash], compile one, compile both -->
<!-- [different qualifiers]). So it looks like while compiling together is more efficient with Maven, it would only add -->
<!-- more complexity to this process. Therefore, the variables will be set to call the compile for each bundle if it is -->
<!-- required and use the bundles already determined hash, regardless of whether the hashes match. -->
<!-- Determine if Oracle Extension needs rebuild -->
<condition property="oracle.current" value="true">
<contains string="${prebuild.oracle.ext.version}" substring="${prebuild.ext.hash}"/>
</condition>
<!-- Determine if Oracle NoSQL Extension needs rebuild -->
<condition property="nosql.current" value="true">
<contains string="${prebuild.oracle.nosql.version}" substring="${prebuild.nosql.hash}"/>
</condition>
<say message="oracle.current = '${oracle.current}' ('prebuild.oracle.ext.version' contains 'prebuild.ext.hash')" if="oracle.current"/>
<say message="nosql.current = '${nosql.current}' ('prebuild.oracle.nosql.version' contains 'prebuild.nosql.hash')" if="nosql.current"/>
<say message="oracle.current = undefined ('prebuild.oracle.ext.version' doesn't contain 'prebuild.ext.hash')" unless="oracle.current"/>
<say message="nosql.current = undefined ('prebuild.oracle.nosql.version' doesn't contain 'prebuild.nosql.hash')" unless="nosql.current"/>
<!-- set what should clean -->
<!-- if either oracle or nosql need rebuild (clean will need to happen in either case)-->
<condition property="clean.target" value="oracle">
<and>
<not> <isset property="oracle.current"/> </not>
<not> <isset property="nosql.current"/> </not>
</and>
</condition>
<condition property="clean.target" value="oracle.ext">
<and>
<not> <isset property="oracle.current"/> </not>
<isset property="nosql.current"/>
</and>
</condition>
<condition property="clean.target" value="oracle.nosql">
<and>
<isset property="oracle.current"/>
<not> <isset property="nosql.current"/> </not>
</and>
</condition>
<say message="clean.target = '${clean.target}'" if="clean.target"/>
<say message="clean.target = undefined" unless="clean.target"/>
</target>
<!-- ================================================================ -->
<!-- BUILD TARGETS -->
<!-- ================================================================ -->
<target name="report-build-not-required" unless="clean.target" depends="set-build-required">
<echo message="Oracle extensions appear current. Conditions not met for rebuild. Build target will be bypassed."/>
</target>
<target name="clean-oracle" if="clean.target" depends="report-build-not-required">
<!-- === Which extensions targeted is based on ${oracle.target} === -->
<!-- oracle.target = oracle.ext: build oracle extension -->
<!-- = oracle.nosql: build oracle nosql extension -->
<!-- = oracle: build both -->
<ant antfile="antbuild.xml" dir="${oraclebuild.2.base.dir}" target="clean-oracle-extension">
<property name="version.qualifier" value="v${oraclebuild.build.date}-${prebuild.git.hash}"/>
<property name="oracle.target" value="${clean.target}"/>
</ant>
<!-- Also need to clean the compdeps repo so it is forced to regenerate -->
<ant antfile="antbuild.xml" dir="${oraclebuild.2.base.dir}" target="generate-local-compdeps">
<property name="generate.compdeps" value="true"/>
</ant>
<!-- What about the oracle repo? force regen, or allow manual install of local repo? -->
</target>
<target name="build-oracle" unless="oracle.current" >
<!-- === Which extensions targeted is based on ${oracle.target} === -->
<!-- oracle.target = oracle.ext: build oracle extension -->
<!-- = oracle.nosql: build oracle nosql extension -->
<!-- = oracle: build both -->
<build_extension qualifierhash="prebuild.ext.hash" buildtarget="oracle.ext"/>
<selectbundle basename="${oracle.ext.prefix}" directory="${oraclebuild.2.common.plugins.dir}"
criterion="${oracle.ext.criteria}" property="postbuild.oracle.ext.version" versiononly="true"
/>
<validate_extension_build prebuildhashproperty="prebuild.ext.hash" currentversionproperty="postbuild.oracle.ext.version" prebuildversion="${prebuild.oracle.ext.version}" successproperty="commit.oracle" failureproperty="oracle.build.failed"/>
</target>
<target name="build-nosql" unless="nosql.current" >
<!-- === Which extensions targeted is based on ${oracle.target} === -->
<!-- oracle.target = oracle.ext: build oracle extension -->
<!-- = oracle.nosql: build oracle nosql extension -->
<!-- = oracle: build both -->
<build_extension qualifierhash="prebuild.nosql.hash" buildtarget="oracle.nosql"/>
<selectbundle basename="${oracle.nosql.prefix}" directory="${oraclebuild.2.common.plugins.dir}"
criterion="${oracle.nosql.criteria}" property="postbuild.oracle.nosql.version" versiononly="true"
/>
<validate_extension_build prebuildhashproperty="prebuild.nosql.hash" currentversionproperty="postbuild.oracle.nosql.version" prebuildversion="${prebuild.oracle.nosql.version}" successproperty="commit.nosql" failureproperty="nosql.build.failed"/>
</target>
<!-- ================================================================ -->
<!-- COMMIT TARGETS -->
<!-- ================================================================ -->
<target name="oracle-failed" if="oracle.build.failed" depends="">
<echo message="cannot commit oracle extention, no bundle to commit"/>
<!-- revert?? -->
</target>
<target name="commit-oracle" if="commit.oracle" depends="oracle-failed">
<echo message="commit-oracle"/>
<!-- commit_extension qualifierhash="" targetprefix="" commithash="commit.oracle.hash"/ -->
</target>
<target name="nosql-failed" if="nosql.build.failed" depends="">
<echo message="cannot commit oracle nosql extention, no bundle to commit"/>
<!-- revert?? -->
</target>
<target name="commit-nosql" if="commit.nosql" depends="nosql-failed">
<echo message="commit-nosql"/>
<!-- commit_extension qualifierhash="" targetprefix="" commithash="commit.oracle.hash"/ -->
</target>
<target name="validate-commits">
<!-- If (! oracle.current) and commit.oracle.hash != prebuild.git.hash /was supposed to build post-commit-hash not equal prebuild haash -->
<!-- Determine if Oracle Extension was commited -->
<condition property="oracle.comitted" value="true">
<and>
<not> <isset property="oracle.current"/> </not>
<contains string="${postbuild.oracle.ext.version}" substring="${postbuild.ext.hash}"/>
</and>
</condition>
<!-- Determine if Oracle NoSQL Extension was commited -->
<condition property="nosql.comitted" value="true">
<and>
<not> <isset property="nosql.current"/> </not>
<contains string="${postbuild.oracle.nosql.version}" substring="${postbuild.nosql.hash}"/>
</and>
</condition>
</target>
<!-- ================================================================ -->
<!-- MACRO DEFINITIONS -->
<!-- ================================================================ -->
<!-- Needed to reduce code redunancy: -->
<!-- antcall is both memory intensive, and operate -->
<!-- outside current environment -->
<!-- ================================================================ -->
<macrodef name="get_git_hash">
<attribute name="githashproperty"/>
<attribute name="repoprojectdir"/>
<sequential>
<!-- echo message="gitHashProperty = '@{githashproperty}'"/>
<echo message="repoProjectDir = '@{repoprojectdir}'"/ -->
<exec outputproperty="@{githashproperty}"
failonerror="false"
failifexecutionfails="false"
errorproperty="githash.failed"
logError="true"
executable="${git.exec}">
<arg value="log"/>
<arg value="-1"/>
<arg value="--format=%h"/>
<arg line="@{repoprojectdir}"/>
</exec>
</sequential>
</macrodef>
<macrodef name="build_extension">
<attribute name="qualifierhash"/>
<attribute name="buildtarget"/>
<sequential>
<!-- === Which extensions targeted is based on ${oracle.target} === -->
<!-- oracle.target = oracle.ext: build oracle extension -->
<!-- = oracle.nosql: build oracle nosql extension -->
<!-- = oracle: build both -->
<ant antfile="antbuild.xml" dir="${oraclebuild.2.base.dir}" target="build-oracle-extension">
<property name="version.qualifier" value="v${oraclebuild.build.date}-${@{qualifierhash}}"/>
<property name="oracle.target" value="@{buildtarget}"/>
</ant>
</sequential>
</macrodef>
<macrodef name="validate_extension_build">
<!-- Verify build was successful. -->
<!-- Compare: -->
<!-- ${currentversionproperty} to prebuildversion (shouldn't match) -->
<!-- ${prebuildhashproperty} should be a substring of currentversion -->
<!-- Set: -->
<!-- successproperty to true if above true -->
<!-- (implies <extension>.current was false & so build was needed) -->
<!-- failureproperty is set if above is false -->
<!-- (implies build was necessary, but something failed) -->
<!-- (need separate property for process flow: "task if=" tests existance) -->
<attribute name="prebuildhashproperty"/>
<attribute name="currentversionproperty"/>
<attribute name="prebuildversion"/>
<attribute name="successproperty"/>
<attribute name="failureproperty"/>
<sequential>
<condition property="@{successproperty}" value="true">
<and>
<isset property="@{currentversionproperty}"/>
<not> <equals arg1="${@{currentversionproperty}}" arg2="@{prebuildversion}"/> </not>
<contains string="${@{currentversionproperty}}" substring="${@{prebuildhashproperty}}"/>
</and>
</condition>
<condition property="@{failureproperty}" value="true">
<not> <isset property="@{successproperty}"/> </not>
</condition>
<say message="Bundle was successfully generated:" if="@{successproperty}"/>
<say message=" @{currentversionproperty} ('${@{currentversionproperty}}') != '@{prebuildversion}'" if="@{successproperty}"/>
<say message=" and '${@{prebuildhashproperty}}' is a substring of '${@{currentversionproperty}}'" if="@{successproperty}"/>
<say message="Bundle generation failure detected." if="@{failureproperty}"/>
</sequential>
</macrodef>
</project>