Search in sources :

Example 16 with ValidationResult

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

the class JSPBatchValidator method validate.

public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE)
        return null;
    if (!shouldValidate((IFile) resource))
        return null;
    final ValidationResult result = new ValidationResult();
    final IReporter reporter = result.getReporter(monitor);
    if (result.getDependsOn() != null) {
        fDependsOn = new HashSet(Arrays.asList(result.getDependsOn()));
    } else {
        fDependsOn = new HashSet();
    }
    // add web.xml as a dependency
    addDependsOn(DeploymentDescriptorPropertyCache.getInstance().getWebXML(resource.getFullPath()));
    // List relevant JSP 2.0 preludes/codas as dependencies
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(resource.getFullPath());
    for (int j = 0; j < propertyGroups.length; j++) {
        IPath[] preludes = propertyGroups[j].getIncludePrelude();
        for (int i = 0; i < preludes.length; i++) {
            addDependsOn(workspaceRoot.getFile(preludes[i]));
        }
        IPath[] codas = propertyGroups[j].getIncludeCoda();
        for (int i = 0; i < codas.length; i++) {
            addDependsOn(workspaceRoot.getFile(codas[i]));
        }
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            if (fragmentCheck((IFile) resource)) {
                validateFile((IFile) resource, reporter);
            }
            IResource[] resources = (IResource[]) fDependsOn.toArray(new IResource[fDependsOn.size()]);
            result.setDependsOn(resources);
            fDependsOn.clear();
        }
    };
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return result;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) PropertyGroup(org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache.PropertyGroup) IPath(org.eclipse.core.runtime.IPath) ValidationResult(org.eclipse.wst.validation.ValidationResult) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IValidatorJob(org.eclipse.wst.validation.internal.provisional.core.IValidatorJob) Job(org.eclipse.core.runtime.jobs.Job) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 17 with ValidationResult

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

the class JSPBatchValidatorTest method testFragmentValidationPreferenceOnWorkspace.

public void testFragmentValidationPreferenceOnWorkspace() throws Exception {
    JSPBatchValidator validator1 = new JSPBatchValidator();
    JSPContentValidator validator2 = new JSPContentValidator();
    String filePath = "/" + PROJECT_NAME + "/WebContent/header.jspf";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    ValidationResult result = null;
    // disable workspace-wide, no problem markers expected
    workspaceScope.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("Problem markers found while fragment validation was disabled", 0, (((ReporterHelper) result.getReporter(null)).getMessages().size()));
    // enable workspace-wide, some problem markers expected
    workspaceScope.putBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, true);
    ValidationFramework.getDefault().validate(new IProject[] { getProject() }, true, false, new NullProgressMonitor());
    ValidationFramework.getDefault().join(new NullProgressMonitor());
    result = validator1.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor());
    result.mergeResults(validator2.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor()));
    assertTrue("Problem markers not found while fragment validation was enabled on workspace", (((ReporterHelper) result.getReporter(null)).getMessages().size()) != 0);
    // check default value is true
    workspaceScope.remove(JSPCorePreferenceNames.VALIDATE_FRAGMENTS);
    projectScope.remove(JSPCorePreferenceNames.VALIDATE_FRAGMENTS);
    projectScope.remove(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS);
    result = validator1.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor());
    result.mergeResults(validator2.validate(file, IResourceDelta.CHANGED, new ValidationState(), new NullProgressMonitor()));
    assertTrue("Problem markers not found while fragment validation was preferences were default", (((ReporterHelper) result.getReporter(null)).getMessages().size()) != 0);
}
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 18 with ValidationResult

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

the class AbstractNestedValidator method validate.

/**
 * Perform the validation using version 2 of the validation framework.
 */
@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());
        }
        InputStream inputStream = null;
        try {
            inputStream = file.getContents();
            validate(file, inputStream, result, reporter, nestedcontext);
            List messages = reporter.getMessages();
            for (Object object : messages) {
                if (object instanceof IMessage) {
                    IMessage message = (IMessage) object;
                    message.setLineNo(message.getLineNumber() + 1);
                }
            }
        } catch (CoreException e) {
            Logger.logException(e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                }
            }
        }
        if (teardownRequired)
            teardownValidation(nestedcontext);
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) List(java.util.List) IOException(java.io.IOException) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 19 with ValidationResult

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

the class HTMLValidator method validate.

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);
    validateFile(null, reporter, (IFile) resource, result);
    return result;
}
Also used : IReporter(org.eclipse.wst.validation.internal.provisional.core.IReporter) ValidationResult(org.eclipse.wst.validation.ValidationResult)

Example 20 with ValidationResult

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

the class Validator2 method validate.

@Override
public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
    /*
		 * String s; switch(kind) { case IResourceDelta.ADDED: s = "added"; break; case IResourceDelta.CHANGED: s = "CHANGED"; break; case IResourceDelta.CONTENT: s = "CONTENT"; break; case
		 * IResourceDelta.REMOVED: s = "REMOVED"; break; default: s = "other"; } System.out.println(s);
		 */
    ValidationResult result = new ValidationResult();
    if (resource.getType() == IResource.FILE) {
        IFile file = (IFile) resource;
        ValidationReport report = doValidation(file, kind, state, monitor);
        StylesheetModel stylesheet = XSLCore.getInstance().getStylesheet(file);
        IFile[] dependencies = stylesheet.getFileDependencies().toArray(new IFile[0]);
        result.setDependsOn(dependencies);
        for (ValidationMessage message : report.getValidationMessages()) {
            XSLValidationMessage xslMsg = (XSLValidationMessage) message;
            ValidatorMessage msg = ValidatorMessage.create(message.getMessage(), resource);
            // $NON-NLS-1$
            msg.setAttribute("lineNumber", xslMsg.getLineNumber());
            // $NON-NLS-1$
            msg.setAttribute("severity", xslMsg.getSeverity());
            result.add(msg);
        }
    }
    return result;
}
Also used : XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) IFile(org.eclipse.core.resources.IFile) XSLValidationMessage(org.eclipse.wst.xsl.core.internal.validation.XSLValidationMessage) ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) ValidationReport(org.eclipse.wst.xml.core.internal.validation.core.ValidationReport) ValidationResult(org.eclipse.wst.validation.ValidationResult) StylesheetModel(org.eclipse.wst.xsl.core.model.StylesheetModel) ValidatorMessage(org.eclipse.wst.validation.ValidatorMessage)

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