/** * Parses a bunlde's manifest into a dictionary. The bundle may be in a jar or in a directory at * the specified location. * * @param bundleLocation root location of the bundle * @return bundle manifest dictionary or <code>null</code> if none * @throws IOException if unable to parse */ protected Map loadManifest(File bundleLocation) throws IOException { ZipFile jarFile = null; InputStream manifestStream = null; String extension = new Path(bundleLocation.getName()).getFileExtension(); try { if (extension != null && extension.equals("jar") && bundleLocation.isFile()) { // $NON-NLS-1$ jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ); ZipEntry manifestEntry = jarFile.getEntry(JarFile.MANIFEST_NAME); if (manifestEntry != null) { manifestStream = jarFile.getInputStream(manifestEntry); } } else { File file = new File(bundleLocation, JarFile.MANIFEST_NAME); if (file.exists()) manifestStream = new FileInputStream(file); } if (manifestStream == null) { return null; } return ManifestElement.parseBundleManifest(manifestStream, new Hashtable(10)); } catch (BundleException e) { PDEPlugin.log(e); } finally { try { if (manifestStream != null) { manifestStream.close(); } } catch (IOException e) { PDEPlugin.log(e); } try { if (jarFile != null) { jarFile.close(); } } catch (IOException e) { PDEPlugin.log(e); } } return null; }
protected Map<String, String> getManifest(String manifestFile) throws IOException, BundleException { URL manifest = getBundle().getEntry("/test_files/containerTests/" + manifestFile); Assert.assertNotNull("Could not find manifest: " + manifestFile, manifest); return ManifestElement.parseBundleManifest(manifest.openStream(), null); }