forked from eclipse-efx/efxclipse-drift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManifestUtil.java
37 lines (31 loc) · 1 KB
/
ManifestUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.eclipse.fx.drift.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
public class ManifestUtil {
private ManifestUtil() {}
private static URL getManifestUrl(Class<?> cls) {
try {
String shortName = cls.getSimpleName() + ".class";
String fullPath = cls.getName().replace('.', '/') + ".class";
URL clsUrl = cls.getResource(shortName);
return new URL(clsUrl.toString().replace(fullPath, "META-INF/MANIFEST.MF"));
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
public static String getManifestEntry(Class<?> context, String name) {
URL manifestUrl = getManifestUrl(context);
try (InputStream in = manifestUrl.openStream()) {
Manifest manifest = new Manifest(in);
Attributes attrs = manifest.getMainAttributes();
return attrs.getValue(name);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}