diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java index 80b6cccacc9..5fbca406d0b 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java @@ -26,22 +26,39 @@ public class Activator extends Plugin { public static final String PLUGIN_ID = "org.eclipse.launchbar.core"; //$NON-NLS-1$ private static Activator plugin; + private static LaunchTargetManager launchTargetManager; + private static LaunchBarManager launchBarManager; + public void start(BundleContext bundleContext) throws Exception { super.start(bundleContext); plugin = this; - bundleContext.registerService(ILaunchTargetManager.class, new LaunchTargetManager(), null); - bundleContext.registerService(ILaunchBarManager.class, new LaunchBarManager(), null); + + launchTargetManager = new LaunchTargetManager(); + bundleContext.registerService(ILaunchTargetManager.class, launchTargetManager, null); + + launchBarManager = new LaunchBarManager(); + bundleContext.registerService(ILaunchBarManager.class, launchBarManager, null); } public void stop(BundleContext bundleContext) throws Exception { super.stop(bundleContext); plugin = null; + launchTargetManager = null; + launchBarManager = null; } public static Activator getDefault() { return plugin; } + public static LaunchBarManager getLaunchBarManager() { + return launchBarManager; + } + + public static LaunchTargetManager getLaunchTargetManager() { + return launchTargetManager; + } + /** * Return the OSGi service with the given service interface. * 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 312dd7e4940..67738817eb0 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 @@ -725,7 +725,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene } public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException { - return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget); + ILaunchConfiguration configuration = getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget); + + // This is the only concrete time we have the mapping from launch + // configuration to launch target. Record it in the target manager for + // the launch delegates to use. + launchTargetManager.setDefaultLaunchTarget(configuration, activeLaunchTarget); + + return configuration; } public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java index d08ce033232..69fefabb0a9 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.launchbar.core.internal.Activator; import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.core.target.ILaunchTargetListener; @@ -198,6 +199,29 @@ public class LaunchTargetManager implements ILaunchTargetManager { } } + @Override + public ILaunchTarget getDefaultLaunchTarget(ILaunchConfiguration configuration) { + Preferences prefs = getTargetsPref().node("configs"); //$NON-NLS-1$ + String targetId = prefs.get(configuration.getName(), null); + if (targetId != null) { + String[] parts = targetId.split(":"); //$NON-NLS-1$ + return getLaunchTarget(parts[0], parts[1]); + } + return null; + } + + @Override + public void setDefaultLaunchTarget(ILaunchConfiguration configuration, ILaunchTarget target) { + Preferences prefs = getTargetsPref().node("configs"); //$NON-NLS-1$ + String targetId = String.join(":", target.getTypeId(), target.getName()); //$NON-NLS-1$ + prefs.put(configuration.getName(), targetId); + try { + prefs.flush(); + } catch (BackingStoreException e) { + Activator.log(e); + } + } + @Override public void addListener(ILaunchTargetListener listener) { listeners.add(listener); diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java index 86dbe5e4ff4..4e792874287 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java @@ -7,6 +7,8 @@ *******************************************************************************/ package org.eclipse.launchbar.core.target; +import org.eclipse.debug.core.ILaunchConfiguration; + /** * The manager for the launch targets. It is registered as an OSGi service. * @@ -84,6 +86,25 @@ public interface ILaunchTargetManager { */ void targetStatusChanged(ILaunchTarget target); + /** + * What is the default target to use for this launch configuration. + * + * @param configuration + * launch configuration or null if not set + * @return default target for this launch configuration + */ + ILaunchTarget getDefaultLaunchTarget(ILaunchConfiguration configuration); + + /** + * Set the default target for the given launch configuraiton. + * + * @param configuration + * launch configuration + * @param target + * default target for this launch configuration + */ + void setDefaultLaunchTarget(ILaunchConfiguration configuration, ILaunchTarget target); + /** * Add a listener. * diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/LaunchConfigurationTargetedDelegate.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/LaunchConfigurationTargetedDelegate.java new file mode 100644 index 00000000000..4ee845742dd --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/LaunchConfigurationTargetedDelegate.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.launchbar.core.target.launch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.LaunchConfigurationDelegate; +import org.eclipse.launchbar.core.internal.Activator; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +/** + * An implementation of the ILaunchConfigurationTargetedDelegate. + * + * Implements the ILaunchConfigurationDelegate2 interfaces to pick out the + * default target and pass it the targeted delegate methods. + * + * The default for the targeted delegate methods is to call the non targeted + * methods in the super class. + * + */ +public abstract class LaunchConfigurationTargetedDelegate extends LaunchConfigurationDelegate + implements ILaunchConfigurationTargetedDelegate { + + @Override + public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException { + ILaunchTarget target = Activator.getLaunchTargetManager().getDefaultLaunchTarget(configuration); + return getLaunch(configuration, mode, target); + } + + @Override + public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) + throws CoreException { + ILaunchTarget target = Activator.getLaunchTargetManager().getDefaultLaunchTarget(configuration); + return buildForLaunch(configuration, mode, target, monitor); + } + + @Override + public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target, + IProgressMonitor monitor) throws CoreException { + return super.buildForLaunch(configuration, mode, monitor); + } + + public boolean superBuildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) + throws CoreException { + return super.buildForLaunch(configuration, mode, monitor); + } + + @Override + public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) + throws CoreException { + ILaunchTarget target = Activator.getLaunchTargetManager().getDefaultLaunchTarget(configuration); + return preLaunchCheck(configuration, mode, target, monitor); + } + + @Override + public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, ILaunchTarget target, + IProgressMonitor monitor) throws CoreException { + return super.preLaunchCheck(configuration, mode, monitor); + } + + @Override + public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) + throws CoreException { + ILaunchTarget target = Activator.getLaunchTargetManager().getDefaultLaunchTarget(configuration); + return finalLaunchCheck(configuration, mode, target, monitor); + } + + @Override + public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, ILaunchTarget target, + IProgressMonitor monitor) throws CoreException { + return super.finalLaunchCheck(configuration, mode, monitor); + } + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/TargetedLaunch.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/TargetedLaunch.java new file mode 100644 index 00000000000..e022e7b9c37 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/TargetedLaunch.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.launchbar.core.target.launch; + +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.Launch; +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +/** + * A ITargetedLaunch implementation that simply extends the standard Launch + * class to store the launch target. + */ +public class TargetedLaunch extends Launch implements ITargetedLaunch { + + private final ILaunchTarget launchTarget; + + public TargetedLaunch(ILaunchConfiguration launchConfiguration, String mode, ILaunchTarget launchTarget, + ISourceLocator locator) { + super(launchConfiguration, mode, locator); + this.launchTarget = launchTarget; + } + + @Override + public ILaunchTarget getLaunchTarget() { + return launchTarget; + } + +} diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/BuildActiveCommandHandler.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/BuildActiveCommandHandler.java index 2c26c8be95a..e37b944353e 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/BuildActiveCommandHandler.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/BuildActiveCommandHandler.java @@ -35,6 +35,8 @@ import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate2; import org.eclipse.launchbar.core.internal.LaunchBarManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.launch.ILaunchConfigurationTargetedDelegate; import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.Messages; import org.eclipse.swt.widgets.Display; @@ -55,8 +57,9 @@ public class BuildActiveCommandHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { try { LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager(); - final ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration(); - final ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); + ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration(); + ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); + ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); new UIJob(Display.getDefault(), Messages.BuildActiveCommandHandler_0) { @Override @@ -71,12 +74,18 @@ public class BuildActiveCommandHandler extends AbstractHandler { } new Job(Messages.BuildActiveCommandHandler_1) { + @Override + public boolean belongsTo(Object family) { + return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); + } + @Override protected IStatus run(IProgressMonitor monitor) { try { if (config == null) { // Default, build the workspace - ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, + monitor); return Status.OK_STATUS; } @@ -87,8 +96,18 @@ public class BuildActiveCommandHandler extends AbstractHandler { if (delegate == null) delegate = config.getType().getDelegates(modes)[0]; ILaunchConfigurationDelegate configDel = delegate.getDelegate(); - if (configDel instanceof ILaunchConfigurationDelegate2) { - ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel; + if (configDel instanceof ILaunchConfigurationTargetedDelegate) { + ILaunchConfigurationTargetedDelegate configDel2 = (ILaunchConfigurationTargetedDelegate) configDel; + boolean ret; + ret = configDel2.preLaunchCheck(config, mode, target, monitor); + if (!ret) { + return Status.CANCEL_STATUS; + } + if (!configDel2.buildForLaunch(config, mode, target, monitor)) { + return Status.OK_STATUS; + } + } else if (configDel instanceof ILaunchConfigurationDelegate2) { + ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2) configDel; boolean ret; ret = configDel2.preLaunchCheck(config, mode, monitor); if (!ret) { @@ -101,12 +120,15 @@ public class BuildActiveCommandHandler extends AbstractHandler { // Fall through, do a normal build if (projects.isEmpty()) { - ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, + monitor); } else { Collection buildConfigs = getBuildConfigs(projects); - ResourcesPlugin.getWorkspace().build(buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]), + ResourcesPlugin.getWorkspace().build( + buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]), IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor); - // TODO, may need to get the buildReferences argument from the descriptor + // TODO, may need to get the buildReferences + // argument from the descriptor } return Status.OK_STATUS; } catch (CoreException e) { diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java index 3373ce19dfc..78e91221edd 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java @@ -14,42 +14,33 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.launchbar.core.internal.LaunchBarManager; import org.eclipse.launchbar.ui.internal.Activator; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.progress.UIJob; public class LaunchActiveCommandHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - new UIJob(Display.getDefault(), "Launching Active Configuration") { - public IStatus runInUIThread(IProgressMonitor monitor) { - try { - LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager(); - ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration(); - if (config == null) - return Status.OK_STATUS; - ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); - DebugUITools.launch(config, launchMode.getIdentifier()); - } catch (CoreException e) { - return e.getStatus(); - } + try { + LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager(); + ILaunchConfiguration config = launchBarManager.getActiveLaunchConfiguration(); + if (config == null) return Status.OK_STATUS; - }; - }.schedule(); + ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); + DebugUITools.launch(config, launchMode.getIdentifier()); - return Status.OK_STATUS; + return Status.OK_STATUS; + } catch (CoreException e) { + return e.getStatus(); + } } protected String getMode(ILaunchMode launchMode) { - return launchMode.getIdentifier(); //$NON-NLS-1$ + return launchMode.getIdentifier(); } }