Search in sources :

Example 1 with Path

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);
        }
    }
}
Also used : Path(java.nio.file.Path) HashSet(java.util.HashSet)

Example 2 with Path

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;
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) StorageException(org.syncany.plugins.transfer.StorageException)

Example 3 with Path

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);
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException)

Example 4 with Path

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);
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileVisitResult(java.nio.file.FileVisitResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 5 with Path

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);
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Path(java.nio.file.Path) FileAppender(ch.qos.logback.core.FileAppender) IOException(java.io.IOException) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Path (java.nio.file.Path)6024 Test (org.junit.Test)2190 IOException (java.io.IOException)1136 File (java.io.File)637 ArrayList (java.util.ArrayList)403 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 InputStream (java.io.InputStream)273 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 Test (org.testng.annotations.Test)226 HashMap (java.util.HashMap)210 Map (java.util.Map)195 OutputStream (java.io.OutputStream)191 ImmutableList (com.google.common.collect.ImmutableList)186 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 List (java.util.List)166 ImmutableMap (com.google.common.collect.ImmutableMap)165