mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Some modifications and fixes for the build Environment and Macros were added
This commit is contained in:
parent
4fd7b386b2
commit
fa2c1a50ab
18 changed files with 604 additions and 159 deletions
|
@ -47,7 +47,7 @@ public interface IEnvironmentVariableProvider{
|
|||
* 4. null to represent the system environment passed to eclipse
|
||||
*/
|
||||
public IBuildEnvironmentVariable getVariable(
|
||||
String variableName, Object level, boolean includeParentLevels);
|
||||
String variableName, Object level, boolean includeParentLevels, boolean resolveMacros);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -58,7 +58,7 @@ public interface IEnvironmentVariableProvider{
|
|||
* @return the array of IBuildEnvironmentVariable that represents the environment variables
|
||||
*/
|
||||
public IBuildEnvironmentVariable[] getVariables(
|
||||
Object level, boolean includeParentLevels);
|
||||
Object level, boolean includeParentLevels, boolean resolveMacros);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -743,19 +743,13 @@ public class GeneratedMakefileBuilder extends ACBuilder {
|
|||
launcher.showCommand(true);
|
||||
|
||||
// Set the environmennt
|
||||
IBuildEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true);
|
||||
IBuildMacroProvider macroProvier = ManagedBuildManager.getBuildMacroProvider();
|
||||
IBuildEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true,true);
|
||||
String[] env = null;
|
||||
ArrayList envList = new ArrayList();
|
||||
if (variables != null) {
|
||||
for(int i = 0; i < variables.length; i++){
|
||||
//resolve the build macros in environment variables
|
||||
try{
|
||||
envList.add(variables[i].getName() + "=" + macroProvier.resolveValue(variables[i].getValue(),""," ",IBuildMacroProvider.CONTEXT_CONFIGURATION,cfg)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
} catch(BuildMacroException e) {
|
||||
envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
env = (String[]) envList.toArray(new String[envList.size()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1098,7 +1098,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
|
|||
*/
|
||||
private String getCWD() {
|
||||
String cwd = ""; //$NON-NLS-1$
|
||||
IBuildEnvironmentVariable cwdvar = ManagedBuildManager.getEnvironmentVariableProvider().getVariable("CWD", getDefaultConfiguration(), false); //$NON-NLS-1$
|
||||
IBuildEnvironmentVariable cwdvar = ManagedBuildManager.getEnvironmentVariableProvider().getVariable("CWD", getDefaultConfiguration(), false, true); //$NON-NLS-1$
|
||||
if (cwdvar != null) { cwd = cwdvar.getValue().replace('\\','/'); } //$NON-NLS-1$ //$NON-NLS-2$
|
||||
return cwd;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ public class EnvVarCollector {
|
|||
* @param vars
|
||||
*/
|
||||
public void add(IBuildEnvironmentVariable vars[]){
|
||||
add(vars,null,-1);
|
||||
}
|
||||
|
||||
public void add(IBuildEnvironmentVariable vars[], IContextInfo info, int num){
|
||||
if(vars == null)
|
||||
return;
|
||||
boolean isCaseInsensitive = !EnvironmentVariableProvider.getDefault().isVariableCaseSensitive();
|
||||
|
@ -55,11 +59,15 @@ public class EnvVarCollector {
|
|||
fMap = new HashMap();
|
||||
}
|
||||
|
||||
if(noCheck)
|
||||
fMap.put(name,var);
|
||||
EnvVarDescriptor des = null;
|
||||
if(noCheck || (des = (EnvVarDescriptor)fMap.get(name)) == null){
|
||||
des = new EnvVarDescriptor(var,info,num);
|
||||
fMap.put(name,des);
|
||||
}
|
||||
else {
|
||||
IBuildEnvironmentVariable prevVar = (IBuildEnvironmentVariable)fMap.remove(name);
|
||||
fMap.put(name,EnvVarOperationProcessor.performOperation(prevVar,var));
|
||||
des.setContextInfo(info);
|
||||
des.setSupplierNum(num);
|
||||
des.setVariable(EnvVarOperationProcessor.performOperation(des.getOriginalVariable(),var));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,19 +78,19 @@ public class EnvVarCollector {
|
|||
* @param includeRemoved true if removed variables should be included in the resulting array
|
||||
* @return IBuildEnvironmentVariable[]
|
||||
*/
|
||||
public IBuildEnvironmentVariable[] toArray(boolean includeRemoved){
|
||||
public EnvVarDescriptor[] toArray(boolean includeRemoved){
|
||||
if(fMap == null)
|
||||
return new IBuildEnvironmentVariable[0];
|
||||
return new EnvVarDescriptor[0];
|
||||
Collection values = fMap.values();
|
||||
List list = new ArrayList();
|
||||
Iterator iter = values.iterator();
|
||||
while(iter.hasNext()){
|
||||
IBuildEnvironmentVariable var = (IBuildEnvironmentVariable)iter.next();
|
||||
if(var != null &&
|
||||
(includeRemoved || var.getOperation() != IBuildEnvironmentVariable.ENVVAR_REMOVE))
|
||||
list.add(var);
|
||||
EnvVarDescriptor des = (EnvVarDescriptor)iter.next();
|
||||
if(des != null &&
|
||||
(includeRemoved || des.getOperation() != IBuildEnvironmentVariable.ENVVAR_REMOVE))
|
||||
list.add(des);
|
||||
}
|
||||
return (IBuildEnvironmentVariable[])list.toArray(new IBuildEnvironmentVariable[list.size()]);
|
||||
return (EnvVarDescriptor[])list.toArray(new EnvVarDescriptor[list.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,14 +99,14 @@ public class EnvVarCollector {
|
|||
* @param name a variable name
|
||||
* @return IBuildEnvironmentVariable
|
||||
*/
|
||||
public IBuildEnvironmentVariable getVariable(String name){
|
||||
public EnvVarDescriptor getVariable(String name){
|
||||
if(fMap == null)
|
||||
return null;
|
||||
|
||||
if(!EnvironmentVariableProvider.getDefault().isVariableCaseSensitive())
|
||||
name = name.toUpperCase();
|
||||
|
||||
return (IBuildEnvironmentVariable)fMap.get(name);
|
||||
return (EnvVarDescriptor)fMap.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +115,7 @@ public class EnvVarCollector {
|
|||
*
|
||||
* @return IBuildEnvironmentVariable[]
|
||||
*/
|
||||
public IBuildEnvironmentVariable[] getVariables(){
|
||||
public EnvVarDescriptor[] getVariables(){
|
||||
return toArray(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.managedbuilder.internal.envvar;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
|
||||
|
||||
/*
|
||||
* this class represents the environment variable-relaed information.
|
||||
* That is the context for which the variable is defined and the supplier
|
||||
* that supplies the variable
|
||||
*
|
||||
*/
|
||||
public class EnvVarDescriptor implements IBuildEnvironmentVariable{
|
||||
private IBuildEnvironmentVariable fVariable;
|
||||
private IContextInfo fContextInfo;
|
||||
private int fSupplierNum;
|
||||
|
||||
public EnvVarDescriptor(IBuildEnvironmentVariable variable, IContextInfo contextInfo, int supplierNum){
|
||||
fVariable = variable;
|
||||
fContextInfo = contextInfo;
|
||||
fSupplierNum = supplierNum;
|
||||
}
|
||||
|
||||
public IContextInfo getContextInfo() {
|
||||
return fContextInfo;
|
||||
}
|
||||
|
||||
public int getSupplierNum() {
|
||||
return fSupplierNum;
|
||||
}
|
||||
|
||||
public IBuildEnvironmentVariable getOriginalVariable() {
|
||||
return fVariable;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return fVariable.getName();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return fVariable.getValue();
|
||||
}
|
||||
|
||||
public int getOperation() {
|
||||
return fVariable.getOperation();
|
||||
}
|
||||
|
||||
public String getDelimiter() {
|
||||
return fVariable.getDelimiter();
|
||||
}
|
||||
|
||||
public void setContextInfo(IContextInfo contextInfo) {
|
||||
fContextInfo = contextInfo;
|
||||
}
|
||||
|
||||
public void setSupplierNum(int supplierNum) {
|
||||
fSupplierNum = supplierNum;
|
||||
}
|
||||
|
||||
public void setVariable(IBuildEnvironmentVariable variable) {
|
||||
fVariable = variable;
|
||||
}
|
||||
|
||||
/* public String getResolvedValue(int contextType, Object contextData){
|
||||
String value = null;
|
||||
if(getOperation() != IBuildEnvironmentVariable.ENVVAR_REMOVE){
|
||||
String name = getName();
|
||||
value = getValue();
|
||||
if(value != null && value.length() > 0){
|
||||
int supplierNum = -1;
|
||||
IMacroContextInfo macroInfo = getMacroContextInfo(fContextInfo);
|
||||
IBuildMacroSupplier macroSuppliers[] = macroInfo.getSuppliers();
|
||||
for(int i = 0; i < macroSuppliers.length; i++){
|
||||
if(macroSuppliers[i] instanceof EnvironmentMacroSupplier){
|
||||
supplierNum = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DefaultMacroSubstitutor sub = new DefaultMacroSubstitutor(new DefaultMacroContextInfo(contextType,contextData),""," ");//,delimiters,""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
try{
|
||||
value = sub.resolveToString(new BuildMacro(name,IBuildMacro.VALUE_TEXT,value),macroInfo,supplierNum);
|
||||
} catch (BuildMacroException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected IMacroContextInfo getMacroContextInfo(IContextInfo info){
|
||||
Object context = info.getContext();
|
||||
if(context instanceof IConfiguration)
|
||||
return new DefaultMacroContextInfo(IBuildMacroProvider.CONTEXT_CONFIGURATION,context);
|
||||
else if(context instanceof IManagedProject)
|
||||
return new DefaultMacroContextInfo(IBuildMacroProvider.CONTEXT_PROJECT,context);
|
||||
else if(context instanceof IWorkspace)
|
||||
return new DefaultMacroContextInfo(IBuildMacroProvider.CONTEXT_WORKSPACE,context);
|
||||
else if(context == null)
|
||||
return new DefaultMacroContextInfo(IBuildMacroProvider.CONTEXT_ECLIPSEENV,context);
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -19,12 +19,23 @@ import java.util.List;
|
|||
import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
|
||||
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.core.ITool;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.DefaultMacroContextInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.DefaultMacroSubstitutor;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.EnvironmentMacroSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.IMacroContextInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor;
|
||||
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +55,8 @@ public class EnvironmentVariableProvider implements
|
|||
private static EnvironmentVariableProvider fInstance = null;
|
||||
private List fListeners = null;
|
||||
|
||||
private EnvVarMacroSubstitutor fMacroSubstitutor;
|
||||
|
||||
private StoredBuildPathEnvironmentContainer fIncludeStoredBuildPathVariables;
|
||||
private StoredBuildPathEnvironmentContainer fLibraryStoredBuildPathVariables;
|
||||
|
||||
|
@ -79,6 +92,55 @@ public class EnvironmentVariableProvider implements
|
|||
|
||||
}
|
||||
|
||||
public class EnvVarMacroSubstitutor extends DefaultMacroSubstitutor {
|
||||
private String fDefaultDelimiter;
|
||||
public EnvVarMacroSubstitutor(int contextType, Object contextData, String inexistentMacroValue, String listDelimiter){
|
||||
super(contextType,contextData,inexistentMacroValue,listDelimiter);
|
||||
fDefaultDelimiter = listDelimiter;
|
||||
}
|
||||
|
||||
public EnvVarMacroSubstitutor(IMacroContextInfo contextInfo, String inexistentMacroValue, String listDelimiter){
|
||||
super(contextInfo, inexistentMacroValue, listDelimiter, null ,inexistentMacroValue);
|
||||
fDefaultDelimiter = listDelimiter;
|
||||
}
|
||||
|
||||
public IBuildEnvironmentVariable resolveVariable(EnvVarDescriptor var) throws BuildMacroException {
|
||||
String value;
|
||||
if(var == null || (value = var.getValue()) == null || value.length() == 0 || var.getOperation() == IBuildEnvironmentVariable.ENVVAR_REMOVE)
|
||||
return var;
|
||||
|
||||
String listDelimiter = var.getDelimiter();
|
||||
if(listDelimiter == null)
|
||||
listDelimiter = fDefaultDelimiter;
|
||||
setListDelimiter(listDelimiter);
|
||||
IBuildMacro macro = EnvironmentMacroSupplier.getInstance().createBuildMacro(var);
|
||||
IMacroContextInfo varMacroInfo = getVarMacroContextInfo(var);
|
||||
int varSupplierNum = getVarMacroSupplierNum(var,varMacroInfo);
|
||||
value = resolveToString(new MacroDescriptor(macro,varMacroInfo,varSupplierNum));
|
||||
removeResolvedMacro(var.getName());
|
||||
return new BuildEnvVar(var.getName(),value,var.getOperation(),var.getDelimiter());
|
||||
}
|
||||
|
||||
protected IMacroContextInfo getVarMacroContextInfo(EnvVarDescriptor var){
|
||||
IContextInfo info = var.getContextInfo();
|
||||
if(info != null)
|
||||
return getMacroContextInfoForContext(info.getContext());
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int getVarMacroSupplierNum(EnvVarDescriptor var, IMacroContextInfo varMacroInfo){
|
||||
int varSupplierNum = -1;
|
||||
IBuildMacroSupplier macroSuppliers[] = varMacroInfo.getSuppliers();
|
||||
for(int i = 0; i < macroSuppliers.length; i++){
|
||||
if(macroSuppliers[i] instanceof EnvironmentMacroSupplier){
|
||||
varSupplierNum = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return varSupplierNum;
|
||||
}
|
||||
}
|
||||
|
||||
protected EnvironmentVariableProvider(){
|
||||
|
||||
}
|
||||
|
@ -94,17 +156,16 @@ public class EnvironmentVariableProvider implements
|
|||
* the context information is taken from the contextInfo passed
|
||||
* @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo
|
||||
*/
|
||||
public IBuildEnvironmentVariable getVariable(String variableName,
|
||||
public EnvVarDescriptor getVariable(String variableName,
|
||||
IContextInfo contextInfo, boolean includeParentLevels){
|
||||
|
||||
if(contextInfo == null)
|
||||
return null;
|
||||
if(variableName == null || "".equals(variableName = variableName.trim())) //$NON-NLS-1$
|
||||
if((variableName = EnvVarOperationProcessor.normalizeName(variableName)) == null) //$NON-NLS-1$
|
||||
return null;
|
||||
|
||||
|
||||
IContextInfo infos[] = getAllContextInfos(contextInfo);
|
||||
variableName = adjustName(variableName);
|
||||
|
||||
if(!includeParentLevels){
|
||||
IEnvironmentVariableSupplier suppliers[] = infos[0].getSuppliers();
|
||||
|
@ -120,6 +181,8 @@ public class EnvironmentVariableProvider implements
|
|||
}
|
||||
|
||||
IBuildEnvironmentVariable variable = null;
|
||||
IContextInfo varContextInfo = null;
|
||||
int varSupplierNum = -1;
|
||||
|
||||
for(int i = infos.length-1 ; i >=0 ; i-- ) {
|
||||
IContextInfo info = infos[i];
|
||||
|
@ -132,6 +195,9 @@ public class EnvironmentVariableProvider implements
|
|||
if(var == null)
|
||||
continue;
|
||||
|
||||
varContextInfo = info;
|
||||
varSupplierNum = j;
|
||||
|
||||
if(variable == null)
|
||||
variable = var;
|
||||
else
|
||||
|
@ -139,37 +205,36 @@ public class EnvironmentVariableProvider implements
|
|||
}
|
||||
}
|
||||
|
||||
if(variable != null && variable.getOperation() == IBuildEnvironmentVariable.ENVVAR_REMOVE)
|
||||
variable = null;
|
||||
return variable;
|
||||
if(variable != null){
|
||||
if(variable.getOperation() == IBuildEnvironmentVariable.ENVVAR_REMOVE)
|
||||
return null;
|
||||
return new EnvVarDescriptor(variable,varContextInfo,varSupplierNum);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariable()
|
||||
*/
|
||||
public IBuildEnvironmentVariable getVariable(String variableName,
|
||||
Object level, boolean includeParentLevels) {
|
||||
Object level, boolean includeParentLevels, boolean resolveMacros) {
|
||||
|
||||
if(variableName == null || "".equals(variableName)) //$NON-NLS-1$
|
||||
return null;
|
||||
|
||||
IBuildEnvironmentVariable var = getVariable(variableName,getContextInfo(level),includeParentLevels);
|
||||
if(level instanceof IConfiguration)
|
||||
IContextInfo info = getContextInfo(level);
|
||||
EnvVarDescriptor var = getVariable(variableName,info,includeParentLevels);
|
||||
if(level instanceof IConfiguration && includeParentLevels)
|
||||
checkBuildPathVariable((IConfiguration)level,variableName,var);
|
||||
return var;
|
||||
}
|
||||
|
||||
public String adjustName(String name){
|
||||
if(!isVariableCaseSensitive())
|
||||
name = name.toUpperCase();
|
||||
return name;
|
||||
return resolveMacros ? calculateResolvedVariable(var,info) : var;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the context info that should be used for the given level
|
||||
* or null if the the given level is not supported
|
||||
*/
|
||||
protected IContextInfo getContextInfo(Object level){
|
||||
public IContextInfo getContextInfo(Object level){
|
||||
DefaultContextInfo info = new DefaultContextInfo(level);
|
||||
if(info.getSuppliers() == null)
|
||||
return null;
|
||||
|
@ -196,10 +261,10 @@ public class EnvironmentVariableProvider implements
|
|||
IBuildEnvironmentVariable vars[] = suppliers[i].getVariables(infos[0].getContext());
|
||||
if(vars != null){
|
||||
for(int j = 0; j < vars.length; j++){
|
||||
set.add(
|
||||
adjustName(vars[j].
|
||||
getName())
|
||||
);
|
||||
String name = EnvVarOperationProcessor.normalizeName(vars[j].
|
||||
getName());
|
||||
if(name != null)
|
||||
set.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +295,7 @@ public class EnvironmentVariableProvider implements
|
|||
else{
|
||||
vars = supplier.getVariables(info.getContext());
|
||||
}
|
||||
envVarSet.add(vars);
|
||||
envVarSet.add(vars,info,j);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,15 +306,30 @@ public class EnvironmentVariableProvider implements
|
|||
* @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariables()
|
||||
*/
|
||||
public IBuildEnvironmentVariable[] getVariables(Object level,
|
||||
boolean includeParentLevels) {
|
||||
boolean includeParentLevels, boolean resolveMacros) {
|
||||
|
||||
EnvVarCollector varSet = getVariables(getContextInfo(level),includeParentLevels);
|
||||
IContextInfo info = getContextInfo(level);
|
||||
EnvVarCollector varSet = getVariables(info,includeParentLevels);
|
||||
|
||||
EnvVarDescriptor vars[] = varSet != null ? varSet.toArray(false) : null;
|
||||
|
||||
if(level instanceof IConfiguration)
|
||||
checkBuildPathVariables((IConfiguration)level,varSet);
|
||||
if(includeParentLevels)
|
||||
checkBuildPathVariables((IConfiguration)level,varSet);
|
||||
else if (vars != null){
|
||||
for(int i = 0; i < vars.length; i++)
|
||||
checkBuildPathVariable((IConfiguration)level,vars[i].getName(),vars[i]);
|
||||
}
|
||||
|
||||
if(varSet != null)
|
||||
return varSet.toArray(false);
|
||||
if(vars != null){
|
||||
if(!resolveMacros)
|
||||
return vars;
|
||||
|
||||
IBuildEnvironmentVariable resolved[] = new IBuildEnvironmentVariable[vars.length];
|
||||
for(int i = 0; i < vars.length; i++)
|
||||
resolved[i] = calculateResolvedVariable(vars[i], info);
|
||||
return resolved;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -336,11 +416,11 @@ public class EnvironmentVariableProvider implements
|
|||
for(int k = 0; k < vars.length; k++){
|
||||
String varName = vars[k];
|
||||
|
||||
IBuildEnvironmentVariable var = getVariable(varName,configuration,true);
|
||||
EnvVarDescriptor var = getVariable(varName,getContextInfo(configuration),true);
|
||||
if(var == null)
|
||||
continue;
|
||||
|
||||
String varValue = var.getValue();
|
||||
String varValue = calculateResolvedVariable(var, getContextInfo(configuration)).getValue();
|
||||
String paths[] = pathResolver.resolveBuildPaths(buildPathType,varName,varValue,configuration);
|
||||
if(paths != null && paths.length != 0)
|
||||
list.addAll(Arrays.asList(paths));
|
||||
|
@ -446,7 +526,7 @@ public class EnvironmentVariableProvider implements
|
|||
* If it is not changed, other build path variables are not checked
|
||||
* In the case of the given variable is not the build path one, this method does nothing
|
||||
*/
|
||||
protected void checkBuildPathVariable(IConfiguration configuration, String varName, IBuildEnvironmentVariable var){
|
||||
protected void checkBuildPathVariable(IConfiguration configuration, String varName, EnvVarDescriptor var){
|
||||
checkBuildPathVariable(configuration, IEnvVarBuildPath.BUILDPATH_INCLUDE, varName, var);
|
||||
checkBuildPathVariable(configuration, IEnvVarBuildPath.BUILDPATH_LIBRARY, varName, var);
|
||||
}
|
||||
|
@ -459,7 +539,7 @@ public class EnvironmentVariableProvider implements
|
|||
* If it is not changed, other build path variables are not checked
|
||||
* In the case of the given variable is not the build path one, this method does nothing
|
||||
*/
|
||||
protected void checkBuildPathVariable(IConfiguration configuration, int buildPathType, String varName, IBuildEnvironmentVariable var){
|
||||
protected void checkBuildPathVariable(IConfiguration configuration, int buildPathType, String varName, EnvVarDescriptor var){
|
||||
StoredBuildPathEnvironmentContainer buildPathVars = getStoredBuildPathVariables(buildPathType);
|
||||
if(buildPathVars == null)
|
||||
return;
|
||||
|
@ -510,4 +590,61 @@ public class EnvironmentVariableProvider implements
|
|||
fLibraryStoredBuildPathVariables = new StoredBuildPathEnvironmentContainer(IEnvVarBuildPath.BUILDPATH_LIBRARY);
|
||||
return fLibraryStoredBuildPathVariables;
|
||||
}
|
||||
|
||||
public IBuildEnvironmentVariable calculateResolvedVariable(EnvVarDescriptor des, IContextInfo info){
|
||||
if(des == null || info == null)
|
||||
return null;
|
||||
|
||||
return calculateResolvedVariable(des,getMacroSubstitutor(getMacroContextInfoForContext(info.getContext()),""," ")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
public IBuildEnvironmentVariable calculateResolvedVariable(EnvVarDescriptor des, IMacroSubstitutor sub){
|
||||
if(des == null)
|
||||
return null;
|
||||
IBuildEnvironmentVariable var = des;
|
||||
|
||||
try{
|
||||
if(sub instanceof EnvVarMacroSubstitutor)
|
||||
var = ((EnvVarMacroSubstitutor)sub).resolveVariable(des);
|
||||
else if(des.getOperation() != IBuildEnvironmentVariable.ENVVAR_REMOVE){
|
||||
String name = des.getName();
|
||||
var = new BuildEnvVar(name,sub.resolveToString(name),des.getOperation(),des.getDelimiter());
|
||||
}
|
||||
} catch (BuildMacroException e){
|
||||
}
|
||||
return var;
|
||||
|
||||
}
|
||||
|
||||
protected int getMacroContextTypeFromContext(Object context){
|
||||
if(context instanceof IConfiguration)
|
||||
return IBuildMacroProvider.CONTEXT_CONFIGURATION;
|
||||
else if(context instanceof IManagedProject)
|
||||
return IBuildMacroProvider.CONTEXT_PROJECT;
|
||||
else if(context instanceof IWorkspace)
|
||||
return IBuildMacroProvider.CONTEXT_WORKSPACE;
|
||||
else if(context == null)
|
||||
return IBuildMacroProvider.CONTEXT_ECLIPSEENV;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IMacroContextInfo getMacroContextInfoForContext(Object context){
|
||||
return new DefaultMacroContextInfo(getMacroContextTypeFromContext(context),context);
|
||||
}
|
||||
|
||||
public IMacroSubstitutor getMacroSubstitutor(IMacroContextInfo info, String inexistentMacroValue, String listDelimiter){
|
||||
if(fMacroSubstitutor == null)
|
||||
fMacroSubstitutor = new EnvVarMacroSubstitutor(info,inexistentMacroValue,listDelimiter);
|
||||
else {
|
||||
try {
|
||||
fMacroSubstitutor.setMacroContextInfo(info);
|
||||
fMacroSubstitutor.setInexistentMacroValue(inexistentMacroValue);
|
||||
fMacroSubstitutor.setListDelimiter(listDelimiter);
|
||||
} catch (BuildMacroException e){
|
||||
fMacroSubstitutor = new EnvVarMacroSubstitutor(info,inexistentMacroValue,listDelimiter);
|
||||
}
|
||||
}
|
||||
return fMacroSubstitutor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,12 @@ import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
|
|||
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IProjectEnvironmentVariableSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.DefaultMacroContextInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.EnvironmentMacroSupplier;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.IMacroContextInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier;
|
||||
|
||||
/**
|
||||
* This is the Environment Variable Supplier used to supply variables
|
||||
|
@ -42,29 +48,35 @@ public class ExternalExtensionEnvironmentSupplier implements
|
|||
private IContextInfo fStartInfo;
|
||||
private Object fStartLevel;
|
||||
private boolean fStartInitialized;
|
||||
private int fStartType;
|
||||
private Object fStartData;
|
||||
private IMacroContextInfo fStartMacroContextInfo;
|
||||
private boolean fStartMacroInfoInitialized;
|
||||
|
||||
public ExtensionEnvVarProvider(Object level){
|
||||
fStartLevel = level;
|
||||
fStartType = getMacroContextTypeFromContext(level);
|
||||
fStartData = level;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariable(java.lang.String, java.lang.Object, boolean)
|
||||
*/
|
||||
public IBuildEnvironmentVariable getVariable(String variableName,
|
||||
Object level, boolean includeParentLevels) {
|
||||
Object level, boolean includeParentLevels, boolean resolveMacros) {
|
||||
if(getValidName(variableName) == null)
|
||||
return null;
|
||||
return super.getVariable(variableName,level,includeParentLevels);
|
||||
return super.getVariable(variableName,level,includeParentLevels,resolveMacros);
|
||||
}
|
||||
|
||||
public IBuildEnvironmentVariable[] getVariables(Object level, boolean includeParentLevels) {
|
||||
return filterVariables(super.getVariables(level,includeParentLevels));
|
||||
public IBuildEnvironmentVariable[] getVariables(Object level, boolean includeParentLevels, boolean resolveMacros) {
|
||||
return filterVariables(super.getVariables(level,includeParentLevels,resolveMacros));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider#getContextInfo(java.lang.Object)
|
||||
*/
|
||||
protected IContextInfo getContextInfo(Object level){
|
||||
public IContextInfo getContextInfo(Object level){
|
||||
IContextInfo startInfo = getStartInfo();
|
||||
if(level == fStartLevel)
|
||||
return startInfo;
|
||||
|
@ -95,6 +107,45 @@ public class ExternalExtensionEnvironmentSupplier implements
|
|||
return fStartInfo;
|
||||
}
|
||||
|
||||
public IMacroSubstitutor getMacroSubstitutor(IMacroContextInfo info, String inexistentMacroValue, String listDelimiter){
|
||||
return super.getMacroSubstitutor(getSubstitutorMacroContextInfo(info),inexistentMacroValue,listDelimiter);
|
||||
}
|
||||
|
||||
protected IMacroContextInfo getSubstitutorMacroContextInfo(IMacroContextInfo info){
|
||||
IMacroContextInfo startInfo = getStartMacroContextInfo();
|
||||
if(info == null)
|
||||
return null;
|
||||
|
||||
if(info.getContextType() == fStartType &&
|
||||
info.getContextData() == fStartData)
|
||||
return startInfo;
|
||||
|
||||
|
||||
if(BuildMacroProvider.getDefault().checkParentContextRelation(startInfo,info))
|
||||
return info;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IMacroContextInfo getStartMacroContextInfo(){
|
||||
if(fStartMacroContextInfo == null && !fStartMacroInfoInitialized){
|
||||
final IMacroContextInfo info = getMacroContextInfoForContext(fStartLevel);
|
||||
if(info != null){
|
||||
fStartMacroContextInfo = new DefaultMacroContextInfo(fStartType,fStartData){
|
||||
protected IBuildMacroSupplier[] getSuppliers(int type, Object data){
|
||||
IBuildMacroSupplier suppliers[] = info.getSuppliers();
|
||||
return filterValidMacroSuppliers(suppliers);
|
||||
}
|
||||
|
||||
public IMacroContextInfo getNext() {
|
||||
return info.getNext();
|
||||
}
|
||||
};
|
||||
fStartInitialized = true;
|
||||
}
|
||||
fStartInitialized = true;
|
||||
}
|
||||
return fStartMacroContextInfo;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider#getStoredBuildPathVariables(int)
|
||||
|
@ -211,4 +262,30 @@ public class ExternalExtensionEnvironmentSupplier implements
|
|||
protected IBuildEnvironmentVariable[] filterVariables(IBuildEnvironmentVariable variables[]){
|
||||
return EnvVarOperationProcessor.filterVariables(variables,fNonOverloadableVariables);
|
||||
}
|
||||
|
||||
protected IBuildMacroSupplier[] filterValidMacroSuppliers(IBuildMacroSupplier suppliers[]){
|
||||
if(suppliers == null)
|
||||
return null;
|
||||
|
||||
int i = 0, j = 0;
|
||||
for(i = 0; i < suppliers.length; i++){
|
||||
if(suppliers[i] instanceof EnvironmentMacroSupplier)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(i >= suppliers.length)
|
||||
return suppliers;
|
||||
|
||||
int startNum = i + 1;
|
||||
|
||||
IBuildMacroSupplier validSuppliers[] =
|
||||
new IBuildMacroSupplier[suppliers.length - startNum];
|
||||
|
||||
for(i = startNum, j = 0; i < suppliers.length; i++, j++)
|
||||
validSuppliers[j] = suppliers[i];
|
||||
|
||||
return validSuppliers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -102,8 +102,11 @@ public class StoredBuildPathEnvironmentContainer extends
|
|||
for(int i = 0; i < vars.length; i++){
|
||||
IBuildEnvironmentVariable var = vars[i];
|
||||
String name = var.getName();
|
||||
IBuildEnvironmentVariable curVar = existingVariables != null ?
|
||||
EnvVarDescriptor des = existingVariables != null ?
|
||||
existingVariables.getVariable(name) : null;
|
||||
EnvironmentVariableProvider provider = ((EnvironmentVariableProvider)ManagedBuildManager.getEnvironmentVariableProvider());
|
||||
IBuildEnvironmentVariable curVar = des != null ?
|
||||
provider.calculateResolvedVariable(des,provider.getContextInfo(configuration)) : null;
|
||||
if(!haveIdenticalValues(var,curVar)){
|
||||
if(curVar == null){
|
||||
env.createVariable(name,null,IBuildEnvironmentVariable.ENVVAR_REMOVE,null);
|
||||
|
@ -131,7 +134,7 @@ public class StoredBuildPathEnvironmentContainer extends
|
|||
* returns false in this case
|
||||
*/
|
||||
public boolean isVariableChanged(String name,
|
||||
IBuildEnvironmentVariable variable,
|
||||
EnvVarDescriptor variable,
|
||||
IConfiguration configuration){
|
||||
StorableEnvironment env = getEnvironment(configuration);
|
||||
if(env == null)
|
||||
|
@ -140,7 +143,11 @@ public class StoredBuildPathEnvironmentContainer extends
|
|||
if(var == null)
|
||||
return false;
|
||||
|
||||
if(haveIdenticalValues(var,variable))
|
||||
EnvironmentVariableProvider provider = ((EnvironmentVariableProvider)ManagedBuildManager.getEnvironmentVariableProvider());
|
||||
IBuildEnvironmentVariable curVar = variable != null ?
|
||||
provider.calculateResolvedVariable(variable,provider.getContextInfo(configuration)) : null;
|
||||
|
||||
if(haveIdenticalValues(var,curVar))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -191,12 +191,12 @@ public class BuildMacroProvider implements IBuildMacroProvider {
|
|||
* @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveStringListValue(java.lang.String, java.lang.String, int, java.lang.Object)
|
||||
*/
|
||||
public String[] resolveStringListValue(String value,
|
||||
String nonexistentMacrosValue, int contextType, Object contextData)
|
||||
throws BuildMacroException {
|
||||
String nonexistentMacrosValue, String listDelimiter,
|
||||
int contextType, Object contextData) throws BuildMacroException {
|
||||
|
||||
IMacroContextInfo info = getMacroContextInfo(contextType,contextData);
|
||||
if(info != null)
|
||||
return MacroResolver.resolveToStringList(value,getMacroSubstitutor(info,nonexistentMacrosValue, " ")); //$NON-NLS-1$
|
||||
return MacroResolver.resolveToStringList(value,getMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -218,12 +218,12 @@ public class BuildMacroProvider implements IBuildMacroProvider {
|
|||
* @see org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider#resolveStringListValueToMakefileFormat(java.lang.String, java.lang.String, int, java.lang.Object)
|
||||
*/
|
||||
public String[] resolveStringListValueToMakefileFormat(String value,
|
||||
String nonexistentMacrosValue, int contextType, Object contextData)
|
||||
String nonexistentMacrosValue, String listDelimiter, int contextType, Object contextData)
|
||||
throws BuildMacroException {
|
||||
|
||||
IMacroContextInfo info = getMacroContextInfo(contextType,contextData);
|
||||
if(info != null)
|
||||
MacroResolver.resolveToStringList(value,getBuildfileMacroSubstitutor(info,nonexistentMacrosValue, " ")); //$NON-NLS-1$
|
||||
MacroResolver.resolveToStringList(value,getBuildfileMacroSubstitutor(info,nonexistentMacrosValue, listDelimiter));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -247,8 +247,15 @@ public class BuildMacroProvider implements IBuildMacroProvider {
|
|||
throws BuildMacroException {
|
||||
|
||||
IMacroContextInfo info = getMacroContextInfo(contextType,contextData);
|
||||
IMacroSubstitutor subst = new DefaultMacroSubstitutor(info,null,""){ //$NON-NLS-1$
|
||||
protected ResolvedMacro resolveMacro(IBuildMacro macro) throws BuildMacroException {
|
||||
if(macro instanceof EclipseVariablesMacroSupplier.EclipseVarMacro)
|
||||
return new ResolvedMacro(macro.getName(),""); //$NON-NLS-1$
|
||||
return super.resolveMacro(macro);
|
||||
}
|
||||
};
|
||||
if(info != null)
|
||||
MacroResolver.checkIntegrity(info,getMacroSubstitutor(info,null,"")); //$NON-NLS-1$
|
||||
MacroResolver.checkIntegrity(info,subst);
|
||||
}
|
||||
|
||||
public IMacroSubstitutor getMacroSubstitutor(IMacroContextInfo info, String inexistentMacroValue, String listDelimiter){
|
||||
|
|
|
@ -170,7 +170,8 @@ public class BuildfileMacroSubstitutor extends DefaultMacroSubstitutor {
|
|||
|
||||
if(fConfiguration != null && fBuilder != null &&
|
||||
!UserDefinedMacroSupplier.getInstance().areMacrosExpanded(fConfiguration) &&
|
||||
macro instanceof EnvironmentMacroSupplier.EnvVarMacro){
|
||||
macro instanceof EnvironmentMacroSupplier.EnvVarMacro &&
|
||||
!MacroResolver.isStringListMacro(macro.getMacroValueType())){
|
||||
String ref = getMacroReference(macro);
|
||||
if(ref != null)
|
||||
resolved = new ResolvedMacro(macro.getName(),ref);
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
|||
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroStatus;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier;
|
||||
|
||||
/**
|
||||
* This substitutor resolves all macro references
|
||||
|
@ -36,6 +37,7 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
private String fInexistentMacroValue;
|
||||
private String fListDelimiter;
|
||||
private String fIncorrectlyReferencedMacroValue;
|
||||
private Map fDelimiterMap;
|
||||
|
||||
protected class ResolvedMacro extends BuildMacro{
|
||||
private boolean fIsDefined;
|
||||
|
@ -86,20 +88,30 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
return fStringListValue;
|
||||
}
|
||||
|
||||
protected String getDelimiter(){
|
||||
if(fDelimiterMap != null){
|
||||
Object delimiter = fDelimiterMap.get(fName);
|
||||
if(delimiter instanceof String)
|
||||
return (String)delimiter;
|
||||
}
|
||||
return fListDelimiter;
|
||||
}
|
||||
|
||||
protected String stringListToString(String values[]) throws BuildMacroException {
|
||||
String result = null;
|
||||
String delimiter;
|
||||
if(values == null)
|
||||
result = null;
|
||||
else if(values.length == 0)
|
||||
result = EMPTY_STRING;
|
||||
else if(values.length == 1)
|
||||
result = values[0];
|
||||
else if(fListDelimiter != null){
|
||||
else if((delimiter = getDelimiter()) != null){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for(int i = 0; i < values.length; i++){
|
||||
buffer.append(values[i]);
|
||||
if(i < values.length-1)
|
||||
buffer.append(fListDelimiter);
|
||||
buffer.append(delimiter);
|
||||
}
|
||||
result = buffer.toString();
|
||||
} else {
|
||||
|
@ -132,65 +144,61 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
private IMacroContextInfo fInfo;
|
||||
private IBuildMacro fMacro;
|
||||
private boolean fInitialized;
|
||||
|
||||
public MacroDescriptor(String name){
|
||||
this(name, null);
|
||||
}
|
||||
private int fSupplierNum;
|
||||
private int fEnvSupplierNum;
|
||||
|
||||
public MacroDescriptor(String name, IMacroContextInfo info){
|
||||
fName = name;
|
||||
fInfo = info;
|
||||
}
|
||||
|
||||
public MacroDescriptor(IBuildMacro macro, IMacroContextInfo info){
|
||||
public MacroDescriptor(String name, IMacroContextInfo info, int supplierNum){
|
||||
fName = name;
|
||||
fInfo = info;
|
||||
fSupplierNum = supplierNum;
|
||||
}
|
||||
|
||||
public MacroDescriptor(IBuildMacro macro, IMacroContextInfo info, int supplierNum){
|
||||
fName = macro.getName();
|
||||
fInfo = info;
|
||||
fMacro = macro;
|
||||
fSupplierNum = supplierNum;
|
||||
fInitialized = true;
|
||||
}
|
||||
|
||||
public MacroDescriptor getNext(){
|
||||
IMacroContextInfo info = getInfo();
|
||||
if(info != null)
|
||||
info = info.getNext();
|
||||
|
||||
return get(fName,info);
|
||||
return new MacroDescriptor(fName,getInfo(),getSupplierNum()+1);
|
||||
}
|
||||
|
||||
protected MacroDescriptor get(String name, IMacroContextInfo info){
|
||||
MacroDescriptor next = null;
|
||||
IBuildMacro macro = null;
|
||||
for(; info != null; info = info.getNext()){
|
||||
if((macro = BuildMacroProvider.getMacro(fName,info,false)) != null){
|
||||
next = new MacroDescriptor(macro,info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
public int getSupplierNum(){
|
||||
init();
|
||||
return fSupplierNum;
|
||||
}
|
||||
|
||||
private void init(){
|
||||
if(fInitialized)
|
||||
return;
|
||||
|
||||
MacroDescriptor des = get(fName,fContextInfo);
|
||||
if(des != null){
|
||||
fInfo = des.fInfo;
|
||||
fMacro = des.fMacro;
|
||||
}
|
||||
|
||||
fInitialized = true;
|
||||
|
||||
for(; fInfo != null; fInfo = fInfo.getNext()){
|
||||
IBuildMacroSupplier suppliers[] = fInfo.getSuppliers();
|
||||
if(suppliers != null){
|
||||
for(; fSupplierNum < suppliers.length; fSupplierNum++){
|
||||
if((fMacro = suppliers[fSupplierNum].getMacro(fName,fInfo.getContextType(),fInfo.getContextData())) != null){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
fSupplierNum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public IMacroContextInfo getInfo(){
|
||||
if(fInfo == null)
|
||||
init();
|
||||
protected IMacroContextInfo getInfo(){
|
||||
init();
|
||||
return fInfo;
|
||||
}
|
||||
|
||||
public IBuildMacro getMacro(){
|
||||
if(fMacro == null)
|
||||
init();
|
||||
init();
|
||||
return fMacro;
|
||||
}
|
||||
|
||||
|
@ -200,38 +208,55 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
private HashSet fMacrosUnderResolution = new HashSet();
|
||||
private Stack fMacroDescriptors = new Stack();
|
||||
|
||||
public DefaultMacroSubstitutor(int contextType, Object contextData, String inexistentMacroValue, String listDelimiter, Map delimiterMap, String incorrectlyReferencedMacroValue){
|
||||
this(new DefaultMacroContextInfo(contextType,contextData),inexistentMacroValue,listDelimiter, delimiterMap, incorrectlyReferencedMacroValue);
|
||||
}
|
||||
|
||||
public DefaultMacroSubstitutor(int contextType, Object contextData, String inexistentMacroValue, String listDelimiter){
|
||||
this(new DefaultMacroContextInfo(contextType,contextData),inexistentMacroValue,listDelimiter);
|
||||
}
|
||||
|
||||
public DefaultMacroSubstitutor(IMacroContextInfo contextInfo, String inexistentMacroValue, String listDelimiter){
|
||||
this(contextInfo, inexistentMacroValue, listDelimiter, inexistentMacroValue);
|
||||
this(contextInfo, inexistentMacroValue, listDelimiter, null ,inexistentMacroValue);
|
||||
}
|
||||
|
||||
public DefaultMacroSubstitutor(IMacroContextInfo contextInfo, String inexistentMacroValue, String listDelimiter, String incorrectlyReferencedMacroValue){
|
||||
public DefaultMacroSubstitutor(IMacroContextInfo contextInfo, String inexistentMacroValue, String listDelimiter, Map delimiterMap, String incorrectlyReferencedMacroValue){
|
||||
fContextInfo = contextInfo;
|
||||
fInexistentMacroValue = inexistentMacroValue;
|
||||
fListDelimiter = listDelimiter;
|
||||
fDelimiterMap = delimiterMap;
|
||||
fIncorrectlyReferencedMacroValue = incorrectlyReferencedMacroValue;
|
||||
}
|
||||
|
||||
protected String resolveToString(MacroDescriptor des) throws BuildMacroException {
|
||||
String result = null;
|
||||
ResolvedMacro value = getResolvedMacro(des);
|
||||
result = value.getStringValue();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String[] resolveToStringList(MacroDescriptor des) throws BuildMacroException {
|
||||
String result[] = null;
|
||||
ResolvedMacro value = getResolvedMacro(des);
|
||||
result = value.getStringListValue();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor#resolveToString(java.lang.String)
|
||||
*/
|
||||
public String resolveToString(String macroName) throws BuildMacroException {
|
||||
String result = null;
|
||||
ResolvedMacro value = getResolvedMacro(macroName);
|
||||
result = value.getStringValue();
|
||||
|
||||
return result;
|
||||
return resolveToString(new MacroDescriptor(macroName,fContextInfo));
|
||||
}
|
||||
|
||||
public void setMacroContextInfo(IMacroContextInfo info)
|
||||
throws BuildMacroException{
|
||||
if(fMacrosUnderResolution.size() != 0)
|
||||
throw new BuildMacroException(IBuildMacroStatus.TYPE_ERROR,(String)null,null,null,0,null);
|
||||
if(checkEqual(fContextInfo,info))
|
||||
return;
|
||||
|
||||
fResolvedMacros.clear();
|
||||
reset();
|
||||
fContextInfo = info;
|
||||
}
|
||||
|
||||
|
@ -246,20 +271,20 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
return ((BuildMacroProvider)ManagedBuildManager.getBuildMacroProvider()).getMacroContextInfo(contextType,contextData);
|
||||
}
|
||||
|
||||
protected ResolvedMacro getResolvedMacro(String macroName)
|
||||
protected ResolvedMacro getResolvedMacro(MacroDescriptor des)
|
||||
throws BuildMacroException {
|
||||
ResolvedMacro value = checkResolvingMacro(macroName);
|
||||
ResolvedMacro value = checkResolvingMacro(des);
|
||||
|
||||
if(value == null)
|
||||
{
|
||||
try{
|
||||
value = resolveMacro(macroName);
|
||||
value = resolveMacro(des);
|
||||
}finally{
|
||||
if(value != null)
|
||||
addResolvedMacro(macroName,value);
|
||||
addResolvedMacro(des,value);
|
||||
else {
|
||||
value = new ResolvedMacro(macroName,fInexistentMacroValue,false);
|
||||
addResolvedMacro(macroName,value);
|
||||
value = new ResolvedMacro(des.fName,fInexistentMacroValue,false);
|
||||
addResolvedMacro(des,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,16 +292,16 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
return value;
|
||||
}
|
||||
|
||||
protected ResolvedMacro resolveMacro(MacroDescriptor des) throws BuildMacroException{
|
||||
return des.fMacro != null ? resolveMacro(des.fMacro) : resolveMacro(des.fName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor#resolveToStringList(java.lang.String)
|
||||
*/
|
||||
public String[] resolveToStringList(String macroName)
|
||||
throws BuildMacroException {
|
||||
String result[] = null;
|
||||
ResolvedMacro value = getResolvedMacro(macroName);
|
||||
result = value.getStringListValue();
|
||||
|
||||
return result;
|
||||
return resolveToStringList(new MacroDescriptor(macroName,fContextInfo));
|
||||
}
|
||||
|
||||
protected ResolvedMacro resolveMacro(String macroName) throws BuildMacroException{
|
||||
|
@ -369,12 +394,13 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
return resolvedMacro;
|
||||
}
|
||||
|
||||
private ResolvedMacro checkResolvingMacro(String name)
|
||||
private ResolvedMacro checkResolvingMacro(MacroDescriptor des)
|
||||
throws BuildMacroException{
|
||||
String name = des.fName;
|
||||
ResolvedMacro value = (ResolvedMacro)fResolvedMacros.get(name);
|
||||
if(value == null){
|
||||
if(fMacrosUnderResolution.add(name))
|
||||
fMacroDescriptors.push(new MacroDescriptor(name,null));
|
||||
fMacroDescriptors.push(des);
|
||||
else {
|
||||
// the macro of the specified name is referenced from the other macros that
|
||||
// are referenced by the given macro
|
||||
|
@ -408,12 +434,17 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
return value;
|
||||
}
|
||||
|
||||
private void addResolvedMacro(String name, ResolvedMacro value){
|
||||
protected void addResolvedMacro(MacroDescriptor des, ResolvedMacro value){
|
||||
String name = des.fName;
|
||||
fMacrosUnderResolution.remove(name);
|
||||
fResolvedMacros.put(name,value);
|
||||
fMacroDescriptors.pop();
|
||||
}
|
||||
|
||||
protected ResolvedMacro removeResolvedMacro(String name){
|
||||
return (ResolvedMacro)fResolvedMacros.remove(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor#getMacroContextInfo()
|
||||
*/
|
||||
|
@ -421,4 +452,65 @@ public class DefaultMacroSubstitutor implements IMacroSubstitutor {
|
|||
return fContextInfo;
|
||||
}
|
||||
|
||||
public void reset() throws BuildMacroException{
|
||||
if(fMacrosUnderResolution.size() != 0)
|
||||
throw new BuildMacroException(IBuildMacroStatus.TYPE_ERROR,(String)null,null,null,0,null);
|
||||
|
||||
fResolvedMacros.clear();
|
||||
}
|
||||
|
||||
public Map getDelimiterMap() {
|
||||
return fDelimiterMap;
|
||||
}
|
||||
|
||||
public void setDelimiterMap(Map delimiterMap) throws BuildMacroException {
|
||||
if(checkEqual(fDelimiterMap,delimiterMap))
|
||||
return;
|
||||
reset();
|
||||
fDelimiterMap = delimiterMap;
|
||||
}
|
||||
|
||||
public String getIncorrectlyReferencedMacroValue() {
|
||||
return fIncorrectlyReferencedMacroValue;
|
||||
}
|
||||
|
||||
protected boolean checkEqual(Object o1, Object o2){
|
||||
if(o1 != null){
|
||||
if(o1.equals(o2))
|
||||
return true;
|
||||
} else if (o2 == null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setIncorrectlyReferencedMacroValue(
|
||||
String incorrectlyReferencedMacroValue) throws BuildMacroException {
|
||||
if(checkEqual(fIncorrectlyReferencedMacroValue,incorrectlyReferencedMacroValue))
|
||||
return;
|
||||
reset();
|
||||
fIncorrectlyReferencedMacroValue = incorrectlyReferencedMacroValue;
|
||||
}
|
||||
|
||||
public String getInexistentMacroValue() {
|
||||
return fInexistentMacroValue;
|
||||
}
|
||||
|
||||
public void setInexistentMacroValue(String inexistentMacroValue) throws BuildMacroException {
|
||||
if(checkEqual(fInexistentMacroValue,inexistentMacroValue))
|
||||
return;
|
||||
reset();
|
||||
fInexistentMacroValue = inexistentMacroValue;
|
||||
}
|
||||
|
||||
public String getListDelimiter() {
|
||||
return fListDelimiter;
|
||||
}
|
||||
|
||||
public void setListDelimiter(String listDelimiter) throws BuildMacroException {
|
||||
if(checkEqual(fListDelimiter,listDelimiter))
|
||||
return;
|
||||
reset();
|
||||
fListDelimiter = listDelimiter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
|||
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
|
||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvVarOperationProcessor;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
|
||||
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
|
||||
|
@ -31,10 +31,10 @@ import org.eclipse.core.resources.IWorkspace;
|
|||
*/
|
||||
public class EnvironmentMacroSupplier implements IBuildMacroSupplier {
|
||||
private static EnvironmentMacroSupplier fInstance;
|
||||
private IEnvironmentVariableProvider fEnvironmentProvider;
|
||||
private EnvironmentVariableProvider fEnvironmentProvider;
|
||||
|
||||
public class EnvVarMacro extends BuildMacro{
|
||||
IBuildEnvironmentVariable fVariable;
|
||||
private IBuildEnvironmentVariable fVariable;
|
||||
private EnvVarMacro(IBuildEnvironmentVariable var){
|
||||
fName = var.getName();
|
||||
fVariable = var;
|
||||
|
@ -92,13 +92,19 @@ public class EnvironmentMacroSupplier implements IBuildMacroSupplier {
|
|||
}
|
||||
|
||||
protected EnvironmentMacroSupplier(){
|
||||
this(ManagedBuildManager.getEnvironmentVariableProvider());
|
||||
this((EnvironmentVariableProvider)ManagedBuildManager.getEnvironmentVariableProvider());
|
||||
}
|
||||
|
||||
public EnvironmentMacroSupplier(IEnvironmentVariableProvider varProvider){
|
||||
public EnvironmentMacroSupplier(EnvironmentVariableProvider varProvider){
|
||||
fEnvironmentProvider = varProvider;
|
||||
}
|
||||
|
||||
public IBuildMacro createBuildMacro(IBuildEnvironmentVariable var){
|
||||
if(var != null)
|
||||
return new EnvVarMacro(var);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static EnvironmentMacroSupplier getInstance(){
|
||||
if(fInstance == null)
|
||||
fInstance = new EnvironmentMacroSupplier();
|
||||
|
@ -116,22 +122,22 @@ public class EnvironmentMacroSupplier implements IBuildMacroSupplier {
|
|||
switch(contextType){
|
||||
case IBuildMacroProvider.CONTEXT_CONFIGURATION:
|
||||
if(contextData instanceof IConfiguration){
|
||||
var = fEnvironmentProvider.getVariable(macroName,contextData,false);
|
||||
var = fEnvironmentProvider.getVariable(macroName,fEnvironmentProvider.getContextInfo(contextData),false);
|
||||
}
|
||||
break;
|
||||
case IBuildMacroProvider.CONTEXT_PROJECT:
|
||||
if(contextData instanceof IManagedProject){
|
||||
var = fEnvironmentProvider.getVariable(macroName,contextData,false);
|
||||
var = fEnvironmentProvider.getVariable(macroName,fEnvironmentProvider.getContextInfo(contextData),false);
|
||||
}
|
||||
break;
|
||||
case IBuildMacroProvider.CONTEXT_WORKSPACE:
|
||||
if(contextData instanceof IWorkspace){
|
||||
var = fEnvironmentProvider.getVariable(macroName,contextData,false);
|
||||
var = fEnvironmentProvider.getVariable(macroName,fEnvironmentProvider.getContextInfo(contextData),false);
|
||||
}
|
||||
break;
|
||||
case IBuildMacroProvider.CONTEXT_ECLIPSEENV:
|
||||
if(contextData == null){
|
||||
var = fEnvironmentProvider.getVariable(macroName,contextData,false);
|
||||
var = fEnvironmentProvider.getVariable(macroName,fEnvironmentProvider.getContextInfo(contextData),false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -149,22 +155,22 @@ public class EnvironmentMacroSupplier implements IBuildMacroSupplier {
|
|||
switch(contextType){
|
||||
case IBuildMacroProvider.CONTEXT_CONFIGURATION:
|
||||
if(contextData instanceof IConfiguration){
|
||||
vars = fEnvironmentProvider.getVariables(contextData,false);
|
||||
vars = fEnvironmentProvider.getVariables(fEnvironmentProvider.getContextInfo(contextData),false).toArray(false);
|
||||
}
|
||||
break;
|
||||
case IBuildMacroProvider.CONTEXT_PROJECT:
|
||||
if(contextData instanceof IManagedProject){
|
||||
vars = fEnvironmentProvider.getVariables(contextData,false);
|
||||
vars = fEnvironmentProvider.getVariables(fEnvironmentProvider.getContextInfo(contextData),false).toArray(false);
|
||||
}
|
||||
break;
|
||||
case IBuildMacroProvider.CONTEXT_WORKSPACE:
|
||||
if(contextData instanceof IWorkspace){
|
||||
vars = fEnvironmentProvider.getVariables(contextData,false);
|
||||
vars = fEnvironmentProvider.getVariables(fEnvironmentProvider.getContextInfo(contextData),false).toArray(false);
|
||||
}
|
||||
break;
|
||||
case IBuildMacroProvider.CONTEXT_ECLIPSEENV:
|
||||
if(contextData == null){
|
||||
vars = fEnvironmentProvider.getVariables(contextData,false);
|
||||
vars = fEnvironmentProvider.getVariables(fEnvironmentProvider.getContextInfo(contextData),false).toArray(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -179,4 +185,7 @@ public class EnvironmentMacroSupplier implements IBuildMacroSupplier {
|
|||
return null;
|
||||
}
|
||||
|
||||
public EnvironmentVariableProvider getEnvironmentVariableProvider(){
|
||||
return fEnvironmentProvider;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public interface IBuildMacroProvider{
|
|||
* NOTE: the IFileContextData is passed that represents the current file and the option
|
||||
* for that file because Macro Value Provider needs to know what option should be used
|
||||
* as a context in case macro is not found for �current file� context
|
||||
* 2. IOption � used to represent the currently selected option context
|
||||
* 2. IOptionContextData interface used to represent the currently selected option context
|
||||
* 3. IConfiguration � used to represent the currently selected configuration context
|
||||
* 4. IProject � used to represent current project context
|
||||
* 5. IWorkspace � used to represent current workspace context
|
||||
|
@ -109,6 +109,7 @@ public interface IBuildMacroProvider{
|
|||
*/
|
||||
public String[] resolveStringListValue(String value,
|
||||
String nonexistentMacrosValue,
|
||||
String listDelimiter,
|
||||
int contextType,
|
||||
Object contextData) throws BuildMacroException;
|
||||
|
||||
|
@ -149,6 +150,7 @@ public interface IBuildMacroProvider{
|
|||
*/
|
||||
public String[] resolveStringListValueToMakefileFormat(String value,
|
||||
String nonexistentMacrosValue,
|
||||
String listDelimiter,
|
||||
int contextType,
|
||||
Object contextData) throws BuildMacroException;
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class CygwinPathResolver implements IBuildPathResolver {
|
|||
ArrayList ls = new ArrayList();
|
||||
String s = exePath + TOOL + variableValue;
|
||||
String[] lines = exec(s);
|
||||
if (s != null && s.length() > 0) {
|
||||
if (lines != null && lines.length > 0) {
|
||||
result = lines[0].replace(BS,SLASH).split(DELIMITER_WIN);
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -882,8 +882,7 @@ public class EnvironmentBlock extends AbstractCOptionPage {
|
|||
if(!canDisplay(name))
|
||||
return null;
|
||||
|
||||
EnvironmentVariableProvider provider = (EnvironmentVariableProvider)ManagedBuildManager.getEnvironmentVariableProvider();
|
||||
return provider.getVariable(name,fSystemContextInfo,includeParentLevels);
|
||||
return EnvironmentVariableProvider.getDefault().getVariable(name,fSystemContextInfo,includeParentLevels);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.managedbuilder.internal.ui;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.DefaultContextInfo;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo;
|
||||
|
@ -90,7 +89,7 @@ public class EnvironmentSetBlock extends AbstractCOptionPage {
|
|||
* the user-modified variables that are not applied yet
|
||||
*/
|
||||
private class UIEnvVarProvider extends EnvironmentVariableProvider{
|
||||
protected IContextInfo getContextInfo(Object context){
|
||||
public IContextInfo getContextInfo(Object context){
|
||||
EnvironmentBlock blocks[] = getAllBlocks();
|
||||
for(int i = 0; i < blocks.length; i++){
|
||||
if(blocks[i].getContext() == context)
|
||||
|
@ -314,7 +313,7 @@ public class EnvironmentSetBlock extends AbstractCOptionPage {
|
|||
* Unlike the default provider, the returned provider also contains
|
||||
* the user-modified variables that are not applied yet
|
||||
*/
|
||||
public IEnvironmentVariableProvider getEnvironmentVariableProvider(){
|
||||
public EnvironmentVariableProvider getEnvironmentVariableProvider(){
|
||||
if(fEnvProvider == null)
|
||||
fEnvProvider = new UIEnvVarProvider();
|
||||
return fEnvProvider;
|
||||
|
|
|
@ -23,8 +23,8 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
|||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter;
|
||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvVarOperationProcessor;
|
||||
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacro;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider;
|
||||
import org.eclipse.cdt.managedbuilder.internal.macros.DefaultMacroContextInfo;
|
||||
|
@ -231,7 +231,7 @@ public class MacrosBlock extends AbstractCOptionPage {
|
|||
IBuildMacroSupplier suppliers[] = super.getSuppliers(contextType,contextData);
|
||||
if(suppliers == null || suppliers.length == 0)
|
||||
return null;
|
||||
IEnvironmentVariableProvider envProvider = obtainEnvironmentVariableProvider();
|
||||
EnvironmentVariableProvider envProvider = obtainEnvironmentVariableProvider();
|
||||
if(envProvider != null){
|
||||
for(int i = 0; i < suppliers.length; i++){
|
||||
if((suppliers[i] instanceof EnvironmentMacroSupplier)){
|
||||
|
@ -1150,7 +1150,7 @@ public class MacrosBlock extends AbstractCOptionPage {
|
|||
return MacroResolver.filterMacros(macros,fHiddenMacros);
|
||||
}
|
||||
|
||||
protected IEnvironmentVariableProvider obtainEnvironmentVariableProvider(){
|
||||
protected EnvironmentVariableProvider obtainEnvironmentVariableProvider(){
|
||||
ICOptionContainer container = getContainer();
|
||||
ManagedBuildOptionBlock optionBlock = null;
|
||||
if(container instanceof BuildPropertyPage){
|
||||
|
|
|
@ -319,8 +319,10 @@ import org.eclipse.swt.widgets.Group;
|
|||
* the user-modified macros that are not applied yet
|
||||
*/
|
||||
public BuildMacroProvider getBuildMacroProvider(){
|
||||
if(fMacroProvider == null)
|
||||
if(fMacroProvider == null){
|
||||
updateContexts();
|
||||
fMacroProvider = new UIMacroProvider();
|
||||
}
|
||||
return fMacroProvider;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue