1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-27 19:05:38 +02:00

Merge "Add property for obtaining character encoding."

This commit is contained in:
Greg Watson 2015-05-29 14:20:36 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit 76ac23a87f
3 changed files with 33 additions and 8 deletions

View file

@ -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 extends Service> T getService(Class<T> 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
*/

View file

@ -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);
}

View file

@ -257,7 +257,7 @@ public class JSchConnection implements IRemoteConnectionControlService, IRemoteC
private boolean isFullySetup; // including sftp channel and environment
private static final Map<IRemoteConnection, JSchConnection> 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 {