aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-03-28 22:59:29 +0100
committerSven Gothel <[email protected]>2013-03-28 22:59:29 +0100
commita256b64fa57d9f7789baaf379bd9afdc54d8095d (patch)
tree7351ccda95f1ddaaa36361ad2b6c2eb8fe35fef2 /src/java
parent0d459235979710be6c9cededb8d9e385fdc25d85 (diff)
VersionUtil: add getManifest(.., String[] extensions) variant, allowing detection of multiple ordered extensions
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/jogamp/common/util/VersionUtil.java35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java
index 22672b4..8d9e6a9 100644
--- a/src/java/com/jogamp/common/util/VersionUtil.java
+++ b/src/java/com/jogamp/common/util/VersionUtil.java
@@ -95,7 +95,19 @@ public class VersionUtil {
* @return the requested manifest or null when not found.
*/
public static Manifest getManifest(ClassLoader cl, String extension) {
-
+ return getManifest(cl, new String[] { extension } );
+ }
+
+ /**
+ * Returns the manifest of the jar which contains one of the specified extensions.
+ * The provided ClassLoader is used for resource loading.
+ * @param cl A ClassLoader which should find the manifest.
+ * @param extensions The values of many 'Extension-Name's jar-manifest attribute; used to identify the manifest.
+ * Matching is applied in decreasing order, i.e. first element is favored over the second, etc.
+ * @return the requested manifest or null when not found.
+ */
+ public static Manifest getManifest(ClassLoader cl, String[] extensions) {
+ final Manifest[] extManifests = new Manifest[extensions.length];
try {
Enumeration<URL> resources = cl.getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
@@ -107,13 +119,26 @@ public class VersionUtil {
IOUtil.close(is, false);
}
Attributes attributes = manifest.getMainAttributes();
- if(attributes != null && extension.equals(attributes.getValue(Attributes.Name.EXTENSION_NAME))) {
- return manifest;
+ if(attributes != null) {
+ for(int i=0; i < extensions.length && null == extManifests[i]; i++) {
+ final String extension = extensions[i];
+ if( extension.equals( attributes.getValue( Attributes.Name.EXTENSION_NAME ) ) ) {
+ if( 0 == i ) {
+ return manifest; // 1st one has highest prio - done
+ }
+ extManifests[i] = manifest;
+ }
+ }
}
}
} catch (IOException ex) {
throw new RuntimeException("Unable to read manifest.", ex);
}
+ for(int i=1; i<extManifests.length; i++) {
+ if( null != extManifests[i] ) {
+ return extManifests[i];
+ }
+ }
return null;
}
@@ -127,8 +152,8 @@ public class VersionUtil {
}
Attributes attr = mf.getMainAttributes();
- Set keys = attr.keySet();
- for(Iterator iter=keys.iterator(); iter.hasNext(); ) {
+ Set<Object> keys = attr.keySet();
+ for(Iterator<Object> iter=keys.iterator(); iter.hasNext(); ) {
Attributes.Name key = (Attributes.Name) iter.next();
String val = attr.getValue(key);
sb.append(" ");