29package com.jogamp.common.util;
31import com.jogamp.common.os.AndroidVersion;
32import com.jogamp.common.os.Platform;
34import java.io.IOException;
35import java.io.InputStream;
37import java.util.ArrayList;
38import java.util.Arrays;
39import java.util.Enumeration;
40import java.util.Iterator;
43import java.util.jar.Attributes;
44import java.util.jar.Manifest;
46import jogamp.common.Debug;
47import jogamp.common.os.PlatformPropsImpl;
50 private static final boolean DEBUG = Debug.debug(
"VersionUtil");
52 public static final String
SEPERATOR =
"-----------------------------------------------------------------------------------------------------";
59 sb =
new StringBuilder();
67 sb.append(Runtime.getRuntime().availableProcessors()).append(
" cores, ").append(
"littleEndian ").append(PlatformPropsImpl.LITTLE_ENDIAN);
81 if( PlatformPropsImpl.JAVA_21 ) {
82 sb.append(
", Java21");
83 }
else if( PlatformPropsImpl.JAVA_17 ) {
84 sb.append(
", Java17");
85 }
else if( PlatformPropsImpl.JAVA_9 ) {
87 }
else if( PlatformPropsImpl.JAVA_6 ) {
89 }
else if( PlatformPropsImpl.JAVA_SE ) {
90 sb.append(
", JavaSE");
92 sb.append(
", dynamicLib: ").append(PlatformPropsImpl.useDynamicLibraries);
113 if(
null != attributes) {
114 return attributes.getValue( Attributes.Name.EXTENSION_NAME );
126 public static Manifest
getManifest(
final ClassLoader cl,
final String extension) {
127 return getManifest(cl,
new String[] { extension } );
138 public static Manifest
getManifest(
final ClassLoader cl,
final String[] extensions) {
151 public static Manifest
getManifest(
final ClassLoader cl,
final String[] extensions,
final boolean acceptFirst) {
152 final Manifest[] extManifests =
new Manifest[extensions.length];
153 Manifest firstManifest =
null;
156 System.err.println();
157 System.err.println(
"XXXX: getManifest: acceptFirst "+acceptFirst+
", extensions "+Arrays.asList(extensions));
159 final List<URL> resources = getResources(cl,
"META-INF/MANIFEST.MF");
160 final List<URL> parentResources = getResources(cl.getParent(),
"META-INF/MANIFEST.MF");
162 for(
final URL r : parentResources) {
163 System.err.println(
"XXXX: drop parent "+r);
166 resources.removeAll(parentResources);
168 for(
final URL r : resources) {
169 System.err.println(
"XXXX: uniq "+r);
172 for(
final URL resource : resources) {
173 final InputStream is = resource.openStream();
174 final Manifest manifest;
176 manifest =
new Manifest(is);
180 final Attributes attributes = manifest.getMainAttributes();
182 if( DEBUG ) { System.err.println(
"XXXX: ext-name "+extensionName+
", resource "+resource); }
183 if(
null != extensionName &&
null != attributes) {
184 if(
null == firstManifest ) {
185 firstManifest = manifest;
187 for(
int i=0; i < extensions.length &&
null == extManifests[i]; i++) {
188 final String extension = extensions[i];
189 if( extension.equals( extensionName ) ) {
193 extManifests[i] = manifest;
198 }
catch (
final IOException ex) {
199 throw new RuntimeException(
"Unable to read manifest.", ex);
201 for(
int i=1; i<extManifests.length; i++) {
202 if(
null != extManifests[i] ) {
203 final Manifest mf = extManifests[i];
207 if( acceptFirst &&
null != firstManifest ) {
208 return firstManifest;
212 private static List<URL> getResources(
final ClassLoader cl,
final String name)
throws IOException {
213 final List<URL> res =
new ArrayList<URL>();
215 final Enumeration<URL> resources = cl.getResources(name);
216 while (resources.hasMoreElements()) {
217 final URL resource = resources.nextElement();
230 sb =
new StringBuilder();
233 final Attributes attr = mf.getMainAttributes();
234 final Set<Object> keys = attr.keySet();
235 for(
final Iterator<Object> iter=keys.iterator(); iter.hasNext(); ) {
236 final Attributes.Name key = (Attributes.Name) iter.next();
237 final String val = attr.getValue(key);
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)
static void close(final Closeable stream, final boolean throwRuntimeException)
static Manifest getManifest(final ClassLoader cl, final String[] extensions, final boolean acceptFirst)
Returns the manifest of the jar which contains one of the specified extensions.
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 final String SEPERATOR
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 String getPlatformInfo()
Prints platform info.
static String getExtensionName(final Attributes attributes)
Returns the attributes' Attributes.Name.EXTENSION_NAME, i.e.
static StringBuilder getFullManifestInfo(final Manifest mf, StringBuilder sb)