diff options
author | cbateman | 2008-07-29 23:00:39 +0000 |
---|---|---|
committer | cbateman | 2008-07-29 23:00:39 +0000 |
commit | b073b014eaf3fef3a6311b50bb144f373df5e0e4 (patch) | |
tree | 29726774512dcdc406ba89ac4ad3b1213ec6ab95 | |
parent | 8fde5a8f0c0a79e38dd2530192199213f0c8cdfd (diff) | |
download | webtools.jsf-b073b014eaf3fef3a6311b50bb144f373df5e0e4.tar.gz webtools.jsf-b073b014eaf3fef3a6311b50bb144f373df5e0e4.tar.xz webtools.jsf-b073b014eaf3fef3a6311b50bb144f373df5e0e4.zip |
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=228298. Enables the V2 validator framework.
3 files changed, 176 insertions, 119 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF b/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF index 5dc60d193..db85a1e02 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF +++ b/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF @@ -109,7 +109,7 @@ Export-Package: org.eclipse.jst.jsf.core, org.eclipse.jst.jsf.facelet.ui", org.eclipse.jst.jsf.taglibprocessing.attributevalues, org.eclipse.jst.jsf.validation.internal;x-friends:="org.eclipse.jst.jsf.ui", - org.eclipse.jst.jsf.validation.internal.appconfig;x-friends:="org.eclipse.jst.jsf.core.tests", + org.eclipse.jst.jsf.validation.internal.appconfig;x-friends:="org.eclipse.jst.jsf.ui,org.eclipse.jst.jsf.core.tests", org.eclipse.jst.jsf.validation.internal.constraints;x-internal:=true, org.eclipse.jst.jsf.validation.internal.constraints.impl;x-internal:=true, org.eclipse.jst.jsf.validation.internal.constraints.util;x-internal:=true, diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/AppConfigValidator.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/AppConfigValidator.java index 0ae9104b2..6f5161705 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/AppConfigValidator.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/AppConfigValidator.java @@ -7,7 +7,7 @@ * * Contributors: * Cameron Bateman/Oracle - initial API and implementation - * + * ********************************************************************************/ package org.eclipse.jst.jsf.validation.internal.appconfig; @@ -20,10 +20,12 @@ import java.util.regex.Pattern; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; @@ -37,11 +39,14 @@ import org.eclipse.jst.jsp.core.internal.Logger; import org.eclipse.wst.common.project.facet.core.IFacetedProject; import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; +import org.eclipse.wst.validation.AbstractValidator; +import org.eclipse.wst.validation.ValidationResult; +import org.eclipse.wst.validation.ValidationState; import org.eclipse.wst.validation.internal.core.ValidationException; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; -import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; +import org.eclipse.wst.validation.internal.provisional.core.IValidator; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; import org.w3c.dom.DocumentType; @@ -49,42 +54,64 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -/** +/** * General build-time validator for the JSF application configuration file (faces-config.xml)b * * @author cbateman * */ -public class AppConfigValidator implements IValidatorJob { +public class AppConfigValidator extends AbstractValidator implements IValidator { + + @Override + public ValidationResult validate(final IResource resource, final int kind, + final ValidationState state, final IProgressMonitor monitor) { + final ValidationResult vr = new ValidationResult(); + if (resource == null || !(resource instanceof IFile)) { + return vr; + } + final IReporter reporter = vr.getReporter(monitor); + validateFile((IFile) resource, reporter); + return vr; + } - public ISchedulingRule getSchedulingRule(IValidationContext helper) { + /** + * @param helper + * @return the scheduling rull for this validator + */ + public ISchedulingRule getSchedulingRule(final IValidationContext helper) { // no scheduling rule return null; } - public IStatus validateInJob(IValidationContext helper, IReporter reporter) + /** + * @param helper + * @param reporter + * @return the result of running validation + * @throws ValidationException + */ + public IStatus validateInJob(final IValidationContext helper, final IReporter reporter) throws ValidationException { IStatus status = Status.OK_STATUS; try { validate(helper, reporter); } - catch (ValidationException e) { + catch (final ValidationException e) { Logger.logException(e); status = new Status(IStatus.ERROR, JSFCorePlugin.getDefault().getPluginID(), IStatus.ERROR, e.getLocalizedMessage(), e); } return status; } - public void cleanup(IReporter reporter) { + public void cleanup(final IReporter reporter) { // no cleanup } - public void validate(IValidationContext helper, IReporter reporter) - throws ValidationException + public void validate(final IValidationContext helper, final IReporter reporter) + throws ValidationException { - String[] uris = helper.getURIs(); - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); + final String[] uris = helper.getURIs(); + final IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); if (uris.length > 0) { IFile currentFile = null; @@ -101,7 +128,7 @@ public class AppConfigValidator implements IValidatorJob { } } } - + // copied from JSPValidator TODO: perhaps just use app config locator? // else { // @@ -134,20 +161,20 @@ public class AppConfigValidator implements IValidatorJob { // } } - private void validateFile(IFile file, IReporter reporter) + private void validateFile(final IFile file, final IReporter reporter) { FacesConfigArtifactEdit facesConfigEdit = null; - + try { - IPath path = JSFAppConfigUtils.getWebContentFolderRelativePath(file); + final IPath path = JSFAppConfigUtils.getWebContentFolderRelativePath(file); facesConfigEdit = FacesConfigArtifactEdit. getFacesConfigArtifactEditForRead(file.getProject(), path.toString()); - + if (facesConfigEdit != null && facesConfigEdit.getFacesConfig()!=null) { - String version = validateVersioning(file, facesConfigEdit, reporter); + final String version = validateVersioning(file, facesConfigEdit, reporter); validateModel(file, facesConfigEdit,reporter, version); } } @@ -159,38 +186,38 @@ public class AppConfigValidator implements IValidatorJob { } } } - + /** * Ensure that the expected project version (facet) jives with what is in * the faces-config. Generally this means: - * + * * if (version == 1.1) then no 1.2 artifacts (error) * if (version == 1.2) then warn if using old artifacts (warning) */ - private String validateVersioning(IFile file, FacesConfigArtifactEdit facesConfigEdit, IReporter reporter) + private String validateVersioning(final IFile file, final FacesConfigArtifactEdit facesConfigEdit, final IReporter reporter) { final String appConfigFileVersion = getAppConfigFileVersion(facesConfigEdit); - + if (appConfigFileVersion != null) { final String projectVersion = getJSFVersion(file.getProject()); - + if (IJSFCoreConstants.FACET_VERSION_1_1.equals(projectVersion) || IJSFCoreConstants.FACET_VERSION_1_0.equals(projectVersion)) { if (IJSFCoreConstants.FACET_VERSION_1_2.equals(appConfigFileVersion)) { - reporter.addMessage(this, + reporter.addMessage(this, DiagnosticFactory .create_APP_CONFIG_IS_NEWER_THAN_JSF_VERSION(file)); } } else if (IJSFCoreConstants.FACET_VERSION_1_2.equals(projectVersion)) { - if (IJSFCoreConstants.FACET_VERSION_1_1.equals(appConfigFileVersion) + if (IJSFCoreConstants.FACET_VERSION_1_1.equals(appConfigFileVersion) || IJSFCoreConstants.FACET_VERSION_1_0.equals(appConfigFileVersion)) { - reporter.addMessage(this, + reporter.addMessage(this, DiagnosticFactory .create_APP_CONFIG_IS_OLDER_THAN_JSF_VERSION(file , appConfigFileVersion, projectVersion)); @@ -200,21 +227,21 @@ public class AppConfigValidator implements IValidatorJob { } return appConfigFileVersion; } - + /** * @param facesConfigEdit * @return the version of the app config file or null if not determinant */ - private String getAppConfigFileVersion(FacesConfigArtifactEdit facesConfigEdit) + private String getAppConfigFileVersion(final FacesConfigArtifactEdit facesConfigEdit) { String appConfigVersion = null; - + final IDOMModel domModel = facesConfigEdit.getIDOMModel(); final IDOMDocument document = domModel.getDocument(); if (document == null) {return null;} - + final DocumentType docType = domModel.getDocument().getDoctype(); - + // if we have DTD doctype then we're looking at 1.1 or before if (docType != null) { @@ -227,52 +254,52 @@ public class AppConfigValidator implements IValidatorJob { } else { - NodeList rootNodes = domModel.getDocument().getChildNodes(); - + final NodeList rootNodes = domModel.getDocument().getChildNodes(); + for (int i = 0; i < rootNodes.getLength(); i++) { - Node node = rootNodes.item(i); + final Node node = rootNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && "faces-config".equals(node.getLocalName())) { - NamedNodeMap map = node.getAttributes(); + final NamedNodeMap map = node.getAttributes(); // the most accurate thing is the version - Node versionAttrib = map.getNamedItem("version"); - + final Node versionAttrib = map.getNamedItem("version"); + if (versionAttrib != null) { appConfigVersion = versionAttrib.getNodeValue(); break; } - + // TODO: add additional heuristic to parse out // the schema } } } - + return appConfigVersion; } - - private void validateModel(final IFile file, - final FacesConfigArtifactEdit facesConfigEdit, + + private void validateModel(final IFile file, + final FacesConfigArtifactEdit facesConfigEdit, final IReporter reporter, final String version) { final FacesConfigType facesConfigType = facesConfigEdit.getFacesConfig(); - FacesConfigValidator validator = new FacesConfigValidator(version); - List messages = new ArrayList(); + final FacesConfigValidator validator = new FacesConfigValidator(version); + final List messages = new ArrayList(); validator.validate(facesConfigType, messages, file); - + for (final Iterator it = messages.iterator(); it.hasNext();) { - IMessage message = (IMessage) it.next(); + final IMessage message = (IMessage) it.next(); reporter.addMessage(this, message); } } - + /** * @param project * @return the version string for the JSF facet on project @@ -283,28 +310,28 @@ public class AppConfigValidator implements IValidatorJob { try { final IFacetedProject facetedProject = ProjectFacetsManager.create(project); - Set facets = facetedProject.getProjectFacets(); - + final Set facets = facetedProject.getProjectFacets(); + for (final Iterator it = facets.iterator(); it.hasNext();) { - IProjectFacetVersion facetVersion = + final IProjectFacetVersion facetVersion = (IProjectFacetVersion) it.next(); - + if (IJSFCoreConstants.JSF_CORE_FACET_ID.equals(facetVersion.getProjectFacet().getId())) { return facetVersion.getVersionString(); } } } - catch (CoreException ce) + catch (final CoreException ce) { JSFCorePlugin.log(ce, "Problem loading faceted project"); // fall-through and return null } return null; } - - private String extractVersionFromPublicId(DocumentType docType) + + private String extractVersionFromPublicId(final DocumentType docType) { final String publicId = docType.getPublicId(); final String publicIdRegex = "-\\/\\/(.*)\\/\\/(.*)\\/\\/.*"; @@ -312,26 +339,26 @@ public class AppConfigValidator implements IValidatorJob { if (publicId != null) { final Pattern pattern = Pattern.compile(publicIdRegex); - Matcher matcher = pattern.matcher(publicId); + final Matcher matcher = pattern.matcher(publicId); if (matcher.matches()) { final String classTypeString = matcher.group(2); final String[] classTypes = classTypeString.split("\\s+"); - + // verify that the class type is a DTD if (classTypes.length > 0 && "DTD".equals(classTypes[0])) { // either 1.0 or 1.1; be most conservative String appConfigVersion = IJSFCoreConstants.JSF_VERSION_1_0; - + // see if the version is in the public id if (IJSFCoreConstants.JSF_VERSION_1_1.equals(classTypes[classTypes.length-1])) { appConfigVersion = IJSFCoreConstants.FACET_VERSION_1_1; } - + return appConfigVersion; } } @@ -340,14 +367,14 @@ public class AppConfigValidator implements IValidatorJob { return null; } - private String extractVersionFromSystemId(DocumentType docType) + private String extractVersionFromSystemId(final DocumentType docType) { final String systemId = docType.getSystemId(); final String systemIdRegEx = "http:\\/\\/java.sun.com\\/dtd\\/web-facesconfig_(.*)\\.dtd"; if (systemId != null) { final Pattern pattern = Pattern.compile(systemIdRegEx); - Matcher matcher = pattern.matcher(systemId); + final Matcher matcher = pattern.matcher(systemId); if (matcher.matches()) { diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml b/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml index 2d1ede2e9..b1306b3a6 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml @@ -126,64 +126,94 @@ </extension> <extension - point="org.eclipse.wst.validation.validator" - id="JSFNonELAttributeValueValidator" - name="%JSFNonELAttributeValueValidator"> - <validator> - <projectNature id="org.eclipse.wst.common.modulecore.ModuleCoreNature" /> - <projectNature id="org.eclipse.jdt.core.javanature" /> - <enablement> - <and> - <test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jst.java"/> - <test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jst.web"/> - <test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jst.jsf"/> - </and> - </enablement> - - <markerId - markerIdValue="JSPSemanticsValidatorMarker"> - </markerId> - <helper - class="org.eclipse.wst.validation.internal.operations.WorkbenchContext"> - </helper> - <run - class="org.eclipse.jst.jsf.ui.internal.validation.JSFValidator" - incremental="true" - fullBuild="true" - /> - <contentTypeBinding - contentTypeId="org.eclipse.jst.jsp.core.jspsource"> - </contentTypeBinding> - <contentTypeBinding - contentTypeId="org.eclipse.jst.jsp.core.jspfragmentsource"> - </contentTypeBinding> - </validator> - </extension> - - <extension - point="org.eclipse.wst.validation.validator" - id="JSFAppConfigValidator" - name="%JSFAppConfigValidator"> - <validator> - <projectNature id="org.eclipse.wst.common.modulecore.ModuleCoreNature" /> - <projectNature id="org.eclipse.jdt.core.javanature" /> - <filter - objectClass="org.eclipse.core.resources.IFile" - nameFilter="faces-config.xml"> - </filter> - <markerId - markerIdValue="JSPSemanticsValidatorMarker"> - </markerId> - <helper - class="org.eclipse.wst.validation.internal.operations.WorkbenchContext"> - </helper> - <run - class="org.eclipse.jst.jsf.validation.internal.appconfig.AppConfigValidator" - incremental="true" - fullBuild="true" - /> - </validator> - </extension> + id="JSFNonELAttributeValueValidator" + name="%JSFNonELAttributeValueValidator" + point="org.eclipse.wst.validation.validatorV2"> + <validator + build="true" + class="org.eclipse.jst.jsf.ui.internal.validation.JSFValidator" + manual="true" + markerId="org.eclipse.jst.jsf.ui.JSPSemanticsValidatorMarker" + sourceid="org.eclipse.jst.jsf.validation.JSFAttributeValueValidator" + version="1"> + <include> + <rules> + <facet + id="jst.java"> + </facet> + </rules> + </include> + <include> + <rules> + <facet + id="jst.web"> + </facet> + </rules> + </include> + <include> + <rules> + <facet + id="jst.jsf"> + </facet> + </rules> + </include> + <include> + <rules> + <projectNature + id="org.eclipse.wst.common.modulecore.ModuleCoreNature"> + </projectNature> + </rules> + </include> + <include> + <rules> + <projectNature + id="org.eclipse.jdt.core.javanature"> + </projectNature> + </rules> + </include> + <include> + <rules> + <contentType + exactMatch="false" + id="org.eclipse.jst.jsp.core.jspsource"> + </contentType> + <contentType + exactMatch="true" + id="org.eclipse.jst.jsp.core.jspfragmentsource"> + </contentType> + </rules> + </include> + <group + id="org.eclipse.wst.sse.core.structuredModelGroup"> + </group> + </validator> + </extension> + + <extension id="JSFAppConfigValidator" name="%JSFAppConfigValidator" point="org.eclipse.wst.validation.validatorV2"> + <validator + build="true" + class="org.eclipse.jst.jsf.validation.internal.appconfig.AppConfigValidator" + manual="true" + markerId="org.eclipse.jst.jsf.ui.JSPSemanticsValidatorMarker" + version="1"> + <include> + <rules> + <projectNature id="org.eclipse.wst.common.modulecore.ModuleCoreNature"/> + </rules> + </include> + <include> + <rules> + <projectNature id="org.eclipse.jdt.core.javanature"/> + </rules> + </include> + <include> + <rules> + <contentType id="org.eclipse.jst.jsf.facesconfig.facesConfigFile" exactMatch="true" /> + </rules> + </include> + </validator> + </extension> + <extension point="org.eclipse.ui.editors.templates"> <template |