1 11 package org.eclipse.ui.internal.about; 12 13 import java.io.IOException ; 14 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.osgi.internal.provisional.verifier.CertificateVerifier; 17 import org.eclipse.osgi.internal.provisional.verifier.CertificateVerifierFactory; 18 import org.eclipse.ui.internal.WorkbenchMessages; 19 import org.eclipse.ui.internal.WorkbenchPlugin; 20 import org.osgi.framework.Bundle; 21 import org.osgi.framework.BundleContext; 22 import org.osgi.framework.Constants; 23 import org.osgi.framework.ServiceReference; 24 25 26 27 31 public class AboutBundleData extends AboutData { 32 33 private Bundle bundle; 34 35 private boolean isSignedDetermined = false; 36 37 private boolean isSigned; 38 39 public AboutBundleData(Bundle bundle) { 40 super(getResourceString(bundle, Constants.BUNDLE_VENDOR), 41 getResourceString(bundle, Constants.BUNDLE_NAME), 42 getResourceString(bundle, Constants.BUNDLE_VERSION), bundle 43 .getSymbolicName()); 44 45 this.bundle = bundle; 46 47 } 48 49 public int getState() { 50 return bundle.getState(); 51 } 52 53 57 public String getStateName() { 58 switch (getState()) { 59 case Bundle.INSTALLED: 60 return WorkbenchMessages.AboutPluginsDialog_state_installed; 61 case Bundle.RESOLVED: 62 return WorkbenchMessages.AboutPluginsDialog_state_resolved; 63 case Bundle.STARTING: 64 return WorkbenchMessages.AboutPluginsDialog_state_starting; 65 case Bundle.STOPPING: 66 return WorkbenchMessages.AboutPluginsDialog_state_stopping; 67 case Bundle.UNINSTALLED: 68 return WorkbenchMessages.AboutPluginsDialog_state_uninstalled; 69 case Bundle.ACTIVE: 70 return WorkbenchMessages.AboutPluginsDialog_state_active; 71 default: 72 return WorkbenchMessages.AboutPluginsDialog_state_unknown; 73 } 74 } 75 76 84 private static String getResourceString(Bundle bundle, String headerName) { 85 String value = (String ) bundle.getHeaders().get(headerName); 86 return value == null ? null : Platform.getResourceString(bundle, value); 87 } 88 89 public boolean isSignedDetermined() { 90 return isSignedDetermined; 91 } 92 93 public boolean isSigned() throws IllegalStateException { 94 95 if (isSignedDetermined) 96 return isSigned; 97 98 BundleContext bundleContext = WorkbenchPlugin.getDefault() 99 .getBundleContext(); 100 ServiceReference certRef = bundleContext 101 .getServiceReference(CertificateVerifierFactory.class.getName()); 102 if (certRef == null) 103 throw new IllegalStateException (); 104 CertificateVerifierFactory certFactory = (CertificateVerifierFactory) bundleContext 105 .getService(certRef); 106 try { 107 CertificateVerifier verifier = certFactory.getVerifier(bundle); 108 isSigned = verifier.isSigned(); 109 isSignedDetermined = true; 110 return isSigned; 111 } catch (IOException e) { 112 throw (IllegalStateException ) new IllegalStateException () 113 .initCause(e); 114 } finally { 115 bundleContext.ungetService(certRef); 116 } 117 } 118 119 122 public Bundle getBundle() { 123 return bundle; 124 } 125 126 } 223 | Popular Tags |