From f2b778e3c7a0371346a5bb12e43e1e2a7e171d3c Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Mon, 27 Apr 2015 10:35:54 -0400 Subject: [PATCH] launchbar: active remote connection is not persisted in the remote services - if you select target for given launch config and restart IDE it is not persistent, because it queries remote services and it has not been set. Moving setting of target in the correct place Note: if launch config is not created yet it would not be create and mapping would not be set but it would be persisted by launch bar itself - also added protection against null listener Change-Id: I41f8651ba2251ca9f841450fc1f511643bfde681 --- .../core/internal/LaunchBarManager.java | 34 +++++++++++++------ .../core/internal/LaunchBarManager2Test.java | 5 +-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java index 70cd0a8f4f5..9049d48924e 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java @@ -831,6 +831,15 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration } // per desc store, desc can be null means it store globally setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target))); + // Also we have to store this in remote connection service + try { + ILaunchConfiguration config = getLaunchConfiguration(desc, target, false); + if (config != null) { + remoteLaunchConfigService.setActiveConnection(config, target); + } + } catch (CoreException e) { + Activator.log(e); + } } private void fireActiveLaunchTargetChanged() { @@ -854,18 +863,16 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration } public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException { - ILaunchConfiguration activeConfig = getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget); - if (activeConfig != null) { - // Save the config -> target mapping - // TODO: seems to be weird place for setting this - remoteLaunchConfigService.setActiveConnection(activeConfig, activeLaunchTarget); - } - return activeConfig; + return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget); } - // Don't call this to get the active launch config. Use getActiveLaunchConfiguration(). It ensures that config -> target - // mapping is saved. + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException { + return getLaunchConfiguration(descriptor, target, true); + } + + private ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target, + boolean create) throws CoreException { if (descriptor == null) { return null; } @@ -884,11 +891,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration configMap = new HashMap<>(); configs.put(descriptor, configMap); } - + if (create == false) + return null; // Not found, create, store and return it ILaunchConfiguration config = configProvider.createLaunchConfiguration(getLaunchManager(), descriptor); if (config != null) { configMap.put(configProvider, config); + // since new LC is created we need to associate it with remote target + storeLaunchTarget(descriptor, target); return config; } } @@ -897,10 +907,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration } public void addListener(Listener listener) { + if (listener == null) + return; listeners.add(listener); } public void removeListener(Listener listener) { + if (listener == null) + return; listeners.remove(listener); } diff --git a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java index 307b2ad8447..c1597e1b246 100644 --- a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java +++ b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java @@ -185,6 +185,7 @@ public class LaunchBarManager2Test { ILaunchConfiguration lc = mock(ILaunchConfiguration.class); doReturn(string).when(lc).getName(); doReturn(lctype2).when(lc).getType(); + doReturn("").when(lc).getAttribute(eq(ORIGINAL_NAME), eq("")); return lc; } @@ -580,7 +581,7 @@ public class LaunchBarManager2Test { return "pbtype"; } } - + String ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName"; protected void projectMappingSetup() throws CoreException { descriptorType = new ProjectBasedLaunchDescriptorType(); descriptorTypeId = ((ProjectBasedLaunchDescriptorType) descriptorType).getId(); @@ -599,7 +600,7 @@ public class LaunchBarManager2Test { mockConfigTypeElement(localTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier()); //lc = provider.createLaunchConfiguration(lman, descType.getDescriptor(aaa)); mockLCProject(launchConfig, aaa); - String ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName"; + mockLCAttribute(launchConfig, ORIGINAL_NAME, aaa.getName()); mockProviderElement(provider); assertEquals(0, manager.getLaunchDescriptors().length);