@@ -0,0 +1,3219 @@
+package org.metaborg.core.project;%0A%0Aimport java.util.Map;%0Aimport java.util.concurrent.ConcurrentMap;%0A%0Aimport org.apache.commons.vfs2.FileName;%0Aimport org.apache.commons.vfs2.FileObject;%0Aimport org.apache.commons.vfs2.FileSystemException;%0Aimport org.metaborg.core.config.ConfigRequest;%0Aimport org.metaborg.core.config.IProjectConfig;%0Aimport org.metaborg.core.config.IProjectConfigService;%0Aimport org.metaborg.core.messages.StreamMessagePrinter;%0Aimport org.metaborg.core.source.ISourceTextService;%0Aimport org.metaborg.util.log.ILogger;%0Aimport org.metaborg.util.log.LoggerUtils;%0A%0Aimport com.google.common.collect.Maps;%0Aimport com.google.inject.Inject;%0A%0Apublic class ConfigBasedProjectService implements IProjectService %7B%0A    private static final ILogger logger = LoggerUtils.logger(ConfigBasedProjectService.class);%0A%0A    private final ConcurrentMap%3CFileName, IProject%3E projects = Maps.newConcurrentMap();%0A%0A    private final ISourceTextService sourceTextService;%0A    private final IProjectConfigService projectConfigService;%0A    %0A    @Inject public ConfigBasedProjectService(ISourceTextService sourceTextService,%0A        IProjectConfigService projectConfigService) %7B%0A        this.sourceTextService = sourceTextService;%0A        this.projectConfigService = projectConfigService;%0A    %7D%0A %0A %0A    @Override public IProject get(FileObject resource) %7B%0A        IProject project = getProject(resource);%0A        if(project == null) %7B%0A            project = findProject(resource);%0A        %7D%0A        return project;%0A    %7D%0A%0A    private IProject getProject(FileObject resource) %7B%0A        for(Map.Entry%3CFileName,IProject%3E entry : projects.entrySet()) %7B%0A            if(resource.getName().isAncestor(entry.getKey())) %7B%0A                return entry.getValue();%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A %0A    private IProject findProject(FileObject resource) %7B%0A        try %7B%0A            FileObject dir = (resource.isFolder() ? resource : resource.getParent());%0A            while(dir != null) %7B%0A                FileName name = dir.getName();%0A                if(projectConfigService.available(dir)) %7B%0A                    final ConfigRequest%3CIProjectConfig%3E configRequest = projectConfigService.get(dir);%0A                    if(!configRequest.valid()) %7B%0A                        logger.error(%22Errors occurred when retrieving project configuration from project directory %7B%7D%22, dir);%0A                        configRequest.reportErrors(new StreamMessagePrinter(sourceTextService, false, false, logger));%0A                    %7D%0A%0A                    final IProject project = new Project(dir, configRequest.config());%0A                    IProject prevProject;%0A                    if((prevProject = projects.putIfAbsent(name, project)) != null) %7B%0A                        logger.warn(%22Project with location %7B%7D already exists%22, name);%0A                        return prevProject;%0A                    %7D%0A                    return project;%0A                %7D%0A                dir = dir.getParent();%0A            %7D%0A        %7D catch(FileSystemException e) %7B%0A            logger.error(%22Error while searching for project configuration.%22,e);%0A        %7D%0A        logger.warn(%22No project configuration file was found for %7B%7D.%22,resource);%0A        return null;%0A    %7D%0A%7D%0A

Add project service that searches for config file.