GlueGen: src/java/com/jogamp/common/util/JogampVersion.java Source File

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
40 public 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() {
151 return this.getAttribute(JogampVersion.IMPLEMENTATION_BUILD);
152 }
153
154 /**
155 * Returns the SCM branch name
156 */
157 public final String getImplementationBranch() {
158 return this.getAttribute(JogampVersion.IMPLEMENTATION_BRANCH);
159 }
160
161 /**
162 * Returns the SCM version of the last commit, e.g. git's sha1
163 */
164 public final String getImplementationCommit() {
165 return this.getAttribute(JogampVersion.IMPLEMENTATION_COMMIT);
166 }
167
168 /**
169 * Returns the SHA of all concatenated source files of the whole project
170 */
171 public final String getImplementationSHASources() {
172 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_SOURCES);
173 }
174
175 /**
176 * Returns the SHA of all concatenated class files of all build classes
177 */
178 public final String getImplementationSHAClasses() {
179 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_CLASSES);
180 }
181
182 /**
183 * Returns the SHA of all concatenated class files of the local (jar) package subset
184 */
185 public final String getImplementationSHAClassesThis() {
186 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_CLASSES_THIS);
187 }
188
189 /**
190 * Returns the SHA of all concatenated native library files of all build libs
191 */
192 public final String getImplementationSHANatives() {
193 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_NATIVES);
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() {
200 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_NATIVES_THIS);
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) {
247 return VersionUtil.getFullManifestInfo(getManifest(), 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}
com.jogamp.common.os.Platform
Utility class for querying platform specific properties.
Definition: Platform.java:58
com.jogamp.common.os.Platform.getNewline
static String getNewline()
Returns the platform's line separator.
Definition: Platform.java:503
com.jogamp.common.util.JogampVersion
Definition: JogampVersion.java:40
com.jogamp.common.util.JogampVersion.getImplementationSHANatives
final String getImplementationSHANatives()
Returns the SHA of all concatenated native library files of all build libs.
Definition: JogampVersion.java:192
com.jogamp.common.util.JogampVersion.hashCode
final int hashCode()
Definition: JogampVersion.java:95
com.jogamp.common.util.JogampVersion.getFullManifestInfo
final StringBuilder getFullManifestInfo(final StringBuilder sb)
Definition: JogampVersion.java:246
com.jogamp.common.util.JogampVersion.getImplementationVendorID
final String getImplementationVendorID()
Definition: JogampVersion.java:211
com.jogamp.common.util.JogampVersion.equals
final boolean equals(final Object o)
Definition: JogampVersion.java:100
com.jogamp.common.util.JogampVersion.getImplementationBuild
final String getImplementationBuild()
Returns the implementation build number, e.g.
Definition: JogampVersion.java:150
com.jogamp.common.util.JogampVersion.getImplementationSHAClasses
final String getImplementationSHAClasses()
Returns the SHA of all concatenated class files of all build classes.
Definition: JogampVersion.java:178
com.jogamp.common.util.JogampVersion.getAttribute
final String getAttribute(final String attributeName)
Definition: JogampVersion.java:119
com.jogamp.common.util.JogampVersion.JogampVersion
JogampVersion(final String packageName, final Manifest mf)
Definition: JogampVersion.java:70
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_BUILD
static final Attributes.Name IMPLEMENTATION_BUILD
See getImplementationBuild().
Definition: JogampVersion.java:43
com.jogamp.common.util.JogampVersion.getAndroidPackageVersionName
final String getAndroidPackageVersionName()
Definition: JogampVersion.java:230
com.jogamp.common.util.JogampVersion.getManifest
final Manifest getManifest()
Definition: JogampVersion.java:107
com.jogamp.common.util.JogampVersion.getImplementationVersion
final String getImplementationVersion()
Returns the IMPLEMENTATION_VERSION.
Definition: JogampVersion.java:226
com.jogamp.common.util.JogampVersion.getImplementationURL
final String getImplementationURL()
Definition: JogampVersion.java:215
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_BRANCH
static final Attributes.Name IMPLEMENTATION_BRANCH
See getImplementationBranch().
Definition: JogampVersion.java:45
com.jogamp.common.util.JogampVersion.getImplementationVendor
final String getImplementationVendor()
Definition: JogampVersion.java:207
com.jogamp.common.util.JogampVersion.getAttributeNames
final Set<?> getAttributeNames()
Definition: JogampVersion.java:136
com.jogamp.common.util.JogampVersion.getAttribute
final String getAttribute(final Attributes.Name attributeName)
Definition: JogampVersion.java:115
com.jogamp.common.util.JogampVersion.getSpecificationVendor
final String getSpecificationVendor()
Definition: JogampVersion.java:238
com.jogamp.common.util.JogampVersion.getImplementationSHASources
final String getImplementationSHASources()
Returns the SHA of all concatenated source files of the whole project.
Definition: JogampVersion.java:171
com.jogamp.common.util.JogampVersion.toString
String toString()
Definition: JogampVersion.java:292
com.jogamp.common.util.JogampVersion.getManifestInfo
StringBuilder getManifestInfo(StringBuilder sb)
Definition: JogampVersion.java:250
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_SHA_SOURCES
static final Attributes.Name IMPLEMENTATION_SHA_SOURCES
See getImplementationSHASources().
Definition: JogampVersion.java:49
com.jogamp.common.util.JogampVersion.getExtensionName
final String getExtensionName()
Definition: JogampVersion.java:140
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_SHA_CLASSES
static final Attributes.Name IMPLEMENTATION_SHA_CLASSES
See getImplementationSHAClasses().
Definition: JogampVersion.java:51
com.jogamp.common.util.JogampVersion.getImplementationCommit
final String getImplementationCommit()
Returns the SCM version of the last commit, e.g.
Definition: JogampVersion.java:164
com.jogamp.common.util.JogampVersion.getImplementationSHANativesThis
final String getImplementationSHANativesThis()
Returns the SHA of all concatenated native library files of the local (jar) package subset.
Definition: JogampVersion.java:199
com.jogamp.common.util.JogampVersion.getImplementationSHAClassesThis
final String getImplementationSHAClassesThis()
Returns the SHA of all concatenated class files of the local (jar) package subset.
Definition: JogampVersion.java:185
com.jogamp.common.util.JogampVersion.toString
StringBuilder toString(StringBuilder sb)
Definition: JogampVersion.java:279
com.jogamp.common.util.JogampVersion.getPackageName
final String getPackageName()
Definition: JogampVersion.java:111
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_SHA_NATIVES
static final Attributes.Name IMPLEMENTATION_SHA_NATIVES
See getImplementationSHANatives().
Definition: JogampVersion.java:55
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_SHA_CLASSES_THIS
static final Attributes.Name IMPLEMENTATION_SHA_CLASSES_THIS
See getImplementationSHAClassesThis().
Definition: JogampVersion.java:53
com.jogamp.common.util.JogampVersion.getImplementationTitle
final String getImplementationTitle()
Definition: JogampVersion.java:203
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_SHA_NATIVES_THIS
static final Attributes.Name IMPLEMENTATION_SHA_NATIVES_THIS
See getImplementationSHANativesThis().
Definition: JogampVersion.java:57
com.jogamp.common.util.JogampVersion.getImplementationBranch
final String getImplementationBranch()
Returns the SCM branch name.
Definition: JogampVersion.java:157
com.jogamp.common.util.JogampVersion.getSpecificationTitle
final String getSpecificationTitle()
Definition: JogampVersion.java:234
com.jogamp.common.util.JogampVersion.IMPLEMENTATION_COMMIT
static final Attributes.Name IMPLEMENTATION_COMMIT
See getImplementationCommit().
Definition: JogampVersion.java:47
com.jogamp.common.util.JogampVersion.getSpecificationVersion
final String getSpecificationVersion()
Definition: JogampVersion.java:242
com.jogamp.common.util.JogampVersion.getAttributeName
final Attributes.Name getAttributeName(final String attributeName)
Definition: JogampVersion.java:123
com.jogamp.common.util.VersionUtil
Definition: VersionUtil.java:45
com.jogamp.common.util.VersionUtil.SEPERATOR
static final String SEPERATOR
Definition: VersionUtil.java:47
com.jogamp.common.util.VersionUtil.getManifest
static Manifest getManifest(final ClassLoader cl, final String extension)
Returns the manifest of the jar which contains the specified extension.
Definition: VersionUtil.java:109
com.jogamp.common.util.VersionUtil.getFullManifestInfo
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)
Definition: VersionUtil.java:157