diff options
author | Michael Rennie | 2007-07-30 18:57:46 +0000 |
---|---|---|
committer | Michael Rennie | 2007-07-30 18:57:46 +0000 |
commit | fe7a7a06ad6027c408352f65c1ab371178afa158 (patch) | |
tree | f4cc2e4d107018f6e43a9d9d4ec7371b58a86079 | |
parent | 4187589aa0293ff8ee67adc9e13cbc9c809ebf78 (diff) | |
download | eclipse.platform.debug-fe7a7a06ad6027c408352f65c1ab371178afa158.tar.gz eclipse.platform.debug-fe7a7a06ad6027c408352f65c1ab371178afa158.tar.xz eclipse.platform.debug-fe7a7a06ad6027c408352f65c1ab371178afa158.zip |
Bug 191379 Console encoding does not match workspace encoding
8 files changed, 88 insertions, 18 deletions
diff --git a/org.eclipse.debug.core/buildnotes_platform-debug.html b/org.eclipse.debug.core/buildnotes_platform-debug.html index 86af06b30..0b2c7ecc8 100644 --- a/org.eclipse.debug.core/buildnotes_platform-debug.html +++ b/org.eclipse.debug.core/buildnotes_platform-debug.html @@ -11,6 +11,13 @@ <h2>Summary of API changes in 3.4</h2> +<h3>July 31, 2007</h3> +<ul> +<li>A new method <code>ILaunchManager#getEncoding(ILaunchConfiguration)</code> was added to allow consumers of +the <code>DebugPlugin#ATTR_CONSOLE_ENCODING</code> preference to get the encoding to use when launching the +configuration specified in as the parameter to getEncoding(..)</li> +</ul> + <h2>July 31, 2007</h2> <h3>Problem Reports Fixed</h3> <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=198248">198248</a>: NPE at org.eclipse.debug.ui.CommonTab.getDefaultSharedConfigLocation<br> diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java index 224a9285f..08eb4a46c 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java @@ -749,7 +749,7 @@ public class DebugPlugin extends Plugin { * @param cmdLine the command line * @param workingDirectory the working directory, or <code>null</code> * @return the resulting process or <code>null</code> if the exec is - * cancelled + * canceled * @exception CoreException if the exec fails * @see Runtime * diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java index 606338fa2..15337bc05 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/ILaunchManager.java @@ -140,7 +140,25 @@ public interface ILaunchManager { * unable to resolve a variable in an environment variable's value * @since 3.0 */ - public String[] getEnvironment(ILaunchConfiguration configuration) throws CoreException; + public String[] getEnvironment(ILaunchConfiguration configuration) throws CoreException; + /** + * This method returns the character encoding to use when launching the specified <code>ILaunchConfiguration</code>. + * The returned encoding can be derived from one of three places in the following order: + * <ol> + * <li>An attribute saved on the configuration itself (where no attribute means use the default encoding).</li> + * <li>The mapped resources for the configuration, in the event one of them has a specific encoding that + * is not the workspace default. If there are more than one mapped resource we optimistically ask only the first resource + * for its encoding.</li> + * <li>We ask the <code>ResourcesPlugin</code> for the workspace preference (which resolves back to the system + * property <code>file.encoding</code> if the user has made no changes to the workspace encoding preference).</li> + * </ol> + * @param configuration the <code>ILaunchConfiguration</code> to get the encoding for + * @return the encoding to use when launching the specified <code>ILaunchConfiguration</code> + * @throws CoreException + * + * @since 3.4 + */ + public String getEncoding(ILaunchConfiguration configuration) throws CoreException; /** * Returns a handle to the launch configuration contained * in the specified file. The file is not verified to exist diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java index 646f933b3..cfa91171b 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java @@ -707,11 +707,7 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig } else { launch.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, null); } - String attribute = getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String)null); - if(attribute == null) { - attribute = ResourcesPlugin.getEncoding(); - } - launch.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, attribute); + launch.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, getLaunchManager().getEncoding(this)); // perform initial pre-launch sanity checks monitor.subTask(DebugCoreMessages.LaunchConfiguration_8); diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java index 9818763a8..160d7d4c4 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java @@ -865,7 +865,30 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe fLaunchConfigurationIndex.clear(); } } - + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchManager#getEncoding(org.eclipse.debug.core.ILaunchConfiguration) + */ + public String getEncoding(ILaunchConfiguration configuration) throws CoreException { + String encoding = configuration.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String)null); + if(encoding == null) { + IResource[] resources = configuration.getMappedResources(); + if(resources != null && resources.length > 0) { + IResource res = resources[0]; + if(res instanceof IFile) { + return ((IFile)res).getCharset(); + } + else if(res instanceof IContainer) { + return ((IContainer)res).getDefaultCharset(); + } + } + else { + return ResourcesPlugin.getEncoding(); + } + } + return encoding; + } + /** * The launch config name cache is cleared when a config is added, deleted or changed. */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties index ad2fc7d17..535e6a711 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties @@ -25,7 +25,7 @@ CommonTab_13=Select a Resource: CommonTab_14=Select a resource to redirect output to: CommonTab_0=Save as CommonTab_1=Console Encoding -CommonTab_2=Workspace Defa&ult ({0}) +CommonTab_2=Defa&ult - inherited ({0}) CommonTab_3=Oth&er CommonTab_4=Standard Input and Output CommonTab_5=&Allocate Console (necessary for input) diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java index d7c438552..f9b7adef0 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractLaunchConfigurationTab.java @@ -35,7 +35,6 @@ import org.eclipse.swt.widgets.Shell; * @since 2.0 */ public abstract class AbstractLaunchConfigurationTab implements ILaunchConfigurationTab { -// TODO Add in access methods for createGroup, createLabel and createSingleText from SWTFactory post 3.2 API freeze /** * The control for this page, or <code>null</code> diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java index 4bd64a577..f3234bb3d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java @@ -82,14 +82,14 @@ import com.ibm.icu.text.MessageFormat; * is stored in, whether it should appear in the favorites list, and perspective * switching behavior for an associated launch. * <p> - * Clients may instantiate this class. This class is not intended to be subclassed. + * Clients may instantiate this class. This class is not intended to be sub-classed. * </p> * @since 2.0 */ public class CommonTab extends AbstractLaunchConfigurationTab { /** - * Provides a persistable dialog for selecting the shared project location + * Provides a persistible dialog for selecting the shared project location * @since 3.2 */ class SharedLocationSelectionDialog extends ContainerSelectionDialog { @@ -113,7 +113,7 @@ public class CommonTab extends AbstractLaunchConfigurationTab { /** * This attribute exists solely for the purpose of making sure that invalid shared locations - * can be revertable. This attribute is not saveable and will never appear in a saved + * can be revertible. This attribute is not saveable and will never appear in a saved * launch configuration. * @since 3.3 */ @@ -328,15 +328,39 @@ public class CommonTab extends AbstractLaunchConfigurationTab { } /** + * Returns the default encoding for the specified config + * @param config + * @return the default encoding + * + * @since 3.4 + */ + private String getDefaultEncoding(ILaunchConfiguration config) { + try { + IResource[] resources = config.getMappedResources(); + if(resources != null && resources.length > 0) { + IResource res = resources[0]; + if(res instanceof IFile) { + return ((IFile)res).getCharset(); + } + else if(res instanceof IContainer) { + return ((IContainer)res).getDefaultCharset(); + } + } + } + catch(CoreException ce) { + DebugUIPlugin.log(ce); + } + return ResourcesPlugin.getEncoding(); + } + + /** * Creates the encoding component * @param parent the parent to add this composite to */ private void createEncodingComponent(Composite parent) { - List allEncodings = IDEEncoding.getIDEEncodings(); - String defaultEncoding = ResourcesPlugin.getEncoding(); Group group = SWTFactory.createGroup(parent, LaunchConfigurationsMessages.CommonTab_1, 2, 1, GridData.FILL_BOTH); - - fDefaultEncodingButton = createRadioButton(group, MessageFormat.format(LaunchConfigurationsMessages.CommonTab_2, new String[]{defaultEncoding})); + + fDefaultEncodingButton = createRadioButton(group, ""); //$NON-NLS-1$ GridData gd = new GridData(SWT.BEGINNING, SWT.NORMAL, true, false); gd.horizontalSpan = 2; fDefaultEncodingButton.setLayoutData(gd); @@ -347,6 +371,7 @@ public class CommonTab extends AbstractLaunchConfigurationTab { fEncodingCombo = new Combo(group, SWT.READ_ONLY); fEncodingCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fEncodingCombo.setFont(parent.getFont()); + List allEncodings = IDEEncoding.getIDEEncodings(); String[] encodingArray = (String[]) allEncodings.toArray(new String[0]); fEncodingCombo.setItems(encodingArray); if (encodingArray.length > 0) { @@ -538,7 +563,9 @@ public class CommonTab extends AbstractLaunchConfigurationTab { encoding = configuration.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String)null); } catch (CoreException e) { } - + String defaultEncoding = getDefaultEncoding(configuration); + fDefaultEncodingButton.setText(MessageFormat.format(LaunchConfigurationsMessages.CommonTab_2, new String[]{defaultEncoding})); + fDefaultEncodingButton.pack(); if (encoding != null) { fAltEncodingButton.setSelection(true); fDefaultEncodingButton.setSelection(false); |