Search in sources :

Example 1 with ILanguageDiscoveryRequest

use of org.metaborg.core.language.ILanguageDiscoveryRequest in project spoofax by metaborg.

the class LanguageDiscoveryService method request.

@Deprecated
@Override
public Iterable<ILanguageDiscoveryRequest> request(FileObject location) throws MetaborgException {
    final Collection<ILanguageDiscoveryRequest> requests = Lists.newLinkedList();
    final FileObject[] configFiles;
    try {
        configFiles = location.findFiles(new FileSelector() {

            @Override
            public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
                final String baseName = fileInfo.getFile().getName().getBaseName();
                return !baseName.equals("bin") && !baseName.equals("target");
            }

            @Override
            public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
                return fileInfo.getFile().getName().getBaseName().equals(MetaborgConstants.FILE_COMPONENT_CONFIG);
            }
        });
    } catch (FileSystemException e) {
        throw new MetaborgException("Searching for language components failed unexpectedly", e);
    }
    if (configFiles == null || configFiles.length == 0) {
        return requests;
    }
    for (FileObject configFile : configFiles) {
        try {
            final FileObject directory = configFile.getParent().getParent();
            final IComponentCreationConfigRequest request = componentFactory.requestFromDirectory(directory);
            requests.add(request);
        } catch (FileSystemException e) {
            logger.error("Could not resolve parent directory of config file {}, skipping", e, configFile);
            continue;
        }
    }
    return requests;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileSelector(org.apache.commons.vfs2.FileSelector) MetaborgException(org.metaborg.core.MetaborgException) ILanguageDiscoveryRequest(org.metaborg.core.language.ILanguageDiscoveryRequest) IComponentCreationConfigRequest(org.metaborg.core.language.IComponentCreationConfigRequest) FileObject(org.apache.commons.vfs2.FileObject) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)1 FileSelectInfo (org.apache.commons.vfs2.FileSelectInfo)1 FileSelector (org.apache.commons.vfs2.FileSelector)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 MetaborgException (org.metaborg.core.MetaborgException)1 IComponentCreationConfigRequest (org.metaborg.core.language.IComponentCreationConfigRequest)1 ILanguageDiscoveryRequest (org.metaborg.core.language.ILanguageDiscoveryRequest)1