1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

rollback getEnv old methods added new getEnv methods that use new constants to fix backward compatability issue

This commit is contained in:
David Inglis 2004-10-29 15:16:45 +00:00
parent a4c551bbd7
commit 28efe5b06a
4 changed files with 81 additions and 31 deletions

View file

@ -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 <code>null</code> 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;
}
}

View file

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

View file

@ -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 {

View file

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