1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

Enable connection timeout and connection cancelled message.

Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2013-12-18 08:46:21 -05:00
parent 4d53ce0c98
commit 290378c74a
3 changed files with 54 additions and 10 deletions

View file

@ -62,6 +62,7 @@ public class JSchConnection implements IRemoteConnection {
fAuthenticator = authenticator; fAuthenticator = authenticator;
} }
@Override
public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt,
boolean[] echo) { boolean[] echo) {
if (logging) { if (logging) {
@ -79,6 +80,7 @@ public class JSchConnection implements IRemoteConnection {
return new String[] { password }; return new String[] { password };
} }
@Override
public String getPassphrase() { public String getPassphrase() {
if (logging) { if (logging) {
System.out.println("getPassphrase"); //$NON-NLS-1$ System.out.println("getPassphrase"); //$NON-NLS-1$
@ -86,6 +88,7 @@ public class JSchConnection implements IRemoteConnection {
return JSchConnection.this.getPassphrase(); return JSchConnection.this.getPassphrase();
} }
@Override
public String getPassword() { public String getPassword() {
if (logging) { if (logging) {
System.out.println("getPassword"); //$NON-NLS-1$ System.out.println("getPassword"); //$NON-NLS-1$
@ -93,6 +96,7 @@ public class JSchConnection implements IRemoteConnection {
return JSchConnection.this.getPassword(); return JSchConnection.this.getPassword();
} }
@Override
public boolean promptPassword(String message) { public boolean promptPassword(String message) {
if (logging) { if (logging) {
System.out.println("promptPassword:" + message); //$NON-NLS-1$ System.out.println("promptPassword:" + message); //$NON-NLS-1$
@ -112,6 +116,7 @@ public class JSchConnection implements IRemoteConnection {
return true; return true;
} }
@Override
public boolean promptPassphrase(String message) { public boolean promptPassphrase(String message) {
if (logging) { if (logging) {
System.out.println("promptPassphrase:" + message); //$NON-NLS-1$ System.out.println("promptPassphrase:" + message); //$NON-NLS-1$
@ -130,6 +135,7 @@ public class JSchConnection implements IRemoteConnection {
return true; return true;
} }
@Override
public boolean promptYesNo(String message) { public boolean promptYesNo(String message) {
if (logging) { if (logging) {
System.out.println("promptYesNo:" + message); //$NON-NLS-1$ System.out.println("promptYesNo:" + message); //$NON-NLS-1$
@ -142,6 +148,7 @@ public class JSchConnection implements IRemoteConnection {
return true; return true;
} }
@Override
public void showMessage(String message) { public void showMessage(String message) {
if (logging) { if (logging) {
System.out.println("showMessage:" + message); //$NON-NLS-1$ System.out.println("showMessage:" + message); //$NON-NLS-1$
@ -187,6 +194,7 @@ public class JSchConnection implements IRemoteConnection {
* @see org.eclipse.remote.core.IRemoteConnection#addConnectionChangeListener * @see org.eclipse.remote.core.IRemoteConnection#addConnectionChangeListener
* (org.eclipse.remote.core.IRemoteConnectionChangeListener) * (org.eclipse.remote.core.IRemoteConnectionChangeListener)
*/ */
@Override
public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) { public void addConnectionChangeListener(IRemoteConnectionChangeListener listener) {
fListeners.add(listener); fListeners.add(listener);
} }
@ -237,6 +245,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#close() * @see org.eclipse.remote.core.IRemoteConnection#close()
*/ */
@Override
public synchronized void close() { public synchronized void close() {
if (fSftpChannel != null) { if (fSftpChannel != null) {
if (fSftpChannel.isConnected()) { if (fSftpChannel.isConnected()) {
@ -259,6 +268,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see java.lang.Comparable#compareTo(java.lang.Object) * @see java.lang.Comparable#compareTo(java.lang.Object)
*/ */
@Override
public int compareTo(IRemoteConnection o) { public int compareTo(IRemoteConnection o) {
return getName().compareTo(o.getName()); return getName().compareTo(o.getName());
} }
@ -268,13 +278,16 @@ public class JSchConnection implements IRemoteConnection {
* *
* @param event * @param event
*/ */
@Override
public void fireConnectionChangeEvent(final int type) { public void fireConnectionChangeEvent(final int type) {
final IRemoteConnection connection = this; final IRemoteConnection connection = this;
IRemoteConnectionChangeEvent event = new IRemoteConnectionChangeEvent() { IRemoteConnectionChangeEvent event = new IRemoteConnectionChangeEvent() {
@Override
public IRemoteConnection getConnection() { public IRemoteConnection getConnection() {
return connection; return connection;
} }
@Override
public int getType() { public int getType() {
return type; return type;
} }
@ -289,6 +302,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(int, java.lang.String, int) * @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(int, java.lang.String, int)
*/ */
@Override
public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException { public void forwardLocalPort(int localPort, String fwdAddress, int fwdPort) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen); throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen);
@ -306,6 +320,7 @@ public class JSchConnection implements IRemoteConnection {
* @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(java.lang .String, int, * @see org.eclipse.remote.core.IRemoteConnection#forwardLocalPort(java.lang .String, int,
* org.eclipse.core.runtime.IProgressMonitor) * org.eclipse.core.runtime.IProgressMonitor)
*/ */
@Override
public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException { public int forwardLocalPort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen); throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen);
@ -340,6 +355,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(int, java.lang.String, int) * @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(int, java.lang.String, int)
*/ */
@Override
public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException { public void forwardRemotePort(int remotePort, String fwdAddress, int fwdPort) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen); throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen);
@ -357,6 +373,7 @@ public class JSchConnection implements IRemoteConnection {
* @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(java. lang.String, int, * @see org.eclipse.remote.core.IRemoteConnection#forwardRemotePort(java. lang.String, int,
* org.eclipse.core.runtime.IProgressMonitor) * org.eclipse.core.runtime.IProgressMonitor)
*/ */
@Override
public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException { public int forwardRemotePort(String fwdAddress, int fwdPort, IProgressMonitor monitor) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen); throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen);
@ -390,6 +407,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getAddress() * @see org.eclipse.remote.core.IRemoteConnection#getAddress()
*/ */
@Override
public String getAddress() { public String getAddress() {
return fAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, EMPTY_STRING); return fAttributes.getAttribute(JSchConnectionAttributes.ADDRESS_ATTR, EMPTY_STRING);
} }
@ -399,6 +417,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getAttributes() * @see org.eclipse.remote.core.IRemoteConnection#getAttributes()
*/ */
@Override
public Map<String, String> getAttributes() { public Map<String, String> getAttributes() {
return Collections.unmodifiableMap(fAttributes.getAttributes()); return Collections.unmodifiableMap(fAttributes.getAttributes());
} }
@ -408,6 +427,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteServices#getCommandShell(int) * @see org.eclipse.remote.core.IRemoteServices#getCommandShell(int)
*/ */
@Override
public IRemoteProcess getCommandShell(int flags) throws IOException { public IRemoteProcess getCommandShell(int flags) throws IOException {
throw new IOException("Not currently implemented"); //$NON-NLS-1$ throw new IOException("Not currently implemented"); //$NON-NLS-1$
} }
@ -433,6 +453,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getEnv() * @see org.eclipse.remote.core.IRemoteConnection#getEnv()
*/ */
@Override
public Map<String, String> getEnv() { public Map<String, String> getEnv() {
return Collections.unmodifiableMap(fEnv); return Collections.unmodifiableMap(fEnv);
} }
@ -442,6 +463,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getEnv(java.lang.String) * @see org.eclipse.remote.core.IRemoteConnection#getEnv(java.lang.String)
*/ */
@Override
public String getEnv(String name) { public String getEnv(String name) {
return getEnv().get(name); return getEnv().get(name);
} }
@ -467,6 +489,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteServices#getFileManager() * @see org.eclipse.remote.core.IRemoteServices#getFileManager()
*/ */
@Override
public IRemoteFileManager getFileManager() { public IRemoteFileManager getFileManager() {
return new JSchFileManager(this); return new JSchFileManager(this);
} }
@ -488,6 +511,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getName() * @see org.eclipse.remote.core.IRemoteConnection#getName()
*/ */
@Override
public String getName() { public String getName() {
return fAttributes.getName(); return fAttributes.getName();
} }
@ -505,6 +529,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getPort() * @see org.eclipse.remote.core.IRemoteConnection#getPort()
*/ */
@Override
public int getPort() { public int getPort() {
return fAttributes.getInt(JSchConnectionAttributes.PORT_ATTR, DEFAULT_PORT); return fAttributes.getInt(JSchConnectionAttributes.PORT_ATTR, DEFAULT_PORT);
} }
@ -514,6 +539,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.util.List) * @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.util.List)
*/ */
@Override
public IRemoteProcessBuilder getProcessBuilder(List<String> command) { public IRemoteProcessBuilder getProcessBuilder(List<String> command) {
return new JSchProcessBuilder(this, command); return new JSchProcessBuilder(this, command);
} }
@ -523,6 +549,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.lang.String[]) * @see org.eclipse.remote.core.IRemoteServices#getProcessBuilder(java.lang.String[])
*/ */
@Override
public IRemoteProcessBuilder getProcessBuilder(String... command) { public IRemoteProcessBuilder getProcessBuilder(String... command) {
return new JSchProcessBuilder(this, command); return new JSchProcessBuilder(this, command);
} }
@ -532,6 +559,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getProperty(java.lang.String ) * @see org.eclipse.remote.core.IRemoteConnection#getProperty(java.lang.String )
*/ */
@Override
public String getProperty(String key) { public String getProperty(String key) {
return fProperties.get(key); return fProperties.get(key);
} }
@ -541,6 +569,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getRemoteServices() * @see org.eclipse.remote.core.IRemoteConnection#getRemoteServices()
*/ */
@Override
public IRemoteServices getRemoteServices() { public IRemoteServices getRemoteServices() {
return fRemoteServices; return fRemoteServices;
} }
@ -575,6 +604,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getUsername() * @see org.eclipse.remote.core.IRemoteConnection#getUsername()
*/ */
@Override
public String getUsername() { public String getUsername() {
return fAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, EMPTY_STRING); return fAttributes.getAttribute(JSchConnectionAttributes.USERNAME_ATTR, EMPTY_STRING);
} }
@ -584,6 +614,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy() * @see org.eclipse.remote.core.IRemoteConnection#getWorkingCopy()
*/ */
@Override
public IRemoteConnectionWorkingCopy getWorkingCopy() { public IRemoteConnectionWorkingCopy getWorkingCopy() {
return new JSchConnectionWorkingCopy(this); return new JSchConnectionWorkingCopy(this);
} }
@ -593,6 +624,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#getWorkingDirectory() * @see org.eclipse.remote.core.IRemoteConnection#getWorkingDirectory()
*/ */
@Override
public String getWorkingDirectory() { public String getWorkingDirectory() {
if (!isOpen()) { if (!isOpen()) {
return "/"; //$NON-NLS-1$ return "/"; //$NON-NLS-1$
@ -608,6 +640,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#isOpen() * @see org.eclipse.remote.core.IRemoteConnection#isOpen()
*/ */
@Override
public boolean isOpen() { public boolean isOpen() {
boolean isOpen = fIsOpen & fSessions.size() > 0; boolean isOpen = fIsOpen & fSessions.size() > 0;
if (isOpen) { if (isOpen) {
@ -744,7 +777,7 @@ public class JSchConnection implements IRemoteConnection {
if (isPasswordAuth()) { if (isPasswordAuth()) {
session.setPassword(getPassword()); session.setPassword(getPassword());
} }
fJSchService.connect(session, 0, progress.newChild(10)); fJSchService.connect(session, getTimeout() * 1000, progress.newChild(10));
if (!progress.isCanceled()) { if (!progress.isCanceled()) {
fSessions.add(session); fSessions.add(session);
return session; return session;
@ -760,6 +793,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#open() * @see org.eclipse.remote.core.IRemoteConnection#open()
*/ */
@Override
public void open(IProgressMonitor monitor) throws RemoteConnectionException { public void open(IProgressMonitor monitor) throws RemoteConnectionException {
open(null, monitor); open(null, monitor);
} }
@ -770,12 +804,15 @@ public class JSchConnection implements IRemoteConnection {
* @see org.eclipse.remote.core.IRemoteConnection#open(org.eclipse.remote.core.IUserAuthenticator, * @see org.eclipse.remote.core.IRemoteConnection#open(org.eclipse.remote.core.IUserAuthenticator,
* org.eclipse.core.runtime.IProgressMonitor) * org.eclipse.core.runtime.IProgressMonitor)
*/ */
@Override
public void open(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException { public void open(final IUserAuthenticator authenticator, IProgressMonitor monitor) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
checkIsConfigured(); checkIsConfigured();
SubMonitor subMon = SubMonitor.convert(monitor, 70); SubMonitor subMon = SubMonitor.convert(monitor, 70);
Session session = newSession(authenticator, subMon.newChild(10)); Session session = newSession(authenticator, subMon.newChild(10));
if (!subMon.isCanceled()) { if (subMon.isCanceled()) {
throw new RemoteConnectionException(Messages.JSchConnection_Connection_was_cancelled);
}
if (!checkConfiguration(session, subMon.newChild(20))) { if (!checkConfiguration(session, subMon.newChild(20))) {
newSession(authenticator, subMon.newChild(10)); newSession(authenticator, subMon.newChild(10));
loadEnv(subMon.newChild(10)); loadEnv(subMon.newChild(10));
@ -786,7 +823,6 @@ public class JSchConnection implements IRemoteConnection {
fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED); fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED);
} }
} }
}
private ChannelSftp openSftpChannel(Session session) throws RemoteConnectionException { private ChannelSftp openSftpChannel(Session session) throws RemoteConnectionException {
try { try {
@ -804,6 +840,7 @@ public class JSchConnection implements IRemoteConnection {
* @see org.eclipse.remote.core.IRemoteConnection#removeConnectionChangeListener * @see org.eclipse.remote.core.IRemoteConnection#removeConnectionChangeListener
* (org.eclipse.remote.core.IRemoteConnectionChangeListener) * (org.eclipse.remote.core.IRemoteConnectionChangeListener)
*/ */
@Override
public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) { public void removeConnectionChangeListener(IRemoteConnectionChangeListener listener) {
fListeners.remove(listener); fListeners.remove(listener);
} }
@ -813,6 +850,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#removeLocalPortForwarding(int) * @see org.eclipse.remote.core.IRemoteConnection#removeLocalPortForwarding(int)
*/ */
@Override
public void removeLocalPortForwarding(int port) throws RemoteConnectionException { public void removeLocalPortForwarding(int port) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen); throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen);
@ -829,6 +867,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#removeRemotePortForwarding(int) * @see org.eclipse.remote.core.IRemoteConnection#removeRemotePortForwarding(int)
*/ */
@Override
public void removeRemotePortForwarding(int port) throws RemoteConnectionException { public void removeRemotePortForwarding(int port) throws RemoteConnectionException {
if (!isOpen()) { if (!isOpen()) {
throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen); throw new RemoteConnectionException(Messages.JSchConnection_connectionNotOpen);
@ -845,6 +884,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#setWorkingDirectory(java.lang.String) * @see org.eclipse.remote.core.IRemoteConnection#setWorkingDirectory(java.lang.String)
*/ */
@Override
public void setWorkingDirectory(String path) { public void setWorkingDirectory(String path) {
if (new Path(path).isAbsolute()) { if (new Path(path).isAbsolute()) {
fWorkingDir = path; fWorkingDir = path;
@ -856,6 +896,7 @@ public class JSchConnection implements IRemoteConnection {
* *
* @see org.eclipse.remote.core.IRemoteConnection#supportsTCPPortForwarding() * @see org.eclipse.remote.core.IRemoteConnection#supportsTCPPortForwarding()
*/ */
@Override
public boolean supportsTCPPortForwarding() { public boolean supportsTCPPortForwarding() {
return true; return true;
} }

View file

@ -25,6 +25,8 @@ public class Messages extends NLS {
public static String ExecCommand_Exec_command; public static String ExecCommand_Exec_command;
public static String FetchInfoCommand_Fetch_info; public static String FetchInfoCommand_Fetch_info;
public static String GetInputStreamCommand_Get_input_stream; public static String GetInputStreamCommand_Get_input_stream;
public static String JSchConnection_Connection_was_cancelled;
public static String JSchConnection_connectionNotOpen; public static String JSchConnection_connectionNotOpen;
public static String JSchConnection_remote_address_must_be_set; public static String JSchConnection_remote_address_must_be_set;
public static String JSchConnection_remotePort; public static String JSchConnection_remotePort;

View file

@ -17,6 +17,7 @@ DeleteCommand_Remove_file=Remove file
ExecCommand_Exec_command=Executing command "{0}" ExecCommand_Exec_command=Executing command "{0}"
FetchInfoCommand_Fetch_info=Fetch info FetchInfoCommand_Fetch_info=Fetch info
GetInputStreamCommand_Get_input_stream=Get input stream GetInputStreamCommand_Get_input_stream=Get input stream
JSchConnection_Connection_was_cancelled=Connection was cancelled
JSchConnection_connectionNotOpen=Connection is not open JSchConnection_connectionNotOpen=Connection is not open
JSchConnection_remote_address_must_be_set=Remote address must be set before opening connection JSchConnection_remote_address_must_be_set=Remote address must be set before opening connection
JSchConnection_remotePort=Could not allocate remote port JSchConnection_remotePort=Could not allocate remote port