From e97eb96c5dddffa57a11772df33dbac79f98bb96 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 27 Jan 2015 16:06:02 -0500 Subject: [PATCH] Bug 458583 Remote Services v2 API with UI, Local, and JSch updated. v2 of Remote API. New Services architecture. Connections are now stored in preferences and loaded by the framework. Attributes are stored in the preferences. Secure attributes are stored in the secure preferences. Remote services renamed to connection types. Remote connections broken up into services. JSch and Local connection types have been updated to new architecture. Also moved the tests from core.tests to jsch.core.tests since they are actually JSch tests and need to reference attribute names from the jsch.core plug-in. This is just phase one. Many more changes are expected to clean up and to fix bugs this introduces. Change-Id: I62ad2567b0c5ca7d277649879a8d16bec7058d5f Signed-off-by: Doug Schaefer --- .../META-INF/MANIFEST.MF | 10 +- bundles/org.eclipse.remote.core/plugin.xml | 16 +- bundles/org.eclipse.remote.core/pom.xml | 2 +- .../schema/remoteServices.exsd | 112 ++++- .../core/AbstractRemoteConnectionManager.java | 101 ---- .../remote/core/AbstractRemoteServices.java | 66 --- .../core/IRemoteCommandShellService.java | 44 ++ .../remote/core/IRemoteConnection.java | 367 ++++---------- .../core/IRemoteConnectionChangeListener.java | 11 +- .../core/IRemoteConnectionControlService.java | 47 ++ .../IRemoteConnectionPropertyService.java | 41 ++ .../IRemoteConnectionProviderService.java | 30 ++ ...anager.java => IRemoteConnectionType.java} | 98 +++- .../core/IRemoteConnectionWorkingCopy.java | 58 +-- ...leManager.java => IRemoteFileService.java} | 33 +- .../core/IRemotePortForwardingService.java | 101 ++++ .../remote/core/IRemoteProcessService.java | 75 +++ .../eclipse/remote/core/IRemoteServices.java | 48 -- .../core/IRemoteServicesDescriptor.java | 38 -- .../remote/core/IRemoteServicesFactory.java | 26 - .../remote/core/IRemoteServicesManager.java | 94 ++++ ...or.java => IUserAuthenticatorService.java} | 4 +- ....java => RemoteConnectionChangeEvent.java} | 34 +- .../eclipse/remote/core/RemoteServices.java | 100 ---- .../remote/core/RemoteServicesUtils.java | 89 +--- .../exception/ConnectionExistsException.java | 28 ++ .../launch/IRemoteLaunchConfigService.java | 53 +++ .../internal/core/RemoteConnection.java | 200 ++++++++ .../internal/core/RemoteConnectionType.java | 241 ++++++++++ .../core/RemoteConnectionWorkingCopy.java | 303 ++++++++++++ .../internal/core/RemoteCorePlugin.java | 18 + .../core/RemoteServicesDescriptor.java | 134 ------ .../internal/core/RemoteServicesImpl.java | 99 ---- .../internal/core/RemoteServicesManager.java | 183 +++++++ .../launch/RemoteLaunchConfigService.java | 65 +++ .../core/services/local/LocalConnection.java | 413 ---------------- .../local/LocalConnectionManager.java | 99 ---- .../local/LocalConnectionPropertyService.java | 53 +++ .../local/LocalConnectionProviderService.java | 56 +++ .../local/LocalConnectionWorkingCopy.java | 114 ----- .../core/services/local/LocalFileManager.java | 54 +-- .../services/local/LocalProcessService.java | 76 +++ .../core/services/local/LocalServices.java | 58 --- .../services/local/LocalServicesFactory.java | 29 -- .../core/services/local/Messages.java | 15 + .../core/services/local/messages.properties | 1 + .../META-INF/MANIFEST.MF | 2 +- .../org.eclipse.remote.jsch.core/plugin.xml | 38 +- .../remote/internal/jsch/core/Activator.java | 12 + .../internal/jsch/core/JSchConnection.java | 447 +++++------------- .../jsch/core/JSchConnectionAttributes.java | 236 --------- .../jsch/core/JSchConnectionManager.java | 156 ------ .../jsch/core/JSchConnectionProxyFactory.java | 10 +- .../jsch/core/JSchConnectionWorkingCopy.java | 310 ------------ .../internal/jsch/core/JSchFileManager.java | 75 ++- .../jsch/core/JSchProcessBuilder.java | 36 +- .../internal/jsch/core/JSchServices.java | 51 -- .../jsch/core/JSchServicesFactory.java | 26 - .../internal/jsch/core/JschFileStore.java | 36 +- bundles/org.eclipse.remote.jsch.ui/plugin.xml | 21 +- .../remote/internal/jsch/ui/Activator.java | 12 + .../jsch/ui/JSchFileSystemContributor.java | 16 +- ...ager.java => JSchUIConnectionService.java} | 37 +- ...ileManager.java => JSchUIFileService.java} | 27 +- .../internal/jsch/ui/JSchUIServices.java | 78 --- .../jsch/ui/JSchUIServicesFactory.java | 26 - .../jsch/ui/JSchUserAuthenticator.java | 17 +- .../jsch/ui/wizards/JSchConnectionPage.java | 130 +++-- .../jsch/ui/wizards/JSchConnectionWizard.java | 51 +- .../META-INF/MANIFEST.MF | 6 +- .../org.eclipse.remote.ui/icons/new_wiz.gif | Bin 0 -> 612 bytes .../org.eclipse.remote.ui/plugin.properties | 9 +- bundles/org.eclipse.remote.ui/plugin.xml | 180 ++++++- bundles/org.eclipse.remote.ui/pom.xml | 2 +- .../schema/remoteUIServices.exsd | 124 ----- .../eclipse/remote/internal/ui/Messages.java | 20 + .../remote/internal/ui/RemoteUIPlugin.java | 13 + .../ui/RemoteUIServicesDescriptor.java | 107 ----- .../internal/ui/ServicePropertyTester.java | 41 ++ .../remote/internal/ui/messages.properties | 6 + .../ConnectionsPreferencePage.java | 104 ++-- .../RemoteDevelopmentPreferencePage.java | 8 +- ...leManager.java => LocalUIFileService.java} | 27 +- .../ui/services/local/LocalUIServices.java | 76 --- .../local/LocalUIServicesFactory.java | 26 - .../views/DeleteRemoteConnectionHandler.java | 72 +++ .../remote/internal/ui/views/Messages.java | 16 + .../ui/views/NewRemoteConnectionHandler.java | 22 + .../ui/views/NewRemoteConnectionTypePage.java | 96 ++++ .../ui/views/NewRemoteConnectionWizard.java | 62 +++ .../ui/views/OpenTerminalHandler.java | 24 + .../views/RemoteConnectionPropertyPage.java | 48 ++ .../RemoteConnectionsActionProvider.java | 17 + .../RemoteConnectionsContentProvider.java | 87 ++++ .../views/RemoteConnectionsLabelProvider.java | 24 + .../ui/views/RemoteConnectionsView.java | 25 + .../internal/ui/views/messages.properties | 2 + .../ui/AbstractRemoteUIConnectionManager.java | 14 +- ...r.java => IRemoteUIConnectionService.java} | 4 +- .../remote/ui/IRemoteUIConnectionWizard.java | 20 +- ...Manager.java => IRemoteUIFileService.java} | 4 +- .../eclipse/remote/ui/IRemoteUIServices.java | 31 -- .../ui/IRemoteUIServicesDescriptor.java | 31 -- .../remote/ui/IRemoteUIServicesFactory.java | 26 - .../eclipse/remote/ui/RemoteUIServices.java | 125 ----- .../ui/dialogs/RemoteResourceBrowser.java | 14 +- .../ui/widgets/RemoteConnectionWidget.java | 153 +++--- .../ui/widgets/RemoteDirectoryWidget.java | 27 +- .../remote/ui/widgets/RemoteFileWidget.java | 27 +- .../widgets/RemoteResourceBrowserWidget.java | 64 +-- releng/org.eclipse.remote.build/mars.target | 15 + .../META-INF/MANIFEST.MF | 2 + .../remote/core/tests/internal/Activator.java | 36 ++ .../org.eclipse.remote.jsch.tests/.classpath | 7 + .../org.eclipse.remote.jsch.tests/.gitignore | 1 + tests/org.eclipse.remote.jsch.tests/.project | 28 ++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 15 + .../build.properties | 4 + .../eclipse/remote/jsch/tests/Activator.java | 55 +++ .../remote/jsch}/tests/ConnectionTests.java | 89 ++-- .../remote/jsch}/tests/FileStoreTests.java | 77 ++- .../remote/jsch}/tests/ProcessTests.java | 81 ++-- .../jsch/tests}/RemoteCoreTestSuite.java | 6 +- 124 files changed, 3864 insertions(+), 4130 deletions(-) delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteConnectionManager.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteCommandShellService.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionControlService.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionPropertyService.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionProviderService.java rename bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/{IRemoteConnectionManager.java => IRemoteConnectionType.java} (50%) rename bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/{IRemoteFileManager.java => IRemoteFileService.java} (79%) create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePortForwardingService.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteProcessService.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesFactory.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesManager.java rename bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/{IUserAuthenticator.java => IUserAuthenticatorService.java} (97%) rename bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/{IRemoteConnectionChangeEvent.java => RemoteConnectionChangeEvent.java} (71%) delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/exception/ConnectionExistsException.java 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/RemoteConnection.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionType.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionWorkingCopy.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesDescriptor.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesImpl.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesManager.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/launch/RemoteLaunchConfigService.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnection.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionManager.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionProviderService.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionWorkingCopy.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalProcessService.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServices.java delete mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServicesFactory.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/Messages.java create mode 100644 bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/messages.properties delete mode 100644 bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionAttributes.java delete mode 100644 bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionManager.java delete mode 100644 bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionWorkingCopy.java delete mode 100644 bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServices.java delete mode 100644 bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServicesFactory.java rename bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/{JSchUIConnectionManager.java => JSchUIConnectionService.java} (75%) rename bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/{JSchUIFileManager.java => JSchUIFileService.java} (82%) delete mode 100644 bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServices.java delete mode 100644 bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServicesFactory.java create mode 100644 bundles/org.eclipse.remote.ui/icons/new_wiz.gif delete mode 100644 bundles/org.eclipse.remote.ui/schema/remoteUIServices.exsd create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/Messages.java delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIServicesDescriptor.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/ServicePropertyTester.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages.properties rename bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/{LocalUIFileManager.java => LocalUIFileService.java} (80%) delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServices.java delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServicesFactory.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/DeleteRemoteConnectionHandler.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/Messages.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionHandler.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionTypePage.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionWizard.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/OpenTerminalHandler.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionPropertyPage.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsActionProvider.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsContentProvider.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsLabelProvider.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsView.java create mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/messages.properties rename bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/{IRemoteUIConnectionManager.java => IRemoteUIConnectionService.java} (92%) rename bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/{IRemoteUIFileManager.java => IRemoteUIFileService.java} (96%) delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServices.java delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesDescriptor.java delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesFactory.java delete mode 100644 bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/RemoteUIServices.java create mode 100644 releng/org.eclipse.remote.build/mars.target create mode 100644 tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/internal/Activator.java create mode 100644 tests/org.eclipse.remote.jsch.tests/.classpath create mode 100644 tests/org.eclipse.remote.jsch.tests/.gitignore create mode 100644 tests/org.eclipse.remote.jsch.tests/.project create mode 100644 tests/org.eclipse.remote.jsch.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 tests/org.eclipse.remote.jsch.tests/META-INF/MANIFEST.MF create mode 100644 tests/org.eclipse.remote.jsch.tests/build.properties create mode 100644 tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/Activator.java rename tests/{org.eclipse.remote.core.tests/src/org/eclipse/remote/core => org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch}/tests/ConnectionTests.java (58%) rename tests/{org.eclipse.remote.core.tests/src/org/eclipse/remote/core => org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch}/tests/FileStoreTests.java (75%) rename tests/{org.eclipse.remote.core.tests/src/org/eclipse/remote/core => org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch}/tests/ProcessTests.java (69%) rename tests/{org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite => org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests}/RemoteCoreTestSuite.java (63%) diff --git a/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF index ad46d7bfdaf..908862dc222 100644 --- a/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.remote.core/META-INF/MANIFEST.MF @@ -2,20 +2,20 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.remote.core;singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.remote.internal.core.RemoteCorePlugin Bundle-Vendor: %pluginProvider Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.filesystem, org.eclipse.core.resources, - org.eclipse.core.variables + org.eclipse.core.variables, + org.eclipse.debug.core 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.messages;x-internal:=true, - org.eclipse.remote.internal.core.preferences;x-friends:="org.eclipse.remote.ui", - org.eclipse.remote.internal.core.services.local;x-internal:=true + org.eclipse.remote.internal.core.preferences;x-friends:="org.eclipse.remote.ui" Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: org.eclipse.equinox.security.storage diff --git a/bundles/org.eclipse.remote.core/plugin.xml b/bundles/org.eclipse.remote.core/plugin.xml index 649790aaebd..9ed983dc93f 100644 --- a/bundles/org.eclipse.remote.core/plugin.xml +++ b/bundles/org.eclipse.remote.core/plugin.xml @@ -7,12 +7,22 @@ - - + + + + + diff --git a/bundles/org.eclipse.remote.core/pom.xml b/bundles/org.eclipse.remote.core/pom.xml index beb3dbd84f9..542bfe6e278 100644 --- a/bundles/org.eclipse.remote.core/pom.xml +++ b/bundles/org.eclipse.remote.core/pom.xml @@ -11,6 +11,6 @@ org.eclipse.remote.core - 1.0.0-SNAPSHOT + 2.0.0-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.remote.core/schema/remoteServices.exsd b/bundles/org.eclipse.remote.core/schema/remoteServices.exsd index 598fca3e0d2..ad5a5424dd4 100644 --- a/bundles/org.eclipse.remote.core/schema/remoteServices.exsd +++ b/bundles/org.eclipse.remote.core/schema/remoteServices.exsd @@ -17,8 +17,10 @@ - - + + + + @@ -47,11 +49,14 @@ - + + + A connection type. + @@ -71,35 +76,103 @@ - + An EFS scheme name for this service - + - The fully qualified name of the Java class implementing <samp>org.eclipse.remote.core.IRemoteServicesFactory</samp>. + The capabilities of this connection. This an integer created by ORing the applicable capabilities as listed in IRemoteServices. + + + + + + + + + + This is a service that implements the given service interface for a given connection type. + + + + + + + The remote services that this service applies to. - + + + + + + + + The interface class that this service implements. The service is found by calling the getService() method on the IRemoteServices object with this interface class as the parameter. + + + + + + + + + + The factory class used to instantiate the service. + + + + + + + This is a service that implements the given service interface for connections of a given connection type. + + + + + + + The connection type for the connections that this service applies to. + + + + + + + + + + The interface class that this service implements. The service is found by calling the getService() method on the IRemoteConnection object with this interface class as the parameter. + + + + + + + + + + The factory class used to instantiate the service. + + + + + + + + - - - - - - The value of the class attribute must implement <samp>org.eclipse.remote.core.IRemoteServicesFactory</samp>. - - @@ -120,6 +193,15 @@ + + + + + + The value of the class attribute must implement <samp>org.eclipse.remote.core.IRemoteServicesFactory</samp>. + + + diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteConnectionManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteConnectionManager.java deleted file mode 100644 index e3f9a63f6c2..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteConnectionManager.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.core; - -import java.lang.reflect.Constructor; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.remote.internal.core.RemoteCorePlugin; - -/** - * Abstract base class for remote connection managers. - * - * @since 8.0 - */ -public abstract class AbstractRemoteConnectionManager implements IRemoteConnectionManager { - private static final String AUTHENTICATOR_EXTENSION_POINT_ID = "authenticator"; //$NON-NLS-1$ - private static final String ID_ATTR = "id"; //$NON-NLS-1$ - private static final String CLASS_ATTR = "class"; //$NON-NLS-1$ - private static final String PRIORITY_ATTR = "priority"; //$NON-NLS-1$ - - private final IRemoteServices fRemoteServices; - private boolean fLoaded; - private Constructor fUserAuthenticatorConstructor; - - public AbstractRemoteConnectionManager(IRemoteServices services) { - fRemoteServices = services; - } - - protected IRemoteServices getRemoteServices() { - return fRemoteServices; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionManager#getUserAuthenticator() - */ - @Override - public IUserAuthenticator getUserAuthenticator(IRemoteConnection connection) { - if (!fLoaded) { - int currPriority = -1; - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = registry.getExtensionPoint(RemoteCorePlugin.getUniqueIdentifier(), - AUTHENTICATOR_EXTENSION_POINT_ID); - final IExtension[] extensions = extensionPoint.getExtensions(); - - for (IExtension ext : extensions) { - final IConfigurationElement[] elements = ext.getConfigurationElements(); - - for (IConfigurationElement ce : elements) { - String id = ce.getAttribute(ID_ATTR); - if (id.equals(getRemoteServices().getId())) { - int priority = 0; - String priorityAttr = ce.getAttribute(PRIORITY_ATTR); - if (priorityAttr != null) { - try { - priority = Integer.parseInt(priorityAttr); - } catch (NumberFormatException e) { - // Assume default - } - } - if (priority > currPriority) { - try { - String widgetClass = ce.getAttribute(CLASS_ATTR); - Class cls = Platform.getBundle(ce.getDeclaringExtension().getContributor().getName()).loadClass( - widgetClass); - if (cls != null) { - fUserAuthenticatorConstructor = cls.getConstructor(IRemoteConnection.class); - currPriority = priority; - } - } catch (ClassNotFoundException | NoSuchMethodException e) { - RemoteCorePlugin.log(e); - } - } - } - } - } - fLoaded = true; - } - if (fUserAuthenticatorConstructor != null) { - try { - return (IUserAuthenticator) fUserAuthenticatorConstructor.newInstance(connection); - } catch (Exception e) { - RemoteCorePlugin.log(e); - } - } - return null; - } -} \ No newline at end of file diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java deleted file mode 100644 index da4adc4704e..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/AbstractRemoteServices.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.core; - -/** - * Abstract base class for remote services. Implementors can use this class to provide a default implementation of a remote - * services provider. - * - * @since 5.0 - */ -public abstract class AbstractRemoteServices implements IRemoteServices { - - protected final IRemoteServicesDescriptor fDescriptor; - - public AbstractRemoteServices(IRemoteServicesDescriptor descriptor) { - fDescriptor = descriptor; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(IRemoteServicesDescriptor o) { - return fDescriptor.compareTo(o); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesDescriptor#getId() - */ - @Override - public String getId() { - return fDescriptor.getId(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesDescriptor#getName() - */ - @Override - public String getName() { - return fDescriptor.getName(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesDescriptor#getScheme() - */ - @Override - public String getScheme() { - return fDescriptor.getScheme(); - } -} \ No newline at end of file diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteCommandShellService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteCommandShellService.java new file mode 100644 index 00000000000..1f85e18a5e7 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteCommandShellService.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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; + +import java.io.IOException; + +/** + * A service that provides a command shell on a remote. This is mainly used by + * Terminal views. + * + * @since 2.0 + */ +public interface IRemoteCommandShellService extends IRemoteConnection.Service { + + /** + * Get a remote process that runs a command shell on the remote system. The shell will be the user's default shell on the remote + * system. The flags may be used to modify behavior of the remote process. These flags may only be supported by specific types + * of remote service providers. Clients can use {@link IRemoteProcessBuilder#getSupportedFlags()} to find out the flags + * supported by the service provider. + * + *
+	 * Current flags are:
+	 *   {@link IRemoteProcessBuilder#NONE}			- disable any flags
+	 *   {@link IRemoteProcessBuilder#ALLOCATE_PTY}	- allocate a pseudo-terminal for the process (RFC-4254 Sec. 6.2)
+	 *   {@link IRemoteProcessBuilder#FORWARD_X11}	- enable X11 forwarding (RFC-4254 Sec. 6.3)
+	 * 
+ * + * @param flags + * bitwise-or of flags + * @return remote process object + * @throws IOException + * @since 7.0 + */ + public IRemoteProcess getCommandShell(int flags) throws IOException; + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java index 5a86677268c..f8373156598 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java @@ -10,177 +10,48 @@ *******************************************************************************/ package org.eclipse.remote.core; -import java.io.IOException; -import java.util.List; -import java.util.Map; - +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.remote.core.exception.RemoteConnectionException; /** - * Abstraction of a connection to a remote system. Clients should use the set methods to provide information on the remote system, - * then call the {{@link #open(IProgressMonitor)} method. Once the connection is completed, call the {@link #close()} method to - * terminate the connection. + * Represents a connection to a remote system. Use the getService method to get at connection + * specific services. Connections have state, open or closed. Some connection types are always + * open in which case the close does nothing. Connections have properties which are values that + * describe the connection and are discovered. Connections also have attributes which are + * client specified values that control the connection. + * + * @noimplement This interface is not intended to be implemented by clients. */ -public interface IRemoteConnection extends Comparable { - public final static String OS_NAME_PROPERTY = "os.name"; //$NON-NLS-1$ - public final static String OS_VERSION_PROPERTY = "os.version"; //$NON-NLS-1$ - public final static String OS_ARCH_PROPERTY = "os.arch"; //$NON-NLS-1$ +public interface IRemoteConnection { /** - * @since 6.0 + * The interface that is extend by services provided for this remote connection. + * @since 2.0 */ - public final static String FILE_SEPARATOR_PROPERTY = "file.separator"; //$NON-NLS-1$ - /** - * @since 6.0 - */ - public final static String PATH_SEPARATOR_PROPERTY = "path.separator"; //$NON-NLS-1$ - /** - * @since 6.0 - */ - public final static String LINE_SEPARATOR_PROPERTY = "line.separator"; //$NON-NLS-1$ - /** - * @since 4.0 - */ - public final static String USER_HOME_PROPERTY = "user.home"; //$NON-NLS-1$ + interface Service { + IRemoteConnection getRemoteConnection(); + + interface Factory { + T getService(IRemoteConnection remoteConnection, Class service); + } + } + + // Common properties + final static String OS_NAME_PROPERTY = "os.name"; //$NON-NLS-1$ + final static String OS_VERSION_PROPERTY = "os.version"; //$NON-NLS-1$ + final static String OS_ARCH_PROPERTY = "os.arch"; //$NON-NLS-1$ + final static String FILE_SEPARATOR_PROPERTY = "file.separator"; //$NON-NLS-1$ + final static String PATH_SEPARATOR_PROPERTY = "path.separator"; //$NON-NLS-1$ + final static String LINE_SEPARATOR_PROPERTY = "line.separator"; //$NON-NLS-1$ + final static String USER_HOME_PROPERTY = "user.home"; //$NON-NLS-1$ /** - * Register a listener that will be notified when this connection's status changes. + * Get the connection type of this connection * - * @param listener + * @return connection type + * @since 2.0 */ - public void addConnectionChangeListener(IRemoteConnectionChangeListener listener); - - /** - * Close the connection. Must be called to terminate the connection. - */ - public void close(); - - /** - * Notify all listeners when this connection's status changes. See {{@link IRemoteConnectionChangeEvent} for a list of event - * types. - * - * @param event - * event type indicating the nature of the event - */ - public void fireConnectionChangeEvent(int type); - - /** - * Forward local port localPort to remote port fwdPort on remote machine fwdAddress. If this IRemoteConnection is not to - * fwdAddress, the port will be routed via the connection machine to fwdAddress. - * - * @param localPort - * local port to forward - * @param fwdAddress - * address of remote machine - * @param fwdPort - * remote port on remote machine - * @throws RemoteConnectionException - */ - public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException; - - /** - * Forward a local port to remote port fwdPort on remote machine fwdAddress. The local port is chosen dynamically and returned - * by the method. If this IRemoteConnection is not to fwdAddress, the port will be routed via the connection machine to - * fwdAddress. - * - * @param fwdAddress - * @param fwdPort - * @param monitor - * @return local port number - * @throws RemoteConnectionException - */ - public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException; - - /** - * Forward remote port remotePort to port fwdPort on machine fwdAddress. When a connection is made to remotePort on the remote - * machine, it is forwarded via this IRemoteConnection to fwdPort on machine fwdAddress. - * - * @param remotePort - * remote port to forward - * @param fwdAddress - * address of recipient machine - * @param fwdPort - * port on recipient machine - * @throws RemoteConnectionException - */ - public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException; - - /** - * Forward a remote port to port fwdPort on remote machine fwdAddress. The remote port is chosen dynamically and returned by the - * method. When a connection is made to this port on the remote machine, it is forwarded via this IRemoteConnection to fwdPort - * on machine fwdAddress. - * - * If fwdAddress is the empty string ("") then the fwdPort will be bound to any address on all interfaces. Note that this - * requires enabling the GatewayPort sshd option on some systems. - * - * @param fwdAddress - * @param fwdPort - * @param monitor - * @return remote port number - * @throws RemoteConnectionException - */ - public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException; - - /** - * Gets the implementation dependent address for this connection - * - * return address - */ - public String getAddress(); - - /** - * Get the implementation specific attributes for the connection. - * - * NOTE: the attributes do not include any security related information (e.g. passwords, keys, etc.) - * - * @return a map containing the connection attribute keys and values - */ - public Map getAttributes(); - - /** - * Get a remote process that runs a command shell on the remote system. The shell will be the user's default shell on the remote - * system. The flags may be used to modify behavior of the remote process. These flags may only be supported by specific types - * of remote service providers. Clients can use {@link IRemoteProcessBuilder#getSupportedFlags()} to find out the flags - * supported by the service provider. - * - *
-	 * Current flags are:
-	 *   {@link IRemoteProcessBuilder#NONE}			- disable any flags
-	 *   {@link IRemoteProcessBuilder#ALLOCATE_PTY}	- allocate a pseudo-terminal for the process (RFC-4254 Sec. 6.2)
-	 *   {@link IRemoteProcessBuilder#FORWARD_X11}	- enable X11 forwarding (RFC-4254 Sec. 6.3)
-	 * 
- * - * @param flags - * bitwise-or of flags - * @return remote process object - * @throws IOException - * @since 7.0 - */ - public IRemoteProcess getCommandShell(int flags) throws IOException; - - /** - * Returns an unmodifiable string map view of the remote environment. The connection must be open prior to calling this method. - * - * @return the remote environment - * @since 5.0 - */ - public Map getEnv(); - - /** - * Returns the value of an environment variable. The connection must be open prior to calling this method. - * - * @param name - * name of the environment variable - * @return value of the environment variable or null if the variable is not defined - */ - public String getEnv(String name); - - /** - * Get a file manager for managing remote files - * - * @return file manager or null if connection is not open - */ - public IRemoteFileManager getFileManager(); + public IRemoteConnectionType getConnectionType(); /** * Get unique name for this connection. @@ -190,83 +61,23 @@ public interface IRemoteConnection extends Comparable { public String getName(); /** - * Gets the port for this connection. Only valid if supported by the service provider. + * Get the service for this remote connection that implements the given interface. * - * return port number - * - * @since 5.0 + * @param service the interface the required service must implements + * @return the desired service or null if there is no such service available + * @throws CoreException + * @since 2.0 */ - public int getPort(); + T getService(Class service); /** - * Get a process builder for creating remote processes + * Does this connection support the given service. * - * @return process builder or null if connection is not open + * @param service The service to be tested + * @return true if this connection supports the service + * @since 2.0 */ - public IRemoteProcessBuilder getProcessBuilder(List command); - - /** - * Get a process builder for creating remote processes - * - * @return process builder or null if connection is not open - */ - public IRemoteProcessBuilder getProcessBuilder(String... command); - - /** - * Gets the remote system property indicated by the specified key. The connection must be open prior to calling this method. - * - * The following keys are supported: - * - *
-	 * os.name			Operating system name 
-	 * os.arch			Operating system architecture
-	 * os.version		Operating system version
-	 * file.separator	File separator ("/" on UNIX)
-	 * path.separator	Path separator (":" on UNIX)
-	 * line.separator	Line separator ("\n" on UNIX)
-	 * user.home		Home directory
-	 * 
- * - * @param key - * the name of the property - * @return the string value of the property, or null if no property has that key - */ - public String getProperty(String key); - - /** - * Get the remote services provider for this connection. - * - * @return remote services provider - * @since 4.0 - */ - public IRemoteServices getRemoteServices(); - - /** - * Gets the username for this connection - * - * return username - */ - public String getUsername(); - - public IRemoteConnectionWorkingCopy getWorkingCopy(); - - /** - * Get the working directory. Relative paths will be resolved using this path. - * - * The remote connection does not need to be open to use this method, however a default directory path, rather than the actual - * working directory, may be returned in this case. - * - * @return String representing the current working directory - * @since 4.0 - */ - public String getWorkingDirectory(); - - /** - * Test if the connection is open. - * - * @return true if connection is open. - */ - public boolean isOpen(); + boolean hasService(Class service); /** * Open the connection. Must be called before the connection can be used. @@ -279,6 +90,61 @@ public interface IRemoteConnection extends Comparable { */ public void open(IProgressMonitor monitor) throws RemoteConnectionException; + /** + * Close the connection. Must be called to terminate the connection. + */ + public void close(); + + /** + * Test if the connection is open. + * + * @return true if connection is open. + */ + public boolean isOpen(); + + /** + * Gets the remote system property indicated by the specified key. The connection must be open prior to calling this method. + * + * @param key + * the name of the property + * @return the string value of the property, or null if no property has that key + */ + public String getProperty(String key); + + /** + * Get an attribute for a connection. + * + * NOTE: the attributes do not include any security related information (e.g. passwords, keys, etc.) + * + * @param key + * @return the attribute value, or empty string if not defined. + * @since 2.0 + */ + public String getAttribute(String key); + + /** + * Get an attribute that is stored in secure storage, such as passwords. + * + * @param key + * @return the attribute value, or empty string if not defined. + * @since 2.0 + */ + public String getSecureAttribute(String key); + + /** + * Return a working copy to allow setting and changing of attributes. + * + * @return working copy of remote + */ + public IRemoteConnectionWorkingCopy getWorkingCopy(); + + /** + * Register a listener that will be notified when this connection's status changes. + * + * @param listener + */ + public void addConnectionChangeListener(IRemoteConnectionChangeListener listener); + /** * Remove a listener that will be notified when this connection's status changes. * @@ -287,41 +153,12 @@ public interface IRemoteConnection extends Comparable { public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener); /** - * Remove the local port forwarding associated with the given port. + * Notify all listeners when this connection's status changes. See {{@link RemoteConnectionChangeEvent} for a list of event + * types. * - * @param port - * forwarded port - * @throws RemoteConnectionException - * @since 7.0 + * @param event + * event type indicating the nature of the event */ - public void removeLocalPortForwarding(int port) throws RemoteConnectionException; + public void fireConnectionChangeEvent(int type); - /** - * Remove the remote port forwarding associated with the given port. - * - * @param port - * forwarded port - * @throws RemoteConnectionException - * @since 7.0 - */ - public void removeRemotePortForwarding(int port) throws RemoteConnectionException; - - /** - * Set the working directory while the connection is open. The working directory will revert to the default when the connection - * is closed then subsequently reopened. - * - * Relative paths will be resolved using this path. The path must be valid and absolute for any changes to be made. - * - * @param path - * String representing the current working directory - * @since 4.0 - */ - public void setWorkingDirectory(String path); - - /** - * Test if this connection supports forwarding of TCP connections - * - * @return true if TCP port forwarding is supported - */ - public boolean supportsTCPPortForwarding(); } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeListener.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeListener.java index 28ef2db7fe7..30c340b942f 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeListener.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeListener.java @@ -13,8 +13,11 @@ package org.eclipse.remote.core; import java.util.EventListener; /** - * Listener used to register for notification of connection status changes. Clients should register a listener using the - * {@link IRemoteConnection#addConnectionChangeListener(IRemoteConnectionChangeListener)} method. + * Listener used to register for notification of connection status changes. + * Listeners can be registered on individual connections using + * {@link IRemoteConnection#addConnectionChangeListener(IRemoteConnectionChangeListener)}, + * or globally for all connections using + * {@link IRemoteServicesManager#addRemoteConnectionChangeListener(IRemoteConnectionChangeListener)}. */ public interface IRemoteConnectionChangeListener extends EventListener { @@ -23,7 +26,9 @@ public interface IRemoteConnectionChangeListener extends EventListener { * * @param event * the connection change event + * @since 2.0 */ - public void connectionChanged(IRemoteConnectionChangeEvent event); + public void connectionChanged(RemoteConnectionChangeEvent event); + } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionControlService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionControlService.java new file mode 100644 index 00000000000..14d74c4818a --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionControlService.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.remote.core.exception.RemoteConnectionException; + +/** + * A service to control and report on the state of a connection, open or closed. + * Connections that do not provide this service are always assumed to be opened. + * + * @since 2.0 + */ +public interface IRemoteConnectionControlService extends IRemoteConnection.Service { + + /** + * Open the connection. Must be called before the connection can be used. + * + * @param monitor + * the progress monitor to use for reporting progress to the user. It is the caller's responsibility to call done() + * on the given monitor. Accepts null, indicating that no progress should be reported and that the operation cannot + * be cancelled. + * @throws RemoteConnectionException + */ + public void open(IProgressMonitor monitor) throws RemoteConnectionException; + + /** + * Close the connection. Must be called to terminate the connection. + */ + public void close(); + + /** + * Test if the connection is open. + * + * @return true if connection is open. + */ + public boolean isOpen(); + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionPropertyService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionPropertyService.java new file mode 100644 index 00000000000..062178fa712 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionPropertyService.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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; + +/** + * A connection property is some descriptive information that's discovered about the connection. + * This service provides property values for a connection. + * + * Examples include: + *
+ * os.name			Operating system name 
+ * os.arch			Operating system architecture
+ * os.version		Operating system version
+ * file.separator	File separator ("/" on UNIX)
+ * path.separator	Path separator (":" on UNIX)
+ * line.separator	Line separator ("\n" on UNIX)
+ * user.home		Home directory
+ * 
+ * + * @since 2.0 + */ +public interface IRemoteConnectionPropertyService extends IRemoteConnection.Service { + + /** + * Gets the remote system property indicated by the specified key. The connection must be open prior to calling this method. + * + * @param key + * the name of the property + * @return the string value of the property, or null if no property has that key + */ + public String getProperty(String key); + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionProviderService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionProviderService.java new file mode 100644 index 00000000000..5fc0d66c8ff --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionProviderService.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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; + +/** + * A connection type service for connectiont types that have automatic means of adding + * and removing services. For example, the Local connection type needs to be able + * to ensure the Local connection is created, or adapters to other target management + * systems may prefer to let those systems manage the connections. + * + * @since 2.0 + */ +public interface IRemoteConnectionProviderService extends IRemoteConnectionType.Service { + + /** + * Initialize the service. Called after all existing connections are loaded. + * This method typically will add the initial connections or start up a job to do it. + * This method is called on startup, it's important that it be fast. + */ + void init(); + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionType.java similarity index 50% rename from bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java rename to bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionType.java index 8eeb68a4b86..3e4117d0815 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionManager.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2013 IBM Corporation 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 @@ -13,18 +13,91 @@ package org.eclipse.remote.core; import java.net.URI; import java.util.List; +import org.eclipse.core.runtime.CoreException; import org.eclipse.remote.core.exception.RemoteConnectionException; + /** - * Interface for managing connections to remote systems. + * A remote connection type manages a list of connections that implement the same services. + * Services may be registered on the individual connections, or at the connection type level + * for service that apply to all connections of this type. + * + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 */ -public interface IRemoteConnectionManager { +public interface IRemoteConnectionType { /** - * The name of the connection for local services. There is only one connection for local services. - * - * @since 7.0 + * The interface that is extend by services provided for this remote services implementation. + * @since 2.0 */ - public static String LOCAL_CONNECTION_NAME = "Local"; //$NON-NLS-1$ + interface Service { + IRemoteConnectionType getConnectionType(); + + interface Factory { + T getService(IRemoteConnectionType connectionType, Class service); + } + } + + // Capabilities + static final int CAPABILITY_ADD_CONNECTIONS = 0x01; + static final int CAPABILITY_EDIT_CONNECTIONS = 0x02; + static final int CAPABILITY_REMOVE_CONNECTIONS = 0x04; + static final int CAPABILITY_SUPPORTS_TCP_PORT_FORWARDING = 0x08; + static final int CAPABILITY_SUPPORTS_X11_FORWARDING = 0x10; + + /** + * Get the remote services manager. This is a convenient way to get back + * to the root. + * + * @return remote services manager + */ + IRemoteServicesManager getRemoteServicesManager(); + + /** + * Get unique ID of this service. Can be used as a lookup key. + * + * @return unique ID + */ + String getId(); + + /** + * Get display name of this service. + * + * @return display name + */ + String getName(); + + /** + * Get the EFS scheme provided by this service. + * + * @return display name + */ + String getScheme(); + + /** + * Gets the capabilities of the remote service. + * + * @return bit-wise or of capability flag constants + */ + int getCapabilities(); + + /** + * Get the service for this remote services implementation that implements the given interface. + * + * @param service the interface the required service must implements + * @return the desired service or null if there is no such service available + * @throws CoreException + * @since 2.0 + */ + T getService(Class service); + + /** + * Does this connection type support the given service. + * + * @param service the service to be tested + * @return true if this connection type supports this service + */ + boolean hasService(Class service); /** * Gets the remote connection corresponding to the supplied name. @@ -53,16 +126,6 @@ public interface IRemoteConnectionManager { */ public List getConnections(); - /** - * Get the user authenticator that will be used when opening connections. The user authenticator is specified using the - * org.eclipse.remote.core.authenticator extension point. - * - * @param connection - * connection that will use this authenticator - * @return user authenticator - */ - public IUserAuthenticator getUserAuthenticator(IRemoteConnection connection); - /** * Creates a new remote connection named with supplied name. The connection attributes will be the default for the * implementation. @@ -88,4 +151,5 @@ public interface IRemoteConnectionManager { * if the connection could not be removed */ public void removeConnection(IRemoteConnection connection) throws RemoteConnectionException; + } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java index 3f16adfc4b4..ad4e269c4db 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionWorkingCopy.java @@ -10,9 +10,18 @@ *******************************************************************************/ package org.eclipse.remote.core; +import org.eclipse.remote.core.exception.RemoteConnectionException; + +/** + * A working copy of a remote connection used to change the name and/or + * attributes of the connection. It is also used when creating a new + * connection + */ public interface IRemoteConnectionWorkingCopy extends IRemoteConnection { + /** * Returns the original connection this working copy was created from. + * Returns null if this is a new connection. * * @return original connection */ @@ -30,27 +39,9 @@ public interface IRemoteConnectionWorkingCopy extends IRemoteConnection { * connection does not need saving. * * @return saved connection + * @throws RemoteConnectionException */ - public IRemoteConnection save(); - - /** - * Set the address for this connection - * - * @param address - */ - public void setAddress(String address); - - /** - * Set an implementation dependent attribute for the connection. Attributes keys supported by the connection can be obtained - * using {@link #getAttributes()}. Attributes are persisted along with connection information. - * - * @param key - * attribute key - * @param value - * attribute value - * @since 5.0 - */ - public void setAttribute(String key, String value); + public IRemoteConnection save() throws RemoteConnectionException; /** * Set the name for this connection @@ -60,26 +51,23 @@ public interface IRemoteConnectionWorkingCopy extends IRemoteConnection { public void setName(String name); /** - * Set the password for this connection + * Set an implementation dependent attribute for the connection. Attributes keys supported by the connection can be obtained + * using {@link #getAttributes()}. Attributes are persisted along with connection information. * - * @param password - * @since 5.0 + * @param key + * attribute key + * @param value + * attribute value */ - public void setPassword(String password); + public void setAttribute(String key, String value); /** - * Set the port used for this connection. Only valid if supported by the underlying service provider. + * Set an attribute such as a password that's stored in secure storage. * - * @param port - * port number for the connection - * @since 5.0 + * @param key + * @param value + * @since 2.0 */ - public void setPort(int port); + public void setSecureAttribute(String key, String value); - /** - * Set the username for this connection - * - * @param username - */ - public void setUsername(String username); } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteFileManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteFileService.java similarity index 79% rename from bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteFileManager.java rename to bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteFileService.java index 370f9cd1934..33ad6512794 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteFileManager.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteFileService.java @@ -16,9 +16,12 @@ import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.runtime.IPath; /** - * Interface for managing resources on a remote system. + * Interface for managing files on a remote system. + * + * @since 2.0 */ -public interface IRemoteFileManager { +public interface IRemoteFileService extends IRemoteConnection.Service { + /** * Get the resource associated with path. IFileStore can then be used to * perform operations on the file. @@ -31,15 +34,28 @@ public interface IRemoteFileManager { * path to resource * @return the file store representing the remote path */ - public IFileStore getResource(String path); + IFileStore getResource(String path); + + /** + * Get the base directory to be used for relative paths. + * + * @return base directory + */ + String getBaseDirectory(); + + /** + * Set the base directory to be used for relative paths.. + * + * @param path new base directory + */ + void setBaseDirectory(String path); /** * Gets the directory separator on the target system. * * @return String - * @since 4.0 */ - public String getDirectorySeparator(); + String getDirectorySeparator(); /** * Convert URI to a remote path. This path is suitable for direct file @@ -49,7 +65,7 @@ public interface IRemoteFileManager { * * @return IPath representing the remote path */ - public String toPath(URI uri); + String toPath(URI uri); /** * Convert remote path to equivalent URI. This URI is suitable for EFS @@ -62,7 +78,7 @@ public interface IRemoteFileManager { * @return URI representing path on remote system, or null if the path is * invalid */ - public URI toURI(IPath path); + URI toURI(IPath path); /** * Convert string representation of a remote path to equivalent URI. This @@ -75,5 +91,6 @@ public interface IRemoteFileManager { * @return URI representing path on remote system, or null if the path is * invalid */ - public URI toURI(String path); + URI toURI(String path); + } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePortForwardingService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePortForwardingService.java new file mode 100644 index 00000000000..fb436b230b9 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemotePortForwardingService.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * 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; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.remote.core.exception.RemoteConnectionException; + +/** + * A connection service for setting up port forwarding between the host and the remote. + * This is a feature provided by SSH. + * + * @since 2.0 + */ +public interface IRemotePortForwardingService extends IRemoteConnection.Service { + + /** + * Forward local port localPort to remote port fwdPort on remote machine fwdAddress. If this IRemoteConnection is not to + * fwdAddress, the port will be routed via the connection machine to fwdAddress. + * + * @param localPort + * local port to forward + * @param fwdAddress + * address of remote machine + * @param fwdPort + * remote port on remote machine + * @throws RemoteConnectionException + */ + public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException; + + /** + * Forward a local port to remote port fwdPort on remote machine fwdAddress. The local port is chosen dynamically and returned + * by the method. If this IRemoteConnection is not to fwdAddress, the port will be routed via the connection machine to + * fwdAddress. + * + * @param fwdAddress + * @param fwdPort + * @param monitor + * @return local port number + * @throws RemoteConnectionException + */ + public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException; + + /** + * Forward remote port remotePort to port fwdPort on machine fwdAddress. When a connection is made to remotePort on the remote + * machine, it is forwarded via this IRemoteConnection to fwdPort on machine fwdAddress. + * + * @param remotePort + * remote port to forward + * @param fwdAddress + * address of recipient machine + * @param fwdPort + * port on recipient machine + * @throws RemoteConnectionException + */ + public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException; + + /** + * Forward a remote port to port fwdPort on remote machine fwdAddress. The remote port is chosen dynamically and returned by the + * method. When a connection is made to this port on the remote machine, it is forwarded via this IRemoteConnection to fwdPort + * on machine fwdAddress. + * + * If fwdAddress is the empty string ("") then the fwdPort will be bound to any address on all interfaces. Note that this + * requires enabling the GatewayPort sshd option on some systems. + * + * @param fwdAddress + * @param fwdPort + * @param monitor + * @return remote port number + * @throws RemoteConnectionException + */ + public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException; + + /** + * Remove the local port forwarding associated with the given port. + * + * @param port + * forwarded port + * @throws RemoteConnectionException + * @since 7.0 + */ + public void removeLocalPortForwarding(int port) throws RemoteConnectionException; + + /** + * Remove the remote port forwarding associated with the given port. + * + * @param port + * forwarded port + * @throws RemoteConnectionException + * @since 7.0 + */ + public void removeRemotePortForwarding(int port) throws RemoteConnectionException; + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteProcessService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteProcessService.java new file mode 100644 index 00000000000..9647c948a2e --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteProcessService.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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; + +import java.util.List; +import java.util.Map; + +/** + * A connection service for starting up processes on a remote. + * + * @since 2.0 + */ +public interface IRemoteProcessService extends IRemoteConnection.Service { + + /** + * Returns an unmodifiable string map view of the remote environment. The connection must be open prior to calling this method. + * + * @return the remote environment + */ + public Map getEnv(); + + /** + * Returns the value of an environment variable. The connection must be open prior to calling this method. + * + * @param name + * name of the environment variable + * @return value of the environment variable or null if the variable is not defined + */ + public String getEnv(String name); + + /** + * Get a process builder for creating remote processes + * + * @return process builder or null if connection is not open + */ + public IRemoteProcessBuilder getProcessBuilder(List command); + + /** + * Get a process builder for creating remote processes + * + * @return process builder or null if connection is not open + */ + public IRemoteProcessBuilder getProcessBuilder(String... command); + + /** + * Get the working directory. Relative paths will be resolved using this path. + * + * The remote connection does not need to be open to use this method, however a default directory path, rather than the actual + * working directory, may be returned in this case. + * + * @return String representing the current working directory + */ + public String getWorkingDirectory(); + + /** + * Set the working directory while the connection is open. The working directory will revert to the default when the connection + * is closed then subsequently reopened. + * + * Relative paths will be resolved using this path. The path must be valid and absolute for any changes to be made. + * + * @param path + * String representing the current working directory + * @since 4.0 + */ + public void setWorkingDirectory(String path); + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java deleted file mode 100644 index 7a2343bd9c2..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServices.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.core; - -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * Abstraction of a remote services provider. Clients obtain this interface using one of the static methods in - * {@link RemoteServices}. The methods on this interface can then be used to access the full range of remote services provided. - */ -public interface IRemoteServices extends IRemoteServicesDescriptor { - public static final int CAPABILITY_ADD_CONNECTIONS = 0x01; - public static final int CAPABILITY_EDIT_CONNECTIONS = 0x02; - public static final int CAPABILITY_REMOVE_CONNECTIONS = 0x04; - public static final int CAPABILITY_SUPPORTS_TCP_PORT_FORWARDING = 0x08; - public static final int CAPABILITY_SUPPORTS_X11_FORWARDING = 0x10; - public static final int CAPABILITY_SUPPORTS_COMMAND_SHELL = 0x20; - - /** - * Get a connection manager for managing remote connections. - * - * @return connection manager or null if services are not initialized - */ - public IRemoteConnectionManager getConnectionManager(); - - /** - * Initialize the remote service. Clients should not call this method (it is called internally.) - * - * @return true if the initialization was successful, false otherwise - * @since 7.0 - */ - public boolean initialize(IProgressMonitor monitor); - - /** - * Gets the capabilities of the remote service. - * - * @return bit-wise or of capability flag constants - */ - public int getCapabilities(); -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java deleted file mode 100644 index 970fed1bbcc..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesDescriptor.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.core; - -/** - * Interface representing a remote services provider extension. Clients can use this to find out information about the extension - * without loading it. - */ -public interface IRemoteServicesDescriptor extends Comparable { - /** - * Get unique ID of this service. Can be used as a lookup key. - * - * @return unique ID - */ - public String getId(); - - /** - * Get display name of this service. - * - * @return display name - */ - public String getName(); - - /** - * Get the EFS scheme provided by this service. - * - * @return display name - */ - public String getScheme(); -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesFactory.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesFactory.java deleted file mode 100644 index 7376e7cd765..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.core; - -/** - * Factory for creating instances of a remote service provider. Implementors must provide a class implementing this interface when - * supplying a new remote services provider extension. - */ -public interface IRemoteServicesFactory { - /** - * Return the remote services implementation for the given descriptor - * - * @param descriptor - * descriptor for the remote services - * @return the remote services implementation, or null if initialization failed - */ - public IRemoteServices getServices(IRemoteServicesDescriptor descriptor); -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesManager.java new file mode 100644 index 00000000000..a80986fa8dc --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteServicesManager.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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; + +import java.net.URI; +import java.util.List; + +/** + * The main entry point into the remote services system. The remote services manager + * is an OSGi service. It provides a list of connection types and the global + * list of all connections. + * + * @noimplement This interface is not intended to be implemented by clients. + * @since 2.0 + */ +public interface IRemoteServicesManager { + + /** + * Get the connection type identified by the id + * + * @param id id of the connection type + * @return connection type or null if the service can not be found + */ + IRemoteConnectionType getConnectionType(String id); + + /** + * Get the connection type that provides connections to locations identified by + * the URI. + * + * @param uri uri of locations to be accessed + * @return the connection type that can be used to access the locations + * or null if no connection type is available for the uri. + */ + IRemoteConnectionType getConnectionType(URI uri); + + /** + * Return the connection type used to access local resources. + * + * @return the local services + */ + IRemoteConnectionType getLocalConnectionType(); + + /** + * Returns the list of all connection type including the local services. + * + * @return all remote services + */ + List getAllConnectionTypes(); + + /** + * Returns the list of connection types except for the local services. + * + * @return all remote services that are really remote + */ + List getRemoteConnectionTypes(); + + /** + * Returns the list of all known remote connections. + * + * @return all remote connections + */ + List getAllRemoteConnections(); + + /** + * Add a global connection change listener that receives events for all connections. + * + * @param listener global connection change listener to be added + */ + void addRemoteConnectionChangeListener(IRemoteConnectionChangeListener listener); + + /** + * Remove the global connection change listener. + * + * @param listener global connection change listener to be removed + */ + void removeRemoteConnectionChangeListener(IRemoteConnectionChangeListener listener); + + /** + * Used by connections and other components to notify the global connection + * change listeners of events. + * + * @param event connection change event + */ + void fireRemoteConnectionChangeEvent(RemoteConnectionChangeEvent event); + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IUserAuthenticator.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IUserAuthenticatorService.java similarity index 97% rename from bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IUserAuthenticator.java rename to bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IUserAuthenticatorService.java index 94e393e547d..75cf3935439 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IUserAuthenticator.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IUserAuthenticatorService.java @@ -18,9 +18,9 @@ import java.net.PasswordAuthentication; /** * Allow clients to provide their own user interface for connection authentication. * - * @since 7.0 + * @since 2.0 */ -public interface IUserAuthenticator { +public interface IUserAuthenticatorService extends IRemoteConnection.Service { /** * ID for an "Ok" response (value 0). diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeEvent.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteConnectionChangeEvent.java similarity index 71% rename from bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeEvent.java rename to bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteConnectionChangeEvent.java index b0d164bccea..333e152c083 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionChangeEvent.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteConnectionChangeEvent.java @@ -13,8 +13,11 @@ package org.eclipse.remote.core; /** * Event representing a change in connection status. The {@link #getType()} method can be used to obtain information about the type * of event that occurred. + * + * @since 2.0 */ -public interface IRemoteConnectionChangeEvent { +public class RemoteConnectionChangeEvent { + /** * Event indicating that the connection was closed. */ @@ -35,12 +38,34 @@ public interface IRemoteConnectionChangeEvent { */ public static final int CONNECTION_RENAMED = 1 << 3; + /** + * Event indicating the connection was added. + * @since 2.0 + */ + public static final int CONNECTION_ADDED = 1 << 4; + + /** + * Event indicating the connection is about to be removed. + * @since 2.0 + */ + public static final int CONNECTION_REMOVED = 1 << 5; + + private final IRemoteConnection connection; + private final int type; + + public RemoteConnectionChangeEvent(IRemoteConnection connection, int type) { + this.connection = connection; + this.type = type; + } + /** * Get the connection that has changed. * * @return IRemoteConnection */ - public IRemoteConnection getConnection(); + public IRemoteConnection getConnection() { + return connection; + } /** * Returns the type of event being reported. This type @@ -50,5 +75,8 @@ public interface IRemoteConnectionChangeEvent { * * @return a bitwise OR of event type constants */ - public int getType(); + public int getType() { + return type; + } + } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java deleted file mode 100644 index 609ced0dd6f..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServices.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.core; - -import java.net.URI; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.remote.internal.core.RemoteServicesDescriptor; -import org.eclipse.remote.internal.core.RemoteServicesImpl; -import org.eclipse.remote.internal.core.services.local.LocalServices; - -/** - * Main entry point for accessing remote services. - * - * @since 7.0 - */ -public class RemoteServices { - /** - * Retrieve the local services provider. Guaranteed to exist and be initialized. - * - * @return local services provider - */ - public static IRemoteServices getLocalServices() { - return getRemoteServices(LocalServices.LocalServicesId); - } - - /** - * Get the remote service implementation identified by id and ensure that it is initialized. - * - * @param id - * id of the remote service - * @return remote service or null if the service cannot be found or failed to initialized - */ - public static IRemoteServices getRemoteServices(String id) { - return getRemoteServices(id, null); - } - - /** - * Get the remote service implementation identified by id and ensure that it is initialized. This method will present the user - * with a dialog box that can be canceled. - * - * @param id - * id of remote service to retrieve - * @param monitor - * progress monitor to allow user to cancel operation - * @return remote service, or null if the service cannot be found or failed to initialized - * @since 5.0 - */ - public static IRemoteServices getRemoteServices(String id, IProgressMonitor monitor) { - RemoteServicesDescriptor proxy = RemoteServicesImpl.getRemoteServiceDescriptorById(id); - if (proxy != null) { - IRemoteServices service = proxy.getServices(); - if (service.initialize(monitor)) { - return service; - } - } - return null; - } - - /** - * Get the remote services identified by a URI. - * - * @param uri - * URI of remote services to retrieve - * @return remote service, or null if the service cannot be found or failed to initialized - */ - public static IRemoteServices getRemoteServices(URI uri) { - return getRemoteServices(uri, null); - } - - /** - * Get the remote services implementation identified by URI. This method will present the user - * with a dialog box that can be canceled. - * - * @param uri - * URI of remote services to retrieve - * @param monitor - * progress monitor to allow user to cancel operation - * @return remote service, or null if the service cannot be found or failed to initialized - * @since 5.0 - */ - public static IRemoteServices getRemoteServices(URI uri, IProgressMonitor monitor) { - RemoteServicesDescriptor proxy = RemoteServicesImpl.getRemoteServiceDescriptorByURI(uri); - if (proxy != null) { - IRemoteServices service = proxy.getServices(); - if (service.initialize(monitor)) { - return service; - } - } - return null; - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java index fd92c6ac083..9cd758f579d 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/RemoteServicesUtils.java @@ -13,76 +13,14 @@ package org.eclipse.remote.core; import java.net.URI; import java.net.URISyntaxException; -import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.remote.internal.core.RemoteServicesDescriptor; -import org.eclipse.remote.internal.core.RemoteServicesImpl; +import org.eclipse.remote.internal.core.RemoteCorePlugin; import org.eclipse.remote.internal.core.preferences.Preferences; /** * Remote services utility methods. - * - * @since 7.0 */ public class RemoteServicesUtils { - /** - * Utility method to get a remote connection given a remote services ID and a connection name. - * - * @param remoteServicesId - * ID of remote services providing the connection - * @param connectionName - * name of the connection to find - * @param monitor - * progress monitor - * @return remote connection or null if the ID or connection name are invalid - */ - public static IRemoteConnection getConnectionWithProgress(String remoteServicesId, String connectionName, - IProgressMonitor monitor) { - SubMonitor progress = SubMonitor.convert(monitor, 10); - IRemoteServices remoteServices = RemoteServices.getRemoteServices(remoteServicesId, progress.newChild(1)); - if (remoteServices != null) { - IRemoteConnectionManager remoteConnectionManager = remoteServices.getConnectionManager(); - if (remoteConnectionManager != null) { - return remoteConnectionManager.getConnection(connectionName); - } - } - return null; - } - - /** - * Utility method to get a file store corresponding to the given path. - * - * @param remoteServicesId - * ID of remote services providing the connection - * @param connectionName - * name of the remote connection to use - * @param path - * path of file on remote system - * @param monitor - * progress monitor - * @return file store corresponding to the remote file or null if the ID or connection name are invalid - */ - public static IFileStore getRemoteFileWithProgress(String remoteServicesId, String connectionName, String path, - IProgressMonitor monitor) { - SubMonitor progress = SubMonitor.convert(monitor, 10); - IRemoteServices remoteServices = RemoteServices.getRemoteServices(remoteServicesId, progress.newChild(10)); - if (remoteServices != null) { - IRemoteConnectionManager remoteConnectionManager = remoteServices.getConnectionManager(); - if (remoteConnectionManager != null) { - IRemoteConnection remoteConnection = remoteConnectionManager.getConnection(connectionName); - if (remoteConnection != null) { - IRemoteFileManager remoteFileManager = remoteConnection.getFileManager(); - if (remoteFileManager != null) { - return remoteFileManager.getResource(path); - } - } - } - } - return null; - } - /** * Convert a UNC path to a URI * @@ -97,19 +35,20 @@ public class RemoteServicesUtils { */ public static URI toURI(IPath path) { if (path.isUNC()) { + IRemoteServicesManager manager = RemoteCorePlugin.getService(IRemoteServicesManager.class); /* * Split the server component if possible. */ String[] parts = path.segment(0).split(":"); //$NON-NLS-1$ - IRemoteServices services = null; + IRemoteConnectionType services = null; String connName = null; if (parts.length == 2) { - services = RemoteServices.getRemoteServices(parts[0]); + services = manager.getConnectionType(parts[0]); connName = parts[1]; } else if (parts.length == 1) { String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); if (id != null) { - services = RemoteServices.getRemoteServices(id); + services = manager.getConnectionType(id); } connName = parts[0]; } @@ -120,17 +59,13 @@ public class RemoteServicesUtils { */ IRemoteConnection conn = null; if (services != null) { - conn = services.getConnectionManager().getConnection(connName); + conn = services.getConnection(connName); } else if (connName != null) { - for (RemoteServicesDescriptor proxy : RemoteServicesImpl.getRemoteServiceDescriptors()) { - services = proxy.getServices(); - if (services != null) { - IRemoteConnectionManager connMgr = services.getConnectionManager(); - if (connMgr != null) { - conn = connMgr.getConnection(connName); - if (conn != null) { - break; - } + for (IRemoteConnectionType s : manager.getAllConnectionTypes()) { + if (s != null) { + conn = s.getConnection(connName); + if (conn != null) { + break; } } } @@ -140,7 +75,7 @@ public class RemoteServicesUtils { * If a connection was found then convert it to a URI. */ if (conn != null) { - String scheme = conn.getRemoteServices().getScheme(); + String scheme = conn.getConnectionType().getScheme(); String filePath = path.removeFirstSegments(1).makeAbsolute().toString(); try { return new URI(scheme, connName, filePath, null, null); diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/exception/ConnectionExistsException.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/exception/ConnectionExistsException.java new file mode 100644 index 00000000000..6bf3fb1255c --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/exception/ConnectionExistsException.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.exception; + +/** + * Thrown when trying to add a connection with the same name as an existing + * connection, or when trying to rename a connection to the same name as an + * existing connection. + * + * @since 2.0 + */ +public class ConnectionExistsException extends RemoteConnectionException { + + private static final long serialVersionUID = -1591235868439783613L; + + public ConnectionExistsException(String message) { + super(message); + } + +} 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/RemoteConnection.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnection.java new file mode 100644 index 00000000000..3a417a16a4c --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnection.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * 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.internal.core; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionChangeListener; +import org.eclipse.remote.core.IRemoteConnectionControlService; +import org.eclipse.remote.core.IRemoteConnectionPropertyService; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.RemoteConnectionChangeEvent; +import org.eclipse.remote.core.exception.ConnectionExistsException; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +/** + * The standard root class for remote connections. Implements common hook up + * with the remote services and the remote services manager as well as handling + * for services. + */ +public class RemoteConnection implements IRemoteConnection { + + private final RemoteConnectionType connectionType; + private String name; + + private Map servicesMap = new HashMap<>(); + + private final List fListeners = new ArrayList<>(); + + final static String EMPTY_STRING = ""; //$NON-NLS-1$ + + public RemoteConnection(RemoteConnectionType connectionType, String name) { + this.connectionType = connectionType; + this.name = name; + } + + @Override + public IRemoteConnectionType getConnectionType() { + return connectionType; + } + + @SuppressWarnings("unchecked") + @Override + public T getService(Class service) { + String serviceName = service.getName(); + Object obj = servicesMap.get(serviceName); + if (obj == null) { + obj = connectionType.getConnectionService(this, service); + if (obj != null) { + servicesMap.put(serviceName, obj); + } + } + + return (T) obj; + } + + @Override + public boolean hasService(Class service) { + return servicesMap.get(service.getName()) != null || connectionType.hasConnectionService(this, service); + } + + @Override + public String getName() { + return name; + } + + /** + * Called from working copy when name has changed. + * + * @param name the new name + */ + void rename(String newName) throws ConnectionExistsException { + try { + // Copy the old preferences over and remove the old node + if (connectionType.getPreferenceNode().nodeExists(newName)) { + throw new ConnectionExistsException(newName); + } + + Preferences newPrefs = connectionType.getPreferenceNode().node(newName); + Preferences oldPrefs = getPreferences(); + for (String key : oldPrefs.keys()) { + newPrefs.put(key, oldPrefs.get(key, null)); + } + + oldPrefs.removeNode(); + } catch (BackingStoreException e) { + RemoteCorePlugin.log(e); + } + + this.name = newName; + } + + Preferences getPreferences() { + return connectionType.getPreferenceNode().node(name); + } + + ISecurePreferences getSecurePreferences() { + return connectionType.getSecurePreferencesNode().node(name); + } + + @Override + public String getAttribute(String key) { + return getPreferences().get(key, EMPTY_STRING); + } + + @Override + public String getSecureAttribute(String key) { + try { + return getSecurePreferences().get(key, EMPTY_STRING); + } catch (StorageException e) { + RemoteCorePlugin.log(e); + return EMPTY_STRING; + } + } + + @Override + public IRemoteConnectionWorkingCopy getWorkingCopy() { + return new RemoteConnectionWorkingCopy(this); + } + + @Override + public String getProperty(String key) { + IRemoteConnectionPropertyService propertyService = getService(IRemoteConnectionPropertyService.class); + if (propertyService != null) { + return propertyService.getProperty(key); + } else { + return null; + } + } + + @Override + public void open(IProgressMonitor monitor) throws RemoteConnectionException { + IRemoteConnectionControlService controlService = getService(IRemoteConnectionControlService.class); + if (controlService != null) { + controlService.open(monitor); + } + } + + @Override + public void close() { + IRemoteConnectionControlService controlService = getService(IRemoteConnectionControlService.class); + if (controlService != null) { + controlService.close(); + } + } + + @Override + public boolean isOpen() { + IRemoteConnectionControlService controlService = getService(IRemoteConnectionControlService.class); + if (controlService != null) { + return controlService.isOpen(); + } else { + // default is always open + return true; + } + } + + @Override + public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) { + fListeners.add(listener); + } + + @Override + public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) { + fListeners.remove(listener); + } + + @Override + public void fireConnectionChangeEvent(final int type) { + RemoteConnectionChangeEvent event = new RemoteConnectionChangeEvent(this, type); + for (IRemoteConnectionChangeListener listener : fListeners) { + listener.connectionChanged(event); + } + // fire to the global listeners too + connectionType.getRemoteServicesManager().fireRemoteConnectionChangeEvent(event); + } + + @Override + public String toString() { + return name + " - " + connectionType.getName(); //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionType.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionType.java new file mode 100644 index 00000000000..cfe95677390 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionType.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * 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.internal.core; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.core.RemoteConnectionChangeEvent; +import org.eclipse.remote.core.exception.ConnectionExistsException; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +/** + * The implementation for a given remote services collection.n + */ +public class RemoteConnectionType implements IRemoteConnectionType { + + private final RemoteServicesManager remoteServicesManager; + private final String id; + private final String name; + private final String scheme; + private final int capabilities; + + private final Map serviceMap = new HashMap<>(); + private final Map serviceDefinitionMap = new HashMap<>(); + + private final Map connections = new HashMap<>(); + + public RemoteConnectionType(IConfigurationElement ce, RemoteServicesManager manager) { + this.remoteServicesManager = manager; + id = ce.getAttribute("id"); //$NON-NLS-1$ + name = ce.getAttribute("name"); //$NON-NLS-1$ + scheme = ce.getAttribute("scheme"); //$NON-NLS-1$ + + String caps = ce.getAttribute("capabilities"); //$NON-NLS-1$ + if (caps != null) { + capabilities = Integer.parseInt(caps); + } else { + capabilities = 0; + } + + // load up existing connections + try { + for (String connectionName : getPreferenceNode().childrenNames()) { + connections.put(connectionName, new RemoteConnection(this, connectionName)); + } + } catch (BackingStoreException e) { + RemoteCorePlugin.log(e); + } + } + + Preferences getPreferenceNode() { + return remoteServicesManager.getPreferenceNode().node(id); + } + + ISecurePreferences getSecurePreferencesNode() { + return remoteServicesManager.getSecurePreferenceNode().node(id); + } + + @Override + public IRemoteServicesManager getRemoteServicesManager() { + return remoteServicesManager; + } + + @Override + public String getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getScheme() { + return scheme; + } + + @Override + public int getCapabilities() { + return capabilities; + } + + @Override + public T getService(Class service) { + String serviceName = service.getName(); + @SuppressWarnings("unchecked") + T obj = (T) serviceMap.get(serviceName); + if (obj == null) { + IConfigurationElement ce = serviceDefinitionMap.get(serviceName); + if (ce != null) { + try { + Service.Factory factory = (Service.Factory) ce.createExecutableExtension("factory"); //$NON-NLS-1$ + if (factory != null) { + obj = factory.getService(this, service); + serviceMap.put(serviceName, obj); + serviceDefinitionMap.remove(serviceName); + } + } catch (CoreException e) { + RemoteCorePlugin.log(e.getStatus()); + } + } + } + return obj; + } + + @Override + public boolean hasService(Class service) { + String serviceName = service.getName(); + return serviceMap.get(serviceName) != null || serviceDefinitionMap.get(service) != null; + } + + /** + * Called from the connection to get a service object for that connection. + * + * @param connection the connection to which the service applies + * @param service the interface the service must implement + * @return the service object + * @throws CoreException + */ + public T getConnectionService(IRemoteConnection connection, Class service) { + // Both top level and connection services are stored in the serviceDefinitionMap. + // In theory the two sets of interfaces can't collide. + IConfigurationElement ce = serviceDefinitionMap.get(service.getName()); + if (ce != null) { + try { + IRemoteConnection.Service.Factory factory = (IRemoteConnection.Service.Factory) ce.createExecutableExtension("factory"); //$NON-NLS-1$ + if (factory != null) { + return factory.getService(connection, service); + } + } catch (CoreException e) { + RemoteCorePlugin.log(e.getStatus()); + } + } + + return null; + } + + public boolean hasConnectionService(IRemoteConnection connection, Class service) { + return serviceDefinitionMap.get(service.getName()) != null; + } + + /** + * Called from the remote service manager to register a service extension for + * this remote services implementation + * + * @param ce the extension element defining the service + */ + public void addService(IConfigurationElement ce) { + String service = ce.getAttribute("service"); //$NON-NLS-1$ + serviceDefinitionMap.put(service, ce); + } + + /** + * Signal connection has been added. + * @since 2.0 + */ + protected void connectionAdded(final IRemoteConnection connection) { + RemoteConnectionChangeEvent event = new RemoteConnectionChangeEvent(connection, RemoteConnectionChangeEvent.CONNECTION_ADDED); + remoteServicesManager.fireRemoteConnectionChangeEvent(event); + } + + /** + * Signal a connnection is about to be removed. + * @since 2.0 + */ + protected void connectionRemoved(final IRemoteConnection connection) { + RemoteConnectionChangeEvent event = new RemoteConnectionChangeEvent(connection, RemoteConnectionChangeEvent.CONNECTION_ADDED); + remoteServicesManager.fireRemoteConnectionChangeEvent(event); + } + + @Override + public IRemoteConnection getConnection(String name) { + return connections.get(name); + } + + @Override + public IRemoteConnection getConnection(URI uri) { + return connections.get(uri.getAuthority()); + } + + @Override + public List getConnections() { + return new ArrayList(connections.values()); + } + + @Override + public IRemoteConnectionWorkingCopy newConnection(String name) throws RemoteConnectionException { + if (connections.containsKey(name)) { + throw new ConnectionExistsException(name); + } + return new RemoteConnectionWorkingCopy(this, name); + } + + void addConnection(RemoteConnection remoteConnection) { + connections.put(remoteConnection.getName(), remoteConnection); + } + + void removeConnection(String name) { + connections.remove(name); + } + + @Override + public void removeConnection(IRemoteConnection connection) throws RemoteConnectionException { + if (connection instanceof RemoteConnection) { + connection.close(); + RemoteConnection conn = (RemoteConnection) connection; + try { + conn.getPreferences().removeNode(); + } catch (BackingStoreException e) { + throw new RemoteConnectionException(e); + } + conn.getSecurePreferences().removeNode(); + connections.remove(conn.getName()); + connection.fireConnectionChangeEvent(RemoteConnectionChangeEvent.CONNECTION_REMOVED); + } else { + RemoteCorePlugin.log("Wrong class for " + connection.getName() + ", was " + connection.getClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionWorkingCopy.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionWorkingCopy.java new file mode 100644 index 00000000000..31e7d20b422 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnectionWorkingCopy.java @@ -0,0 +1,303 @@ +/******************************************************************************* + * 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.internal.core; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionChangeListener; +import org.eclipse.remote.core.IRemoteConnectionControlService; +import org.eclipse.remote.core.IRemoteConnectionPropertyService; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.RemoteConnectionChangeEvent; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +public class RemoteConnectionWorkingCopy implements IRemoteConnectionWorkingCopy { + + private RemoteConnection original; + private RemoteConnectionType connectionType; + private String newName; + private Map newAttributes = new HashMap<>(); + private Map newSecureAttributes = new HashMap<>(); + private List newListeners = new ArrayList<>(); + + /** + * New Connection. + */ + public RemoteConnectionWorkingCopy(RemoteConnectionType connectionType, String name) { + this.connectionType = connectionType; + this.newName = name; + } + + /** + * Edit Connection + */ + public RemoteConnectionWorkingCopy(RemoteConnection original) { + this.original = original; + } + + @Override + public String getName() { + if (newName != null) { + return newName; + } else if (original != null) { + return original.getName(); + } else { + return null; + } + } + + @Override + public void setName(String name) { + // set if only if it's changed + if (original == null || !name.equals(original.getName())) { + newName = name; + } + } + + @Override + public String getAttribute(String key) { + String value = newAttributes.get(key); + if (value != null) { + return value; + } + + if (original != null) { + return original.getAttribute(key); + } + + return RemoteConnection.EMPTY_STRING; + } + + @Override + public void setAttribute(String key, String value) { + // set only if it's changed or value is null + if (original == null || value == null || !value.equals(original.getAttribute(key))) { + newAttributes.put(key, value); + } + } + + @Override + public String getSecureAttribute(String key) { + String value = newSecureAttributes.get(key); + if (value != null) { + return value; + } + + if (original != null) { + return original.getSecureAttribute(key); + } + + return RemoteConnection.EMPTY_STRING; + } + + @Override + public void setSecureAttribute(String key, String value) { + // set only if it's changed or value is null + if (original == null || value == null || !value.equals(original.getSecureAttribute(key))) { + newSecureAttributes.put(key, value); + } + } + + @Override + public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) { + if (original != null) { + original.addConnectionChangeListener(listener); + } else { + newListeners.add(listener); + } + } + + @Override + public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) { + if (original != null) { + original.removeConnectionChangeListener(listener); + } else { + newListeners.remove(listener); + } + } + + @Override + public void fireConnectionChangeEvent(int type) { + if (original != null) { + original.fireConnectionChangeEvent(type); + } else { + RemoteConnectionChangeEvent event = new RemoteConnectionChangeEvent(this, type); + for (IRemoteConnectionChangeListener listener : newListeners) { + listener.connectionChanged(event); + } + connectionType.getRemoteServicesManager().fireRemoteConnectionChangeEvent(event); + } + } + + @Override + public IRemoteConnectionType getConnectionType() { + return connectionType; + } + + @Override + public IRemoteConnectionWorkingCopy getWorkingCopy() { + return this; + } + + @Override + public T getService(Class service) { + if (original != null) { + return original.getService(service); + } else { + return connectionType.getConnectionService(this, service); + } + } + + @Override + public boolean hasService(Class service) { + if (original != null) { + return original.hasService(service); + } else { + return connectionType.hasConnectionService(this, service); + } + } + + @Override + public IRemoteConnection getOriginal() { + return original; + } + + @Override + public boolean isDirty() { + return newName != null || !newAttributes.isEmpty() || !newSecureAttributes.isEmpty(); + } + + @Override + public IRemoteConnection save() throws RemoteConnectionException { + if (newName != null && original != null) { + // rename, delete the old one + original.fireConnectionChangeEvent(RemoteConnectionChangeEvent.CONNECTION_RENAMED); + connectionType.removeConnection(original.getName()); + original.rename(newName); + } + + boolean added = false; + if (original == null) { + original = new RemoteConnection(connectionType, newName); + added = true; + } + + Preferences prefs = original.getPreferences(); + for (Map.Entry entry : newAttributes.entrySet()) { + String value = entry.getValue(); + if (value != null && !value.isEmpty()) { + prefs.put(entry.getKey(), value); + } else { + prefs.remove(entry.getKey()); + } + } + try { + prefs.flush(); + } catch (BackingStoreException e1) { + throw new RemoteConnectionException(e1); + } + newAttributes.clear(); + + ISecurePreferences securePrefs = original.getSecurePreferences(); + for (Map.Entry entry : newSecureAttributes.entrySet()) { + String value = entry.getValue(); + if (value != null && !value.isEmpty()) { + try { + securePrefs.put(entry.getKey(), value, true); + } catch (StorageException e) { + throw new RemoteConnectionException(e); + } + } else { + securePrefs.remove(entry.getKey()); + } + } + try { + securePrefs.flush(); + } catch (IOException e) { + throw new RemoteConnectionException(e); + } + newSecureAttributes.clear(); + + connectionType.addConnection(original); + if (added) { + original.fireConnectionChangeEvent(RemoteConnectionChangeEvent.CONNECTION_ADDED); + } + return original; + } + + @Override + public void open(IProgressMonitor monitor) throws RemoteConnectionException { + if (original != null) { + original.open(monitor); + } else { + IRemoteConnectionControlService controlService = + connectionType.getConnectionService(this, IRemoteConnectionControlService.class); + if (controlService != null) { + controlService.open(monitor); + } + } + } + + @Override + public void close() { + if (original != null) { + original.close(); + } else { + IRemoteConnectionControlService controlService = + connectionType.getConnectionService(this, IRemoteConnectionControlService.class); + if (controlService != null) { + controlService.close(); + } + } + } + + @Override + public boolean isOpen() { + if (original != null) { + return original.isOpen(); + } else { + IRemoteConnectionControlService controlService = + connectionType.getConnectionService(this, IRemoteConnectionControlService.class); + if (controlService != null) { + return controlService.isOpen(); + } else { + return true; + } + } + } + + @Override + public String getProperty(String key) { + if (original != null) { + return original.getProperty(key); + } else { + IRemoteConnectionPropertyService propertyService = + connectionType.getConnectionService(this, IRemoteConnectionPropertyService.class); + if (propertyService != null) { + return propertyService.getProperty(key); + } else { + return null; + } + } + } + +} 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 e125fa7606a..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 @@ -17,8 +17,12 @@ import org.eclipse.core.runtime.CoreException; 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; /** * The activator class controls the plug-in life cycle @@ -78,6 +82,18 @@ public class RemoteCorePlugin extends Plugin { log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, e.getMessage(), e)); } + /** + * Return the OSGi service with the given service interface. + * + * @param service service interface + * @return the specified service or null if it's not registered + */ + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + /** * The constructor */ @@ -93,6 +109,8 @@ public class RemoteCorePlugin extends Plugin { public void start(BundleContext context) throws Exception { 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/RemoteServicesDescriptor.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesDescriptor.java deleted file mode 100644 index d5c72f84a32..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesDescriptor.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.osgi.util.NLS; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.IRemoteServicesDescriptor; -import org.eclipse.remote.core.IRemoteServicesFactory; -import org.eclipse.remote.internal.core.messages.Messages; - -public class RemoteServicesDescriptor implements IRemoteServicesDescriptor { - private static final String ATTR_ID = "id"; //$NON-NLS-1$ - private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_SCHEME = "scheme"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - - private static String getAttribute(IConfigurationElement configElement, String name, String defaultValue) { - String value = configElement.getAttribute(name); - if (value != null) { - return value; - } - if (defaultValue != null) { - return defaultValue; - } - throw new IllegalArgumentException(NLS.bind(Messages.RemoteServicesProxy_0, name)); - } - - private final IConfigurationElement fConfigElement; - - private final String fId; - private final String fName; - private final String fScheme; - private IRemoteServicesFactory fFactory; - private IRemoteServices fDelegate = null; - - public RemoteServicesDescriptor(IConfigurationElement configElement) { - fConfigElement = configElement; - fId = getAttribute(configElement, ATTR_ID, null); - fName = getAttribute(configElement, ATTR_NAME, fId); - fScheme = getAttribute(configElement, ATTR_SCHEME, null); - getAttribute(configElement, ATTR_CLASS, null); - fFactory = null; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(IRemoteServicesDescriptor arg0) { - return getName().compareTo(arg0.getName()); - } - - /** - * Get the factory from the plugin - * - * @return instance of the factory - */ - public IRemoteServicesFactory getFactory() { - if (fFactory != null) { - return fFactory; - } - try { - fFactory = (IRemoteServicesFactory) fConfigElement.createExecutableExtension(ATTR_CLASS); - } catch (Exception e) { - RemoteCorePlugin.log(NLS.bind(Messages.RemoteServicesProxy_1, new Object[] { fConfigElement.getAttribute(ATTR_CLASS), - fId, fConfigElement.getDeclaringExtension().getNamespaceIdentifier() })); - } - return fFactory; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getId() - */ - @Override - public String getId() { - return fId; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getName() - */ - @Override - public String getName() { - return fName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getScheme() - */ - @Override - public String getScheme() { - return fScheme; - } - - /** - * Get the remote services implementation for this descriptor. The service has not been initialized. - * - * @return the remote services implementation - */ - public IRemoteServices getServices() { - loadServices(); - return fDelegate; - } - - /** - * Create the remote services factory. Note that the services will not be - * initialized. - */ - private void loadServices() { - if (fDelegate == null) { - IRemoteServicesFactory factory = getFactory(); - if (factory != null) { - fDelegate = factory.getServices(this); - } - } - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesImpl.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesImpl.java deleted file mode 100644 index 4fb7616033a..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.remote.core.RemoteServices; -import org.eclipse.remote.internal.core.services.local.LocalServices; - -/** - * Main entry point for remote services - * - * @since 7.0 - */ -public class RemoteServicesImpl { - public static final String REMOTE_SERVICES_EXTENSION_POINT_ID = "remoteServices"; //$NON-NLS-1$ - - // Active remote services plugins (not necessarily loaded) - private static final Map fRemoteServicesById = Collections - .synchronizedMap(new HashMap()); - private static final Map fRemoteServicesByScheme = Collections - .synchronizedMap(new HashMap()); - - private RemoteServicesImpl() { - // Hide constructor - } - - public static RemoteServicesDescriptor getRemoteServiceDescriptorById(String id) { - retrieveRemoteServices(); - return fRemoteServicesById.get(id); - } - - public static RemoteServicesDescriptor getRemoteServiceDescriptorByURI(URI uri) { - String scheme = uri.getScheme(); - if (scheme != null) { - retrieveRemoteServices(); - return fRemoteServicesByScheme.get(scheme); - } - return null; - } - - /** - * Retrieve a sorted list of remote service descriptors. Does not return the local service provider. This must be obtained - * using the {@link RemoteServices#getLocalServices()} method. - * - * @return remote service descriptors - */ - public static List getRemoteServiceDescriptors() { - retrieveRemoteServices(); - List descriptors = new ArrayList(); - for (RemoteServicesDescriptor descriptor : fRemoteServicesById.values()) { - if (!descriptor.getId().equals(LocalServices.LocalServicesId)) { - descriptors.add(descriptor); - } - } - Collections.sort(descriptors); - return descriptors; - } - - /** - * Find and load all remoteServices plugins. - */ - private static void retrieveRemoteServices() { - if (fRemoteServicesById.isEmpty()) { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = registry.getExtensionPoint(RemoteCorePlugin.getUniqueIdentifier(), - REMOTE_SERVICES_EXTENSION_POINT_ID); - final IExtension[] extensions = extensionPoint.getExtensions(); - - for (IExtension ext : extensions) { - final IConfigurationElement[] elements = ext.getConfigurationElements(); - - for (IConfigurationElement ce : elements) { - RemoteServicesDescriptor proxy = new RemoteServicesDescriptor(ce); - fRemoteServicesById.put(proxy.getId(), proxy); - fRemoteServicesByScheme.put(proxy.getScheme(), proxy); - } - } - } - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesManager.java new file mode 100644 index 00000000000..7195f99265a --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteServicesManager.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * 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.internal.core; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.SecurePreferencesFactory; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionChangeListener; +import org.eclipse.remote.core.IRemoteConnectionProviderService; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.core.RemoteConnectionChangeEvent; +import org.osgi.service.prefs.Preferences; + +/** + * The implementation for the remote services manager service. + */ +public class RemoteServicesManager implements IRemoteServicesManager { + + private static final String LOCAL_SERVICES_ID = "org.eclipse.remote.LocalServices"; //$NON-NLS-1$ + + // Map from id to remote services + private final Map connectionTypeMap = new HashMap<>(); + + // Map from URI scheme to remote services + private final Map schemeMap = new HashMap<>(); + + private final List listeners = new LinkedList<>(); + private boolean inited; + + /** + * Loads up the services extensions and then loads up the persisted connections. + * This stuff can't be done from the constructor for the manager since that's done + * in the bundle activator which is way too early. It also gives us the ability + * to override the initialization in tests + */ + protected void init() { + if (inited) { + return; + } + inited = true; + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint point = registry.getExtensionPoint(RemoteCorePlugin.getUniqueIdentifier(), "remoteServices"); //$NON-NLS-1$ + + // Load up the connection types + for (IExtension ext : point.getExtensions()) { + for (IConfigurationElement ce : ext.getConfigurationElements()) { + if (ce.getName().equals("connectionType")) { //$NON-NLS-1$ + RemoteConnectionType services = new RemoteConnectionType(ce, this); + connectionTypeMap.put(services.getId(), services); + String scheme = services.getScheme(); + if (scheme != null) { + schemeMap.put(scheme, services); + } + } + } + } + + // Load up the services + for (IExtension ext : point.getExtensions()) { + for (IConfigurationElement ce : ext.getConfigurationElements()) { + String name = ce.getName(); + if (name.equals("connectionTypeService") || name.equals("connectionService")) { //$NON-NLS-1$ //$NON-NLS-2$ + String id = ce.getAttribute("connectionTypeId"); //$NON-NLS-1$ + RemoteConnectionType services = connectionTypeMap.get(id); + if (services != null) { + services.addService(ce); + } + } + } + } + + // Init connection providers + for (IRemoteConnectionType connectionType : connectionTypeMap.values()) { + IRemoteConnectionProviderService providerService = connectionType.getService(IRemoteConnectionProviderService.class); + if (providerService != null) { + providerService.init(); + } + } + } + + public Preferences getPreferenceNode() { + return InstanceScope.INSTANCE.getNode(RemoteCorePlugin.getUniqueIdentifier()).node("connections"); //$NON-NLS-1$ + } + + public ISecurePreferences getSecurePreferenceNode() { + return SecurePreferencesFactory.getDefault().node(RemoteCorePlugin.getUniqueIdentifier()).node("connections"); //$NON-NLS-1$ + } + + @Override + public IRemoteConnectionType getConnectionType(String id) { + init(); + return connectionTypeMap.get(id); + } + + @Override + public IRemoteConnectionType getConnectionType(URI uri) { + init(); + return schemeMap.get(uri.getScheme()); + } + + @Override + public IRemoteConnectionType getLocalConnectionType() { + return getConnectionType(LOCAL_SERVICES_ID); + } + + @Override + public List getAllConnectionTypes() { + init(); + return new ArrayList(connectionTypeMap.values()); + } + + @Override + public List getRemoteConnectionTypes() { + init(); + List services = new ArrayList<>(connectionTypeMap.values().size() - 1); + IRemoteConnectionType localServices = getLocalConnectionType(); + for (IRemoteConnectionType s : connectionTypeMap.values()) { + if (!s.equals(localServices)) { + services.add(s); + } + } + return services; + } + + @Override + public List getAllRemoteConnections() { + // TODO do this without getting the connection managers and force loading the plugins + List connections = new ArrayList<>(); + for (IRemoteConnectionType services : getAllConnectionTypes()) { + connections.addAll(services.getConnections()); + } + return connections; + } + + @Override + public void addRemoteConnectionChangeListener(IRemoteConnectionChangeListener listener) { + synchronized (listeners) { + listeners.add(listener); + } + } + + @Override + public void removeRemoteConnectionChangeListener(IRemoteConnectionChangeListener listener) { + synchronized (listeners) { + listeners.remove(listener); + } + } + + @Override + public void fireRemoteConnectionChangeEvent(RemoteConnectionChangeEvent event) { + List iListeners; + synchronized (listeners) { + iListeners = new ArrayList<>(listeners); + } + for (IRemoteConnectionChangeListener listener : iListeners) { + listener.connectionChanged(event); + } + } + +} 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); + } + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnection.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnection.java deleted file mode 100644 index 18b112be9c7..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnection.java +++ /dev/null @@ -1,413 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core.services.local; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.Path; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionChangeEvent; -import org.eclipse.remote.core.IRemoteConnectionChangeListener; -import org.eclipse.remote.core.IRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.core.IRemoteFileManager; -import org.eclipse.remote.core.IRemoteProcess; -import org.eclipse.remote.core.IRemoteProcessBuilder; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.exception.RemoteConnectionException; -import org.eclipse.remote.core.exception.UnableToForwardPortException; -import org.eclipse.remote.internal.core.RemoteCorePlugin; -import org.eclipse.remote.internal.core.messages.Messages; - -public class LocalConnection implements IRemoteConnection { - private final String fName = IRemoteConnectionManager.LOCAL_CONNECTION_NAME; - private final String fAddress = Messages.LocalConnection_1; - private final String fUsername = System.getProperty("user.name"); //$NON-NLS-1$ - private boolean fConnected = true; - private IPath fWorkingDir = null; - - private final IRemoteFileManager fFileMgr = new LocalFileManager(); - private final IRemoteConnection fConnection = this; - private final IRemoteServices fRemoteServices; - private final ListenerList fListeners = new ListenerList(); - - public LocalConnection(IRemoteServices services) { - fRemoteServices = services; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#addConnectionChangeListener - * (org.eclipse.remote.core.IRemoteConnectionChangeListener) - */ - @Override - public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) { - fListeners.add(listener); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#close() - */ - @Override - public void close() { - if (fConnected) { - fConnected = false; - fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_CLOSED); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(IRemoteConnection connection) { - return getName().compareTo(connection.getName()); - } - - /** - * Notify all listeners when this connection's status changes. - * - * @param event - */ - @Override - public void fireConnectionChangeEvent(final int type) { - IRemoteConnectionChangeEvent event = new IRemoteConnectionChangeEvent() { - @Override - public IRemoteConnection getConnection() { - return fConnection; - } - - @Override - public int getType() { - return type; - } - }; - for (Object listener : fListeners.getListeners()) { - ((IRemoteConnectionChangeListener) listener).connectionChanged(event); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(int, - * java.lang.String, int) - */ - @Override - public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException { - throw new UnableToForwardPortException(Messages.LocalConnection_2); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(java.lang - * .String, int, org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException { - throw new UnableToForwardPortException(Messages.LocalConnection_2); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(int, - * java.lang.String, int) - */ - @Override - public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException { - throw new UnableToForwardPortException(Messages.LocalConnection_2); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(java. - * lang.String, int, org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException { - throw new UnableToForwardPortException(Messages.LocalConnection_2); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getAddress() - */ - @Override - public String getAddress() { - return fAddress; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getAttributes() - */ - @Override - public Map getAttributes() { - return new HashMap(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getCommandShell(int) - */ - @Override - public IRemoteProcess getCommandShell(int flags) throws IOException { - throw new IOException("Not currently implemented"); //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getEnv() - */ - @Override - public Map getEnv() { - return System.getenv(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#getEnv(java.lang.String) - */ - @Override - public String getEnv(String name) { - return System.getenv(name); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getFileManager(j) - */ - @Override - public IRemoteFileManager getFileManager() { - return fFileMgr; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getName() - */ - @Override - public String getName() { - return fName; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getPort() - */ - @Override - public int getPort() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.util.List) - */ - @Override - public IRemoteProcessBuilder getProcessBuilder(List command) { - return new LocalProcessBuilder(command); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.lang.String[]) - */ - @Override - public IRemoteProcessBuilder getProcessBuilder(String... command) { - return new LocalProcessBuilder(command); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#getProperty(java.lang.String - * ) - */ - @Override - public String getProperty(String key) { - /* - * Convert os.name and os.arch to framework properties so they make more sense - */ - switch (key) { - case IRemoteConnection.OS_NAME_PROPERTY: - return RemoteCorePlugin.getDefault().getBundle().getBundleContext().getProperty("osgi.os"); //$NON-NLS-1$ - case IRemoteConnection.OS_ARCH_PROPERTY: - return RemoteCorePlugin.getDefault().getBundle().getBundleContext().getProperty("osgi.arch"); //$NON-NLS-1$ - } - return System.getProperty(key); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getRemoteServices() - */ - @Override - public IRemoteServices getRemoteServices() { - return fRemoteServices; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getUsername() - */ - @Override - public String getUsername() { - return fUsername; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() - */ - @Override - public IRemoteConnectionWorkingCopy getWorkingCopy() { - return new LocalConnectionWorkingCopy(this); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteFileManager#getWorkingDirectory(org - * .eclipse.core.runtime.IProgressMonitor) - */ - @Override - public String getWorkingDirectory() { - if (fWorkingDir == null) { - String cwd = System.getProperty("user.home"); //$NON-NLS-1$ - if (cwd == null) { - cwd = System.getProperty("user.dir"); //$NON-NLS-1$; - } - if (cwd == null) { - fWorkingDir = Path.ROOT; - } else { - fWorkingDir = new Path(cwd); - } - } - return fWorkingDir.toString(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#isOpen() - */ - @Override - public boolean isOpen() { - return fConnected; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#open() - */ - @Override - public void open(IProgressMonitor monitor) throws RemoteConnectionException { - if (!fConnected) { - fConnected = true; - fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#removeConnectionChangeListener - * (org.eclipse.remote.core.IRemoteConnectionChangeListener) - */ - @Override - public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) { - fListeners.remove(listener); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#removeLocalPortForwarding(int) - */ - @Override - public void removeLocalPortForwarding(int port) throws RemoteConnectionException { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#removeRemotePortForwarding(int) - */ - @Override - public void removeRemotePortForwarding(int port) throws RemoteConnectionException { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteFileManager#setWorkingDirectory(java - * .lang.String) - */ - @Override - public void setWorkingDirectory(String pathStr) { - IPath path = new Path(pathStr); - if (path.isAbsolute()) { - fWorkingDir = path; - } - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnection#supportsTCPPortForwarding() - */ - @Override - public boolean supportsTCPPortForwarding() { - return false; - } - -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionManager.java deleted file mode 100644 index 23468927c16..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core.services.local; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.filesystem.EFS; -import org.eclipse.remote.core.AbstractRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.exception.RemoteConnectionException; -import org.eclipse.remote.internal.core.messages.Messages; - -public class LocalConnectionManager extends AbstractRemoteConnectionManager { - private final IRemoteConnection fLocalConnection; - - public LocalConnectionManager(IRemoteServices services) { - super(services); - fLocalConnection = new LocalConnection(services); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#getConnection(java - * .lang.String) - */ - @Override - public IRemoteConnection getConnection(String name) { - if (name.equals(fLocalConnection.getName())) { - return fLocalConnection; - } - return null; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#getConnection(java - * .net.URI) - */ - @Override - public IRemoteConnection getConnection(URI uri) { - if (uri.getScheme().equals(EFS.getLocalFileSystem().getScheme())) { - return fLocalConnection; - } - return null; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#getConnections() - */ - @Override - public List getConnections() { - List list = new ArrayList(); - list.add(fLocalConnection); - return list; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#newConnection(java - * .lang.String) - */ - @Override - public IRemoteConnectionWorkingCopy newConnection(String name) throws RemoteConnectionException { - throw new RemoteConnectionException(Messages.Unable_to_create_new_local_connections); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#removeConnection - * (org.eclipse.remote.core.IRemoteConnection) - */ - @Override - public void removeConnection(IRemoteConnection connection) { - // Nothing - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java new file mode 100644 index 00000000000..2ed4089a60a --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.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.internal.core.services.local; + +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnection.Service; +import org.eclipse.remote.core.IRemoteConnectionPropertyService; +import org.eclipse.remote.internal.core.RemoteCorePlugin; + +public class LocalConnectionPropertyService implements IRemoteConnectionPropertyService { + + private final IRemoteConnection connection; + + public LocalConnectionPropertyService(IRemoteConnection connection) { + this.connection = connection; + } + + public static class Factory implements IRemoteConnectionPropertyService.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnection remoteConnection, Class service) { + if (service.equals(IRemoteConnectionPropertyService.class)) { + return (T) new LocalConnectionPropertyService(remoteConnection); + } + return null; + } + } + + @Override + public IRemoteConnection getRemoteConnection() { + return connection; + } + + @Override + public String getProperty(String key) { + switch (key) { + case IRemoteConnection.OS_NAME_PROPERTY: + return RemoteCorePlugin.getDefault().getBundle().getBundleContext().getProperty("osgi.os"); //$NON-NLS-1$ + case IRemoteConnection.OS_ARCH_PROPERTY: + return RemoteCorePlugin.getDefault().getBundle().getBundleContext().getProperty("osgi.arch"); //$NON-NLS-1$ + } + return System.getProperty(key); + } + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionProviderService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionProviderService.java new file mode 100644 index 00000000000..71128b744fb --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionProviderService.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 + * + * Contributors: + * QNX - initial API and implementation + *******************************************************************************/ +package org.eclipse.remote.internal.core.services.local; + +import org.eclipse.remote.core.IRemoteConnectionProviderService; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionType.Service; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.internal.core.RemoteCorePlugin; + +public class LocalConnectionProviderService implements IRemoteConnectionProviderService { + + private static final String localConnectionName = Messages.LocalConnectionProviderService_LocalConnectionName; + + private IRemoteConnectionType connectionType; + + public static class Factory implements IRemoteConnectionType.Service.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnectionType connectionType, Class service) { + if (service.equals(IRemoteConnectionProviderService.class)) { + return (T) new LocalConnectionProviderService(connectionType); + } + return null; + } + } + + public LocalConnectionProviderService(IRemoteConnectionType connectionType) { + this.connectionType = connectionType; + } + + @Override + public void init() { + if (connectionType.getConnections().isEmpty()) { + try { + connectionType.newConnection(localConnectionName).save(); + } catch (RemoteConnectionException e) { + RemoteCorePlugin.log(e.getStatus()); + } + } + } + + @Override + public IRemoteConnectionType getConnectionType() { + return connectionType; + } + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionWorkingCopy.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionWorkingCopy.java deleted file mode 100644 index a9c0073104d..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionWorkingCopy.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core.services.local; - -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; - -public class LocalConnectionWorkingCopy extends LocalConnection implements IRemoteConnectionWorkingCopy { - - private final LocalConnection fOriginal; - - public LocalConnectionWorkingCopy(LocalConnection connection) { - super(connection.getRemoteServices()); - fOriginal = connection; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#getOriginal() - */ - @Override - public IRemoteConnection getOriginal() { - return fOriginal; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#isDirty() - */ - @Override - public boolean isDirty() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#save() - */ - @Override - public IRemoteConnection save() { - return fOriginal; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAddress(java.lang.String) - */ - @Override - public void setAddress(String address) { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAttribute(java.lang.String, java.lang.String) - */ - @Override - public void setAttribute(String key, String value) { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String) - */ - @Override - public void setName(String name) { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPassword(java.lang.String) - */ - @Override - public void setPassword(String password) { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPort(int) - */ - @Override - public void setPort(int port) { - // Do nothing - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setUsername(java.lang.String) - */ - @Override - public void setUsername(String username) { - // Do nothing - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalFileManager.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalFileManager.java index c619b7084bf..5577850b453 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalFileManager.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalFileManager.java @@ -17,56 +17,56 @@ import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.remote.core.IRemoteFileManager; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteFileService; +import org.eclipse.remote.core.IRemoteProcessService; + +public class LocalFileManager implements IRemoteFileService { + + private final IRemoteConnection connection; + + public LocalFileManager(IRemoteConnection connection) { + this.connection = connection; + } + + @Override + public IRemoteConnection getRemoteConnection() { + return connection; + } -public class LocalFileManager implements IRemoteFileManager { - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteFileManager#getDirectorySeparator() - */ @Override public String getDirectorySeparator() { return System.getProperty("file.separator", "/"); //$NON-NLS-1$ //$NON-NLS-2$ } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteFileManager#getResource(java.lang.String) - */ @Override public IFileStore getResource(String path) { return EFS.getLocalFileSystem().getStore(new Path(path)); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteFileManager#toPath(java.net.URI) - */ + @Override + public String getBaseDirectory() { + return connection.getService(IRemoteProcessService.class).getWorkingDirectory(); + } + + @Override + public void setBaseDirectory(String path) { + connection.getService(IRemoteProcessService.class).setWorkingDirectory(path); + } + @Override public String toPath(URI uri) { return URIUtil.toPath(uri).toString(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteFileManager#toURI(org.eclipse.core.runtime.IPath) - */ @Override public URI toURI(IPath path) { return URIUtil.toURI(path); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteFileManager#toURI(java.lang.String) - */ @Override public URI toURI(String path) { return URIUtil.toURI(path); } + } diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalProcessService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalProcessService.java new file mode 100644 index 00000000000..6bdb204c1ee --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalProcessService.java @@ -0,0 +1,76 @@ +package org.eclipse.remote.internal.core.services.local; + +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.Path; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnection.Service; +import org.eclipse.remote.core.IRemoteProcessBuilder; +import org.eclipse.remote.core.IRemoteProcessService; + +public class LocalProcessService implements IRemoteProcessService { + + private final IRemoteConnection remoteConnection; + private String workingDirectory; + + public LocalProcessService(IRemoteConnection remoteConnection) { + this.remoteConnection = remoteConnection; + } + + public static class Factory implements IRemoteProcessService.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnection remoteConnection, Class service) { + if (IRemoteProcessService.class.equals(service)) { + return (T) new LocalProcessService(remoteConnection); + } + return null; + } + } + + @Override + public IRemoteConnection getRemoteConnection() { + return remoteConnection; + } + + @Override + public Map getEnv() { + return System.getenv(); + } + + @Override + public String getEnv(String name) { + return System.getenv(name); + } + + @Override + public IRemoteProcessBuilder getProcessBuilder(List command) { + return new LocalProcessBuilder(command); + } + + @Override + public IRemoteProcessBuilder getProcessBuilder(String... command) { + return new LocalProcessBuilder(command); + } + + @Override + public String getWorkingDirectory() { + if (workingDirectory == null) { + workingDirectory = System.getProperty("user.home"); //$NON-NLS-1$ + if (workingDirectory == null) { + workingDirectory = System.getProperty("user.dir"); //$NON-NLS-1$ + if (workingDirectory == null) { + workingDirectory = Path.ROOT.toOSString(); + } + } + } + return workingDirectory; + } + + @Override + public void setWorkingDirectory(String path) { + workingDirectory = path; + } + +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServices.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServices.java deleted file mode 100644 index 06024a5a78c..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServices.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core.services.local; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.remote.core.AbstractRemoteServices; -import org.eclipse.remote.core.IRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteServicesDescriptor; - -public class LocalServices extends AbstractRemoteServices { - public static final String LocalServicesId = "org.eclipse.remote.LocalServices"; //$NON-NLS-1$ - - private final IRemoteConnectionManager fConnMgr = new LocalConnectionManager(this); - - public LocalServices(IRemoteServicesDescriptor descriptor) { - super(descriptor); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getCapabilities() - */ - @Override - public int getCapabilities() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteServicesDescriptor#getConnectionManager - * () - */ - @Override - public IRemoteConnectionManager getConnectionManager() { - return fConnMgr; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#initialize(org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public boolean initialize(IProgressMonitor monitor) { - return true; - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServicesFactory.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServicesFactory.java deleted file mode 100644 index ae24bd94140..00000000000 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalServicesFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.core.services.local; - -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.IRemoteServicesDescriptor; -import org.eclipse.remote.core.IRemoteServicesFactory; - -public class LocalServicesFactory implements IRemoteServicesFactory { - private static LocalServices services = null; - - /* (non-Javadoc) - * @see org.eclipse.remote.core.IRemoteServicesFactory#getServices(org.eclipse.remote.core.IRemoteServicesDescriptor) - */ - public IRemoteServices getServices(IRemoteServicesDescriptor descriptor) { - if (services == null) { - services = new LocalServices(descriptor); - } - return services; - } -} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/Messages.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/Messages.java new file mode 100644 index 00000000000..571f9045ca8 --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/Messages.java @@ -0,0 +1,15 @@ +package org.eclipse.remote.internal.core.services.local; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.remote.internal.core.services.local.messages"; //$NON-NLS-1$ + public static String LocalConnectionProviderService_LocalConnectionName; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/messages.properties b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/messages.properties new file mode 100644 index 00000000000..e72dc8616fc --- /dev/null +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/messages.properties @@ -0,0 +1 @@ +LocalConnectionProviderService_LocalConnectionName=Local diff --git a/bundles/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF index a004fb31789..35e5cbd3b36 100644 --- a/bundles/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.remote.jsch.core/META-INF/MANIFEST.MF @@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, com.jcraft.jsch, org.eclipse.equinox.security Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.remote.internal.jsch.core;x-friends:="org.eclipse.remote.jsch.ui", +Export-Package: org.eclipse.remote.internal.jsch.core;x-friends:="org.eclipse.remote.jsch.ui,org.eclipse.remote.jsch.tests", org.eclipse.remote.internal.jsch.core.messages;x-internal:=true Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.7 diff --git a/bundles/org.eclipse.remote.jsch.core/plugin.xml b/bundles/org.eclipse.remote.jsch.core/plugin.xml index e6bc8c9474b..0a85f2ed12c 100644 --- a/bundles/org.eclipse.remote.jsch.core/plugin.xml +++ b/bundles/org.eclipse.remote.jsch.core/plugin.xml @@ -3,12 +3,42 @@ - - + + + + + + + + + + + + + T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + public IJSchService getService() { return fJSchService; } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java index 0ca81d6c5b3..89155a6fe52 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.remote.internal.jsch.core; -import java.io.IOException; import java.net.PasswordAuthentication; import java.util.ArrayList; import java.util.Collections; @@ -19,20 +18,19 @@ import java.util.List; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jsch.core.IJSchService; import org.eclipse.osgi.util.NLS; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionChangeEvent; -import org.eclipse.remote.core.IRemoteConnectionChangeListener; +import org.eclipse.remote.core.IRemoteConnectionControlService; +import org.eclipse.remote.core.IRemoteConnectionPropertyService; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.core.IRemoteFileManager; -import org.eclipse.remote.core.IRemoteProcess; +import org.eclipse.remote.core.IRemotePortForwardingService; import org.eclipse.remote.core.IRemoteProcessBuilder; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.IUserAuthenticator; +import org.eclipse.remote.core.IRemoteProcessService; +import org.eclipse.remote.core.IUserAuthenticatorService; +import org.eclipse.remote.core.RemoteConnectionChangeEvent; import org.eclipse.remote.core.exception.AddressInUseException; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.core.exception.UnableToForwardPortException; @@ -50,17 +48,27 @@ import com.jcraft.jsch.UserInfo; /** * @since 5.0 */ -public class JSchConnection implements IRemoteConnection { +public class JSchConnection implements IRemoteConnectionControlService, IRemoteConnectionPropertyService, IRemotePortForwardingService, IRemoteProcessService { + // Connection Type ID + public static final String JSCH_ID = "org.eclipse.remote.JSch"; //$NON-NLS-1$ + + // Attributes + public static final String ADDRESS_ATTR = "JSCH_ADDRESS_ATTR"; //$NON-NLS-1$ + public static final String USERNAME_ATTR = "JSCH_USERNAME_ATTR"; //$NON-NLS-1$ + public static final String PASSWORD_ATTR = "JSCH_PASSWORD_ATTR"; //$NON-NLS-1$ + public static final String PORT_ATTR = "JSCH_PORT_ATTR"; //$NON-NLS-1$ + public static final String PROXYCONNECTION_ATTR = "JSCH_PROXYCONNECTION_ATTR"; //$NON-NLS-1$ + public static final String PROXYCOMMAND_ATTR = "JSCH_PROXYCOMMAND_ATTR"; //$NON-NLS-1$ + public static final String IS_PASSWORD_ATTR = "JSCH_IS_PASSWORD_ATTR"; //$NON-NLS-1$ + public static final String PASSPHRASE_ATTR = "JSCH_PASSPHRASE_ATTR"; //$NON-NLS-1$ + public static final String TIMEOUT_ATTR = "JSCH_TIMEOUT_ATTR"; //$NON-NLS-1$ + public static final String USE_LOGIN_SHELL_ATTR = "JSCH_USE_LOGIN_SHELL_ATTR"; //$NON-NLS-1$ + /** * Class to supply credentials from connection attributes without user interaction. */ private class JSchUserInfo implements UserInfo, UIKeyboardInteractive { private boolean firstTryPassphrase = true; - private final IUserAuthenticator fAuthenticator; - - public JSchUserInfo(IUserAuthenticator authenticator) { - fAuthenticator = authenticator; - } @Override public String getPassphrase() { @@ -88,11 +96,18 @@ public class JSchConnection implements IRemoteConnection { } } - if (fAuthenticator != null) { - String[] result = fAuthenticator.prompt(destination, name, instruction, prompt, echo); + IUserAuthenticatorService authService = fRemoteConnection.getService(IUserAuthenticatorService.class); + if (authService != null) { + String[] result = authService.prompt(destination, name, instruction, prompt, echo); if (result != null) { if (prompt.length == 1 && prompt[0].trim().equalsIgnoreCase("password:")) { //$NON-NLS-1$ - fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, result[0]); + IRemoteConnectionWorkingCopy wc = fRemoteConnection.getWorkingCopy(); + wc.setSecureAttribute(PASSWORD_ATTR, result[0]); + try { + wc.save(); + } catch (RemoteConnectionException e) { + Activator.log(e.getStatus()); + } } } return result; @@ -109,13 +124,20 @@ public class JSchConnection implements IRemoteConnection { firstTryPassphrase = false; return true; } - if (fAuthenticator != null) { - PasswordAuthentication auth = fAuthenticator.prompt(getUsername(), message); + IUserAuthenticatorService authService = fRemoteConnection.getService(IUserAuthenticatorService.class); + if (authService != null) { + PasswordAuthentication auth = authService.prompt(getUsername(), message); if (auth == null) { return false; } - fAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, auth.getUserName()); - fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, new String(auth.getPassword())); + IRemoteConnectionWorkingCopy wc = fRemoteConnection.getWorkingCopy(); + wc.setAttribute(USERNAME_ATTR, auth.getUserName()); + wc.setSecureAttribute(PASSPHRASE_ATTR, new String(auth.getPassword())); + try { + wc.save(); + } catch (RemoteConnectionException e) { + Activator.log(e.getStatus()); + } return true; } return false; @@ -126,13 +148,20 @@ public class JSchConnection implements IRemoteConnection { if (logging) { System.out.println("promptPassword:" + message); //$NON-NLS-1$ } - if (fAuthenticator != null) { - PasswordAuthentication auth = fAuthenticator.prompt(getUsername(), message); + IUserAuthenticatorService authService = fRemoteConnection.getService(IUserAuthenticatorService.class); + if (authService != null) { + PasswordAuthentication auth = authService.prompt(getUsername(), message); if (auth == null) { return false; } - fAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, auth.getUserName()); - fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, new String(auth.getPassword())); + IRemoteConnectionWorkingCopy wc = fRemoteConnection.getWorkingCopy(); + wc.setAttribute(USERNAME_ATTR, auth.getUserName()); + wc.setSecureAttribute(PASSWORD_ATTR, new String(auth.getPassword())); + try { + wc.save(); + } catch (RemoteConnectionException e) { + Activator.log(e.getStatus()); + } return true; } return false; @@ -143,10 +172,11 @@ public class JSchConnection implements IRemoteConnection { if (logging) { System.out.println("promptYesNo:" + message); //$NON-NLS-1$ } - if (fAuthenticator != null) { - int prompt = fAuthenticator.prompt(IUserAuthenticator.QUESTION, Messages.AuthInfo_Authentication_message, message, - new int[] { IUserAuthenticator.YES, IUserAuthenticator.NO }, IUserAuthenticator.YES); - return prompt == IUserAuthenticator.YES; + IUserAuthenticatorService authService = fRemoteConnection.getService(IUserAuthenticatorService.class); + if (authService != null) { + int prompt = authService.prompt(IUserAuthenticatorService.QUESTION, Messages.AuthInfo_Authentication_message, message, + new int[] { IUserAuthenticatorService.YES, IUserAuthenticatorService.NO }, IUserAuthenticatorService.YES); + return prompt == IUserAuthenticatorService.YES; } return true; } @@ -156,9 +186,10 @@ public class JSchConnection implements IRemoteConnection { if (logging) { System.out.println("showMessage:" + message); //$NON-NLS-1$ } - if (fAuthenticator != null) { - fAuthenticator.prompt(IUserAuthenticator.INFORMATION, Messages.AuthInfo_Authentication_message, message, - new int[] { IUserAuthenticator.OK }, IUserAuthenticator.OK); + IUserAuthenticatorService authService = fRemoteConnection.getService(IUserAuthenticatorService.class); + if (authService != null) { + authService.prompt(IUserAuthenticatorService.INFORMATION, Messages.AuthInfo_Authentication_message, message, + new int[] { IUserAuthenticatorService.OK }, IUserAuthenticatorService.OK); } } } @@ -173,35 +204,46 @@ public class JSchConnection implements IRemoteConnection { private String fWorkingDir; + private final IRemoteConnection fRemoteConnection; private final IJSchService fJSchService; - private final JSchConnectionAttributes fAttributes; - private final JSchConnectionManager fManager; private final Map fEnv = new HashMap(); private final Map fProperties = new HashMap(); - private final IRemoteServices fRemoteServices; - private final ListenerList fListeners = new ListenerList(); private final List fSessions = new ArrayList(); private ChannelSftp fSftpChannel; private boolean isFullySetup; // including sftp channel and environment - public JSchConnection(String name, IRemoteServices services) { - fRemoteServices = services; - fManager = (JSchConnectionManager) services.getConnectionManager(); - fAttributes = new JSchConnectionAttributes(name); + public JSchConnection(IRemoteConnection connection) { + fRemoteConnection = connection; fJSchService = Activator.getDefault().getService(); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#addConnectionChangeListener - * (org.eclipse.remote.core.IRemoteConnectionChangeListener) - */ @Override - public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) { - fListeners.add(listener); + public IRemoteConnection getRemoteConnection() { + return fRemoteConnection; + } + + public static class Factory implements IRemoteConnection.Service.Factory { + @Override + @SuppressWarnings("unchecked") + public T getService(IRemoteConnection connection, Class service) { + // This little trick creates an instance of this class for a connection + // then for each interface it implements, it returns the same object. + // This works because the connection caches the service so only one gets created. + // As a side effect, it makes this class a service too which can be used + // by the this plug-in + if (JSchConnection.class.equals(service)) { + return (T) new JSchConnection(connection); + } else if (IRemoteConnectionControlService.class.equals(service) + || IRemoteConnectionPropertyService.class.equals(service) + || IRemotePortForwardingService.class.equals(service) + || IRemoteProcessService.class.equals(service)) { + return (T) connection.getService(JSchConnection.class); + } else { + return null; + } + } } private boolean checkConfiguration(Session session, IProgressMonitor monitor) throws RemoteConnectionException { @@ -237,19 +279,14 @@ public class JSchConnection implements IRemoteConnection { * @throws RemoteConnectionException */ private void checkIsConfigured() throws RemoteConnectionException { - if (fAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, null) == null) { + if (fRemoteConnection.getAttribute(ADDRESS_ATTR) == null) { throw new RemoteConnectionException(Messages.JSchConnection_remote_address_must_be_set); } - if (fAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, null) == null) { + if (fRemoteConnection.getAttribute(USERNAME_ATTR) == null) { throw new RemoteConnectionException(Messages.JSchConnection_username_must_be_set); } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#close() - */ @Override public synchronized void close() { if (fSftpChannel != null) { @@ -264,17 +301,7 @@ public class JSchConnection implements IRemoteConnection { } } fSessions.clear(); - fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_CLOSED); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(IRemoteConnection o) { - return getName().compareTo(o.getName()); + fRemoteConnection.fireConnectionChangeEvent(RemoteConnectionChangeEvent.CONNECTION_CLOSED); } /** @@ -293,35 +320,6 @@ public class JSchConnection implements IRemoteConnection { return exec.setCommand(cmd).getResult(monitor).trim(); } - /** - * Notify all fListeners when this connection's status changes. - * - * @param event - */ - @Override - public void fireConnectionChangeEvent(final int type) { - final IRemoteConnection connection = this; - IRemoteConnectionChangeEvent event = new IRemoteConnectionChangeEvent() { - @Override - public IRemoteConnection getConnection() { - return connection; - } - - @Override - public int getType() { - return type; - } - }; - for (Object listener : fListeners.getListeners()) { - ((IRemoteConnectionChangeListener) listener).connectionChanged(event); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(int, java.lang.String, int) - */ @Override public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException { if (!isOpen()) { @@ -334,12 +332,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(java.lang .String, int, - * org.eclipse.core.runtime.IProgressMonitor) - */ @Override public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException { if (!isOpen()) { @@ -370,11 +362,6 @@ public class JSchConnection implements IRemoteConnection { return -1; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(int, java.lang.String, int) - */ @Override public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException { if (!isOpen()) { @@ -387,12 +374,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(java.lang.String, int, - * org.eclipse.core.runtime.IProgressMonitor) - */ @Override public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException { if (!isOpen()) { @@ -422,34 +403,8 @@ public class JSchConnection implements IRemoteConnection { return -1; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getAddress() - */ - @Override public String getAddress() { - return fAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getAttributes() - */ - @Override - public Map getAttributes() { - return Collections.unmodifiableMap(fAttributes.getAttributes()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getCommandShell(int) - */ - @Override - public IRemoteProcess getCommandShell(int flags) throws IOException { - throw new IOException("Not currently implemented"); //$NON-NLS-1$ + return fRemoteConnection.getAttribute(ADDRESS_ATTR); } /** @@ -467,21 +422,11 @@ public class JSchConnection implements IRemoteConnection { return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getEnv() - */ @Override public Map getEnv() { return Collections.unmodifiableMap(fEnv); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getEnv(java.lang.String) - */ @Override public String getEnv(String name) { return getEnv().get(name); @@ -503,89 +448,41 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getFileManager() - */ - @Override - public IRemoteFileManager getFileManager() { - return new JSchFileManager(this); - } - - public JSchConnectionAttributes getInfo() { - return fAttributes; - } - - public JSchConnectionManager getManager() { - return fManager; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getName() - */ - @Override - public String getName() { - return fAttributes.getName(); - } - public String getPassphrase() { - return fAttributes.getSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, EMPTY_STRING); + return fRemoteConnection.getSecureAttribute(PASSPHRASE_ATTR); } public String getPassword() { - return fAttributes.getSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, EMPTY_STRING); + return fRemoteConnection.getSecureAttribute(PASSWORD_ATTR); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getPort() - */ - @Override public int getPort() { - return fAttributes.getInt(JSchConnectionAttributes.PORT_ATTR, DEFAULT_PORT); + String portStr = fRemoteConnection.getAttribute(PORT_ATTR); + return portStr != null ? Integer.parseInt(portStr) : DEFAULT_PORT; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.util.List) - */ @Override public IRemoteProcessBuilder getProcessBuilder(List command) { return new JSchProcessBuilder(this, command); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.lang.String[]) - */ @Override public IRemoteProcessBuilder getProcessBuilder(String... command) { return new JSchProcessBuilder(this, command); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getProperty(java.lang.String ) - */ @Override public String getProperty(String key) { return fProperties.get(key); } /** - * Gets the proxy command. For no proxy command an empty string is returned. + * Gets the proxy command. For no proxy command null is returned. * * @return proxy command */ public String getProxyCommand() { - return fAttributes.getAttribute(JSchConnectionAttributes.PROXYCOMMAND_ATTR, EMPTY_STRING); + return fRemoteConnection.getAttribute(PROXYCOMMAND_ATTR); } /** @@ -595,29 +492,19 @@ public class JSchConnection implements IRemoteConnection { */ public JSchConnection getProxyConnection() { String proxyConnectionName = getProxyConnectionName(); - if (proxyConnectionName.equals(EMPTY_STRING)) { + if (proxyConnectionName.isEmpty()) { return null; } - return (JSchConnection) fManager.getConnection(proxyConnectionName); + return fRemoteConnection.getConnectionType().getConnection(proxyConnectionName).getService(JSchConnection.class); } /** * Gets the proxy connection name * - * @return proxy connection name. If no proxy is used returns an empty string. Never returns null. + * @return proxy connection name. If no proxy is used returns null. */ public String getProxyConnectionName() { - return fAttributes.getAttribute(JSchConnectionAttributes.PROXYCONNECTION_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getRemoteServices() - */ - @Override - public IRemoteServices getRemoteServices() { - return fRemoteServices; + return fRemoteConnection.getAttribute(PROXYCONNECTION_ATTR); } /** @@ -641,11 +528,6 @@ public class JSchConnection implements IRemoteConnection { return fSftpChannel; } - /* - * (non-Javadoc) - * - * @see com.jcraft.jsch.Session#getStreamForwarder(java.lang.String, int) - */ public Channel getStreamForwarder(String host, int port) throws RemoteConnectionException { try { @@ -658,34 +540,14 @@ public class JSchConnection implements IRemoteConnection { } public int getTimeout() { - return fAttributes.getInt(JSchConnectionAttributes.TIMEOUT_ATTR, DEFAULT_TIMEOUT); + String str = fRemoteConnection.getAttribute(TIMEOUT_ATTR); + return str != null ? Integer.parseInt(str) : DEFAULT_TIMEOUT; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getUsername() - */ - @Override public String getUsername() { - return fAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, EMPTY_STRING); + return fRemoteConnection.getAttribute(USERNAME_ATTR); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() - */ - @Override - public IRemoteConnectionWorkingCopy getWorkingCopy() { - return new JSchConnectionWorkingCopy(this); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getWorkingDirectory() - */ @Override public String getWorkingDirectory() { if (!isOpen()) { @@ -715,18 +577,14 @@ public class JSchConnection implements IRemoteConnection { return hasOpenSession; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#isOpen() - */ @Override public boolean isOpen() { return hasOpenSession() && isFullySetup; } public boolean isPasswordAuth() { - return fAttributes.getBoolean(JSchConnectionAttributes.IS_PASSWORD_ATTR, DEFAULT_IS_PASSWORD); + String str = fRemoteConnection.getAttribute(IS_PASSWORD_ATTR); + return str != null ? Boolean.parseBoolean(str) : DEFAULT_IS_PASSWORD; } private void loadEnv(IProgressMonitor monitor) throws RemoteConnectionException { @@ -793,10 +651,10 @@ public class JSchConnection implements IRemoteConnection { */ private void loadProperties(IProgressMonitor monitor) throws RemoteConnectionException { SubMonitor subMon = SubMonitor.convert(monitor, 100); - fProperties.put(FILE_SEPARATOR_PROPERTY, "/"); //$NON-NLS-1$ - fProperties.put(PATH_SEPARATOR_PROPERTY, ":"); //$NON-NLS-1$ - fProperties.put(LINE_SEPARATOR_PROPERTY, "\n"); //$NON-NLS-1$ - fProperties.put(USER_HOME_PROPERTY, getWorkingDirectory()); + fProperties.put(IRemoteConnection.FILE_SEPARATOR_PROPERTY, "/"); //$NON-NLS-1$ + fProperties.put(IRemoteConnection.PATH_SEPARATOR_PROPERTY, ":"); //$NON-NLS-1$ + fProperties.put(IRemoteConnection.LINE_SEPARATOR_PROPERTY, "\n"); //$NON-NLS-1$ + fProperties.put(IRemoteConnection.USER_HOME_PROPERTY, getWorkingDirectory()); String osVersion; String osArch; @@ -830,26 +688,26 @@ public class JSchConnection implements IRemoteConnection { osVersion = "unknown"; //$NON-NLS-1$ osArch = "unknown"; //$NON-NLS-1$ } - fProperties.put(OS_NAME_PROPERTY, osName); - fProperties.put(OS_VERSION_PROPERTY, osVersion); - fProperties.put(OS_ARCH_PROPERTY, osArch); + fProperties.put(IRemoteConnection.OS_NAME_PROPERTY, osName); + fProperties.put(IRemoteConnection.OS_VERSION_PROPERTY, osVersion); + fProperties.put(IRemoteConnection.OS_ARCH_PROPERTY, osArch); } - private Session newSession(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException { + private Session newSession(IProgressMonitor monitor) throws RemoteConnectionException { SubMonitor progress = SubMonitor.convert(monitor, 10); try { Session session = fJSchService.createSession(getAddress(), getPort(), getUsername()); - session.setUserInfo(new JSchUserInfo(authenticator)); + session.setUserInfo(new JSchUserInfo()); if (isPasswordAuth()) { session.setConfig("PreferredAuthentications", "password,keyboard-interactive,gssapi-with-mic,publickey"); //$NON-NLS-1$ //$NON-NLS-2$ session.setPassword(getPassword()); } else { session.setConfig("PreferredAuthentications", "publickey,gssapi-with-mic,password,keyboard-interactive"); //$NON-NLS-1$ //$NON-NLS-2$ } - if (getProxyCommand().equals(EMPTY_STRING) && getProxyConnectionName().equals(EMPTY_STRING)) { + if (getProxyCommand().isEmpty() && getProxyConnectionName().isEmpty()) { fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10)); // connect without proxy } else { - if (getProxyCommand().equals(EMPTY_STRING)) { + if (getProxyCommand().isEmpty()) { session.setProxy(JSchConnectionProxyFactory.createForwardProxy(getProxyConnection(), progress.newChild(10))); fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10)); @@ -869,11 +727,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#open() - */ @Override public void open(IProgressMonitor monitor) throws RemoteConnectionException { open(monitor, true); @@ -903,7 +756,7 @@ public class JSchConnection implements IRemoteConnection { SubMonitor subMon = SubMonitor.convert(monitor, 60); if (!hasOpenSession()) { checkIsConfigured(); - newSession(fManager.getUserAuthenticator(this), subMon.newChild(10)); + newSession(subMon.newChild(10)); if (subMon.isCanceled()) { throw new RemoteConnectionException(Messages.JSchConnection_Connection_was_cancelled); } @@ -914,11 +767,11 @@ public class JSchConnection implements IRemoteConnection { // getCwd checks the exec channel before checkConfiguration checks the sftp channel fWorkingDir = getCwd(subMon.newChild(10)); if (!checkConfiguration(fSessions.get(0), subMon.newChild(20))) { - newSession(fManager.getUserAuthenticator(this), subMon.newChild(10)); + newSession(subMon.newChild(10)); loadEnv(subMon.newChild(10)); } loadProperties(subMon.newChild(10)); - fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED); + fRemoteConnection.fireConnectionChangeEvent(RemoteConnectionChangeEvent.CONNECTION_OPENED); } } @@ -932,22 +785,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#removeConnectionChangeListener - * (org.eclipse.remote.core.IRemoteConnectionChangeListener) - */ - @Override - public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) { - fListeners.remove(listener); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#removeLocalPortForwarding(int) - */ @Override public void removeLocalPortForwarding(int port) throws RemoteConnectionException { if (!isOpen()) { @@ -960,11 +797,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#removeRemotePortForwarding(int) - */ @Override public void removeRemotePortForwarding(int port) throws RemoteConnectionException { if (!isOpen()) { @@ -977,11 +809,6 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#setWorkingDirectory(java.lang.String) - */ @Override public void setWorkingDirectory(String path) { if (new Path(path).isAbsolute()) { @@ -989,31 +816,9 @@ public class JSchConnection implements IRemoteConnection { } } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#supportsTCPPortForwarding() - */ - @Override - public boolean supportsTCPPortForwarding() { - return true; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - String str = getName() + " [" + getUsername() + "@" + getAddress(); //$NON-NLS-1$ //$NON-NLS-2$ - if (getPort() >= 0) { - str += ":" + getPort(); //$NON-NLS-1$ - } - return str + "]"; //$NON-NLS-1$ - } - public boolean useLoginShell() { - return fAttributes.getBoolean(JSchConnectionAttributes.USE_LOGIN_SHELL_ATTR, DEFAULT_USE_LOGIN_SHELL); + String str = fRemoteConnection.getAttribute(USE_LOGIN_SHELL_ATTR); + return !str.isEmpty() ? Boolean.parseBoolean(str) : DEFAULT_USE_LOGIN_SHELL; } + } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionAttributes.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionAttributes.java deleted file mode 100644 index 4ceaa0af373..00000000000 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionAttributes.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2014 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - * Markus Schorn - Bug 449306: Unnecessary access to secure storage. - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.core; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.equinox.security.storage.ISecurePreferences; -import org.eclipse.equinox.security.storage.SecurePreferencesFactory; -import org.eclipse.equinox.security.storage.StorageException; -import org.osgi.service.prefs.BackingStoreException; -import org.osgi.service.prefs.Preferences; - -public class JSchConnectionAttributes { - public static final String CONNECTIONS_KEY = "connections"; //$NON-NLS-1$ - - public static final String ADDRESS_ATTR = "JSCH_ADDRESS_ATTR"; //$NON-NLS-1$ - public static final String USERNAME_ATTR = "JSCH_USERNAME_ATTR"; //$NON-NLS-1$ - public static final String PASSWORD_ATTR = "JSCH_PASSWORD_ATTR"; //$NON-NLS-1$ - public static final String PORT_ATTR = "JSCH_PORT_ATTR"; //$NON-NLS-1$ - public static final String PROXYCONNECTION_ATTR = "JSCH_PROXYCONNECTION_ATTR"; //$NON-NLS-1$ - public static final String PROXYCOMMAND_ATTR = "JSCH_PROXYCOMMAND_ATTR"; //$NON-NLS-1$ - public static final String IS_PASSWORD_ATTR = "JSCH_IS_PASSWORD_ATTR"; //$NON-NLS-1$ - public static final String PASSPHRASE_ATTR = "JSCH_PASSPHRASE_ATTR"; //$NON-NLS-1$ - public static final String TIMEOUT_ATTR = "JSCH_TIMEOUT_ATTR"; //$NON-NLS-1$ - public static final String USE_LOGIN_SHELL_ATTR = "JSCH_USE_LOGIN_SHELL_ATTR"; //$NON-NLS-1$ - - private String fName; - private String fNewName; - - private final Map fAttributes = Collections.synchronizedMap(new HashMap()); - private final Map fSecureAttributes = Collections.synchronizedMap(new HashMap()); - - private boolean fSecureAttributesLoaded; - - public JSchConnectionAttributes(String name) { - fName = name; - load(); - } - - private void clearPreferences() { - try { - getPreferences().clear(); - } catch (BackingStoreException e) { - Activator.log(e.getMessage()); - } - getSecurePreferences().clear(); - } - - public JSchConnectionAttributes copy() { - JSchConnectionAttributes copy = new JSchConnectionAttributes(fName); - copy.getAttributes().putAll(fAttributes); - copy.setSecureAttributes(getSecureAttributes()); - return copy; - } - - private void flushPreferences() { - try { - getPreferences().flush(); - } catch (BackingStoreException e) { - Activator.log(e.getMessage()); - } - try { - getSecurePreferences().flush(); - } catch (IOException e) { - Activator.log(e.getMessage()); - } - } - - public String getAttribute(String key, String def) { - if (fAttributes.containsKey(key)) { - return fAttributes.get(key); - } - return def; - } - - public Map getAttributes() { - return fAttributes; - } - - public boolean getBoolean(String key, boolean def) { - if (fAttributes.containsKey(key)) { - return Boolean.parseBoolean(fAttributes.get(key)); - } - return def; - } - - public int getInt(String key, int def) { - try { - return Integer.parseInt(fAttributes.get(key)); - } catch (NumberFormatException e) { - return def; - } - } - - public String getName() { - if (fNewName == null) { - return fName; - } - return fNewName; - } - - private Preferences getPreferences() { - IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); - Preferences connections = root.node(CONNECTIONS_KEY); - return connections.node(fName); - } - - public String getSecureAttribute(String key, String def) { - loadSecureAttributes(); - if (fSecureAttributes.containsKey(key)) { - return fSecureAttributes.get(key); - } - return def; - } - - public Map getSecureAttributes() { - loadSecureAttributes(); - return fSecureAttributes; - } - - void setSecureAttributes(Map secureAttributes) { - fSecureAttributes.clear(); - fSecureAttributes.putAll(secureAttributes); - fSecureAttributesLoaded = true; - } - - private ISecurePreferences getSecurePreferences() { - ISecurePreferences secRoot = SecurePreferencesFactory.getDefault(); - ISecurePreferences secConnections = secRoot.node(CONNECTIONS_KEY); - return secConnections.node(fName); - } - - private void load() { - IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); - Preferences connections = root.node(CONNECTIONS_KEY); - Preferences nodes = connections.node(fName); - try { - loadAttributes(nodes); - } catch (BackingStoreException e) { - Activator.log(e.getMessage()); - } - fSecureAttributesLoaded = false; - } - - private void loadAttributes(Preferences node) throws BackingStoreException { - fAttributes.clear(); - for (String key : node.keys()) { - fAttributes.put(key, node.get(key, null)); - } - } - - private void loadSecureAttributes() { - if (fSecureAttributesLoaded) { - return; - } - - ISecurePreferences secNode = getSecurePreferences(); - try { - fSecureAttributes.clear(); - for (String key : secNode.keys()) { - fSecureAttributes.put(key, secNode.get(key, null)); - } - } catch (StorageException e) { - Activator.log(e.getMessage()); - } - fSecureAttributesLoaded = true; - } - - public void remove() { - clearPreferences(); - flushPreferences(); - } - - public void save() { - clearPreferences(); - if (fNewName != null) { - fName = fNewName; - fNewName = null; - } - savePreferences(); - flushPreferences(); - } - - private void savePreferences() { - Preferences node = getPreferences(); - synchronized (fAttributes) { - for (Entry entry : fAttributes.entrySet()) { - if (entry.getValue() != null) { - node.put(entry.getKey(), entry.getValue()); - } else { - node.remove(entry.getKey()); - } - } - } - if (fSecureAttributesLoaded) { - try { - ISecurePreferences secNode = getSecurePreferences(); - synchronized (fSecureAttributes) { - for (Entry entry : fSecureAttributes.entrySet()) { - secNode.put(entry.getKey(), entry.getValue(), true); - } - } - } catch (StorageException e) { - Activator.log(e.getMessage()); - } - } - } - - public void setAttribute(String key, String value) { - fAttributes.put(key, value); - } - - public void setName(String name) { - fNewName = name; - } - - public void setSecureAttribute(String key, String value) { - loadSecureAttributes(); - fSecureAttributes.put(key, value); - } -} diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionManager.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionManager.java deleted file mode 100644 index a93f29ed79a..00000000000 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionManager.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.core; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.osgi.util.NLS; -import org.eclipse.remote.core.AbstractRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.exception.RemoteConnectionException; -import org.eclipse.remote.internal.jsch.core.messages.Messages; -import org.osgi.service.prefs.BackingStoreException; -import org.osgi.service.prefs.Preferences; - -public class JSchConnectionManager extends AbstractRemoteConnectionManager { - private Map fConnections; - - /** - * @since 4.0 - */ - public JSchConnectionManager(IRemoteServices services) { - super(services); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#getConnection(java - * .lang.String) - */ - @Override - public IRemoteConnection getConnection(String name) { - loadConnections(); - return fConnections.get(name); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#getConnection(java - * .net.URI) - */ - /** - * @since 4.0 - */ - @Override - public IRemoteConnection getConnection(URI uri) { - String connName = JSchFileSystem.getConnectionNameFor(uri); - if (connName != null) { - return getConnection(connName); - } - return null; - } - - public JSchConnection createConnection(String name) { - return new JSchConnection(name, getRemoteServices()); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#getConnections() - */ - @Override - public List getConnections() { - loadConnections(); - List conns = new ArrayList(); - conns.addAll(fConnections.values()); - return conns; - } - - private synchronized void loadConnections() { - if (fConnections == null) { - fConnections = Collections.synchronizedMap(new HashMap()); - IEclipsePreferences root = InstanceScope.INSTANCE.getNode(Activator.getUniqueIdentifier()); - Preferences connections = root.node(JSchConnectionAttributes.CONNECTIONS_KEY); - try { - for (String name : connections.childrenNames()) { - JSchConnection connection = new JSchConnection(name, getRemoteServices()); - fConnections.put(name, connection); - } - } catch (BackingStoreException e) { - Activator.log(e.getMessage()); - } - } - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#newConnection(java - * .lang.String, java.util.Map) - */ - /** - * @since 5.0 - */ - @Override - public IRemoteConnectionWorkingCopy newConnection(String name) throws RemoteConnectionException { - if (getConnection(name) != null) { - throw new RemoteConnectionException(NLS.bind(Messages.JSchConnectionManager_connection_with_name_exists, name)); - } - return createConnection(name).getWorkingCopy(); - } - - public void add(JSchConnection conn) { - if (!fConnections.containsKey(conn.getName())) { - fConnections.put(conn.getName(), conn); - } - } - - public void remove(JSchConnection conn) { - if (fConnections.containsKey(conn.getName())) { - fConnections.remove(conn.getName()); - } - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteConnectionManager#removeConnection - * (org.eclipse.remote.core.IRemoteConnection) - */ - @Override - public void removeConnection(IRemoteConnection conn) throws RemoteConnectionException { - if (!(conn instanceof JSchConnection)) { - throw new RemoteConnectionException(Messages.JSchConnectionManager_invalidConnectionType); - } - if (conn.isOpen()) { - throw new RemoteConnectionException(Messages.JSchConnectionManager_cannotRemoveOpenConnection); - } - ((JSchConnection) conn).getInfo().remove(); - fConnections.remove(conn.getName()); - } -} diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionProxyFactory.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionProxyFactory.java index dbd496cb4e1..0446d5a0d74 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionProxyFactory.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionProxyFactory.java @@ -24,9 +24,10 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteProcess; -import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.IRemoteProcessService; +import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.internal.jsch.core.messages.Messages; @@ -113,8 +114,9 @@ public class JSchConnectionProxyFactory { } } else { List cmd = new ArgumentParser(command).getTokenList(); - process = RemoteServices.getLocalServices().getConnectionManager().getConnection( - IRemoteConnectionManager.LOCAL_CONNECTION_NAME).getProcessBuilder(cmd).start(); + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); + IRemoteConnection connection = manager.getLocalConnectionType().getConnections().get(0); + process = connection.getService(IRemoteProcessService.class).getProcessBuilder(cmd).start(); } // Wait on command to produce stdout output diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionWorkingCopy.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionWorkingCopy.java deleted file mode 100644 index 1fef9769203..00000000000 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnectionWorkingCopy.java +++ /dev/null @@ -1,310 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010, 2014 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - * Markus Schorn - Bug 449306: Unnecessary access to secure storage. - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.core; - -import java.util.Collections; -import java.util.Map; - -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionChangeEvent; -import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; - -/** - * @since 5.0 - */ -public class JSchConnectionWorkingCopy extends JSchConnection implements IRemoteConnectionWorkingCopy { - private final JSchConnectionAttributes fWorkingAttributes; - private final JSchConnection fOriginal; - private boolean fIsDirty; - - public JSchConnectionWorkingCopy(JSchConnection connection) { - super(connection.getName(), connection.getRemoteServices()); - fWorkingAttributes = connection.getInfo().copy(); - fOriginal = connection; - fIsDirty = false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getAddress() - */ - @Override - public String getAddress() { - return fWorkingAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getAttributes() - */ - @Override - public Map getAttributes() { - return Collections.unmodifiableMap(fWorkingAttributes.getAttributes()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getName() - */ - @Override - public String getName() { - return fWorkingAttributes.getName(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#getOriginal() - */ - @Override - public IRemoteConnection getOriginal() { - return fOriginal; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.internal.jsch.core.JSchConnection#getPassphrase() - */ - @Override - public String getPassphrase() { - return fWorkingAttributes.getSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.internal.jsch.core.JSchConnection#getPassword() - */ - @Override - public String getPassword() { - return fWorkingAttributes.getSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getPort() - */ - @Override - public int getPort() { - return fWorkingAttributes.getInt(JSchConnectionAttributes.PORT_ATTR, DEFAULT_PORT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.internal.jsch.core.JSchConnection#getProxyCommand() - */ - @Override - public String getProxyCommand() { - return fWorkingAttributes.getAttribute(JSchConnectionAttributes.PROXYCOMMAND_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.internal.jsch.core.JSchConnection#getProxyConnectionName() - */ - @Override - public String getProxyConnectionName() { - return fWorkingAttributes.getAttribute(JSchConnectionAttributes.PROXYCONNECTION_ATTR, EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.internal.jsch.core.JSchConnection#getTimeout() - */ - @Override - public int getTimeout() { - return fWorkingAttributes.getInt(JSchConnectionAttributes.TIMEOUT_ATTR, DEFAULT_TIMEOUT); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getUsername() - */ - @Override - public String getUsername() { - return fWorkingAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, JSchConnection.EMPTY_STRING); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() - */ - @Override - public IRemoteConnectionWorkingCopy getWorkingCopy() { - return this; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#isDirty() - */ - @Override - public boolean isDirty() { - return fIsDirty; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.internal.jsch.core.JSchConnection#isPasswordAuth() - */ - @Override - public boolean isPasswordAuth() { - return fWorkingAttributes.getBoolean(JSchConnectionAttributes.IS_PASSWORD_ATTR, DEFAULT_IS_PASSWORD); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#save() - */ - @Override - public IRemoteConnection save() { - JSchConnectionAttributes info = fOriginal.getInfo(); - info.getAttributes().clear(); - info.getAttributes().putAll(fWorkingAttributes.getAttributes()); - info.setSecureAttributes(fWorkingAttributes.getSecureAttributes()); - if (!getName().equals(info.getName())) { - info.setName(getName()); - getManager().remove(fOriginal); - fOriginal.fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_RENAMED); - } - info.save(); - getManager().add(fOriginal); - fIsDirty = false; - return fOriginal; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAddress(java.lang.String) - */ - @Override - public void setAddress(String address) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.ADDRESS_ATTR, address); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAttribute(java.lang.String, java.lang.String) - */ - @Override - public void setAttribute(String key, String value) { - fIsDirty = true; - fWorkingAttributes.setAttribute(key, value); - } - - public void setIsPasswordAuth(boolean flag) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.IS_PASSWORD_ATTR, Boolean.toString(flag)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String) - */ - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String) - */ - @Override - public void setName(String name) { - fIsDirty = true; - fWorkingAttributes.setName(name); - } - - public void setPassphrase(String passphrase) { - fIsDirty = true; - fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, passphrase); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPassword(java.lang.String) - */ - @Override - public void setPassword(String password) { - fIsDirty = true; - fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, password); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPort(int) - */ - @Override - public void setPort(int port) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.PORT_ATTR, Integer.toString(port)); - } - - /** - * Sets the proxy command. Set to empty string for no command - * - * @param proxyCommand - * proxy command - */ - public void setProxyCommand(String proxyCommand) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.PROXYCOMMAND_ATTR, proxyCommand); - } - - /** - * Sets the proxy connection name. Set to empty string for no proxy connection - * - * @param proxyCommand - * proxy connection name - */ - public void setProxyConnectionName(String proxyConnectionName) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.PROXYCONNECTION_ATTR, proxyConnectionName); - } - - public void setTimeout(int timeout) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.TIMEOUT_ATTR, Integer.toString(timeout)); - } - - public void setUseLoginShell(boolean flag) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.USE_LOGIN_SHELL_ATTR, Boolean.toString(flag)); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setUsername(java.lang.String) - */ - @Override - public void setUsername(String userName) { - fIsDirty = true; - fWorkingAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, userName); - } -} diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchFileManager.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchFileManager.java index fb4ea90eee2..565eb480dab 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchFileManager.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchFileManager.java @@ -15,62 +15,64 @@ import java.net.URI; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.remote.core.IRemoteFileManager; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteFileService; +import org.eclipse.remote.core.IRemoteProcessService; +import org.eclipse.remote.core.IRemoteConnection.Service; -public class JSchFileManager implements IRemoteFileManager { - private final JSchConnection fConnection; +public class JSchFileManager implements IRemoteFileService { - public JSchFileManager(JSchConnection connection) { + private final IRemoteConnection fConnection; + + public JSchFileManager(IRemoteConnection connection) { fConnection = connection; } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteFileManager#getDirectorySeparator() - */ - /** - * @since 4.0 - */ + public static class Factory implements IRemoteFileService.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnection remoteConnection, Class service) { + if (IRemoteFileService.class.equals(service)) { + return (T) new JSchFileManager(remoteConnection); + } + return null; + } + } + + @Override + public IRemoteConnection getRemoteConnection() { + return fConnection; + } + @Override public String getDirectorySeparator() { return "/"; //$NON-NLS-1$ } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteFileManager#getResource(java.lang. - * String) - */ @Override public IFileStore getResource(String pathStr) { IPath path = new Path(pathStr); if (!path.isAbsolute()) { - path = new Path(fConnection.getWorkingDirectory()).append(path); + path = new Path(getBaseDirectory()).append(path); } return JschFileStore.getInstance(JSchFileSystem.getURIFor(fConnection.getName(), path.toString())); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteFileManager#toPath(java.net.URI) - */ + @Override + public String getBaseDirectory() { + return fConnection.getService(IRemoteProcessService.class).getWorkingDirectory(); + } + + @Override + public void setBaseDirectory(String path) { + fConnection.getService(IRemoteProcessService.class).setWorkingDirectory(path); + } + @Override public String toPath(URI uri) { return uri.getPath(); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteFileManager#toURI(org.eclipse.core - * .runtime.IPath) - */ @Override public URI toURI(IPath path) { try { @@ -80,14 +82,9 @@ public class JSchFileManager implements IRemoteFileManager { } } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteFileManager#toURI(java.lang.String) - */ @Override public URI toURI(String path) { return toURI(new Path(path)); } + } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java index 7b6bc9fea6f..5793bd8c301 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchProcessBuilder.java @@ -24,7 +24,7 @@ import java.util.Set; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.remote.core.AbstractRemoteProcessBuilder; -import org.eclipse.remote.core.IRemoteFileManager; +import org.eclipse.remote.core.IRemoteFileService; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.internal.core.RemoteDebugOptions; @@ -34,15 +34,13 @@ import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSchException; public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { + private final JSchConnection fConnection; private final Map fRemoteEnv = new HashMap(); private final Set charSet = new HashSet(); private Map fNewRemoteEnv = null; - /** - * @since 4.0 - */ public JSchProcessBuilder(JSchConnection connection, List command) { super(command); fConnection = connection; @@ -58,34 +56,21 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { } } - /** - * @since 4.0 - */ public JSchProcessBuilder(JSchConnection connection, String... command) { this(connection, Arrays.asList(command)); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.AbstractRemoteProcessBuilder#directory() - */ @Override public IFileStore directory() { IFileStore dir = super.directory(); - IRemoteFileManager fileMgr = fConnection.getFileManager(); - if (dir == null && fileMgr != null) { - dir = fileMgr.getResource(fConnection.getWorkingDirectory()); + IRemoteFileService fileService = fConnection.getRemoteConnection().getService(IRemoteFileService.class); + if (dir == null && fileService != null) { + dir = fileService.getResource(fConnection.getWorkingDirectory()); directory(dir); } return dir; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.AbstractRemoteProcessBuilder#environment() - */ @Override public Map environment() { if (fNewRemoteEnv == null) { @@ -95,21 +80,11 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { return fNewRemoteEnv; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.AbstractRemoteProcessBuilder#getSupportedFlags () - */ @Override public int getSupportedFlags() { return ALLOCATE_PTY | FORWARD_X11; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteProcessBuilder#start(int) - */ @Override public IRemoteProcess start(int flags) throws IOException { if (!fConnection.isOpen()) { @@ -234,4 +209,5 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder { inputString = newString.toString(); return inputString; } + } \ No newline at end of file diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServices.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServices.java deleted file mode 100644 index 6117a9ed902..00000000000 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServices.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.core; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.remote.core.AbstractRemoteServices; -import org.eclipse.remote.core.IRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteServicesDescriptor; - -public class JSchServices extends AbstractRemoteServices { - public static final String JSCH_ID = "org.eclipse.remote.JSch"; //$NON-NLS-1$ - - private final JSchConnectionManager connMgr = new JSchConnectionManager(this); - - public JSchServices(IRemoteServicesDescriptor descriptor) { - super(descriptor); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.core.IRemoteServicesDescriptor#getConnectionManager - * () - */ - public IRemoteConnectionManager getConnectionManager() { - return connMgr; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#initialize(org.eclipse.core.runtime.IProgressMonitor) - */ - public boolean initialize(IProgressMonitor monitor) { - return true; - } - - public int getCapabilities() { - return CAPABILITY_ADD_CONNECTIONS | CAPABILITY_EDIT_CONNECTIONS | CAPABILITY_REMOVE_CONNECTIONS - | CAPABILITY_SUPPORTS_TCP_PORT_FORWARDING | CAPABILITY_SUPPORTS_X11_FORWARDING; - } -} diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServicesFactory.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServicesFactory.java deleted file mode 100644 index 52320843b0d..00000000000 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchServicesFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.core; - -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.IRemoteServicesDescriptor; -import org.eclipse.remote.core.IRemoteServicesFactory; - -public class JSchServicesFactory implements IRemoteServicesFactory { - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServicesFactory#getServices(org.eclipse.remote.core.IRemoteServicesDescriptor) - */ - public IRemoteServices getServices(IRemoteServicesDescriptor descriptor) { - return new JSchServices(descriptor); - } -} diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java index d7b6f4e248f..1082c4d75bc 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JschFileStore.java @@ -30,9 +30,8 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.osgi.util.NLS; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.internal.jsch.core.commands.ChildInfosCommand; import org.eclipse.remote.internal.jsch.core.commands.DeleteCommand; @@ -73,24 +72,27 @@ public class JschFileStore extends FileStore { } private JSchConnection checkConnection(IProgressMonitor monitor) throws RemoteConnectionException { - IRemoteServices services = RemoteServices.getRemoteServices(fURI); - assert (services instanceof JSchServices); - if (services == null) { + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); + IRemoteConnectionType connectionType = manager.getConnectionType(fURI); + if (connectionType == null) { throw new RemoteConnectionException(NLS.bind(Messages.JschFileStore_No_remote_services_found_for_URI, fURI)); } - IRemoteConnectionManager manager = services.getConnectionManager(); - assert (manager != null); - IRemoteConnection connection = manager.getConnection(fURI); - if (connection == null || !(connection instanceof JSchConnection)) { - throw new RemoteConnectionException(NLS.bind(Messages.JschFileStore_Invalid_connection_for_URI, fURI)); - } - if (!connection.isOpen()) { - connection.open(monitor); - if (!connection.isOpen()) { - throw new RemoteConnectionException(Messages.JschFileStore_Connection_is_not_open); + + try { + IRemoteConnection connection = connectionType.getConnection(fURI); + if (connection == null) { + throw new RemoteConnectionException(NLS.bind(Messages.JschFileStore_Invalid_connection_for_URI, fURI)); } + if (!connection.isOpen()) { + connection.open(monitor); + if (!connection.isOpen()) { + throw new RemoteConnectionException(Messages.JschFileStore_Connection_is_not_open); + } + } + return connection.getService(JSchConnection.class); + } catch (CoreException e) { + throw new RemoteConnectionException(e); } - return (JSchConnection) connection; } /* diff --git a/bundles/org.eclipse.remote.jsch.ui/plugin.xml b/bundles/org.eclipse.remote.jsch.ui/plugin.xml index f84b7e90cb5..d25045b6819 100644 --- a/bundles/org.eclipse.remote.jsch.ui/plugin.xml +++ b/bundles/org.eclipse.remote.jsch.ui/plugin.xml @@ -1,14 +1,6 @@ - - - - + + + + + + diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/Activator.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/Activator.java index be51be3f318..080fe5c6e4f 100644 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/Activator.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/Activator.java @@ -78,6 +78,18 @@ public class Activator extends Plugin { public Activator() { } + /** + * Return the OSGi service with the given service interface. + * + * @param service service interface + * @return the specified service or null if it's not registered + */ + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + public IJSchService getService() { return fJSchService; } diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchFileSystemContributor.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchFileSystemContributor.java index 85d5d25260d..667f02475ac 100644 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchFileSystemContributor.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchFileSystemContributor.java @@ -27,14 +27,12 @@ import java.net.URI; import java.net.URISyntaxException; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.jsch.core.JSchConnection; import org.eclipse.remote.internal.jsch.core.JSchFileSystem; -import org.eclipse.remote.internal.jsch.core.JSchServices; import org.eclipse.remote.internal.jsch.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIFileManager; -import org.eclipse.remote.ui.IRemoteUIServices; -import org.eclipse.remote.ui.RemoteUIServices; +import org.eclipse.remote.ui.IRemoteUIFileService; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.ide.fileSystem.FileSystemContributor; @@ -48,9 +46,9 @@ public class JSchFileSystemContributor extends FileSystemContributor { */ @Override public URI browseFileSystem(String initialPath, Shell shell) { - IRemoteServices services = RemoteServices.getRemoteServices(JSchServices.JSCH_ID); - IRemoteUIServices uiServices = RemoteUIServices.getRemoteUIServices(services); - IRemoteUIFileManager uiFileMgr = uiServices.getUIFileManager(); + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); + IRemoteConnectionType connectionType = manager.getConnectionType(JSchConnection.JSCH_ID); + IRemoteUIFileService uiFileMgr = connectionType.getService(IRemoteUIFileService.class); uiFileMgr.showConnections(true); String path = uiFileMgr.browseDirectory(shell, Messages.JSchFileSystemContributor_0, initialPath, 0); if (path != null) { diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIConnectionManager.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIConnectionService.java similarity index 75% rename from bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIConnectionManager.java rename to bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIConnectionService.java index 9c108403141..f0e6bfd1064 100644 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIConnectionManager.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIConnectionService.java @@ -20,30 +20,43 @@ import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteServices; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionType.Service; import org.eclipse.remote.core.exception.RemoteConnectionException; -import org.eclipse.remote.internal.jsch.core.JSchConnectionManager; import org.eclipse.remote.internal.jsch.ui.messages.Messages; import org.eclipse.remote.internal.jsch.ui.wizards.JSchConnectionWizard; import org.eclipse.remote.ui.AbstractRemoteUIConnectionManager; +import org.eclipse.remote.ui.IRemoteUIConnectionService; import org.eclipse.remote.ui.IRemoteUIConnectionWizard; import org.eclipse.swt.widgets.Shell; -public class JSchUIConnectionManager extends AbstractRemoteUIConnectionManager { - private final JSchConnectionManager fConnMgr; +public class JSchUIConnectionService extends AbstractRemoteUIConnectionManager { - public JSchUIConnectionManager(IRemoteServices services) { - fConnMgr = (JSchConnectionManager) services.getConnectionManager(); + private final IRemoteConnectionType fConnectionType; + + public JSchUIConnectionService(IRemoteConnectionType connectionType) { + fConnectionType = connectionType; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIConnectionManager#getConnectionWizard(org.eclipse.swt.widgets.Shell) - */ + public static class Factory implements IRemoteConnectionType.Service.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnectionType connectionType, Class service) { + if (IRemoteUIConnectionService.class.equals(service)) { + return (T) new JSchUIConnectionService(connectionType); + } + return null; + } + } + + @Override + public IRemoteConnectionType getConnectionType() { + return fConnectionType; + } + @Override public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) { - return new JSchConnectionWizard(shell, fConnMgr); + return new JSchConnectionWizard(shell, fConnectionType); } @Override diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIFileManager.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIFileService.java similarity index 82% rename from bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIFileManager.java rename to bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIFileService.java index 96557a0449a..200c0de397f 100644 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIFileManager.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIFileService.java @@ -16,15 +16,38 @@ import java.util.List; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.jface.window.Window; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.ui.IRemoteUIFileManager; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionType.Service; +import org.eclipse.remote.ui.IRemoteUIFileService; import org.eclipse.remote.ui.dialogs.RemoteResourceBrowser; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; -public class JSchUIFileManager implements IRemoteUIFileManager { +public class JSchUIFileService implements IRemoteUIFileService { + private final IRemoteConnectionType connectionType; private IRemoteConnection connection = null; private boolean showConnections = false; + public JSchUIFileService(IRemoteConnectionType connectionType) { + this.connectionType = connectionType; + } + + public static class Factory implements IRemoteConnectionType.Service.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnectionType connectionType, Class service) { + if (IRemoteUIFileService.class.equals(service)) { + return (T) new JSchUIFileService(connectionType); + } + return null; + } + } + + @Override + public IRemoteConnectionType getConnectionType() { + return connectionType; + } + /* * (non-Javadoc) * diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServices.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServices.java deleted file mode 100644 index 4da5846584d..00000000000 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServices.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.ui; - -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; -import org.eclipse.remote.ui.IRemoteUIFileManager; -import org.eclipse.remote.ui.IRemoteUIServices; - -public class JSchUIServices implements IRemoteUIServices { - private static JSchUIServices fInstance = null; - - /** - * Get shared instance of this class - * - * @return instance - */ - public static JSchUIServices getInstance(IRemoteServices services) { - if (fInstance == null) { - fInstance = new JSchUIServices(services); - } - return fInstance; - } - - private final IRemoteServices fServices; - - public JSchUIServices(IRemoteServices services) { - fServices = services; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getId() - */ - @Override - public String getId() { - return fServices.getId(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getName() - */ - @Override - public String getName() { - return fServices.getName(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIConnectionManager() - */ - @Override - public IRemoteUIConnectionManager getUIConnectionManager() { - return new JSchUIConnectionManager(fServices); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesDescriptor#getUIFileManager() - */ - @Override - public IRemoteUIFileManager getUIFileManager() { - return new JSchUIFileManager(); - } -} diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServicesFactory.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServicesFactory.java deleted file mode 100644 index bacc32f74d5..00000000000 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUIServicesFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.jsch.ui; - -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.ui.IRemoteUIServices; -import org.eclipse.remote.ui.IRemoteUIServicesFactory; - -public class JSchUIServicesFactory implements IRemoteUIServicesFactory { - /* - * (non-Javadoc) - * - * @see org.eclipse.ptp.remote.ui.IRemoteUIServicesFactory#getServices(org.eclipse.ptp.remote.core.IRemoteServices) - */ - public IRemoteUIServices getServices(IRemoteServices services) { - return JSchUIServices.getInstance(services); - } -} diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUserAuthenticator.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUserAuthenticator.java index 7f14b5c6384..646fa3a303d 100644 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUserAuthenticator.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/JSchUserAuthenticator.java @@ -16,24 +16,35 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jsch.ui.UserInfoPrompter; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IUserAuthenticator; +import org.eclipse.remote.core.IUserAuthenticatorService; +import org.eclipse.remote.internal.jsch.core.JSchConnection; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; -public class JSchUserAuthenticator implements IUserAuthenticator { +public class JSchUserAuthenticator implements IUserAuthenticatorService { + + private final IRemoteConnection remoteConnection; private UserInfoPrompter prompter; public JSchUserAuthenticator(IRemoteConnection conn) { + this.remoteConnection = conn; try { - prompter = new UserInfoPrompter(new JSch().getSession(conn.getUsername(), conn.getAddress())); + String username = conn.getAttribute(JSchConnection.USERNAME_ATTR); + String address = conn.getAttribute(JSchConnection.ADDRESS_ATTR); + prompter = new UserInfoPrompter(new JSch().getSession(username, address)); } catch (JSchException e) { // Not allowed } } + @Override + public IRemoteConnection getRemoteConnection() { + return remoteConnection; + } + @Override public PasswordAuthentication prompt(String username, String message) { if (prompter.promptPassword(message)) { diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionPage.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionPage.java index 6cef7805c48..89ff0e951e8 100755 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionPage.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionPage.java @@ -15,16 +15,16 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; -import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.internal.jsch.core.Activator; import org.eclipse.remote.internal.jsch.core.JSchConnection; -import org.eclipse.remote.internal.jsch.core.JSchConnectionAttributes; -import org.eclipse.remote.internal.jsch.core.JSchConnectionWorkingCopy; import org.eclipse.remote.internal.jsch.ui.messages.Messages; import org.eclipse.remote.ui.widgets.RemoteConnectionWidget; import org.eclipse.swt.SWT; @@ -51,6 +51,7 @@ import org.eclipse.ui.forms.events.IExpansionListener; import org.eclipse.ui.forms.widgets.ExpandableComposite; public class JSchConnectionPage extends WizardPage { + private class DataModifyListener implements ModifyListener { @Override public synchronized void modifyText(ModifyEvent e) { @@ -72,18 +73,18 @@ public class JSchConnectionPage extends WizardPage { private String fInitialName = "Remote Host"; //$NON-NLS-1$ private Set fInvalidConnectionNames; private final Map fInitialAttributes = new HashMap(); - private JSchConnectionWorkingCopy fConnection; + private IRemoteConnectionWorkingCopy fConnection; - private final IRemoteConnectionManager fConnectionManager; + private final IRemoteConnectionType fConnectionType; private final DataModifyListener fDataModifyListener = new DataModifyListener(); private RemoteConnectionWidget fProxyConnectionWidget; private Text fProxyCommandText; private static final String PREFS_PAGE_ID_NET_PROXY = "org.eclipse.ui.net.NetPreferences"; //$NON-NLS-1$ - public JSchConnectionPage(IRemoteConnectionManager connMgr) { + public JSchConnectionPage(IRemoteConnectionType connectionType) { super(Messages.JSchNewConnectionPage_New_Connection); - fConnectionManager = connMgr; + fConnectionType = connectionType; setPageComplete(false); } @@ -258,7 +259,12 @@ public class JSchConnectionPage extends WizardPage { createAuthControls(authGroup); createAdvancedControls(authGroup); - loadValues(); + try { + loadValues(); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + /* * Register listeners after loading values so we don't trigger listeners */ @@ -312,7 +318,7 @@ public class JSchConnectionPage extends WizardPage { link.setText(Messages.JSchConnectionPage_Help); } - public JSchConnectionWorkingCopy getConnection() { + public IRemoteConnectionWorkingCopy getConnection() { return fConnection; } @@ -326,67 +332,69 @@ public class JSchConnectionPage extends WizardPage { private boolean isInvalidName(String name) { if (fConnection == null) { if (fInvalidConnectionNames == null) { - return fConnectionManager.getConnection(name) != null; + return fConnectionType.getConnection(name) != null; } return fInvalidConnectionNames.contains(name); } return false; } - private void loadValues() { + private void loadValues() throws CoreException { + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); if (fConnection != null) { fConnectionName.setText(fConnection.getName()); - fHostText.setText(fConnection.getAddress()); - fUserText.setText(fConnection.getUsername()); - fPortText.setText(Integer.toString(fConnection.getPort())); - fTimeoutText.setText(Integer.toString(fConnection.getTimeout())); - boolean isPwd = fConnection.isPasswordAuth(); + fHostText.setText(fConnection.getAttribute(JSchConnection.ADDRESS_ATTR)); + fUserText.setText(fConnection.getAttribute(JSchConnection.USERNAME_ATTR)); + fPortText.setText(fConnection.getAttribute(JSchConnection.PORT_ATTR)); + fTimeoutText.setText(fConnection.getAttribute(JSchConnection.TIMEOUT_ATTR)); + String isPwdStr = fConnection.getAttribute(JSchConnection.IS_PASSWORD_ATTR); + boolean isPwd = isPwdStr != null && Boolean.parseBoolean(isPwdStr); fPasswordButton.setSelection(isPwd); fPublicKeyButton.setSelection(!isPwd); if (isPwd) { - fPasswordText.setText(fConnection.getPassword()); + fPasswordText.setText(fConnection.getSecureAttribute(JSchConnection.PASSWORD_ATTR)); } else { - fPassphraseText.setText(fConnection.getPassphrase()); + fPassphraseText.setText(fConnection.getSecureAttribute(JSchConnection.PASSPHRASE_ATTR)); } - fProxyCommandText.setText(fConnection.getProxyCommand()); - IRemoteConnection proxyConn = fConnection.getProxyConnection(); + fProxyCommandText.setText(fConnection.getAttribute(JSchConnection.PROXYCOMMAND_ATTR)); + JSchConnection proxyConn = fConnection.getService(JSchConnection.class).getProxyConnection(); if (proxyConn == null) { - proxyConn = RemoteServices.getLocalServices().getConnectionManager() - .getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME); + // Use local connection + fProxyConnectionWidget.setConnection(manager.getLocalConnectionType().getConnections().get(0)); + } else { + fProxyConnectionWidget.setConnection(proxyConn.getRemoteConnection()); } - fProxyConnectionWidget.setConnection(proxyConn); } else { fConnectionName.setText(fInitialName); - String host = fInitialAttributes.get(JSchConnectionAttributes.ADDRESS_ATTR); + String host = fInitialAttributes.get(JSchConnection.ADDRESS_ATTR); if (host != null) { fHostText.setText(host); } - String username = fInitialAttributes.get(JSchConnectionAttributes.USERNAME_ATTR); + String username = fInitialAttributes.get(JSchConnection.USERNAME_ATTR); if (username != null) { fUserText.setText(username); } - String port = fInitialAttributes.get(JSchConnectionAttributes.PORT_ATTR); + String port = fInitialAttributes.get(JSchConnection.PORT_ATTR); if (port != null) { fPortText.setText(port); } - String timeout = fInitialAttributes.get(JSchConnectionAttributes.TIMEOUT_ATTR); + String timeout = fInitialAttributes.get(JSchConnection.TIMEOUT_ATTR); if (timeout != null) { fTimeoutText.setText(timeout); } - String isPwd = fInitialAttributes.get(JSchConnectionAttributes.IS_PASSWORD_ATTR); + String isPwd = fInitialAttributes.get(JSchConnection.IS_PASSWORD_ATTR); if (isPwd != null) { fPasswordButton.setSelection(Boolean.parseBoolean(isPwd)); } - String password = fInitialAttributes.get(JSchConnectionAttributes.PASSWORD_ATTR); + String password = fInitialAttributes.get(JSchConnection.PASSWORD_ATTR); if (password != null) { fPasswordText.setText(password); } - String passphrase = fInitialAttributes.get(JSchConnectionAttributes.PASSPHRASE_ATTR); + String passphrase = fInitialAttributes.get(JSchConnection.PASSPHRASE_ATTR); if (passphrase != null) { fPassphraseText.setText(passphrase); } - fProxyConnectionWidget.setConnection(RemoteServices.getLocalServices().getConnectionManager() - .getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME)); + fProxyConnectionWidget.setConnection(manager.getLocalConnectionType().getConnections().get(0)); } } @@ -409,14 +417,14 @@ public class JSchConnectionPage extends WizardPage { } public void setAddress(String address) { - fInitialAttributes.put(JSchConnectionAttributes.ADDRESS_ATTR, address); + fInitialAttributes.put(JSchConnection.ADDRESS_ATTR, address); } public void setAttributes(Map attributes) { fInitialAttributes.putAll(attributes); } - public void setConnection(JSchConnectionWorkingCopy connection) { + public void setConnection(IRemoteConnectionWorkingCopy connection) { fConnection = connection; } @@ -437,7 +445,7 @@ public class JSchConnectionPage extends WizardPage { } public void setPort(int port) { - fInitialAttributes.put(JSchConnectionAttributes.PORT_ATTR, Integer.toString(port)); + fInitialAttributes.put(JSchConnection.PORT_ATTR, Integer.toString(port)); } private void setTextFieldWidthInChars(Text text, int chars) { @@ -453,56 +461,34 @@ public class JSchConnectionPage extends WizardPage { } public void setUsername(String username) { - fInitialAttributes.put(JSchConnectionAttributes.USERNAME_ATTR, username); + fInitialAttributes.put(JSchConnection.USERNAME_ATTR, username); } private void storeValues() { if (fConnection == null) { try { - JSchConnection conn = (JSchConnection) fConnectionManager.newConnection(fConnectionName.getText().trim()); - fConnection = (JSchConnectionWorkingCopy) conn.getWorkingCopy(); + fConnection = fConnectionType.newConnection(fConnectionName.getText().trim()); } catch (RemoteConnectionException e) { Activator.log(e); } } if (fConnection != null) { - if (!fConnection.getName().equals(fConnectionName.getText().trim())) { - fConnection.setName(fConnectionName.getText().trim()); - } - if (!fConnection.getAddress().equals(fHostText.getText().trim())) { - fConnection.setAddress(fHostText.getText().trim()); - } - if (!fConnection.getUsername().equals(fUserText.getText().trim())) { - fConnection.setUsername(fUserText.getText().trim()); - } - if (!fConnection.getPassword().equals(fPasswordText.getText().trim())) { - fConnection.setPassword(fPasswordText.getText().trim()); - } - if (!fConnection.getPassphrase().equals(fPassphraseText.getText().trim())) { - fConnection.setPassphrase(fPassphraseText.getText().trim()); - } - if (fConnection.isPasswordAuth() != fPasswordButton.getSelection()) { - fConnection.setIsPasswordAuth(fPasswordButton.getSelection()); - } - int timeout = Integer.parseInt(fTimeoutText.getText().trim()); - if (fConnection.getTimeout() != timeout) { - fConnection.setTimeout(timeout); - } - int port = Integer.parseInt(fPortText.getText().trim()); - if (fConnection.getPort() != port) { - fConnection.setPort(port); - } - if (!fConnection.getProxyCommand().equals(fProxyCommandText.getText().trim())) { - fConnection.setProxyCommand(fProxyCommandText.getText().trim()); - } + fConnection.setName(fConnectionName.getText().trim()); + fConnection.setAttribute(JSchConnection.ADDRESS_ATTR, fHostText.getText().trim()); + fConnection.setAttribute(JSchConnection.USERNAME_ATTR, fUserText.getText().trim()); + fConnection.setSecureAttribute(JSchConnection.PASSWORD_ATTR, fPasswordText.getText().trim()); + fConnection.setSecureAttribute(JSchConnection.PASSPHRASE_ATTR, fPassphraseText.getText().trim()); + fConnection.setAttribute(JSchConnection.IS_PASSWORD_ATTR, Boolean.toString(fPasswordButton.getSelection())); + fConnection.setAttribute(JSchConnection.TIMEOUT_ATTR, fTimeoutText.getText().trim()); + fConnection.setAttribute(JSchConnection.PORT_ATTR, fPortText.getText().trim()); + fConnection.setAttribute(JSchConnection.PROXYCOMMAND_ATTR, fProxyCommandText.getText().trim()); IRemoteConnection proxyConnection = fProxyConnectionWidget.getConnection(); + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); String proxyConnectionName = ""; //$NON-NLS-1$ - if (proxyConnection != null && proxyConnection.getRemoteServices() != RemoteServices.getLocalServices()) { + if (proxyConnection != null && proxyConnection.getConnectionType() != manager.getLocalConnectionType()) { proxyConnectionName = proxyConnection.getName(); } - if (!fConnection.getProxyConnectionName().equals(proxyConnectionName)) { - fConnection.setProxyConnectionName(proxyConnectionName); - } + fConnection.setAttribute(JSchConnection.PROXYCONNECTION_ATTR, proxyConnectionName); } } diff --git a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionWizard.java b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionWizard.java index b768e9213dc..3383f1e4440 100755 --- a/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionWizard.java +++ b/bundles/org.eclipse.remote.jsch.ui/src/org/eclipse/remote/internal/jsch/ui/wizards/JSchConnectionWizard.java @@ -15,37 +15,27 @@ import java.util.Set; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.internal.jsch.core.JSchConnectionWorkingCopy; import org.eclipse.remote.ui.IRemoteUIConnectionWizard; import org.eclipse.swt.widgets.Shell; public class JSchConnectionWizard extends Wizard implements IRemoteUIConnectionWizard { + private final Shell fShell; private final JSchConnectionPage fPage; - public JSchConnectionWizard(Shell shell, IRemoteConnectionManager connMgr) { + public JSchConnectionWizard(Shell shell, IRemoteConnectionType connectionType) { fShell = shell; - fPage = new JSchConnectionPage(connMgr); + fPage = new JSchConnectionPage(connectionType); } - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.wizard.Wizard#addPages() - */ @Override public void addPages() { super.addPages(); addPage(fPage); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIConnectionWizard#getWorkingCopy() - */ public IRemoteConnectionWorkingCopy open() { WizardDialog dialog = new WizardDialog(fShell, this); dialog.setBlockOnOpen(true); @@ -55,50 +45,31 @@ public class JSchConnectionWizard extends Wizard implements IRemoteUIConnectionW return null; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.wizard.Wizard#performCancel() - */ + @Override + public IRemoteConnectionWorkingCopy getConnection() { + return fPage.getConnection(); + } + @Override public boolean performCancel() { return true; } - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.wizard.Wizard#performFinish() - */ @Override public boolean performFinish() { return true; } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIConnectionWizard#setConnection(org.eclipse.remote.core.IRemoteConnectionWorkingCopy) - */ public void setConnection(IRemoteConnectionWorkingCopy connection) { - fPage.setConnection((JSchConnectionWorkingCopy) connection); + fPage.setConnection(connection); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIConnectionWizard#setConnectionName(java.lang.String) - */ public void setConnectionName(String name) { fPage.setConnectionName(name); } - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIConnectionWizard#setInvalidConnectionNames(java.util.Set) - */ public void setInvalidConnectionNames(Set names) { fPage.setInvalidConnectionNames(names); } + } diff --git a/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF index 5515186f105..21a994d8c0a 100644 --- a/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.remote.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.remote.ui;singleton:=true -Bundle-Version: 1.1.0.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.remote.internal.ui.RemoteUIPlugin Bundle-Vendor: %pluginProvider Require-Bundle: org.eclipse.ui, @@ -12,7 +12,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.remote.core, org.eclipse.core.filesystem, org.eclipse.core.resources, - org.eclipse.ui.trace + org.eclipse.ui.trace, + org.eclipse.ui.navigator, + org.eclipse.core.expressions Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.remote.internal.ui;x-internal:=true, diff --git a/bundles/org.eclipse.remote.ui/icons/new_wiz.gif b/bundles/org.eclipse.remote.ui/icons/new_wiz.gif new file mode 100644 index 0000000000000000000000000000000000000000..7aea894d0b603a02aed2a7f706bcb3170988774d GIT binary patch literal 612 zcmZ{h>q}E%9Dt8G)5LOgQI2^@7e=H}5t7*jq~=si${U5|rU_+M-j`oOU#sb&i!)6! zQj1L2<%^C`(3Frs!zQH!M$LxHZR)0;HP3s_`~J#5py%WBe0&lT<%eQbQbx*H7)D;+ zC9mj8tL`~bsh6u?DXLzlp`Oc4!$r+QwcX=`U*-e?sC#^9(mL|ZR{74{H@%DrT- zV)#}6;rDanLRp{LGx3fOqC^RS3vNq|)X-(A$o!#sus3{C+!5o{Rj7~JHa zq?m$3AWMR=N;c$n#X>#8pgrH*sO=7AfY*vOt}fICx=Rq;>*}tJq5D zJOzs&S}52kF^hQm&roD!pv_wX{I_nC2C7b_o=HnlsqcF+ z>%ILpZc-}G=AK7a*@3|wd!lmkaw^a@Hhgq+cl5#IStlz|F}po7cvo=5fta}bq!M(A z4UvV+$@aw_y%1lD%Gl7ITxjV2!wCgP%26SkA9VL}>?w1J7eN*3kUXk(DEU6m(EdKjHN)jkv7c;{Jb4a3C!1>qfFng9R* literal 0 HcmV?d00001 diff --git a/bundles/org.eclipse.remote.ui/plugin.properties b/bundles/org.eclipse.remote.ui/plugin.properties index 4a15de900f4..06336c3c29e 100644 --- a/bundles/org.eclipse.remote.ui/plugin.properties +++ b/bundles/org.eclipse.remote.ui/plugin.properties @@ -10,4 +10,11 @@ pluginName=Remote Services UI pluginProvider=Eclipse PTP RemoteDevPrefPage.name=Remote Development -ConnectionsPreferencePage.name=Remote Connections \ No newline at end of file +ConnectionsPreferencePage.name=Remote Connections +ConnectionsViewCategory.name=Connections +ConnectionsView.name=Connections +ConnectionsContent.name=Connections +NewConnectionCommand.name=New Connection +DeleteConnectionCommand.name=Delete Connection +OpenTerminalCommand.name=Open Terminal +ConnectionProperties.name=Connection diff --git a/bundles/org.eclipse.remote.ui/plugin.xml b/bundles/org.eclipse.remote.ui/plugin.xml index 4d605d28529..b1de474ad95 100644 --- a/bundles/org.eclipse.remote.ui/plugin.xml +++ b/bundles/org.eclipse.remote.ui/plugin.xml @@ -1,15 +1,6 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + name diff --git a/bundles/org.eclipse.remote.ui/pom.xml b/bundles/org.eclipse.remote.ui/pom.xml index 57570bbb584..851df2fb7b1 100644 --- a/bundles/org.eclipse.remote.ui/pom.xml +++ b/bundles/org.eclipse.remote.ui/pom.xml @@ -11,6 +11,6 @@ org.eclipse.remote.ui - 1.1.0-SNAPSHOT + 2.0.0-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.remote.ui/schema/remoteUIServices.exsd b/bundles/org.eclipse.remote.ui/schema/remoteUIServices.exsd deleted file mode 100644 index 06b64bf6b46..00000000000 --- a/bundles/org.eclipse.remote.ui/schema/remoteUIServices.exsd +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - [Enter description of this extension point.] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [Enter the first release in which this extension point appears.] - - - - - - - - - [Enter extension point usage example here.] - - - - - - - - - [Enter API information here.] - - - - - - - - - [Enter information about supplied implementation of this extension point.] - - - - - diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/Messages.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/Messages.java new file mode 100644 index 00000000000..a98aa0636cf --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/Messages.java @@ -0,0 +1,20 @@ +package org.eclipse.remote.internal.ui; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.remote.internal.ui.messages"; //$NON-NLS-1$ + public static String NewRemoteConnectionTypePage_LaunchTargetType; + public static String NewRemoteConnectionTypePage_SelectTargetType; + public static String NewRemoteConnectionWizard_0; + public static String OpenTerminalHandler_OpenTerminalDesc; + public static String OpenTerminalHandler_OpenTerminalTitle; + public static String RemoteConnectionPropertyPage_ConnectionName; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIPlugin.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIPlugin.java index 3df651febba..3173ec632aa 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIPlugin.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIPlugin.java @@ -5,6 +5,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.remote.internal.ui.messages.Messages; 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 @@ -70,6 +71,18 @@ public class RemoteUIPlugin extends AbstractUIPlugin { log(new Status(IStatus.ERROR, getDefault().getBundle().getSymbolicName(), IStatus.ERROR, Messages.PTPRemoteUIPlugin_3, e)); } + /** + * Return the OSGi service with the given service interface. + * + * @param service service interface + * @return the specified service or null if it's not registered + */ + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + /** * The constructor */ diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIServicesDescriptor.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIServicesDescriptor.java deleted file mode 100644 index 1117dac743a..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/RemoteUIServicesDescriptor.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.ui; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.osgi.util.NLS; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIServices; -import org.eclipse.remote.ui.IRemoteUIServicesDescriptor; -import org.eclipse.remote.ui.IRemoteUIServicesFactory; - -public class RemoteUIServicesDescriptor implements IRemoteUIServicesDescriptor { - private static final String ATTR_ID = "id"; //$NON-NLS-1$ - private static final String ATTR_NAME = "name"; //$NON-NLS-1$ - private static final String ATTR_CLASS = "class"; //$NON-NLS-1$ - - private static String getAttribute(IConfigurationElement configElement, String name, String defaultValue) { - String value = configElement.getAttribute(name); - if (value != null) { - return value; - } - if (defaultValue != null) { - return defaultValue; - } - throw new IllegalArgumentException(NLS.bind(Messages.RemoteUIServicesProxy_1, name)); - } - - private final IConfigurationElement configElement; - private final String id; - private final String name; - private IRemoteUIServicesFactory fFactory = null; - private IRemoteUIServices fDelegate = null; - - public RemoteUIServicesDescriptor(IConfigurationElement configElement) { - this.configElement = configElement; - this.id = getAttribute(configElement, ATTR_ID, null); - this.name = getAttribute(configElement, ATTR_NAME, this.id); - getAttribute(configElement, ATTR_CLASS, null); - } - - /** - * Get the factory from the plugin - * - * @return instance of the factory - */ - public IRemoteUIServicesFactory getFactory() { - if (fFactory != null) { - return fFactory; - } - try { - fFactory = (IRemoteUIServicesFactory) configElement.createExecutableExtension(ATTR_CLASS); - } catch (Exception e) { - RemoteUIPlugin.log(NLS.bind(Messages.RemoteUIServicesProxy_2, new Object[] { configElement.getAttribute(ATTR_CLASS), - id, configElement.getDeclaringExtension().getNamespaceIdentifier() })); - } - return fFactory; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getId() - */ - public String getId() { - return id; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.core.IRemoteServices#getName() - */ - public String getName() { - return name; - } - - /** - * Get the remote UI services implementation for this descriptor. - * - * @return the remote UI services implementation, or null if initialization failed - */ - public IRemoteUIServices getUIServices(IRemoteServices services) { - loadServices(services); - return fDelegate; - } - - /** - * Create and initialize the remote UI services factory - */ - private void loadServices(IRemoteServices services) { - if (fDelegate == null) { - IRemoteUIServicesFactory factory = getFactory(); - if (factory != null) { - fDelegate = factory.getServices(services); - } - } - } -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/ServicePropertyTester.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/ServicePropertyTester.java new file mode 100644 index 00000000000..e11a355517c --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/ServicePropertyTester.java @@ -0,0 +1,41 @@ +package org.eclipse.remote.internal.ui; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; + +public class ServicePropertyTester extends PropertyTester { + + @Override + @SuppressWarnings("unchecked") + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if (receiver instanceof IRemoteConnection) { + IRemoteConnection connection = (IRemoteConnection) receiver; + if (property.equals("hasConnectionTypeService")) { //$NON-NLS-1$ + if (args.length > 0 && args[0] instanceof String) { + String serviceName = (String) args[0]; + try { + Class service = Class.forName(serviceName); + return connection.getConnectionType().hasService((Class) service); + } catch (ClassNotFoundException e) { + return false; + } + } + } else if (property.equals("hasConnectionService")) { //$NON-NLS-1$ + if (args.length > 0 && args[0] instanceof String) { + String serviceName = (String) args[0]; + try { + Class service = Class.forName(serviceName); + return connection.hasService((Class) service); + } catch (ClassNotFoundException e) { + return false; + } + } + } else if (property.equals("canDelete")) { //$NON-NLS-1$ + return (connection.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_REMOVE_CONNECTIONS) != 0; + } + } + return false; + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages.properties b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages.properties new file mode 100644 index 00000000000..26212f3755b --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages.properties @@ -0,0 +1,6 @@ +NewRemoteConnectionTypePage_LaunchTargetType=Launch Target Type +NewRemoteConnectionTypePage_SelectTargetType=Select type of launch target to create. +NewRemoteConnectionWizard_0=Launch Target Type +OpenTerminalHandler_OpenTerminalDesc=A real terminal would open now +OpenTerminalHandler_OpenTerminalTitle=Open Terminal +RemoteConnectionPropertyPage_ConnectionName=Connection Name: diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java index 7da4f298e2c..def2e77dd59 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java @@ -28,19 +28,17 @@ import org.eclipse.jface.viewers.TableLayout; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionControlService; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemotePreferenceConstants; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; +import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.core.exception.RemoteConnectionException; -import org.eclipse.remote.internal.core.RemoteServicesDescriptor; -import org.eclipse.remote.internal.core.RemoteServicesImpl; import org.eclipse.remote.internal.core.preferences.Preferences; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; +import org.eclipse.remote.ui.IRemoteUIConnectionService; import org.eclipse.remote.ui.IRemoteUIConnectionWizard; -import org.eclipse.remote.ui.RemoteUIServices; import org.eclipse.remote.ui.widgets.RemoteConnectionWidget; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; @@ -112,10 +110,10 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe return connection.isOpen() ? Messages.ConnectionsPreferencePage_open : Messages.ConnectionsPreferencePage_closed; case 1: return connection.getName(); - case 2: - return connection.getAddress(); - case 3: - return connection.getUsername(); +// case 2: +// return connection.getAttribute(IRemoteConnection.ADDRESS_ATTR); +// case 3: +// return connection.getAttribute(IRemoteConnection.USERNAME_ATTR); } return null; } @@ -188,8 +186,8 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe private String[] fServiceIDs; private boolean fIsDirty; private IRemoteConnection fSelectedConnection; - private IRemoteConnectionManager fConnectionManager; - private IRemoteUIConnectionManager fUIConnectionManager; + private IRemoteConnectionType fConnectionType; + private IRemoteUIConnectionService fUIConnectionManager; private final Map fWorkingCopies = new HashMap(); @@ -214,7 +212,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe if (fIsDirty) { MessageDialog dialog = new MessageDialog(getShell(), Messages.ConnectionsPreferencePage_Confirm_Actions, null, Messages.ConnectionsPreferencePage_There_are_unsaved_changes, MessageDialog.QUESTION, new String[] { - IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); + IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); if (dialog.open() == 1) { return; } @@ -263,12 +261,18 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe label.setLayoutData(new GridData()); fServicesCombo = new Combo(selectComp, SWT.READ_ONLY); label.setLayoutData(new GridData()); - List descriptors = RemoteServicesImpl.getRemoteServiceDescriptors(); - String[] names = new String[descriptors.size()]; - fServiceIDs = new String[descriptors.size()]; - for (int i = 0; i < descriptors.size(); i++) { - names[i] = descriptors.get(i).getName(); - fServiceIDs[i] = descriptors.get(i).getId(); + + IRemoteServicesManager manager = RemoteUIPlugin.getService(IRemoteServicesManager.class); + List services = manager.getRemoteConnectionTypes(); + String[] names = new String[services.size()]; + fServiceIDs = new String[services.size()]; + { + int i = 0; + for (IRemoteConnectionType s : services) { + names[i] = s.getName(); + fServiceIDs[i] = s.getId(); + i++; + } } fServicesCombo.addSelectionListener(fEventHandler); fServicesCombo.setItems(names); @@ -287,8 +291,11 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe fConnectionTable.addMouseListener(new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) { - if (fSelectedConnection != null && !getOriginalIfClean(fSelectedConnection).isOpen()) { - editConnection(); + if (fSelectedConnection != null) { + IRemoteConnection original = getOriginalIfClean(fSelectedConnection); + if (original.isOpen()) { + editConnection(); + } } } @@ -404,7 +411,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe private void initWorkingConnections() { fWorkingCopies.clear(); - for (IRemoteConnection conn : fConnectionManager.getConnections()) { + for (IRemoteConnection conn : fConnectionType.getConnections()) { fWorkingCopies.put(conn.getName(), conn); } } @@ -467,13 +474,13 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe } private void selectServices(String id) { - IRemoteServices services = RemoteServices.getRemoteServices(id); - if (services != null) { - fConnectionManager = services.getConnectionManager(); - fUIConnectionManager = RemoteUIServices.getRemoteUIServices(services).getUIConnectionManager(); + IRemoteServicesManager manager = RemoteUIPlugin.getService(IRemoteServicesManager.class); + fConnectionType = manager.getConnectionType(id); + if (fConnectionType != null) { + fUIConnectionManager = fConnectionType.getService(IRemoteUIConnectionService.class); initWorkingConnections(); fConnectionViewer.refresh(); - fAddButton.setEnabled((services.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); + fAddButton.setEnabled((fConnectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0); } fIsDirty = false; } @@ -485,12 +492,11 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe TableItem[] items = fConnectionTable.getSelection(); if (items.length > 0) { IRemoteConnection conn = getOriginalIfClean((IRemoteConnection) items[0].getData()); - if (conn.isOpen()) { + if (conn.hasService(IRemoteConnectionControlService.class) && conn.isOpen()) { conn.close(); } else { if (conn instanceof IRemoteConnectionWorkingCopy) { IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) conn; - conn = wc.getOriginal(); if (wc.isDirty()) { MessageDialog dialog = new MessageDialog(getShell(), Messages.ConnectionsPreferencePage_Confirm_Actions, null, Messages.ConnectionsPreferencePage_This_connection_contains_unsaved_changes, @@ -498,15 +504,18 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe if (dialog.open() == 1) { return; } - wc.save(); + try { + conn = wc.save(); + } catch (RemoteConnectionException e) { + RemoteUIPlugin.log(e); + } /* * Replace working copy with original so that the correct version will be used in the future */ fWorkingCopies.put(conn.getName(), conn); } } - IRemoteUIConnectionManager mgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()) - .getUIConnectionManager(); + IRemoteUIConnectionService mgr = conn.getConnectionType().getService(IRemoteUIConnectionService.class); if (mgr != null) { mgr.openConnectionWithProgress(getShell(), null, conn); } @@ -523,10 +532,11 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe /* * Remove any deleted connections */ - for (IRemoteConnection conn : fConnectionManager.getConnections()) { - if (!fWorkingCopies.containsKey(conn.getName()) && !conn.isOpen()) { + for (IRemoteConnection conn : fConnectionType.getConnections()) { + if (!fWorkingCopies.containsKey(conn.getName()) && + (!conn.hasService(IRemoteConnectionControlService.class) || !conn.isOpen())) { try { - fConnectionManager.removeConnection(conn); + fConnectionType.removeConnection(conn); } catch (RemoteConnectionException e) { // Ignore } @@ -539,7 +549,11 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe if (conn instanceof IRemoteConnectionWorkingCopy) { IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) conn; if (wc.isDirty()) { - wc.save(); + try { + wc.save(); + } catch (RemoteConnectionException e) { + RemoteUIPlugin.log(e); + } } } } @@ -553,14 +567,16 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe fCloseButton.setEnabled(false); if (fSelectedConnection != null) { IRemoteConnection conn = getOriginalIfClean(fSelectedConnection); - if (!conn.isOpen()) { - fEditButton - .setEnabled((conn.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_EDIT_CONNECTIONS) != 0); - fRemoveButton - .setEnabled((conn.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_REMOVE_CONNECTIONS) != 0); - fOpenButton.setEnabled(true); + if (conn.hasService(IRemoteConnectionControlService.class)) { + if (!conn.isOpen()) { + fEditButton.setEnabled((conn.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_EDIT_CONNECTIONS) != 0); + fRemoveButton.setEnabled((conn.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_REMOVE_CONNECTIONS) != 0); + fOpenButton.setEnabled(true); + } else { + fCloseButton.setEnabled(true); + } } else { - fCloseButton.setEnabled(true); + fEditButton.setEnabled((conn.getConnectionType().getCapabilities() & IRemoteConnectionType.CAPABILITY_EDIT_CONNECTIONS) != 0); } } } diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/RemoteDevelopmentPreferencePage.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/RemoteDevelopmentPreferencePage.java index 6877fba0c74..476d3909295 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/RemoteDevelopmentPreferencePage.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/RemoteDevelopmentPreferencePage.java @@ -17,8 +17,9 @@ import java.util.List; import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.remote.core.IRemotePreferenceConstants; -import org.eclipse.remote.internal.core.RemoteServicesDescriptor; -import org.eclipse.remote.internal.core.RemoteServicesImpl; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; import org.eclipse.remote.internal.ui.messages.Messages; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -46,7 +47,8 @@ public class RemoteDevelopmentPreferencePage extends FieldEditorPreferencePage i nameAndValue[1] = ""; //$NON-NLS-1$ namesAndValues.add(nameAndValue); - for (RemoteServicesDescriptor service : RemoteServicesImpl.getRemoteServiceDescriptors()) { + IRemoteServicesManager manager = RemoteUIPlugin.getService(IRemoteServicesManager.class); + for (IRemoteConnectionType service : manager.getRemoteConnectionTypes()) { nameAndValue = new String[2]; nameAndValue[0] = service.getName(); nameAndValue[1] = service.getId(); diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIFileManager.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIFileService.java similarity index 80% rename from bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIFileManager.java rename to bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIFileService.java index d22f7bd34fe..cfe33f0ba06 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIFileManager.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIFileService.java @@ -15,15 +15,38 @@ import java.util.Arrays; import java.util.List; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.ui.IRemoteUIFileManager; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteConnectionType.Service; +import org.eclipse.remote.ui.IRemoteUIFileService; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; -public class LocalUIFileManager implements IRemoteUIFileManager { +public class LocalUIFileService implements IRemoteUIFileService { + private final IRemoteConnectionType connectionType; private IRemoteConnection connection = null; + public LocalUIFileService(IRemoteConnectionType connectionType) { + this.connectionType = connectionType; + } + + public static class Factory implements IRemoteConnectionType.Service.Factory { + @SuppressWarnings("unchecked") + @Override + public T getService(IRemoteConnectionType connectionType, Class service) { + if (IRemoteUIFileService.class.equals(service)) { + return (T) new LocalUIFileService(connectionType); + } + return null; + } + } + + @Override + public IRemoteConnectionType getConnectionType() { + return connectionType; + } + /* * (non-Javadoc) * diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServices.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServices.java deleted file mode 100644 index 6977175a162..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServices.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.ui.services.local; - -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; -import org.eclipse.remote.ui.IRemoteUIFileManager; -import org.eclipse.remote.ui.IRemoteUIServices; - -public class LocalUIServices implements IRemoteUIServices { - private static LocalUIServices fInstance = null; - private final static LocalUIFileManager fFileMgr = new LocalUIFileManager(); - - /** - * Get shared instance of this class - * - * @return instance - */ - public static LocalUIServices getInstance(IRemoteServices services) { - if (fInstance == null) { - fInstance = new LocalUIServices(services); - } - return fInstance; - } - - private final IRemoteServices fServices; - - public LocalUIServices(IRemoteServices services) { - fServices = services; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIServicesDescriptor#getId() - */ - public String getId() { - return fServices.getId(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIServicesDescriptor#getName() - */ - public String getName() { - return fServices.getName(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.remote.ui.IRemoteUIServicesDescriptor#getUIConnectionManager(org.eclipse.remote.core.IRemoteConnectionManager) - */ - public IRemoteUIConnectionManager getUIConnectionManager() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIServicesDescriptor#getUIFileManager(org.eclipse.remote.core.IRemoteConnection) - */ - public IRemoteUIFileManager getUIFileManager() { - return fFileMgr; - } -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServicesFactory.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServicesFactory.java deleted file mode 100644 index 55ed14c8d07..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/services/local/LocalUIServicesFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.internal.ui.services.local; - -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.ui.IRemoteUIServices; -import org.eclipse.remote.ui.IRemoteUIServicesFactory; - -public class LocalUIServicesFactory implements IRemoteUIServicesFactory { - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIServicesFactory#getServices(org.eclipse.remote.core.IRemoteServices) - */ - public IRemoteUIServices getServices(IRemoteServices services) { - return LocalUIServices.getInstance(services); - } -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/DeleteRemoteConnectionHandler.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/DeleteRemoteConnectionHandler.java new file mode 100644 index 00000000000..b962ba9ab23 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/DeleteRemoteConnectionHandler.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * 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.internal.ui.views; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +public class DeleteRemoteConnectionHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); + if (selection != null && selection instanceof IStructuredSelection) { + // Get the manageable connections from the selection + List connections = new ArrayList(); + @SuppressWarnings("unchecked") + Iterator i = ((IStructuredSelection) selection).iterator(); + while (i.hasNext()) { + Object obj = i.next(); + if (obj instanceof IRemoteConnection) { + IRemoteConnection connection = (IRemoteConnection)obj; + IRemoteConnectionType connectionType = connection.getConnectionType(); + if ((connectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_REMOVE_CONNECTIONS) != 0) { + connections.add(connection); + } + } + } + + // Confirm the delete + String message = Messages.DeleteRemoteConnectionHandler_ConfirmDeleteMessage; + for (IRemoteConnection connection : connections) { + message += " " + connection.getName(); //$NON-NLS-1 //$NON-NLS-1$ + } + message += "?"; //$NON-NLS-1 //$NON-NLS-1$ + if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.DeleteRemoteConnectionHandler_DeleteConnectionTitle, message)) { + for (IRemoteConnection connection : connections) { + IRemoteConnectionType connectionType = connection.getConnectionType(); + try { + connectionType.removeConnection(connection); + } catch (RemoteConnectionException e) { + RemoteUIPlugin.log(e.getStatus()); + } + } + } + } + return Status.OK_STATUS; + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/Messages.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/Messages.java new file mode 100644 index 00000000000..bc140ebd628 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/Messages.java @@ -0,0 +1,16 @@ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.remote.internal.ui.views.messages"; //$NON-NLS-1$ + public static String DeleteRemoteConnectionHandler_ConfirmDeleteMessage; + public static String DeleteRemoteConnectionHandler_DeleteConnectionTitle; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionHandler.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionHandler.java new file mode 100644 index 00000000000..4d0b62b0ccf --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionHandler.java @@ -0,0 +1,22 @@ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +public class NewRemoteConnectionHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + NewRemoteConnectionWizard wizard = new NewRemoteConnectionWizard(); + Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + WizardDialog dialog = new WizardDialog(parent, wizard); + dialog.open(); + return Status.OK_STATUS; + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionTypePage.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionTypePage.java new file mode 100644 index 00000000000..6763909213c --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionTypePage.java @@ -0,0 +1,96 @@ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.remote.core.IRemoteConnectionType; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.ui.Messages; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; +import org.eclipse.remote.ui.IRemoteUIConnectionService; +import org.eclipse.remote.ui.IRemoteUIConnectionWizard; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +/** + * @since 2.0 API tooling made me put this in even though it's an internal package... + */ +public class NewRemoteConnectionTypePage extends WizardPage { + + private Table table; + private IRemoteUIConnectionWizard nextWizard; + + public NewRemoteConnectionTypePage() { + super("NewLaunchTargetTypePage"); //$NON-NLS-1$ + setTitle(Messages.NewRemoteConnectionTypePage_LaunchTargetType); + setDescription(Messages.NewRemoteConnectionTypePage_SelectTargetType); + } + + public IRemoteUIConnectionWizard getNextWizard() { + return nextWizard; + } + + @Override + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout()); + + table = new Table(comp, SWT.SINGLE | SWT.BORDER); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + table.setLayoutData(data); + + setPageComplete(false); + + IRemoteServicesManager remoteManager = RemoteUIPlugin.getService(IRemoteServicesManager.class); + for (IRemoteConnectionType connectionType : remoteManager.getAllConnectionTypes()) { + if ((connectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) == 0) + continue; + + IRemoteUIConnectionService connManager = connectionType.getService(IRemoteUIConnectionService.class); + if (connManager == null) + continue; + + IRemoteUIConnectionWizard wizard = connManager.getConnectionWizard(parent.getShell()); + if (wizard == null) + continue; + + TableItem item = new TableItem(table, SWT.NONE); + item.setText(connectionType.getName()); + item.setData(wizard); + // TODO connection type icons somehow +// Image icon = ui.getIcon(); +// if (icon != null) { +// item.setImage(icon); +// } + + // TODO select the last selected entry + table.select(0); + setPageComplete(true); + } + + setControl(comp); + } + + @Override + public boolean canFlipToNextPage() { + return isPageComplete(); + } + + @Override + public IWizardPage getNextPage() { + nextWizard = (IRemoteUIConnectionWizard)table.getSelection()[0].getData(); + if (nextWizard != null) { + nextWizard.addPages(); + IWizardPage [] pages = nextWizard.getPages(); + if (pages.length > 0) { + return pages[0]; + } + } + + return super.getNextPage(); + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionWizard.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionWizard.java new file mode 100644 index 00000000000..79b4f498799 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/NewRemoteConnectionWizard.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; +import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.internal.ui.Messages; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; +import org.eclipse.remote.ui.IRemoteUIConnectionWizard; + +/** + * @since 2.0 + */ +public class NewRemoteConnectionWizard extends Wizard { + + private final NewRemoteConnectionTypePage typePage; + + public NewRemoteConnectionWizard() { + setWindowTitle(Messages.NewRemoteConnectionWizard_0); + typePage = new NewRemoteConnectionTypePage(); + setForcePreviousAndNextButtons(true); + } + + @Override + public void addPages() { + addPage(typePage); + } + + @Override + public boolean performFinish() { + IRemoteUIConnectionWizard nextWizard = typePage.getNextWizard(); + if (nextWizard != null) { + IRemoteConnectionWorkingCopy wc = nextWizard.getConnection(); + try { + wc.save(); + } catch (RemoteConnectionException e) { + RemoteUIPlugin.log(e); + return false; + } + return true; + } else { + // what happened? + return false; + } + } + + @Override + public boolean canFinish() { + // Need to move onto the new target wizard + return false; + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/OpenTerminalHandler.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/OpenTerminalHandler.java new file mode 100644 index 00000000000..ddf4f4a6d5f --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/OpenTerminalHandler.java @@ -0,0 +1,24 @@ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.remote.internal.ui.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +public class OpenTerminalHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // TODO Need to figure out how to open a terminal for this connection + Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + MessageDialog.open(MessageDialog.INFORMATION, parent, + Messages.OpenTerminalHandler_OpenTerminalTitle, Messages.OpenTerminalHandler_OpenTerminalDesc, SWT.NONE); + return Status.OK_STATUS; + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionPropertyPage.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionPropertyPage.java new file mode 100644 index 00000000000..47ec6d32182 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionPropertyPage.java @@ -0,0 +1,48 @@ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.internal.ui.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.PropertyPage; + +public class RemoteConnectionPropertyPage extends PropertyPage { + + @Override + protected Control createContents(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout(2, false)); + + IRemoteConnection connection = null; + Object element = getElement(); + if (element instanceof IRemoteConnection) { + connection = (IRemoteConnection) element; + } else if (element instanceof IAdaptable) { + connection = (IRemoteConnection) ((IAdaptable) element).getAdapter(IRemoteConnection.class); + } + + if (connection != null) { + Label nameLabel = new Label(comp, SWT.NONE); + nameLabel.setText(Messages.RemoteConnectionPropertyPage_ConnectionName); + + Text nameText = new Text(comp, SWT.BORDER); + nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + nameText.setText(connection.getName()); + } + + return comp; + } + + @Override + public boolean performOk() { + // TODO, change the name if it needs changing + return true; + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsActionProvider.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsActionProvider.java new file mode 100644 index 00000000000..1e09bb16f8c --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsActionProvider.java @@ -0,0 +1,17 @@ +package org.eclipse.remote.internal.ui.views; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.window.SameShellProvider; +import org.eclipse.ui.dialogs.PropertyDialogAction; +import org.eclipse.ui.navigator.CommonActionProvider; + +public class RemoteConnectionsActionProvider extends CommonActionProvider { + + @Override + public void fillContextMenu(IMenuManager menu) { + // Property menu + menu.add(new PropertyDialogAction(new SameShellProvider(getActionSite().getViewSite().getShell()), + getActionSite().getStructuredViewer())); + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsContentProvider.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsContentProvider.java new file mode 100644 index 00000000000..0cc8cc60488 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsContentProvider.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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.internal.ui.views; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.RemoteConnectionChangeEvent; +import org.eclipse.remote.core.IRemoteConnectionChangeListener; +import org.eclipse.remote.core.IRemoteServicesManager; + +public class RemoteConnectionsContentProvider implements ITreeContentProvider, IRemoteConnectionChangeListener { + + private IRemoteServicesManager remoteServicesManager; + private Viewer viewer; + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + this.viewer = viewer; + + if (newInput instanceof IRemoteServicesManager) { + if (remoteServicesManager != null) { + // remove us as a listener on the old manager + remoteServicesManager.removeRemoteConnectionChangeListener(this); + } + + remoteServicesManager = (IRemoteServicesManager) newInput; + remoteServicesManager.addRemoteConnectionChangeListener(this); + } + } + + @Override + public void connectionChanged(RemoteConnectionChangeEvent event) { + // Refresh the viewer on the UI thread + viewer.getControl().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + viewer.refresh(); + } + }); + } + + @Override + public void dispose() { + if (remoteServicesManager != null) { + remoteServicesManager.removeRemoteConnectionChangeListener(this); + } + } + + @Override + public Object[] getElements(Object inputElement) { + return remoteServicesManager.getAllRemoteConnections().toArray(); + } + + @Override + public Object[] getChildren(Object parentElement) { + // Connections have no children by default + return new Object[0]; + } + + @Override + public Object getParent(Object element) { + if (element instanceof IRemoteConnection) { + return remoteServicesManager; + } else { + return null; + } + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof IRemoteServicesManager) { + return true; + } else { + return false; + } + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsLabelProvider.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsLabelProvider.java new file mode 100644 index 00000000000..9009d2ea9c0 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsLabelProvider.java @@ -0,0 +1,24 @@ +package org.eclipse.remote.internal.ui.views; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.swt.graphics.Image; + + +public class RemoteConnectionsLabelProvider extends LabelProvider { + + @Override + public String getText(Object element) { + if (element instanceof IRemoteConnection) { + return ((IRemoteConnection) element).getName(); + } else { + return super.getText(element); + } + } + + @Override + public Image getImage(Object element) { + // TODO Need a method to get icons for the UI connection managers. + return super.getImage(element); + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsView.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsView.java new file mode 100644 index 00000000000..a3db899a4d5 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/RemoteConnectionsView.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.internal.ui.views; + +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; +import org.eclipse.ui.navigator.CommonNavigator; + +public class RemoteConnectionsView extends CommonNavigator { + + @Override + protected Object getInitialInput() { + // the remote services manager is the root object + return RemoteUIPlugin.getService(IRemoteServicesManager.class); + } + +} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/messages.properties b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/messages.properties new file mode 100644 index 00000000000..ee73ad7de56 --- /dev/null +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/views/messages.properties @@ -0,0 +1,2 @@ +DeleteRemoteConnectionHandler_ConfirmDeleteMessage=Delete connection +DeleteRemoteConnectionHandler_DeleteConnectionTitle=Delete Connection diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/AbstractRemoteUIConnectionManager.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/AbstractRemoteUIConnectionManager.java index bf62dfcd6ca..3b0f05c27d7 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/AbstractRemoteUIConnectionManager.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/AbstractRemoteUIConnectionManager.java @@ -27,18 +27,9 @@ import org.eclipse.swt.widgets.Shell; /** * Abstract base class for providing UI connection manager services. - * - * @since 7.0 */ -public abstract class AbstractRemoteUIConnectionManager implements IRemoteUIConnectionManager { - /* - * (non-Javadoc) - * - * @see org.eclipse.remote.ui.IRemoteUIConnectionManager# - * openConnectionWithProgress(org.eclipse.swt.widgets.Shell, - * org.eclipse.jface.operation.IRunnableContext, - * org.eclipse.remote.core.IRemoteConnection) - */ +public abstract class AbstractRemoteUIConnectionManager implements IRemoteUIConnectionService { + public void openConnectionWithProgress(final Shell shell, IRunnableContext context, final IRemoteConnection connection) { if (!connection.isOpen()) { IRunnableWithProgress op = new IRunnableWithProgress() { @@ -70,4 +61,5 @@ public abstract class AbstractRemoteUIConnectionManager implements IRemoteUIConn } } } + } diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionService.java similarity index 92% rename from bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java rename to bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionService.java index d2482fabf2e..5828164570e 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionManager.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionService.java @@ -12,13 +12,15 @@ package org.eclipse.remote.ui; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.swt.widgets.Shell; /** * Interface for providing connection management operations in the UI. Clients can call these methods to open generic dialogs for * operations on connections. + * @since 2.0 */ -public interface IRemoteUIConnectionManager { +public interface IRemoteUIConnectionService extends IRemoteConnectionType.Service { /** * Create a wizard for adding or editing connections. The implementation can choose to do this in any way, but typically will * use a dialog or wizard. diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionWizard.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionWizard.java index d1eae8617f4..770b04ccbec 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionWizard.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIConnectionWizard.java @@ -12,12 +12,13 @@ package org.eclipse.remote.ui; import java.util.Set; +import org.eclipse.jface.wizard.IWizard; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; /** * Interface for creating and editing connections in the UI. */ -public interface IRemoteUIConnectionWizard { +public interface IRemoteUIConnectionWizard extends IWizard { /** * Open configuration wizard allowing the user to enter information about a connection. If the user confirms the information is * correct (e.g. selects OK in a dialog) then a working copy of the connection is returned. If the user discards the @@ -25,7 +26,15 @@ public interface IRemoteUIConnectionWizard { * * @return connection working copy or null if the wizard is canceled */ - public IRemoteConnectionWorkingCopy open(); + IRemoteConnectionWorkingCopy open(); + + /** + * Get the connection being edited. + * + * @return connection being edited + * @since 2.0 + */ + IRemoteConnectionWorkingCopy getConnection(); /** * Set a connection containing the information to be edited by the wizard. Setting this value overrides the @@ -34,7 +43,7 @@ public interface IRemoteUIConnectionWizard { * @param connection * connection used to initialize the wizard */ - public void setConnection(IRemoteConnectionWorkingCopy connection); + void setConnection(IRemoteConnectionWorkingCopy connection); /** * Set the initial name of the connection. @@ -42,7 +51,7 @@ public interface IRemoteUIConnectionWizard { * @param name * initial connection name */ - public void setConnectionName(String name); + void setConnectionName(String name); /** * Supply a set of connection names that are invalid. The dialog should display an error if the user trys to select a name from @@ -51,5 +60,6 @@ public interface IRemoteUIConnectionWizard { * @param names * set of invalid connections names */ - public void setInvalidConnectionNames(Set names); + void setInvalidConnectionNames(Set names); + } diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIFileManager.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIFileService.java similarity index 96% rename from bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIFileManager.java rename to bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIFileService.java index 67e5c334fbb..cdba005247e 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIFileManager.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIFileService.java @@ -13,13 +13,15 @@ package org.eclipse.remote.ui; import java.util.List; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.swt.widgets.Shell; /** * Interface for providing file management operations in the UI. Clients can call these methods to open generic dialogs for * operations on remote resources. + * @since 2.0 */ -public interface IRemoteUIFileManager { +public interface IRemoteUIFileService extends IRemoteConnectionType.Service { /** * Browse for a remote directory. The return value is the path of the * directory on the remote system. diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServices.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServices.java deleted file mode 100644 index bff022f66d3..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServices.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.ui; - -/** - * Abstraction of a UI remote services provider. Clients obtain this interface using one of the static methods in - * {@link RemoteUIServices}. The methods on this interface can then be used to access the full range of UI services provided. - */ -public interface IRemoteUIServices extends IRemoteUIServicesDescriptor { - /** - * Get a UI connection manager for managing connections - * - * @return UI connection manager or null if no connection manager operations are supported - */ - public IRemoteUIConnectionManager getUIConnectionManager(); - - /** - * Get a UI file manager for managing remote files. - * - * @return UI file manager or null if no file manager operations are supported - */ - public IRemoteUIFileManager getUIFileManager(); -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesDescriptor.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesDescriptor.java deleted file mode 100644 index 840e1a4fd13..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesDescriptor.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.ui; - -/** - * Interface representing a remote UI services provider extension. Clients can use this to find out information about the extension - * without loading it. - */ -public interface IRemoteUIServicesDescriptor { - /** - * Get unique ID of this service. Can be used as a lookup key. - * - * @return unique ID - */ - public String getId(); - - /** - * Get display name of this service. - * - * @return display name - */ - public String getName(); -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesFactory.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesFactory.java deleted file mode 100644 index 9489052d636..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/IRemoteUIServicesFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.ui; - -import org.eclipse.remote.core.IRemoteServices; - -/** - * Factory for creating instances of a remote UI service provider. Implementors must provide a class implementing this interface - * when supplying a new remote UI services provider extension. - */ -public interface IRemoteUIServicesFactory { - /** - * @param services - * remote services - * @return remote services delegate - */ - public IRemoteUIServices getServices(IRemoteServices services); -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/RemoteUIServices.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/RemoteUIServices.java deleted file mode 100644 index 3b4de2a0599..00000000000 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/RemoteUIServices.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 IBM Corporation 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: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.remote.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; -import org.eclipse.remote.internal.ui.RemoteUIPlugin; -import org.eclipse.remote.internal.ui.RemoteUIServicesDescriptor; -import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.ui.PlatformUI; - -/** - * Main entry point for accessing remote UI services. - * - * @since 7.0 - */ -public class RemoteUIServices { - private static final String EXTENSION_POINT_ID = "remoteUIServices"; //$NON-NLS-1$ - - private static Map fRemoteUIServices = null; - private static Map fRemoteServices = new HashMap(); - - /** - * Look up a remote service provider and ensure it is initialized. The method will use the supplied container's progress - * service, or, if null, the platform progress service, in order to allow the initialization to be canceled. - * - * @param id - * id of service to locate - * @param context - * context with progress service, or null to use the platform progress service - * @return remote service or null if the service can't be located or the progress monitor was canceled - * @since 5.0 - */ - public static IRemoteServices getRemoteServices(final String id, IRunnableContext context) { - IRemoteServices service = fRemoteServices.get(id); - if (service == null) { - final IRemoteServices[] remoteService = new IRemoteServices[1]; - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask(Messages.RemoteUIServices_Configuring_remote_services, 10); - remoteService[0] = RemoteServices.getRemoteServices(id, monitor); - } - }; - try { - if (context != null) { - context.run(true, false, runnable); - } else { - PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); - } - } catch (InvocationTargetException e) { - // Ignored - } catch (InterruptedException e) { - // cancelled - } - service = remoteService[0]; - if (service != null) { - fRemoteServices.put(id, service); - } - } - return service; - } - - /** - * Helper method to find UI services that correspond to a particular remote services implementation - * - * @param services - * @return remote UI services - */ - public static IRemoteUIServices getRemoteUIServices(IRemoteServices services) { - if (fRemoteUIServices == null) { - fRemoteUIServices = retrieveRemoteUIServices(); - } - - /* - * Find the UI services corresponding to services. - */ - RemoteUIServicesDescriptor descriptor = fRemoteUIServices.get(services.getId()); - if (descriptor != null) { - return descriptor.getUIServices(services); - } - return null; - } - - /** - * Find and load all remoteUIServices plugins. - */ - private static Map retrieveRemoteUIServices() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = registry.getExtensionPoint(RemoteUIPlugin.getUniqueIdentifier(), EXTENSION_POINT_ID); - final IExtension[] extensions = extensionPoint.getExtensions(); - - Map services = new HashMap(5); - - for (IExtension ext : extensions) { - final IConfigurationElement[] elements = ext.getConfigurationElements(); - - for (IConfigurationElement ce : elements) { - RemoteUIServicesDescriptor descriptor = new RemoteUIServicesDescriptor(ce); - services.put(descriptor.getId(), descriptor); - } - } - - return services; - } -} diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java index 53f7cd16f6f..8d836359b42 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/dialogs/RemoteResourceBrowser.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.operation.IRunnableContext; @@ -24,6 +25,7 @@ import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.wizard.ProgressMonitorPart; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; import org.eclipse.remote.internal.ui.messages.Messages; import org.eclipse.remote.ui.widgets.RemoteResourceBrowserWidget; import org.eclipse.swt.SWT; @@ -120,7 +122,11 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext { fResourceBrowserWidget.setInitialPath(fInitialPath); } if (fConnection != null) { - fResourceBrowserWidget.setConnection(fConnection); + try { + fResourceBrowserWidget.setConnection(fConnection); + } catch (CoreException e) { + RemoteUIPlugin.log(e.getStatus()); + } } updateDialog(); return contents; @@ -181,7 +187,11 @@ public class RemoteResourceBrowser extends Dialog implements IRunnableContext { }); fResourceBrowserWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); if (fConnection != null) { - fResourceBrowserWidget.setConnection(fConnection); + try { + fResourceBrowserWidget.setConnection(fConnection); + } catch (CoreException e) { + RemoteUIPlugin.log(e.getStatus()); + } } Composite monitorComposite = new Composite(main, SWT.NULL); diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java index cf6d1a0e995..f3c84466abd 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteConnectionWidget.java @@ -10,25 +10,23 @@ *******************************************************************************/ package org.eclipse.remote.ui.widgets; +import java.util.Collections; +import java.util.Comparator; import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.ListenerList; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemotePreferenceConstants; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; -import org.eclipse.remote.internal.core.RemoteServicesDescriptor; -import org.eclipse.remote.internal.core.RemoteServicesImpl; +import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.internal.core.preferences.Preferences; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; +import org.eclipse.remote.ui.IRemoteUIConnectionService; import org.eclipse.remote.ui.IRemoteUIConnectionWizard; -import org.eclipse.remote.ui.RemoteUIServices; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -133,22 +131,19 @@ public class RemoteConnectionWidget extends Composite { */ public static int FLAG_NO_LOCAL_SELECTION = 1 << 1; - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private Combo fServicesCombo = null; private Button fLocalButton; private Button fRemoteButton; private final Combo fConnectionCombo; private final Button fNewConnectionButton; - private final List fRemoteServices; + private final List fConnectionTypes; private IRemoteConnection fSelectedConnection; - private IRemoteServices fDefaultServices; + private IRemoteServicesManager fRemoteServicesManager = RemoteUIPlugin.getService(IRemoteServicesManager.class); + private IRemoteConnectionType fDefaultConnectionType; private boolean fSelectionListernersEnabled = true; private boolean fEnabled = true; - private final IRunnableContext fContext; - private final ListenerList fSelectionListeners = new ListenerList(); private final WidgetListener fWidgetListener = new WidgetListener(); @@ -184,7 +179,6 @@ public class RemoteConnectionWidget extends Composite { */ public RemoteConnectionWidget(Composite parent, int style, String title, int flags, IRunnableContext context) { super(parent, style); - fContext = context; Composite body = this; @@ -214,11 +208,11 @@ public class RemoteConnectionWidget extends Composite { if ((flags & FLAG_FORCE_PROVIDER_SELECTION) == 0) { String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); if (id != null) { - fDefaultServices = getRemoteServices(id); + fDefaultConnectionType = fRemoteServicesManager.getConnectionType(id); } } - if (fDefaultServices == null) { + if (fDefaultConnectionType == null) { /* * Remote provider */ @@ -253,7 +247,7 @@ public class RemoteConnectionWidget extends Composite { fConnectionCombo = new Combo(body, SWT.DROP_DOWN | SWT.READ_ONLY); fConnectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fConnectionCombo.addSelectionListener(fWidgetListener); - if (fDefaultServices != null) { + if (fDefaultConnectionType != null) { fConnectionCombo.setFocus(); } fConnectionCombo.setEnabled(false); @@ -263,7 +257,8 @@ public class RemoteConnectionWidget extends Composite { fNewConnectionButton.setLayoutData(new GridData()); fNewConnectionButton.addSelectionListener(fWidgetListener); - fRemoteServices = RemoteServicesImpl.getRemoteServiceDescriptors(); + fRemoteServicesManager = RemoteUIPlugin.getService(IRemoteServicesManager.class); + fConnectionTypes = fRemoteServicesManager.getRemoteConnectionTypes(); if (fServicesCombo != null) { initializeRemoteServicesCombo(null); @@ -309,51 +304,21 @@ public class RemoteConnectionWidget extends Composite { return fSelectedConnection; } - private IRemoteConnection getRemoteConnection(IRemoteServices services, String name) { - IRemoteConnectionManager manager = getRemoteConnectionManager(services); - if (manager != null) { - return manager.getConnection(name); - } - return null; - } - - private IRemoteConnection getRemoteConnection(String name) { - IRemoteServices services = getSelectedServices(); - if (fDefaultServices != null && name.equals(IRemoteConnectionManager.LOCAL_CONNECTION_NAME)) { - services = RemoteServices.getLocalServices(); - } - return getRemoteConnection(services, name); - } - - protected IRemoteConnectionManager getRemoteConnectionManager(IRemoteServices services) { - if (services != null) { - return services.getConnectionManager(); - } - return null; - } - - protected IRemoteServices getRemoteServices(String id) { - if (id != null && !id.equals(EMPTY_STRING)) { - return RemoteUIServices.getRemoteServices(id, fContext); - } - return null; - } - - private IRemoteServices getSelectedServices() { - if (fDefaultServices != null) { - return fDefaultServices; + private IRemoteConnectionType getSelectedConnectionType() { + if (fDefaultConnectionType != null) { + return fDefaultConnectionType; } int selectionIndex = fServicesCombo.getSelectionIndex(); - if (fRemoteServices.size() > 0 && selectionIndex > 0) { - return RemoteServices.getRemoteServices(fRemoteServices.get(selectionIndex - 1).getId()); + if (fConnectionTypes.size() > 0 && selectionIndex > 0) { + return fRemoteServicesManager.getConnectionType(fConnectionTypes.get(selectionIndex - 1).getId()); } return null; } - private IRemoteUIConnectionManager getUIConnectionManager() { - IRemoteServices services = getSelectedServices(); + private IRemoteUIConnectionService getUIConnectionManager() { + IRemoteConnectionType services = getSelectedConnectionType(); if (services != null) { - return RemoteUIServices.getRemoteUIServices(services).getUIConnectionManager(); + return services.getService(IRemoteUIConnectionService.class); } return null; } @@ -366,19 +331,19 @@ public class RemoteConnectionWidget extends Composite { /** * Handle the section of a new connection. Update connection option buttons appropriately. + * @throws CoreException */ protected void handleConnectionSelected() { final boolean enabled = fWidgetListener.isEnabled(); fWidgetListener.disable(); IRemoteConnection selectedConnection = null; if (fLocalButton != null && fLocalButton.getSelection()) { - selectedConnection = RemoteServices.getLocalServices().getConnectionManager() - .getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME); + selectedConnection = fRemoteServicesManager.getLocalConnectionType().getConnections().get(0); } else { int currentSelection = fConnectionCombo.getSelectionIndex(); if (currentSelection > 0) { String connectionName = fConnectionCombo.getItem(currentSelection); - selectedConnection = getRemoteConnection(connectionName); + selectedConnection = getSelectedConnectionType().getConnection(connectionName); } } if (selectedConnection == null || fSelectedConnection == null @@ -396,6 +361,7 @@ public class RemoteConnectionWidget extends Composite { * connection combo with the new connection. * * TODO should probably select the new connection + * @throws CoreException */ protected void handleNewRemoteConnectionSelected() { if (getUIConnectionManager() != null) { @@ -404,8 +370,12 @@ public class RemoteConnectionWidget extends Composite { wizard.setConnectionName(initialConnectionName()); IRemoteConnectionWorkingCopy conn = wizard.open(); if (conn != null) { - handleRemoteServiceSelected(conn.save()); - handleConnectionSelected(); + try { + handleRemoteServiceSelected(conn.save()); + handleConnectionSelected(); + } catch (CoreException e) { + RemoteUIPlugin.log(e); + } } } } @@ -422,23 +392,24 @@ public class RemoteConnectionWidget extends Composite { * @param notify * if true, notify handlers that the connection has changed. This should only happen if the user changes the * connection. + * @throws CoreException */ protected void handleRemoteServiceSelected(IRemoteConnection conn) { final boolean enabled = fWidgetListener.isEnabled(); fWidgetListener.disable(); try { - IRemoteServices selectedServices = getSelectedServices(); + IRemoteConnectionType selectedConnectionType = getSelectedConnectionType(); if (conn != null) { - selectedServices = conn.getRemoteServices(); + selectedConnectionType = conn.getConnectionType(); } /* * If a connection was supplied, set its remote service provider in the combo. Otherwise use the currently selected * service. */ - if (fDefaultServices == null && conn != null) { - for (int index = 0; index < fRemoteServices.size(); index++) { - if (fRemoteServices.get(index).getId().equals(selectedServices.getId())) { + if (fDefaultConnectionType == null && conn != null) { + for (int index = 0; index < fConnectionTypes.size(); index++) { + if (fConnectionTypes.get(index).getId().equals(selectedConnectionType.getId())) { fServicesCombo.select(index + 1); break; } @@ -448,22 +419,26 @@ public class RemoteConnectionWidget extends Composite { fConnectionCombo.removeAll(); fConnectionCombo.add(Messages.RemoteConnectionWidget_selectConnection); - if (selectedServices == null) { + if (selectedConnectionType == null) { fConnectionCombo.select(0); fConnectionCombo.setEnabled(false); fNewConnectionButton.setEnabled(false); } else { fConnectionCombo.setEnabled(true); - IRemoteConnectionManager connectionManager = selectedServices.getConnectionManager(); - /* * Populate the connection combo and select the connection */ int selected = 0; int offset = 1; - Set sorted = new TreeSet(connectionManager.getConnections()); + List sorted = selectedConnectionType.getConnections(); + Collections.sort(sorted, new Comparator() { + @Override + public int compare(IRemoteConnection o1, IRemoteConnection o2) { + return o1.getName().compareTo(o2.getName()); + } + }); for (IRemoteConnection s : sorted) { fConnectionCombo.add(s.getName()); @@ -480,7 +455,7 @@ public class RemoteConnectionWidget extends Composite { * Enable 'new' button if new connections are supported */ fNewConnectionButton - .setEnabled((selectedServices.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); + .setEnabled((selectedConnectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0); } } finally { fWidgetListener.setEnabled(enabled); @@ -490,7 +465,7 @@ public class RemoteConnectionWidget extends Composite { private String initialConnectionName() { String name = DEFAULT_CONNECTION_NAME; int count = 1; - while (getSelectedServices().getConnectionManager().getConnection(name) != null) { + while (getSelectedConnectionType().getConnection(name) != null) { name = DEFAULT_CONNECTION_NAME + " " + count++; //$NON-NLS-1$ } return name; @@ -505,21 +480,21 @@ public class RemoteConnectionWidget extends Composite { protected void initializeRemoteServicesCombo(String id) { final boolean enabled = fWidgetListener.isEnabled(); fWidgetListener.disable(); - IRemoteServices defService = null; + IRemoteConnectionType defService = null; if (id != null) { - defService = getRemoteServices(id); + defService = fRemoteServicesManager.getConnectionType(id); } fServicesCombo.removeAll(); int offset = 1; int defIndex = 0; fServicesCombo.add(Messages.RemoteConnectionWidget_selectRemoteProvider); - for (int i = 0; i < fRemoteServices.size(); i++) { - fServicesCombo.add(fRemoteServices.get(i).getName()); - if (defService != null && fRemoteServices.get(i).equals(defService)) { + for (int i = 0; i < fConnectionTypes.size(); i++) { + fServicesCombo.add(fConnectionTypes.get(i).getName()); + if (defService != null && fConnectionTypes.get(i).equals(defService)) { defIndex = i + offset; } } - if (fRemoteServices.size() > 0) { + if (fConnectionTypes.size() > 0) { fServicesCombo.select(defIndex); } fWidgetListener.setEnabled(enabled); @@ -558,10 +533,11 @@ public class RemoteConnectionWidget extends Composite { * * @param connection * connection to select + * @throws CoreException */ public void setConnection(IRemoteConnection connection) { fSelectionListernersEnabled = false; - if (fLocalButton != null && connection != null && connection.getRemoteServices() == RemoteServices.getLocalServices()) { + if (fLocalButton != null && connection != null && connection.getConnectionType() == fRemoteServicesManager.getLocalConnectionType()) { fLocalButton.setSelection(true); handleButtonSelected(); } else { @@ -579,12 +555,13 @@ public class RemoteConnectionWidget extends Composite { * remote services id * @param name * connection name + * @throws CoreException * @since 6.0 */ public void setConnection(String id, String name) { - IRemoteServices services = getRemoteServices(id); - if (services != null) { - IRemoteConnection connection = getRemoteConnection(services, name); + IRemoteConnectionType connectionType = fRemoteServicesManager.getConnectionType(id); + if (connectionType != null) { + IRemoteConnection connection = connectionType.getConnection(name); if (connection != null) { setConnection(connection); } @@ -603,7 +580,7 @@ public class RemoteConnectionWidget extends Composite { } private void updateEnablement() { - if (fDefaultServices != null) { + if (fDefaultConnectionType != null) { boolean isRemote = true; if (fLocalButton != null) { fLocalButton.setEnabled(fEnabled); @@ -612,12 +589,12 @@ public class RemoteConnectionWidget extends Composite { } fConnectionCombo.setEnabled(fEnabled && isRemote); fNewConnectionButton.setEnabled(fEnabled && isRemote - && (fDefaultServices.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); + && (fDefaultConnectionType.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0); } else { - IRemoteServices services = getSelectedServices(); + IRemoteConnectionType services = getSelectedConnectionType(); fConnectionCombo.setEnabled(fEnabled && services != null); fNewConnectionButton.setEnabled(fEnabled && services != null - && (services.getCapabilities() & IRemoteServices.CAPABILITY_ADD_CONNECTIONS) != 0); + && (services.getCapabilities() & IRemoteConnectionType.CAPABILITY_ADD_CONNECTIONS) != 0); fServicesCombo.setEnabled(fEnabled); } } diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java index 71b045ca356..3f6617192ea 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteDirectoryWidget.java @@ -15,10 +15,10 @@ import java.util.Map; import org.eclipse.core.runtime.ListenerList; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteProcessService; import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; -import org.eclipse.remote.ui.IRemoteUIFileManager; -import org.eclipse.remote.ui.RemoteUIServices; +import org.eclipse.remote.ui.IRemoteUIConnectionService; +import org.eclipse.remote.ui.IRemoteUIFileService; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -201,12 +201,12 @@ public class RemoteDirectoryWidget extends Composite { } private void browse() { - IRemoteUIConnectionManager connMgr = getUIConnectionManager(); + IRemoteUIConnectionService connMgr = getUIConnectionManager(); if (connMgr != null) { connMgr.openConnectionWithProgress(getShell(), null, fRemoteConnection); } if (fRemoteConnection.isOpen()) { - IRemoteUIFileManager fileMgr = getUIFileManager(); + IRemoteUIFileService fileMgr = getUIFileManager(); if (fileMgr != null) { fileMgr.setConnection(fRemoteConnection); String path = fileMgr.browseDirectory(getShell(), fBrowseMessage, "", 0); //$NON-NLS-1$ @@ -219,21 +219,21 @@ public class RemoteDirectoryWidget extends Composite { private String getSavedPath() { if (fRemoteConnection != null) { - return previousSelections.get(fRemoteConnection.getRemoteServices().getId() + "." + fRemoteConnection.getName()); //$NON-NLS-1$ + return previousSelections.get(fRemoteConnection.getConnectionType().getId() + "." + fRemoteConnection.getName()); //$NON-NLS-1$ } return null; } - private IRemoteUIFileManager getUIFileManager() { + private IRemoteUIFileService getUIFileManager() { if (fRemoteConnection != null) { - return RemoteUIServices.getRemoteUIServices(fRemoteConnection.getRemoteServices()).getUIFileManager(); + return fRemoteConnection.getConnectionType().getService(IRemoteUIFileService.class); } return null; } - private IRemoteUIConnectionManager getUIConnectionManager() { + private IRemoteUIConnectionService getUIConnectionManager() { if (fRemoteConnection != null) { - return RemoteUIServices.getRemoteUIServices(fRemoteConnection.getRemoteServices()).getUIConnectionManager(); + return fRemoteConnection.getConnectionType().getService(IRemoteUIConnectionService.class); } return null; } @@ -246,7 +246,10 @@ public class RemoteDirectoryWidget extends Composite { private void restoreDefault(String path) { if (path == null && fRemoteConnection != null) { - path = fRemoteConnection.getWorkingDirectory().toString(); + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + if (processService != null) { + path = processService.getWorkingDirectory().toString(); + } } if (path == null) { path = ""; //$NON-NLS-1$ @@ -256,7 +259,7 @@ public class RemoteDirectoryWidget extends Composite { private void setSavedPath(String path) { if (fRemoteConnection != null) { - previousSelections.put(fRemoteConnection.getRemoteServices().getId() + "." + fRemoteConnection.getName(), path); //$NON-NLS-1$ + previousSelections.put(fRemoteConnection.getConnectionType().getId() + "." + fRemoteConnection.getName(), path); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java index fa24961937f..e49a6e0ac3d 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteFileWidget.java @@ -15,10 +15,10 @@ import java.util.Map; import org.eclipse.core.runtime.ListenerList; import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.remote.core.IRemoteProcessService; import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; -import org.eclipse.remote.ui.IRemoteUIFileManager; -import org.eclipse.remote.ui.RemoteUIServices; +import org.eclipse.remote.ui.IRemoteUIConnectionService; +import org.eclipse.remote.ui.IRemoteUIFileService; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -137,12 +137,12 @@ public class RemoteFileWidget extends Composite { } private void browse() { - IRemoteUIConnectionManager connMgr = getUIConnectionManager(); + IRemoteUIConnectionService connMgr = getUIConnectionManager(); if (connMgr != null) { connMgr.openConnectionWithProgress(getShell(), null, fRemoteConnection); } if (fRemoteConnection.isOpen()) { - IRemoteUIFileManager fileMgr = getUIFileManager(); + IRemoteUIFileService fileMgr = getUIFileManager(); if (fileMgr != null) { fileMgr.setConnection(fRemoteConnection); String path = fileMgr.browseFile(getShell(), fBrowseMessage, "", 0); //$NON-NLS-1$ @@ -165,21 +165,21 @@ public class RemoteFileWidget extends Composite { private String getSavedPath() { if (fRemoteConnection != null) { - return fPreviousSelections.get(fRemoteConnection.getRemoteServices().getId() + "." + fRemoteConnection.getName()); //$NON-NLS-1$ + return fPreviousSelections.get(fRemoteConnection.getConnectionType().getId() + "." + fRemoteConnection.getName()); //$NON-NLS-1$ } return null; } - private IRemoteUIConnectionManager getUIConnectionManager() { + private IRemoteUIConnectionService getUIConnectionManager() { if (fRemoteConnection != null) { - return RemoteUIServices.getRemoteUIServices(fRemoteConnection.getRemoteServices()).getUIConnectionManager(); + return fRemoteConnection.getConnectionType().getService(IRemoteUIConnectionService.class); } return null; } - private IRemoteUIFileManager getUIFileManager() { + private IRemoteUIFileService getUIFileManager() { if (fRemoteConnection != null) { - return RemoteUIServices.getRemoteUIServices(fRemoteConnection.getRemoteServices()).getUIFileManager(); + return fRemoteConnection.getConnectionType().getService(IRemoteUIFileService.class); } return null; } @@ -203,7 +203,10 @@ public class RemoteFileWidget extends Composite { private void restoreDefault(String path) { if (path == null && fRemoteConnection != null) { - path = fRemoteConnection.getWorkingDirectory().toString(); + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + if (processService != null) { + path = processService.getWorkingDirectory().toString(); + } } if (path == null) { path = ""; //$NON-NLS-1$ @@ -276,7 +279,7 @@ public class RemoteFileWidget extends Composite { private void setSavedPath(String path) { if (fRemoteConnection != null) { - fPreviousSelections.put(fRemoteConnection.getRemoteServices().getId() + "." + fRemoteConnection.getName(), path); //$NON-NLS-1$ + fPreviousSelections.put(fRemoteConnection.getConnectionType().getId() + "." + fRemoteConnection.getName(), path); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java index 684b292f2cf..72d717092b6 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/ui/widgets/RemoteResourceBrowserWidget.java @@ -43,7 +43,8 @@ import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteFileManager; +import org.eclipse.remote.core.IRemoteFileService; +import org.eclipse.remote.core.IRemoteProcessService; import org.eclipse.remote.internal.ui.DeferredFileStore; import org.eclipse.remote.internal.ui.DeferredFileStoreComparer; import org.eclipse.remote.internal.ui.PendingUpdateAdapter; @@ -51,9 +52,9 @@ import org.eclipse.remote.internal.ui.RemoteContentProvider; import org.eclipse.remote.internal.ui.RemoteResourceComparator; import org.eclipse.remote.internal.ui.RemoteTreeViewer; import org.eclipse.remote.internal.ui.RemoteUIImages; +import org.eclipse.remote.internal.ui.RemoteUIPlugin; import org.eclipse.remote.internal.ui.messages.Messages; -import org.eclipse.remote.ui.IRemoteUIConnectionManager; -import org.eclipse.remote.ui.RemoteUIServices; +import org.eclipse.remote.ui.IRemoteUIConnectionService; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -187,7 +188,7 @@ public class RemoteResourceBrowserWidget extends Composite { private String fResource; private String fInitialPath; private IPath fRootPath; - private IRemoteFileManager fFileMgr; + private IRemoteFileService fFileMgr; private IRemoteConnection fConnection; private final ListenerList fSelectionListeners = new ListenerList(); @@ -222,7 +223,11 @@ public class RemoteResourceBrowserWidget extends Composite { fRemoteConnectionWidget.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { - connectionSelected(); + try { + connectionSelected(); + } catch (CoreException e) { + RemoteUIPlugin.log(e.getStatus()); + } updateEnablement(); notifySelectionChangedListeners(new SelectionChangedEvent(fTreeViewer, new ISelection() { @Override @@ -435,7 +440,7 @@ public class RemoteResourceBrowserWidget extends Composite { setRoot(null); return true; } - IRemoteUIConnectionManager uiMgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()).getUIConnectionManager(); + IRemoteUIConnectionService uiMgr = conn.getConnectionType().getService(IRemoteUIConnectionService.class); if (uiMgr != null) { uiMgr.openConnectionWithProgress(getShell(), getRunnableContext(), conn); } @@ -443,18 +448,21 @@ public class RemoteResourceBrowserWidget extends Composite { return false; } - fFileMgr = conn.getFileManager(); + fFileMgr = conn.getService(IRemoteFileService.class); if (fFileMgr != null) { /* * Note: the call to findInitialPath must happen before the * fTreeViewer input is set or the fTreeViewer fails. No idea why this * is. */ - String cwd = conn.getWorkingDirectory(); - IPath initial = findInitialPath(cwd, fInitialPath); + IRemoteProcessService processService = conn.getService(IRemoteProcessService.class); + if (processService != null) { + String cwd = processService.getWorkingDirectory(); + IPath initial = findInitialPath(cwd, fInitialPath); - // TODO: not platform independent - needs IRemotePath - setRoot(initial.toString()); + // TODO: not platform independent - needs IRemotePath + setRoot(initial.toString()); + } fConnection = conn; return true; @@ -465,8 +473,9 @@ public class RemoteResourceBrowserWidget extends Composite { /** * When a new connection is selected, make sure it is open before using it. + * @throws CoreException */ - private void connectionSelected() { + private void connectionSelected() throws CoreException { /* * Make sure the connection is open before we try and read from the * connection. @@ -492,7 +501,7 @@ public class RemoteResourceBrowserWidget extends Composite { public void run(IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 10); String baseName = "newfolder"; //$NON-NLS-1$ - final IFileStore path = fConnection.getFileManager().getResource(parent); + final IFileStore path = fConnection.getService(IRemoteFileService.class).getResource(parent); IFileStore child = path.getChild(baseName); int count = 1; try { @@ -516,19 +525,19 @@ public class RemoteResourceBrowserWidget extends Composite { public void run() { DelayedInputDialog dialog = new DelayedInputDialog(getShell(), Messages.RemoteResourceBrowserWidget_1, Messages.RemoteResourceBrowserWidget_2, basePath.getName(), new IInputValidator() { - @Override - public String isValid(String newText) { - if (!newText.equals("")) { //$NON-NLS-1$ - IFileStore newPath = path.getChild(newText); - if (newPath.fetchInfo().exists()) { - return Messages.RemoteResourceBrowserWidget_3; - } - } else { - return Messages.RemoteResourceBrowserWidget_4; - } - return null; + @Override + public String isValid(String newText) { + if (!newText.equals("")) { //$NON-NLS-1$ + IFileStore newPath = path.getChild(newText); + if (newPath.fetchInfo().exists()) { + return Messages.RemoteResourceBrowserWidget_3; } - }); + } else { + return Messages.RemoteResourceBrowserWidget_4; + } + return null; + } + }); fValidateJob.setDialog(dialog); if (dialog.open() == Dialog.OK) { userPath[0] = dialog.getValue(); @@ -603,7 +612,7 @@ public class RemoteResourceBrowserWidget extends Composite { public IFileStore getResource() { if (fResource != null) { if (!fResource.equals("") && getConnection() != null) { //$NON-NLS-1$ - return getConnection().getFileManager().getResource(fResource); + return getConnection().getService(IRemoteFileService.class).getResource(fResource); } } return null; @@ -645,8 +654,9 @@ public class RemoteResourceBrowserWidget extends Composite { * Set the connection for the browser * * @param connection + * @throws CoreException */ - public void setConnection(IRemoteConnection connection) { + public void setConnection(IRemoteConnection connection) throws CoreException { changeInput(connection); if (fRemoteConnectionWidget != null) { fRemoteConnectionWidget.setConnection(connection); diff --git a/releng/org.eclipse.remote.build/mars.target b/releng/org.eclipse.remote.build/mars.target new file mode 100644 index 00000000000..3f533456cf9 --- /dev/null +++ b/releng/org.eclipse.remote.build/mars.target @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/tests/org.eclipse.remote.core.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.remote.core.tests/META-INF/MANIFEST.MF index ec82a44cb6a..2e8299e1df1 100644 --- a/tests/org.eclipse.remote.core.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.remote.core.tests/META-INF/MANIFEST.MF @@ -11,3 +11,5 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.remote.core;bundle-version="1.0.0", org.eclipse.remote.ui;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Activator: org.eclipse.remote.core.tests.internal.Activator +Bundle-ActivationPolicy: lazy diff --git a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/internal/Activator.java b/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/internal/Activator.java new file mode 100644 index 00000000000..f2834537b33 --- /dev/null +++ b/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/internal/Activator.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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.tests.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public class Activator implements BundleActivator { + + private static BundleContext bundleContext; + + @Override + public void start(BundleContext context) throws Exception { + bundleContext = context; + } + + @Override + public void stop(BundleContext context) throws Exception { + bundleContext = null; + } + + public static T getService(Class service) { + ServiceReference ref = bundleContext.getServiceReference(service); + return ref != null ? bundleContext.getService(ref) : null; + } + +} diff --git a/tests/org.eclipse.remote.jsch.tests/.classpath b/tests/org.eclipse.remote.jsch.tests/.classpath new file mode 100644 index 00000000000..eca7bdba8f0 --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/org.eclipse.remote.jsch.tests/.gitignore b/tests/org.eclipse.remote.jsch.tests/.gitignore new file mode 100644 index 00000000000..ae3c1726048 --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/tests/org.eclipse.remote.jsch.tests/.project b/tests/org.eclipse.remote.jsch.tests/.project new file mode 100644 index 00000000000..05b96bf0a29 --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.remote.jsch.tests + + + + + + 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/tests/org.eclipse.remote.jsch.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.remote.jsch.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..0c68a61dca8 --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/.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/tests/org.eclipse.remote.jsch.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.remote.jsch.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..e1756cf6b29 --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: JSch Remote Tests +Bundle-SymbolicName: org.eclipse.remote.jsch.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.remote.jsch.tests.Activator +Bundle-Vendor: Eclipse PTP +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.filesystem, + org.eclipse.remote.core, + org.eclipse.remote.jsch.core, + org.junit +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy diff --git a/tests/org.eclipse.remote.jsch.tests/build.properties b/tests/org.eclipse.remote.jsch.tests/build.properties new file mode 100644 index 00000000000..34d2e4d2dad --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/Activator.java b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/Activator.java new file mode 100644 index 00000000000..6198498b999 --- /dev/null +++ b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/Activator.java @@ -0,0 +1,55 @@ +package org.eclipse.remote.jsch.tests; + +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.remote.jsch.tests"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Return the OSGi service with the given service interface. + * + * @param service service interface + * @return the specified service or null if it's not registered + */ + 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/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/ConnectionTests.java similarity index 58% rename from tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java rename to tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/ConnectionTests.java index 8c198d888c7..63d2a749e15 100644 --- a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ConnectionTests.java +++ b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/ConnectionTests.java @@ -1,4 +1,4 @@ -package org.eclipse.remote.core.tests; +package org.eclipse.remote.jsch.tests; import java.io.BufferedReader; import java.io.IOException; @@ -8,29 +8,30 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.core.IRemoteFileManager; +import org.eclipse.remote.core.IRemoteFileService; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcessBuilder; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; -import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.core.IRemoteProcessService; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.jsch.core.JSchConnection; public class ConnectionTests extends TestCase { private static final String USERNAME = "test"; //$NON-NLS-1$ private static final String PASSWORD = ""; //$NON-NLS-1$ private static final String HOST = "localhost"; //$NON-NLS-1$ - private IRemoteServices fRemoteServices; + private IRemoteConnectionType fConnectionType; private IRemoteConnection fRemoteConnection; - private IRemoteConnectionManager fRemoteConnectionManager; public void testEnv() { - String var = fRemoteConnection.getEnv("SHELL"); //$NON-NLS-1$ + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + assertNotNull(processService); + String var = processService.getEnv("SHELL"); //$NON-NLS-1$ assertNotNull(var); - var = fRemoteConnection.getEnv("FOO_VAR_SHOULD_NOT_BE_DEFINED"); //$NON-NLS-1$ + var = processService.getEnv("FOO_VAR_SHOULD_NOT_BE_DEFINED"); //$NON-NLS-1$ assertNull(var); assertNotNull(fRemoteConnection.getProperty("os.name")); //$NON-NLS-1$ @@ -40,7 +41,7 @@ public class ConnectionTests extends TestCase { assertNotNull(fRemoteConnection.getProperty("path.separator")); //$NON-NLS-1$ assertNotNull(fRemoteConnection.getProperty("line.separator")); //$NON-NLS-1$ - IRemoteProcessBuilder builder = fRemoteConnection.getProcessBuilder("env"); //$NON-NLS-1$ + IRemoteProcessBuilder builder = processService.getProcessBuilder("env"); //$NON-NLS-1$ assertNotNull(builder); builder.environment().put("FOO", "BAR"); //$NON-NLS-1$ //$NON-NLS-2$ builder.environment().put("USER", "FOO"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -65,19 +66,21 @@ public class ConnectionTests extends TestCase { } public void testWd() { + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + assertNotNull(processService); /* * Test connection wd */ - String oldWd = fRemoteConnection.getWorkingDirectory(); + String oldWd = processService.getWorkingDirectory(); assertTrue(oldWd.startsWith("/")); String newWd = "/tmp"; - fRemoteConnection.setWorkingDirectory(newWd); - assertTrue(fRemoteConnection.getWorkingDirectory().equals(newWd)); + processService.setWorkingDirectory(newWd); + assertTrue(processService.getWorkingDirectory().equals(newWd)); /* * Test process builder inherits wd from connection */ - IRemoteProcessBuilder builder = fRemoteConnection.getProcessBuilder("pwd"); //$NON-NLS-1$ + IRemoteProcessBuilder builder = processService.getProcessBuilder("pwd"); //$NON-NLS-1$ assertNotNull(builder); try { IRemoteProcess proc = builder.start(); @@ -92,9 +95,9 @@ public class ConnectionTests extends TestCase { /* * Test process builder wd */ - final IRemoteFileManager fileManager = fRemoteConnection.getFileManager(); + final IRemoteFileService fileManager = fRemoteConnection.getService(IRemoteFileService.class); assertNotNull(fileManager); - builder = fRemoteConnection.getProcessBuilder("pwd"); //$NON-NLS-1$ + builder = processService.getProcessBuilder("pwd"); //$NON-NLS-1$ assertNotNull(builder); builder.directory(fileManager.getResource("/bin")); try { @@ -108,46 +111,42 @@ public class ConnectionTests extends TestCase { } } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ @Override protected void setUp() throws Exception { - fRemoteServices = RemoteServices.getRemoteServices("org.eclipse.remote.JSch"); //$NON-NLS-1$ - assertNotNull(fRemoteServices); + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); + fConnectionType = manager.getConnectionType("org.eclipse.remote.JSch"); //$NON-NLS-1$ + assertNotNull(fConnectionType); - fRemoteConnectionManager = fRemoteServices.getConnectionManager(); - assertNotNull(fRemoteConnectionManager); + IRemoteConnectionWorkingCopy wc = fConnectionType.newConnection("test_connection"); //$NON-NLS-1$ - try { - IRemoteConnectionWorkingCopy wc = fRemoteConnectionManager.newConnection("test_connection"); //$NON-NLS-1$ - wc.setAddress(HOST); - wc.setUsername(USERNAME); - wc.setPassword(PASSWORD); - fRemoteConnection = wc.save(); - } catch (RemoteConnectionException e) { - fail(e.getMessage()); + String host = System.getenv("TEST_HOST"); + if (host == null) { + host = HOST; } + wc.setAttribute(JSchConnection.ADDRESS_ATTR, host); - try { - fRemoteConnection.open(new NullProgressMonitor()); - } catch (RemoteConnectionException e) { - fail(e.getMessage()); + String username = System.getenv("TEST_USERNAME"); + if (username == null) { + username = USERNAME; } + wc.setAttribute(JSchConnection.USERNAME_ATTR, username); + + String password = System.getenv("TEST_PASSWORD"); + if (password == null) { + password = PASSWORD; + } + wc.setSecureAttribute(JSchConnection.PASSWORD_ATTR, password); + + fRemoteConnection = wc.save(); + assertNotNull(fRemoteConnection); + + fRemoteConnection.open(new NullProgressMonitor()); assertTrue(fRemoteConnection.isOpen()); } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ @Override protected void tearDown() throws Exception { - fRemoteConnection.close(); - fRemoteConnectionManager.removeConnection(fRemoteConnection); + fConnectionType.removeConnection(fRemoteConnection); } } diff --git a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/FileStoreTests.java similarity index 75% rename from tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java rename to tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/FileStoreTests.java index b8c3be0562f..8c1e3ed2504 100644 --- a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/FileStoreTests.java +++ b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/FileStoreTests.java @@ -1,4 +1,4 @@ -package org.eclipse.remote.core.tests; +package org.eclipse.remote.jsch.tests; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -18,12 +18,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; -import org.eclipse.remote.core.IRemoteFileManager; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; -import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.core.IRemoteFileService; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.jsch.core.JSchConnection; public class FileStoreTests extends TestCase { private static final String CONNECTION_NAME = "test_connection"; @@ -36,10 +35,9 @@ public class FileStoreTests extends TestCase { private static final String REMOTE_FILE = "remote_file"; private static final String TEST_STRING = "a string containing fairly *()(*&^$%## random text"; - private IRemoteServices fRemoteServices; + private IRemoteConnectionType fConnectionType; private IRemoteConnection fRemoteConnection; - private IRemoteConnectionManager fRemoteConnectionManager; - private IRemoteFileManager fRemoteFileManager; + private IRemoteFileService fRemoteFileManager; private IFileStore fRemoteDir; private IFileStore fLocalDir; @@ -146,31 +144,37 @@ public class FileStoreTests extends TestCase { */ @Override protected void setUp() throws Exception { - fRemoteServices = RemoteServices.getRemoteServices("org.eclipse.remote.JSch"); - assertNotNull(fRemoteServices); + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); + fConnectionType = manager.getConnectionType("org.eclipse.remote.JSch"); + assertNotNull(fConnectionType); - fRemoteConnectionManager = fRemoteServices.getConnectionManager(); - assertNotNull(fRemoteConnectionManager); + IRemoteConnectionWorkingCopy wc = fConnectionType.newConnection(CONNECTION_NAME); - try { - IRemoteConnectionWorkingCopy wc = fRemoteConnectionManager.newConnection(CONNECTION_NAME); - wc.setAddress(HOST); - wc.setUsername(USERNAME); - wc.setPassword(PASSWORD); - fRemoteConnection = wc.save(); - assertNotNull(fRemoteConnection); - } catch (RemoteConnectionException e) { - fail(e.getMessage()); + String host = System.getenv("TEST_HOST"); + if (host == null) { + host = HOST; } + wc.setAttribute(JSchConnection.ADDRESS_ATTR, host); - try { - fRemoteConnection.open(new NullProgressMonitor()); - } catch (RemoteConnectionException e) { - fail(e.getMessage()); + String username = System.getenv("TEST_USERNAME"); + if (username == null) { + username = USERNAME; } + wc.setAttribute(JSchConnection.USERNAME_ATTR, username); + + String password = System.getenv("TEST_PASSWORD"); + if (password == null) { + password = PASSWORD; + } + wc.setSecureAttribute(JSchConnection.PASSWORD_ATTR, password); + + fRemoteConnection = wc.save(); + assertNotNull(fRemoteConnection); + + fRemoteConnection.open(new NullProgressMonitor()); assertTrue(fRemoteConnection.isOpen()); - fRemoteFileManager = fRemoteConnection.getFileManager(); + fRemoteFileManager = fRemoteConnection.getService(IRemoteFileService.class); assertNotNull(fRemoteFileManager); URI remoteDirUri = fRemoteFileManager.toURI(REMOTE_DIR); @@ -178,19 +182,11 @@ public class FileStoreTests extends TestCase { assertNotNull(remoteDirUri); assertNotNull(localDirUri); - try { - fRemoteDir = EFS.getStore(fRemoteFileManager.toURI(REMOTE_DIR)); - fLocalDir = EFS.getLocalFileSystem().getStore(new Path(LOCAL_DIR)); - } catch (CoreException e) { - fail(e.getMessage()); - } + fRemoteDir = EFS.getStore(fRemoteFileManager.toURI(REMOTE_DIR)); + fLocalDir = EFS.getLocalFileSystem().getStore(new Path(LOCAL_DIR)); - try { - fRemoteDir.mkdir(EFS.NONE, null); - fLocalDir.mkdir(EFS.NONE, null); - } catch (CoreException e) { - fail(e.getMessage()); - } + fRemoteDir.mkdir(EFS.NONE, null); + fLocalDir.mkdir(EFS.NONE, null); } /* @@ -202,8 +198,7 @@ public class FileStoreTests extends TestCase { protected void tearDown() throws Exception { fRemoteDir.delete(EFS.NONE, new NullProgressMonitor()); fLocalDir.delete(EFS.NONE, new NullProgressMonitor()); - fRemoteConnection.close(); - fRemoteConnectionManager.removeConnection(fRemoteConnection); + fConnectionType.removeConnection(fRemoteConnection); } } diff --git a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/ProcessTests.java similarity index 69% rename from tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java rename to tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/ProcessTests.java index fbab4de5563..001c8993529 100644 --- a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/ProcessTests.java +++ b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/ProcessTests.java @@ -1,4 +1,4 @@ -package org.eclipse.remote.core.tests; +package org.eclipse.remote.jsch.tests; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -13,13 +13,13 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionManager; +import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteProcess; import org.eclipse.remote.core.IRemoteProcessBuilder; -import org.eclipse.remote.core.IRemoteServices; -import org.eclipse.remote.core.RemoteServices; -import org.eclipse.remote.core.exception.RemoteConnectionException; +import org.eclipse.remote.core.IRemoteProcessService; +import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.remote.internal.jsch.core.JSchConnection; public class ProcessTests extends TestCase { private static final String USERNAME = "test"; //$NON-NLS-1$ @@ -27,7 +27,7 @@ public class ProcessTests extends TestCase { private static final String HOST = "localhost"; //$NON-NLS-1$ private static int NUM_THREADS = 1; // Test currently fails for more than one thread - private IRemoteServices fRemoteServices; + private IRemoteConnectionType fConnectionType; private IRemoteConnection fRemoteConnection; public void testConcurrentProcess() { @@ -39,7 +39,9 @@ public class ProcessTests extends TestCase { @Override public void run() { final Set results = Collections.synchronizedSet(new HashSet()); - IRemoteProcessBuilder builder = fRemoteConnection.getProcessBuilder("perl", "-v", threadNum); //$NON-NLS-1$ + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + assertNotNull(processService); + IRemoteProcessBuilder builder = processService.getProcessBuilder("perl", "-v", threadNum); //$NON-NLS-1$ assertNotNull(builder); builder.redirectErrorStream(true); for (int i = 0; i < 10; i++) { @@ -77,7 +79,9 @@ public class ProcessTests extends TestCase { } public void testEnv() { - IRemoteProcessBuilder builder = fRemoteConnection.getProcessBuilder("printenv"); //$NON-NLS-1$ + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + assertNotNull(processService); + IRemoteProcessBuilder builder = processService.getProcessBuilder("printenv"); //$NON-NLS-1$ assertNotNull(builder); builder.redirectErrorStream(true); String path = builder.environment().get("PATH"); @@ -89,7 +93,7 @@ public class ProcessTests extends TestCase { String line; String result = null; while ((line = stdout.readLine()) != null) { - assertTrue(result == null); + assertNull(result); result = line; } assertEquals(result, "PATH=" + path); @@ -100,7 +104,9 @@ public class ProcessTests extends TestCase { } public void testEcho() { - IRemoteProcessBuilder builder = fRemoteConnection.getProcessBuilder("cat"); //$NON-NLS-1$ + IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class); + assertNotNull(processService); + IRemoteProcessBuilder builder = processService.getProcessBuilder("cat"); //$NON-NLS-1$ assertNotNull(builder); builder.redirectErrorStream(true); final StringBuffer result = new StringBuffer(); @@ -165,49 +171,42 @@ public class ProcessTests extends TestCase { assertEquals("0123456789", result.toString()); } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ @Override protected void setUp() throws Exception { - fRemoteServices = RemoteServices.getRemoteServices("org.eclipse.remote.JSch"); //$NON-NLS-1$ - assertNotNull(fRemoteServices); + IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class); + fConnectionType = manager.getConnectionType("org.eclipse.remote.JSch"); //$NON-NLS-1$ + assertNotNull(fConnectionType); - IRemoteConnectionManager connMgr = fRemoteServices.getConnectionManager(); - assertNotNull(connMgr); + IRemoteConnectionWorkingCopy wc = fConnectionType.newConnection("test_connection"); //$NON-NLS-1$ - try { - IRemoteConnectionWorkingCopy wc = connMgr.newConnection("test_connection"); //$NON-NLS-1$ - wc.setAddress(HOST); - wc.setUsername(USERNAME); - wc.setPassword(PASSWORD); - fRemoteConnection = wc.save(); - assertNotNull(fRemoteConnection); - } catch (RemoteConnectionException e) { - fail(e.getLocalizedMessage()); + String host = System.getenv("TEST_HOST"); + if (host == null) { + host = HOST; } + wc.setAttribute(JSchConnection.ADDRESS_ATTR, host); - try { - fRemoteConnection.open(new NullProgressMonitor()); - } catch (RemoteConnectionException e) { - fail(e.getLocalizedMessage()); + String username = System.getenv("TEST_USERNAME"); + if (username == null) { + username = USERNAME; } + wc.setAttribute(JSchConnection.USERNAME_ATTR, username); + + String password = System.getenv("TEST_PASSWORD"); + if (password == null) { + password = PASSWORD; + } + wc.setSecureAttribute(JSchConnection.PASSWORD_ATTR, password); + + fRemoteConnection = wc.save(); + assertNotNull(fRemoteConnection); + + fRemoteConnection.open(new NullProgressMonitor()); assertTrue(fRemoteConnection.isOpen()); } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ @Override protected void tearDown() throws Exception { - fRemoteConnection.close(); - IRemoteConnectionManager connMgr = fRemoteServices.getConnectionManager(); - assertNotNull(connMgr); - connMgr.removeConnection(fRemoteConnection); + fConnectionType.removeConnection(fRemoteConnection); } } diff --git a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/RemoteCoreTestSuite.java similarity index 63% rename from tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java rename to tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/RemoteCoreTestSuite.java index bcf45503f82..e1b4f17bd14 100644 --- a/tests/org.eclipse.remote.core.tests/src/org/eclipse/remote/core/tests/suite/RemoteCoreTestSuite.java +++ b/tests/org.eclipse.remote.jsch.tests/src/org/eclipse/remote/jsch/tests/RemoteCoreTestSuite.java @@ -1,12 +1,8 @@ -package org.eclipse.remote.core.tests.suite; +package org.eclipse.remote.jsch.tests; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.remote.core.tests.ConnectionTests; -import org.eclipse.remote.core.tests.FileStoreTests; -import org.eclipse.remote.core.tests.ProcessTests; - public class RemoteCoreTestSuite { public static Test suite() { TestSuite suite = new TestSuite(RemoteCoreTestSuite.class.getName());