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
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 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() {
150 }
151
152 /**
153 * Returns the SCM branch name
154 */
155 public final String getImplementationBranch() {
157 }
158
159 /**
160 * Returns the SCM version of the last commit, e.g. git's sha1
161 */
162 public final String getImplementationCommit() {
164 }
165
166 /**
167 * Returns the SHA of all concatenated source files of the whole project
168 */
169 public final String getImplementationSHASources() {
171 }
172
173 /**
174 * Returns the SHA of all concatenated class files of all build classes
175 */
176 public final String getImplementationSHAClasses() {
178 }
179
180 /**
181 * Returns the SHA of all concatenated class files of the local (jar) package subset
182 */
183 public final String getImplementationSHAClassesThis() {
185 }
186
187 /**
188 * Returns the SHA of all concatenated native library files of all build libs
189 */
190 public final String getImplementationSHANatives() {
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() {
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) {
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}
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)
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 String getExtensionName(final Manifest mf)
Returns the manifest's Attributes.Name.EXTENSION_NAME, i.e.
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)