Search in sources :

Example 1 with FileSelectInfo

use of org.apache.commons.vfs2.FileSelectInfo in project pentaho-kettle by pentaho.

the class MessagesSourceCrawler method crawl.

public void crawl() throws Exception {
    for (final String sourceDirectory : sourceDirectories) {
        FileObject folder = KettleVFS.getFileObject(sourceDirectory);
        FileObject[] javaFiles = folder.findFiles(new FileSelector() {

            @Override
            public boolean traverseDescendents(FileSelectInfo info) throws Exception {
                return true;
            }

            @Override
            public boolean includeFile(FileSelectInfo info) throws Exception {
                return info.getFile().getName().getExtension().equals("java");
            }
        });
        for (FileObject javaFile : javaFiles) {
            /**
             * We don't want the Messages.java files, there is nothing in there for us.
             */
            boolean skip = false;
            for (String filename : filesToAvoid) {
                if (javaFile.getName().getBaseName().equals(filename)) {
                    skip = true;
                }
            }
            if (skip) {
                // don't process this file.
                continue;
            }
            // For each of these files we look for keys...
            // 
            lookForOccurrencesInFile(sourceDirectory, javaFile);
        }
    }
    // 
    for (SourceCrawlerXMLFolder xmlFolder : xmlFolders) {
        String[] xmlDirs = { xmlFolder.getFolder() };
        String[] xmlMasks = { xmlFolder.getWildcard() };
        String[] xmlReq = { "N" };
        // search sub-folders too
        boolean[] xmlSubdirs = { true };
        FileInputList xulFileInputList = FileInputList.createFileList(new Variables(), xmlDirs, xmlMasks, xmlReq, xmlSubdirs);
        for (FileObject fileObject : xulFileInputList.getFiles()) {
            try {
                Document doc = XMLHandler.loadXMLFile(fileObject);
                // 
                for (SourceCrawlerXMLElement xmlElement : xmlFolder.getElements()) {
                    addLabelOccurrences(xmlFolder.getDefaultSourceFolder(), fileObject, doc.getElementsByTagName(xmlElement.getSearchElement()), xmlFolder.getKeyPrefix(), xmlElement.getKeyTag(), xmlElement.getKeyAttribute(), xmlFolder.getDefaultPackage(), xmlFolder.getPackageExceptions());
                }
            } catch (KettleXMLException e) {
                log.logError("Unable to open XUL / XML document: " + fileObject);
            }
        }
    }
}
Also used : FileSelector(org.apache.commons.vfs2.FileSelector) Document(org.w3c.dom.Document) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) Variables(org.pentaho.di.core.variables.Variables) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 2 with FileSelectInfo

use of org.apache.commons.vfs2.FileSelectInfo in project spoofax by metaborg.

the class SpoofaxIgnoresSelector method traverseDescendents.

@Override
public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
    final int depth = fileInfo.getDepth();
    final FileObject resource = fileInfo.getFile();
    final FileName name = resource.getName();
    final String base = name.getBaseName();
    switch(depth) {
        case 1:
            switch(base) {
                case "bin":
                case "include":
                case "target":
                case ".cache":
                case ".settings":
                case ".mvn":
                    return false;
            }
            break;
        case 3:
            switch(base) {
                // Ignore editor/java/trans and src-gen/stratego-java/trans.
                case "trans":
                    {
                        final FileObject parent1 = resource.getParent();
                        if (parent1 != null) {
                            final String parent1base = parent1.getName().getBaseName();
                            if (parent1base.equals("java") || parent1base.equals("stratego-java")) {
                                final FileObject parent2 = parent1.getParent();
                                if (parent2 != null) {
                                    final String parent2base = parent2.getName().getBaseName();
                                    return !(parent2base.equals("editor") || parent2base.equals("src-gen"));
                                }
                            }
                        }
                        break;
                    }
            }
            break;
    }
    return true;
}
Also used : FileName(org.apache.commons.vfs2.FileName) FileObject(org.apache.commons.vfs2.FileObject)

Example 3 with FileSelectInfo

use of org.apache.commons.vfs2.FileSelectInfo in project pentaho-metaverse by pentaho.

