1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.debug.core.ILaunchConfiguration; 19 import org.eclipse.osgi.service.resolver.BundleDescription; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.pde.core.plugin.IPluginAttribute; 22 import org.eclipse.pde.core.plugin.IPluginElement; 23 import org.eclipse.pde.core.plugin.IPluginExtension; 24 import org.eclipse.pde.core.plugin.IPluginModelBase; 25 import org.eclipse.pde.core.plugin.PluginRegistry; 26 import org.eclipse.pde.core.plugin.TargetPlatform; 27 import org.eclipse.pde.internal.core.util.IdUtil; 28 import org.eclipse.pde.internal.ui.IPDEUIConstants; 29 import org.eclipse.pde.internal.ui.PDELabelProvider; 30 import org.eclipse.pde.internal.ui.PDEPlugin; 31 import org.eclipse.pde.internal.ui.PDEPluginImages; 32 import org.eclipse.pde.internal.ui.PDEUIMessages; 33 import org.eclipse.pde.internal.ui.elements.NamedElement; 34 import org.eclipse.pde.ui.launcher.EclipseLaunchShortcut; 35 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 36 import org.eclipse.swt.graphics.Image; 37 38 public class EclipsePluginValidationOperation extends LaunchValidationOperation { 39 40 private Map fExtensionErrors = new HashMap (2); 41 private static Object [] EMPTY = new Object [0]; 42 43 44 public EclipsePluginValidationOperation(ILaunchConfiguration configuration) { 45 super(configuration); 46 } 47 48 protected IPluginModelBase[] getModels() throws CoreException{ 49 return LaunchPluginValidator.getPluginList(fLaunchConfiguration); 50 } 51 52 public void run(IProgressMonitor monitor) throws CoreException { 53 super.run(monitor); 54 if (fExtensionErrors.size() > 0) 55 fExtensionErrors.clear(); 56 validateExtensions(); 57 } 58 59 private void validateExtensions() { 60 try { 61 if (fLaunchConfiguration.getAttribute(IPDELauncherConstants.USE_PRODUCT, false)) { 62 String product = fLaunchConfiguration.getAttribute(IPDELauncherConstants.PRODUCT, (String )null); 63 if (product != null) { 64 validateExtension(product); 65 String application = getApplication(product); 66 if (application != null) 67 validateExtension(application); 68 } 69 } else { 70 String configType = fLaunchConfiguration.getType().getIdentifier(); 71 String attribute = configType.equals(EclipseLaunchShortcut.CONFIGURATION_TYPE) 72 ? IPDELauncherConstants.APPLICATION : IPDELauncherConstants.APP_TO_TEST; 73 String application = fLaunchConfiguration.getAttribute(attribute, TargetPlatform.getDefaultApplication()); 74 if (!IPDEUIConstants.CORE_TEST_APPLICATION.equals(application)) { 75 validateExtension(application); 76 } 77 } 78 } catch (CoreException e) { 79 PDEPlugin.log(e); 80 } 81 } 82 83 private String getApplication(String product) { 84 String bundleID = product.substring(0, product.lastIndexOf('.')); 85 BundleDescription bundle = getState().getBundle(bundleID, null); 86 if (bundle != null) { 87 IPluginModelBase model = PluginRegistry.findModel(bundle); 88 if (model != null) { 89 IPluginExtension[] extensions = model.getPluginBase().getExtensions(); 90 for (int i = 0; i < extensions.length; i++) { 91 IPluginExtension ext = extensions[i]; 92 String point = ext.getPoint(); 93 if ("org.eclipse.core.runtime.products".equals(point) && product.equals(IdUtil.getFullId(ext))) { 95 if (ext.getChildCount() == 1) { 96 IPluginElement prod = (IPluginElement)ext.getChildren()[0]; 97 if (prod.getName().equals("product")) { IPluginAttribute attr = prod.getAttribute("application"); return attr != null ? attr.getValue() : null; 100 } 101 } 102 } 103 } 104 } 105 } 106 return null; 107 } 108 109 private void validateExtension(String id) { 110 String bundleID = id.substring(0, id.lastIndexOf('.')); 111 BundleDescription bundle = getState().getBundle(bundleID, null); 112 if (bundle == null) { 113 String name = NLS.bind(PDEUIMessages.EclipsePluginValidationOperation_pluginMissing, bundleID); 114 PDELabelProvider provider = PDEPlugin.getDefault().getLabelProvider(); 115 Image image = provider.get(PDEPluginImages.DESC_PLUGIN_OBJ); 116 fExtensionErrors.put(new NamedElement(name, image), EMPTY); 117 } 118 } 119 120 public boolean hasErrors() { 121 return super.hasErrors() || fExtensionErrors.size() >= 1; 122 } 123 124 public Map getInput() { 125 Map map = super.getInput(); 126 map.putAll(fExtensionErrors); 127 return map; 128 } 129 130 } 131 | Popular Tags |