Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs')
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java10
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2ServerConnection.java132
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java188
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/PServerSSH2ServerConnection.java16
4 files changed, 173 insertions, 173 deletions
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java
index a31de7776..7bdb66a7b 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java
+++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java
@@ -62,11 +62,11 @@ public class CVSSSH2Plugin extends Plugin {
properties.put(DebugOptions.LISTENER_SYMBOLICNAME, ID);
debugRegistration = context.registerService(DebugOptionsListener.class, Policy.DEBUG_OPTIONS_LISTENER, properties);
- tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null);
- tracker.open();
+ tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null);
+ tracker.open();
}
- public IJSchService getJSchService() {
- return (IJSchService)tracker.getService();
- }
+ public IJSchService getJSchService() {
+ return (IJSchService)tracker.getService();
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2ServerConnection.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2ServerConnection.java
index f99e461c5..567f45514 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2ServerConnection.java
+++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2ServerConnection.java
@@ -45,20 +45,20 @@ public class CVSSSH2ServerConnection implements IServerConnection {
private static final String SSH1_COMPATIBILITY_CLASS = "org.eclipse.team.internal.ccvs.ssh.SSHServerConnection"; //$NON-NLS-1$
private final class SSH2IOException extends IOException {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private final JSchException e;
+ private final JSchException e;
- SSH2IOException(String s, JSchException e) {
- super(s);
- this.e = e;
- }
+ SSH2IOException(String s, JSchException e) {
+ super(s);
+ this.e = e;
+ }
- public Throwable getCause() {
- return e;
- }
- }
- private static final String COMMAND = "cvs server"; //$NON-NLS-1$
+ public Throwable getCause() {
+ return e;
+ }
+ }
+ private static final String COMMAND = "cvs server"; //$NON-NLS-1$
private ICVSRepositoryLocation location;
private String password;
private InputStream inputStream;
@@ -130,10 +130,10 @@ public class CVSSSH2ServerConnection implements IServerConnection {
try {
OutputStream channel_out = null;
InputStream channel_in = null;
- boolean firstTime = true;
- boolean tryAgain = false;
+ boolean firstTime = true;
+ boolean tryAgain = false;
while (firstTime || tryAgain) {
- tryAgain = false; // reset the try again flag
+ tryAgain = false; // reset the try again flag
session = JSchSession.getSession(location, location.getUsername(), password, location.getHost(), location.getPort(), monitor);
channel = session.getSession().openChannel("exec"); //$NON-NLS-1$
((ChannelExec) channel).setCommand(COMMAND);
@@ -142,24 +142,24 @@ public class CVSSSH2ServerConnection implements IServerConnection {
try {
channel.connect();
} catch (JSchException ee) {
- // This strange logic is here due to how the JSch client shares sessions.
- // It is possible that we have obtained a session that thinks it is connected
- // but is not. Channel connection only works if the session is connected so the
- // above channel connect may fail because the session is down. For this reason,
- // we want to retry if the connection fails.
- try {
- if (firstTime && (isSessionDownError(ee) || isChannelNotOpenError(ee))) {
- tryAgain = true;
- }
- if (!tryAgain) {
- throw ee;
- }
- } finally {
- // Always dispose of the current session when a failure occurs so we can start from scratch
- session.dispose();
- }
+ // This strange logic is here due to how the JSch client shares sessions.
+ // It is possible that we have obtained a session that thinks it is connected
+ // but is not. Channel connection only works if the session is connected so the
+ // above channel connect may fail because the session is down. For this reason,
+ // we want to retry if the connection fails.
+ try {
+ if (firstTime && (isSessionDownError(ee) || isChannelNotOpenError(ee))) {
+ tryAgain = true;
+ }
+ if (!tryAgain) {
+ throw ee;
+ }
+ } finally {
+ // Always dispose of the current session when a failure occurs so we can start from scratch
+ session.dispose();
+ }
}
- firstTime = false; // the first time is done
+ firstTime = false; // the first time is done
}
int timeout = location.getTimeout();
inputStream = new PollingInputStream(new TimeoutInputStream(new FilterInputStream(channel_in) {
@@ -182,31 +182,31 @@ public class CVSSSH2ServerConnection implements IServerConnection {
CVSSSH2Messages.CVSSSH2ServerConnection_4, e);
}
ssh1.open(monitor);
- } else {
- String message = e.getMessage();
- if (JSchSession.isAuthenticationFailure(e)) {
- // Do not retry as the Jsh library has it's own retry logic
- throw new CVSAuthenticationException(CVSSSH2Messages.CVSSSH2ServerConnection_0, CVSAuthenticationException.NO_RETRY,location, e);
- } else if (message.startsWith("Session.connect: ")) { //$NON-NLS-1$
- // Jsh has messages formatted like "Session.connect: java.net.NoRouteToHostException: ..."
- // Strip of the exception and try to convert it to a more meaningfull string
- int start = message.indexOf(": ") + 1; //$NON-NLS-1$
- if (start != -1) {
- int end = message.indexOf(": ", start); //$NON-NLS-1$
- if (end != -1) {
- String exception = message.substring(start, end).trim();
- if (exception.indexOf("NoRouteToHostException") != -1) { //$NON-NLS-1$
- message = NLS.bind(CVSSSH2Messages.CVSSSH2ServerConnection_1, new String[] { location.getHost() });
- throw new NoRouteToHostException(message);
- } else if (exception.indexOf("java.net.UnknownHostException") != -1) { //$NON-NLS-1$
- throw new UnknownHostException(location.getHost());
- } else {
- message = message.substring(end + 1).trim();
- }
- }
- }
- }
- throw new SSH2IOException(message, e);
+ } else {
+ String message = e.getMessage();
+ if (JSchSession.isAuthenticationFailure(e)) {
+ // Do not retry as the Jsh library has it's own retry logic
+ throw new CVSAuthenticationException(CVSSSH2Messages.CVSSSH2ServerConnection_0, CVSAuthenticationException.NO_RETRY,location, e);
+ } else if (message.startsWith("Session.connect: ")) { //$NON-NLS-1$
+ // Jsh has messages formatted like "Session.connect: java.net.NoRouteToHostException: ..."
+ // Strip of the exception and try to convert it to a more meaningfull string
+ int start = message.indexOf(": ") + 1; //$NON-NLS-1$
+ if (start != -1) {
+ int end = message.indexOf(": ", start); //$NON-NLS-1$
+ if (end != -1) {
+ String exception = message.substring(start, end).trim();
+ if (exception.indexOf("NoRouteToHostException") != -1) { //$NON-NLS-1$
+ message = NLS.bind(CVSSSH2Messages.CVSSSH2ServerConnection_1, new String[] { location.getHost() });
+ throw new NoRouteToHostException(message);
+ } else if (exception.indexOf("java.net.UnknownHostException") != -1) { //$NON-NLS-1$
+ throw new UnknownHostException(location.getHost());
+ } else {
+ message = message.substring(end + 1).trim();
+ }
+ }
+ }
+ }
+ throw new SSH2IOException(message, e);
}
}
}
@@ -247,14 +247,14 @@ public class CVSSSH2ServerConnection implements IServerConnection {
}
return null;
}
-
- private boolean isChannelNotOpenError(JSchException ee) {
- return ee.getMessage().indexOf("channel is not opened") != -1; //$NON-NLS-1$
- }
- private boolean isSessionDownError(JSchException ee) {
- return ee.getMessage().equals("session is down"); //$NON-NLS-1$
- }
- private boolean isSSH2Unsupported(JSchException e) {
- return e.toString().indexOf("invalid server's version string") != -1; //$NON-NLS-1$
- }
+
+ private boolean isChannelNotOpenError(JSchException ee) {
+ return ee.getMessage().indexOf("channel is not opened") != -1; //$NON-NLS-1$
+ }
+ private boolean isSessionDownError(JSchException ee) {
+ return ee.getMessage().equals("session is down"); //$NON-NLS-1$
+ }
+ private boolean isSSH2Unsupported(JSchException e) {
+ return e.toString().indexOf("invalid server's version string") != -1; //$NON-NLS-1$
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java
index 3e290148c..3a7b051d9 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java
+++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java
@@ -31,24 +31,24 @@ class JSchSession {
private static final int SSH_DEFAULT_PORT = 22;
private static Hashtable<String, JSchSession> pool = new Hashtable<>();
- private final Session session;
- private final ICVSRepositoryLocation location;
-
- protected static int getCVSTimeoutInMillis() {
- //return CVSProviderPlugin.getPlugin().getTimeout() * 1000;
- // TODO Hard-code the timeout for now since JSch doesn't respect CVS timeout
- // See bug 92887
- return 60000;
- }
-
- public static boolean isAuthenticationFailure(JSchException ee) {
- return ee.getMessage().equals("Auth fail"); //$NON-NLS-1$
- }
-
- static JSchSession getSession(final ICVSRepositoryLocation location, String username, String password, String hostname, int port, IProgressMonitor monitor) throws JSchException {
- int actualPort = port;
- if (actualPort == ICVSRepositoryLocation.USE_DEFAULT_PORT)
- actualPort = getPort(location);
+ private final Session session;
+ private final ICVSRepositoryLocation location;
+
+ protected static int getCVSTimeoutInMillis() {
+ //return CVSProviderPlugin.getPlugin().getTimeout() * 1000;
+ // TODO Hard-code the timeout for now since JSch doesn't respect CVS timeout
+ // See bug 92887
+ return 60000;
+ }
+
+ public static boolean isAuthenticationFailure(JSchException ee) {
+ return ee.getMessage().equals("Auth fail"); //$NON-NLS-1$
+ }
+
+ static JSchSession getSession(final ICVSRepositoryLocation location, String username, String password, String hostname, int port, IProgressMonitor monitor) throws JSchException {
+ int actualPort = port;
+ if (actualPort == ICVSRepositoryLocation.USE_DEFAULT_PORT)
+ actualPort = getPort(location);
String key = getPoolKey(username, hostname, actualPort);
@@ -56,47 +56,47 @@ class JSchSession {
JSchSession jschSession = pool.get(key);
if (jschSession != null && !jschSession.getSession().isConnected()) {
pool.remove(key);
- jschSession = null;
+ jschSession = null;
}
if (jschSession == null) {
- IJSchService service = getJSchService();
- IJSchLocation jlocation=service.getLocation(username, hostname, actualPort);
-
- // As for the connection method "pserverssh2",
- // there is not a place to save the given password for ssh2.
- if (!location.getMethod().getName().equals("pserverssh2")) { //$NON-NLS-1$
- IPasswordStore pstore = new IPasswordStore() {
- public void clear(IJSchLocation l) {
- location.flushUserInfo();
- }
- public boolean isCached(IJSchLocation l) {
- return location.getUserInfoCached();
- }
- public void update(IJSchLocation l) {
- location.setPassword(l.getPassword());
- location.setAllowCaching(true);
- }
- };
- jlocation.setPasswordStore(pstore);
- }
- jlocation.setComment(NLS.bind(CVSSSH2Messages.JSchSession_3, new String[] {location.toString()}));
-
- Session session = null;
- try {
- session = createSession(service, jlocation, password, monitor);
- } catch (JSchException e) {
- throw e;
- }
- if (session == null)
- throw new JSchException(CVSSSH2Messages.JSchSession_4);
- if (session.getTimeout() != location.getTimeout() * 1000)
- session.setTimeout(location.getTimeout() * 1000);
- JSchSession schSession = new JSchSession(session, location);
- pool.put(key, schSession);
- return schSession;
+ IJSchService service = getJSchService();
+ IJSchLocation jlocation=service.getLocation(username, hostname, actualPort);
+
+ // As for the connection method "pserverssh2",
+ // there is not a place to save the given password for ssh2.
+ if (!location.getMethod().getName().equals("pserverssh2")) { //$NON-NLS-1$
+ IPasswordStore pstore = new IPasswordStore() {
+ public void clear(IJSchLocation l) {
+ location.flushUserInfo();
+ }
+ public boolean isCached(IJSchLocation l) {
+ return location.getUserInfoCached();
+ }
+ public void update(IJSchLocation l) {
+ location.setPassword(l.getPassword());
+ location.setAllowCaching(true);
+ }
+ };
+ jlocation.setPasswordStore(pstore);
+ }
+ jlocation.setComment(NLS.bind(CVSSSH2Messages.JSchSession_3, new String[] {location.toString()}));
+
+ Session session = null;
+ try {
+ session = createSession(service, jlocation, password, monitor);
+ } catch (JSchException e) {
+ throw e;
+ }
+ if (session == null)
+ throw new JSchException(CVSSSH2Messages.JSchSession_4);
+ if (session.getTimeout() != location.getTimeout() * 1000)
+ session.setTimeout(location.getTimeout() * 1000);
+ JSchSession schSession = new JSchSession(session, location);
+ pool.put(key, schSession);
+ return schSession;
}
- return jschSession;
+ return jschSession;
} catch (JSchException e) {
pool.remove(key);
if(e.toString().indexOf("Auth cancel")!=-1){ //$NON-NLS-1$
@@ -106,35 +106,35 @@ class JSchSession {
}
}
- private static Session createSession(IJSchService service, IJSchLocation location, String password, IProgressMonitor monitor) throws JSchException {
- if (password != null)
- location.setPassword(password);
- Session session = service.createSession(location, null);
- session.setTimeout(getCVSTimeoutInMillis());
- if (password != null)
+ private static Session createSession(IJSchService service, IJSchLocation location, String password, IProgressMonitor monitor) throws JSchException {
+ if (password != null)
+ location.setPassword(password);
+ Session session = service.createSession(location, null);
+ session.setTimeout(getCVSTimeoutInMillis());
+ if (password != null)
session.setPassword(password);
- service.connect(session, getCVSTimeoutInMillis(), monitor);
- return session;
- }
+ service.connect(session, getCVSTimeoutInMillis(), monitor);
+ return session;
+ }
- private static IJSchService getJSchService(){
- return CVSSSH2Plugin.getDefault().getJSchService();
- }
+ private static IJSchService getJSchService(){
+ return CVSSSH2Plugin.getDefault().getJSchService();
+ }
- private static String getPoolKey(String username, String hostname, int port) {
- return username + "@" + hostname + ":" + port; //$NON-NLS-1$ //$NON-NLS-2$
- }
+ private static String getPoolKey(String username, String hostname, int port) {
+ return username + "@" + hostname + ":" + port; //$NON-NLS-1$ //$NON-NLS-2$
+ }
- private static String getPoolKey(ICVSRepositoryLocation location){
- return location.getUsername() + "@" + location.getHost() + ":" + getPort(location); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ private static String getPoolKey(ICVSRepositoryLocation location){
+ return location.getUsername() + "@" + location.getHost() + ":" + getPort(location); //$NON-NLS-1$ //$NON-NLS-2$
+ }
private static int getPort(ICVSRepositoryLocation location) {
- int port = location.getPort();
- if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT)
- port = SSH_DEFAULT_PORT;
- return port;
- }
+ int port = location.getPort();
+ if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT)
+ port = SSH_DEFAULT_PORT;
+ return port;
+ }
static void shutdown() {
if (getJSch() != null && pool.size() > 0) {
@@ -153,21 +153,21 @@ class JSchSession {
static JSch getJSch() {
return getJSchService().getJSch();
}
-
- private JSchSession(Session session, ICVSRepositoryLocation location) {
- this.session = session;
- this.location = location;
- }
-
- public Session getSession() {
- return session;
- }
-
- public void dispose() {
- if (session.isConnected()) {
- session.disconnect();
- }
- pool.remove(getPoolKey(location));
- }
+
+ private JSchSession(Session session, ICVSRepositoryLocation location) {
+ this.session = session;
+ this.location = location;
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ public void dispose() {
+ if (session.isConnected()) {
+ session.disconnect();
+ }
+ pool.remove(getPoolKey(location));
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/PServerSSH2ServerConnection.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/PServerSSH2ServerConnection.java
index 00ff5bea8..700719e82 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/PServerSSH2ServerConnection.java
+++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/PServerSSH2ServerConnection.java
@@ -112,14 +112,14 @@ public class PServerSSH2ServerConnection implements IServerConnection {
session.setPortForwardingL(lport, rhost, rport);
}
} catch (JSchException ee) {
- retry--;
- if(retry<0){
- throw new CVSAuthenticationException(CVSSSH2Messages.CVSSSH2ServerConnection_3, CVSAuthenticationException.NO_RETRY, location);
- }
- if(session != null && session.isConnected()){
- session.disconnect();
- }
- continue;
+ retry--;
+ if(retry<0){
+ throw new CVSAuthenticationException(CVSSSH2Messages.CVSSSH2ServerConnection_3, CVSAuthenticationException.NO_RETRY, location);
+ }
+ if(session != null && session.isConnected()){
+ session.disconnect();
+ }
+ continue;
}
break;
}

Back to the top