use of org.eclipse.emf.mwe.core.WorkflowInterruptedException in project dsl-devkit by dsldevkit.
the class ExportFragment method getModel.
/**
* 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) {
// NOPMD PreserveStackTrace by wth on 24.11.10 08:27
throw new WorkflowInterruptedException(NLS.bind(Messages.ExportFragment_NO_EXPORT_FILE, uri));
}
// No file found at implicit location: work with a null model, generating code that implements the default behavior.
return null;
}
}
use of org.eclipse.emf.mwe.core.WorkflowInterruptedException in project dsl-devkit by dsldevkit.
the class ValidValidatorFragment method getValidModel.
/**
* 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.getName(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;
}
use of org.eclipse.emf.mwe.core.WorkflowInterruptedException in project xtext-core by eclipse.
the class AbstractReaderTest method testLoadByType_withUnkownNsURI.
@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
}
}
use of org.eclipse.emf.mwe.core.WorkflowInterruptedException in project xtext-core by eclipse.
the class SlotEntry method findEClasses.
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;
}
use of org.eclipse.emf.mwe.core.WorkflowInterruptedException in project xtext-core by eclipse.
the class Validator method validate.
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);
}
}
Aggregations