1 11 package org.eclipse.ui.internal.util; 12 13 import java.net.URL ; 14 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Path; 17 import org.eclipse.core.runtime.Platform; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.ui.internal.WorkbenchPlugin; 20 import org.osgi.framework.Bundle; 21 22 26 public class BundleUtility { 27 public static boolean isActive(Bundle bundle) { 28 if (bundle == null) { 29 return false; 30 } 31 return bundle.getState() == Bundle.ACTIVE; 32 } 33 34 public static boolean isActivated(Bundle bundle) { 35 if ((bundle.getState() & Bundle.STARTING) != 0) 36 return WorkbenchPlugin.getDefault().isStarting(bundle); 37 return bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STOPPING)) != 0; 38 } 39 40 public static boolean isReady(Bundle bundle) { 42 return bundle != null && isReady(bundle.getState()); 43 } 44 45 public static boolean isReady(int bundleState) { 46 return (bundleState & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING)) != 0; 47 } 48 49 public static boolean isActive(String bundleId) { 50 return isActive(Platform.getBundle(bundleId)); 51 } 52 53 public static boolean isActivated(String bundleId) { 54 return isActivated(Platform.getBundle(bundleId)); 55 } 56 57 public static boolean isReady(String bundleId) { 58 return isReady(Platform.getBundle(bundleId)); 59 } 60 61 public static URL find(Bundle bundle, String path) { 62 if (bundle == null) { 63 return null; 64 } 65 return Platform.find(bundle, new Path(path)); 66 } 67 68 public static URL find(String bundleId, String path) { 69 return find(Platform.getBundle(bundleId), path); 70 } 71 72 public static void log(String bundleId, Throwable exception) { 73 Bundle bundle = Platform.getBundle(bundleId); 74 if (bundle == null) { 75 return; 76 } 77 IStatus status = new Status(IStatus.ERROR, bundleId, IStatus.ERROR, 78 exception.getMessage() == null ? "" : exception.getMessage(), exception); 80 Platform.getLog(bundle).log(status); 81 } 82 } 83 | Popular Tags |