Search in sources :

Example 1 with VersionControlCommandFailedException

use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.

the class HgAutoSparseState method loadHgManifest.

private void loadHgManifest() throws VersionControlCommandFailedException, InterruptedException {
    if (!hgManifestLoaded) {
        // Cache manifest data
        try (InputStream is = new FileInputStream(hgCmdLine.extractRawManifest());
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, // doesn't care what the filesystem encoding is and just stores the raw bytes.
            System.getProperty("file.encoding", "UTF-8")))) {
            hgManifest = new HashMap<Path, ManifestInfo>();
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split("\0", 2);
                if (parts.length != 2) {
                    // not a valid raw manifest line, skip
                    continue;
                }
                Path path = Paths.get(parts[0]);
                String hash = "";
                String flag = "";
                try {
                    hash = parts[1].substring(0, 40);
                    flag = parts[1].substring(40);
                } catch (IndexOutOfBoundsException e) {
                    // not a valid raw manifest line, skip
                    continue;
                }
                if (flag.equals("d")) {
                    // deletion entry, remove existing manifest entry from the map
                    hgManifest.remove(path);
                    continue;
                }
                Path directory = path.getParent();
                hgDirectParents.add(directory);
                while (directory != null) {
                    hgKnownDirectories.add(directory);
                    directory = directory.getParent();
                }
                hgManifest.put(path, ManifestInfo.of(hash, flag));
            }
        } catch (IOException e) {
            throw new VersionControlCommandFailedException("Unable to load raw manifest into an inputstream");
        }
        hgManifestLoaded = true;
        LOG.debug("Loaded %d manifest entries", hgManifest.size());
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) VersionControlCommandFailedException(com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 2 with VersionControlCommandFailedException

use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.

the class HgAutoSparseState method addToSparseProfile.

@Override
public void addToSparseProfile(Path path) {
    Path relativePath = hgRoot.relativize(path);
    // check if the path or a parent of it has already been added to the sparse profile
    Path parent = relativePath;
    while (parent != null) {
        if (hgSparseSeen.contains(parent)) {
            return;
        }
        parent = parent.getParent();
    }
    // Obtain hg manifest and directories
    try {
        loadHgManifest();
    } catch (VersionControlCommandFailedException | InterruptedException e) {
        LOG.debug("Failed to load the hg manifest");
        return;
    }
    if (hgManifest.isEmpty()) {
        return;
    }
    // is ignored.
    if (!hgManifest.containsKey(relativePath) && !hgDirectParents.contains(relativePath)) {
        LOG.debug("Not adding unknown file or directory %s to sparse profile", relativePath);
        return;
    }
    // For files, add the direct parent directory instead, unless that's an ignored path
    if (ignoredPaths.contains(relativePath)) {
        // don't add the project directory directly
        return;
    }
    if (hgManifest.containsKey(relativePath)) {
        Path directory = relativePath.getParent();
        if (directory != null && !ignoredPaths.contains(directory)) {
            relativePath = directory;
        }
    }
    hgSparseSeen.add(relativePath);
}
Also used : Path(java.nio.file.Path) VersionControlCommandFailedException(com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException)

Example 3 with VersionControlCommandFailedException

use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.

the class HgAutoSparseState method existsInManifest.

@Override
public boolean existsInManifest(Path path) {
    try {
        loadHgManifest();
    } catch (VersionControlCommandFailedException | InterruptedException e) {
        LOG.debug("Failed to load the manifest");
        return false;
    }
    Path relativePath = hgRoot.relativize(path);
    if (hgKnownDirectories.contains(relativePath)) {
        return true;
    }
    ManifestInfo manifestInfo = getManifestInfoForFile(path);
    return manifestInfo != null ? true : false;
}
Also used : Path(java.nio.file.Path) VersionControlCommandFailedException(com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException)

Example 4 with VersionControlCommandFailedException

use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.

the class AutoSparseIntegrationTest method assumeHgSparseInstalled.

private static void assumeHgSparseInstalled() {
    // If hg sparse throws an exception, then skip tests.
    Throwable exception = null;
    try {
        Path exportFile = Files.createTempFile("buck_autosparse_rules", "");
        try (Writer writer = new BufferedWriter(new FileWriter(exportFile.toFile()))) {
            // deliberately mostly empty
            writer.write("[include]\n");
        }
        ((HgCmdLineInterface) repoCmdline).exportHgSparseRules(exportFile);
    } catch (VersionControlCommandFailedException | InterruptedException | IOException e) {
        exception = e;
    }
    Assume.assumeNoException(exception);
}
Also used : Path(java.nio.file.Path) VersionControlCommandFailedException(com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) HgCmdLineInterface(com.facebook.buck.util.versioncontrol.HgCmdLineInterface) BufferedWriter(java.io.BufferedWriter)

Aggregations

VersionControlCommandFailedException (com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException)4 Path (java.nio.file.Path)4 IOException (java.io.IOException)2 HgCmdLineInterface (com.facebook.buck.util.versioncontrol.HgCmdLineInterface)1 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Writer (java.io.Writer)1