Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 321588
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 53-59 Link Here
53
 org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;x-internal:=true,
53
 org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;x-internal:=true,
54
 org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;x-internal:=true,
54
 org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;x-internal:=true,
55
 org.eclipse.cdt.internal.core.dom.rewrite.util;x-internal:=true,
55
 org.eclipse.cdt.internal.core.dom.rewrite.util;x-internal:=true,
56
 org.eclipse.cdt.internal.core.envvar;x-friends:="org.eclipse.cdt.ui",
56
 org.eclipse.cdt.internal.core.envvar;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.managedbuilder.core",
57
 org.eclipse.cdt.internal.core.index;x-friends:="org.eclipse.cdt.ui",
57
 org.eclipse.cdt.internal.core.index;x-friends:="org.eclipse.cdt.ui",
58
 org.eclipse.cdt.internal.core.index.composite;x-internal:=true,
58
 org.eclipse.cdt.internal.core.index.composite;x-internal:=true,
59
 org.eclipse.cdt.internal.core.index.composite.c;x-internal:=true,
59
 org.eclipse.cdt.internal.core.index.composite.c;x-internal:=true,
(-)src/org/eclipse/cdt/internal/core/envvar/UserDefinedEnvironmentSupplier.java (-11 / +55 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 Intel Corporation and others.
2
 * Copyright (c) 2005, 2010 Intel Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-18 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.cdt.internal.core.envvar;
12
package org.eclipse.cdt.internal.core.envvar;
13
13
14
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.HashSet;
15
import java.util.Iterator;
16
import java.util.Iterator;
17
import java.util.Map;
16
import java.util.Set;
18
import java.util.Set;
17
19
18
import org.eclipse.cdt.core.CCorePlugin;
20
import org.eclipse.cdt.core.CCorePlugin;
Lines 35-43 Link Here
35
import org.osgi.service.prefs.Preferences;
37
import org.osgi.service.prefs.Preferences;
36
38
37
/**
39
/**
38
 * This is the Environment Variable Supplier used to supply variables
40
 * This is the Environment Variable Supplier used to supply and persist user 
39
 * defined by a user
41
 * defined variables.  Variables are stored in the context of a CDT {@link ICConfigurationDescription},
40
 * 
42
 * or, globally at the {@link IWorkspace} level.
43
 *
44
 * <p>
45
 * This class is Singleton held by {@link EnvironmentVariableManager}.
46
 *
47
 * <p>
48
 * It also allows temporary 'overriding' of variables. These are not persisted, but override
49
 * the values of any existing user-defined variable. This functionality is used by HeadlessBuilder
50
 * to temporarily override environment variables on the command line.
51
 *
41
 * @since 3.0
52
 * @since 3.0
42
 */
53
 */
43
public class UserDefinedEnvironmentSupplier extends 
54
public class UserDefinedEnvironmentSupplier extends 
Lines 56-63 Link Here
56
		};
67
		};
57
*/
68
*/
58
	private StorableEnvironment fWorkspaceVariables;
69
	private StorableEnvironment fWorkspaceVariables;
59
	
70
	private StorableEnvironment fOverrideVariables = new StorableEnvironment(false);
60
	
