GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
JogampVersion.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.common.util;
30
31import java.util.Iterator;
32import java.util.Set;
33import java.util.jar.Attributes;
34import java.util.jar.Manifest;
35
36import jogamp.common.os.AndroidUtils;
37
38import com.jogamp.common.os.Platform;
39
40public class JogampVersion {
41
42 /** See {@link #getImplementationBuild()} */
43 public static final Attributes.Name IMPLEMENTATION_BUILD = new Attributes.Name("Implementation-Build");
44 /** See {@link #getImplementationBranch()} */
45 public static final Attributes.Name IMPLEMENTATION_BRANCH = new Attributes.Name("Implementation-Branch");
46 /** See {@link #getImplementationCommit()} */
47 public static final Attributes.Name IMPLEMENTATION_COMMIT = new Attributes.Name("Implementation-Commit");
48 /** See {@link #getImplementationSHASources()} */
49 public static final Attributes.Name IMPLEMENTATION_SHA_SOURCES = new Attributes.Name("Implementation-SHA-Sources");
50 /** See {@link #getImplementationSHAClasses()} */
51 public static final Attributes.Name IMPLEMENTATION_SHA_CLASSES = new Attributes.Name("Implementation-SHA-Classes");
52 /** See {@link #getImplementationSHAClassesThis()} */
53 public static final Attributes.Name IMPLEMENTATION_SHA_CLASSES_THIS = new Attributes.Name("Implementation-SHA-Classes-this");
54 /** See {@link #getImplementationSHANatives()} */
55 public static final Attributes.Name IMPLEMENTATION_SHA_NATIVES = new Attributes.Name("Implementation-SHA-Natives");
56 /** See {@link #getImplementationSHANativesThis()} */
57 public static final Attributes.Name IMPLEMENTATION_SHA_NATIVES_THIS = new Attributes.Name("Implementation-SHA-Natives-this");
58
59 /** For FAT JogAmp jar files */
60 private static final String packageNameFAT = "com.jogamp";
61
62 private final String packageName;
63 private final Manifest mf;
64 private final int hash;
65 private final Attributes mainAttributes;
66 private final Set<?>/*<Attributes.Name>*/ mainAttributeNames;
67
68 private final String androidPackageVersionName;
69
70 protected JogampVersion(final String packageName, final Manifest mf) {
71 if( null != mf ) {
72 // use provided valid data
73 this.mf = mf;
74 this.packageName = packageName;
75 } else {
76 // try FAT jar file
77 final Manifest fatMF = VersionUtil.getManifest(JogampVersion.class.getClassLoader(), packageNameFAT);
78 if( null != fatMF ) {
79 // use FAT jar file
80 this.mf = fatMF;
81 this.packageName = packageNameFAT;
82 } else {
83 // use faulty data, unresolvable ..
84 this.mf = new Manifest();
85 this.packageName = packageName;
86 }
87 }
88 this.hash = this.mf.hashCode();
89 mainAttributes = this.mf.getMainAttributes();
90 mainAttributeNames = mainAttributes.keySet();
91 androidPackageVersionName = AndroidUtils.getPackageInfoVersionName(this.packageName); // null if !Android
92 }
93
94 @Override
95 public final int hashCode() {
96 return hash;
97 }
98
99 @Override
100 public final boolean equals(final Object o) {
101 if (o instanceof JogampVersion) {
102 return mf.equals(((JogampVersion) o).getManifest());
103 }
104 return false;
105 }
106
107 public final Manifest getManifest() {
108 return mf;
109 }
110
111 public final String getPackageName() {
112 return packageName;
113 }
114
115 public final String getAttribute(final Attributes.Name attributeName) {
116 return (null != attributeName) ? (String) mainAttributes.get(attributeName) : null;
117 }
118
119 public final String getAttribute(final String attributeName) {
120 return getAttribute(getAttributeName(attributeName));
121 }
122
123 public final Attributes.Name getAttributeName(final String attributeName) {
124 for (final Iterator<?> iter = mainAttributeNames.iterator(); iter.hasNext();) {
125 final Attributes.Name an = (Attributes.Name) iter.next();
126 if (an.toString().equals(attributeName)) {
127 return an;
128 }
129 }
130 return null;
131 }
132
133 /**
134 * @return set of type {@link Attributes.Name}, disguised as anonymous
135 */
136 public final Set<?>/*<Attributes.Name>*/ getAttributeNames() {
137 return mainAttributeNames;
138 }
139
140 public final String getExtensionName() {
141 if(null != androidPackageVersionName) {
142 return packageName;
143 }
144 return this.getAttribute(Attributes.Name.EXTENSION_NAME);
145 }
146
147 /**
148 * Returns the implementation build number, e.g. <code>2.0-b456-20130328</code>.
149 */
150 public final String getImplementationBuild() {
152 }
153
154 /**
155 * Returns the SCM branch name
156 */
157 public final String getImplementationBranch() {
159 }
160
161 /**
162 * Returns the SCM version of the last commit, e.g. git's sha1
163 */
164 public final String getImplementationCommit() {
166 }
167
168 /**
169 * Returns the SHA of all concatenated source files of the whole project
170 */
171 public final String getImplementationSHASources() {
173 }
174
175 /**
176 * Returns the SHA of all concatenated class files of all build classes
177 */
178 public final String getImplementationSHAClasses() {
180 }
181
182 /**
183 * Returns the SHA of all concatenated class files of the local (jar) package subset
184 */
185 public final String getImplementationSHAClassesThis() {
187 }
188
189 /**
190 * Returns the SHA of all concatenated native library files of all build libs
191 */
192 public final String getImplementationSHANatives() {
194 }
195
196 /**
197 * Returns the SHA of all concatenated native library files of the local (jar) package subset
198 */
199 public final String getImplementationSHANativesThis() {
201 }
202
203 public final String getImplementationTitle() {
204 return this.getAttribute(Attributes.Name.IMPLEMENTATION_TITLE);
205 }
206
207 public final String getImplementationVendor() {
208 return this.getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR);
209 }
210
211 public final String getImplementationVendorID() {
212 return this.getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR_ID);
213 }
214
215 public final String getImplementationURL() {
216 return this.getAttribute(Attributes.Name.IMPLEMENTATION_URL);
217 }
218
219 /**
220 * Returns the {@link Attributes.Name#IMPLEMENTATION_VERSION IMPLEMENTATION_VERSION}.
221 * <p>
222 * E.g. <code>2.0.2-rc-20130328</code> for snapshots prior to <code>2.0.2</code> release
223 * and <code>2.0.2</code> for the upcoming release.
224 * </p>
225 */
226 public final String getImplementationVersion() {
227 return this.getAttribute(Attributes.Name.IMPLEMENTATION_VERSION);
228 }
229
230 public final String getAndroidPackageVersionName() {
231 return androidPackageVersionName;
232 }
233
234 public final String getSpecificationTitle() {
235 return this.getAttribute(Attributes.Name.SPECIFICATION_TITLE);
236 }
237
238 public final String getSpecificationVendor() {
239 return this.getAttribute(Attributes.Name.SPECIFICATION_VENDOR);
240 }
241
242 public final String getSpecificationVersion() {
243 return this.getAttribute(Attributes.Name.SPECIFICATION_VERSION);
244 }
245
246 public final StringBuilder getFullManifestInfo(final StringBuilder sb) {
248 }
249
250 public StringBuilder getManifestInfo(StringBuilder sb) {
251 if(null==sb) {
252 sb = new StringBuilder();
253 }
254 final String nl = Platform.getNewline();
255 sb.append("Package: ").append(getPackageName()).append(nl);
256 sb.append("Extension Name: ").append(getExtensionName()).append(nl);
257 sb.append("Specification Title: ").append(getSpecificationTitle()).append(nl);
258 sb.append("Specification Vendor: ").append(getSpecificationVendor()).append(nl);
259 sb.append("Specification Version: ").append(getSpecificationVersion()).append(nl);
260 sb.append("Implementation Title: ").append(getImplementationTitle()).append(nl);
261 sb.append("Implementation Vendor: ").append(getImplementationVendor()).append(nl);
262 sb.append("Implementation Vendor ID: ").append(getImplementationVendorID()).append(nl);
263 sb.append("Implementation URL: ").append(getImplementationURL()).append(nl);
264 sb.append("Implementation Version: ").append(getImplementationVersion()).append(nl);
265 sb.append("Implementation Build: ").append(getImplementationBuild()).append(nl);
266 sb.append("Implementation Branch: ").append(getImplementationBranch()).append(nl);
267 sb.append("Implementation Commit: ").append(getImplementationCommit()).append(nl);
268 sb.append("Implementation SHA Sources: ").append(getImplementationSHASources()).append(nl);
269 sb.append("Implementation SHA Classes: ").append(getImplementationSHAClasses()).append(nl);
270 sb.append("Implementation SHA Classes-this: ").append(getImplementationSHAClassesThis()).append(nl);
271 sb.append("Implementation SHA Natives: ").append(getImplementationSHANatives()).append(nl);
272 sb.append("Implementation SHA Natives-this: ").append(getImplementationSHANativesThis()).append(nl);
273 if(null != getAndroidPackageVersionName()) {
274 sb.append("Android Package Version: ").append(getAndroidPackageVersionName()).append(nl);
275 }
276 return sb;
277 }
278
279 public StringBuilder toString(StringBuilder sb) {
280 if(null==sb) {
281 sb = new StringBuilder();
282 }
283
284 sb.append(VersionUtil.SEPERATOR).append(Platform.getNewline());
285 getManifestInfo(sb);
286 sb.append(VersionUtil.SEPERATOR);
287
288 return sb;
289 }
290
291 @Override
292 public String toString() {
293 return toString(null).toString();
294 }
295}
Utility class for querying platform specific properties.
Definition: Platform.java:58
static String getNewline()
Returns the platform's line separator.
Definition: Platform.java:503
final String getImplementationSHANatives()
Returns the SHA of all concatenated native library files of all build libs.
final StringBuilder getFullManifestInfo(final StringBuilder sb)
final boolean equals(final Object o)
final String getImplementationBuild()
Returns the implementation build number, e.g.
final String getImplementationSHAClasses()
Returns the SHA of all concatenated class files of all build classes.
final String getAttribute(final String attributeName)
JogampVersion(final String packageName, final Manifest mf)
static final Attributes.Name IMPLEMENTATION_BUILD
See getImplementationBuild().
final String getImplementationVersion()
Returns the IMPLEMENTATION_VERSION.
static final Attributes.Name IMPLEMENTATION_BRANCH
See getImplementationBranch().
final String getAttribute(final Attributes.Name attributeName)
final String getImplementationSHASources()
Returns the SHA of all concatenated source files of the whole project.
StringBuilder getManifestInfo(StringBuilder sb)
static final Attributes.Name IMPLEMENTATION_SHA_SOURCES
See getImplementationSHASources().
static final Attributes.Name IMPLEMENTATION_SHA_CLASSES
See getImplementationSHAClasses().
final String getImplementationCommit()
Returns the SCM version of the last commit, e.g.
final String getImplementationSHANativesThis()
Returns the SHA of all concatenated native library files of the local (jar) package subset.
final String getImplementationSHAClassesThis()
Returns the SHA of all concatenated class files of the local (jar) package subset.
StringBuilder toString(StringBuilder sb)
static final Attributes.Name IMPLEMENTATION_SHA_NATIVES
See getImplementationSHANatives().
static final Attributes.Name IMPLEMENTATION_SHA_CLASSES_THIS
See getImplementationSHAClassesThis().
static final Attributes.Name IMPLEMENTATION_SHA_NATIVES_THIS
See getImplementationSHANativesThis().
final String getImplementationBranch()
Returns the SCM branch name.
static final Attributes.Name IMPLEMENTATION_COMMIT
See getImplementationCommit().
final Attributes.Name getAttributeName(final String attributeName)
static Manifest getManifest(final ClassLoader cl, final String extension)
Returns the manifest of the jar which contains the specified extension.
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)