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