From 28efe5b06a5851a4ebbe5484acb0fdcb768da791 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Fri, 29 Oct 2004 15:16:45 +0000 Subject: [PATCH] rollback getEnv old methods added new getEnv methods that use new constants to fix backward compatability issue --- .../cdt/launch/AbstractCLaunchDelegate.java | 102 +++++++++++++----- .../internal/LocalRunLaunchDelegate.java | 4 +- .../internal/ui/MigratingCEnvironmentTab.java | 3 - .../cdt/launch/ui/CEnvironmentTab.java | 3 + 4 files changed, 81 insertions(+), 31 deletions(-) diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java index e92013145b1..35103a9bcc9 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java @@ -21,6 +21,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Map.Entry; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; @@ -74,31 +75,6 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat abstract public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException; - /** - * Return the save environment variables in the configuration. The array - * does not include the default environment of the target. array[n] : - * name=value - * @throws CoreException - */ - protected String[] getEnvironmentArray(ILaunchConfiguration config) throws CoreException { - try { - // Migrate old env settings to new. - Map map = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); - if (map != null) { - ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); - wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map); - wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); - wc.doSave(); - } - } catch (CoreException e) { - } - String[] array = DebugPlugin.getDefault().getLaunchManager().getEnvironment(config); - if (array == null) { - return new String[0]; - } - return array; - } - /** * Returns the working directory specified by the given launch * configuration, or null if none. @@ -783,7 +759,7 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat * @return * @throws CoreException */ - protected Properties getEnvironmentProperty(ILaunchConfiguration config) throws CoreException { + protected Properties getEnvironmentAsProperty(ILaunchConfiguration config) throws CoreException { String[] envp = getEnvironmentArray(config); Properties p = new Properties( ); for( int i = 0; i < envp.length; i++ ) { @@ -799,4 +775,78 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat return p; } + /** + * Return the save environment variables in the configuration. The array + * does not include the default environment of the target. array[n] : + * name=value + * @throws CoreException + */ + protected String[] getEnvironment(ILaunchConfiguration config) throws CoreException { + try { + // Migrate old env settings to new. + Map map = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); + ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); + if (map != null) { + wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map); + wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); + config = wc.doSave(); + } + boolean append = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_INHERIT, true); + wc.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, append); + } catch (CoreException e) { + } + String[] array = DebugPlugin.getDefault().getLaunchManager().getEnvironment(config); + if (array == null) { + return new String[0]; + } + return array; + } + + /** + * Return the save environment variables in the configuration. The array + * does not include the default environment of the target. array[n] : + * name=value + * @deprecated + */ + protected String[] getEnvironmentArray(ILaunchConfiguration config) { + Map env = null; + try { + env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); + } catch (CoreException e) { + } + if (env == null) { + return new String[0]; + } + String[] array = new String[env.size()]; + Iterator entries = env.entrySet().iterator(); + Entry entry; + for (int i = 0; entries.hasNext() && i < array.length; i++) { + entry = (Entry)entries.next(); + array[i] = ((String)entry.getKey()) + "=" + ((String)entry.getValue()); //$NON-NLS-1$ + } + return array; + } + + /** + * Return the save environment variables of this configuration. The array + * does not include the default environment of the target. + * @deprecated + */ + protected Properties getEnvironmentProperty(ILaunchConfiguration config) { + Properties prop = new Properties(); + Map env = null; + try { + env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null); + } catch (CoreException e) { + } + if (env == null) + return prop; + Iterator entries = env.entrySet().iterator(); + Entry entry; + while (entries.hasNext()) { + entry = (Entry)entries.next(); + prop.setProperty((String)entry.getKey(), (String)entry.getValue()); + } + return prop; + } } \ No newline at end of file diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java index 4f5ca56c272..ffa492fe798 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java @@ -79,7 +79,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate { if (wd != null) { opt.setWorkingDirectory(wd.getAbsolutePath()); } - opt.setEnvironment(getEnvironmentProperty(config)); + opt.setEnvironment(getEnvironmentAsProperty(config)); } } catch (CDIException e) { abort( @@ -120,7 +120,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate { command.addAll(Arrays.asList(arguments)); String[] commandArray = (String[]) command.toArray(new String[command.size()]); monitor.worked(5); - Process process = exec(commandArray, getEnvironmentArray(config), wd); + Process process = exec(commandArray, getEnvironment(config), wd); monitor.worked(3); DebugPlugin.newProcess(launch, process, renderProcessLabel(commandArray[0])); } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java index cadbe75a28a..e58a18a8851 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/MigratingCEnvironmentTab.java @@ -17,10 +17,7 @@ import org.eclipse.debug.ui.EnvironmentTab; /** - * @author DInglis * @deprecated - temporary class for while configs are migrated to new EnvironmentTab - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments */ public class MigratingCEnvironmentTab extends EnvironmentTab { diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CEnvironmentTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CEnvironmentTab.java index f25fc57c9df..764b5e5d746 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CEnvironmentTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CEnvironmentTab.java @@ -63,6 +63,9 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.help.WorkbenchHelp; +/** + * @deprecated + */ public class CEnvironmentTab extends CLaunchConfigurationTab { protected Properties fElements;