Search in sources :

Example 1 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project liferay-ide by liferay.

the class WorkflowDefinitionValidator method validate.

@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE) {
        return null;
    }
    ValidationResult result = new ValidationResult();
    IFile workflowDefinitionXml = (IFile) resource;
    if (workflowDefinitionXml.isAccessible() && CoreUtil.isLiferayProject(resource.getProject())) {
        IScopeContext[] scopes = { new InstanceScope(), new DefaultScope() };
        ProjectScope projectScope = new ProjectScope(workflowDefinitionXml.getProject());
        boolean useProjectSettings = projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(ProjectCore.USE_PROJECT_SETTINGS, false);
        if (useProjectSettings) {
            scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
        }
        try {
            Map<String, Object>[] problems = detectProblems(workflowDefinitionXml, scopes);
            for (int i = 0; i < problems.length; i++) {
                Object messageValue = problems[i].get(IMarker.MESSAGE);
                ValidatorMessage message = ValidatorMessage.create(messageValue.toString(), resource);
                message.setType(MARKER_TYPE);
                message.setAttributes(problems[i]);
                result.add(message);
            }
            if (ListUtil.isNotEmpty(problems)) {
                IResource[] resources = { workflowDefinitionXml };
                result.setDependsOn(resources);
            }
        } catch (Exception e) {
            KaleoCore.logError(e);
        }
    }
    return result;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IFile(org.eclipse.core.resources.IFile) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) ValidationResult(org.eclipse.wst.validation.ValidationResult) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage) CoreException(org.eclipse.core.runtime.CoreException) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource)

Example 2 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project webtools.sourceediting by eclipse.

the class JsValidator method validate.

public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE || !shouldValidate((IFile) resource))
        return null;
    ValidationResult result = new ValidationResult();
    IReporter reporter = result.getReporter(monitor);
    IFile file = (IFile) resource;
    validateFile(file, reporter);
    result.setDependsOn(createDependencies(file));
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) IFile(org.eclipse.core.resources.IFile) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 3 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project webtools.sourceediting by eclipse.

the class JSPBatchValidatorTest method testFragmentValidationPreferenceOnProject.

public void testFragmentValidationPreferenceOnProject() throws Exception {
    JSPBatchValidator validator1 = new JSPBatchValidator();
    JSPContentValidator validator2 = new JSPContentValidator();
    String filePath = "/" + PROJECT_NAME + "/WebContent/header.jspf";
    ValidationResult result = null;
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    // enable workspace-wide but disable in project, no problem markers
    // expected
    workspaceScope.putBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, true);
    projectScope.putBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, true);
    projectScope.putBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, false);
    result = validator1.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor());
    result.mergeResults(validator2.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor()));
    assertEquals("Problems found while fragment validation was disabled in project but enabled on workspace", 0, (((ReporterHelper) result.getReporter(null)).getMessages().size()));
    /*
		 * disable workspace-wide but enable in project, some problem markers
		 * expected
		 */
    workspaceScope.putBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, false);
    projectScope.putBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, true);
    projectScope.putBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, true);
    JSPFContentProperties.setProperty(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, file, Boolean.toString(true));
    result = validator1.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor());
    result.mergeResults(validator2.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor()));
    assertTrue("Problems not found while fragment validation was enabled for project but disabled on workspace", 0 < (((ReporterHelper) result.getReporter(null)).getMessages().size()));
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ValidationState(org.eclipse.wst.validation.ValidationState) IFile(org.eclipse.core.resources.IFile) JSPBatchValidator(org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator) JSPContentValidator(org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator) ValidationResult(org.eclipse.wst.validation.ValidationResult) ReporterHelper(org.eclipse.wst.validation.ReporterHelper)

Example 4 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project webtools.sourceediting by eclipse.

the class JSONSyntaxValidator method validate.

public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    fReporter = result.getReporter(monitor);
    validateFile((IFile) resource, fReporter);
    return result;
}
Also used : ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 5 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project webtools.sourceediting by eclipse.

the class MarkupValidator method validate.

/* (non-Javadoc)
	 * @see org.eclipse.wst.validation.AbstractValidator#validate(org.eclipse.core.resources.IResource, int, org.eclipse.wst.validation.ValidationState, org.eclipse.core.runtime.IProgressMonitor)
	 */
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    IReporter reporter = result.getReporter(monitor);
    validateV1File((IFile) resource, reporter);
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Aggregations

ValidationResult (org.eclipse.wst.validation.ValidationResult)21 IFile (org.eclipse.core.resources.IFile)14 IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)9 CoreException (org.eclipse.core.runtime.CoreException)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IResource (org.eclipse.core.resources.IResource)4 IOException (java.io.IOException)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 ValidationState (org.eclipse.wst.validation.ValidationState)3 ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)3 List (java.util.List)2 Map (java.util.Map)2 IProject (org.eclipse.core.resources.IProject)2 ProjectScope (org.eclipse.core.resources.ProjectScope)2 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)2 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)2 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)2 JSPBatchValidator (org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator)2 JSPContentValidator (org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)2