Search in sources :

Example 1 with IComponentCreationConfigRequest

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

the class LanguageComponentFactory method createConfigs.

@Override
public Collection<ComponentCreationConfig> createConfigs(Iterable<IComponentCreationConfigRequest> requests) throws MetaborgException {
    final List<ComponentCreationConfig> configs = Lists.newArrayList();
    for (IComponentCreationConfigRequest request : requests) {
        final ComponentCreationConfig config = createConfig(request);
        configs.add(config);
    }
    return configs;
}
Also used : IComponentCreationConfigRequest(org.metaborg.core.language.IComponentCreationConfigRequest) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig)

Example 2 with IComponentCreationConfigRequest

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

the class LanguageDiscoveryService method scanComponentsInDirectory.

@Override
public Set<ILanguageComponent> scanComponentsInDirectory(FileObject directory) throws MetaborgException {
    final Collection<IComponentCreationConfigRequest> requests = componentFactory.requestAllInDirectory(directory);
    final Collection<ComponentCreationConfig> configs = componentFactory.createConfigs(requests);
    final Set<ILanguageComponent> components = Sets.newHashSet();
    for (ComponentCreationConfig config : configs) {
        final ILanguageComponent component = languageService.add(config);
        components.add(component);
    }
    return components;
}
Also used : IComponentCreationConfigRequest(org.metaborg.core.language.IComponentCreationConfigRequest) ComponentCreationConfig(org.metaborg.core.language.ComponentCreationConfig) ILanguageComponent(org.metaborg.core.language.ILanguageComponent)

Example 3 with IComponentCreationConfigRequest

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

the class LanguageComponentFactory method requestAllInDirectory.

@Override
public Collection<IComponentCreationConfigRequest> requestAllInDirectory(FileObject directory) throws MetaborgException {
    final Set<IComponentCreationConfigRequest> requests = Sets.newHashSet();
    try {
        if (!directory.exists()) {
            throw new MetaborgException("Cannot scan directory " + directory + ", it does not exist");
        }
        if (!directory.isFolder()) {
            throw new MetaborgException("Cannot scan " + directory + ", it is not a directory");
        }
        final Iterable<FileObject> files = ResourceUtils.find(directory, new LanguageFileScanSelector());
        for (FileObject file : files) {
            final IComponentCreationConfigRequest request;
            if (file.isFolder()) {
                request = requestFromDirectory(file);
            } else {
                request = requestFromArchive(file);
            }
            requests.add(request);
        }
    } catch (FileSystemException e) {
        throw new MetaborgException("Cannot scan " + directory + ", unexpected I/O error", e);
    }
    return requests;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaborgException(org.metaborg.core.MetaborgException) IComponentCreationConfigRequest(org.metaborg.core.language.IComponentCreationConfigRequest) FileObject(org.apache.commons.vfs2.FileObject)

Example 4 with IComponentCreationConfigRequest

use of org.metaborg.core.language.IComponentCreationConfigRequest 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

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