org.eclipse.emf.mwe.core.WorkflowInterruptedException Java Examples

The following examples show how to use org.eclipse.emf.mwe.core.WorkflowInterruptedException. 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: SlotEntry.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected Set<EClass> findEClasses(ResourceSet resourceSet, String nsURI2, String typeName2) {
	if (typeName2 == null)
		return Collections.emptySet();
	Set<EClass> result = Sets.newHashSet();
	Set<String> keySet = getNsUris();
	for (String string : keySet) {
		try {
			EPackage ePackage = resourceSet.getPackageRegistry().getEPackage(string);
			if (ePackage != null) {
				EClassifier classifier = ePackage.getEClassifier(typeName2);
				if (classifier instanceof EClass)
					result.add((EClass) classifier);
			}
		} catch(NoClassDefFoundError e) {
			throw new NoClassDefFoundError("NoClassDefFoundError while loading ePackage: " + string + " - " + e.getMessage());
		}
	}
	if (result.isEmpty()) {
		throw new WorkflowInterruptedException("Couldn't find EClass for name '" + typeName2 + "'.");
	}
	return result;
}
 
Example #2
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testLoadByType_withUnkownNsURI() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Entity");
	entry.setNsURI("unknown ns uri");
	reader.addLoad(entry);

	WorkflowContext ctx = ctx();
	try {
		reader.invoke(ctx, monitor(), issues());
		fail("workflow interuption expected.");
	} catch (WorkflowInterruptedException e) {
		//expected
	}
}
 
Example #3
Source File: Validator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void validate(ResourceSet resourceSet, IResourceServiceProvider.Registry registry, Issues issues) {
	List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
	for (Resource resource : resources) {
		try {
			resource.load(null);
			IResourceServiceProvider provider = registry.getResourceServiceProvider(resource.getURI());
			if (provider != null) {
				List<Issue> result = provider.getResourceValidator().validate(resource, CheckMode.ALL, null);
				for (Issue issue : result) {
					switch (issue.getSeverity()) {
						case ERROR:
							issues.addError(issue.getMessage(), issue);
							break;
						case WARNING:
							issues.addWarning(issue.getMessage(), issue);
							break;
						case INFO:
							issues.addInfo(issue.getMessage(), issue);
							break;
						case IGNORE:
							break;
					}
				}
			}
		} catch (IOException e) {
			throw new WorkflowInterruptedException("Couldn't load resource (" + resource.getURI() + ")", e);
		}
	}
	if (isStopOnError() && issues.hasErrors()) {
		String errorMessage = toString(issues);
		throw new WorkflowInterruptedException("Validation problems: \n" + errorMessage);
	}
}
 
Example #4
Source File: FormatFragmentUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Retrieve the format model associated with a given grammar.
 * <p>
 * <em>Note</em>: Expected to either be in same folder with the same name (except for the extension) or in the SRC outlet.
 * </p>
 *
 * @param grammar
 *          the grammar, must not be {@code null}
 * @param context
 *          xpand execution context, must not be {@code null}
 * @return the format model, or {@code null} if the resource could not be loaded
 * @throws FileNotFoundException
 *           thrown if the format file could not be found
 */
@SuppressWarnings("PMD.NPathComplexity")
public static FormatConfiguration getFormatModel(final Grammar grammar, final XpandExecutionContext context) throws FileNotFoundException {
  Variable resourceUriVariable = context.getVariable("resourceUri");
  if (resourceUriVariable == null) {
    return null;
  }
  URI uri = (URI) resourceUriVariable.getValue();
  final Resource grammarResource = grammar.eResource();
  final ResourceSet resourceSet = grammarResource.getResourceSet();
  Resource formatResource = null;
  try {
    formatResource = resourceSet.getResource(uri, true);
  } catch (final ClasspathUriResolutionException e) {
    // make another attempt
    uri = getDefaultFormatLocation(grammar, context);
    try {
      formatResource = resourceSet.getResource(uri, true);
    } catch (WrappedException e1) {
      formatResource = resourceSet.getResource(uri, false);
      if (formatResource != null) {
        resourceSet.getResources().remove(formatResource);
      }
      throw new FileNotFoundException(uri.toString()); // NOPMD
    }
  }
  if (formatResource == null) {
    throw new FileNotFoundException(uri.toString());
  }

  final List<Issue> issues = getModelValidator().validate(formatResource, LOG);

  for (final Issue issue : issues) {
    if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
      throw new WorkflowInterruptedException("Errors found in " + uri.toString() + ": " + issue.getMessage());
    }
  }

  return formatResource.getContents().size() == 0 ? null : (FormatConfiguration) formatResource.getContents().get(0);
}
 
