Search in sources :

Example 1 with HgCmdLineInterface

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

the class ProjectFilesystemDelegateFactory method newInstance.

/**
   * Must always create a new delegate for the specified {@code root}.
   */
public static ProjectFilesystemDelegate newInstance(Path root, String hgCmd, AutoSparseConfig autoSparseConfig) {
    Optional<EdenClient> client = tryToCreateEdenClient();
    if (client.isPresent()) {
        try {
            EdenMount mount = client.get().getMountFor(root);
            if (mount != null) {
                return new EdenProjectFilesystemDelegate(mount);
            }
        } catch (TException | EdenError e) {
            // If Eden is running but root is not a mount point, Eden getMountFor() should just return
            // null rather than throw an error.
            LOG.error(e, "Failed to find Eden client for %s.", root);
        }
    }
    if (autoSparseConfig.enabled()) {
        // We can't access BuckConfig because that class requires a
        // ProjectFileSystem, which we are in the process of building
        // Access the required info from the Config instead
        HgCmdLineInterface hgCmdLine = new HgCmdLineInterface(new PrintStreamProcessExecutorFactory(), root, hgCmd, ImmutableMap.of());
        AutoSparseState autoSparseState = AbstractAutoSparseFactory.getAutoSparseState(root, hgCmdLine, autoSparseConfig);
        if (autoSparseState != null) {
            LOG.debug("Autosparse enabled, using AutoSparseProjectFilesystemDelegate");
            return new AutoSparseProjectFilesystemDelegate(autoSparseState, root);
        }
    }
    // No Eden or Mercurial info available, use the default
    return new DefaultProjectFilesystemDelegate(root);
}
Also used : TException(com.facebook.thrift.TException) AutoSparseState(com.facebook.buck.util.autosparse.AutoSparseState) EdenClient(com.facebook.buck.eden.EdenClient) EdenMount(com.facebook.buck.eden.EdenMount) EdenError(com.facebook.eden.thrift.EdenError) PrintStreamProcessExecutorFactory(com.facebook.buck.util.PrintStreamProcessExecutorFactory) EdenProjectFilesystemDelegate(com.facebook.buck.eden.EdenProjectFilesystemDelegate) HgCmdLineInterface(com.facebook.buck.util.versioncontrol.HgCmdLineInterface) AutoSparseProjectFilesystemDelegate(com.facebook.buck.util.autosparse.AutoSparseProjectFilesystemDelegate)

Example 2 with HgCmdLineInterface

use of com.facebook.buck.util.versioncontrol.HgCmdLineInterface 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

HgCmdLineInterface (com.facebook.buck.util.versioncontrol.HgCmdLineInterface)2 EdenClient (com.facebook.buck.eden.EdenClient)1 EdenMount (com.facebook.buck.eden.EdenMount)1 EdenProjectFilesystemDelegate (com.facebook.buck.eden.EdenProjectFilesystemDelegate)1 PrintStreamProcessExecutorFactory (com.facebook.buck.util.PrintStreamProcessExecutorFactory)1 AutoSparseProjectFilesystemDelegate (com.facebook.buck.util.autosparse.AutoSparseProjectFilesystemDelegate)1 AutoSparseState (com.facebook.buck.util.autosparse.AutoSparseState)1 VersionControlCommandFailedException (com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException)1 EdenError (com.facebook.eden.thrift.EdenError)1 TException (com.facebook.thrift.TException)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 Path (java.nio.file.Path)1