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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations