diff options
23 files changed, 810 insertions, 1108 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java index b849b2158..20bb9118c 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java @@ -109,5 +109,17 @@ public interface ICVSRepositoryLocation extends IAdaptable { * @param monitor the progress monitor used while validating */ public void validateConnection(IProgressMonitor monitor) throws CVSException; -} - + + /** + * Returns the plugged-in authenticator for this location. + * @since 3.0 + */ + public IUserAuthenticator getUserAuthenticator(); + + /** + * Sets the plugged-in authenticator for this location. This is a hook + * for testing. + * @since 3.0 + */ + public void setUserAuthenticator(IUserAuthenticator authenticator); +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java index 0182e6136..5ec457ebb 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IUserAuthenticator.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.team.internal.ccvs.core; - - - /** * IUserAuthenticators are used to ensure that the user * is validated for access to a given repository. The @@ -20,6 +17,52 @@ package org.eclipse.team.internal.ccvs.core; * appropriate for the given repository type. */ public interface IUserAuthenticator { + + /** + * Button id for an "Ok" button (value 0). + */ + public int OK_ID = 0; + + /** + * Button id for a "Cancel" button (value 1). + */ + public int CANCEL_ID = 1; + + /** + * Button id for a "Yes" button (value 2). + */ + public int YES_ID = 2; + + /** + * Button id for a "No" button (value 3). + */ + public int NO_ID = 3; + + /** + * Constant for a prompt with no type (value 0). + */ + public final static int NONE = 0; + + /** + * Constant for an error prompt (value 1). + */ + public final static int ERROR = 1; + + /** + * Constant for an information prompt (value 2). + */ + public final static int INFORMATION = 2; + + /** + * Constant for a question prompt (value 3). + */ + public final static int QUESTION = 3; + + /** + * Constant for a warning dialog (value 4). + */ + public final static int WARNING = 4; + /** * Authenticates the user for access to a given repository. * The obtained values for user name and password will be placed @@ -35,4 +78,28 @@ public interface IUserAuthenticator { * @return true if the validation was successful, and false otherwise. */ public void promptForUserInfo(ICVSRepositoryLocation location, IUserInfo userInfo, String message) throws CVSException; -} + + /** + * Prompts the authenticator for additional information regarding this authentication + * request. A default implementation of this method should return the <code>defaultResponse</code>, + * whereas alternate implementations could prompt the user with a dialog. + * + * @param location the repository location for this authentication + * @param promptType one of the following values: + * <ul> + * <li> <code>NONE</code> for a unspecified prompt type </li> + * <li> <code>ERROR</code> for an error prompt </li> + * <li> <code>INFORMATION</code> for an information prompt </li> + * <li> <code>QUESTION </code> for a question prompt </li> + * <li> <code>WARNING</code> for a warning prompt </li> + * </ul> + * @param title the prompt title that could be displayed to the user + * @param message the prompt + * @param promptResponses the possible responses to the prompt + * @param defaultResponse the default response to the prompt + * @return the response to the prompt + * + * @since 3.0 + */ + public int prompt(ICVSRepositoryLocation location, int promptType, String title, String message, int[] promptResponses, int defaultResponseIndex); +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java index 6d0e4caf1..d80ad3889 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java @@ -14,47 +14,15 @@ package org.eclipse.team.internal.ccvs.core.connection; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.StringTokenizer; +import java.util.*; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.Status; import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.internal.ccvs.core.CVSStatus; -import org.eclipse.team.internal.ccvs.core.CVSTag; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; -import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder; -import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.IConnectionMethod; -import org.eclipse.team.internal.ccvs.core.IUserAuthenticator; -import org.eclipse.team.internal.ccvs.core.IUserInfo; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.client.Command; -import org.eclipse.team.internal.ccvs.core.client.Session; -import org.eclipse.team.internal.ccvs.core.client.Update; -import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree; -import org.eclipse.team.internal.ccvs.core.resources.RemoteModule; +import org.eclipse.team.internal.ccvs.core.*; +import org.eclipse.team.internal.ccvs.core.client.*; +import org.eclipse.team.internal.ccvs.core.resources.*; /** * This class manages a CVS repository location. @@ -1044,4 +1012,17 @@ public class CVSRepositoryLocation extends PlatformObject implements ICVSReposit } } + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation#getUserAuthenticator() + */ + public IUserAuthenticator getUserAuthenticator() { + return getAuthenticator(); + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation#setUserAuthenticator() + */ + public void setUserAuthenticator(IUserAuthenticator authenticator) { + this.authenticator = authenticator; + } } diff --git a/bundles/org.eclipse.team.cvs.ssh/plugin.xml b/bundles/org.eclipse.team.cvs.ssh/plugin.xml index a25f214f0..cc5d16f81 100644 --- a/bundles/org.eclipse.team.cvs.ssh/plugin.xml +++ b/bundles/org.eclipse.team.cvs.ssh/plugin.xml @@ -21,7 +21,7 @@ <import plugin="org.eclipse.team.core"/> </requires> - +<!-- <extension id="ssh" point="org.eclipse.team.cvs.core.connectionmethods"> @@ -35,5 +35,6 @@ </run> </adapter> </extension> +--> </plugin> diff --git a/bundles/org.eclipse.team.cvs.ssh/src/org/eclipse/team/internal/ccvs/ssh/SSHServerConnection.java b/bundles/org.eclipse.team.cvs.ssh/src/org/eclipse/team/internal/ccvs/ssh/SSHServerConnection.java index 34d05725b..98e1d1904 100644 --- a/bundles/org.eclipse.team.cvs.ssh/src/org/eclipse/team/internal/ccvs/ssh/SSHServerConnection.java +++ b/bundles/org.eclipse.team.cvs.ssh/src/org/eclipse/team/internal/ccvs/ssh/SSHServerConnection.java @@ -41,7 +41,7 @@ public class SSHServerConnection implements IServerConnection { // ssh client Client client; - protected SSHServerConnection(ICVSRepositoryLocation location, String password) { + public SSHServerConnection(ICVSRepositoryLocation location, String password) { this.location = location; this.password = password; } diff --git a/bundles/org.eclipse.team.cvs.ssh2/.project b/bundles/org.eclipse.team.cvs.ssh2/.project index baf3b986b..79d0c9b3d 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/.project +++ b/bundles/org.eclipse.team.cvs.ssh2/.project @@ -8,6 +8,7 @@ <project>org.eclipse.core.runtime</project> <project>org.eclipse.team.core</project> <project>org.eclipse.team.cvs.core</project> + <project>org.eclipse.team.cvs.ssh</project> </projects> <buildSpec> <buildCommand> diff --git a/bundles/org.eclipse.team.cvs.ssh2/plugin.properties b/bundles/org.eclipse.team.cvs.ssh2/plugin.properties index 978e0fcec..02b9439ce 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/plugin.properties +++ b/bundles/org.eclipse.team.cvs.ssh2/plugin.properties @@ -1,2 +1,14 @@ -providerName=JCraft,Inc. +############################################################################### +# Copyright (c) 2000, 2003 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Common Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: +# Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. +# IBM Corporation - implementation +############################################################################### +providerName=Eclipse.org pluginName=CVS SSH2 +ssh2PreferencePage.name=SSH2 Connection Method diff --git a/bundles/org.eclipse.team.cvs.ssh2/plugin.xml b/bundles/org.eclipse.team.cvs.ssh2/plugin.xml index ce852dd9f..afbe14f3d 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/plugin.xml +++ b/bundles/org.eclipse.team.cvs.ssh2/plugin.xml @@ -1,10 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> <plugin id="org.eclipse.team.cvs.ssh2" name="%pluginName" version="0.1.0" provider-name="%providerName" - class="org.eclipse.team.cvs.ssh2.CVSSSH2Plugin"> + class="org.eclipse.team.ccvs.ssh2.CVSSSH2Plugin"> <runtime> <library name="cvsssh2.jar"> @@ -17,16 +18,17 @@ </runtime> <requires> <import plugin="org.eclipse.core.boot"/> - <import plugin="org.eclipse.core.runtime.compatibility"/> + <import plugin="org.eclipse.core.runtime.compatibility"/> <import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.team.cvs.core"/> <import plugin="org.eclipse.team.core"/> <import plugin="org.eclipse.ui"/> + <import plugin="org.eclipse.team.cvs.ssh"/> </requires> <extension - id="ssh" + id="ssh2" point="org.eclipse.team.cvs.core.connectionmethods"> <adapter> <run @@ -39,22 +41,9 @@ </adapter> </extension> <extension - id="ssh" - point="org.eclipse.team.cvs.core.connectionmethods"> - <adapter> - <run - class="org.eclipse.team.ccvs.ssh2.PServerSSH2Method"> - <parameter - name="trace" - value="false"> - </parameter> - </run> - </adapter> - </extension> - <extension point="org.eclipse.ui.preferencePages"> <page - name="CVSSSH2" + name="%ssh2PreferencePage.name" category="org.eclipse.team.cvs.ui.CVSPreferences" class="org.eclipse.team.ccvs.ssh2.CVSSSH2PreferencePage" id="org.eclipse.team.cvs.ssh2.CVSSSH2Preferences"> diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Method.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Method.java index 4bbab8690..eb3d6d3c3 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Method.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Method.java @@ -1,26 +1,38 @@ /* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights + * reserved. This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 which accompanies this + * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and + * implementation. + ******************************************************************************/ package org.eclipse.team.ccvs.ssh2; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.internal.ccvs.core.IConnectionMethod; import org.eclipse.team.internal.ccvs.core.IServerConnection; +import org.eclipse.team.internal.ccvs.ssh.SSHServerConnection; public class CVSSSH2Method implements IConnectionMethod { - public String getName() { return "extssh2"; } - public IServerConnection createConnection(ICVSRepositoryLocation root, - String password) { - return new CVSSSH2ServerConnection(root, password); - } - public void disconnect(ICVSRepositoryLocation location) { - } -} + public String getName() { + return "extssh"; //$NON-NLS-1$ + } + + public IServerConnection createConnection(ICVSRepositoryLocation root, String password) { + IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore(); + + // Support for user defined switching between SSH1 and SSH2 for now. Will + // improve this to provide automatic server version detection. + if(store.getBoolean(CVSSSH2PreferencePage.KEY_USE_SSH2)) { + return new CVSSSH2ServerConnection(root, password); + } else { + return new SSHServerConnection(root, password); + } + } + + public void disconnect(ICVSRepositoryLocation location) { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Plugin.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Plugin.java index 219758e99..02acf74f1 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Plugin.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2Plugin.java @@ -1,52 +1,55 @@ /* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights + * reserved. This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 which accompanies this + * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and + * implementation. + ******************************************************************************/ package org.eclipse.team.ccvs.ssh2; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.Plugin; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; +public class CVSSSH2Plugin extends AbstractUIPlugin { -import org.eclipse.jface.preference.IPreferenceStore; + public static String ID = "org.eclipse.team.cvs.ssh2"; //$NON-NLS-1$ + private static CVSSSH2Plugin plugin; -public class CVSSSH2Plugin extends AbstractUIPlugin{ - - public static String ID="org.eclipse.team.cvs.ssh2"; - private static CVSSSH2Plugin plugin; - - public CVSSSH2Plugin(IPluginDescriptor d){ - super(d); - plugin=this; - } - - public static CVSSSH2Plugin getPlugin(){ return plugin; } + public CVSSSH2Plugin(IPluginDescriptor d) { + super(d); + plugin = this; + } - public void shutdown() throws org.eclipse.core.runtime.CoreException{ - JSchSession.shutdown(); - super.shutdown(); - } + public static CVSSSH2Plugin getPlugin() { + return plugin; + } - public static CVSSSH2Plugin getDefault() { - return plugin; - } + public void shutdown() throws org.eclipse.core.runtime.CoreException { + JSchSession.shutdown(); + super.shutdown(); + } - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - } + public static CVSSSH2Plugin getDefault() { + return plugin; + } - protected void initializeDefaultPreferences(IPreferenceStore store) { - CVSSSH2PreferencePage.initDefaults(store); - } -} + public static IWorkspace getWorkspace() { + return ResourcesPlugin.getWorkspace(); + } + + protected void initializeDefaultPreferences(IPreferenceStore store) { + CVSSSH2PreferencePage.initDefaults(store); + } + + public void startup() throws CoreException { + Policy.localize("org.eclipse.team.ccvs.ssh2.messages"); //$NON-NLS-1$ + super.startup(); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2PreferencePage.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2PreferencePage.java index a68a8f62a..0588c5f67 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2PreferencePage.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2PreferencePage.java @@ -11,22 +11,12 @@ Contributors: **********************************************************************/ package org.eclipse.team.ccvs.ssh2; -import org.eclipse.jface.preference.FieldEditor; -import org.eclipse.jface.preference.FieldEditorPreferencePage; -import org.eclipse.jface.preference.FileFieldEditor; -import org.eclipse.jface.preference.RadioGroupFieldEditor; -import org.eclipse.jface.preference.StringFieldEditor; -import org.eclipse.jface.preference.IntegerFieldEditor; -import org.eclipse.jface.preference.DirectoryFieldEditor; -import org.eclipse.jface.preference.ColorFieldEditor; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.util.PropertyChangeEvent; - +import org.eclipse.jface.preference.*; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.*; - import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -41,6 +31,9 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage public static String KEY_PROXY_USER="CVSSSH2PreferencePage.PROXY_USER"; public static String KEY_PROXY_PASS="CVSSSH2PreferencePage.PROXY_PASS"; public static String KEY_SSH2HOME="CVSSSH2PreferencePage.SSH2HOME"; + + // Temporary preference for using ssh2 instead of ssh1 + public static String KEY_USE_SSH2="CVSSSH2PreferencePage.SSH2_USE_SSH2"; static String SOCKS5="SOCKS5"; static String HTTP="HTTP"; @@ -61,6 +54,7 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage private Text proxyPassText; private Button enableProxy; private Button enableAuth; + private Button enableSSH2; private boolean useProxy; private boolean useAuth; @@ -72,7 +66,15 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage } protected void createFieldEditors() { - ssh2homeEditor= + enableSSH2=new Button(getFieldEditorParent(), SWT.CHECK); + enableSSH2.setText("Enable SSH2 instead of SSH1 (temporary until SSH2 is fully tested)"); + GridData gd=new GridData(); + gd.horizontalSpan=2; + enableSSH2.setLayoutData(gd); + + createSpacer(getFieldEditorParent(), 3); + + ssh2homeEditor= new DirectoryFieldEditor(KEY_SSH2HOME, "SSH2 Home", getFieldEditorParent()); @@ -84,7 +86,7 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage } private void updateControls() { - boolean enable=enableProxy.getSelection(); + boolean enable=enableProxy.getSelection(); proxyTypeLabel.setEnabled(enable); proxyTypeCombo.setEnabled(enable); proxyPortLabel.setEnabled(enable); @@ -115,6 +117,7 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage setDefault(store, KEY_PROXY_AUTH, "false"); setDefault(store, KEY_PROXY_USER, ""); setDefault(store, KEY_PROXY_PASS, ""); + store.setDefault(KEY_USE_SSH2, false); } private static void setDefault(IPreferenceStore store, String key, String value){ @@ -125,6 +128,7 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage private void initControls(){ IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore(); + enableSSH2.setSelection(store.getBoolean(KEY_USE_SSH2)); useProxy=store.getString(KEY_PROXY).equals("true"); enableProxy.setSelection(useProxy); proxyHostText.setText(store.getString(KEY_PROXY_HOST)); @@ -148,7 +152,7 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage gd.horizontalAlignment=GridData.FILL; group.setLayoutData(gd); group.setFont(composite.getFont()); - + enableProxy=new Button(group, SWT.CHECK); enableProxy.setText("Enable proxy connection"); gd=new GridData(); @@ -248,6 +252,8 @@ public class CVSSSH2PreferencePage extends FieldEditorPreferencePage store.setValue(KEY_PROXY_AUTH, enableAuth.getSelection()); store.setValue(KEY_PROXY_USER, proxyUserText.getText()); store.setValue(KEY_PROXY_PASS, proxyPassText.getText()); + + store.setValue(KEY_USE_SSH2, enableSSH2.getSelection()); } CVSSSH2Plugin.getDefault().savePluginPreferences(); return result; diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2ServerConnection.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2ServerConnection.java index c39a14334..64dee22f7 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2ServerConnection.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/CVSSSH2ServerConnection.java @@ -1,102 +1,98 @@ /* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights + * reserved. This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 which accompanies this + * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and + * implementation. + ******************************************************************************/ package org.eclipse.team.ccvs.ssh2; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.internal.ccvs.core.IServerConnection; import org.eclipse.team.internal.ccvs.core.connection.CVSAuthenticationException; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; - import com.jcraft.jsch.*; public class CVSSSH2ServerConnection implements IServerConnection { - - private static final String COMMAND="cvs server"; - - private ICVSRepositoryLocation location; - private String password; - - private InputStream inputStream; - private OutputStream outputStream; - - private Session session; - private Channel channel; - - protected CVSSSH2ServerConnection(ICVSRepositoryLocation location, - String password) { - this.location=location; - this.password=password; - } - - public void close() throws IOException { - if(channel!=null) - channel.disconnect(); - } - - public InputStream getInputStream() { return inputStream; } - public OutputStream getOutputStream() { return outputStream; } - - public void open(IProgressMonitor monitor) throws IOException, - CVSAuthenticationException { - monitor.subTask("CVSSSH2ServerConnection.open"); - monitor.worked(1); - try{ - String hostname=location.getHost(); - String username=location.getUsername(); - int port=location.getPort(); - if(port==ICVSRepositoryLocation.USE_DEFAULT_PORT) - port=0; - - int retry=1; - OutputStream channel_out; - InputStream channel_in; - - while(true){ - session=JSchSession.getSession(username, password, hostname, port, monitor); - channel=session.openChannel("exec"); - ((ChannelExec)channel).setCommand(COMMAND); - - channel_out=channel.getOutputStream(); - channel_in=channel.getInputStream(); - - try{ channel.connect(); } - catch(JSchException ee){ - if(!session.isConnected()){ - //System.out.println("sesssion is down"); - //channel.disconnect(); - retry--; - if(retry<0){ - throw new CVSAuthenticationException("session is down"); - } - continue; - } - throw ee; + + private static final String COMMAND = "cvs server"; + + private ICVSRepositoryLocation location; + private String password; + + private InputStream inputStream; + private OutputStream outputStream; + + private Session session; + private Channel channel; + + protected CVSSSH2ServerConnection(ICVSRepositoryLocation location, String password) { + this.location = location; + this.password = password; + } + + public void close() throws IOException { + if (channel != null) + channel.disconnect(); + } + + public InputStream getInputStream() { + return inputStream; + } + public OutputStream getOutputStream() { + return outputStream; + } + + public void open(IProgressMonitor monitor) throws IOException, CVSAuthenticationException { + monitor.subTask(Policy.bind("CVSSSH2ServerConnection.open", location.getHost())); //$NON-NLS-1$ + monitor.worked(1); + try { + String hostname = location.getHost(); + String username = location.getUsername(); + int port = location.getPort(); + if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT) + port = 0; + + int retry = 1; + OutputStream channel_out; + InputStream channel_in; + + while (true) { + session = JSchSession.getSession(location, username, password, hostname, port, monitor); + channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(COMMAND); + + channel_out = channel.getOutputStream(); + channel_in = channel.getInputStream(); + + try { + channel.connect(); + } catch (JSchException ee) { + if (!session.isConnected()) { + //System.out.println("sesssion is down"); + //channel.disconnect(); + retry--; + if (retry < 0) { + throw new CVSAuthenticationException("session is down"); + } + continue; + } + throw ee; + } + break; + } + + inputStream = channel_in; + outputStream = channel_out; + } catch (JSchException e) { + //e.printStackTrace(); + throw new CVSAuthenticationException(e.toString()); + } } - break; - } - - inputStream=channel_in; - outputStream=channel_out; - } - catch(JSchException e){ - //e.printStackTrace(); - throw new CVSAuthenticationException(e.toString()); - } - } -} +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/JSchSession.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/JSchSession.java index 7fff34b4b..e10e6915c 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/JSchSession.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/JSchSession.java @@ -1,318 +1,242 @@ /* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights + * reserved. This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 which accompanies this + * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and + * implementation. + ******************************************************************************/ package org.eclipse.team.ccvs.ssh2; -import java.util.Enumeration; -import java.io.File; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.IOException; +import java.io.*; import java.net.Socket; import java.net.UnknownHostException; +import java.util.Enumeration; -import org.eclipse.team.internal.ccvs.core.util.Util; +import org.eclipse.core.boot.BootLoader; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.team.internal.ccvs.core.*; +import org.eclipse.team.internal.ccvs.core.util.Util; import com.jcraft.jsch.*; -class JSchSession{ - private static final int SSH_DEFAULT_PORT=22; - private static JSch jsch; - private static java.util.Hashtable pool=new java.util.Hashtable(); - - static String default_ssh_home=null; - static { - default_ssh_home=System.getProperty("user.home"); - if(default_ssh_home!=null){ - default_ssh_home=default_ssh_home+java.io.File.separator+".ssh"; - } - } - - private static String current_ssh_home=null; - - static Session getSession(String username, String password, - String hostname, int port, - final IProgressMonitor monitor) throws JSchException{ - if(port==0) port=SSH_DEFAULT_PORT; - if(jsch==null){ - jsch=new JSch(); - } - - IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore(); - String ssh_home=store.getString(CVSSSH2PreferencePage.KEY_SSH2HOME); - - if(current_ssh_home==null || - !current_ssh_home.equals(ssh_home)){ - current_ssh_home=ssh_home; - if(ssh_home.length()==0) - ssh_home=default_ssh_home; - - try{ - java.io.File file; - file=new java.io.File(ssh_home, "id_dsa"); - if(file.exists()) jsch.addIdentity(file.getPath()); - file=new java.io.File(ssh_home, "id_rsa"); - if(file.exists()) jsch.addIdentity(file.getPath()); - file=new java.io.File(ssh_home, "known_hosts"); - jsch.setKnownHosts(file.getPath()); - } - catch(Exception e){ - } - } - - String key=username+"@"+hostname+":"+port; - - try{ - Session session=(Session)pool.get(key); - if(session!=null && !session.isConnected()){ - pool.remove(key); - session=null; - } - - if(session==null){ - session=jsch.getSession(username, hostname, port); - - boolean useProxy=store.getString(CVSSSH2PreferencePage.KEY_PROXY).equals("true"); - if(useProxy){ - String _type=store.getString(CVSSSH2PreferencePage.KEY_PROXY_TYPE); - String _host=store.getString(CVSSSH2PreferencePage.KEY_PROXY_HOST); - String _port=store.getString(CVSSSH2PreferencePage.KEY_PROXY_PORT); - - boolean useAuth=store.getString(CVSSSH2PreferencePage.KEY_PROXY_AUTH).equals("true"); - String _user=store.getString(CVSSSH2PreferencePage.KEY_PROXY_USER); - String _pass=store.getString(CVSSSH2PreferencePage.KEY_PROXY_PASS); - - Proxy proxy=null; - String proxyhost=_host+":"+_port; - if(_type.equals(CVSSSH2PreferencePage.HTTP)){ - proxy=new ProxyHTTP(proxyhost); - if(useAuth){ - ((ProxyHTTP)proxy).setUserPasswd(_user, _pass); - } - } - else if(_type.equals(CVSSSH2PreferencePage.SOCKS5)){ - proxy=new ProxySOCKS5(proxyhost); - if(useAuth){ - ((ProxySOCKS5)proxy).setUserPasswd(_user, _pass); - } - } - else{ - proxy=null; - } - if(proxy!=null){ - session.setProxy(proxy); - } +class JSchSession { + private static final int SSH_DEFAULT_PORT = 22; + private static JSch jsch; + private static java.util.Hashtable pool = new java.util.Hashtable(); + + static String default_ssh_home = null; + static { + String ssh_dir_name = ".ssh"; //$NON-NLS-1$ + + // Windows doesn't like files or directories starting with a dot. + if (BootLoader.getOS().equals(BootLoader.OS_WIN32)) { + ssh_dir_name = "ssh"; //$NON-NLS-1$ + } + default_ssh_home = System.getProperty("user.home"); //$NON-NLS-1$ + if (default_ssh_home != null) { + default_ssh_home = default_ssh_home + java.io.File.separator + ssh_dir_name; + } else { + + } } - session.setPassword(password); - - UserInfo ui=new MyUserInfo(username); - session.setUserInfo(ui); - - session.setSocketFactory(new SocketFactory(){ - InputStream in=null; - OutputStream out=null; - public Socket createSocket(String host, int port) throws IOException, - UnknownHostException{ - Socket socket=null; - socket=Util.createSocket(host, port, monitor); - return socket; - } - public InputStream getInputStream(Socket socket) throws IOException{ - if(in==null) in=socket.getInputStream(); - return in; - } - public OutputStream getOutputStream(Socket socket) throws IOException{ - if(out==null) out=socket.getOutputStream(); - return out; - } - }); - - session.connect(); - pool.put(key, session); - } - return session; - } - catch(JSchException e){ - //e.printStackTrace(); - pool.remove(key); - throw e; - } - } - - private static class MyUserInfo implements UserInfo, UIKeyboardInteractive{ - private String username; - private String password; - private String passphrase; - MyUserInfo(String username){ - this.username=username; - } - public String getPassword(){ return password; } - public String getPassphrase(){ return passphrase; } - public boolean promptYesNo(String str){ - YesNoPrompt prompt=new YesNoPrompt(str); - Display.getDefault().syncExec(prompt); - return prompt.getResult()==SWT.YES; - } - public boolean promptPassphrase(String message){ - PassphrasePrompt prompt=new PassphrasePrompt(message); - Display.getDefault().syncExec(prompt); - String _passphrase=prompt.getPassphrase(); - if(_passphrase!=null)passphrase=_passphrase; - return _passphrase!=null; - } - public boolean promptPassword(String message){ - PasswordPrompt prompt=new PasswordPrompt(message); - Display.getDefault().syncExec(prompt); - String _password=prompt.getPassword(); - if(_password!=null)password=_password; - return _password!=null; - } - public void showMessage(final String foo){ - final Display display=Display.getCurrent(); - display.syncExec(new Runnable(){ - public void run(){ - Shell shell=new Shell(display); - MessageBox box=new MessageBox(shell,SWT.OK); - box.setMessage(foo); - box.open(); - shell.dispose(); - } - }); - } - public String[] promptKeyboardInteractive(String destination, - String name, - String instruction, - String lang, - String[] prompt, - boolean[] echo){ - KeyboardInteractivePrompt _prompt=new KeyboardInteractivePrompt(destination, - name, - instruction, - lang, - prompt, - echo); - Display.getDefault().syncExec(_prompt); - String[] result=_prompt.getResult(); - return result; - } - - private class YesNoPrompt implements Runnable{ - private String prompt; - private int result; - YesNoPrompt(String prompt){ - this.prompt=prompt; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - MessageBox box=new MessageBox(shell,SWT.YES|SWT.NO); - box.setMessage(prompt); - result=box.open(); - shell.dispose(); - } - public int getResult(){ return result; } - } - private class PasswordPrompt implements Runnable{ - private String message; - private String password; - PasswordPrompt(String message){ - this.message=message; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - PasswordDialog dialog=new PasswordDialog(shell, message); - dialog.open(); - shell.dispose(); - password=dialog.getPassword(); - } - public String getPassword(){ - return password; - } - } - private class PassphrasePrompt implements Runnable{ - private String message; - private String passphrase; - PassphrasePrompt(String message){ - this.message=message; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - PassphraseDialog dialog=new PassphraseDialog(shell, message); - dialog.open(); - shell.dispose(); - passphrase=dialog.getPassphrase(); - } - public String getPassphrase(){ - return passphrase; - } - } - private class KeyboardInteractivePrompt implements Runnable{ - private String destination; - private String name; - private String instruction; - private String lang; - private String[] prompt; - private boolean[] echo; - private String[] result; - KeyboardInteractivePrompt(String destination, - String name, - String instruction, - String lang, - String[] prompt, - boolean[] echo){ - this.destination=destination; - this.name=name; - this.instruction=instruction; - this.lang=lang; - this.prompt=prompt; - this.echo=echo; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - KeyboardInteractiveDialog dialog=new KeyboardInteractiveDialog(shell, - destination, - name, - instruction, - lang, - prompt, - echo); - dialog.open(); - shell.dispose(); - result=dialog.getResult(); - } - public String[] getResult(){ - return result; - } - } - } + private static String current_ssh_home = null; + + /** + * User information delegates to the IUserAuthenticator. This allows + * headless access to the connection method. + */ + private static class MyUserInfo implements UserInfo { + private String username; + private String password; + private String passphrase; + private ICVSRepositoryLocation location; + + MyUserInfo(String username, ICVSRepositoryLocation location) { + this.location = location; + this.username = username; + } + public String getPassword() { + return password; + } + public String getPassphrase() { + return passphrase; + } + public boolean promptYesNo(String str) { + IUserAuthenticator authenticator = location.getUserAuthenticator(); + int prompt = authenticator.prompt( + location, + IUserAuthenticator.QUESTION, + Policy.bind("JSchSession.5"), //$NON-NLS-1$ + str, + new int[] {IUserAuthenticator.YES_ID, IUserAuthenticator.NO_ID}, + 0 //yes the default + ); + return prompt == 0; + } + public boolean promptPassphrase(String message) { + IUserAuthenticator authenticator = location.getUserAuthenticator(); + final String[] _password = new String[1]; + IUserInfo info = new IUserInfo() { + private String a; + public String getUsername() { + return username; + } + public boolean isUsernameMutable() { + return false; + } + public void setPassword(String password) { + _password[0] = password; + } + public void setUsername(String username) { + } + }; + try { + authenticator.promptForUserInfo(location, info, message); + } catch (CVSException e) { + return false; + } + + if (_password[0] != null) + passphrase = _password[0]; + return _password != null; + } + public boolean promptPassword(String message) { + return promptPassphrase(message); + } + public void showMessage(String message) { + IUserAuthenticator authenticator = location.getUserAuthenticator(); + authenticator.prompt( + location, + IUserAuthenticator.INFORMATION, + Policy.bind("JSchSession.5"), //$NON-NLS-1$ + message, + new int[] {IUserAuthenticator.OK_ID}, + IUserAuthenticator.OK_ID + ); + } + } + + static Session getSession(ICVSRepositoryLocation location, String username, String password, String hostname, int port, final IProgressMonitor monitor) throws JSchException { + if (port == 0) + port = SSH_DEFAULT_PORT; + if (jsch == null) { + jsch = new JSch(); + } + + IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore(); + String ssh_home = store.getString(CVSSSH2PreferencePage.KEY_SSH2HOME); + + if (current_ssh_home == null || !current_ssh_home.equals(ssh_home)) { + current_ssh_home = ssh_home; + if (ssh_home.length() == 0) + ssh_home = default_ssh_home; + + try { + java.io.File file; + file = new java.io.File(ssh_home, "id_dsa"); //$NON-NLS-1$ + if (file.exists()) + jsch.addIdentity(file.getPath()); + file = new java.io.File(ssh_home, "id_rsa"); //$NON-NLS-1$ + if (file.exists()) + jsch.addIdentity(file.getPath()); + file = new java.io.File(ssh_home, "known_hosts"); //$NON-NLS-1$ + jsch.setKnownHosts(file.getPath()); + } catch (Exception e) { + } + } + + String key = username + "@" + hostname + ":" + port; //$NON-NLS-1$ //$NON-NLS-2$ + + try { + Session session = (Session) pool.get(key); + if (session != null && !session.isConnected()) { + pool.remove(key); + session = null; + } + + if (session == null) { + session = jsch.getSession(username, hostname, port); + + boolean useProxy = store.getString(CVSSSH2PreferencePage.KEY_PROXY).equals("true"); //$NON-NLS-1$ + if (useProxy) { + String _type = store.getString(CVSSSH2PreferencePage.KEY_PROXY_TYPE); + String _host = store.getString(CVSSSH2PreferencePage.KEY_PROXY_HOST); + String _port = store.getString(CVSSSH2PreferencePage.KEY_PROXY_PORT); + + boolean useAuth = store.getString(CVSSSH2PreferencePage.KEY_PROXY_AUTH).equals("true"); //$NON-NLS-1$ + String _user = store.getString(CVSSSH2PreferencePage.KEY_PROXY_USER); + String _pass = store.getString(CVSSSH2PreferencePage.KEY_PROXY_PASS); + + Proxy proxy = null; + String proxyhost = _host + ":" + _port; //$NON-NLS-1$ + if (_type.equals(CVSSSH2PreferencePage.HTTP)) { + proxy = new ProxyHTTP(proxyhost); + if (useAuth) { + ((ProxyHTTP) proxy).setUserPasswd(_user, _pass); + } + } else if (_type.equals(CVSSSH2PreferencePage.SOCKS5)) { + proxy = new ProxySOCKS5(proxyhost); + if (useAuth) { + ((ProxySOCKS5) proxy).setUserPasswd(_user, _pass); + } + } else { + proxy = null; + } + if (proxy != null) { + session.setProxy(proxy); + } + } + + session.setPassword(password); + + UserInfo ui = new MyUserInfo(username, location); + session.setUserInfo(ui); + + session.setSocketFactory(new SocketFactory() { + InputStream in = null; + OutputStream out = null; + public Socket createSocket(String host, int port) throws IOException, UnknownHostException { + Socket socket = null; + socket = Util.createSocket(host, port, monitor); + return socket; + } + public InputStream getInputStream(Socket socket) throws IOException { + if (in == null) + in = socket.getInputStream(); + return in; + } + public OutputStream getOutputStream(Socket socket) throws IOException { + if (out == null) + out = socket.getOutputStream(); + return out; + } + }); + + session.connect(); + pool.put(key, session); + } + return session; + } catch (JSchException e) { + pool.remove(key); + throw e; + } + } - static void shutdown(){ - if(jsch!=null && pool.size()>0){ - for(Enumeration e=pool.elements(); e.hasMoreElements();){ - Session session=(Session)(e.nextElement()); - try{ session.disconnect(); } - catch(Exception ee){} - } - pool.clear(); - } - } -} + static void shutdown() { + if (jsch != null && pool.size() > 0) { + for (Enumeration e = pool.elements(); e.hasMoreElements(); ) { + Session session = (Session) (e.nextElement()); + try { + session.disconnect(); + } catch (Exception ee) { + } + } + pool.clear(); + } + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/KeyboardInteractiveDialog.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/KeyboardInteractiveDialog.java deleted file mode 100644 index 2f7c68b3d..000000000 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/KeyboardInteractiveDialog.java +++ /dev/null @@ -1,126 +0,0 @@ -/* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ -package org.eclipse.team.ccvs.ssh2; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -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.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.help.WorkbenchHelp; - -public class KeyboardInteractiveDialog extends Dialog { - - private Text[] texts; - protected String destination; - protected String name; - protected String instruction; - protected String lang; - protected String[] prompt; - protected boolean[] echo; - private String message; - private String[] result; - - public KeyboardInteractiveDialog(Shell parentShell, - String destination, - String name, - String instruction, - String lang, - String[] prompt, - boolean[] echo){ - super(parentShell); - this.destination=destination; - this.name=name; - this.instruction=instruction; - this.lang=lang; - this.prompt=prompt; - this.echo=echo; - this.message="Keyboard Interactive for "+destination+(name!=null && name.length()>0 ? ": "+name : ""); - } - - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(message); - } - - public void create() { - super.create(); - if(texts.length>0){ - texts[0].setFocus(); - } - } - - protected Control createDialogArea(Composite parent) { - Composite main=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=3; - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); - - if (message!=null) { - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } - if (instruction!=null && instruction.length()>0) { - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(instruction); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } - createPasswordFields(main); - return main; - } - - protected void createPasswordFields(Composite parent) { - texts=new Text[prompt.length]; - - for(int i=0; i<prompt.length; i++){ - new Label(parent, SWT.NONE).setText(prompt[i]); - texts[i]=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - texts[i].setLayoutData(data); - - if(!echo[i]){ - texts[i].setEchoChar('*'); - } - new Label(parent, SWT.NONE); - } - - } - - public String[] getResult() { - return result; - } - - protected void okPressed() { - result=new String[prompt.length]; - for(int i=0; i<texts.length; i++){ - result[i]=texts[i].getText(); - } - super.okPressed(); - } - - protected void cancelPressed() { - result=null; - super.cancelPressed(); - } -} diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2Method.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2Method.java index 59c70ac06..806662741 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2Method.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2Method.java @@ -1,14 +1,13 @@ /* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights + * reserved. This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 which accompanies this + * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and + * implementation. + ******************************************************************************/ package org.eclipse.team.ccvs.ssh2; import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; @@ -16,11 +15,12 @@ import org.eclipse.team.internal.ccvs.core.IConnectionMethod; import org.eclipse.team.internal.ccvs.core.IServerConnection; public class PServerSSH2Method implements IConnectionMethod { - public String getName() { return "pserverssh2"; } - public IServerConnection createConnection(ICVSRepositoryLocation root, - String password) { - return new PServerSSH2ServerConnection(root, password); - } - public void disconnect(ICVSRepositoryLocation location) { - } -} + public String getName() { + return "pserverssh2"; + } + public IServerConnection createConnection(ICVSRepositoryLocation root, String password) { + return new PServerSSH2ServerConnection(root, password); + } + public void disconnect(ICVSRepositoryLocation location) { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2ServerConnection.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2ServerConnection.java index 9b31d5b9e..8acbbd131 100644 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2ServerConnection.java +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PServerSSH2ServerConnection.java @@ -1,258 +1,145 @@ /* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights + * reserved. This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 which accompanies this + * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and + * implementation. + ******************************************************************************/ package org.eclipse.team.ccvs.ssh2; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - +import java.io.*; import java.util.Properties; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.IServerConnection; +import org.eclipse.team.internal.ccvs.core.*; import org.eclipse.team.internal.ccvs.core.connection.CVSAuthenticationException; - import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.IConnectionMethod; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.MessageBox; - -import java.io.PipedInputStream; -import java.io.PipedOutputStream; import com.jcraft.jsch.*; public class PServerSSH2ServerConnection implements IServerConnection { - - private ICVSRepositoryLocation location; - private String password; - - private Session session; - private Channel channel; - - private static int localport=2402; - - private IServerConnection psc=null; - protected PServerSSH2ServerConnection(ICVSRepositoryLocation location, - String password) { - this.location=location; - this.password=password; - } + private ICVSRepositoryLocation location; + private String password; - public void close() throws IOException { - psc.close(); - } + private Session session; + private Channel channel; - public InputStream getInputStream() { return psc.getInputStream(); } - public OutputStream getOutputStream() { return psc.getOutputStream(); } + private static int localport = 2402; - public void open(IProgressMonitor monitor) throws IOException, - CVSAuthenticationException { - monitor.subTask("PServerSSH2ServerConnection.open"); - monitor.worked(1); - String cvs_root=location.getRootDirectory(); - int cvs_port=location.getPort(); - if(cvs_port==0) cvs_port=2401; - String cvs_host=location.getHost(); - String ssh_host=cvs_host; - String ssh_user=location.getUsername(); + private IServerConnection psc = null; - String host=cvs_host; - if(host.indexOf('@')!=-1){ - cvs_host=host.substring(host.lastIndexOf('@')+1); - host=host.substring(0, host.lastIndexOf('@')); - if(host.indexOf('@')!=-1){ - ssh_host=host.substring(host.lastIndexOf('@')+1); - if(ssh_host.length()==0)ssh_host=cvs_host; - ssh_user=host.substring(0, host.lastIndexOf('@')); - } - else{ - ssh_host=host; - } - } - - int ssh_port=0; - if(ssh_host.indexOf('#')!=-1){ - try{ - ssh_port=Integer.parseInt(ssh_host.substring(ssh_host.lastIndexOf('#')+1)); - ssh_host=ssh_host.substring(0, ssh_host.lastIndexOf('#')); - } - catch(Exception e){ - } - } - - int lport=cvs_port; - String rhost=(cvs_host.equals(ssh_host) ? "localhost" : cvs_host); - int rport=cvs_port; + protected PServerSSH2ServerConnection(ICVSRepositoryLocation location, String password) { + this.location = location; + this.password = password; + } - // ssh -L lport:rhost:rport ssh_user@ssh_host - int retry=1; - while(true){ - try{ - session=JSchSession.getSession(ssh_user, "", ssh_host, ssh_port, monitor); - String[] list=session.getPortForwardingL(); - String name=":"+rhost+":"+rport; - boolean done=false; - for(int i=0; i<list.length; i++){ - if(list[i].endsWith(name)) { - try{ - String foo=list[i].substring(0, list[i].indexOf(':')); - lport=Integer.parseInt(foo); - } - catch(Exception ee){ - } - done=true; - break; - } + public void close() throws IOException { + psc.close(); } - if(!done){ - lport=localport++; - session.setPortForwardingL(lport, rhost, rport); + + public InputStream getInputStream() { + return psc.getInputStream(); } - } - catch(JSchException ee){ - if(!session.isConnected()){ - //System.out.println("sesssion is down"); - retry--; - if(retry<0){ - throw new CVSAuthenticationException(ee.toString()); - } - continue; + public OutputStream getOutputStream() { + return psc.getOutputStream(); } - throw new CVSAuthenticationException(ee.toString()); - } - break; - } - - // CVSROOT=":pserver:localhost:"+lport+""cvs_root - try{ - Properties prop=new Properties(); - prop.put("connection", "pserver"); - prop.put("user", location.getUsername()); - prop.put("password", password); - prop.put("host", "localhost"); - prop.put("port", Integer.toString(lport)); - prop.put("root", cvs_root); - CVSRepositoryLocation cvsrl=CVSRepositoryLocation.fromProperties(prop); - - IConnectionMethod method=cvsrl.getMethod(); - psc=method.createConnection(cvsrl, password); - } - catch(Exception e){ - throw new CVSAuthenticationException(e.toString()); - } - psc.open(monitor); - } - - class MyUserInfo implements UserInfo{ - private String username; - private String password; - private String passphrase; - MyUserInfo(String username){ - this.username=username; - } - public String getPassword(){ return password; } - public String getPassphrase(){ return passphrase; } - public boolean promptYesNo(String str){ - YesNoPrompt prompt=new YesNoPrompt(str); - Display.getDefault().syncExec(prompt); - return prompt.getResult()==SWT.YES; - } - public boolean promptPassphrase(String message){ - PassphrasePrompt prompt=new PassphrasePrompt(message); - Display.getDefault().syncExec(prompt); - String _passphrase=prompt.getPassphrase(); - if(_passphrase!=null)passphrase=_passphrase; - return _passphrase!=null; - } - public boolean promptPassword(String message){ - PasswordPrompt prompt=new PasswordPrompt(message); - Display.getDefault().syncExec(prompt); - String _password=prompt.getPassword(); - if(_password!=null)password=_password; - return _password!=null; - } - public void showMessage(final String foo){ - final Display display=Display.getCurrent(); - display.syncExec(new Runnable(){ - public void run(){ - Shell shell=new Shell(display); - MessageBox box=new MessageBox(shell,SWT.OK); - box.setMessage(foo); - box.open(); - shell.dispose(); - } - }); - } - - private class YesNoPrompt implements Runnable{ - private String prompt; - private int result; - YesNoPrompt(String prompt){ - this.prompt=prompt; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - MessageBox box=new MessageBox(shell,SWT.YES|SWT.NO); - box.setMessage(prompt); - result=box.open(); - shell.dispose(); - } - public int getResult(){ return result; } - } - private class PasswordPrompt implements Runnable{ - private String message; - private String password; - PasswordPrompt(String message){ - this.message=message; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - PasswordDialog dialog=new PasswordDialog(shell, message); - dialog.open(); - shell.dispose(); - password=dialog.getPassword(); - } - public String getPassword(){ - return password; - } - } - private class PassphrasePrompt implements Runnable{ - private String message; - private String passphrase; - PassphrasePrompt(String message){ - this.message=message; - } - public void run(){ - Display display=Display.getCurrent(); - Shell shell=new Shell(display); - PassphraseDialog dialog=new PassphraseDialog(shell, message); - dialog.open(); - shell.dispose(); - passphrase=dialog.getPassphrase(); - } - public String getPassphrase(){ - return passphrase; - } - } - } -} + public void open(IProgressMonitor monitor) throws IOException, CVSAuthenticationException { + monitor.subTask("PServerSSH2ServerConnection.open"); + monitor.worked(1); + String cvs_root = location.getRootDirectory(); + int cvs_port = location.getPort(); + if (cvs_port == 0) + cvs_port = 2401; + String cvs_host = location.getHost(); + String ssh_host = cvs_host; + String ssh_user = location.getUsername(); + + String host = cvs_host; + if (host.indexOf('@') != -1) { + cvs_host = host.substring(host.lastIndexOf('@') + 1); + host = host.substring(0, host.lastIndexOf('@')); + if (host.indexOf('@') != -1) { + ssh_host = host.substring(host.lastIndexOf('@') + 1); + if (ssh_host.length() == 0) + ssh_host = cvs_host; + ssh_user = host.substring(0, host.lastIndexOf('@')); + } else { + ssh_host = host; + } + } + + int ssh_port = 0; + if (ssh_host.indexOf('#') != -1) { + try { + ssh_port = Integer.parseInt(ssh_host.substring(ssh_host.lastIndexOf('#') + 1)); + ssh_host = ssh_host.substring(0, ssh_host.lastIndexOf('#')); + } catch (Exception e) { + } + } + + int lport = cvs_port; + String rhost = (cvs_host.equals(ssh_host) ? "localhost" : cvs_host); + int rport = cvs_port; + + // ssh -L lport:rhost:rport ssh_user@ssh_host + int retry = 1; + while (true) { + try { + session = JSchSession.getSession(location, ssh_user, "", ssh_host, ssh_port, monitor); + String[] list = session.getPortForwardingL(); + String name = ":" + rhost + ":" + rport; + boolean done = false; + for (int i = 0; i < list.length; i++) { + if (list[i].endsWith(name)) { + try { + String foo = list[i].substring(0, list[i].indexOf(':')); + lport = Integer.parseInt(foo); + } catch (Exception ee) { + } + done = true; + break; + } + } + if (!done) { + lport = localport++; + session.setPortForwardingL(lport, rhost, rport); + } + } catch (JSchException ee) { + if (!session.isConnected()) { + //System.out.println("sesssion is down"); + retry--; + if (retry < 0) { + throw new CVSAuthenticationException(ee.toString()); + } + continue; + } + throw new CVSAuthenticationException(ee.toString()); + } + break; + } + + // CVSROOT=":pserver:localhost:"+lport+""cvs_root + try { + Properties prop = new Properties(); + prop.put("connection", "pserver"); + prop.put("user", location.getUsername()); + prop.put("password", password); + prop.put("host", "localhost"); + prop.put("port", Integer.toString(lport)); + prop.put("root", cvs_root); + + CVSRepositoryLocation cvsrl = CVSRepositoryLocation.fromProperties(prop); + + IConnectionMethod method = cvsrl.getMethod(); + psc = method.createConnection(cvsrl, password); + } catch (Exception e) { + throw new CVSAuthenticationException(e.toString()); + } + psc.open(monitor); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PassphraseDialog.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PassphraseDialog.java deleted file mode 100644 index 3635ef6a0..000000000 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PassphraseDialog.java +++ /dev/null @@ -1,99 +0,0 @@ -/* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ -package org.eclipse.team.ccvs.ssh2; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -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.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.help.WorkbenchHelp; - -/** - * A dialog for prompting for a passphrase. - */ -public class PassphraseDialog extends Dialog { - protected Text passphraseField; - protected String passphrase = null; - - protected String message = null; - - public PassphraseDialog(Shell parentShell, String message) { - super(parentShell); - this.message = message; - } - - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(message); - } - - public void create() { - super.create(); - passphraseField.setFocus(); - } - - protected Control createDialogArea(Composite parent) { - Composite main=new Composite(parent, SWT.NONE); - - GridLayout layout=new GridLayout(); - layout.numColumns=3; - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); - - if (message!=null) { - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } - - createPassphraseFields(main); - return main; - } - - protected void createPassphraseFields(Composite parent) { - new Label(parent, SWT.NONE).setText("Passphrase:"); - passphraseField=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - passphraseField.setLayoutData(data); - passphraseField.setEchoChar('*'); - - new Label(parent, SWT.NONE); - } - - public String getPassphrase() { - return passphrase; - } - - protected void okPressed() { - String _passphrase = passphraseField.getText(); - if(_passphrase==null || _passphrase.length()==0){ - //messageLabel.setText("passphrase is not given."); - //messageLabel.setForeground(messageLabel.getDisplay().getSystemColor(SWT.COLOR_RED)); - return; - } - passphrase=_passphrase; - super.okPressed(); - } - protected void cancelPressed() { - passphrase=null; - super.cancelPressed(); - } -} diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PasswordDialog.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PasswordDialog.java deleted file mode 100644 index f3737f7b9..000000000 --- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/PasswordDialog.java +++ /dev/null @@ -1,98 +0,0 @@ -/* -*-mode:java; c-basic-offset:2; -*- */ -/********************************************************************** -Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation. -**********************************************************************/ -package org.eclipse.team.ccvs.ssh2; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -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.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.help.WorkbenchHelp; - -public class PasswordDialog extends Dialog { - - protected Text passwordField; - protected String password=null; - - protected String message=null; - - public PasswordDialog(Shell parentShell, String message) { - super(parentShell); - this.message=message; - } - - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(message); - } - - public void create() { - super.create(); - passwordField.setFocus(); - } - - protected Control createDialogArea(Composite parent) { - Composite main=new Composite(parent, SWT.NONE); - GridLayout layout=new GridLayout(); - layout.numColumns=3; - main.setLayout(layout); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); - - if (message!=null) { - Label messageLabel=new Label(main, SWT.WRAP); - messageLabel.setText(message); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.horizontalSpan=3; - messageLabel.setLayoutData(data); - } - - createPasswordFields(main); - return main; - } - - protected void createPasswordFields(Composite parent) { - new Label(parent, SWT.NONE).setText("Password:"); - - passwordField=new Text(parent, SWT.BORDER); - GridData data=new GridData(GridData.FILL_HORIZONTAL); - data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); - passwordField.setLayoutData(data); - passwordField.setEchoChar('*'); - - new Label(parent, SWT.NONE); - } - - public String getPassword() { - return password; - } - - protected void okPressed() { - String _password=passwordField.getText(); - if(_password==null || _password.length()==0){ - //messageLabel.setText("password is not given."); - //messageLabel.setForeground(messageLabel.getDisplay().getSystemColor(SWT.COLOR_RED)); - return; - } - password=_password; - super.okPressed(); - } - - protected void cancelPressed() { - password=null; - super.cancelPressed(); - } -} diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/Policy.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/Policy.java new file mode 100644 index 000000000..da74a9786 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/Policy.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.ccvs.ssh2; + + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Policy { + protected static ResourceBundle bundle = null; + + /** + * Creates a NLS catalog for the given locale. + */ + public static void localize(String bundleName) { + bundle = ResourceBundle.getBundle(bundleName); + } + + /** + * Gets a string from the resource bundle. We don't want to crash because of a missing String. + * Returns the key if not found. + */ + public static String bind(String key) { + try { + return bundle.getString(key); + } catch (MissingResourceException e) { + return key; + } catch (NullPointerException e) { + return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * Lookup the message with the given ID in this catalog and bind its + * substitution locations with the given string. + */ + public static String bind(String id, String binding) { + return bind(id, new String[] { binding }); + } + + /** + * Gets a string from the resource bundle and binds it with the given arguments. If the key is + * not found, return the key. + */ + public static String bind(String key, Object[] args) { + try { + return MessageFormat.format(bind(key), args); + } catch (MissingResourceException e) { + return key; + } catch (NullPointerException e) { + return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + +} diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/messages.properties b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/messages.properties new file mode 100644 index 000000000..f17784e7c --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/ccvs/ssh2/messages.properties @@ -0,0 +1,2 @@ +JSchSession.5=SSH2 Client +CVSSSH2ServerConnection.open=Opening SSH2 connection to {0}... diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java index b76026ac5..9d7ff4976 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkbenchUserAuthenticator.java @@ -11,7 +11,9 @@ package org.eclipse.team.internal.ccvs.ui; import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jface.dialogs.*; import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.team.core.IFileTypeInfo; @@ -144,4 +146,38 @@ public class WorkbenchUserAuthenticator implements IUserAuthenticator { userinfo.setPassword(result[0]); } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#prompt(org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, int, java.lang.String, java.lang.String, int[], int) + */ + public int prompt(ICVSRepositoryLocation location, final int promptType, final String title, final String message, final int[] promptResponses, final int defaultResponse) { + final Display display = CVSUIPlugin.getStandardDisplay(); + final int[] retval = new int[1]; + final String[] buttons = new String[promptResponses.length]; + for (int i = 0; i < promptResponses.length; i++) { + int prompt = promptResponses[i]; + switch(prompt) { + case IUserAuthenticator.OK_ID: buttons[i] = IDialogConstants.OK_LABEL; break; + case IUserAuthenticator.CANCEL_ID: buttons[i] = IDialogConstants.CANCEL_LABEL; break; + case IUserAuthenticator.NO_ID: buttons[i] = IDialogConstants.NO_LABEL; break; + case IUserAuthenticator.YES_ID: buttons[i] = IDialogConstants.YES_LABEL; break; + } + } + + display.syncExec(new Runnable() { + public void run() { + final MessageDialog dialog = new MessageDialog( + new Shell(display), + title, + null /* title image */, + message, + promptType, + buttons, + 1 + ); + retval[0] = dialog.open(); + } + }); + return retval[0]; + } } diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java index 63425949e..ee409b1f0 100644 --- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java @@ -180,12 +180,12 @@ public class CVSTestSetup extends TestSetup { // Validate that we can connect, also creates and caches the repository location. This // is important for the UI tests. CVSRepositoryLocation repository = (CVSRepositoryLocation)CVSProviderPlugin.getPlugin().getRepository(location); - + repository.setUserAuthenticator(new TestsUserAuthenticator()); repository.setReadLocation(READ_REPOSITORY_LOCATION); repository.setWriteLocation(WRITE_REPOSITORY_LOCATION); // Give some info about which repository the tests are running with - System.out.println("Connecting to: " + repository.getHost()); + System.out.println("Connecting to: " + repository.getHost() + ":" + repository.getMethod().getName()); try { try { diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java new file mode 100644 index 000000000..0b5a7fef1 --- /dev/null +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/TestsUserAuthenticator.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.tests.ccvs.core; + +import org.eclipse.team.internal.ccvs.core.*; + +/** + * A test authenticator that provide defaults for all methods. + */ +public class TestsUserAuthenticator implements IUserAuthenticator { + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#promptForUserInfo(org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, org.eclipse.team.internal.ccvs.core.IUserInfo, java.lang.String) + */ + public void promptForUserInfo(ICVSRepositoryLocation location, IUserInfo userInfo, String message) throws CVSException { + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.IUserAuthenticator#prompt(org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, int, java.lang.String, java.lang.String, int[], int) + */ + public int prompt(ICVSRepositoryLocation location, int promptType, String title, String message, int[] promptResponses, int defaultResponseIndex) { + return defaultResponseIndex; + } +} |