1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

The initial check-in for the option enablement expressions

This commit is contained in:
Mikhail Sennikovsky 2005-11-17 14:16:58 +00:00
parent 7e52da1b5f
commit 403a805175
12 changed files with 977 additions and 21 deletions

View file

@ -984,10 +984,13 @@ Options can also be associated with a toolchain. However in such a case the opti
</documentation>
</annotation>
<complexType>
<choice>
<element ref="enumeratedOptionValue" minOccurs="0" maxOccurs="unbounded"/>
<element ref="listOptionValue" minOccurs="0" maxOccurs="unbounded"/>
</choice>
<sequence>
<choice>
<element ref="listOptionValue" minOccurs="0" maxOccurs="unbounded"/>
<element ref="enumeratedOptionValue" minOccurs="0" maxOccurs="unbounded"/>
</choice>
<element ref="enablement" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
@ -1602,6 +1605,187 @@ If the &quot;buildPathResolver&quot; attribute is specified, the &quot;pathDelim
</complexType>
</element>
<element name="enablement">
<annotation>
<documentation>
Contains boolean expression that specifies option applicability
</documentation>
</annotation>
<complexType>
<choice>
<element ref="and"/>
<element ref="or"/>
<element ref="not"/>
<element ref="checkOption"/>
<element ref="checkString"/>
<element ref="false"/>
</choice>
<attribute name="type" type="string" use="default" value="ALL">
<annotation>
<documentation>
Represents the applicability type for this enablement.
Can contain the following values:
UI_VISIBILITY – the given enablement expression specifies whether the option is to be visible in UI,
UI_ENABLEMENT – the given enablement expression specifies the enable state of the controls that represent the option in UI,
CMD_USAGE – the given enablement expression specifies whether the option is to be used in command line
ALL – this value means the combination of all the above values.
Several types could be specified simultaneously using the &quot;|&quot; as a delimiter, e.g.:
type=&quot;UI_VISIBILITY|CMD_USAGE&quot;
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="and">
<annotation>
<documentation>
Represents boolean &quot;and&quot; operation
</documentation>
</annotation>
<complexType>
<sequence>
<element ref="and"/>
<element ref="or"/>
<element ref="not"/>
<element ref="checkOption"/>
<element ref="checkString"/>
</sequence>
</complexType>
</element>
<element name="or">
<annotation>
<documentation>
Represents boolean &quot;or&quot; operation
</documentation>
</annotation>
<complexType>
<sequence>
<element ref="and"/>
<element ref="or"/>
<element ref="not"/>
<element ref="checkOption"/>
<element ref="checkString"/>
</sequence>
</complexType>
</element>
<element name="not">
<annotation>
<documentation>
Represents boolean &quot;not&quot; operation
</documentation>
</annotation>
<complexType>
<choice>
<element ref="and"/>
<element ref="or"/>
<element ref="not"/>
<element ref="checkOption"/>
<element ref="checkString"/>
</choice>
</complexType>
</element>
<element name="checkOption">
<annotation>
<documentation>
Performs an option value check. The option value can be checked either agains some pre-defined value or against the value of another option
</documentation>
</annotation>
<complexType>
<attribute name="optionId" type="string">
<annotation>
<documentation>
The option id. The default is the id of the option that holds this expression. When searching for the option to be checked, MBS will examine all the options the holder contains along with all superclasses of each option to find the option with the specified id.
</documentation>
</annotation>
</attribute>
<attribute name="holderId" type="string">
<annotation>
<documentation>
The option holder id that holds the option. The default is the id of the holder that holds the container of this expression. When searching for the needed holder, MBS will examine all the holders the current configuration contains along with all superclasses of each holder in order to find the holder with the specified id.
</documentation>
</annotation>
</attribute>
<attribute name="value" type="string">
<annotation>
<documentation>
Specifies the expected value. If the current option value matches the value specified in this attribute, the checkOption element is treated as true, otherwise – as false.
The expected value could be specified either as a string that may contain build macros or as a regular expression. During the comparison, the build macros are resolved and the option value is checked to match the resulting string or regular expression. The way the expected value is specified and treated depends on the value of the isRegex attribute
</documentation>
</annotation>
</attribute>
<attribute name="isRegex" type="string" use="default" value="false">
<annotation>
<documentation>
Specifies whether the string specified in the &quot;value&quot; attribute should be treated as a regular eexpression. The default is false
</documentation>
</annotation>
</attribute>
<attribute name="otherOptionId" type="string">
<annotation>
<documentation>
The id of the option which is to be compared with the option specified with the “optionId” attribute. The default is the id of the option that holds this expression. If the “value” attribute is specified, both the “otherOptionId” and the “otherHolderId” attributes are ignored. When searching for the option to be checked, MBS will examine all the options the holder contains along with all superclasses of each option to find the option with the specified id.
</documentation>
</annotation>
</attribute>
<attribute name="otherHolderId" type="string">
<annotation>
<documentation>
The option holder id that holds the option specified with the “otherOptionId” attribute. The default is the id of the holder that holds the container of this expression. If the “value” attribute is specified, both the “otherOptionId” and the “otherHolderId” attributes are ingnored. When searching for the needed holder, MBS will examine all the holders the current configuration contains along with all superclasses of each holder in order to find the holder with the specified id.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="checkString">
<annotation>
<documentation>
Performs a string check.
</documentation>
</annotation>
<complexType>
<attribute name="string" type="string" use="required">
<annotation>
<documentation>
Represents the string to be checked. The string will typically contain the build macros.
</documentation>
</annotation>
</attribute>
<attribute name="value" type="string" use="required">
<annotation>
<documentation>
Specifies the expected value. If the current string specified in the “string” attribute matches the value specified in this attribute, the checkString element is treated as true, otherwise – as false.
The expected value could be specified either as a string that might contain the build macros or as a regular expression.
The way the value is specified and treated depends on the value of the isRegex attribute.
</documentation>
</annotation>
</attribute>
<attribute name="isRegex" type="string" use="default" value="false">
<annotation>
<documentation>
Specifies whether the string specified in the &quot;value&quot; attribute should be treated as a regular eexpression. The default is false
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="false" type="string">
<annotation>
<documentation>
Represents the &quot;false&quot; value. This element can be used as a direct child of the &quot;enablement&quot; element to represent that the given option applicability is disabled. E.g. to specify that the option is never displayed in UI or never used in the command line.
</documentation>
</annotation>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>

