From 5fce7bf604de506d9a0d9f429b3483486fd82626 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 19 May 2015 18:49:20 -0400 Subject: [PATCH] Re-add the remote launch config service. PTP is using it. --- .../META-INF/MANIFEST.MF | 1 + .../launch/IRemoteLaunchConfigService.java | 53 +++++++++++++++ .../internal/core/RemoteCorePlugin.java | 3 + .../launch/RemoteLaunchConfigService.java | 65 +++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/launch/IRemoteLaunchConfigService.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/launch/RemoteLaunchConfigService.java diff --git a/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF index 91963849960..0dacec9ee70 100644 --- a/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF @@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0", Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.remote.core, org.eclipse.remote.core.exception, + org.eclipse.remote.core.launch, org.eclipse.remote.internal.core;x-friends:="org.eclipse.remote.ui,org.eclipse.remote.jsch.core", org.eclipse.remote.internal.core.preferences;x-friends:="org.eclipse.remote.ui" Bundle-Localization: plugin diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/launch/IRemoteLaunchConfigService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/launch/IRemoteLaunchConfigService.java new file mode 100644 index 00000000000..db4592a3223 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/launch/IRemoteLaunchConfigService.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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 + * + * Contributors: + * QNX - initial API and implementation + *******************************************************************************/ +package org.eclipse.remote.core.launch; + +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.remote.core.IRemoteConnection; + +/** + * Manages and persists the mapping between launch configurations and + * remote connections that they run on. Each launch configuration has an + * active remote connection. + * + * @since 2.0 + */ +public interface IRemoteLaunchConfigService { + + /** + * Sets the active remote connection for the given launch configuration. + * + * @param launchConfig launch configuration + * @param connection active remote connection + */ + void setActiveConnection(ILaunchConfiguration launchConfig, IRemoteConnection connection); + + /** + * Gets the active remote connection for the given launch configuration + * @param launchConfig launch configuration + * @return active remote connection + */ + IRemoteConnection getActiveConnection(ILaunchConfiguration launchConfig); + + /** + * For a given launch configuration type, get the remote connection that was last + * used by a launch configuration of that type. + * + * This is used for new launch configurations with the assumption that the user + * will want to use the same remote connection. + * + * @param launchConfigType launch configuration type + * @return last active remote configuration + */ + IRemoteConnection getLastActiveConnection(ILaunchConfigurationType launchConfigType); + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java index 4272f87e817..bc564fabee1 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteCorePlugin.java @@ -18,6 +18,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.core.launch.IRemoteLaunchConfigService; +import org.eclipse.remote.internal.core.launch.RemoteLaunchConfigService; import org.eclipse.remote.internal.core.preferences.Preferences; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -108,6 +110,7 @@ public class RemoteCorePlugin extends Plugin { super.start(context); plugin = this; context.registerService(IRemoteServicesManager.class, new RemoteServicesManager(), null); + context.registerService(IRemoteLaunchConfigService.class, new RemoteLaunchConfigService(), null); RemoteDebugOptions.configure(context); ResourcesPlugin.getWorkspace().addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() { @Override diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/launch/RemoteLaunchConfigService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/launch/RemoteLaunchConfigService.java new file mode 100644 index 00000000000..5b2ce2316a2 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/launch/RemoteLaunchConfigService.java @@ -0,0 +1,65 @@ +package org.eclipse.remote.internal.core.launch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.core.launch.IRemoteLaunchConfigService; +import org.eclipse.remote.internal.core.RemoteCorePlugin; +import org.osgi.service.prefs.Preferences; + +public class RemoteLaunchConfigService implements IRemoteLaunchConfigService { + + private static final String REMOTE_LAUNCH_CONFIG = "remoteLaunchConfig"; //$NON-NLS-1$ + private static final String REMOTE_LAUNCH_TYPE = "remoteLaunchType"; //$NON-NLS-1$ + + private Preferences getPreferences(String node) { + return InstanceScope.INSTANCE.getNode(RemoteCorePlugin.getUniqueIdentifier()).node(node); + } + + private IRemoteConnection getRemoteConnection(String remoteId) { + if (remoteId == null) { + return null; + } + + String[] ids = remoteId.split(":"); //$NON-NLS-1$ + if (ids.length < 2) { + return null; + } + + IRemoteServicesManager manager = RemoteCorePlugin.getService(IRemoteServicesManager.class); + IRemoteConnectionType connectionType = manager.getConnectionType(ids[0]); + if (connectionType == null) { + return null; + } + + return connectionType.getConnection(ids[1]); + } + + @Override + public void setActiveConnection(ILaunchConfiguration launchConfig, IRemoteConnection connection) { + String remoteId = connection.getConnectionType().getId() + ":" + connection.getName(); //$NON-NLS-1$ + getPreferences(REMOTE_LAUNCH_CONFIG).put(launchConfig.getName(), remoteId); + try { + getPreferences(REMOTE_LAUNCH_TYPE).put(launchConfig.getType().getIdentifier(), remoteId); + } catch (CoreException e) { + RemoteCorePlugin.log(e.getStatus()); + } + } + + @Override + public IRemoteConnection getActiveConnection(ILaunchConfiguration launchConfig) { + String remoteId = getPreferences(REMOTE_LAUNCH_CONFIG).get(launchConfig.getName(), null); + return getRemoteConnection(remoteId); + } + + @Override + public IRemoteConnection getLastActiveConnection(ILaunchConfigurationType launchConfigType) { + String remoteId = getPreferences(REMOTE_LAUNCH_TYPE).get(launchConfigType.getIdentifier(), null); + return getRemoteConnection(remoteId); + } + +}