From 2b373042a4c47763fd9a5ed2f067f3c65e3742cf Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 29 Dec 2015 18:29:56 -0500 Subject: [PATCH] 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 --- .../core/ProjectLaunchConfigProvider.java | 90 +++++++++++++++++++ .../core/internal/LaunchBarManager.java | 4 +- .../core/internal/target/LaunchTarget.java | 17 ++-- .../internal/target/LaunchTargetManager.java | 35 +++++--- .../target/LocalLaunchTargetProvider.java | 3 +- .../launchbar/core/target/ILaunchTarget.java | 11 ++- .../core/target/ILaunchTargetManager.java | 28 ++++-- .../.classpath | 7 ++ .../.project | 28 ++++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 12 +++ .../about.html | 24 +++++ .../build.properties | 6 ++ .../plugin.xml | 22 +++++ .../remote/core/internal/Activator.java | 56 ++++++++++++ .../remote/core/internal/Messages.java | 23 +++++ .../internal/RemoteConnectionListener.java | 38 ++++++++ .../internal/RemoteLaunchTargetProvider.java | 64 +++++++++++++ .../internal/RemoteTargetAdapterFactory.java | 43 +++++++++ .../remote/core/internal/messages.properties | 9 ++ 20 files changed, 500 insertions(+), 27 deletions(-) create mode 100644 bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectLaunchConfigProvider.java create mode 100644 bundles/org.eclipse.launchbar.remote.core/.classpath create mode 100644 bundles/org.eclipse.launchbar.remote.core/.project create mode 100644 bundles/org.eclipse.launchbar.remote.core/.settings/org.eclipse.jdt.core.prefs create mode 100644 bundles/org.eclipse.launchbar.remote.core/META-INF/MANIFEST.MF create mode 100644 bundles/org.eclipse.launchbar.remote.core/about.html create mode 100644 bundles/org.eclipse.launchbar.remote.core/build.properties create mode 100644 bundles/org.eclipse.launchbar.remote.core/plugin.xml create mode 100644 bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Activator.java create mode 100644 bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Messages.java create mode 100644 bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteConnectionListener.java create mode 100644 bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteLaunchTargetProvider.java create mode 100644 bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteTargetAdapterFactory.java create mode 100644 bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/messages.properties diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectLaunchConfigProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectLaunchConfigProvider.java new file mode 100644 index 00000000000..7d3dae8bb00 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectLaunchConfigProvider.java @@ -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 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 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. + } + +} 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 67738817eb0..5f5e48d08f1 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 @@ -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; } diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java index 49c6e4ef0b3..a5b7da1f75a 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java @@ -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) 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 69fefabb0a9..26a6b9640a9 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 @@ -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 typeProviders = new HashMap<>(); private List 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 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 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(); diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java index eb7c130e6fe..701231b83f7 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java @@ -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); } } diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java index 99817fc4689..3c3215a49a4 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java @@ -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 */ 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 4e792874287..db1510f6a27 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 @@ -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 diff --git a/bundles/org.eclipse.launchbar.remote.core/.classpath b/bundles/org.eclipse.launchbar.remote.core/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.eclipse.launchbar.remote.core/.project b/bundles/org.eclipse.launchbar.remote.core/.project new file mode 100644 index 00000000000..74f0f93e954 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.launchbar.remote.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.eclipse.launchbar.remote.core/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.launchbar.remote.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/org.eclipse.launchbar.remote.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.launchbar.remote.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..436092919fc --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.eclipse.launchbar.remote.core/about.html b/bundles/org.eclipse.launchbar.remote.core/about.html new file mode 100644 index 00000000000..d7c511887d6 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/about.html @@ -0,0 +1,24 @@ + + +About + + +

About This Content

+ +

June 22, 2007

+

License

+ +

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 http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

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 http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/bundles/org.eclipse.launchbar.remote.core/build.properties b/bundles/org.eclipse.launchbar.remote.core/build.properties new file mode 100644 index 00000000000..bdcc25a2886 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.xml diff --git a/bundles/org.eclipse.launchbar.remote.core/plugin.xml b/bundles/org.eclipse.launchbar.remote.core/plugin.xml new file mode 100644 index 00000000000..d8af7c00df5 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Activator.java b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Activator.java new file mode 100644 index 00000000000..13fa89635b7 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Activator.java @@ -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 getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + +} diff --git a/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Messages.java b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Messages.java new file mode 100644 index 00000000000..9ef2e4f98a3 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/Messages.java @@ -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() { + } +} diff --git a/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteConnectionListener.java b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteConnectionListener.java new file mode 100644 index 00000000000..026b1725889 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteConnectionListener.java @@ -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; + } + } + +} diff --git a/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteLaunchTargetProvider.java b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteLaunchTargetProvider.java new file mode 100644 index 00000000000..1fee2b5576f --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteLaunchTargetProvider.java @@ -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); + } + +} diff --git a/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteTargetAdapterFactory.java b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteTargetAdapterFactory.java new file mode 100644 index 00000000000..2bd8c032518 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/RemoteTargetAdapterFactory.java @@ -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 getAdapter(Object adaptableObject, Class 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 }; + } + +} diff --git a/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/messages.properties b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/messages.properties new file mode 100644 index 00000000000..1cd2d0574f1 --- /dev/null +++ b/bundles/org.eclipse.launchbar.remote.core/src/org/eclipse/launchbar/remote/core/internal/messages.properties @@ -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