mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-02 22:55:26 +02:00
Bug 484993 - Add support for IRemoteConnection launch targets.
Creates a new core plug-in that bridges the gap between ILaunchTarget and IRemoteConnection. Also adds unique id's to ILaunchTarget that are separate from the user visible name. This is to allow for unique names in o.e.remote which include the connection type and the connection name. The launch target type is for all o.e.remote targets. Change-Id: I08d4c3534fc0947f946bfcdec3f13df04fc4ec98
This commit is contained in:
parent
b63caf6c72
commit
2b373042a4
20 changed files with 500 additions and 27 deletions
|
@ -0,0 +1,90 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
|
||||
public abstract class ProjectLaunchConfigProvider extends AbstractLaunchConfigProvider {
|
||||
|
||||
private Map<IProject, ILaunchConfiguration> configs = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target)
|
||||
throws CoreException {
|
||||
ILaunchConfiguration config = null;
|
||||
IProject project = descriptor.getAdapter(IProject.class);
|
||||
if (project != null) {
|
||||
config = configs.get(project);
|
||||
if (config == null) {
|
||||
config = createLaunchConfiguration(descriptor, target);
|
||||
// launch config added will get called below to add it to the
|
||||
// configs map
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target,
|
||||
ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
|
||||
super.populateLaunchConfiguration(descriptor, target, workingCopy);
|
||||
|
||||
// Set the project
|
||||
workingCopy.setMappedResources(new IResource[] { descriptor.getAdapter(IProject.class) });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||
if (ownsLaunchConfiguration(configuration)) {
|
||||
IProject project = configuration.getMappedResources()[0].getProject();
|
||||
configs.put(project, configuration);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||
for (Entry<IProject, ILaunchConfiguration> entry : configs.entrySet()) {
|
||||
if (configuration.equals(entry.getValue())) {
|
||||
configs.remove(entry.getKey());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException {
|
||||
IProject project = descriptor.getAdapter(IProject.class);
|
||||
if (project != null) {
|
||||
configs.remove(project);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchTargetRemoved(ILaunchTarget target) throws CoreException {
|
||||
// nothing to do since this provider isn't associated with a single
|
||||
// target.
|
||||
}
|
||||
|
||||
}
|
|
@ -730,7 +730,9 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
|||
// 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);
|
||||
if (configuration != null) {
|
||||
launchTargetManager.setDefaultLaunchTarget(configuration, activeLaunchTarget);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
|
|
@ -13,13 +13,20 @@ import org.eclipse.launchbar.core.target.ILaunchTarget;
|
|||
public class LaunchTarget extends PlatformObject implements ILaunchTarget {
|
||||
|
||||
private final String typeId;
|
||||
private final String id;
|
||||
private final String name;
|
||||
|
||||
public LaunchTarget(String typeId, String name) {
|
||||
public LaunchTarget(String typeId, String id, String name) {
|
||||
this.typeId = typeId;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -34,7 +41,7 @@ public class LaunchTarget extends PlatformObject implements ILaunchTarget {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((typeId == null) ? 0 : typeId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
@ -48,10 +55,10 @@ public class LaunchTarget extends PlatformObject implements ILaunchTarget {
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LaunchTarget other = (LaunchTarget) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
if (typeId == null) {
|
||||
if (other.typeId != null)
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
|
@ -37,7 +38,9 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
private Map<String, ILaunchTargetProvider> typeProviders = new HashMap<>();
|
||||
private List<ILaunchTargetListener> listeners = new LinkedList<>();
|
||||
|
||||
private static final String DELIMETER = ","; //$NON-NLS-1$
|
||||
private static final String DELIMETER1 = ","; //$NON-NLS-1$
|
||||
private static final String DELIMETER2 = "!"; //$NON-NLS-1$
|
||||
private static final String DELIMETER3 = ":"; //$NON-NLS-1$
|
||||
|
||||
private Preferences getTargetsPref() {
|
||||
return InstanceScope.INSTANCE.getNode(Activator.getDefault().getBundle().getSymbolicName())
|
||||
|
@ -71,8 +74,13 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
targets.put(typeId, type);
|
||||
}
|
||||
|
||||
for (String name : prefs.get(typeId, "").split(DELIMETER)) { //$NON-NLS-1$
|
||||
type.put(name, new LaunchTarget(typeId, name));
|
||||
for (String name : prefs.get(typeId, "").split(DELIMETER1)) { //$NON-NLS-1$
|
||||
if (name.contains(DELIMETER2)) {
|
||||
String[] list = name.split(DELIMETER2);
|
||||
type.put(list[0], new LaunchTarget(typeId, list[0], list[1]));
|
||||
} else {
|
||||
type.put(name, new LaunchTarget(typeId, name, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (BackingStoreException e) {
|
||||
|
@ -139,11 +147,11 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ILaunchTarget getLaunchTarget(String typeId, String name) {
|
||||
public ILaunchTarget getLaunchTarget(String typeId, String id) {
|
||||
initTargets();
|
||||
Map<String, ILaunchTarget> type = targets.get(typeId);
|
||||
if (type != null) {
|
||||
return type.get(name);
|
||||
return type.get(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -154,7 +162,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ILaunchTarget addLaunchTarget(String typeId, String name) {
|
||||
public ILaunchTarget addLaunchTarget(String typeId, String id, String name) {
|
||||
initTargets();
|
||||
Map<String, ILaunchTarget> type = targets.get(typeId);
|
||||
if (type == null) {
|
||||
|
@ -162,9 +170,11 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
targets.put(typeId, type);
|
||||
}
|
||||
|
||||
ILaunchTarget target = new LaunchTarget(typeId, name);
|
||||
type.put(name, target);
|
||||
getTargetsPref().put(typeId, String.join(DELIMETER, type.keySet()));
|
||||
ILaunchTarget target = new LaunchTarget(typeId, id, name);
|
||||
type.put(id, target);
|
||||
|
||||
getTargetsPref().put(typeId, type.values().stream().map(t -> t.getId() + DELIMETER2 + t.getName())
|
||||
.collect(Collectors.joining(DELIMETER1)));
|
||||
|
||||
for (ILaunchTargetListener listener : listeners) {
|
||||
listener.launchTargetAdded(target);
|
||||
|
@ -183,7 +193,8 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
targets.remove(target.getTypeId());
|
||||
getTargetsPref().remove(target.getTypeId());
|
||||
} else {
|
||||
getTargetsPref().put(target.getTypeId(), String.join(DELIMETER, type.keySet()));
|
||||
getTargetsPref().put(target.getTypeId(), type.values().stream()
|
||||
.map(t -> t.getId() + DELIMETER2 + t.getName()).collect(Collectors.joining(DELIMETER1)));
|
||||
}
|
||||
|
||||
for (ILaunchTargetListener listener : listeners) {
|
||||
|
@ -204,7 +215,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
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$
|
||||
String[] parts = targetId.split(DELIMETER3);
|
||||
return getLaunchTarget(parts[0], parts[1]);
|
||||
}
|
||||
return null;
|
||||
|
@ -213,7 +224,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
|
|||
@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$
|
||||
String targetId = String.join(DELIMETER3, target.getTypeId(), target.getId());
|
||||
prefs.put(configuration.getName(), targetId);
|
||||
try {
|
||||
prefs.flush();
|
||||
|
|
|
@ -19,7 +19,8 @@ public class LocalLaunchTargetProvider implements ILaunchTargetProvider {
|
|||
public void init(ILaunchTargetManager targetManager) {
|
||||
if (targetManager.getLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId,
|
||||
Messages.LocalTarget_name) == null) {
|
||||
targetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, Messages.LocalTarget_name);
|
||||
targetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, Messages.LocalTarget_name,
|
||||
Messages.LocalTarget_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,17 @@ import org.eclipse.launchbar.core.internal.target.LaunchTarget;
|
|||
* @noimplement not to be implemented by clients
|
||||
*/
|
||||
public interface ILaunchTarget extends IAdaptable {
|
||||
public static final ILaunchTarget NULL_TARGET = new LaunchTarget("null", "---");
|
||||
public static final ILaunchTarget NULL_TARGET = new LaunchTarget("null", "null", "---");
|
||||
|
||||
/**
|
||||
* The name of the target.
|
||||
* The id for the target. It is unique for each type.
|
||||
*
|
||||
* @return id for the target.
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* The user consumable name of the target.
|
||||
*
|
||||
* @return name of the target
|
||||
*/
|
||||
|
|
|
@ -45,11 +45,11 @@ public interface ILaunchTargetManager {
|
|||
*
|
||||
* @param typeId
|
||||
* type of the launch target
|
||||
* @param name
|
||||
* name of the launch target
|
||||
* @param id
|
||||
* id of the launch target
|
||||
* @return the launch target
|
||||
*/
|
||||
ILaunchTarget getLaunchTarget(String typeId, String name);
|
||||
ILaunchTarget getLaunchTarget(String typeId, String id);
|
||||
|
||||
/**
|
||||
* Return the status of the launch target.
|
||||
|
@ -61,7 +61,21 @@ public interface ILaunchTargetManager {
|
|||
TargetStatus getStatus(ILaunchTarget target);
|
||||
|
||||
/**
|
||||
* Add a launch target with the given typeId and name.
|
||||
* Add a launch target with the given typeId, id, and name.
|
||||
*
|
||||
* @param typeId
|
||||
* type id of the launch target
|
||||
* @param id
|
||||
* id for the target.
|
||||
* @param name
|
||||
* name of the launch target
|
||||
* @return the created launch target
|
||||
*/
|
||||
ILaunchTarget addLaunchTarget(String typeId, String id, String name);
|
||||
|
||||
/**
|
||||
* Add a launch target with the given typeId and name. The name is also the
|
||||
* id for the target.
|
||||
*
|
||||
* @param typeId
|
||||
* type id of the launch target
|
||||
|
@ -69,7 +83,9 @@ public interface ILaunchTargetManager {
|
|||
* name of the launch target
|
||||
* @return the created launch target
|
||||
*/
|
||||
ILaunchTarget addLaunchTarget(String typeId, String name);
|
||||
default ILaunchTarget addLaunchTarget(String typeId, String name) {
|
||||
return addLaunchTarget(typeId, name, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a launch target.
|
||||
|
@ -96,7 +112,7 @@ public interface ILaunchTargetManager {
|
|||
ILaunchTarget getDefaultLaunchTarget(ILaunchConfiguration configuration);
|
||||
|
||||
/**
|
||||
* Set the default target for the given launch configuraiton.
|
||||
* Set the default target for the given launch configuration.
|
||||
*
|
||||
* @param configuration
|
||||
* launch configuration
|
||||
|
|
7
bundles/org.eclipse.launchbar.remote.core/.classpath
Normal file
7
bundles/org.eclipse.launchbar.remote.core/.classpath
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
bundles/org.eclipse.launchbar.remote.core/.project
Normal file
28
bundles/org.eclipse.launchbar.remote.core/.project
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.launchbar.remote.core</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,7 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,12 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: LaunchBar Remote Core
|
||||
Bundle-SymbolicName: org.eclipse.launchbar.remote.core;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: org.eclipse.launchbar.remote.core.internal.Activator
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.launchbar.core;bundle-version="2.0.0",
|
||||
org.eclipse.remote.core;bundle-version="2.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
24
bundles/org.eclipse.launchbar.remote.core/about.html
Normal file
24
bundles/org.eclipse.launchbar.remote.core/about.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
|
||||
|
||||
<body lang="EN-US">
|
||||
<h2>About This Content</h2>
|
||||
|
||||
<p>June 22, 2007</p>
|
||||
<h3>License</h3>
|
||||
|
||||
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
|
||||
indicated below, the Content is provided to you under the terms and conditions of the
|
||||
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
|
||||
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
|
||||
For purposes of the EPL, "Program" will mean the Content.</p>
|
||||
|
||||
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
|
||||
being redistributed by another party ("Redistributor") and different terms and conditions may
|
||||
apply to your use of any object code in the Content. Check the Redistributor's license that was
|
||||
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
|
||||
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
|
||||
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
|
||||
|
||||
</body></html>
|
|
@ -0,0 +1,6 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
about.html,\
|
||||
plugin.xml
|
22
bundles/org.eclipse.launchbar.remote.core/plugin.xml
Normal file
22
bundles/org.eclipse.launchbar.remote.core/plugin.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="org.eclipse.launchbar.core.launchTargetTypes">
|
||||
<launchTargetType
|
||||
id="org.eclipse.launchbar.remote.core.launchTargetType"
|
||||
provider="org.eclipse.launchbar.remote.core.internal.RemoteLaunchTargetProvider">
|
||||
</launchTargetType>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.adapters">
|
||||
<factory
|
||||
adaptableType="org.eclipse.launchbar.core.target.ILaunchTarget"
|
||||
class="org.eclipse.launchbar.remote.core.internal.RemoteTargetAdapterFactory">
|
||||
<adapter
|
||||
type="org.eclipse.remote.core.IRemoteConnection">
|
||||
</adapter>
|
||||
</factory>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* 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.remote.core.internal;
|
||||
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "org.eclipse.launchbar.remote.core"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
private static RemoteConnectionListener remoteConnectionListener;
|
||||
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
|
||||
remoteConnectionListener = new RemoteConnectionListener();
|
||||
getService(IRemoteServicesManager.class).addRemoteConnectionChangeListener(remoteConnectionListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
getService(IRemoteServicesManager.class).removeRemoteConnectionChangeListener(remoteConnectionListener);
|
||||
remoteConnectionListener = null;
|
||||
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static <T> T getService(Class<T> service) {
|
||||
BundleContext context = plugin.getBundle().getBundleContext();
|
||||
ServiceReference<T> ref = context.getServiceReference(service);
|
||||
return ref != null ? context.getService(ref) : null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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.remote.core.internal;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.launchbar.remote.core.internal.messages"; //$NON-NLS-1$
|
||||
public static String RemoteLaunchTargetProvider_Closed;
|
||||
public static String RemoteLaunchTargetProvider_Missing;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*******************************************************************************
|
||||
* 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.remote.core.internal;
|
||||
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||
|
||||
public class RemoteConnectionListener implements IRemoteConnectionChangeListener {
|
||||
|
||||
private ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class);
|
||||
|
||||
@Override
|
||||
public void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||
IRemoteConnection connection = event.getConnection();
|
||||
switch (event.getType()) {
|
||||
case RemoteConnectionChangeEvent.CONNECTION_ADDED:
|
||||
targetManager.addLaunchTarget(RemoteLaunchTargetProvider.TYPE_ID,
|
||||
RemoteLaunchTargetProvider.getTargetId(connection), connection.getName());
|
||||
break;
|
||||
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
||||
ILaunchTarget target = targetManager.getLaunchTarget(RemoteLaunchTargetProvider.TYPE_ID,
|
||||
RemoteLaunchTargetProvider.getTargetId(connection));
|
||||
if (target != null) {
|
||||
targetManager.removeLaunchTarget(target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* 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.remote.core.internal;
|
||||
|
||||
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.IRemoteServicesManager;
|
||||
|
||||
public class RemoteLaunchTargetProvider implements ILaunchTargetProvider {
|
||||
|
||||
static final String TYPE_ID = "org.eclipse.launchbar.remote.core.launchTargetType"; //$NON-NLS-1$
|
||||
static final String DELIMITER = "|"; //$NON-NLS-1$
|
||||
|
||||
private static final TargetStatus CLOSED = new TargetStatus(Code.ERROR, Messages.RemoteLaunchTargetProvider_Closed);
|
||||
|
||||
@Override
|
||||
public void init(ILaunchTargetManager targetManager) {
|
||||
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
||||
|
||||
// Remove missing ones
|
||||
for (ILaunchTarget target : targetManager.getLaunchTargetsOfType(TYPE_ID)) {
|
||||
IRemoteConnection connection = target.getAdapter(IRemoteConnection.class);
|
||||
if (connection == null) {
|
||||
targetManager.removeLaunchTarget(target);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new ones
|
||||
// TODO filter out the Local connection?
|
||||
for (IRemoteConnection connection : manager.getAllRemoteConnections()) {
|
||||
String id = getTargetId(connection);
|
||||
if (targetManager.getLaunchTarget(TYPE_ID, id) == null) {
|
||||
targetManager.addLaunchTarget(TYPE_ID, id, connection.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTargetId(IRemoteConnection connection) {
|
||||
return connection.getConnectionType().getId() + DELIMITER + connection.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetStatus getStatus(ILaunchTarget target) {
|
||||
IRemoteConnection connection = target.getAdapter(IRemoteConnection.class);
|
||||
if (connection != null) {
|
||||
if (connection.isOpen()) {
|
||||
return TargetStatus.OK_STATUS;
|
||||
} else {
|
||||
return CLOSED;
|
||||
}
|
||||
}
|
||||
return new TargetStatus(Code.ERROR, Messages.RemoteLaunchTargetProvider_Missing);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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.remote.core.internal;
|
||||
|
||||
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 RemoteTargetAdapterFactory implements IAdapterFactory {
|
||||
|
||||
private static final IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
|
||||
if (adaptableObject instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) adaptableObject;
|
||||
if (target.getTypeId().equals(RemoteLaunchTargetProvider.TYPE_ID)) {
|
||||
String[] list = target.getId().split("\\" + RemoteLaunchTargetProvider.DELIMITER); //$NON-NLS-1$
|
||||
if (list.length == 2) {
|
||||
IRemoteConnectionType type = manager.getConnectionType(list[0]);
|
||||
if (type != null) {
|
||||
return (T) type.getConnection(list[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAdapterList() {
|
||||
return new Class[] { IRemoteConnection.class };
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#******************************************************************************
|
||||
# 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
|
||||
#******************************************************************************
|
||||
RemoteLaunchTargetProvider_Closed=Closed
|
||||
RemoteLaunchTargetProvider_Missing=Connection missing
|
Loading…
Add table
Reference in a new issue