blob: da519d56d6432cf0fc6ca1a8264f148f8946e157 [file] [log] [blame]
<!--/*******************************************************************************
* 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:
* eric.gwin - initial API and implementation
#******************************************************************************/-->
<!--/*******************************************************************************
This buildfile looks for a eclipselink.jar file in the current directory, and
generates an appropriate ear file for use as a WLS shared library. If the jar
does not exist, an attempt to generate one will be attempted (it is assumed
that the this file resides at the same location as the primary buildfile for
EclipseLink - not necessary, but assumed).
#******************************************************************************/-->
<project name="wls-shared-lib" default="create-shared-lib-install" basedir=".">
<scriptdef name="genImpVersion" language="javascript" manager="javax">
<attribute name="input"/>
<attribute name="property"/>
<attribute name="newline"/>
<![CDATA[
// getting the value
input = attributes.get("input");
property = attributes.get("property");
newline = attributes.get("newline");
if (input == null || property == null || newline == null) {
self.fail("'input', 'property', and 'newline' attributes must be set.");
}
if (input.startsWith("${") || input == "" ) {
// Set the result of an undefined (unexpanded) or "empty string" variable to 'NA'
project.setProperty(attributes.get("property"), "NA");
}
else {
// Verstion String is displayed just before Qualifier in
// "java -jar eclipselink.jar" output
// Convert newlines to ','
trimmedInput = input.replace(newline, ',');
// Get "endString" Index based on search for last instance of "Build Qualifier"
endLastRev = trimmedInput.lastIndexOf(", Build Qualifier");
// Get "beginString" index based upon the last space in the line above the endString index
beginLastRev = trimmedInput.lastIndexOf(" ", endLastRev);
// Trim the string to not include the leading space, or the end-of-line
trimmedInput = trimmedInput.substring(beginLastRev+1, endLastRev);
project.setProperty(attributes.get("property"), trimmedInput);
}
]]>
</scriptdef>
<scriptdef name="genSpecVersion" language="javascript" manager="javax">
<attribute name="input"/>
<attribute name="property"/>
<![CDATA[
// getting the value
input = attributes.get("input");
property = attributes.get("property");
if (input == null || property == null) {
self.fail("both 'input' and 'property' attributes must be set.");
}
if (input.startsWith("${") || input == "" ) {
// Set the result of an undefined (unexpanded) or "empty string" variable to 'NA'
project.setProperty(attributes.get("property"), "NA");
}
else {
// Trim the string to not include the bugfix or qualifier tokens
endLastRev = input.lastIndexOf(".");
trimmedInput = input.substring(0, endLastRev);
endLastRev = trimmedInput.lastIndexOf(".");
trimmedInput = input.substring(0, endLastRev);
project.setProperty(attributes.get("property"), trimmedInput);
}
]]>
</scriptdef>
<scriptdef name="genEarnameVersion" language="javascript" manager="javax">
<attribute name="input"/>
<attribute name="property"/>
<![CDATA[
// getting the value
input = attributes.get("input");
property = attributes.get("property");
if (input == null || property == null) {
self.fail("both 'input' and 'property' attributes must be set.");
}
if (input.startsWith("${") || input == "" ) {
// Set the result of an undefined (unexpanded) or "empty string" variable to 'NA'
project.setProperty(attributes.get("property"), "NA");
}
else {
// replace "." in version string with "_"
project.setProperty(attributes.get("property"), input.replace('.', '_'));
}
]]>
</scriptdef>
<!-- ================================================================================= -->
<target name="verify-eclipselink-exist">
<property name="eclipselink.jar" value="eclipselink.jar"/>
<condition property="eclipselink.exist">
<available file="${eclipselink.jar}"/>
</condition>
</target>
<target name="generate-eclipselink" unless="eclipselink.exist" depends="verify-eclipselink-exist">
<echo message="EclipseLink jar not found! Building..."/>
<condition property="eclipselink.build.file" value="build.xml"
else="antbuild.xml">
<available file="build.xml"/>
</condition>
<ant antfile="${eclipselink.build.file}" dir="." target="build-eclipselink-jar"/>
</target>
<target name="identify-eclipselink" depends="generate-eclipselink">
<!-- unzip src="${eclipselink.jar}" dest=".">
<patternset>
<include name="META-INF/MANIFEST.MF"/>
</patternset>
</unzip -->
<java jar="${eclipselink.jar}" outputproperty="implimentation.version" fork="true"/>
<!-- echo message="${implimentation.version}"/ -->
<genImpVersion input="${implimentation.version}" property="implimentation.version" newline="${line.separator}"/>
<genSpecVersion input="${implimentation.version}" property="specification.version"/>
<genEarnameVersion input="${implimentation.version}" property="earname.version"/>
<echo message="SpecV: '${specification.version}'"/>
<echo message="ImpV: '${implimentation.version}'"/>
<echo message="EarV: '${earname.version}'"/>
</target>
<target name="package-wls-shared-lib" depends="prepare-wls-metadata">
<!-- generate Ear file -->
<!-- if eclipselink.jar exists, generate ear with "o.e.p:spec version:imp version" -->
<jar destfile="${shared-lib.dir}/${wls-shared-lib.name}.ear">
<metainf dir="${metadata.dir}" includes="*.xml"/>
<manifest>
<attribute name="Extension-Name" value="${wls-shared-lib.base.name}"/>
<attribute name="Specification-Version" value="${specification.version}"/>
<attribute name="Implementation-Version" value="${implimentation.version}"/>
</manifest>
<zipfileset dir="." includes="${eclipselink.jar}" prefix="lib"/>
</jar>
</target>
<target name="create-shared-lib-install" depends="package-wls-shared-lib">
<delete file="eclipselink${earname.version}-shared-lib.zip"/>
<!-- generate Ear file -->
<!-- if eclipselink.jar exists, generate ear with "o.e.p:spec version:imp version" -->
<zip destfile="eclipselink${earname.version}-shared-lib.zip">
<zipfileset dir="${shared-lib.dir}" includes="${wls-shared-lib.name}.ear" prefix="shared-lib"/>
<zipfileset dir="${shared-lib.dir}" includes="weblogic-application.xml" prefix="application"/>
<zipfileset dir="${shared-lib.dir}" includes="README"/>
</zip>
</target>
<!-- ======================================================================================================================================= -->
<!-- METADATA GENERATION -->
<!-- Ugly so moved to bottom of file -->
<target name="prepare-wls-metadata" depends="identify-eclipselink">
<!-- artifact definitions -->
<property name="wls-shared-lib.base.name" value="org.eclipse.persistence"/>
<property name="wls-shared-lib.name" value="${wls-shared-lib.base.name}${earname.version}-shared-lib"/>
<!-- location to generate metadata artifacts -->
<property name="shared-lib.dir" value="build/shared-lib"/>
<property name="metadata.dir" value="${shared-lib.dir}/etc"/>
<delete dir="${shared-lib.dir}"/>
<mkdir dir="${metadata.dir}"/>
<!-- Create Library Metadata -->
<echo file="${metadata.dir}/weblogic-application.xml" append="false">&lt;weblogic-application&gt;
&lt;prefer-application-packages&gt;
&lt;package-name&gt;org.eclipse.persistence.*&lt;/package-name&gt;
&lt;package-name&gt;commonj.sdo.*&lt;/package-name&gt;
&lt;/prefer-application-packages&gt;
&lt;/weblogic-application&gt;
</echo>
<echo file="${metadata.dir}/application.xml" append="false">&lt;application&gt;
&lt;display-name&gt;${wls-shared-lib.name}&lt;/display-name&gt;
&lt;module&gt;
&lt;java&gt;&lt;/java&gt;
&lt;/module&gt;
&lt;/application&gt;
</echo>
<!-- Create "Application" Metadata -->
<echo file="${shared-lib.dir}/weblogic-application.xml" append="false">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;wls:weblogic-application xmlns:wls=&quot;http://xmlns.oracle.com/weblogic/weblogic-application&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.2/weblogic-application.xsd&quot;&gt;
&lt;wls:application-param&gt;
&lt;wls:param-name&gt;webapp.encoding.default&lt;/wls:param-name&gt;
&lt;wls:param-value&gt;UTF-8&lt;/wls:param-value&gt;
&lt;/wls:application-param&gt;
&lt;wls:library-ref&gt;
&lt;wls:library-name&gt;${wls-shared-lib.base.name}&lt;/wls:library-name&gt;
&lt;wls:specification-version&gt;${specification.version}&lt;/wls:specification-version&gt;
&lt;wls:implementation-version&gt;${implimentation.version}&lt;/wls:implementation-version&gt;
&lt;wls:exact-match&gt;true&lt;/wls:exact-match&gt;
&lt;/wls:library-ref&gt;
&lt;/wls:weblogic-application&gt;
</echo>
<!-- Create Sharedlib "Install" readme -->
<echo file="${shared-lib.dir}/README" append="false">
How to use a different version of EclipseLink than ships with Weblogic in your application
------------------------------------------------------------------------------------------
Put the shared library (the ear in the 'shared-lib' dir) in the ...
Package the 'weblogoc-application.xml found in the 'app' dir with your application, and...
</echo>
</target>
</project>