Search in sources :

Example 1 with PathInfo

use of com.facebook.buck.distributed.thrift.PathInfo in project buck by facebook.

the class DistBuildService method uploadBuckDotFiles.

public ListenableFuture<Void> uploadBuckDotFiles(final StampedeId id, final ProjectFilesystem filesystem, FileHashCache fileHashCache, ListeningExecutorService executorService) throws IOException {
    ListenableFuture<Pair<List<FileInfo>, List<PathInfo>>> filesFuture = executorService.submit(() -> {
        List<Path> buckDotFilesExceptConfig = Lists.newArrayList();
        for (Path path : filesystem.getDirectoryContents(filesystem.getRootPath())) {
            String fileName = path.getFileName().toString();
            if (!filesystem.isDirectory(path) && !filesystem.isSymLink(path) && fileName.startsWith(".") && fileName.contains("buck") && !fileName.startsWith(".buckconfig")) {
                buckDotFilesExceptConfig.add(path);
            }
        }
        List<FileInfo> fileEntriesToUpload = new LinkedList<>();
        List<PathInfo> pathEntriesToUpload = new LinkedList<>();
        for (Path path : buckDotFilesExceptConfig) {
            FileInfo fileInfoObject = new FileInfo();
            fileInfoObject.setContent(filesystem.readFileIfItExists(path).get().getBytes());
            fileInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
            fileEntriesToUpload.add(fileInfoObject);
            PathInfo pathInfoObject = new PathInfo();
            pathInfoObject.setPath(path.toString());
            pathInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
            pathEntriesToUpload.add(pathInfoObject);
        }
        return new Pair<>(fileEntriesToUpload, pathEntriesToUpload);
    });
    ListenableFuture<Void> setFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
        setBuckDotFiles(id, filesAndPaths.getSecond());
        return Futures.immediateFuture(null);
    }, executorService);
    ListenableFuture<Void> uploadFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
        uploadMissingFilesFromList(filesAndPaths.getFirst(), executorService);
        return Futures.immediateFuture(null);
    }, executorService);
    return Futures.transform(Futures.allAsList(ImmutableList.of(setFilesFuture, uploadFilesFuture)), new Function<List<Void>, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable List<Void> input) {
            return null;
        }
    });
}
Also used : Path(java.nio.file.Path) LinkedList(java.util.LinkedList) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) PathInfo(com.facebook.buck.distributed.thrift.PathInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Nullable(javax.annotation.Nullable) Pair(com.facebook.buck.model.Pair)

Aggregations

FileInfo (com.facebook.buck.distributed.thrift.FileInfo)1 PathInfo (com.facebook.buck.distributed.thrift.PathInfo)1 Pair (com.facebook.buck.model.Pair)1 ImmutableList (com.google.common.collect.ImmutableList)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1