-
Notifications
You must be signed in to change notification settings - Fork 3
/
sharedlib.xml
245 lines (222 loc) · 12.1 KB
/
sharedlib.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!--
Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0,
or the Eclipse Distribution License v. 1.0 which is available at
http://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
-->
<!--
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).
#******************************************************************************/-->
<!--
* 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.
-->
<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"><weblogic-application>
<prefer-application-packages>
<package-name>org.eclipse.persistence.*</package-name>
<package-name>commonj.sdo.*</package-name>
</prefer-application-packages>
</weblogic-application>
</echo>
<echo file="${metadata.dir}/application.xml" append="false"><application>
<display-name>${wls-shared-lib.name}</display-name>
<module>
<java></java>
</module>
</application>
</echo>
<!-- Create "Application" Metadata -->
<echo file="${shared-lib.dir}/weblogic-application.xml" append="false"><?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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">
<wls:application-param>
<wls:param-name>webapp.encoding.default</wls:param-name>
<wls:param-value>UTF-8</wls:param-value>
</wls:application-param>
<wls:library-ref>
<wls:library-name>${wls-shared-lib.base.name}</wls:library-name>
<wls:specification-version>${specification.version}</wls:specification-version>
<wls:implementation-version>${implimentation.version}</wls:implementation-version>
<wls:exact-match>true</wls:exact-match>
</wls:library-ref>
</wls:weblogic-application>
</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>