diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionHostService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionHostService.java
new file mode 100644
index 00000000000..949c8efe070
--- /dev/null
+++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnectionHostService.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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;
+
+/**
+ * A service to obtain host specific information.
+ *
+ * @since 2.0
+ */
+public interface IRemoteConnectionHostService extends IRemoteConnection.Service {
+
+ /**
+ * Obtain the hostname associated with this connection.
+ *
+ * @return
+ */
+ String getHostname();
+
+ /**
+ * Obtain the username associated with this connection.
+ *
+ * @return
+ */
+ String getUsername();
+
+ /**
+ * Obtain the port associated with this connection
+ *
+ * @return
+ */
+ int getPort();
+}
diff --git a/bundles/org.eclipse.remote.jsch.core/plugin.xml b/bundles/org.eclipse.remote.jsch.core/plugin.xml
index 0a85f2ed12c..b772a0400d1 100644
--- a/bundles/org.eclipse.remote.jsch.core/plugin.xml
+++ b/bundles/org.eclipse.remote.jsch.core/plugin.xml
@@ -34,6 +34,11 @@
factory="org.eclipse.remote.internal.jsch.core.JSchFileManager$Factory"
service="org.eclipse.remote.core.IRemoteFileService">
+
+
T getService(IRemoteConnection connection, Class service) {
@@ -236,9 +286,8 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
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)) {
+ || IRemoteConnectionPropertyService.class.equals(service) || IRemotePortForwardingService.class.equals(service)
+ || IRemoteProcessService.class.equals(service) || IRemoteConnectionHostService.class.equals(service)) {
return (T) connection.getService(JSchConnection.class);
} else {
return null;
@@ -287,6 +336,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionControlService#close()
+ */
@Override
public synchronized void close() {
if (fSftpChannel != null) {
@@ -320,6 +374,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return exec.setCommand(cmd).getResult(monitor).trim();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemotePortForwardingService#forwardLocalPort(int, java.lang.String, int)
+ */
@Override
public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException {
if (!isOpen()) {
@@ -332,6 +391,12 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemotePortForwardingService#forwardLocalPort(java.lang.String, int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
@Override
public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException {
if (!isOpen()) {
@@ -362,6 +427,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return -1;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemotePortForwardingService#forwardRemotePort(int, java.lang.String, int)
+ */
@Override
public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException {
if (!isOpen()) {
@@ -374,6 +444,12 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemotePortForwardingService#forwardRemotePort(java.lang.String, int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
@Override
public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException {
if (!isOpen()) {
@@ -403,7 +479,13 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return -1;
}
- public String getAddress() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionHostService#getHostname()
+ */
+ @Override
+ public String getHostname() {
return fRemoteConnection.getAttribute(ADDRESS_ATTR);
}
@@ -422,11 +504,21 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return null;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessService#getEnv()
+ */
@Override
public Map getEnv() {
return Collections.unmodifiableMap(fEnv);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessService#getEnv(java.lang.String)
+ */
@Override
public String getEnv(String name) {
return getEnv().get(name);
@@ -456,21 +548,42 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return fRemoteConnection.getSecureAttribute(PASSWORD_ATTR);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionHostService#getPort()
+ */
+ @Override
public int getPort() {
String portStr = fRemoteConnection.getAttribute(PORT_ATTR);
return portStr != null ? Integer.parseInt(portStr) : DEFAULT_PORT;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessService#getProcessBuilder(java.util.List)
+ */
@Override
public IRemoteProcessBuilder getProcessBuilder(List command) {
return new JSchProcessBuilder(this, command);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessService#getProcessBuilder(java.lang.String[])
+ */
@Override
public IRemoteProcessBuilder getProcessBuilder(String... command) {
return new JSchProcessBuilder(this, command);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionPropertyService#getProperty(java.lang.String)
+ */
@Override
public String getProperty(String key) {
return fProperties.get(key);
@@ -528,8 +641,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return fSftpChannel;
}
- public Channel getStreamForwarder(String host, int port) throws RemoteConnectionException
- {
+ public Channel getStreamForwarder(String host, int port) throws RemoteConnectionException {
try {
Channel channel = fSessions.get(0).getStreamForwarder(host, port);
channel.connect();
@@ -544,10 +656,21 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return str != null ? Integer.parseInt(str) : DEFAULT_TIMEOUT;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionHostService#getUsername()
+ */
+ @Override
public String getUsername() {
return fRemoteConnection.getAttribute(USERNAME_ATTR);
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessService#getWorkingDirectory()
+ */
@Override
public String getWorkingDirectory() {
if (!isOpen()) {
@@ -577,6 +700,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
return hasOpenSession;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionControlService#isOpen()
+ */
@Override
public boolean isOpen() {
return hasOpenSession() && isFullySetup;
@@ -696,7 +824,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
private Session newSession(IProgressMonitor monitor) throws RemoteConnectionException {
SubMonitor progress = SubMonitor.convert(monitor, 10);
try {
- Session session = fJSchService.createSession(getAddress(), getPort(), getUsername());
+ Session session = fJSchService.createSession(getHostname(), getPort(), getUsername());
session.setUserInfo(new JSchUserInfo());
if (isPasswordAuth()) {
session.setConfig("PreferredAuthentications", "password,keyboard-interactive,gssapi-with-mic,publickey"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -708,8 +836,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10)); // connect without proxy
} else {
if (getProxyCommand().isEmpty()) {
- session.setProxy(JSchConnectionProxyFactory.createForwardProxy(getProxyConnection(),
- progress.newChild(10)));
+ session.setProxy(JSchConnectionProxyFactory.createForwardProxy(getProxyConnection(), progress.newChild(10)));
fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10));
} else {
session.setProxy(JSchConnectionProxyFactory.createCommandProxy(getProxyConnection(), getProxyCommand(),
@@ -727,6 +854,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteConnectionControlService#open(org.eclipse.core.runtime.IProgressMonitor)
+ */
@Override
public void open(IProgressMonitor monitor) throws RemoteConnectionException {
open(monitor, true);
@@ -753,7 +885,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
* @throws RemoteConnectionException
*/
private void open(IProgressMonitor monitor, boolean setupFully) throws RemoteConnectionException {
- SubMonitor subMon = SubMonitor.convert(monitor, 60);
+ SubMonitor subMon = SubMonitor.convert(monitor, 60);
if (!hasOpenSession()) {
checkIsConfigured();
newSession(subMon.newChild(10));
@@ -785,6 +917,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemotePortForwardingService#removeLocalPortForwarding(int)
+ */
@Override
public void removeLocalPortForwarding(int port) throws RemoteConnectionException {
if (!isOpen()) {
@@ -797,6 +934,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemotePortForwardingService#removeRemotePortForwarding(int)
+ */
@Override
public void removeRemotePortForwarding(int port) throws RemoteConnectionException {
if (!isOpen()) {
@@ -809,6 +951,11 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessService#setWorkingDirectory(java.lang.String)
+ */
@Override
public void setWorkingDirectory(String path) {
if (new Path(path).isAbsolute()) {