From f2a0641ca7800447bae1e343926ee746b01f0d35 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Fri, 29 May 2015 10:23:52 -0400 Subject: [PATCH] Add property for obtaining character encoding. Change-Id: I70a000215abd20c14192f63f908d1f42743c52a0 Signed-off-by: Greg Watson --- .../remote/core/IRemoteConnection.java | 13 +++++++--- .../local/LocalConnectionPropertyService.java | 2 ++ .../internal/jsch/core/JSchConnection.java | 26 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java index f8373156598..a71ec76a47f 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/core/IRemoteConnection.java @@ -26,6 +26,7 @@ import org.eclipse.remote.core.exception.RemoteConnectionException; public interface IRemoteConnection { /** * The interface that is extend by services provided for this remote connection. + * * @since 2.0 */ interface Service { @@ -44,6 +45,10 @@ public interface IRemoteConnection { final static String PATH_SEPARATOR_PROPERTY = "path.separator"; //$NON-NLS-1$ final static String LINE_SEPARATOR_PROPERTY = "line.separator"; //$NON-NLS-1$ final static String USER_HOME_PROPERTY = "user.home"; //$NON-NLS-1$ + /** + * @since 2.0 + */ + final static String LOCALE_CHARMAP_PROPERTY = "locale.charmap"; //$NON-NLS-1$ /** * Get the connection type of this connection @@ -63,9 +68,10 @@ public interface IRemoteConnection { /** * Get the service for this remote connection that implements the given interface. * - * @param service the interface the required service must implements + * @param service + * the interface the required service must implements * @return the desired service or null if there is no such service available - * @throws CoreException + * @throws CoreException * @since 2.0 */ T getService(Class service); @@ -73,7 +79,8 @@ public interface IRemoteConnection { /** * Does this connection support the given service. * - * @param service The service to be tested + * @param service + * The service to be tested * @return true if this connection supports the service * @since 2.0 */ diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java index 2ed4089a60a..db156d1ab4e 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/services/local/LocalConnectionPropertyService.java @@ -46,6 +46,8 @@ public class LocalConnectionPropertyService implements IRemoteConnectionProperty return RemoteCorePlugin.getDefault().getBundle().getBundleContext().getProperty("osgi.os"); //$NON-NLS-1$ case IRemoteConnection.OS_ARCH_PROPERTY: return RemoteCorePlugin.getDefault().getBundle().getBundleContext().getProperty("osgi.arch"); //$NON-NLS-1$ + case IRemoteConnection.LOCALE_CHARMAP_PROPERTY: + return System.getProperty("file.encoding"); //$NON-NLS-1$ } return System.getProperty(key); } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java index 8f4210e71ef..1ad80c127ce 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java @@ -257,7 +257,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC private boolean isFullySetup; // including sftp channel and environment private static final Map connectionMap = new HashMap<>(); - + public JSchConnection(IRemoteConnection connection) { fRemoteConnection = connection; fJSchService = Activator.getDefault().getService(); @@ -829,11 +829,17 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC String osVersion; String osArch; + String encoding; + String osName = executeCommand("uname", subMon.newChild(10)); //$NON-NLS-1$ - if (osName.equalsIgnoreCase("Linux")) { //$NON-NLS-1$ + switch (osName.toLowerCase()) { + case "linux": //$NON-NLS-1$ osArch = executeCommand("uname -m", subMon.newChild(10)); //$NON-NLS-1$ osVersion = executeCommand("uname -r", subMon.newChild(10)); //$NON-NLS-1$ - } else if (osName.equalsIgnoreCase("Darwin")) { //$NON-NLS-1$ + encoding = executeCommand("locale charmap", subMon.newChild(10)); //$NON-NLS-1$ + break; + + case "darwin": //$NON-NLS-1$ osName = executeCommand("sw_vers -productName", subMon.newChild(10)); //$NON-NLS-1$ osVersion = executeCommand("sw_vers -productVersion", subMon.newChild(10)); //$NON-NLS-1$ osArch = executeCommand("uname -m", subMon.newChild(10)); //$NON-NLS-1$ @@ -843,7 +849,10 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC osArch = "x86_64"; //$NON-NLS-1$ } } - } else if (osName.equalsIgnoreCase("AIX")) { //$NON-NLS-1$ + encoding = executeCommand("locale charmap", subMon.newChild(10)); //$NON-NLS-1$ + break; + + case "aix": //$NON-NLS-1$ osArch = executeCommand("uname -p", subMon.newChild(10)); //$NON-NLS-1$ osVersion = executeCommand("oslevel", subMon.newChild(10)); //$NON-NLS-1$ if (osArch.equalsIgnoreCase("powerpc")) { //$NON-NLS-1$ @@ -855,13 +864,20 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC osArch += "64"; //$NON-NLS-1$ } } - } else { + encoding = executeCommand("locale charmap", subMon.newChild(10)); //$NON-NLS-1$ + break; + + default: osVersion = "unknown"; //$NON-NLS-1$ osArch = "unknown"; //$NON-NLS-1$ + encoding = "unknown"; //$NON-NLS-1$ + break; } + fProperties.put(IRemoteConnection.OS_NAME_PROPERTY, osName); fProperties.put(IRemoteConnection.OS_VERSION_PROPERTY, osVersion); fProperties.put(IRemoteConnection.OS_ARCH_PROPERTY, osArch); + fProperties.put(IRemoteConnection.LOCALE_CHARMAP_PROPERTY, encoding); } private Session newSession(IProgressMonitor monitor) throws RemoteConnectionException {