[118448] [validation] org.eclipse.wst.validation.validator support for facets
diff --git a/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF
index 893a4bc..cb91f1c 100644
--- a/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.validation/META-INF/MANIFEST.MF
@@ -17,5 +17,6 @@
org.eclipse.wst.common.frameworks,
org.eclipse.jem.util,
org.eclipse.core.runtime,
- org.eclipse.wst.common.project.facet.core
+ org.eclipse.wst.common.project.facet.core,
+ org.eclipse.core.expressions
Eclipse-AutoStart: true
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java
index d3c3c23..38daa3a 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidationRegistryReader.java
@@ -24,6 +24,11 @@
import java.util.StringTokenizer;
import java.util.logging.Level;
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionConverter;
+import org.eclipse.core.expressions.ExpressionTagNames;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
@@ -924,27 +929,31 @@
* @param vmds
* @param projectNatures
*/
- private void calculateVmdsForNatureAndFacets(Set vmds, String[] projectNatures,IProject project) {
+ private void calculateVmdsForNatureAndFacets(Set vmds, String[] projectNatures, IProject project) {
Set projVmds;
String[] projectFacetIds = getProjectFacetIds(project);
Iterator allValidators = getAllValidators().iterator();
while (allValidators.hasNext()) {
ValidatorMetaData vmd = (ValidatorMetaData) allValidators.next();
- if (containsProjectFacet(vmd, projectFacetIds)) {
+ if (containsProjectFacet(vmd, projectFacetIds) || isFacetEnabled(vmd, project)) {
vmds.add(vmd);
}
}
for (int i = 0; i < projectNatures.length; i++) {
String projectNatureId = projectNatures[i];
projVmds = (Set) _validators.get(projectNatureId);
- if (projVmds == null) {
+ if (projVmds == null)
continue;
- }
+
Iterator iterator = projVmds.iterator();
while (iterator.hasNext()) {
ValidatorMetaData vmd = (ValidatorMetaData) iterator.next();
if (!vmds.contains(vmd) && (vmd.getFacetFilters() == null || vmd.getFacetFilters().length == 0)) {
- vmds.add(vmd);
+ if (vmd.getEnablementExpresion() == null)
+ vmds.add(vmd);
+ else if (isFacetEnabled(vmd, project))
+ vmds.add(vmd);
+
}
}
}
@@ -960,6 +969,19 @@
}
return false;
}
+
+ private boolean isFacetEnabled(ValidatorMetaData vmd, IProject project) {
+ try {
+ Expression expression = vmd.getEnablementExpresion();
+ if (expression != null) {
+ EvaluationResult result = vmd.getEnablementExpresion().evaluate(new EvaluationContext(null,project));
+ return result.equals(EvaluationResult.TRUE);
+ }
+ } catch (CoreException ce) {
+ Logger.getLogger().log(ce);
+ }
+ return false;
+ }
private String[] getProjectFacetIds(IProject project) {
try {
@@ -1323,13 +1345,10 @@
vmd.addFilters(getFilters(element)); // validator may, or may not, have filters
vmd.addProjectNatureFilters(getProjectNatureFilters(element)); // validator may, or may not, specify a project nature
vmd.addFacetFilters(getFacetIds(element));//validator may or may not specify the facet
+ vmd.setEnablementElement(getEnablementElement(element));
vmd.addAggregatedValidatorNames(getAggregateValidatorsNames(element)); // if a validator
- // aggregated another
- // validator, it
- // should identify
- // the
- // sub-validator(s)'
- // class name
+ // aggregated another validator, it should identify
+ // the sub-validator(s)' class name
vmd.setValidatorDisplayName(validatorName.intern()); // validator must have a display name.
vmd.setValidatorUniqueName(validatorImplName.intern());
vmd.setPluginId(pluginId);
@@ -1362,6 +1381,18 @@
return vmd;
}
+ private Expression getEnablementElement(IConfigurationElement element) {
+ IConfigurationElement[] enablements = element.getChildren(ExpressionTagNames.ENABLEMENT);
+ if (enablements.length == 0)
+ return null;
+ try {
+ return ExpressionConverter.getDefault().perform(enablements[0]);
+ } catch (CoreException ce) {
+ Logger.getLogger().log(ce);
+ }
+ return null;
+ }
+
private List getTempList() {
// Return a list for temporary use
if (_tempList == null) {
diff --git a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorMetaData.java b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorMetaData.java
index f669c54..b17adb0 100644
--- a/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorMetaData.java
+++ b/plugins/org.eclipse.wst.validation/validate/org/eclipse/wst/validation/internal/ValidatorMetaData.java
@@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;
+import org.eclipse.core.expressions.Expression;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -66,6 +67,7 @@
private boolean manualValidation = true;
private boolean buildValidation = true;
private Map helpers = Collections.synchronizedMap( new HashMap() );
+ private Expression enablementExpression = null;
/* package */ValidatorMetaData() {
//default
@@ -586,4 +588,14 @@
return null;
}
+
+ public Expression getEnablementExpresion() {
+ return enablementExpression;
+ }
+
+ public void setEnablementElement(Expression enablementElement) {
+ enablementExpression = enablementElement;
+ }
+
+
}
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.validation/xsds/validatorExtSchema.exsd b/plugins/org.eclipse.wst.validation/xsds/validatorExtSchema.exsd
index 7850369..8614cdb 100644
--- a/plugins/org.eclipse.wst.validation/xsds/validatorExtSchema.exsd
+++ b/plugins/org.eclipse.wst.validation/xsds/validatorExtSchema.exsd
@@ -49,6 +49,7 @@
<element ref="run"/>
<element ref="markerId" minOccurs="0" maxOccurs="1"/>
<element ref="facet" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="enablement" minOccurs="0" maxOccurs="1"/>
</sequence>
<attribute name="to" type="string">
<annotation>
@@ -245,6 +246,57 @@
</complexType>
</element>
+ <element name="enablement">
+ <complexType>
+ <sequence>
+ <element ref="or" minOccurs="1" maxOccurs="unbounded"/>
+ <element ref="and" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="or">
+ <complexType>
+ <sequence>
+ <element ref="test"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="and">
+ <complexType>
+ <sequence>
+ <element ref="test"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="test">
+ <complexType>
+ <attribute name="property" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="value" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="version" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>