/** * 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()]); }
private void fireEvent(ICdtVariable vars[], int type) { for (ICdtVariable var : vars) { IPath path = getVariablePath(var); if (path != null) fireVariableChangeEvent(var.getName(), path, type); } }