71
61
	static class VarKey {
72
	static class VarKey {
62
		private IEnvironmentVariable fVar;
73
		private IEnvironmentVariable fVar;
63
		private boolean fNameOnly;
74
		private boolean fNameOnly;
Lines 375-384 Link Here
375
	public IEnvironmentVariable getVariable(String name, Object context) {
386
	public IEnvironmentVariable getVariable(String name, Object context) {
376
		if(getValidName(name) == null)
387
		if(getValidName(name) == null)
377
			return null;
388
			return null;
389
		IEnvironmentVariable var = fOverrideVariables.getVariable(name);
378
		StorableEnvironment env = getEnvironment(context);
390
		StorableEnvironment env = getEnvironment(context);
379
		if(env == null)
391
		if (env == null)
380
			return null;
392
			return var;
381
		return env.getVariable(name);
393
		return EnvVarOperationProcessor.performOperation(env.getVariable(name), var);
382
	}
394
	}
383
395
384
	/* (non-Javadoc)
396
	/* (non-Javadoc)
Lines 388-396 Link Here
388
		StorableEnvironment env = getEnvironment(context);
400
		StorableEnvironment env = getEnvironment(context);
389
		if(env == null)
401
		if(env == null)
390
			return null;
402
			return null;
391
		return filterVariables(env.getVariables());
403
		IEnvironmentVariable[] override = filterVariables(fOverrideVariables.getVariables());
404
		IEnvironmentVariable[] normal = filterVariables(env.getVariables());
405
		return combineVariables(normal, override);
406
	}
407
408
	private IEnvironmentVariable[] combineVariables(IEnvironmentVariable[] oldVariables, IEnvironmentVariable[] newVariables) {
409
		Map<String, IEnvironmentVariable> vars = new HashMap<String, IEnvironmentVariable>(oldVariables.length + newVariables.length);
410
		for (IEnvironmentVariable variable : oldVariables)
411
			vars.put(variable.getName(), variable);
412
		for (IEnvironmentVariable variable : newVariables) {
413
			if (!vars.containsKey(variable.getName()))
414
				vars.put(variable.getName(), variable);
415
			else
416
				vars.put(variable.getName(), EnvVarOperationProcessor.performOperation(vars.get(variable.getName()), variable));
417
		}
418
		return vars.values().toArray(new IEnvironmentVariable[vars.size()]);
419
	}
420
421
	/**
422
	 * Add an environment variable 'override'. This variable won't be persisted but will instead 
423
	 * replace / remove / prepend / append any existing environment variable with the same name.
424
	 * This change is not persisted and remains for the current eclipse session.
425
	 *
426
	 * @param name Environment variable name
427
	 * @param value Environment variable value
428
	 * @param op one of the IBuildEnvironmentVariable.ENVVAR_* operation types
429
	 * @param delimiter delimiter to use or null for default
430
	 * @return Overriding IEnvironmentVariable or null if name is not valid 
431
	 */
432
	public IEnvironmentVariable createOverrideVariable(String name, String value, int op, String delimiter) {
433
		if (getValidName(name) == null)
434
			return null;
435
		return fOverrideVariables.createVariable(name,value,op,delimiter);
392
	}
436
	}
393
	
437
394
	public IEnvironmentVariable createVariable(String name, String value, int op, String delimiter, Object context){
438
	public IEnvironmentVariable createVariable(String name, String value, int op, String delimiter, Object context){
395
		if(getValidName(name) == null)
439
		if(getValidName(name) == null)
396
			return null;
440
			return null;
(-)src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuildMessages.java (+4 lines)
Lines 22-27 Link Here
22
	public static String HeadlessBuilder_cleaning_all_projects;
22
	public static String HeadlessBuilder_cleaning_all_projects;
23
	public static String HeadlessBuilder_CouldntLockWorkspace;
23
	public static String HeadlessBuilder_CouldntLockWorkspace;
24
	public static String HeadlessBuilder_Directory;
24
	public static String HeadlessBuilder_Directory;
25
	public static String HeadlessBuilder_EnvVar_Append;
26
	public static String HeadlessBuilder_EnvVar_Prepend;
27
	public static String HeadlessBuilder_EnvVar_Remove;
28
	public static String HeadlessBuilder_EnvVar_Replace;
25
	public static String HeadlessBuilder_Error;
29
	public static String HeadlessBuilder_Error;
26
	public static String HeadlessBuilder_importAll;
30
	public static String HeadlessBuilder_importAll;
27
	public static String HeadlessBuilder_IncludeFile;
31
	public static String HeadlessBuilder_IncludeFile;
(-)src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuildMessages.properties (-1 / +5 lines)
Lines 17-22 Link Here
17
HeadlessBuilder_cleaning_all_projects=Cleaning All Projects...
17
HeadlessBuilder_cleaning_all_projects=Cleaning All Projects...
18
HeadlessBuilder_CouldntLockWorkspace=Could not obtain lock for workspace location
18
HeadlessBuilder_CouldntLockWorkspace=Could not obtain lock for workspace location
19
HeadlessBuilder_Directory=Directory: 
19
HeadlessBuilder_Directory=Directory: 
20
HeadlessBuilder_EnvVar_Append=\ \ \ -Ea         {var=value} append value to environment variable when running all tools
21
HeadlessBuilder_EnvVar_Prepend=\ \ \ -Ep         {var=value} prepend value to environment variable when running all tools
22
HeadlessBuilder_EnvVar_Remove=\ \ \ -Er         {var} remove/unset the given environment variable
23
HeadlessBuilder_EnvVar_Replace=\ \ \ -E          {var=value} replace/add value to environment variable when running all tools 
20
HeadlessBuilder_Error=Error: 
24
HeadlessBuilder_Error=Error: 
21
HeadlessBuilder_invalid_argument=Invalid Arguments: 
25
HeadlessBuilder_invalid_argument=Invalid Arguments: 
22
HeadlessBuilder_is_not_accessible=\ is not accessible\!
26
HeadlessBuilder_is_not_accessible=\ is not accessible\!
Lines 36-42 Link Here
36
HeadlessBuilder_usage_build=\ \ \ -build      {project_name_reg_ex{/config_reg_ex} | all}
40
HeadlessBuilder_usage_build=\ \ \ -build      {project_name_reg_ex{/config_reg_ex} | all}
37
HeadlessBuilder_usage_clean_build=\ \ \ -cleanBuild {project_name_reg_ex{/config_reg_ex} | all}
41
HeadlessBuilder_usage_clean_build=\ \ \ -cleanBuild {project_name_reg_ex{/config_reg_ex} | all}
38
HeadlessBuilder_usage_import=\ \ \ -import     {[uri:/]/path/to/project}
42
HeadlessBuilder_usage_import=\ \ \ -import     {[uri:/]/path/to/project}
39
HeadlessBuilder_importAll=\ \ \ -importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI
43
HeadlessBuilder_importAll=\ \ \ -importAll  {[uri:/]/path/to/projectTreeURI} Import all projects under URI
40
HeadlessBuilder_IncludeFile=\ \ \ -include    {include_file} additional include_file to pass to tools
44
HeadlessBuilder_IncludeFile=\ \ \ -include    {include_file} additional include_file to pass to tools
41
HeadlessBuilder_InlucdePath=\ \ \ -I          {include_path} additional include_path to add to tools
45
HeadlessBuilder_InlucdePath=\ \ \ -I          {include_path} additional include_path to add to tools
42
HeadlessBuilder_invalid_uri=Invalid project URI:
46
HeadlessBuilder_invalid_uri=Invalid project URI:
(-)src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java (+30 lines)
Lines 28-33 Link Here
28
import java.util.regex.Pattern;
28
import java.util.regex.Pattern;
29
import java.util.regex.PatternSyntaxException;
29
import java.util.regex.PatternSyntaxException;
30
30
31
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
31
import org.eclipse.cdt.core.model.CoreModel;
32
import org.eclipse.cdt.core.model.CoreModel;
32
import org.eclipse.cdt.core.resources.ACBuilder;
33
import org.eclipse.cdt.core.resources.ACBuilder;
33
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
34
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
Lines 35-40 Link Here
35
import org.eclipse.cdt.core.settings.model.CMacroEntry;
36
import org.eclipse.cdt.core.settings.model.CMacroEntry;
36
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
37
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
37
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
38
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
39
import org.eclipse.cdt.internal.core.envvar.EnvironmentVariableManager;
38
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
40
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
39
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
41
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
40
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
42
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
Lines 76-81 Link Here
76
 *   - Add Include path to build :             -I          {include_path}
78
 *   - Add Include path to build :             -I          {include_path}
77
 *   - Add Include file to build :             -include    {include_file}
79
 *   - Add Include file to build :             -include    {include_file}
78
 *   - Add preprocessor define to build :      -D          {prepoc_define}
80
 *   - Add preprocessor define to build :      -D          {prepoc_define}
81
 *   - Replace environment variable in build : -E          {var=value}
82
 *   - Append environment variable to build :  -Ea         {var=value}
83
 *   - Prepend environment variable to build : -Ep         {var=value}
84
 *   - Remove environment variable in build :  -Er         {var}
79
 *
85
 *
80
 * Build output is automatically sent to stdout.
86
 * Build output is automatically sent to stdout.
81
 * @since 6.0
87
 * @since 6.0
Lines 480-485 Link Here
480
	 *   -I          {include_path} additional include_path to add to tools
486
	 *   -I          {include_path} additional include_path to add to tools
481
	 *   -include    {include_file} additional include_file to pass to tools
487
	 *   -include    {include_file} additional include_file to pass to tools
482
	 *   -D          {prepoc_define} addition preprocessor defines to pass to the tools
488
	 *   -D          {prepoc_define} addition preprocessor defines to pass to the tools
489
  	 *   -E			 {var=value} replace/add value to environment variable when running all tools
490
	 *   -Ea		 {var=value} append value to environment variable when running all tools
491
	 *   -Ep		 {var=value} prepend value to environment variable when running all tools
492
	 *   -Er         {var} remove/unset the given environment variable
483
	 *
493
	 *
484
	 * Each argument may be specified more than once
494
	 * Each argument may be specified more than once
485
	 * @param args String[] of arguments to parse
495
	 * @param args String[] of arguments to parse
Lines 510-515 Link Here
510
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludePathEntry(args[++i], 0));
520
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludePathEntry(args[++i], 0));
511
				} else if ("-include".equals(args[i])) { //$NON-NLS-1$
521
				} else if ("-include".equals(args[i])) { //$NON-NLS-1$
512
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludeFileEntry(args[++i], 0));
522
					HeadlessBuilderExternalSettingsProvider.additionalSettings.add(new CIncludeFileEntry(args[++i], 0));
