1 12 package org.eclipse.update.internal.configurator; 13 import java.io.*; 14 import java.util.jar.*; 15 16 import org.eclipse.osgi.util.*; 17 import org.osgi.framework.*; 18 21 public class BundleManifest implements IConfigurationConstants { 22 private File manifestFile; 23 private PluginEntry pluginEntry; 24 private IOException exception; 25 private String bundleURL; 26 29 public BundleManifest(File manifest) { 30 super(); 31 manifestFile = manifest; 32 if (manifest.exists() && !manifest.isDirectory()) { 33 FileInputStream fos = null; 34 try { 35 fos = new FileInputStream(manifest); 36 parse(fos); 37 } catch (IOException ioe) { 38 } finally { 39 if (fos != null) { 40 try { 41 fos.close(); 42 } catch (IOException e) { 43 } 44 } 45 } 46 } 47 } 48 51 public BundleManifest(InputStream input, String bundleUrl) { 52 super(); 53 bundleURL = bundleUrl; 54 if (input != null) { 55 parse(input); 56 } 57 } 58 65 private void parse(InputStream in) { 66 try { 67 Manifest m = new Manifest(in); 68 Attributes a = m.getMainAttributes(); 69 String symbolicName = a.getValue(Constants.BUNDLE_SYMBOLICNAME); 71 if (symbolicName == null) { 72 return; 74 } 75 String id; 76 try { 77 ManifestElement[] elements = ManifestElement.parseHeader( 78 Constants.BUNDLE_SYMBOLICNAME, symbolicName); 79 id = elements[0].getValue(); 80 } catch (BundleException be) { 81 throw new IOException(be.getMessage()); 82 } 83 String version = a.getValue(Constants.BUNDLE_VERSION); 85 if (version == null) { 86 Utils.log(NLS.bind(Messages.BundleManifest_noVersion, (new String [] { Constants.BUNDLE_VERSION, id }))); 87 return; 88 } 89 version = version.trim(); 90 String hostPlugin = a.getValue(Constants.FRAGMENT_HOST); 91 pluginEntry = new PluginEntry(); 92 pluginEntry.setVersionedIdentifier(new VersionedIdentifier(id, 93 version)); 94 pluginEntry.isFragment(hostPlugin != null 95 && hostPlugin.length() > 0); 96 if(bundleURL!=null){ 98 pluginEntry.setURL(bundleURL); 99 }else{ 100 File pluginDir = manifestFile.getParentFile(); 101 if (pluginDir != null) { 102 pluginDir = pluginDir.getParentFile(); 103 } 104 if (pluginDir != null){ 105 pluginEntry.setURL(PLUGINS + "/" + pluginDir.getName() + "/"); } 107 } 108 } catch (IOException ioe) { 110 exception = ioe; 111 } 112 } 113 public boolean exists() { 114 return exception != null || pluginEntry != null; 115 } 116 123 public PluginEntry getPluginEntry() throws IOException { 124 if (exception != null) { 125 throw exception; 126 } 127 return pluginEntry; 128 } 129 } 130 | Popular Tags |