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);
}
}
}
}
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;
}
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;
}
}
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));
}
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));
}
Aggregations