GlueGen v2.6.0-rc-20250712
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
45public 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
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
static final int SDK_INT
SDK Version number, key to VERSION_CODES.
static final String CODENAME
Development codename, or the string "REL" for official release.
static final String SDK_NAME
SDK Version string.
static final String RELEASE
official build version string
StringBuilder toString(StringBuilder sb)
Utility class for querying platform specific properties.
Definition: Platform.java:58
static VersionNumber getOSVersionNumber()
Returns the OS version number.
Definition: Platform.java:386
static String getOSVersion()
Returns the OS version.
Definition: Platform.java:379
static String getJavaVersion()
Returns the JAVA version.
Definition: Platform.java:489
static String getJavaVMName()
Returns the JAVA VM name.
Definition: Platform.java:468
static ABIType getABIType()
Returns the ABI type.
Definition: Platform.java:444
static VersionNumber getJavaVersionNumber()
Returns the JAVA version number.
Definition: Platform.java:496
static String getJavaVendorURL()
Returns the JAVA vendor url.
Definition: Platform.java:482
static OSType getOSType()
Returns the OS type.
Definition: Platform.java:401
static MachineDataInfo getMachineDataInfo()
Returns the MachineDataInfo of the running machine.
Definition: Platform.java:510
static String getJavaRuntimeName()
Returns the JAVA runtime name.
Definition: Platform.java:475
static String getOSName()
Returns the OS name.
Definition: Platform.java:372
static String getArchName()
Returns the CPU architecture String.
Definition: Platform.java:393
static String getJavaVendor()
Returns the JAVA vendor.
Definition: Platform.java:461
static String getNewline()
Returns the platform's line separator.
Definition: Platform.java:503
static final boolean AWT_AVAILABLE
true if AWT is available and not in headless mode, otherwise false.
Definition: Platform.java:281
static CPUType getCPUType()
Returns the CPU architecture type.
Definition: Platform.java:415
static void close(final Closeable stream, final boolean throwRuntimeException)
Definition: IOUtil.java:1405
static StringBuilder getPlatformInfo(StringBuilder sb)
Appends environment information like OS, JVM and CPU architecture properties to the StringBuilder.
static Manifest getManifest(final ClassLoader cl, final String[] extensions)
Returns the manifest of the jar which contains one of the specified extensions.
static Manifest getManifest(final ClassLoader cl, final String extension)
Returns the manifest of the jar which contains the specified extension.
static String getPlatformInfo()
Prints platform info.
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)