Search in sources :

Example 21 with FileSelectInfo

use of org.apache.commons.vfs2.FileSelectInfo 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)20 FileSelectInfo (org.apache.commons.vfs2.FileSelectInfo)19 IOException (java.io.IOException)10 AllFileSelector (org.apache.commons.vfs2.AllFileSelector)9 KettleException (org.pentaho.di.core.exception.KettleException)9 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)9 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)7 FileName (org.apache.commons.vfs2.FileName)5 FileSelector (org.apache.commons.vfs2.FileSelector)5 Test (org.junit.Test)5 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 JobMeta (org.pentaho.di.job.JobMeta)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1