use of java.nio.file.Path in project syncany by syncany.
the class DefaultRecursiveWatcher method unregisterStaleWatches.
private synchronized void unregisterStaleWatches() {
Set<Path> paths = new HashSet<Path>(watchPathKeyMap.keySet());
Set<Path> stalePaths = new HashSet<Path>();
for (Path path : paths) {
if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {
stalePaths.add(path);
}
}
if (stalePaths.size() > 0) {
logger.log(Level.INFO, "Cancelling stale path watches ...");
for (Path stalePath : stalePaths) {
unregisterWatch(stalePath);
}
}
}
use of java.nio.file.Path in project syncany by syncany.
the class LocalTransferManager method list.
@Override
public <T extends RemoteFile> Map<String, T> list(Class<T> remoteFileClass) throws StorageException {
connect();
Path folder = Paths.get(getRemoteFilePath(remoteFileClass));
Map<String, T> files = Maps.newHashMap();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(folder)) {
for (Path path : directoryStream) {
try {
T remoteFile = RemoteFile.createRemoteFile(path.getFileName().toString(), remoteFileClass);
files.put(path.getFileName().toString(), remoteFile);
} catch (StorageException e) {
logger.log(Level.INFO, "Cannot create instance of " + remoteFileClass.getSimpleName() + " for file " + path + "; maybe invalid file name pattern. Ignoring file.");
}
}
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to list directory", e);
}
return files;
}
use of java.nio.file.Path in project bazel by bazelbuild.
the class SimpleJavaLibraryBuilder method prepareSourceCompilation.
protected void prepareSourceCompilation(JavaLibraryBuildRequest build) throws IOException {
Path classDirectory = Paths.get(build.getClassDir());
if (Files.exists(classDirectory)) {
try {
// Necessary for local builds in order to discard previous outputs
cleanupDirectory(classDirectory);
} catch (IOException e) {
throw new IOException("Cannot clean output directory '" + classDirectory + "'", e);
}
}
Files.createDirectories(classDirectory);
setUpSourceJars(build);
// Create sourceGenDir if necessary.
if (build.getSourceGenDir() != null) {
Path sourceGenDir = Paths.get(build.getSourceGenDir());
if (Files.exists(sourceGenDir)) {
try {
cleanupDirectory(sourceGenDir);
} catch (IOException e) {
throw new IOException("Cannot clean output directory '" + sourceGenDir + "'", e);
}
}
Files.createDirectories(sourceGenDir);
}
}
use of java.nio.file.Path in project bazel by bazelbuild.
the class SimpleJavaLibraryBuilder method setUpSourceJars.
/**
* Extracts the all source jars from the build request into the temporary directory specified in
* the build request. Empties the temporary directory, if it exists.
*/
private void setUpSourceJars(JavaLibraryBuildRequest build) throws IOException {
String sourcesDir = build.getTempDir();
Path sourceDirFile = Paths.get(sourcesDir);
if (Files.exists(sourceDirFile)) {
cleanupDirectory(sourceDirFile);
}
if (build.getSourceJars().isEmpty()) {
return;
}
final ByteArrayOutputStream protobufMetadataBuffer = new ByteArrayOutputStream();
for (String sourceJar : build.getSourceJars()) {
for (Path root : getJarFileSystem(Paths.get(sourceJar)).getRootDirectories()) {
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
String fileName = path.getFileName().toString();
if (fileName.endsWith(".java")) {
build.getSourceFiles().add(path);
} else if (fileName.equals(PROTOBUF_META_NAME)) {
Files.copy(path, protobufMetadataBuffer);
}
return FileVisitResult.CONTINUE;
}
});
}
}
Path output = Paths.get(build.getClassDir(), PROTOBUF_META_NAME);
if (protobufMetadataBuffer.size() > 0) {
try (OutputStream outputStream = Files.newOutputStream(output)) {
protobufMetadataBuffer.writeTo(outputStream);
}
} else if (Files.exists(output)) {
// Delete stalled meta file.
Files.delete(output);
}
}
use of java.nio.file.Path in project helios by spotify.
the class LoggingTestWatcher method setupFileLogging.
/**
* Sets up a FileAppender under the path {@code $logDir/<timestamp>-<name>-<pid>.log}. If not set
* as a system property then {@code $logDir} falls back to {@code /tmp/helios-test/log}.
*/
private void setupFileLogging(final String name) {
final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
final LoggerContext context = rootLogger.getLoggerContext();
context.reset();
final String ts = new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS").format(new Date());
final String pid = ManagementFactory.getRuntimeMXBean().getName().split("@", 2)[0];
final PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setContext(context);
ple.setPattern("%d{HH:mm:ss.SSS} %-5level %logger{1} %F:%L - %msg%n");
ple.start();
final Path directory = Paths.get(System.getProperty("logDir", "/tmp/helios-test/log/"));
final String filename = String.format("%s-%s-%s.log", ts, name, pid);
final Path file = directory.resolve(filename);
final FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
fileAppender.setEncoder(ple);
fileAppender.setFile(file.toString());
fileAppender.setContext(context);
fileAppender.start();
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);
try {
Files.createDirectories(directory);
} catch (IOException e) {
throw Throwables.propagate(e);
}
configureLogger("org.eclipse.jetty", Level.ERROR);
configureLogger("org.apache.curator", Level.ERROR);
configureLogger("org.apache.zookeeper", Level.ERROR);
configureLogger("com.spotify.helios", Level.DEBUG);
}
Aggregations