Search in sources :

Example 11 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project sling by apache.

the class BundleProjectValidator method validate.

@Override
public ValidationResult validate(ValidationEvent event, ValidationState state, IProgressMonitor monitor) {
    ValidationResult res = new ValidationResult();
    IResource resource = event.getResource();
    if (!resource.getName().equals("MANIFEST.MF") || resource.getType() != IResource.FILE) {
        return res;
    }
    try {
        // sync resource with filesystem if necessary
        if (!resource.isSynchronized(IResource.DEPTH_ZERO)) {
            resource.refreshLocal(IResource.DEPTH_ZERO, null);
        }
        for (IFile descriptor : scValidator.findMissingScrDescriptors((IFile) resource)) {
            addValidatorMessage(res, resource, "No DS descriptor found at path " + descriptor.getProjectRelativePath() + ".");
        }
    } catch (CoreException e) {
        getLogger().warn("Failed validating project " + resource.getFullPath(), e);
    }
    return res;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ValidationResult(org.eclipse.wst.validation.ValidationResult) IResource(org.eclipse.core.resources.IResource)

Example 12 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project sling by apache.

the class IgnoreMissingGrammarXmlValidator method validate.

/** Perform the validation using version 2 of the validation framework. Copied from {@link AbstractNestedValidator#validate(IResource,
     * int, ValidationState, IProgressMonitor). Cannot use original one as that skips resources starting with "." */
@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    ValidationResult result = new ValidationResult();
    IFile file = null;
    if (resource instanceof IFile)
        file = (IFile) resource;
    if (file != null && shouldValidate(file)) {
        IReporter reporter = result.getReporter(monitor);
        NestedValidatorContext nestedcontext = getNestedContext(state, false);
        boolean teardownRequired = false;
        if (nestedcontext == null) {
            // validationstart was not called, so manually setup and tear down
            nestedcontext = getNestedContext(state, true);
            nestedcontext.setProject(file.getProject());
            setupValidation(nestedcontext);
            teardownRequired = true;
        } else {
            nestedcontext.setProject(file.getProject());
        }
        doValidate(file, null, result, reporter, nestedcontext);
        if (teardownRequired)
            teardownValidation(nestedcontext);
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) NestedValidatorContext(org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 13 with ValidationResult

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

the class JSPContentValidator method validate.

public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    if (!shouldValidate(resource))
        return null;
    ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    if (fragmentCheck((IFile) resource)) {
        IStructuredModel model = null;
        try {
            model = StructuredModelManager.getModelManager().getModelForRead((IFile) resource);
            if (!reporter.isCancelled() && model instanceof IDOMModel) {
                reporter.removeAllMessages(this, resource);
                validate((IFile) resource, kind, state, monitor, (IDOMModel) model, reporter);
            }
        } catch (IOException e) {
            Logger.logException(e);
        } catch (CoreException e) {
            Logger.logException(e);
        } finally {
            if (model != null)
                model.releaseFromRead();
        }
    }
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 14 with ValidationResult

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

the class JSPValidator method validate.

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

Example 15 with ValidationResult

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

the class TLDValidator method validate.

public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    ValidationResult result = new ValidationResult();
    IFile file = (IFile) resource;
    if (file.isAccessible()) {
        // TAGX
        if (fTagXexts.contains(file.getFileExtension()) || fTagXnames.contains(file.getName())) {
            monitor.beginTask("", 4);
            org.eclipse.wst.xml.core.internal.validation.eclipse.Validator xmlValidator = new org.eclipse.wst.xml.core.internal.validation.eclipse.Validator();
            ValidationResult result3 = new MarkupValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            if (monitor.isCanceled())
                return result;
            ValidationResult result2 = xmlValidator.validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            if (monitor.isCanceled())
                return result;
            ValidationResult result1 = new JSPActionValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1));
            List messages = new ArrayList(result1.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(result2.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(result3.getReporter(new NullProgressMonitor()).getMessages());
            messages.addAll(new JSPDirectiveValidator().validate(resource, kind, state, new SubProgressMonitor(monitor, 1)).getReporter(new NullProgressMonitor()).getMessages());
            for (int i = 0; i < messages.size(); i++) {
                IMessage message = (IMessage) messages.get(i);
                if (message.getText() != null && message.getText().length() > 0) {
                    ValidatorMessage vmessage = ValidatorMessage.create(message.getText(), resource);
                    if (message.getAttributes() != null) {
                        Map attrs = message.getAttributes();
                        Iterator it = attrs.entrySet().iterator();
                        while (it.hasNext()) {
                            Map.Entry entry = (Map.Entry) it.next();
                            if (!(entry.getValue() instanceof String || entry.getValue() instanceof Integer || entry.getValue() instanceof Boolean)) {
                                it.remove();
                            }
                        }
                        vmessage.setAttributes(attrs);
                    }
                    vmessage.setAttribute(IMarker.LINE_NUMBER, message.getLineNumber());
                    vmessage.setAttribute(IMarker.MESSAGE, message.getText());
                    if (message.getOffset() > -1) {
                        vmessage.setAttribute(IMarker.CHAR_START, message.getOffset());
                        vmessage.setAttribute(IMarker.CHAR_END, message.getOffset() + message.getLength());
                    }
                    int severity = 0;
                    switch(message.getSeverity()) {
                        case IMessage.HIGH_SEVERITY:
                            severity = IMarker.SEVERITY_ERROR;
                            break;
                        case IMessage.NORMAL_SEVERITY:
                            severity = IMarker.SEVERITY_WARNING;
                            break;
                        case IMessage.LOW_SEVERITY:
                            severity = IMarker.SEVERITY_INFO;
                            break;
                    }
                    vmessage.setAttribute(IMarker.SEVERITY, severity);
                    vmessage.setType(MARKER_TYPE);
                    result.add(vmessage);
                }
            }
            monitor.done();
        } else // TLD
        {
            try {
                final IJavaProject javaProject = JavaCore.create(file.getProject());
                if (javaProject.exists()) {
                    IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
                    ProjectScope projectScope = new ProjectScope(file.getProject());
                    if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
                        scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
                    }
                    Map[] problems = detectProblems(javaProject, file, scopes);
                    for (int i = 0; i < problems.length; i++) {
                        ValidatorMessage message = ValidatorMessage.create(problems[i].get(IMarker.MESSAGE).toString(), resource);
                        message.setType(MARKER_TYPE);
                        message.setAttributes(problems[i]);
                        result.add(message);
                    }
                }
            } catch (Exception e) {
                Logger.logException(e);
            }
        }
    }
    return result;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) ValidationResult(org.eclipse.wst.validation.ValidationResult) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Iterator(java.util.Iterator) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) Map(java.util.Map) MarkupValidator(org.eclipse.wst.xml.core.internal.validation.MarkupValidator) AbstractValidator(org.eclipse.wst.validation.AbstractValidator) MarkupValidator(org.eclipse.wst.xml.core.internal.validation.MarkupValidator)

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