File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
src/main/java/org/scijava/util Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,23 @@ public static Manifest getManifest(final Class<?> c) {
143143 }
144144 }
145145
146+ /**
147+ * Gets the JAR manifest associated with the given XML document. Assumes the
148+ * XML document was loaded as a resource from inside a JAR.
149+ */
150+ public static Manifest getManifest (final XML xml ) throws IOException {
151+ final String path = xml .getPath ();
152+ if (path == null || !path .startsWith ("file:" )) return null ;
153+ final int dotJAR = path .indexOf (".jar!/" );
154+ return getManifest (new File (path .substring (5 , dotJAR + 4 )));
155+ }
156+
157+ /** Gets the JAR manifest associated with the given JAR file. */
158+ public static Manifest getManifest (final File jarFile ) throws IOException {
159+ if (!jarFile .exists ()) throw new FileNotFoundException ();
160+ return getManifest (new URL ("jar:file:" + jarFile .getAbsolutePath () + "!/" ));
161+ }
162+
146163 private static Manifest getManifest (final URL jarURL ) throws IOException {
147164 final JarURLConnection conn = (JarURLConnection ) jarURL .openConnection ();
148165 return new Manifest (conn .getManifest ());
You can’t perform that action at this time.
0 commit comments