View file

@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.core;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression;
public class BooleanExpressionApplicabilityCalculator implements IOptionApplicability {
private OptionEnablementExpression fExpressions[];
public BooleanExpressionApplicabilityCalculator(IManagedConfigElement optionElement){
this(optionElement.getChildren(OptionEnablementExpression.NAME));
}
public BooleanExpressionApplicabilityCalculator(IManagedConfigElement enablementElements[]){
fExpressions = new OptionEnablementExpression[enablementElements.length];
for(int i = 0; i < enablementElements.length; i++){
fExpressions[i] = new OptionEnablementExpression(enablementElements[i]);
}
}
public boolean isOptionVisible(IBuildObject configuration,
IHoldsOptions holder,
IOption option){
return evaluate(configuration, holder, option, OptionEnablementExpression.FLAG_UI_VISIBILITY);
}
public boolean isOptionEnabled(IBuildObject configuration,
IHoldsOptions holder,
IOption option){
return evaluate(configuration, holder, option, OptionEnablementExpression.FLAG_UI_ENABLEMENT);
}
public boolean isOptionUsedInCommandLine(IBuildObject configuration,
IHoldsOptions holder,
IOption option){
return evaluate(configuration, holder, option, OptionEnablementExpression.FLAG_CMD_USAGE);
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder, IOption option, int flags){
for(int i = 0; i < fExpressions.length; i++){
if(!fExpressions[i].evaluate(configuration, holder, option, flags))
return false;
}
return true;
}
}

View file

