private IEnvironmentVariable[] combineVariables( IEnvironmentVariable[] oldVariables, IEnvironmentVariable[] newVariables) { Map<String, IEnvironmentVariable> vars = new HashMap<String, IEnvironmentVariable>(oldVariables.length + newVariables.length); for (IEnvironmentVariable variable : oldVariables) vars.put(variable.getName(), variable); for (IEnvironmentVariable variable : newVariables) { if (!vars.containsKey(variable.getName())) vars.put(variable.getName(), variable); else vars.put( variable.getName(), EnvVarOperationProcessor.performOperation(vars.get(variable.getName()), variable)); } return vars.values().toArray(new IEnvironmentVariable[vars.size()]); }
/** * Gets the CDT environment from the CDT project's configuration referenced by the launch * * @since 3.0 */ public static String[] getLaunchEnvironment(ILaunchConfiguration config) throws CoreException { // Get the project String projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null); if (projectName == null) { return null; } projectName = projectName.trim(); if (projectName.length() == 0) { return null; } IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project == null || !project.isAccessible()) return null; ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, false); // Not a CDT project? if (projDesc == null) return null; String buildConfigID = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); // $NON-NLS-1$ ICConfigurationDescription cfg = null; if (buildConfigID.length() != 0) cfg = projDesc.getConfigurationById(buildConfigID); // if configuration is null fall-back to active if (cfg == null) cfg = projDesc.getActiveConfiguration(); // Environment variables and inherited vars HashMap<String, String> envMap = new HashMap<String, String>(); IEnvironmentVariable[] vars = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(cfg, true); for (IEnvironmentVariable var : vars) envMap.put(var.getName(), var.getValue()); // Add variables from build info ICdtVariable[] build_vars = CCorePlugin.getDefault().getCdtVariableManager().getVariables(cfg); for (ICdtVariable var : build_vars) { try { envMap.put(var.getName(), var.getStringValue()); } catch (CdtVariableException e) { // Some Eclipse dynamic variables can't be resolved dynamically... we don't care. } } // Turn it into an envp format List<String> strings = new ArrayList<String>(envMap.size()); for (Entry<String, String> entry : envMap.entrySet()) { StringBuffer buffer = new StringBuffer(entry.getKey()); buffer.append('=').append(entry.getValue()); strings.add(buffer.toString()); } return strings.toArray(new String[strings.size()]); }
public IEnvironmentVariable[] getVariables(ICConfigurationDescription des) { EnvVarCollector cr = EnvironmentVariableManager.getVariables(getContextInfo(des), true); if (cr != null) { EnvVarDescriptor collected[] = cr.toArray(true); List<IEnvironmentVariable> vars = new ArrayList<IEnvironmentVariable>(collected.length); IEnvironmentVariable var; IEnvironmentContextInfo info = new DefaultEnvironmentContextInfo(des); // getContextInfo(des); for (int i = 0; i < collected.length; i++) { var = collected[i]; var = EnvironmentVariableManager.getVariable(var.getName(), info, true); if (var != null) vars.add(var); } return vars.toArray(new EnvVarDescriptor[vars.size()]); } return new EnvVarDescriptor[0]; }
public IEnvironmentVariable addVariable( IEnvironmentVariable var, ICConfigurationDescription des) { return addVariable(var.getName(), var.getValue(), var.getOperation(), var.getDelimiter(), des); }