Example #5
Source File: ValidValidatorFragment.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the valid model.
 *
 * @param grammar
 *          the grammar
 * @return the valid model
 */
private ValidModel getValidModel(final Grammar grammar) {
  if (model != null) {
    return model;
  }

  Resource resource = null;
  final String name = GrammarUtil.getSimpleName(grammar) + '.' + XTEXT_EXTENSION;
  URI uri;
  for (final Resource res : grammar.eResource().getResourceSet().getResources()) {
    if (res.getURI() != null && name.equals(EmfResourceUtil.getFileName(res.getURI()))) {
      resource = res;
      break;
    }
  }
  if (getValidURI() == null) {
    Assert.isNotNull(resource, NLS.bind(Messages.RESOURCE_NOT_FOUND, name));
    uri = resource.getURI().trimFileExtension().appendFileExtension(VALID_EXTENSION);
  } else {
    uri = URI.createURI(getValidURI());
  }

  resource = resource.getResourceSet().getResource(uri, true);

  final List<Issue> issues = VALIDATOR.validate(resource, LOGGER);
  for (final Issue issue : issues) {
    if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
      throw new WorkflowInterruptedException(NLS.bind(Messages.ERROR_FOUND, uri.toString()));
    }
  }
  model = (ValidModel) resource.getContents().get(0);
  return model;
}
 
Example #6
Source File: Reader.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void installAsAdapter(ResourceSet set, IAllContainersState containersState)
		throws WorkflowInterruptedException {
	set.eAdapters().add(new DelegatingIAllContainerAdapter(containersState));
}
 
Example #7
Source File: ExportFragment.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Get the export model that we have to process.
 *
 * @param grammar
 *          The grammar
 * @return The model
 */
private synchronized ExportModel getModel(final Grammar grammar) { // NOPMD NPathComplexity by wth on 24.11.10 08:22
  if (modelLoaded) {
    return model;
  }
  modelLoaded = true;
  Resource resource = grammar.eResource();
  if (resource == null) {
    return null;
  }

  final ResourceSet resourceSet = resource.getResourceSet();
  URI uri = null;
  if (getExportFileURI() != null) {
    uri = URI.createURI(getExportFileURI());
  } else {
    uri = grammar.eResource().getURI().trimFileExtension().appendFileExtension(EXPORT_FILE_EXTENSION);
  }
  try {
    resource = resourceSet.getResource(uri, true);
    final List<Issue> issues = VALIDATOR.validate(resource, LOGGER);

    for (final Issue issue : issues) {
      if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
        throw new WorkflowInterruptedException(NLS.bind(Messages.ExportFragment_EXPORT_ERRORS, uri));
      }
    }
    if (resource.getContents().size() == 0) {
      return null;
    }
    model = (ExportModel) resource.getContents().get(0);
    return model;
  } catch (final ClasspathUriResolutionException e) {
    // Resource does not exist.
    if (getExportFileURI() != null) {
      // Explicit file specified, but not found: stop the workflow.
      throw new WorkflowInterruptedException(NLS.bind(Messages.ExportFragment_NO_EXPORT_FILE, uri)); // NOPMD PreserveStackTrace by wth on 24.11.10 08:27
    }
    // No file found at implicit location: work with a null model, generating code that implements the default behavior.
    return null;
  }
}