@ -22,16 +22,17 @@ import java.util.Set;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.PluginVersionIdentifier;
@ -341,7 +342,13 @@ public class Option extends BuildObject implements IOption {
String applicabilityCalculatorStr = element.getAttribute(APPLICABILITY_CALCULATOR);
if (applicabilityCalculatorStr != null && element instanceof DefaultManagedConfigElement) {
applicabilityCalculatorElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
} else {
IManagedConfigElement enablements[] = element.getChildren(OptionEnablementExpression.NAME);
if(enablements.length > 0)
applicabilityCalculator = new BooleanExpressionApplicabilityCalculator(enablements);
}
// valueHandler
// Store the configuration element IFF there is a value handler defined
String valueHandler = element.getAttribute(VALUE_HANDLER);
@ -879,11 +886,12 @@ public class Option extends BuildObject implements IOption {
* @see org.eclipse.cdt.managedbuilder.core.IOption#getApplicabilityCalculatorElement()
*/
public IConfigurationElement getApplicabilityCalculatorElement() {
if (applicabilityCalculatorElement == null) {
/* if (applicabilityCalculatorElement == null) {
if (superClass != null) {
return ((Option)superClass).getApplicabilityCalculatorElement();
}
}
*/
return applicabilityCalculatorElement;
}
@ -893,22 +901,20 @@ public class Option extends BuildObject implements IOption {
* @see org.eclipse.cdt.managedbuilder.core.IOption#getApplicabilityCalculator()
*/
public IOptionApplicability getApplicabilityCalculator() {
if (applicabilityCalculator != null) {
return applicabilityCalculator;
if (applicabilityCalculator == null) {
if (applicabilityCalculatorElement != null) {
try {
if (applicabilityCalculatorElement.getAttribute(APPLICABILITY_CALCULATOR) != null)
applicabilityCalculator = (IOptionApplicability) applicabilityCalculatorElement
.createExecutableExtension(APPLICABILITY_CALCULATOR);
} catch (CoreException e) {
}
}
else if(superClass != null)
applicabilityCalculator = superClass.getApplicabilityCalculator();
}
IConfigurationElement element = getApplicabilityCalculatorElement();
if (element != null) {
try {
if (element.getAttribute(APPLICABILITY_CALCULATOR) != null) {
applicabilityCalculator = (IOptionApplicability) element
.createExecutableExtension(APPLICABILITY_CALCULATOR);
return applicabilityCalculator;
}
} catch (CoreException e) {
}
}
return null;
return applicabilityCalculator;
}
/* (non-Javadoc)

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
public class AndExpression extends CompositeExpression {
public static final String NAME = "and"; //$NON-NLS-1$
public AndExpression(IManagedConfigElement element) {
super(element);
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option) {
IBooleanExpression children[] = getChildren();
for(int i = 0; i < children.length; i++){
if(!children[i].evaluate(configuration, holder, option))
return false;
}
return true;
}
}

View file

@ -0,0 +1,289 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacroProvider;
import org.eclipse.cdt.managedbuilder.internal.macros.IMacroContextInfo;
import org.eclipse.cdt.managedbuilder.internal.macros.IMacroSubstitutor;
import org.eclipse.cdt.managedbuilder.internal.macros.MacroResolver;
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
public class CheckOptionExpression implements IBooleanExpression {
public static final String NAME = "checkOption"; //$NON-NLS-1$
public static final String OPTION_ID = "optionId"; //$NON-NLS-1$
public static final String HOLDER_ID = "holderId"; //$NON-NLS-1$
public static final String VALUE = "value"; //$NON-NLS-1$
public static final String IS_REGEX = "isRegex"; //$NON-NLS-1$
public static final String OTHER_OPTION_ID = "otherOptionId"; //$NON-NLS-1$
public static final String OTHER_HOLDER_ID = "otherHolderId"; //$NON-NLS-1$
public static final String YES = "yes"; //$NON-NLS-1$
public static final String TRUE = "true"; //$NON-NLS-1$
private String fOptionId;
private String fHolderId;
private String fValue;
private boolean fIsRegex;
private String fOtherOptionId;
private String fOtherHolderId;
public CheckOptionExpression(IManagedConfigElement element){
fOptionId = element.getAttribute(OPTION_ID);
fHolderId = element.getAttribute(HOLDER_ID);
fValue = element.getAttribute(VALUE);
fIsRegex = getBooleanValue(element.getAttribute(IS_REGEX));
fOtherOptionId = element.getAttribute(OTHER_OPTION_ID);
fOtherHolderId = element.getAttribute(OTHER_HOLDER_ID);
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option) {
boolean result = false;
IBuildObject ho[] = getHolderAndOption(fOptionId, fHolderId,
configuration, holder, option);
if(ho != null){
if(fValue != null)
result = evaluate((IOption)ho[1],((IHoldsOptions)ho[0]),fValue);
else {
IBuildObject otherHo[] = getHolderAndOption(fOtherOptionId, fOtherHolderId,
configuration, holder, option);
if(otherHo != null)
result = evaluate((IOption)ho[1],((IHoldsOptions)ho[0]),
(IOption)otherHo[1],((IHoldsOptions)otherHo[0]));
}
}
return result;
}
public boolean evaluate(IOption option, IHoldsOptions holder, String value){
IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
String delimiter = ManagedBuildManager.getEnvironmentVariableProvider().getDefaultDelimiter();
String inexVal = " "; //$NON-NLS-1$
try {
String resolvedValue = provider.resolveValue(value, inexVal, delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,holder));
switch(option.getValueType()){
case IOption.STRING:
case IOption.ENUMERATED:{
String stringValue = option.getStringValue();
stringValue = provider.resolveValue(stringValue, inexVal, delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,holder));
if(fIsRegex){
Pattern pattern = Pattern.compile(resolvedValue);
Matcher matcher = pattern.matcher(stringValue);
return matcher.matches();
}
return stringValue.equals(resolvedValue);
}
case IOption.BOOLEAN:
return option.getBooleanValue() == getBooleanValue(resolvedValue);
case IOption.INCLUDE_PATH:
case IOption.STRING_LIST:
case IOption.PREPROCESSOR_SYMBOLS:
case IOption.LIBRARIES:
case IOption.OBJECTS:{
List list = (List)option.getValue();
String listValue = provider.convertStringListToString((String[])list.toArray(new String[list.size()]),delimiter);
listValue = provider.resolveValue(listValue, inexVal, delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,holder));
if(fIsRegex){
Pattern pattern = Pattern.compile(resolvedValue);
Matcher matcher = pattern.matcher(listValue);
return matcher.matches();
}
return listValue.equals(resolvedValue);
}
default:
break;
}
} catch (BuildException e) {
} catch (BuildMacroException e) {
}
return false;
}
protected boolean getBooleanValue(String value){
if(TRUE.equalsIgnoreCase(value))
return true;
else if(YES.equalsIgnoreCase(value))
return true;
return false;
}
public boolean evaluate(IOption option, IHoldsOptions holder,
IOption otherOption, IHoldsOptions otherHolder){
try {
if(option.getValueType() != otherOption.getValueType())
return false;
BuildMacroProvider provider = (BuildMacroProvider)ManagedBuildManager.getBuildMacroProvider();
String delimiter = ManagedBuildManager.getEnvironmentVariableProvider().getDefaultDelimiter();
String inexVal = " "; //$NON-NLS-1$
switch(option.getValueType()){
case IOption.STRING:
case IOption.ENUMERATED:{
String stringValue = option.getStringValue();
stringValue = provider.resolveValue(stringValue, inexVal, delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,holder));
String str = otherOption.getStringValue();
str = provider.resolveValue(str, inexVal, delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(otherOption,otherHolder));
return stringValue.equals(str);
}
case IOption.BOOLEAN:
return option.getBooleanValue() == otherOption.getBooleanValue();
case IOption.INCLUDE_PATH:
case IOption.STRING_LIST:
case IOption.PREPROCESSOR_SYMBOLS:
case IOption.LIBRARIES:
case IOption.OBJECTS:{
List list = (List)option.getValue();
String listValue[] = (String[])list.toArray(new String[list.size()]);
list = (List)otherOption.getValue();
String otherValue[] = (String[])list.toArray(new String[list.size()]);
IMacroContextInfo info = provider.getMacroContextInfo(IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,holder));
IMacroSubstitutor subst = provider.getMacroSubstitutor(info,inexVal,delimiter);
listValue = MacroResolver.resolveStringListValues(listValue,subst,false);
info = provider.getMacroContextInfo(IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(otherOption,otherHolder));
subst = provider.getMacroSubstitutor(info,inexVal,delimiter);
otherValue = MacroResolver.resolveStringListValues(otherValue,subst,false);
if(listValue.length == otherValue.length){
for(int i = 0; i < listValue.length; i++){
if(!listValue[i].equals(otherValue[i]))
return false;
}
return true;
}
return false;
}
default:
break;
}
} catch (BuildException e) {
} catch (BuildMacroException e) {
} catch (ClassCastException e) {
}
return false;
}
protected IBuildObject[] getHolderAndOption(String optionId,
String holderId,
IBuildObject configuration,
IHoldsOptions holder,
IOption option
){
IBuildObject result[] = null;
if(optionId == null)
result = new IBuildObject[]{holder,option};
else {
IHoldsOptions hld = null;
if(holderId == null)
hld = holder;
else
hld = getHolder(holderId,configuration);
if(hld != null) {
IOption opt = getOption(optionId,hld);
if(opt != null)
result = new IBuildObject[]{hld,opt};
}
}
return result;
}
protected IOption getOption(String optionId,
IHoldsOptions holder){
return holder.getOptionBySuperClassId(optionId);
}
protected IHoldsOptions getHolder(String id,
IBuildObject cfg){
IHoldsOptions holder = null;
if(cfg instanceof IResourceConfiguration){
IHoldsOptions holders[] = ((IResourceConfiguration)cfg).getTools();
for(int i = 0; i < holders.length; i++){
if(isHolder(id,holders[i])){
holder = holders[i];
break;
}
}
} else if (cfg instanceof IConfiguration){
IToolChain tc = ((IConfiguration)cfg).getToolChain();
if(isHolder(id,tc))
holder = tc;
else {
IHoldsOptions holders[] = tc.getTools();
for(int i = 0; i < holders.length; i++){
if(isHolder(id,holders[i])){
holder = holders[i];
break;
}
}
}
}
return holder;
}
protected boolean isHolder(String id, IHoldsOptions holder){
do {
if(id.equals(holder.getId()))
return true;
if(holder instanceof IToolChain)
holder = ((IToolChain)holder).getSuperClass();
else if(holder instanceof ITool)
holder = ((ITool)holder).getSuperClass();
else
holder = null;
} while(holder != null);
return false;
}
}

View file

@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
public class CheckStringExpression implements IBooleanExpression {
public static final String NAME = "checkString"; //$NON-NLS-1$
public static final String STRING = "string"; //$NON-NLS-1$
public static final String VALUE = "value"; //$NON-NLS-1$
public static final String IS_REGEX = "isRegex"; //$NON-NLS-1$
public static final String YES = "yes"; //$NON-NLS-1$
public static final String TRUE = "true"; //$NON-NLS-1$
private String fString;
private String fValue;
private boolean fIsRegex;
public CheckStringExpression(IManagedConfigElement element){
fString = element.getAttribute(STRING);
if(fString == null)
fString = new String();
fValue = element.getAttribute(VALUE);
if(fValue == null)
fValue = new String();
fIsRegex = getBooleanValue(element.getAttribute(IS_REGEX));
}
protected boolean getBooleanValue(String value){
if(TRUE.equalsIgnoreCase(value))
return true;
else if(YES.equalsIgnoreCase(value))
return true;
return false;
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option) {
IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
IEnvironmentVariableProvider env = ManagedBuildManager.getEnvironmentVariableProvider();
String delimiter = env.getDefaultDelimiter();
try {
String resolvedString = provider.resolveValue(fString,
" ", //$NON-NLS-1$
delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,configuration)
);
String resolvedValue = provider.resolveValue(fValue,
" ", //$NON-NLS-1$
delimiter,
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData(option,configuration)
);
if(fIsRegex){
Pattern pattern = Pattern.compile(resolvedValue);
Matcher matcher = pattern.matcher(resolvedString);
return matcher.matches();
}
return resolvedString.equals(resolvedValue);
} catch (BuildMacroException e) {
}
return false;
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
public abstract class CompositeExpression implements IBooleanExpression {
private IBooleanExpression fChildren[];
protected CompositeExpression(IManagedConfigElement element){
IManagedConfigElement childElement[] = element.getChildren();
IBooleanExpression children[] = new IBooleanExpression[childElement.length];
int num = 0;
for(int i = 0; i < childElement.length; i++){
IBooleanExpression child = createExpression(childElement[i]);
if(child != null)
children[num++] = child;
}
if(num < children.length){
IBooleanExpression tmp[] = new IBooleanExpression[num];
System.arraycopy(children,0,tmp,0,num);
children = tmp;
}
fChildren = children;
}
protected IBooleanExpression createExpression(IManagedConfigElement element){
String name = element.getName();
if(AndExpression.NAME.equals(name))
return new AndExpression(element);
else if(OrExpression.NAME.equals(name))
return new OrExpression(element);
else if(NotExpression.NAME.equals(name))
return new NotExpression(element);
else if(CheckOptionExpression.NAME.equals(name))
return new CheckOptionExpression(element);
else if(CheckStringExpression.NAME.equals(name))
return new CheckStringExpression(element);
else if(FalseExpression.NAME.equals(name))
return new FalseExpression(element);
return null;
}
public IBooleanExpression[] getChildren(){
return fChildren;
}
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
public class FalseExpression implements IBooleanExpression {
public static final String NAME = "false"; //$NON-NLS-1$
public FalseExpression(IManagedConfigElement element) {
}
public boolean evaluate(IBuildObject configuration, IHoldsOptions holder,
IOption option) {
return false;
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IOption;
public interface IBooleanExpression {
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option);
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
public class NotExpression extends AndExpression {
public static final String NAME = "not"; //$NON-NLS-1$
public NotExpression(IManagedConfigElement element) {
super(element);
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option) {
return !super.evaluate(configuration, holder, option);
}
}

View file

@ -0,0 +1,117 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
public class OptionEnablementExpression extends AndExpression{
public static final String NAME = "enablement"; //$NON-NLS-1$
public static final String TYPE = "type"; //$NON-NLS-1$
public static final String TYPE_UI_VISIBILITY = "UI_VISIBILITY"; //$NON-NLS-1$
public static final String TYPE_UI_ENABLEMENT = "UI_ENABLEMENT"; //$NON-NLS-1$
public static final String TYPE_CMD_USAGE = "CMD_USAGE"; //$NON-NLS-1$
public static final String TYPE_ALL = "ALL"; //$NON-NLS-1$
public static final String FLAG_DELIMITER = "|"; //$NON-NLS-1$
public static final int FLAG_UI_VISIBILITY = 0x01;
public static final int FLAG_UI_ENABLEMENT = 0x02;
public static final int FLAG_CMD_USAGE = 0x04;
public static final int FLAG_ALL = ~0;
private int fEnablementFlags;
public OptionEnablementExpression(IManagedConfigElement element) {
super(element);
fEnablementFlags = calculateFlags(element.getAttribute(TYPE));
}
public String[] convertToList(String value, String delimiter){
List list = new ArrayList();
int delLength = delimiter.length();
int valLength = value.length();
if(delLength == 0){
list.add(value);
}
else{
int start = 0;
int stop;
while(start < valLength){
stop = value.indexOf(delimiter,start);
if(stop == -1)
stop = valLength;
String subst = value.substring(start,stop);
list.add(subst);
start = stop + delLength;
}
}
return (String[])list.toArray(new String[list.size()]);
}
protected int calculateFlags(String flagsString){
int flags = 0;
if(flagsString != null){
String strings[] = convertToList(flagsString,FLAG_DELIMITER);
for(int i = 0; i < strings.length; i++){
String str = strings[i].trim();
if(TYPE_UI_VISIBILITY.equals(str))
flags |= FLAG_UI_VISIBILITY;
else if(TYPE_UI_ENABLEMENT.equals(str))
flags |= FLAG_UI_ENABLEMENT;
else if(TYPE_CMD_USAGE.equals(str))
flags |= FLAG_CMD_USAGE;
else if(TYPE_ALL.equals(str))
flags |= FLAG_ALL;
}
}
if(flags == 0)
flags = FLAG_ALL;
return flags;
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option,
int flags){
if(!checkFlags(flags) || evaluate(configuration, holder, option))
return true;
return false;
}
/* public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option) {
if(getChildren().length == 0)
return false;
return super.evaluate(configuration,holder,option);
}
*/
public boolean checkFlags(int flags){
return (fEnablementFlags & flags) == flags;
}
public int getFlags(){
return fEnablementFlags;
}
}

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
public class OrExpression extends CompositeExpression {
public static final String NAME = "or"; //$NON-NLS-1$
public OrExpression(IManagedConfigElement element) {
super(element);
}
public boolean evaluate(IBuildObject configuration,
IHoldsOptions holder,
IOption option) {
IBooleanExpression children[] = getChildren();
for(int i = 0; i < children.length; i++){
if(children[i].evaluate(configuration, holder, option))
return true;
}
return false;
}
}