1 11 package org.eclipse.core.runtime.adaptor; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor; 16 import org.eclipse.osgi.framework.internal.core.AbstractBundle; 17 import org.eclipse.osgi.framework.internal.core.BundleHost; 18 import org.eclipse.osgi.framework.log.FrameworkLogEntry; 19 import org.eclipse.osgi.service.resolver.BundleDescription; 20 import org.eclipse.osgi.service.resolver.StateHelper; 21 import org.osgi.framework.Bundle; 22 import org.osgi.framework.BundleContext; 23 24 31 public class BundleStopper { 32 33 private Hashtable stoppedBundles; 34 35 private BundleDescription[] allToStop = null; 36 37 private void logCycles(Object [][] cycles) { 38 if (cycles.length > 0) { 40 StringBuffer cycleText = new StringBuffer ("["); for (int i = 0; i < cycles.length; i++) { 42 cycleText.append('['); 43 for (int j = 0; j < cycles[i].length; j++) { 44 cycleText.append(((BundleDescription) cycles[i][j]).getSymbolicName()); 45 cycleText.append(','); 46 } 47 cycleText.insert(cycleText.length() - 1, ']'); 48 } 49 cycleText.setCharAt(cycleText.length() - 1, ']'); 50 String message = EclipseAdaptorMsg.formatter.getString("ECLIPSE_BUNDLESTOPPER_CYCLES_FOUND", cycleText); FrameworkLogEntry entry = new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, message, 0, null, null); 52 EclipseAdaptor.getDefault().getFrameworkLog().log(entry); 53 } 54 } 55 56 public void stopBundles() { 57 allToStop = EclipseAdaptor.getDefault().getState().getResolvedBundles(); 58 StateHelper stateHelper = EclipseAdaptor.getDefault().getPlatformAdmin().getStateHelper(); 59 Object [][] cycles = stateHelper.sortBundles(allToStop); 60 logCycles(cycles); 61 stoppedBundles = new Hashtable (allToStop.length); 62 basicStopBundles(); 63 } 64 65 private void basicStopBundles() { 66 BundleContext context = EclipseAdaptor.getDefault().getContext(); 67 for (int stoppingIndex = allToStop.length - 1; stoppingIndex >= 0; stoppingIndex--) { 69 AbstractBundle toStop = (AbstractBundle) context.getBundle(allToStop[stoppingIndex].getBundleId()); 70 try { 71 if (toStop.getState() != Bundle.ACTIVE || !(toStop instanceof BundleHost) || toStop.getBundleId() == 0) 72 continue; 73 if (!((EclipseBundleData) toStop.getBundleData()).isAutoStartable()) 74 continue; 75 toStop.stop(); 76 } catch (Exception e) { 77 String message = EclipseAdaptorMsg.formatter.getString("ECLIPSE_BUNDLESTOPPER_ERROR_STOPPING_BUNDLE", allToStop[stoppingIndex].toString()); FrameworkLogEntry entry = new FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME, message, 0, e, null); 79 EclipseAdaptor.getDefault().getFrameworkLog().log(entry); 80 } finally { 81 stoppedBundles.put(toStop, toStop); 82 } 83 } 84 } 85 86 public boolean isStopped(Bundle bundle) { 87 if (stoppedBundles == null) 88 return false; 89 return stoppedBundles.get(bundle) != null; 90 } 91 } | Popular Tags |