Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
VersionUtil: add getManifest(.., String[] extensions) variant, allowi…
…ng detection of multiple ordered extensions
  • Loading branch information
sgothel committed Mar 28, 2013
1 parent 0d45923 commit a256b64
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/java/com/jogamp/common/util/VersionUtil.java
Expand Up @@ -95,7 +95,19 @@ public static String getPlatformInfo() {
* @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()) {
Expand All @@ -107,13 +119,26 @@ public static Manifest getManifest(ClassLoader cl, String extension) {
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;
}

Expand All @@ -127,8 +152,8 @@ public static StringBuilder getFullManifestInfo(Manifest mf, StringBuilder sb) {
}

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(" ");
Expand Down

0 comments on commit a256b64

Please sign in to comment.