the class VfsDateRangeFilter method includeFile.

@Override
public boolean includeFile(FileSelectInfo fileInfo) {
    try {
        boolean result = super.includeFile(fileInfo);
        if (fileInfo.getFile().getType() == FileType.FOLDER) {
            Date folderDate = format.parse(fileInfo.getFile().getName().getBaseName());
            // assume a match on start & end dates
            int startCompare = 0;
            int endCompare = 0;
            // it is a valid date, now, is it greater than or equal to the requested date?
            if (startingDate != null) {
                startCompare = folderDate.compareTo(startingDate);
            }
            if (endingDate != null) {
                endCompare = folderDate.compareTo(endingDate);
            }
            return startCompare >= 0 && endCompare <= 0 && result;
        } else {
            return false;
        }
    } catch (Exception e) {
        // [PDI-17775] Doing a full exception catch due to the extended class throwing a general exception
        return false;
    }
}
Also used : Date(java.util.Date) FileSystemException(org.apache.commons.vfs2.FileSystemException) ParseException(java.text.ParseException)

Example 4 with FileSelectInfo

use of org.apache.commons.vfs2.FileSelectInfo in project pentaho-metaverse by pentaho.

the class VfsDateRangeFilterTest method testAccept_startDateSet.

@Test
public void testAccept_startDateSet() throws Exception {
    filter = new VfsDateRangeFilter(format, start);
    FileSelectInfo fsi = mock(FileSelectInfo.class);
    FileObject fo = mock(FileObject.class);
    FileName fn = mock(FileName.class);
    when(fn.getBaseName()).thenReturn(end);
    when(fo.getType()).thenReturn(FileType.FOLDER);
    when(fo.getName()).thenReturn(fn);
    when(fsi.getFile()).thenReturn(fo);
    when(fsi.getDepth()).thenReturn(1);
    assertTrue(filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn(start);
    assertTrue("Start date is not inclusive", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn("20000101");
    assertFalse("Before start date was accepted", filter.includeFile(fsi));
}
Also used : FileName(org.apache.commons.vfs2.FileName) FileObject(org.apache.commons.vfs2.FileObject) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) Test(org.junit.Test)

Example 5 with FileSelectInfo

use of org.apache.commons.vfs2.FileSelectInfo in project pentaho-metaverse by pentaho.

the class VfsDateRangeFilterTest method testAccept_startDateSet_endDateSet.

@Test
public void testAccept_startDateSet_endDateSet() throws Exception {
    filter = new VfsDateRangeFilter(format, start, end);
    FileSelectInfo fsi = mock(FileSelectInfo.class);
    FileObject fo = mock(FileObject.class);
    FileName fn = mock(FileName.class);
    when(fn.getBaseName()).thenReturn(end);
    when(fo.getType()).thenReturn(FileType.FOLDER);
    when(fo.getName()).thenReturn(fn);
    when(fsi.getFile()).thenReturn(fo);
    when(fsi.getDepth()).thenReturn(1);
    assertTrue("End date is not inclusive", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn(start);
    assertTrue("Start date is not inclusive", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn(between);
    assertTrue("Between start and end date is not accepted", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn("20000101");
    assertFalse("Before start date was accepted", filter.includeFile(fsi));
    when(fn.getBaseName()).thenReturn("21000101");
    assertFalse("After end date was accepted", filter.includeFile(fsi));
}
Also used : FileName(org.apache.commons.vfs2.FileName) FileObject(org.apache.commons.vfs2.FileObject) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) Test(org.junit.Test)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)23 FileSelectInfo (org.apache.commons.vfs2.FileSelectInfo)22 IOException (java.io.IOException)12 AllFileSelector (org.apache.commons.vfs2.AllFileSelector)10 KettleException (org.pentaho.di.core.exception.KettleException)10 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)10 FileSelector (org.apache.commons.vfs2.FileSelector)7 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)7 FileName (org.apache.commons.vfs2.FileName)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 Test (org.junit.Test)5 File (java.io.File)2 InputStream (java.io.InputStream)2 CompressedFileFileObject (org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject)2 JobMeta (org.pentaho.di.job.JobMeta)2 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1