523
				} else if ("-E".equals(args[i])) { //$NON-NLS-1$
524
					addEnvironmentVariable(args[++i], IEnvironmentVariable.ENVVAR_REPLACE);
525
				} else if ("-Ea".equals(args[i])) { //$NON-NLS-1$
526
					addEnvironmentVariable(args[++i], IEnvironmentVariable.ENVVAR_APPEND);
527
				} else if ("-Ep".equals(args[i])) { //$NON-NLS-1$
528
					addEnvironmentVariable(args[++i], IEnvironmentVariable.ENVVAR_PREPEND);
529
				} else if ("-Er".equals(args[i])) { //$NON-NLS-1$
530
					addEnvironmentVariable(args[++i], IEnvironmentVariable.ENVVAR_REMOVE);
513
				} else {
531
				} else {
514
					throw new Exception(HeadlessBuildMessages.HeadlessBuilder_unknown_argument + args[i]);
532
					throw new Exception(HeadlessBuildMessages.HeadlessBuilder_unknown_argument + args[i]);
515
				}
533
				}
Lines 526-531 Link Here
526
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_InlucdePath);
544
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_InlucdePath);
527
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_IncludeFile);
545
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_IncludeFile);
528
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_PreprocessorDefine);
546
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_PreprocessorDefine);
547
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_EnvVar_Replace);
548
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_EnvVar_Append);
549
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_EnvVar_Prepend);
550
			System.err.println(HeadlessBuildMessages.HeadlessBuilder_EnvVar_Remove);
529
			return false;
551
			return false;
530
		}
552
		}
531
553
Lines 544-549 Link Here
544
		return true;
566
		return true;
545
	}
567
	}
546
568
569
	private void addEnvironmentVariable(String string, int op) throws Exception {
570
		String[] parts = string.split("=", 2); //$NON-NLS-1$
571
		String name = parts[0];
572
		String value = ""; //$NON-NLS-1$
573
		if (parts.length > 1)
574
			value = parts[1];
575
		EnvironmentVariableManager.fUserSupplier.createOverrideVariable(name, value, op, null);
576
	}
547
577
548
	public void stop() {
578
	public void stop() {
549
	}
579
	}

Return to bug 321588