Example usage for org.eclipse.jgit.transport TransportGitSsh setSshSessionFactory

List of usage examples for org.eclipse.jgit.transport TransportGitSsh setSshSessionFactory

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport TransportGitSsh setSshSessionFactory.

Prototype

public void setSshSessionFactory(SshSessionFactory factory) 

Source Link

Document

Set SSH session factory instead of the default one for this instance of the transport.

Usage

From source file:org.eclipse.ptp.internal.rdt.sync.git.core.JGitRepo.java

License:Open Source License

/**
 * Creates a new transport object for executing commands at the given remote location.
 * //from   ww  w.  ja v  a  2 s. c o  m
 * @param remoteLocation
 *            the remote location
 *            
 * @return new transport instance - never null.
 * @throws TransportException
 *            on problem creating transport
 * @throws RuntimeException
 *            if the requested transport is not supported by JGit.
 */
private TransportGitSsh buildTransport(final RemoteLocation remoteLoc, IProgressMonitor monitor)
        throws TransportException {
    RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 10);
    RemoteConfig remoteConfig = buildRemoteConfig(git.getRepository().getConfig());
    final URIish uri = buildURI(remoteLoc.getDirectory());
    TransportGitSsh transport;
    try {
        subMon.subTask(Messages.JGitRepo_15);
        transport = (TransportGitSsh) Transport.open(git.getRepository(), uri);
    } catch (NotSupportedException e) {
        throw new RuntimeException(e);
    } finally {
        if (monitor != null) {
            monitor.done();
        }
    }

    // Set the transport to use our own means of executing remote commands.
    transport.setSshSessionFactory(new SshSessionFactory() {
        @Override
        public RemoteSession getSession(URIish uri, CredentialsProvider credentialsProvider, FS fs, int tms)
                throws TransportException {
            return new PTPSession(remoteLoc);
        }
    });

    transport.applyConfig(remoteConfig);
    return transport;
}