Search in sources :

Example 1 with IProjectConfig

use of org.metaborg.core.config.IProjectConfig in project spoofax by metaborg.

the class DefaultDependencyService method checkDependencies.

@Override
public MissingDependencies checkDependencies(IProject project) {
    final IProjectConfig config = project.config();
    final Collection<LanguageIdentifier> compileDeps = config.compileDeps();
    final Collection<LanguageIdentifier> missingCompile = Lists.newLinkedList();
    for (LanguageIdentifier identifier : compileDeps) {
        if (languageService.getComponent(identifier) == null) {
            missingCompile.add(identifier);
        }
    }
    final Collection<LanguageIdentifier> sourceDeps = config.sourceDeps();
    final Collection<LanguageIdentifier> missingSource = Lists.newLinkedList();
    for (LanguageIdentifier identifier : sourceDeps) {
        if (languageService.getComponent(identifier) == null) {
            missingSource.add(identifier);
        }
    }
    return new MissingDependencies(missingCompile, missingSource);
}
Also used : LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) IProjectConfig(org.metaborg.core.config.IProjectConfig)

Example 2 with IProjectConfig

use of org.metaborg.core.config.IProjectConfig 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 3 with IProjectConfig

use of org.metaborg.core.config.IProjectConfig 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 4 with IProjectConfig

use of org.metaborg.core.config.IProjectConfig in project spoofax by metaborg.

the class SingleFileProjectService method get.

@Override
public IProject get(FileObject resource) {
    FileObject rootFolder = resource;
    try {
        // project location should be a directory (otherwise building gave errors), so take parent dir (if possible)
        if (resource.isFile()) {
            rootFolder = resource.getParent();
        }
    } catch (FileSystemException e) {
    // ignore
    }
    final IProjectConfig config = projectConfigService.defaultConfig(rootFolder);
    return new Project(rootFolder, config);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) IProjectConfig(org.metaborg.core.config.IProjectConfig)

Aggregations

IProjectConfig (org.metaborg.core.config.IProjectConfig)4 FileName (org.apache.commons.vfs2.FileName)2 FileObject (org.apache.commons.vfs2.FileObject)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 StreamMessagePrinter (org.metaborg.core.messages.StreamMessagePrinter)2 MetaborgException (org.metaborg.core.MetaborgException)1 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)1