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

GlueGen v2.6.0-rc-20250722 GlueGen, Native Binding Generator for Java™ (public API).

VersionUtil.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 com.jogamp.common.os.AndroidVersion;
32import com.jogamp.common.os.Platform;
33
34import java.io.IOException;
35import java.io.InputStream;
36import java.net.URL;
37import java.util.Enumeration;
38import java.util.Iterator;
39import java.util.Set;
40import java.util.jar.Attributes;
41import java.util.jar.Manifest;
42
43import jogamp.common.os.PlatformPropsImpl;
44
45 public class VersionUtil {
46
47 public static final String SEPERATOR = "-----------------------------------------------------------------------------------------------------";
48
49 /**
50 * Appends environment information like OS, JVM and CPU architecture properties to the StringBuilder.
51 */
52 public static StringBuilder getPlatformInfo(StringBuilder sb) {
53 if(null == sb) {
54 sb = new StringBuilder();
55 }
56
57 sb.append(SEPERATOR).append(Platform.getNewline());
58
59 // environment
60 sb.append("Platform: ").append(Platform.getOSType()).append(" / ").append(Platform.getOSName()).append(' ').append(Platform.getOSVersion()).append(" (").append(Platform.getOSVersionNumber()).append("), ");
61 sb.append(Platform.getArchName()).append(" (").append(Platform.getCPUType()).append(", ").append(Platform.getABIType()).append("), ");
62 sb.append(Runtime.getRuntime().availableProcessors()).append(" cores, ").append("littleEndian ").append(PlatformPropsImpl.LITTLE_ENDIAN);
63 sb.append(Platform.getNewline());
64 if( Platform.OSType.ANDROID == PlatformPropsImpl.OS_TYPE ) {
65 sb.append("Platform: Android Version: ").append(AndroidVersion.CODENAME).append(", ");
66 sb.append(AndroidVersion.RELEASE).append(" [").append(AndroidVersion.RELEASE).append("], SDK: ").append(AndroidVersion.SDK_INT).append(", ").append(AndroidVersion.SDK_NAME);
67 sb.append(Platform.getNewline());
68 }
69
70 Platform.getMachineDataInfo().toString(sb).append(Platform.getNewline());
71
72 // JVM/JRE
73 sb.append("Platform: Java Version: ").append(Platform.getJavaVersion()).append(" (").append(Platform.getJavaVersionNumber()).append("u").append(PlatformPropsImpl.JAVA_VERSION_UPDATE).append("), VM: ").append(Platform.getJavaVMName());
74 sb.append(", Runtime: ").append(Platform.getJavaRuntimeName()).append(Platform.getNewline());
75 sb.append("Platform: Java Vendor: ").append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL());
76 if( PlatformPropsImpl.JAVA_21 ) {
77 sb.append(", Java21");
78 } else if( PlatformPropsImpl.JAVA_17 ) {
79 sb.append(", Java17");
80 } else if( PlatformPropsImpl.JAVA_9 ) {
81 sb.append(", Java9");
82 } else if( PlatformPropsImpl.JAVA_6 ) {
83 sb.append(", Java6");
84 } else if( PlatformPropsImpl.JAVA_SE ) {
85 sb.append(", JavaSE");
86 }
87 sb.append(", dynamicLib: ").append(PlatformPropsImpl.useDynamicLibraries);
88 sb.append(", AWT enabled: ").append(Platform.AWT_AVAILABLE);
89 sb.append(Platform.getNewline()).append(SEPERATOR);
90
91 return sb;
92 }
93
94 /**
95 * Prints platform info.
96 * @see #getPlatformInfo(java.lang.StringBuilder)
97 */
98 public static String getPlatformInfo() {
99 return getPlatformInfo(null).toString();
100 }
101
102 /**
103 * Returns the manifest of the jar which contains the specified extension.
104 * The provided ClassLoader is used for resource loading.
105 * @param cl A ClassLoader which should find the manifest.
106 * @param extension The value of the 'Extension-Name' jar-manifest attribute; used to identify the manifest.
107 * @return the requested manifest or null when not found.
108 */
109 public static Manifest getManifest(final ClassLoader cl, final String extension) {
110 return getManifest(cl, new String[] { extension } );
111 }
112
113 /**
114 * Returns the manifest of the jar which contains one of the specified extensions.
115 * The provided ClassLoader is used for resource loading.
116 * @param cl A ClassLoader which should find the manifest.
117 * @param extensions The values of many 'Extension-Name's jar-manifest attribute; used to identify the manifest.
118 * Matching is applied in decreasing order, i.e. first element is favored over the second, etc.
119 * @return the requested manifest or null when not found.
120 */
121 public static Manifest getManifest(final ClassLoader cl, final String[] extensions) {
122 final Manifest[] extManifests = new Manifest[extensions.length];
123 try {
124 final Enumeration<URL> resources = cl.getResources("META-INF/MANIFEST.MF");
125 while (resources.hasMoreElements()) {
126 final InputStream is = resources.nextElement().openStream();
127 final Manifest manifest;
128 try {
129 manifest = new Manifest(is);
130 } finally {
131 IOUtil.close(is, false);
132 }
133 final Attributes attributes = manifest.getMainAttributes();
134 if(attributes != null) {
135 for(int i=0; i < extensions.length && null == extManifests[i]; i++) {
136 final String extension = extensions[i];
137 if( extension.equals( attributes.getValue( Attributes.Name.EXTENSION_NAME ) ) ) {
138 if( 0 == i ) {
139 return manifest; // 1st one has highest prio - done
140 }
141 extManifests[i] = manifest;
142 }
143 }
144 }
145 }
146 } catch (final IOException ex) {
147 throw new RuntimeException("Unable to read manifest.", ex);
148 }
149 for(int i=1; i<extManifests.length; i++) {
150 if( null != extManifests[i] ) {
151 return extManifests[i];
152 }
153 }
154 return null;
155 }
156
157 public static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb) {
158 if(null==mf) {
159 return sb;
160 }
161
162 if(null==sb) {
163 sb = new StringBuilder();
164 }
165
166 final Attributes attr = mf.getMainAttributes();
167 final Set<Object> keys = attr.keySet();
168 for(final Iterator<Object> iter=keys.iterator(); iter.hasNext(); ) {
169 final Attributes.Name key = (Attributes.Name) iter.next();
170 final String val = attr.getValue(key);
171 sb.append(" ");
172 sb.append(key);
173 sb.append(" = ");
174 sb.append(val);
175 sb.append(Platform.getNewline());
176 }
177 return sb;
178 }
179}
180
com.jogamp.common.os.AndroidVersion
Definition: AndroidVersion.java:37
com.jogamp.common.os.AndroidVersion.SDK_INT
static final int SDK_INT
SDK Version number, key to VERSION_CODES.
Definition: AndroidVersion.java:60
com.jogamp.common.os.AndroidVersion.CODENAME
static final String CODENAME
Development codename, or the string "REL" for official release.
Definition: AndroidVersion.java:51
com.jogamp.common.os.AndroidVersion.SDK_NAME
static final String SDK_NAME
SDK Version string.
Definition: AndroidVersion.java:63
com.jogamp.common.os.AndroidVersion.RELEASE
static final String RELEASE
official build version string
Definition: AndroidVersion.java:57
com.jogamp.common.os.MachineDataInfo.toString
StringBuilder toString(StringBuilder sb)
Definition: MachineDataInfo.java:355
com.jogamp.common.os.Platform
Utility class for querying platform specific properties.
Definition: Platform.java:58
com.jogamp.common.os.Platform.getOSVersionNumber
static VersionNumber getOSVersionNumber()
Returns the OS version number.
Definition: Platform.java:386
com.jogamp.common.os.Platform.getOSVersion
static String getOSVersion()
Returns the OS version.
Definition: Platform.java:379
com.jogamp.common.os.Platform.getJavaVersion
static String getJavaVersion()
Returns the JAVA version.
Definition: Platform.java:489
com.jogamp.common.os.Platform.getJavaVMName
static String getJavaVMName()
Returns the JAVA VM name.
Definition: Platform.java:468
com.jogamp.common.os.Platform.getABIType
static ABIType getABIType()
Returns the ABI type.
Definition: Platform.java:444
com.jogamp.common.os.Platform.getJavaVersionNumber
static VersionNumber getJavaVersionNumber()
Returns the JAVA version number.
Definition: Platform.java:496
com.jogamp.common.os.Platform.getJavaVendorURL
static String getJavaVendorURL()
Returns the JAVA vendor url.
Definition: Platform.java:482
com.jogamp.common.os.Platform.getOSType
static OSType getOSType()
Returns the OS type.
Definition: Platform.java:401
com.jogamp.common.os.Platform.getMachineDataInfo
static MachineDataInfo getMachineDataInfo()
Returns the MachineDataInfo of the running machine.
Definition: Platform.java:510
com.jogamp.common.os.Platform.getJavaRuntimeName
static String getJavaRuntimeName()
Returns the JAVA runtime name.
Definition: Platform.java:475
com.jogamp.common.os.Platform.getOSName
static String getOSName()
Returns the OS name.
Definition: Platform.java:372
com.jogamp.common.os.Platform.getArchName
static String getArchName()
Returns the CPU architecture String.
Definition: Platform.java:393
com.jogamp.common.os.Platform.getJavaVendor
static String getJavaVendor()
Returns the JAVA vendor.
Definition: Platform.java:461
com.jogamp.common.os.Platform.getNewline
static String getNewline()
Returns the platform's line separator.
Definition: Platform.java:503
com.jogamp.common.os.Platform.AWT_AVAILABLE
static final boolean AWT_AVAILABLE
true if AWT is available and not in headless mode, otherwise false.
Definition: Platform.java:281
com.jogamp.common.os.Platform.getCPUType
static CPUType getCPUType()
Returns the CPU architecture type.
Definition: Platform.java:415
com.jogamp.common.util.IOUtil
Definition: IOUtil.java:69
com.jogamp.common.util.IOUtil.close
static void close(final Closeable stream, final boolean throwRuntimeException)
Definition: IOUtil.java:1405
com.jogamp.common.util.VersionUtil
Definition: VersionUtil.java:45
com.jogamp.common.util.VersionUtil.getPlatformInfo
static StringBuilder getPlatformInfo(StringBuilder sb)
Appends environment information like OS, JVM and CPU architecture properties to the StringBuilder.
Definition: VersionUtil.java:52
com.jogamp.common.util.VersionUtil.getManifest
static Manifest getManifest(final ClassLoader cl, final String[] extensions)
Returns the manifest of the jar which contains one of the specified extensions.
Definition: VersionUtil.java:121
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.getPlatformInfo
static String getPlatformInfo()
Prints platform info.
Definition: VersionUtil.java:98
com.jogamp.common.util.VersionUtil.getFullManifestInfo
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)
Definition: VersionUtil.java:157
com.jogamp.common.os.Platform.OSType
Definition: Platform.java:60
com.jogamp.common.os.Platform.OSType.ANDROID
ANDROID
Definition: Platform.java:61