mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-05 16:15:25 +02:00
Bug 482938 - Pass LaunchTarget to launch delegates.
Creates a new standard delegate that implements the targeted launch delegate interface introduced earlier. Also provided a standard launch object that stores the launch target to be launched on. Adds storing of the config to target mapping in the launch target manager. Sets that mapping as close to build/launch time as we can. Change-Id: I78a1412af043f0be240d5617fcfc08b81c3fb3ea
This commit is contained in:
parent
9435e1f802
commit
632980a73a
8 changed files with 228 additions and 31 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<IBuildConfiguration> 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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue