error checking for OSGi Launcher Also renamed extension point based on Wassim's feedback
diff --git a/ui/org.eclipse.pde.ui/plugin.xml b/ui/org.eclipse.pde.ui/plugin.xml index abd2d68..b48a18d 100644 --- a/ui/org.eclipse.pde.ui/plugin.xml +++ b/ui/org.eclipse.pde.ui/plugin.xml
@@ -8,7 +8,7 @@ <extension-point id="newExtension" name="%expoint.newExtension.name" schema="schema/newExtension.exsd"/> <extension-point id="templates" name="%expoint.templates.name" schema="schema/templates.exsd"/> <extension-point id="samples" name="%expoint.samples.name" schema="schema/samples.exsd"/> - <extension-point id="osgiLauncher" name="%expoint.osgiLauncher.name" schema="schema/osgiLauncher.exsd"/> + <extension-point id="osgiLaunchers" name="%expoint.osgiLauncher.name" schema="schema/osgiLaunchers.exsd"/> <!-- Extensions --> <extension @@ -1973,7 +1973,7 @@ </perspectiveExtension> </extension> <extension - point="org.eclipse.pde.ui.osgiLauncher"> + point="org.eclipse.pde.ui.osgiLaunchers"> <launcher class="org.eclipse.pde.internal.ui.launcher.EquinoxLauncher" id="org.eclipse.pde.ui.EquinoxLauncher"
diff --git a/ui/org.eclipse.pde.ui/schema/osgiLauncher.exsd b/ui/org.eclipse.pde.ui/schema/osgiLaunchers.exsd similarity index 100% rename from ui/org.eclipse.pde.ui/schema/osgiLauncher.exsd rename to ui/org.eclipse.pde.ui/schema/osgiLaunchers.exsd
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java index 9004913..312e998 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
@@ -59,6 +59,14 @@ public static String OSGiBundlesTab_frameworkLabel; + public static String OSGiFrameworkBlock_initializingErrorMessage; + + public static String OSGiFrameworkBlock_initializingErrorTitle; + + public static String OSGiLaunchConfiguration_cannotFindLaunchConfiguration; + + public static String OSGiLaunchConfiguration_selected; + public static String RemoveUnknownExecEnvironments_label; public static String RevertUnsupportSingletonResolution_desc;
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiFrameworkBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiFrameworkBlock.java index c82cb44..309e385 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiFrameworkBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiFrameworkBlock.java
@@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.pde.internal.ui.launcher; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -19,6 +20,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.ui.launcher.AbstractLauncherTab; import org.eclipse.pde.ui.launcher.AbstractOSGiLaunchConfiguration; @@ -58,7 +60,7 @@ public OSGiFrameworkBlock(AbstractLauncherTab tab) { IExtensionRegistry registry = Platform.getExtensionRegistry(); - fConfigElements = orderElements(registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLauncher")); //$NON-NLS-1$ + fConfigElements = orderElements(validateElements(registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLaunchers"))); //$NON-NLS-1$ fTab = tab; fListener = new Listener(); } @@ -76,6 +78,17 @@ return elems; } + private IConfigurationElement[] validateElements(IConfigurationElement[] elems) { + ArrayList list = new ArrayList(elems.length); + for (int i = 0; i < elems.length; i++) { + if (elems[i].getAttribute("id") == null || elems[i].getAttribute("name") == null //$NON-NLS-1$ //$NON-NLS-2$ + || elems[i].getAttribute("class") == null) //$NON-NLS-1$ + continue; + list.add(elems[i]); + } + return (IConfigurationElement[]) list.toArray(new IConfigurationElement[list.size()]); + } + public void createControl(Composite parent) { createFrameworkGroup(parent); createDefaultsGroup(parent); @@ -94,12 +107,18 @@ if (id == null) id = EquinoxLauncher.ID; - for (int i = 0; i < fConfigElements.length; i++) { - if (id.equals(fConfigElements[i].getAttribute("id"))){ //$NON-NLS-1$ - fLauncherCombo.select(i); - return; + for ( int j = 0; j < 2; j++) { + for (int i = 0; i < fConfigElements.length; i++) { + if (id.equals(fConfigElements[i].getAttribute("id"))){ //$NON-NLS-1$ + fLauncherCombo.select(i); + return; + } } + id = EquinoxLauncher.ID; } + // If we can't find equinox, set it to anything + if (fLauncherCombo.getSelectionIndex() == -1) + fLauncherCombo.select(0); } public void performApply(ILaunchConfigurationWorkingCopy config) { @@ -157,13 +176,21 @@ private void setLauncher(ILaunchConfigurationWorkingCopy config) { try { String oldId = config.getAttribute(OSGiLaunchConfiguration.OSGI_ENV_ID, ""); //$NON-NLS-1$ - String newId = fConfigElements[fLauncherCombo.getSelectionIndex()].getAttribute("id"); //$NON-NLS-1$ + int selection = fLauncherCombo.getSelectionIndex(); + if (selection == -1) + return; + String newId = fConfigElements[selection].getAttribute("id"); //$NON-NLS-1$ if (!newId.equals(oldId)) { - AbstractOSGiLaunchConfiguration launcher = (AbstractOSGiLaunchConfiguration) fConfigElements[fLauncherCombo.getSelectionIndex()].createExecutableExtension("class"); //$NON-NLS-1$ - if (launcher != null) { - launcher.initialize(config); + try { config.setAttribute(OSGiLaunchConfiguration.OSGI_ENV_ID, fConfigElements[fLauncherCombo.getSelectionIndex()].getAttribute("id")); //$NON-NLS-1$ - fTab.initializeFrom(config); + AbstractOSGiLaunchConfiguration launcher = (AbstractOSGiLaunchConfiguration) fConfigElements[fLauncherCombo.getSelectionIndex()].createExecutableExtension("class"); //$NON-NLS-1$ + if (launcher != null) { + launcher.initialize(config); + fTab.initializeFrom(config); + } + } catch (Exception e) { + PDEPlugin.logException(e, PDEUIMessages.OSGiFrameworkBlock_initializingErrorTitle, + PDEUIMessages.OSGiFrameworkBlock_initializingErrorMessage); } } } catch (CoreException e) {
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourceLookupDirector.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourceLookupDirector.java index 59710ed..275f5d8 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourceLookupDirector.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourceLookupDirector.java
@@ -31,7 +31,9 @@ public void initializeDefaults(ILaunchConfiguration configuration) throws CoreException { - String id = configuration.getAttribute(OSGiLaunchConfiguration.OSGI_ENV_ID, ""); //$NON-NLS-1$ + String id = configuration.getAttribute(OSGiLaunchConfiguration.OSGI_ENV_ID, (String)null); + if (id == null) + id = EquinoxLauncher.ID; String locatorId = null; locatorId = getFrameworkSourceLocator(id); if (locatorId == null) @@ -45,7 +47,7 @@ private String getFrameworkSourceLocator(String id) { if (id != null) { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLauncher"); //$NON-NLS-1$ + IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLaunchers"); //$NON-NLS-1$ for (int i = 0; i < elements.length; i++) { if (elements[i].getAttribute("id").equals(id)) { //$NON-NLS-1$ String attr = elements[i].getAttribute("sourceLocatorId"); //$NON-NLS-1$
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourcePathComputer.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourcePathComputer.java index 7425b86..c30dec4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourcePathComputer.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiSourcePathComputer.java
@@ -18,6 +18,7 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.sourcelookup.ISourceContainer; import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourcePathComputer; +import org.eclipse.pde.internal.ui.PDEPlugin; import org.eclipse.pde.ui.launcher.AbstractOSGiLaunchConfiguration; import org.eclipse.pde.ui.launcher.OSGiLaunchConfiguration; @@ -41,17 +42,21 @@ if (id != null) { try { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLauncher"); //$NON-NLS-1$ + IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLaunchers"); //$NON-NLS-1$ IConfigurationElement elem = null; for (int i = 0; i < elements.length; i++) { - if (elements[i].getAttribute("id").equals(id)) { //$NON-NLS-1$ + if (id.equals(elements[i].getAttribute("id"))) { //$NON-NLS-1$ elem = elements[i]; break; } } if (elem != null) { - AbstractOSGiLaunchConfiguration launcher= (AbstractOSGiLaunchConfiguration)elem.createExecutableExtension("class"); //$NON-NLS-1$ - return launcher.getSourceContainers(); + try { + AbstractOSGiLaunchConfiguration launcher= (AbstractOSGiLaunchConfiguration)elem.createExecutableExtension("class"); //$NON-NLS-1$ + return launcher.getSourceContainers(); + } catch (Exception e) { + PDEPlugin.log(e); + } } } catch (SecurityException e) { } catch (IllegalArgumentException e) { @@ -61,7 +66,5 @@ } return null; } - - }
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties index 31782d6..3fa4ae6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
@@ -2543,4 +2543,9 @@ PerspectiveTemplate_showViewShortcuts = Add Show View &Shortcuts PerspectiveTemplate_newWizardShortcuts = Add New &Wizard Shortcuts PerspectiveTemplate_actionSets = Add &Menu and Toolbar Contributions (Action Sets) + OSGiBundlesTab_frameworkLabel=OSGi &Framework: +OSGiLaunchConfiguration_cannotFindLaunchConfiguration=Cannot find an AbstractOSGiLauncherConfiguration for the {0} OSGi framework +OSGiLaunchConfiguration_selected=selected +OSGiFrameworkBlock_initializingErrorTitle=Error initializing OSGi launch configuration +OSGiFrameworkBlock_initializingErrorMessage=Problems occurred when initializing launch configuration for the selected OSGi Framework
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/OSGiLaunchConfiguration.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/OSGiLaunchConfiguration.java index c899d06..7cbde20 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/OSGiLaunchConfiguration.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/OSGiLaunchConfiguration.java
@@ -14,10 +14,16 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.internal.ui.IPDEUIConstants; +import org.eclipse.pde.internal.ui.PDEUIMessages; +import org.eclipse.pde.internal.ui.launcher.EquinoxLauncher; /** * A launch delegate for launching OSGi frameworks @@ -33,28 +39,34 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { String id = configuration.getAttribute(OSGI_ENV_ID, (String)null); - if (id != null) { - AbstractOSGiLaunchConfiguration launcher = findLauncher(id); + // if no OSGi Env specified, then launch with Equinox + if (id == null) + id = EquinoxLauncher.ID; + AbstractOSGiLaunchConfiguration launcher = findLauncher(id); + if (launcher != null) launcher.launch(configuration, mode, launch, monitor); - } } - private AbstractOSGiLaunchConfiguration findLauncher(String id ) { + private AbstractOSGiLaunchConfiguration findLauncher(String id ) throws CoreException { IExtensionRegistry registry = Platform.getExtensionRegistry(); - IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLauncher"); //$NON-NLS-1$ + IConfigurationElement[] elements = registry.getConfigurationElementsFor("org.eclipse.pde.ui.osgiLaunchers"); //$NON-NLS-1$ IConfigurationElement elem = null; for (int i = 0; i < elements.length; i++) { - if (elements[i].getAttribute("id").equals(id)) { //$NON-NLS-1$ + if (id.equals(elements[i].getAttribute("id"))) { //$NON-NLS-1$ elem = elements[i]; break; } } - if (elem != null) + if (elem != null) try { return (AbstractOSGiLaunchConfiguration)elem.createExecutableExtension("class"); //$NON-NLS-1$ } catch (CoreException e) { + } catch (ClassCastException e) { } - return null; + String name = (elem == null) ? null : elem.getAttribute("name"); //$NON-NLS-1$ + String message = NLS.bind(PDEUIMessages.OSGiLaunchConfiguration_cannotFindLaunchConfiguration, (name == null) ? PDEUIMessages.OSGiLaunchConfiguration_selected : name); + IStatus status = new Status(IStatus.ERROR, IPDEUIConstants.PLUGIN_ID, IStatus.OK, message , null); + throw new CoreException(status); } }