Search in sources :

Example 6 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class SpoofaxContext method init.

public void init() {
    this.base = this.resourceService().resolve(baseURI);
    this.project = projectService.get(base);
    if (this.project == null) {
        this.languageSpec = null;
        return;
    }
    try {
        this.languageSpec = languageSpecService.get(project);
    } catch (ConfigException e) {
        throw new MetaborgRuntimeException("Cannot convert project " + project + " into a language specification project", e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) ConfigException(org.metaborg.core.config.ConfigException)

Example 7 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class Builder method printMessages.

private boolean printMessages(Iterable<IMessage> messages, String phase, BuildInput input, boolean pardoned) {
    final IMessagePrinter printer = input.messagePrinter;
    if (printer != null) {
        for (IMessage message : messages) {
            printer.print(message, pardoned);
        }
    }
    final boolean failed = !pardoned && MessageUtils.containsSeverity(messages, MessageSeverity.ERROR);
    if (input.throwOnErrors && failed) {
        throw new MetaborgRuntimeException(phase + " produced errors");
    }
    return !failed;
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) IMessagePrinter(org.metaborg.core.messages.IMessagePrinter) IMessage(org.metaborg.core.messages.IMessage)

Example 8 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class LanguageIdentifierService method identifyToResource.

@Override
@Nullable
public IdentifiedResource identifyToResource(FileObject resource, Iterable<? extends ILanguageImpl> impls) {
    // Ignore directories.
    try {
        if (resource.getType() == FileType.FOLDER) {
            return null;
        }
    } catch (FileSystemException e) {
        logger.error("Cannot identify {}, cannot determine its file type", e, resource);
        return null;
    }
    // Try to identify using the dialect identifier first.
    try {
        final IdentifiedDialect dialect = dialectIdentifier.identify(resource);
        if (dialect != null) {
            return new IdentifiedResource(resource, dialect);
        }
    } catch (MetaborgException e) {
        logger.error("Cannot identify dialect of {}", e, resource);
        return null;
    } catch (MetaborgRuntimeException e) {
    // Ignore
    }
    // Identify using identification facet.
    final Set<ILanguage> identifiedLanguages = Sets.newLinkedHashSet();
    ILanguageImpl identifiedImpl = null;
    for (ILanguageImpl impl : impls) {
        if (identify(resource, impl)) {
            identifiedLanguages.add(impl.belongsTo());
            identifiedImpl = impl;
        }
    }
    if (identifiedLanguages.size() > 1) {
        throw new IllegalStateException("Resource " + resource + " identifies to multiple languages: " + Joiner.on(", ").join(identifiedLanguages));
    }
    if (identifiedImpl == null) {
        return null;
    }
    return new IdentifiedResource(resource, null, identifiedImpl);
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaborgException(org.metaborg.core.MetaborgException) IdentifiedDialect(org.metaborg.core.language.dialect.IdentifiedDialect) Nullable(javax.annotation.Nullable)

Example 9 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class ResourceService method resolve.

@Override
public FileObject resolve(FileObject parent, String path) {
    try {
        final String pathEncoded = URIEncode.encode(path);
        final URI uri = new URI(pathEncoded);
        if (uri.isAbsolute()) {
            return resolve(uri);
        }
    } catch (URISyntaxException e) {
    // Ignore
    }
    final File file = new File(path);
    if (file.isAbsolute()) {
        return resolve("file://" + path);
    }
    try {
        return parent.resolveFile(path);
    } catch (FileSystemException e) {
        throw new MetaborgRuntimeException(e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) FileSystemException(org.apache.commons.vfs2.FileSystemException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) LocalFile(org.apache.commons.vfs2.provider.local.LocalFile)

Example 10 with MetaborgRuntimeException

use of org.metaborg.core.MetaborgRuntimeException in project spoofax by metaborg.

the class AnalysisResultProcessor method getUpdates.

private BehaviorSubject<AnalysisChange<A>> getUpdates(I input, IContext context) {
    if (input.detached()) {
        throw new MetaborgRuntimeException("Cannot get updates for detached (no source) units");
    }
    final FileObject source = input.source();
    final FileName name = source.getName();
    // THREADING: it is possible that two different threads asking for a subject may do the parsing twice here, as
    // this is not an atomic operation. However, the chance is very low and it does not break anything (only
    // duplicates some work), so it is acceptable.
    BehaviorSubject<AnalysisChange<A>> updates = updatesPerResource.get(name);
    if (updates == null) {
        updates = BehaviorSubject.create();
        updatesPerResource.put(name, updates);
        try {
            logger.trace("Requesting parse result for {}", source);
            final P parseResult = parseResultRequester.request(input).toBlocking().single();
            if (!parseResult.valid()) {
                updates.onNext(AnalysisChange.<A>error(source, new AnalysisException(context, "Parsing failed")));
                return updates;
            }
            logger.trace("Analysing for {}", source);
            final IAnalyzeResult<A, AU> result;
            try (IClosableLock lock = context.write()) {
                result = analysisService.analyze(parseResult, context);
            }
            updates.onNext(AnalysisChange.<A>update(source, result.result()));
        // HACK: ignore analyze unit updates from result.updates(), may cause incrementality problems.
        } catch (AnalysisException e) {
            final String message = logger.format("Analysis for {} failed", name);
            logger.error(message, e);
            updates.onNext(AnalysisChange.<A>error(source, e));
        } catch (Exception e) {
            final String message = logger.format("Analysis for {} failed", name);
            logger.error(message, e);
            updates.onNext(AnalysisChange.<A>error(source, new AnalysisException(context, message, e)));
        }
    }
    return updates;
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) FileName(org.apache.commons.vfs2.FileName) MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) AnalysisException(org.metaborg.core.analysis.AnalysisException) AnalysisException(org.metaborg.core.analysis.AnalysisException) FileObject(org.apache.commons.vfs2.FileObject) IClosableLock(org.metaborg.util.concurrent.IClosableLock)

Aggregations

MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)26 FileObject (org.apache.commons.vfs2.FileObject)16 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)9 MetaborgException (org.metaborg.core.MetaborgException)7 Nullable (javax.annotation.Nullable)6 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 IContext (org.metaborg.core.context.IContext)4 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)4 IStrategoString (org.spoofax.interpreter.terms.IStrategoString)4 File (java.io.File)3 IOException (java.io.IOException)3 ContextException (org.metaborg.core.context.ContextException)3 ILanguage (org.metaborg.core.language.ILanguage)3 IdentifiedDialect (org.metaborg.core.language.dialect.IdentifiedDialect)3 IMessage (org.metaborg.core.messages.IMessage)3 IProject (org.metaborg.core.project.IProject)3 ISpoofaxParseUnit (org.metaborg.spoofax.core.unit.ISpoofaxParseUnit)3 FileName (org.apache.commons.vfs2.FileName)2 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)2