Search in sources :

Example 11 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)

Example 12 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 13 with FileSelectInfo

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

the class VfsDateRangeFilterTest method testAccept_notFolder.

@Test
public void testAccept_notFolder() throws Exception {
    filter = new VfsDateRangeFilter(format, start);
    FileSelectInfo fsi = mock(FileSelectInfo.class);
    FileObject fo = mock(FileObject.class);
    when(fo.getType()).thenReturn(FileType.FILE);
    when(fsi.getFile()).thenReturn(fo);
    when(fsi.getDepth()).thenReturn(1);
    assertFalse(filter.includeFile(fsi));
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) Test(org.junit.Test)

Example 14 with FileSelectInfo

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

the class VfsDateRangeFilterTest method testAccept_invalidDateStringFolder.

@Test
public void testAccept_invalidDateStringFolder() throws Exception {
    filter = new VfsDateRangeFilter(format, start, end);
    filter = new VfsDateRangeFilter(format, null, end);
    FileSelectInfo fsi = mock(FileSelectInfo.class);
    FileObject fo = mock(FileObject.class);
    FileName fn = mock(FileName.class);
    when(fn.getBaseName()).thenReturn("not a date");
    when(fo.getType()).thenReturn(FileType.FOLDER);
    when(fo.getName()).thenReturn(fn);
    when(fsi.getFile()).thenReturn(fo);
    when(fsi.getDepth()).thenReturn(1);
    assertFalse("Invalid 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 15 with FileSelectInfo

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

the class VfsDateRangeFilterTest method testAccept_startDateNull_endDateSet.

@Test
public void testAccept_startDateNull_endDateSet() throws Exception {
    filter = new VfsDateRangeFilter(format, null, 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("20000101");
    assertTrue("Before end date was not 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)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