mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 481352 - Adapt Qt and Arduino providers to ILaunchTargets
ILaunchTarget replaces IRemoteConnection. Change-Id: I77825ae1347cec7095655548e06cb6dbc5c2aaf4
This commit is contained in:
parent
19cd53ec10
commit
790f90ee55
9 changed files with 194 additions and 22 deletions
|
@ -20,32 +20,31 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.launchbar.core.AbstractLaunchConfigProvider;
|
import org.eclipse.launchbar.core.AbstractLaunchConfigProvider;
|
||||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch config provider for Qt projects running on the Local connection. Simply uses the C++ Application launch config
|
* Launch config provider for Qt projects running on the Local connection.
|
||||||
* type.
|
* Simply uses the C++ Application launch config type.
|
||||||
*/
|
*/
|
||||||
public class QtLocalLaunchConfigProvider extends AbstractLaunchConfigProvider {
|
public class QtLocalLaunchConfigProvider extends AbstractLaunchConfigProvider {
|
||||||
|
|
||||||
private static final String localConnectionTypeId = "org.eclipse.remote.LocalServices"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
private Map<IProject, ILaunchConfiguration> configs = new HashMap<>();
|
private Map<IProject, ILaunchConfiguration> configs = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||||
return localConnectionTypeId.equals(target.getConnectionType().getId());
|
return ILaunchTargetManager.localLaunchTargetTypeId.equals(target.getTypeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
return DebugPlugin.getDefault().getLaunchManager()
|
return DebugPlugin.getDefault().getLaunchManager()
|
||||||
.getLaunchConfigurationType(QtLocalRunLaunchConfigDelegate.TYPE_ID);
|
.getLaunchConfigurationType(QtLocalRunLaunchConfigDelegate.TYPE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
ILaunchConfiguration config = configs.get(descriptor);
|
ILaunchConfiguration config = configs.get(descriptor);
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
|
@ -56,7 +55,7 @@ public class QtLocalLaunchConfigProvider extends AbstractLaunchConfigProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target,
|
||||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ public class QtLocalLaunchConfigProvider extends AbstractLaunchConfigProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchTargetRemoved(IRemoteConnection target) throws CoreException {
|
public void launchTargetRemoved(ILaunchTarget target) throws CoreException {
|
||||||
// nothing to do since the Local connection can't be removed
|
// nothing to do since the Local connection can't be removed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,6 +107,13 @@
|
||||||
type="org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration">
|
type="org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration">
|
||||||
</adapter>
|
</adapter>
|
||||||
</factory>
|
</factory>
|
||||||
|
<factory
|
||||||
|
adaptableType="org.eclipse.launchbar.core.target.ILaunchTarget"
|
||||||
|
class="org.eclipse.cdt.arduino.core.internal.remote.ArduinoTargetAdapterFactory">
|
||||||
|
<adapter
|
||||||
|
type="org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection">
|
||||||
|
</adapter>
|
||||||
|
</factory>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.cdt.core.ToolChainFactory">
|
point="org.eclipse.cdt.core.ToolChainFactory">
|
||||||
|
@ -115,4 +122,11 @@
|
||||||
family="Arduino GCC">
|
family="Arduino GCC">
|
||||||
</factory>
|
</factory>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.launchbar.core.launchTargetTypes">
|
||||||
|
<launchTargetType
|
||||||
|
id="org.eclipse.cdt.arduino.core.connectionType"
|
||||||
|
provider="org.eclipse.cdt.arduino.core.internal.remote.ArduinoLaunchTargetProvider">
|
||||||
|
</launchTargetType>
|
||||||
|
</extension>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.arduino.core.internal;
|
package org.eclipse.cdt.arduino.core.internal;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnectionListener;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Plugin;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.framework.ServiceReference;
|
import org.osgi.framework.ServiceReference;
|
||||||
|
|
||||||
|
@ -43,9 +45,13 @@ public class Activator extends Plugin {
|
||||||
|
|
||||||
public void start(BundleContext bundleContext) throws Exception {
|
public void start(BundleContext bundleContext) throws Exception {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
IRemoteServicesManager remoteManager = getService(IRemoteServicesManager.class);
|
||||||
|
remoteManager.addRemoteConnectionChangeListener(ArduinoRemoteConnectionListener.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(BundleContext bundleContext) throws Exception {
|
public void stop(BundleContext bundleContext) throws Exception {
|
||||||
|
IRemoteServicesManager remoteManager = getService(IRemoteServicesManager.class);
|
||||||
|
remoteManager.removeRemoteConnectionChangeListener(ArduinoRemoteConnectionListener.INSTANCE);
|
||||||
plugin = null;
|
plugin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,26 +21,25 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||||
import org.eclipse.launchbar.core.ProjectPerTargetLaunchConfigProvider;
|
import org.eclipse.launchbar.core.ProjectPerTargetLaunchConfigProvider;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
|
||||||
|
|
||||||
public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchConfigProvider {
|
public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchConfigProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target)
|
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
return DebugPlugin.getDefault().getLaunchManager()
|
return DebugPlugin.getDefault().getLaunchManager()
|
||||||
.getLaunchConfigurationType(ArduinoLaunchConfigurationDelegate.TYPE_ID);
|
.getLaunchConfigurationType(ArduinoLaunchConfigurationDelegate.TYPE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException {
|
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
|
||||||
if (!super.supports(descriptor, target)) {
|
if (!super.supports(descriptor, target)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target != null && !target.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
if (target != null && !target.getTypeId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchCo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target,
|
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target,
|
||||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
|
@ -59,14 +58,13 @@ public class ArduinoLaunchConfigurationProvider extends ProjectPerTargetLaunchCo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException {
|
protected ILaunchTarget getLaunchTarget(ILaunchConfiguration configuration) throws CoreException {
|
||||||
String name = configuration.getAttribute(ArduinoLaunchConfigurationDelegate.CONNECTION_NAME, ""); //$NON-NLS-1$
|
String name = configuration.getAttribute(ArduinoLaunchConfigurationDelegate.CONNECTION_NAME, ""); //$NON-NLS-1$
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
ILaunchTargetManager manager = Activator.getService(ILaunchTargetManager.class);
|
||||||
IRemoteConnectionType type = manager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
return manager.getLaunchTarget(ArduinoRemoteConnection.TYPE_ID, name);
|
||||||
return type.getConnection(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.eclipse.cdt.arduino.core.internal.remote;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTargetProvider;
|
||||||
|
import org.eclipse.launchbar.core.target.TargetStatus;
|
||||||
|
import org.eclipse.launchbar.core.target.TargetStatus.Code;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||||
|
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||||
|
|
||||||
|
public class ArduinoLaunchTargetProvider implements ILaunchTargetProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(ILaunchTargetManager targetManager) {
|
||||||
|
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||||
|
IRemoteConnectionType remoteType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
|
||||||
|
|
||||||
|
// remove any targets that don't have connections
|
||||||
|
for (ILaunchTarget target : targetManager.getLaunchTargetsOfType(ArduinoRemoteConnection.TYPE_ID)) {
|
||||||
|
if (remoteType.getConnection(target.getName()) == null) {
|
||||||
|
targetManager.removeLaunchTarget(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add any targets that are missing
|
||||||
|
for (IRemoteConnection connection : remoteType.getConnections()) {
|
||||||
|
if (targetManager.getLaunchTarget(ArduinoRemoteConnection.TYPE_ID, connection.getName()) == null) {
|
||||||
|
targetManager.addLaunchTarget(ArduinoRemoteConnection.TYPE_ID, connection.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetStatus getStatus(ILaunchTarget target) {
|
||||||
|
ArduinoRemoteConnection connection = target.getAdapter(ArduinoRemoteConnection.class);
|
||||||
|
if (connection.getRemoteConnection().isOpen()) {
|
||||||
|
return TargetStatus.OK_STATUS;
|
||||||
|
} else {
|
||||||
|
return new TargetStatus(Code.ERROR, "Not connected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.cdt.arduino.core.internal.remote;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||||
|
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||||
|
|
||||||
|
public class ArduinoRemoteConnectionListener implements IRemoteConnectionChangeListener {
|
||||||
|
|
||||||
|
public static ArduinoRemoteConnectionListener INSTANCE = new ArduinoRemoteConnectionListener();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||||
|
switch (event.getType()) {
|
||||||
|
case RemoteConnectionChangeEvent.CONNECTION_ADDED:
|
||||||
|
if (event.getConnection().getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||||
|
ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class);
|
||||||
|
targetManager.addLaunchTarget(ArduinoRemoteConnection.TYPE_ID, event.getConnection().getName());
|
||||||
|
}
|
||||||
|
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
||||||
|
if (event.getConnection().getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||||
|
ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class);
|
||||||
|
ILaunchTarget target = targetManager.getLaunchTarget(ArduinoRemoteConnection.TYPE_ID,
|
||||||
|
event.getConnection().getName());
|
||||||
|
if (target != null) {
|
||||||
|
targetManager.removeLaunchTarget(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package org.eclipse.cdt.arduino.core.internal.remote;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||||
|
import org.eclipse.core.runtime.IAdapterFactory;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||||
|
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||||
|
|
||||||
|
public class ArduinoTargetAdapterFactory implements IAdapterFactory {
|
||||||
|
|
||||||
|
private IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
|
||||||
|
if (adaptableObject instanceof ILaunchTarget) {
|
||||||
|
ILaunchTarget target = (ILaunchTarget) adaptableObject;
|
||||||
|
if (target.getTypeId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||||
|
IRemoteConnectionType connectionType = remoteManager.getConnectionType(target.getTypeId());
|
||||||
|
IRemoteConnection connection = connectionType.getConnection(target.getName());
|
||||||
|
if (connection != null) {
|
||||||
|
return (T) connection.getService(ArduinoRemoteConnection.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?>[] getAdapterList() {
|
||||||
|
return new Class<?>[] { ArduinoRemoteConnection.class };
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -90,4 +90,11 @@
|
||||||
name="Boards">
|
name="Boards">
|
||||||
</page>
|
</page>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.launchbar.ui.launchTargetTypeUI">
|
||||||
|
<launchTargetTypeUI
|
||||||
|
id="org.eclipse.cdt.arduino.core.connectionType"
|
||||||
|
labelProvider="org.eclipse.cdt.arduino.ui.internal.remote.ArduinoLaunchTargetLabelProvider">
|
||||||
|
</launchTargetTypeUI>
|
||||||
|
</extension>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.eclipse.cdt.arduino.ui.internal.remote;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
|
||||||
|
import org.eclipse.cdt.arduino.ui.internal.Activator;
|
||||||
|
import org.eclipse.jface.viewers.LabelProvider;
|
||||||
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
|
||||||
|
public class ArduinoLaunchTargetLabelProvider extends LabelProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText(Object element) {
|
||||||
|
if (element instanceof ILaunchTarget) {
|
||||||
|
return ((ILaunchTarget) element).getName();
|
||||||
|
}
|
||||||
|
return super.getText(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Image getImage(Object element) {
|
||||||
|
if (element instanceof ILaunchTarget
|
||||||
|
&& ((ILaunchTarget) element).getTypeId().equals(ArduinoRemoteConnection.TYPE_ID)) {
|
||||||
|
return Activator.getDefault().getImageRegistry().get(Activator.IMG_ARDUINO);
|
||||||
|
}
|
||||||
|
return super.getImage(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue