1 11 package org.eclipse.update.internal.model; 12 import java.io.*; 13 import java.util.jar.*; 14 15 import org.eclipse.osgi.util.*; 16 import org.eclipse.update.core.*; 17 import org.osgi.framework.*; 18 21 public class BundleManifest { 22 private PluginEntry pluginEntry; 23 private IOException exception; 24 27 public BundleManifest(File manifest) { 28 super(); 29 if (manifest.exists() && !manifest.isDirectory()) { 30 FileInputStream fos = null; 31 try { 32 fos = new FileInputStream(manifest); 33 parse(fos); 34 } catch (IOException ioe) { 35 } finally { 36 if (fos != null) { 37 try { 38 fos.close(); 39 } catch (IOException e) { 40 } 41 } 42 } 43 } 44 } 45 48 public BundleManifest(InputStream input) { 49 super(); 50 if (input != null) { 51 parse(input); 52 } 53 } 54 61 private void parse(InputStream in) { 62 try { 63 Manifest m = new Manifest(in); 64 Attributes a = m.getMainAttributes(); 65 String symbolicName = a.getValue(Constants.BUNDLE_SYMBOLICNAME); 67 if (symbolicName == null) { 68 return; 70 } 71 String id; 72 try { 73 ManifestElement[] elements = ManifestElement.parseHeader( 74 Constants.BUNDLE_SYMBOLICNAME, symbolicName); 75 id = elements[0].getValue(); 76 } catch (BundleException be) { 77 throw new IOException(be.getMessage()); 78 } 79 String version = a.getValue(Constants.BUNDLE_VERSION); 81 if (version == null) { 82 return; 83 } 84 String hostPlugin = a.getValue(Constants.FRAGMENT_HOST); 85 pluginEntry = new PluginEntry(); 86 pluginEntry.setVersionedIdentifier(new VersionedIdentifier(id, 87 version)); 88 pluginEntry.isFragment(hostPlugin != null 89 && hostPlugin.length() > 0); 90 } catch (IOException ioe) { 91 exception = ioe; 92 } 93 } 94 public boolean exists() { 95 return exception != null || pluginEntry != null; 96 } 97 104 public PluginEntry getPluginEntry() throws IOException { 105 if (exception != null) { 106 throw exception; 107 } else { 108 return pluginEntry; 109 } 110 } 111 } 112 | Popular Tags |