Search in sources :

Example 1 with WorkflowInterruptedException

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;
    }
}
Also used : Issue(org.eclipse.xtext.validation.Issue) ClasspathUriResolutionException(org.eclipse.xtext.resource.ClasspathUriResolutionException) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 2 with WorkflowInterruptedException

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;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI)

Example 3 with WorkflowInterruptedException

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
    }
}
Also used : WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) WorkflowContext(org.eclipse.emf.mwe.core.WorkflowContext) IndexTestLanguageStandaloneSetup(org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup) Test(org.junit.Test)

Example 4 with WorkflowInterruptedException

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;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 5 with WorkflowInterruptedException

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);
    }
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Issue(org.eclipse.xtext.validation.Issue) WorkflowInterruptedException(org.eclipse.emf.mwe.core.WorkflowInterruptedException) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException)

Aggregations

WorkflowInterruptedException (org.eclipse.emf.mwe.core.WorkflowInterruptedException)6 Resource (org.eclipse.emf.ecore.resource.Resource)4 Issue (org.eclipse.xtext.validation.Issue)4 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 ClasspathUriResolutionException (org.eclipse.xtext.resource.ClasspathUriResolutionException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EPackage (org.eclipse.emf.ecore.EPackage)1 WorkflowContext (org.eclipse.emf.mwe.core.WorkflowContext)1 Variable (org.eclipse.xtend.expression.Variable)1 IndexTestLanguageStandaloneSetup (org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 Test (org.junit.Test)1