Search in sources :

Example 1 with IMessagePrinter

use of org.metaborg.core.messages.IMessagePrinter 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 2 with IMessagePrinter

use of org.metaborg.core.messages.IMessagePrinter in project spoofax by metaborg.

the class Builder method build.

@Override
public IBuildOutput<P, A, AU, T> build(BuildInput input, IProgress progress, ICancel cancel) throws InterruptedException {
    cancel.throwIfCancelled();
    final Multimap<ILanguageImpl, IdentifiedResourceChange> changes = ArrayListMultimap.create();
    identifyResources(input.sourceChanges, input, changes, cancel);
    if (changes.size() == 0) {
        // When there are no source changes, keep the old state and skip building.
        final IBuildOutputInternal<P, A, AU, T> buildOutput = buildOutputProvider.get();
        buildOutput.setState(input.state);
        return buildOutput;
    }
    cancel.throwIfCancelled();
    logger.info("Building " + input.project.location());
    final BuildState newState = new BuildState();
    final IBuildOutputInternal<P, A, AU, T> buildOutput = buildOutputProvider.get();
    buildOutput.setState(newState);
    final Iterable<ILanguageImpl> buildOrder = input.buildOrder.buildOrder();
    progress.setWorkRemaining(Iterables.size(buildOrder));
    for (ILanguageImpl language : buildOrder) {
        cancel.throwIfCancelled();
        final LanguageBuildState languageState = input.state.get(resourceService, languageIdentifier, language);
        final Collection<IdentifiedResourceChange> sourceChanges = changes.get(language);
        if (sourceChanges.size() == 0) {
            // When there are no source changes for this language, keep the old state and don't build.
            newState.add(language, languageState);
            continue;
        }
        final Iterable<FileObject> includePaths = input.includePaths.get(language);
        final Iterable<IdentifiedResource> includeFiles = languagePathService.toFiles(includePaths, language);
        final LanguageBuildDiff diff = languageState.diff(changes.get(language), includeFiles);
        final boolean pardoned = input.pardonedLanguages.contains(language);
        final Collection<FileObject> newResources = updateLanguageResources(input, language, diff, buildOutput, pardoned, progress.subProgress(1), cancel);
        final Iterable<ResourceChange> newResourceChanges = ResourceUtils.toChanges(newResources, ResourceChangeKind.Create);
        identifyResources(newResourceChanges, input, changes, cancel);
        newState.add(language, diff.newState);
    }
    final IMessagePrinter printer = input.messagePrinter;
    if (printer != null) {
        printer.printSummary();
    }
    return buildOutput;
}
Also used : IdentifiedResourceChange(org.metaborg.core.resource.IdentifiedResourceChange) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) IMessagePrinter(org.metaborg.core.messages.IMessagePrinter) FileObject(org.apache.commons.vfs2.FileObject) IdentifiedResource(org.metaborg.core.language.IdentifiedResource) ResourceChange(org.metaborg.core.resource.ResourceChange) IdentifiedResourceChange(org.metaborg.core.resource.IdentifiedResourceChange)

Aggregations

IMessagePrinter (org.metaborg.core.messages.IMessagePrinter)2 FileObject (org.apache.commons.vfs2.FileObject)1 MetaborgRuntimeException (org.metaborg.core.MetaborgRuntimeException)1 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)1 IdentifiedResource (org.metaborg.core.language.IdentifiedResource)1 IMessage (org.metaborg.core.messages.IMessage)1 IdentifiedResourceChange (org.metaborg.core.resource.IdentifiedResourceChange)1 ResourceChange (org.metaborg.core.resource.ResourceChange)1