org.eclipse.wst.validation.internal.core.ValidationException Java Examples

The following examples show how to use org.eclipse.wst.validation.internal.core.ValidationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlSourceValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidate_appEngineStandardFacet() throws CoreException, ValidationException {
  IProject project = appEngineStandardProject.getProject();
  IFile file = project.getFile("testdata.xml");
  file.create(ValidationTestUtils.stringToInputStream(APPLICATION_XML), 0, null);

  IDocument document = ValidationTestUtils.getDocument(file);

  // Adds the URI of the file to be validated to the IncrementalHelper.
  IncrementalHelper helper = new IncrementalHelper(document, project);
  IPath path = file.getFullPath();
  helper.setURI(path.toString());

  XmlSourceValidator validator = new XmlSourceValidator();
  validator.setHelper(new AppEngineWebXmlValidator());
  validator.connect(document);
  validator.validate(helper, reporter);
  assertEquals(1, reporter.getMessages().size());
}
 
Example #2
Source File: XmlSourceValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidate_dynamicWebProject() throws CoreException, ValidationException {
  IProject project = dynamicWebProject.getProject();
  IFile file = project.getFile("testdata.xml");
  file.create(ValidationTestUtils.stringToInputStream(APPLICATION_XML), 0, null);

  IDocument document = ValidationTestUtils.getDocument(file);

  // Adds the URI of the file to be validated to the IncrementalHelper.
  IncrementalHelper helper = new IncrementalHelper(document, project);
  IPath path = file.getFullPath();
  helper.setURI(path.toString());

  XmlSourceValidator validator = new XmlSourceValidator();
  validator.setHelper(new AppEngineWebXmlValidator());
  validator.connect(document);
  validator.validate(helper, reporter);
  assertTrue(reporter.getMessages().isEmpty());
}
 
Example #3
Source File: XmlSourceValidatorTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoErrorOnNonFacetedProject() throws CoreException, ValidationException {
  IProject project = nonFacetedProject.getProject();
  assertNull("project should have not been faceted", ProjectFacetsManager.create(project));

  project.getFolder("folder").create(true, true, null);
  project.getFile("folder/file.ext").create(new ByteArrayInputStream(new byte[0]), true, null);
  assertTrue(project.getFile("folder/file.ext").exists());

  IValidationContext validationContext = mock(IValidationContext.class);
  when(validationContext.getURIs()).thenReturn(
      new String[] {project.getName() + "/folder/file.ext"});

  new XmlSourceValidator().validate(validationContext, reporter);
  // Should not throw NPE and exit normally.
}
 
Example #4
Source File: XmlSourceValidator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Validates a given {@link IDocument} if the project has the App Engine Standard facet.
 */
@Override
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
  IProject project = getProject(helper);
  try {
    IFacetedProject facetedProject = ProjectFacetsManager.create(project);
    if (facetedProject != null && AppEngineStandardFacet.hasFacet(facetedProject)) {
      String encoding = getDocumentEncoding(document);
      byte[] bytes = document.get().getBytes(encoding);
      IFile source = getFile(helper);
      validate(reporter, source, bytes);
    }
  } catch (IOException | CoreException ex) {
    logger.log(Level.SEVERE, ex.getMessage());
  }
}
 
Example #5
Source File: TypeScriptSourceValidator.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {

	if (helper == null || document == null) {
		return;
	}

	if ((reporter != null) && (reporter.isCancelled() == true)) {
		throw new OperationCanceledException();
	}

	// we cannot use helper#getURI() to retrieve the IFile which is
	// validating, because
	// this helper is filled by using IStructuredModel (see
	// ReconcileStepForValidator#getFile())
	// and JSDT JavaScript Editor doesn't manage IStructuredModel
	IFile file = TypeScriptResourceUtil.getFile(document);
	if (file == null || !TypeScriptResourceUtil.canConsumeTsserver(file)) {
		return;
	}

	try {
		IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(file.getProject());
		IIDETypeScriptFile tsFile = tsProject.openFile(file, document);
		TypeScriptValidationHelper.validate(tsFile, reporter, this);
	} catch (Exception e) {
		Trace.trace(Trace.SEVERE, "Error while TypeScript validation.", e);
	}
}
 
Example #6
Source File: TypeScriptValidator.java    From typescript.java with MIT License 4 votes vote down vote up
@Override
public void validate(IValidationContext context, IReporter reporter) throws ValidationException {
	// It seems that it is never called?
}
 
Example #7
Source File: TypeScriptValidator.java    From typescript.java with MIT License 4 votes vote down vote up
@Override
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException {
	IStatus status = Status.OK_STATUS;
	validate(helper, reporter);
	return status;
}