1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 02:15:31 +02:00

Bug 463468 - provide set methods for host services

Change-Id: I68d4e7bb1cdcc81d9584d8055b0460d7c4cad5c2
Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2015-03-30 16:37:39 -04:00
parent 91596fb8d7
commit 82f4d12873
3 changed files with 238 additions and 4 deletions

View file

@ -20,10 +20,31 @@ public interface IRemoteConnectionHostService extends IRemoteConnection.Service
/**
* Obtain the hostname associated with this connection.
*
* @return
* @return hostname
*/
String getHostname();
/**
* Obtain the port associated with this connection
*
* @return port
*/
int getPort();
/**
* Obtain the timeout used when establishing the connection.
*
* @return timeout
*/
int getTimeout();
/**
* Obtain the flag that indicates a login shell should be started once the connection is established
*
* @return login shell flag
*/
boolean useLoginShell();
/**
* Obtain the username associated with this connection.
*
@ -32,9 +53,73 @@ public interface IRemoteConnectionHostService extends IRemoteConnection.Service
String getUsername();
/**
* Obtain the port associated with this connection
* Set the hostname associated with this connection. Note, this method can only be used for an
* IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @return
* @param hostname
* new hostname for connection
*/
int getPort();
void setHostname(String hostname);
/**
* Set the pass phrase associated with this connection. Note, this method can only be used for an
* IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param passphrase
*/
void setPassphrase(String passphrase);
/**
* Set the password associated with this connection. Note, this method can only be used for an
* IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param password
* new password for connection
*/
void setPassword(String password);
/**
* Set the port used for the connection. Note, this method can only be used forh an
* IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param port
* new port for connection
*/
void setPort(int port);
/**
* Set the timeout used when establishing the connection. A timeout of 0 means infinite. Note, this method can only be used
* for an IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param timeout
* new timeout value
*/
void setTimeout(int timeout);
/**
* Set the flag indicating a login shell should be stated for this connection. Note, this method can only be used
* for an IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param useLogingShell
* true to start a login shell
*/
void setUseLoginShell(boolean useLogingShell);
/**
* Set the connection to try password authentication first. Note, this method can only be used for an
* IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param usePassword
* use password authentication
*/
void setUsePassword(boolean usePassword);
/**
* Set the username associated with this connection. Note, this method can only be used for an
* IRemoteConnectionWorkingCopy and will have no effect otherwise.
*
* @param username
* new username for connection
*/
void setUsername(String username);
}

View file

@ -652,6 +652,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
@Override
public int getTimeout() {
String str = fRemoteConnection.getAttribute(TIMEOUT_ATTR);
return !str.isEmpty() ? Integer.parseInt(str) : DEFAULT_TIMEOUT;
@ -967,9 +968,74 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
}
}
@Override
public boolean useLoginShell() {
String str = fRemoteConnection.getAttribute(USE_LOGIN_SHELL_ATTR);
return !str.isEmpty() ? Boolean.parseBoolean(str) : DEFAULT_USE_LOGIN_SHELL;
}
@Override
public void setHostname(String hostname) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setAttribute(ADDRESS_ATTR, hostname);
}
}
@Override
public void setPassphrase(String passphrase) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setSecureAttribute(PASSPHRASE_ATTR, passphrase);
}
}
@Override
public void setPassword(String password) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setSecureAttribute(PASSWORD_ATTR, password);
}
}
@Override
public void setPort(int port) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setAttribute(PORT_ATTR, Integer.toString(port));
}
}
@Override
public void setTimeout(int timeout) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setAttribute(TIMEOUT_ATTR, Integer.toString(timeout));
}
}
@Override
public void setUseLoginShell(boolean useLogingShell) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setAttribute(USE_LOGIN_SHELL_ATTR, Boolean.toString(useLogingShell));
}
}
@Override
public void setUsePassword(boolean usePassword) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setAttribute(IS_PASSWORD_ATTR, Boolean.toString(usePassword));
}
}
@Override
public void setUsername(String username) {
if (fRemoteConnection instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) fRemoteConnection;
wc.setAttribute(USERNAME_ATTR, username);
}
}
}

View file

@ -0,0 +1,83 @@
package org.eclipse.remote.core.tests.internal;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionHostService;
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 junit.framework.TestCase;
public class ServiceTests extends TestCase {
private static final String USERNAME = "greg"; //$NON-NLS-1$
private static final String PASSWORD = ""; //$NON-NLS-1$
private static final String HOST = "localhost"; //$NON-NLS-1$
private IRemoteConnectionType fConnectionType;
private IRemoteConnection fRemoteConnection;
public void testHostService() {
IRemoteConnectionWorkingCopy wc = null;
try {
wc = fConnectionType.newConnection("test_connection");//$NON-NLS-1$
} catch (RemoteConnectionException e) {
fail(e.getLocalizedMessage());
}
IRemoteConnectionHostService hostService = wc.getService(IRemoteConnectionHostService.class);
assertNotNull(hostService);
String host = System.getenv("TEST_HOST");
if (host == null) {
host = HOST;
}
hostService.setHostname(host);
String username = System.getenv("TEST_USERNAME");
if (username == null) {
username = USERNAME;
}
hostService.setUsername(username);
String password = System.getenv("TEST_PASSWORD");
if (password == null) {
password = PASSWORD;
}
hostService.setPassword(password);
try {
fRemoteConnection = wc.save();
} catch (RemoteConnectionException e) {
fail(e.getLocalizedMessage());
}
assertNotNull(fRemoteConnection);
try {
fRemoteConnection.open(new NullProgressMonitor());
} catch (RemoteConnectionException e) {
fail(e.getLocalizedMessage());
}
assertTrue(fRemoteConnection.isOpen());
hostService = fRemoteConnection.getService(IRemoteConnectionHostService.class);
assertNotNull(hostService);
assertEquals(hostService.getHostname(), host);
assertEquals(hostService.getUsername(), username);
}
@Override
protected void setUp() throws Exception {
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
fConnectionType = manager.getConnectionType("org.eclipse.remote.JSch"); //$NON-NLS-1$
assertNotNull(fConnectionType);
}
@Override
protected void tearDown() throws Exception {
fConnectionType.removeConnection(fRemoteConnection);
}
}