use of java.io.FilenameFilter in project graphdb by neo4j-attic.
the class ProvisionerTest method shouldProvisionMavenArtifact.
@Test
public void shouldProvisionMavenArtifact() throws MalformedURLException {
final String EXPECTED_DIRECTORY = "prove_dir";
Provisioner prover = new Provisioner();
prover.setProvisionDirectory(EXPECTED_DIRECTORY);
prover.include("mvn:org.neo4j/neo4j-kernel/1.1", "neo4j-kernel.jar");
prover.provision();
File actualDirectory = new File(EXPECTED_DIRECTORY);
String[] foundJars = actualDirectory.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith("jar");
}
});
assertThat(foundJars.length, is(equalTo(1)));
FileUtils.delete(actualDirectory);
}
use of java.io.FilenameFilter in project intellij-leiningen-plugin by derkork.
the class LeiningenRunnerSettings method getRealLeiningenJar.
/**
* Returns the real leiningen jar.
* @return the real leiningen jar
*/
@NotNull
public String getRealLeiningenJar() {
if (overrideLeiningenJar) {
return leiningenJar;
}
// first check LEIN_JAR env variable
String env = System.getenv("LEIN_JAR");
if (!StringUtil.isEmpty(env)) {
return env;
}
// ok it's not set, look for a file below the lein home
File leinHome = new File(getRealLeiningenHome());
if (leinHome.exists() && leinHome.isDirectory()) {
File selfInstalls = new File(leinHome, "self-installs");
if (selfInstalls.exists() && selfInstalls.isDirectory()) {
File[] files = selfInstalls.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("leiningen-") && name.endsWith("-standalone.jar");
}
});
if (files.length > 0) {
return files[0].getPath();
}
}
}
// fallback
return "leiningen-standalone.jar";
}
use of java.io.FilenameFilter in project druid by druid-io.
the class AppenderatorImpl method bootstrapSinksFromDisk.
/**
* Populate "sinks" and "sinkTimeline" with committed segments, and announce them with the segmentAnnouncer.
*
* @return persisted commit metadata
*/
private Object bootstrapSinksFromDisk() {
Preconditions.checkState(sinks.isEmpty(), "Already bootstrapped?!");
final File baseDir = tuningConfig.getBasePersistDirectory();
if (!baseDir.exists()) {
return null;
}
final File[] files = baseDir.listFiles();
if (files == null) {
return null;
}
final File commitFile = computeCommitFile();
final Committed committed;
try {
if (commitFile.exists()) {
committed = objectMapper.readValue(commitFile, Committed.class);
} else {
committed = Committed.nil();
}
} catch (Exception e) {
throw new ISE(e, "Failed to read commitFile: %s", commitFile);
}
log.info("Loading sinks from[%s]: %s", baseDir, committed.getHydrants().keySet());
for (File sinkDir : files) {
final File identifierFile = new File(sinkDir, IDENTIFIER_FILE_NAME);
if (!identifierFile.isFile()) {
// No identifier in this sinkDir; it must not actually be a sink directory. Skip it.
continue;
}
try {
final SegmentIdentifier identifier = objectMapper.readValue(new File(sinkDir, "identifier.json"), SegmentIdentifier.class);
final int committedHydrants = committed.getCommittedHydrants(identifier.getIdentifierAsString());
if (committedHydrants <= 0) {
log.info("Removing uncommitted sink at [%s]", sinkDir);
FileUtils.deleteDirectory(sinkDir);
continue;
}
// To avoid reading and listing of "merged" dir and other special files
final File[] sinkFiles = sinkDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String fileName) {
return !(Ints.tryParse(fileName) == null);
}
});
Arrays.sort(sinkFiles, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return Ints.compare(Integer.parseInt(o1.getName()), Integer.parseInt(o2.getName()));
}
});
List<FireHydrant> hydrants = Lists.newArrayList();
for (File hydrantDir : sinkFiles) {
final int hydrantNumber = Integer.parseInt(hydrantDir.getName());
if (hydrantNumber >= committedHydrants) {
log.info("Removing uncommitted segment at [%s]", hydrantDir);
FileUtils.deleteDirectory(hydrantDir);
} else {
log.info("Loading previously persisted segment at [%s]", hydrantDir);
if (hydrantNumber != hydrants.size()) {
throw new ISE("Missing hydrant [%,d] in sinkDir [%s].", hydrants.size(), sinkDir);
}
hydrants.add(new FireHydrant(new QueryableIndexSegment(identifier.getIdentifierAsString(), indexIO.loadIndex(hydrantDir)), hydrantNumber));
}
}
// Make sure we loaded enough hydrants.
if (committedHydrants != hydrants.size()) {
throw new ISE("Missing hydrant [%,d] in sinkDir [%s].", hydrants.size(), sinkDir);
}
Sink currSink = new Sink(identifier.getInterval(), schema, identifier.getShardSpec(), identifier.getVersion(), tuningConfig.getMaxRowsInMemory(), tuningConfig.isReportParseExceptions(), hydrants);
sinks.put(identifier, currSink);
sinkTimeline.add(currSink.getInterval(), currSink.getVersion(), identifier.getShardSpec().createChunk(currSink));
segmentAnnouncer.announceSegment(currSink.getSegment());
} catch (IOException e) {
log.makeAlert(e, "Problem loading sink[%s] from disk.", schema.getDataSource()).addData("sinkDir", sinkDir).emit();
}
}
// Make sure we loaded all committed sinks.
final Set<String> loadedSinks = Sets.newHashSet(Iterables.transform(sinks.keySet(), new Function<SegmentIdentifier, String>() {
@Override
public String apply(SegmentIdentifier input) {
return input.getIdentifierAsString();
}
}));
final Set<String> missingSinks = Sets.difference(committed.getHydrants().keySet(), loadedSinks);
if (!missingSinks.isEmpty()) {
throw new ISE("Missing committed sinks [%s]", Joiner.on(", ").join(missingSinks));
}
return committed.getMetadata();
}
use of java.io.FilenameFilter in project che by eclipse.
the class InstallExtension method main.
public static void main(String[] args) throws IOException {
for (String arg : args) {
if (arg.startsWith(EXT_DIR_PARAMETER)) {
extDirPath = Paths.get(arg.substring(EXT_DIR_PARAMETER.length()));
} else if (arg.startsWith(EXT_RESOURCES_DIR_PARAMETER)) {
final Path extResourcesDirPath = Paths.get(arg.substring(EXT_RESOURCES_DIR_PARAMETER.length()));
final String tempDirName = "temp";
extResourcesWorkDirPath = extResourcesDirPath.resolve(tempDirName);
// delete working directory from previous build if it exist
IoUtil.deleteRecursive(extResourcesWorkDirPath.toFile());
Files.createDirectory(extResourcesWorkDirPath);
IoUtil.copy(extResourcesDirPath.toFile(), extResourcesWorkDirPath.toFile(), new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !(tempDirName.equals(name));
}
});
} else {
System.err.println("Unknown flag: " + arg);
System.exit(1);
}
}
List<Extension> extensions = findExtensionsByPath(extDirPath);
for (Extension extension : extensions) {
final File pom = extResourcesWorkDirPath.resolve("pom.xml").toFile();
final Model model = Model.readFrom(pom);
model.dependencies().add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion));
model.writeTo(pom);
// Add GWT module if there is one
if (extension.gwtModuleName != null) {
final Path ideGwtXmlPath = IoUtil.findFile(IDE_GWT_XML_FILE_NAME, extResourcesWorkDirPath.toFile()).toPath();
GwtXmlUtils.inheritGwtModule(ideGwtXmlPath, extension.gwtModuleName);
}
}
}
use of java.io.FilenameFilter in project neo4j by neo4j.
the class StoreFilesTest method deleteMustNotDeleteFilesInIgnoredDirectories.
@Test
public void deleteMustNotDeleteFilesInIgnoredDirectories() throws Exception {
File dir = getBaseDir();
File ignore = new File(dir, "ignore");
File a = new File(dir, "a");
File b = new File(dir, "b");
File c = new File(ignore, "c");
File d = new File(ignore, "d");
createOnFileSystem(a);
createOnFileSystem(c);
createOnPageCache(b);
createOnPageCache(d);
FilenameFilter filter = (directory, name) -> !name.startsWith("ignore");
storeFiles = new StoreFiles(fs, pageCache, filter);
storeFiles.delete(dir);
assertFalse(fs.fileExists(a));
assertFalse(pc.fileExists(b));
assertTrue(fs.fileExists(c));
assertTrue(pc.fileExists(d));
}
Aggregations