mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 15:15:25 +02:00
[229610] [api] File transfers should use workspace text file encoding
This commit is contained in:
parent
4c176f689d
commit
cc0d7dabcf
10 changed files with 96 additions and 23 deletions
|
@ -7,6 +7,7 @@
|
|||
* Contributors:
|
||||
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
|
||||
* David Dykstal (IBM) - [226728] NPE during init with clean workspace
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
********************************************************************************/
|
||||
package org.eclipse.rse.internal.core;
|
||||
|
||||
|
@ -15,6 +16,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -36,6 +38,7 @@ import org.eclipse.rse.core.model.ISystemProfile;
|
|||
import org.eclipse.rse.internal.core.model.SystemModelChangeEvent;
|
||||
import org.eclipse.rse.internal.core.model.SystemProfileManager;
|
||||
import org.eclipse.rse.logging.Logger;
|
||||
import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
|
||||
|
||||
/**
|
||||
* This is a job named "Initialize RSE". It is instantiated and run during
|
||||
|
@ -203,6 +206,16 @@ public final class RSEInitJob extends Job {
|
|||
}
|
||||
submonitor.done();
|
||||
}
|
||||
|
||||
// set the default encoding provider
|
||||
SystemEncodingUtil encodingUtil = SystemEncodingUtil.getInstance();
|
||||
encodingUtil.setDefaultEncodingProvider(
|
||||
new SystemEncodingUtil.DefaultEncodingProvider(){
|
||||
public String getLocalDefaultEncoding() {
|
||||
return ResourcesPlugin.getEncoding();
|
||||
}
|
||||
});
|
||||
|
||||
initializerPhase.done();
|
||||
// finish up - propogate cancel if necessary
|
||||
if (monitor.isCanceled()) {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
* David McKnight (IBM) - [224377] "open with" menu does not have "other" option
|
||||
* Kevin Doyle (IBM) - [224162] SystemEditableRemoteFile.saveAs does not work because FileServiceSubSytem.upload does invalid check
|
||||
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.files.ui.resources;
|
||||
|
@ -1523,11 +1524,12 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
}
|
||||
else {
|
||||
// using text mode so the char set needs to be local
|
||||
String localEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
if (properties.getLocalEncoding() != null){
|
||||
localEncoding = properties.getLocalEncoding();
|
||||
}
|
||||
file.setCharset(localEncoding, null);
|
||||
String localEncoding = properties.getLocalEncoding();
|
||||
file.setCharset(localEncoding, null);
|
||||
}
|
||||
|
||||
// otherwise, the default charset is inherited so no need to set
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
* Rupen Mardirossian (IBM) - [210682] Collisions when doing a copy operation across systems will us the SystemCopyDialog
|
||||
* Xuan Chen (IBM) - [229093] set charset of the temp file of the text remote file to its remote encoding
|
||||
* Rupen Mardirossian (IBM) - [198728] downloadResourcesToWorkspace now creates empty folders for copying across connections via createEmptyFolders method
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.files.ui.resources;
|
||||
|
@ -280,12 +281,12 @@ public class UniversalFileTransferUtility
|
|||
else
|
||||
{
|
||||
// using text mode so the char set needs to be local
|
||||
String localEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
SystemIFileProperties properties = new SystemIFileProperties(tempFile);
|
||||
if (properties.getLocalEncoding() != null){
|
||||
localEncoding = properties.getLocalEncoding();
|
||||
String localEncoding = properties.getLocalEncoding();
|
||||
tempFile.setCharset(localEncoding, null);
|
||||
}
|
||||
tempFile.setCharset(localEncoding, null);
|
||||
// otherwise, the default charset is inherited so no need to set
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -588,11 +589,11 @@ public class UniversalFileTransferUtility
|
|||
else
|
||||
{
|
||||
// using text mode so the char set needs to be local
|
||||
String localEncoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
if (properties.getLocalEncoding() != null){
|
||||
localEncoding = properties.getLocalEncoding();
|
||||
String localEncoding = properties.getLocalEncoding();
|
||||
tempFile.setCharset(localEncoding, null);
|
||||
}
|
||||
tempFile.setCharset(localEncoding, null);
|
||||
// otherwise, the default charset is inherited so no need to set
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -970,7 +971,8 @@ public class UniversalFileTransferUtility
|
|||
// copy remote file to workspace
|
||||
SystemUniversalTempFileListener listener = SystemUniversalTempFileListener.getListener();
|
||||
listener.addIgnoreFile(tempFile);
|
||||
String encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
String encoding = tempFile.getParent().getDefaultCharset();
|
||||
|
||||
download(srcFileOrFolder, tempFile, encoding, monitor);
|
||||
listener.removeIgnoreFile(tempFile);
|
||||
if (!tempFile.exists() && !tempFile.isSynchronized(IResource.DEPTH_ZERO))
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
* David McKnight (IBM) - [224377] "open with" menu does not have "other" option
|
||||
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
|
||||
* Rupen Mardirossian (IBM) - [198728] Folder being copied across systems is added to original set of files in order to extract empty (sub)folders in doDrop method
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.files.ui.view;
|
||||
|
@ -2569,9 +2570,9 @@ public class SystemViewRemoteFileAdapter
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
//System.out.println("how do we get here!??");
|
||||
|
||||
// Not sure how we can get here since if the source and target subsystems are different, then a doDrag() needs to
|
||||
// occur, resulting in a local resource (i.e. IFile) rather than a remote resource (i.e. IRemoteFile).
|
||||
// TODO investigate to see if we can get rid of this code
|
||||
if (srcFileOrFolder.isFile())
|
||||
{
|
||||
try
|
||||
|
@ -2597,6 +2598,7 @@ public class SystemViewRemoteFileAdapter
|
|||
String newPath = newPathBuf.toString();
|
||||
|
||||
monitor.subTask(copyMessage.getLevelOneText());
|
||||
|
||||
targetFS.upload(srcFileOrFolder.getAbsolutePath(), SystemEncodingUtil.ENCODING_UTF_8, newPath, System.getProperty("file.encoding"), monitor); //$NON-NLS-1$
|
||||
|
||||
result = targetFS.getRemoteFileObject(targetFolder, name, monitor);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Martin Oberhuber (Wind River) - [183824] Forward SystemMessageException from IRemoteFileSubsystem
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.internal.importexport.files;
|
||||
|
||||
|
@ -21,7 +22,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.rse.core.model.IHost;
|
||||
import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
|
||||
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
|
||||
import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility;
|
||||
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
|
||||
|
@ -99,7 +99,9 @@ class RemoteExporter {
|
|||
// for windows
|
||||
dest = dest.replace('/', sep);
|
||||
}
|
||||
rfss.upload(file.getLocation().makeAbsolute().toOSString(), SystemEncodingUtil.ENCODING_UTF_8, dest, System.getProperty("file.encoding"), new NullProgressMonitor()); //$NON-NLS-1$
|
||||
String localEncoding = file.getCharset();
|
||||
String hostEncoding = Utilities.getIRemoteFile(_host, dest).getEncoding();
|
||||
rfss.upload(file.getLocation().makeAbsolute().toOSString(), localEncoding, dest, hostEncoding, new NullProgressMonitor()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,10 +10,11 @@
|
|||
* Martin Oberhuber (Wind River) - [174945] split importexport icons from rse.ui
|
||||
* David McKnight (IBM) - [216252] [api][nls] Resource Strings specific to subsystems should be moved from rse.ui into files.ui / shells.ui / processes.ui where possible
|
||||
* David McKnight (IBM) - [223204] [cleanup] fix broken nls strings in files.ui and others
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.internal.importexport.files;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
imimport java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -49,7 +50,6 @@ import org.eclipse.rse.ui.SystemBasePlugin;
|
|||
import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
||||
import org.eclipse.ui.dialogs.ContainerGenerator;
|
||||
import org.eclipse.ui.dialogs.IOverwriteQuery;
|
||||
|
||||
// Similar to org.eclipse.ui.wizards.datatransfer.ImportOperation
|
||||
/**
|
||||
* An operation which does the actual work of copying objects from the local
|
||||
|
@ -463,7 +463,7 @@ public class RemoteFileImportOperation extends WorkspaceModifyOperation {
|
|||
// 030820: added the following kludge to circumvent problem in
|
||||
// artemis. (artemis 3 will fix this)
|
||||
// TODO remove for 6.0
|
||||
String encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
String encoding = ((UniFilePlus) fileObject).remoteFile.getEncoding();
|
||||
if (encoding.startsWith("CP")) //$NON-NLS-1$
|
||||
{
|
||||
encoding = "Cp" + encoding.substring(2); //$NON-NLS-1$
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* David McKnight (IBM) [215847]SystemEncodingUtil needs to convert to unsigned when checking xml file
|
||||
*
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.rse.services.clientserver;
|
||||
|
@ -31,6 +31,8 @@ public class SystemEncodingUtil {
|
|||
|
||||
private static SystemEncodingUtil instance;
|
||||
public static String ENCODING_UTF_8 = "UTF-8"; //$NON-NLS-1$
|
||||
|
||||
private DefaultEncodingProvider _defaultEncodingProvider = new DefaultEncodingProvider();
|
||||
|
||||
/**
|
||||
* Constructor to create the utility class.
|
||||
|
@ -52,6 +54,51 @@ public class SystemEncodingUtil {
|
|||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provider for the default encodings that RSE uses.
|
||||
* Clients may subclass this class, and override methods.
|
||||
* @since org.eclipse.rse.services 3.0
|
||||
*/
|
||||
public static class DefaultEncodingProvider {
|
||||
|
||||
/**
|
||||
* Return the default encoding for local workspace resources.
|
||||
* Clients may override.
|
||||
* @return String the local default encoding.
|
||||
*/
|
||||
public String getLocalDefaultEncoding() {
|
||||
return System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the default encoding provider.
|
||||
*
|
||||
* This is a system-wide change, and clients will not be notified
|
||||
* of changed default encodings due to changing the provider. Therefore,
|
||||
* changing the provider should be done only once during early system
|
||||
* startup.
|
||||
*
|
||||
* @param p the new encoding provider.
|
||||
*/
|
||||
public void setDefaultEncodingProvider(DefaultEncodingProvider p) {
|
||||
_defaultEncodingProvider = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local default encoding as provided by the default encoding
|
||||
* provider. This method should be called after RSE startup is complete
|
||||
* in order to get the proper default workspace encoding.
|
||||
*
|
||||
* @return the local default encoding
|
||||
*/
|
||||
public String getLocalDefaultEncoding() {
|
||||
return _defaultEncodingProvider.getLocalDefaultEncoding();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the encoding of the environment. This is the encoding being used by the JVM,
|
||||
* which by default is the machine encoding, unless changed explicitly.
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.util.List;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
import org.eclipse.rse.services.AbstractService;
|
||||
import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
|
||||
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
|
||||
|
||||
|
||||
|
@ -186,7 +187,7 @@ public abstract class AbstractFileService extends AbstractService implements IFi
|
|||
* @since 2.0
|
||||
*/
|
||||
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException {
|
||||
return System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
return SystemEncodingUtil.getInstance().getLocalDefaultEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,6 +75,7 @@ import org.eclipse.rse.services.clientserver.FileTypeMatcher;
|
|||
import org.eclipse.rse.services.clientserver.IClientServerConstants;
|
||||
import org.eclipse.rse.services.clientserver.IMatcher;
|
||||
import org.eclipse.rse.services.clientserver.NamePatternMatcher;
|
||||
import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
|
||||
import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage;
|
||||
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
||||
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
|
||||
|
@ -1466,7 +1467,7 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
|||
return encoding;
|
||||
}
|
||||
else {
|
||||
return System.getProperty("file.encoding"); //$NON-NLS-1$
|
||||
return SystemEncodingUtil.getInstance().getLocalDefaultEncoding();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
|
||||
* Martin Oberhuber (Wind River) - [186779] Fix IRSESystemType.getAdapter()
|
||||
* Martin Oberhuber (Wind River) - [175680] Deprecate obsolete ISystemRegistry methods
|
||||
* David McKnight (IBM) - [229610] [api] File transfers should use workspace text file encoding
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.ui;
|
||||
|
@ -49,6 +50,7 @@ import org.eclipse.rse.core.model.IHost;
|
|||
import org.eclipse.rse.core.model.ISystemProfile;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
import org.eclipse.rse.internal.ui.SystemResources;
|
||||
import org.eclipse.rse.services.clientserver.SystemEncodingUtil;
|
||||
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
||||
import org.eclipse.rse.ui.dialogs.ISystemPromptDialog;
|
||||
import org.eclipse.rse.ui.dialogs.SystemPromptDialog;
|
||||
|
@ -959,7 +961,8 @@ public class SystemConnectionForm implements Listener, SelectionListener, Runnab
|
|||
otherEncodingCombo.setText(defaultEncoding);
|
||||
}
|
||||
else {
|
||||
otherEncodingCombo.setText(System.getProperty("file.encoding")); //$NON-NLS-1$
|
||||
String workspaceDefault = SystemEncodingUtil.getInstance().getLocalDefaultEncoding();
|
||||
otherEncodingCombo.setText(workspaceDefault); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue