1 11 12 package org.eclipse.core.runtime.internal.adaptor; 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.util.jar.Manifest ; 17 import org.eclipse.osgi.baseadaptor.BaseData; 18 import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry; 19 import org.eclipse.osgi.baseadaptor.loader.*; 20 import org.eclipse.osgi.framework.util.KeyedElement; 21 22 public class ClasspathManifest implements KeyedElement { 23 public static final Object KEY = new Object (); 24 public static final int HASHCODE = KEY.hashCode(); 25 26 private Manifest manifest; 27 private boolean initialized = false; 28 29 public int getKeyHashCode() { 30 return HASHCODE; 31 } 32 33 public boolean compare(KeyedElement other) { 34 return other.getKey() == KEY; 35 } 36 37 public Object getKey() { 38 return KEY; 39 } 40 41 public Manifest getManifest(ClasspathEntry cpEntry, ClasspathManager loader) { 42 if (initialized) 43 return manifest; 44 if (!hasPackageInfo(cpEntry, loader)) { 45 initialized = true; 46 manifest = null; 47 return manifest; 48 } 49 BundleEntry mfEntry = cpEntry.getBundleFile().getEntry(org.eclipse.osgi.framework.internal.core.Constants.OSGI_BUNDLE_MANIFEST); 50 if (mfEntry != null) 51 try { 52 InputStream manIn = mfEntry.getInputStream(); 53 manifest = new Manifest (manIn); 54 manIn.close(); 55 } catch (IOException e) { 56 } 58 initialized = true; 59 return manifest; 60 } 61 62 private boolean hasPackageInfo(ClasspathEntry cpEntry, ClasspathManager loader) { 63 BaseData bundledata = null; 64 if (cpEntry.getBundleFile() == loader.getBaseData().getBundleFile()) 65 bundledata = loader.getBaseData(); 66 if (bundledata == null) { 67 FragmentClasspath[] fragCPs = loader.getFragmentClasspaths(); 68 if (fragCPs != null) 69 for (int i = 0; i < fragCPs.length; i++) 70 if (cpEntry.getBundleFile() == fragCPs[i].getBundleData().getBundleFile()) { 71 bundledata = fragCPs[i].getBundleData(); 72 break; 73 } 74 } 75 if (bundledata == null) 76 return true; 77 EclipseStorageHook storageHook = (EclipseStorageHook) bundledata.getStorageHook(EclipseStorageHook.KEY); 78 return storageHook == null ? true : storageHook.hasPackageInfo(); 79 } 80 81 } 82 | Popular Tags |