1 11 package org.eclipse.pde.internal.core; 12 13 import java.util.Dictionary ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.IWorkspaceRunnable; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.osgi.service.resolver.BundleDescription; 22 import org.eclipse.osgi.service.resolver.State; 23 import org.eclipse.osgi.service.resolver.StateObjectFactory; 24 import org.eclipse.pde.core.plugin.IPluginModelBase; 25 26 public class BundleValidationOperation implements IWorkspaceRunnable { 27 28 private static StateObjectFactory FACTORY; 29 30 private IPluginModelBase[] fModels; 31 private Dictionary [] fProperties; 32 private State fState; 33 34 public BundleValidationOperation(IPluginModelBase[] models) { 35 this(models, new Dictionary [] { TargetPlatformHelper.getTargetEnvironment()}); 36 } 37 38 public BundleValidationOperation(IPluginModelBase[] models, Dictionary [] properties) { 39 fModels = models; 40 fProperties = properties; 41 } 42 43 public void run(IProgressMonitor monitor) throws CoreException { 44 if (FACTORY == null) 45 FACTORY = Platform.getPlatformAdmin().getFactory(); 46 monitor.beginTask("", fModels.length + 1); fState = FACTORY.createState(true); 48 for (int i = 0; i < fModels.length; i++) { 49 BundleDescription bundle = fModels[i].getBundleDescription(); 50 if (bundle != null) 51 fState.addBundle(FACTORY.createBundleDescription(bundle)); 52 monitor.worked(1); 53 } 54 fState.setPlatformProperties(fProperties); 55 fState.resolve(false); 56 monitor.done(); 57 } 58 59 public Map getResolverErrors() { 60 Map map = new HashMap (); 61 BundleDescription[] bundles = fState.getBundles(); 62 for (int i = 0; i < bundles.length; i++) { 63 if (!bundles[i].isResolved()) { 64 map.put(bundles[i], fState.getResolverErrors(bundles[i])); 65 } 66 } 67 return map; 68 } 69 70 public State getState() { 71 return fState; 72 } 73 74 public boolean hasErrors() { 75 return fState.getHighestBundleId() > -1 76 && fState.getBundles().length > fState.getResolvedBundles().length; 77 } 78 79 } 80 | Popular Tags |