Search in sources :

Example 1 with StreamMessagePrinter

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

the class ConfigBasedProjectService method findProject.

private IProject findProject(FileObject resource) {
    try {
        FileObject dir = (resource.isFolder() ? resource : resource.getParent());
        while (dir != null) {
            FileName name = dir.getName();
            if (projectConfigService.available(dir)) {
                final ConfigRequest<? extends IProjectConfig> configRequest = projectConfigService.get(dir);
                if (!configRequest.valid()) {
                    logger.error("Errors occurred when retrieving project configuration from project directory {}", dir);
                    configRequest.reportErrors(new StreamMessagePrinter(sourceTextService, false, false, logger));
                }
                final IProjectConfig config = configRequest.config();
                if (config == null) {
                    logger.error("Could not retrieve project configuration from project directory {}", dir);
                    return null;
                }
                final IProject project = new Project(dir, config);
                IProject prevProject;
                if ((prevProject = projects.putIfAbsent(name, project)) != null) {
                    logger.warn("Project with location {} already exists", name);
                    return prevProject;
                }
                return project;
            }
            dir = dir.getParent();
        }
    } catch (FileSystemException e) {
        logger.error("Error while searching for project configuration.", e);
    }
    logger.warn("No project configuration file was found for {}.", resource);
    return null;
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileName(org.apache.commons.vfs2.FileName) FileObject(org.apache.commons.vfs2.FileObject) IProjectConfig(org.metaborg.core.config.IProjectConfig)

Example 2 with StreamMessagePrinter

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

the class SimpleProjectService method create.

@Override
public IProject create(FileObject location) throws MetaborgException {
    final FileName name = location.getName();
    for (FileName projectName : projects.keySet()) {
        if (name.equals(projectName) || name.isAncestor(projectName)) {
            final String message = String.format("Location %s is equal to or nested in project %s", name, projectName);
            throw new MetaborgException(message);
        }
    }
    final ConfigRequest<? extends IProjectConfig> configRequest = projectConfigService.get(location);
    if (!configRequest.valid()) {
        logger.error("Errors occurred when retrieving project configuration from project directory {}", location);
        configRequest.reportErrors(new StreamMessagePrinter(sourceTextService, false, false, logger));
    }
    final IProjectConfig config;
    if (configRequest.config() != null) {
        config = configRequest.config();
    } else {
        logger.debug("Using default configuration for project at {}", location);
        config = projectConfigService.defaultConfig(location);
    }
    final IProject project = new Project(location, config);
    if (projects.putIfAbsent(name, project) != null) {
        final String message = String.format("Project with location %s already exists", name);
        throw new MetaborgException(message);
    }
    return project;
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) FileName(org.apache.commons.vfs2.FileName) MetaborgException(org.metaborg.core.MetaborgException) IProjectConfig(org.metaborg.core.config.IProjectConfig)

Example 3 with StreamMessagePrinter

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

the class SpoofaxLanguageSpecService method get.

@Override
@Nullable
public ISpoofaxLanguageSpec get(IProject project) throws ConfigException {
    if (project instanceof ISpoofaxLanguageSpec) {
        return (ISpoofaxLanguageSpec) project;
    }
    final FileObject location = project.location();
    if (!configService.available(location)) {
        return null;
    }
    final ConfigRequest<ISpoofaxLanguageSpecConfig> configRequest = configService.get(location);
    if (!configRequest.valid()) {
        logger.error("Errors occurred when retrieving language specification configuration from project {}", project);
        configRequest.reportErrors(new StreamMessagePrinter(sourceTextService, false, false, logger));
        throw new ConfigException("Configuration for language specification at " + project + " is invalid");
    }
    final ISpoofaxLanguageSpecConfig config = configRequest.config();
    if (config == null) {
        // Configuration should never be null if it is available, but sanity check anyway.
        return null;
    }
    return new SpoofaxLanguageSpecWrapper(config, project);
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) ISpoofaxLanguageSpecConfig(org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig) ConfigException(org.metaborg.core.config.ConfigException) FileObject(org.apache.commons.vfs2.FileObject) Nullable(javax.annotation.Nullable)

Example 4 with StreamMessagePrinter

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

the class LanguageSpecBuilder method compile.

public void compile(LanguageSpecBuildInput input) throws MetaborgException {
    logger.debug("Running pre-Java build for {}", input.languageSpec().location());
    initPluto();
    try {
        final String path = path(input);
        plutoBuild(GenerateSourcesBuilder.request(generateSourcesBuilderInput(input)), path);
    } catch (RequiredBuilderFailed e) {
        if (e.getMessage().contains("no rebuild of failing builder")) {
            throw new MetaborgException(failingRebuildMessage, e);
        } else {
            throw new MetaborgException();
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Throwable e) {
        throw new MetaborgException(e);
    }
    final SpoofaxCommonPaths paths = new SpoofaxLangSpecCommonPaths(input.languageSpec().location());
    // HACK: compile the main ESV file to make sure that packed.esv file is always available.
    final Iterable<FileObject> esvRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_ESV_NAME);
    final FileObject mainEsvFile = paths.findEsvMainFile(esvRoots);
    try {
        if (mainEsvFile != null && mainEsvFile.exists()) {
            logger.info("Compiling Main ESV file {}", mainEsvFile);
            // @formatter:off
            final BuildInput buildInput = new BuildInputBuilder(input.languageSpec()).addSource(mainEsvFile).addTransformGoal(new CompileGoal()).withMessagePrinter(new StreamMessagePrinter(sourceTextService, false, true, logger)).build(dependencyService, languagePathService);
            // @formatter:on
            final ISpoofaxBuildOutput result = runner.build(buildInput, null, null).schedule().block().result();
            if (!result.success()) {
                throw new MetaborgException("Compiling Main ESV file failed");
            }
        }
    } catch (FileSystemException e) {
        final String message = logger.format("Could not compile ESV file {}", mainEsvFile);
        throw new MetaborgException(message, e);
    } catch (InterruptedException e) {
    // Ignore
    }
    // HACK: compile the main DS file if available, after generating sources (because ds can depend on Stratego
    // strategies), to generate an interpreter.
    final Iterable<FileObject> dsRoots = languagePathService.sourcePaths(input.project(), SpoofaxConstants.LANG_DYNSEM_NAME);
    final FileObject mainDsFile = paths.findDsMainFile(dsRoots, input.languageSpec().config().strategoName());
    try {
        if (mainDsFile != null && mainDsFile.exists()) {
            if (languageIdentifierService.identify(mainDsFile, input.project()) == null) {
                logger.error("Could not identify DynSem main file {}, please add DynSem as a compile dependency", mainDsFile);
            }
            logger.info("Compiling main DynSem file {}", mainDsFile);
            // @formatter:off
            final BuildInput buildInput = new BuildInputBuilder(input.languageSpec()).addSource(mainDsFile).addTransformGoal(new EndNamedGoal("Generate interpreter")).withMessagePrinter(new StreamMessagePrinter(sourceTextService, false, true, logger)).build(dependencyService, languagePathService);
            // @formatter:on
            final ISpoofaxBuildOutput result = runner.build(buildInput, null, null).schedule().block().result();
            if (!result.success()) {
                logger.error("Compiling main DynSem file {} failed", mainDsFile);
            }
        }
    } catch (FileSystemException e) {
        final String message = logger.format("Could not compile DynSem file {}", mainDsFile);
        throw new MetaborgException(message, e);
    } catch (InterruptedException e) {
    // Ignore
    }
    for (IBuildStep buildStep : buildSteps) {
        buildStep.execute(LanguageSpecBuildPhase.compile, input);
    }
}
Also used : StreamMessagePrinter(org.metaborg.core.messages.StreamMessagePrinter) CompileGoal(org.metaborg.core.action.CompileGoal) ISpoofaxBuildOutput(org.metaborg.spoofax.core.build.ISpoofaxBuildOutput) MetaborgException(org.metaborg.core.MetaborgException) BuildInputBuilder(org.metaborg.core.build.BuildInputBuilder) FileSystemException(org.apache.commons.vfs2.FileSystemException) BuildInput(org.metaborg.core.build.BuildInput) EndNamedGoal(org.metaborg.core.action.EndNamedGoal) RequiredBuilderFailed(build.pluto.builder.RequiredBuilderFailed) FileObject(org.apache.commons.vfs2.FileObject) SpoofaxCommonPaths(org.metaborg.spoofax.core.build.SpoofaxCommonPaths)

Aggregations

StreamMessagePrinter (org.metaborg.core.messages.StreamMessagePrinter)4 FileObject (org.apache.commons.vfs2.FileObject)3 FileName (org.apache.commons.vfs2.FileName)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 MetaborgException (org.metaborg.core.MetaborgException)2 IProjectConfig (org.metaborg.core.config.IProjectConfig)2 RequiredBuilderFailed (build.pluto.builder.RequiredBuilderFailed)1 Nullable (javax.annotation.Nullable)1 CompileGoal (org.metaborg.core.action.CompileGoal)1 EndNamedGoal (org.metaborg.core.action.EndNamedGoal)1 BuildInput (org.metaborg.core.build.BuildInput)1 BuildInputBuilder (org.metaborg.core.build.BuildInputBuilder)1 ConfigException (org.metaborg.core.config.ConfigException)1 ISpoofaxBuildOutput (org.metaborg.spoofax.core.build.ISpoofaxBuildOutput)1 SpoofaxCommonPaths (org.metaborg.spoofax.core.build.SpoofaxCommonPaths)1 ISpoofaxLanguageSpecConfig (org.metaborg.spoofax.meta.core.config.ISpoofaxLanguageSpecConfig)1