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

GlueGen v2.6.0 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 Manifest mf) {
71 if( null != mf ) {
72 // use provided valid data
73 this.mf = mf;
74 this.packageName = VersionUtil.getExtensionName(mf);
75 } else {
76 // try FAT jar file and accept first Manifest w/ extension-name if none matches
77 final Manifest fatMF = VersionUtil.getManifest(JogampVersion.class.getClassLoader(), new String[] { packageNameFAT }, true);
78 if( null != fatMF ) {
79 this.mf = fatMF;
80 this.packageName = VersionUtil.getExtensionName(fatMF);
81 } else {
82 this.mf = new Manifest();
83 this.packageName = "unknown";
84 }
85 }
86 this.hash = this.mf.hashCode();
87 mainAttributes = this.mf.getMainAttributes();
88 mainAttributeNames = mainAttributes.keySet();
89 androidPackageVersionName = AndroidUtils.getPackageInfoVersionName(this.packageName); // null if !Android
90 }
91
92 @Override
93 public final int hashCode() {
94 return hash;
95 }
96
97 @Override
98 public final boolean equals(final Object o) {
99 if (o instanceof JogampVersion) {
100 return mf.equals(((JogampVersion) o).getManifest());
101 }
102 return false;
103 }
104
105 public final Manifest getManifest() {
106 return mf;
107 }
108
109 public final String getPackageName() {
110 return packageName;
111 }
112
113 public final String getAttribute(final Attributes.Name attributeName) {
114 return (null != attributeName) ? (String) mainAttributes.get(attributeName) : null;
115 }
116
117 public final String getAttribute(final String attributeName) {
118 return getAttribute(getAttributeName(attributeName));
119 }
120
121 public final Attributes.Name getAttributeName(final String attributeName) {
122 for (final Iterator<?> iter = mainAttributeNames.iterator(); iter.hasNext();) {
123 final Attributes.Name an = (Attributes.Name) iter.next();
124 if (an.toString().equals(attributeName)) {
125 return an;
126 }
127 }
128 return null;
129 }
130
131 /**
132 * @return set of type {@link Attributes.Name}, disguised as anonymous
133 */
134 public final Set<?>/*<Attributes.Name>*/ getAttributeNames() {
135 return mainAttributeNames;
136 }
137
138 public final String getExtensionName() {
139 if(null != androidPackageVersionName) {
140 return packageName;
141 }
142 return this.getAttribute(Attributes.Name.EXTENSION_NAME);
143 }
144
145 /**
146 * Returns the implementation build number, e.g. <code>2.0-b456-20130328</code>.
147 */
148 public final String getImplementationBuild() {
149 return this.getAttribute(JogampVersion.IMPLEMENTATION_BUILD);
150 }
151
152 /**
153 * Returns the SCM branch name
154 */
155 public final String getImplementationBranch() {
156 return this.getAttribute(JogampVersion.IMPLEMENTATION_BRANCH);
157 }
158
159 /**
160 * Returns the SCM version of the last commit, e.g. git's sha1
161 */
162 public final String getImplementationCommit() {
163 return this.getAttribute(JogampVersion.IMPLEMENTATION_COMMIT);
164 }
165
166 /**
167 * Returns the SHA of all concatenated source files of the whole project
168 */
169 public final String getImplementationSHASources() {
170 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_SOURCES);
171 }
172
173 /**
174 * Returns the SHA of all concatenated class files of all build classes
175 */
176 public final String getImplementationSHAClasses() {
177 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_CLASSES);
178 }
179
180 /**
181 * Returns the SHA of all concatenated class files of the local (jar) package subset
182 */
183 public final String getImplementationSHAClassesThis() {
184 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_CLASSES_THIS);
185 }
186
187 /**
188 * Returns the SHA of all concatenated native library files of all build libs
189 */
190 public final String getImplementationSHANatives() {
191 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_NATIVES);
192 }
193
194 /**
195 * Returns the SHA of all concatenated native library files of the local (jar) package subset
196 */
197 public final String getImplementationSHANativesThis() {
198 return this.getAttribute(JogampVersion.IMPLEMENTATION_SHA_NATIVES_THIS);
199 }
200
201 public final String getImplementationTitle() {
202 return this.getAttribute(Attributes.Name.IMPLEMENTATION_TITLE);
203 }
204
205 public final String getImplementationVendor() {
206 return this.getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR);
207 }
208
209 public final String getImplementationVendorID() {
210 return this.getAttribute(Attributes.Name.IMPLEMENTATION_VENDOR_ID);
211 }
212
213 public final String getImplementationURL() {
214 return this.getAttribute(Attributes.Name.IMPLEMENTATION_URL);
215 }
216
217 /**
218 * Returns the {@link Attributes.Name#IMPLEMENTATION_VERSION IMPLEMENTATION_VERSION}.
219 * <p>
220 * E.g. <code>2.0.2-rc-20130328</code> for snapshots prior to <code>2.0.2</code> release
221 * and <code>2.0.2</code> for the upcoming release.
222 * </p>
223 */
224 public final String getImplementationVersion() {
225 return this.getAttribute(Attributes.Name.IMPLEMENTATION_VERSION);
226 }
227
228 public final String getAndroidPackageVersionName() {
229 return androidPackageVersionName;
230 }
231
232 public final String getSpecificationTitle() {
233 return this.getAttribute(Attributes.Name.SPECIFICATION_TITLE);
234 }
235
236 public final String getSpecificationVendor() {
237 return this.getAttribute(Attributes.Name.SPECIFICATION_VENDOR);
238 }
239
240 public final String getSpecificationVersion() {
241 return this.getAttribute(Attributes.Name.SPECIFICATION_VERSION);
242 }
243
244 public final StringBuilder getFullManifestInfo(final StringBuilder sb) {
245 return VersionUtil.getFullManifestInfo(getManifest(), sb);
246 }
247
248 public StringBuilder getManifestInfo(StringBuilder sb) {
249 if(null==sb) {
250 sb = new StringBuilder();
251 }
252 final String nl = Platform.getNewline();
253 sb.append("Package: ").append(getPackageName()).append(nl);
254 sb.append("Extension Name: ").append(getExtensionName()).append(nl);
255 sb.append("Specification Title: ").append(getSpecificationTitle()).append(nl);
256 sb.append("Specification Vendor: ").append(getSpecificationVendor()).append(nl);
257 sb.append("Specification Version: ").append(getSpecificationVersion()).append(nl);
258 sb.append("Implementation Title: ").append(getImplementationTitle()).append(nl);
259 sb.append("Implementation Vendor: ").append(getImplementationVendor()).append(nl);
260 sb.append("Implementation Vendor ID: ").append(getImplementationVendorID()).append(nl);
261 sb.append("Implementation URL: ").append(getImplementationURL()).append(nl);
262 sb.append("Implementation Version: ").append(getImplementationVersion()).append(nl);
263 sb.append("Implementation Build: ").append(getImplementationBuild()).append(nl);
264 sb.append("Implementation Branch: ").append(getImplementationBranch()).append(nl);
265 sb.append("Implementation Commit: ").append(getImplementationCommit()).append(nl);
266
267 addOptionalTag(sb, "Implementation SHA Sources", () -> { return getImplementationSHASources(); });
268 addOptionalTag(sb, "Implementation SHA Classes", () -> { return getImplementationSHAClasses(); });
269 addOptionalTag(sb, "Implementation SHA Classes-this", () -> { return getImplementationSHAClassesThis(); });
270 addOptionalTag(sb, "Implementation SHA Natives", () -> { return getImplementationSHANatives(); });
271 addOptionalTag(sb, "Implementation SHA Natives-this", () -> { return getImplementationSHANativesThis(); });
272 addOptionalTag(sb, "Android Package Version", () -> { return getAndroidPackageVersionName(); });
273 return sb;
274 }
275 private static interface TagProvider {
276 public String get();
277 }
278 private static void addOptionalTag(final StringBuilder sb, final String title, final TagProvider tag) {
279 final String tagName = tag.get();
280 if( null != tagName ) {
281 sb.append(title+": ").append(tagName).append(Platform.getNewline());
282 }
283 }
284
285 public StringBuilder toString(StringBuilder sb) {
286 if(null==sb) {
287 sb = new StringBuilder();
288 }
289
290 sb.append(VersionUtil.SEPERATOR).append(Platform.getNewline());
291 getManifestInfo(sb);
292 sb.append(VersionUtil.SEPERATOR);
293
294 return sb;
295 }
296
297 @Override
298 public String toString() {
299 return toString(null).toString();
300 }
301}
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:190
com.jogamp.common.util.JogampVersion.hashCode
final int hashCode()
Definition: JogampVersion.java:93
com.jogamp.common.util.JogampVersion.getFullManifestInfo
final StringBuilder getFullManifestInfo(final StringBuilder sb)
Definition: JogampVersion.java:244
com.jogamp.common.util.JogampVersion.getImplementationVendorID
final String getImplementationVendorID()
Definition: JogampVersion.java:209
com.jogamp.common.util.JogampVersion.equals
final boolean equals(final Object o)
Definition: JogampVersion.java:98
com.jogamp.common.util.JogampVersion.getImplementationBuild
final String getImplementationBuild()
Returns the implementation build number, e.g.
Definition: JogampVersion.java:148
com.jogamp.common.util.JogampVersion.getImplementationSHAClasses
final String getImplementationSHAClasses()
Returns the SHA of all concatenated class files of all build classes.
Definition: JogampVersion.java:176
com.jogamp.common.util.JogampVersion.getAttribute
final String getAttribute(final String attributeName)
Definition: JogampVersion.java:117
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:228
com.jogamp.common.util.JogampVersion.getManifest
final Manifest getManifest()
Definition: JogampVersion.java:105
com.jogamp.common.util.JogampVersion.getImplementationVersion
final String getImplementationVersion()
Returns the IMPLEMENTATION_VERSION.
Definition: JogampVersion.java:224
com.jogamp.common.util.JogampVersion.getImplementationURL
final String getImplementationURL()
Definition: JogampVersion.java:213
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:205
com.jogamp.common.util.JogampVersion.getAttributeNames
final Set<?> getAttributeNames()
Definition: JogampVersion.java:134
com.jogamp.common.util.JogampVersion.getAttribute
final String getAttribute(final Attributes.Name attributeName)
Definition: JogampVersion.java:113
com.jogamp.common.util.JogampVersion.getSpecificationVendor
final String getSpecificationVendor()
Definition: JogampVersion.java:236
com.jogamp.common.util.JogampVersion.getImplementationSHASources
final String getImplementationSHASources()
Returns the SHA of all concatenated source files of the whole project.
Definition: JogampVersion.java:169
com.jogamp.common.util.JogampVersion.toString
String toString()
Definition: JogampVersion.java:298
com.jogamp.common.util.JogampVersion.getManifestInfo
StringBuilder getManifestInfo(StringBuilder sb)
Definition: JogampVersion.java:248
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:138
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:162
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:197
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:183
com.jogamp.common.util.JogampVersion.toString
StringBuilder toString(StringBuilder sb)
Definition: JogampVersion.java:285
com.jogamp.common.util.JogampVersion.getPackageName
final String getPackageName()
Definition: JogampVersion.java:109
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:201
com.jogamp.common.util.JogampVersion.JogampVersion
JogampVersion(final Manifest mf)
Definition: JogampVersion.java:70
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:155
com.jogamp.common.util.JogampVersion.getSpecificationTitle
final String getSpecificationTitle()
Definition: JogampVersion.java:232
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:240
com.jogamp.common.util.JogampVersion.getAttributeName
final Attributes.Name getAttributeName(final String attributeName)
Definition: JogampVersion.java:121
com.jogamp.common.util.VersionUtil
Definition: VersionUtil.java:49
com.jogamp.common.util.VersionUtil.SEPERATOR
static final String SEPERATOR
Definition: VersionUtil.java:52
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:126
com.jogamp.common.util.VersionUtil.getExtensionName
static String getExtensionName(final Manifest mf)
Returns the manifest's Attributes.Name.EXTENSION_NAME, i.e.
Definition: VersionUtil.java:108
com.jogamp.common.util.VersionUtil.getFullManifestInfo
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)
Definition: VersionUtil.java:224