当前位置: 首页>>代码示例>>Java>>正文


Java SshTransport类代码示例

本文整理汇总了Java中org.eclipse.jgit.transport.SshTransport的典型用法代码示例。如果您正苦于以下问题:Java SshTransport类的具体用法?Java SshTransport怎么用?Java SshTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SshTransport类属于org.eclipse.jgit.transport包,在下文中一共展示了SshTransport类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pushToRepository

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
/**
 * Push all changes and tags to given remote.
 *
 * @param git
 *     instance.
 * @param remote
 *     to be used.
 * @param passphrase
 *     to access private key.
 * @param privateKey
 *     file location.
 *
 * @return List of all results of given push.
 */
public Iterable<PushResult> pushToRepository(Git git, String remote, String passphrase, Path privateKey) {
    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            session.setUserInfo(new PassphraseUserInfo(passphrase));
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            if (privateKey != null) {
                JSch defaultJSch = super.createDefaultJSch(fs);
                defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
                return defaultJSch;
            } else {
                return super.createDefaultJSch(fs);
            }
        }
    };

    try {
        return git.push()
            .setRemote(remote)
            .setPushAll()
            .setPushTags()
            .setTransportConfigCallback(transport -> {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            })
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:48,代码来源:GitOperations.java

示例2: initSessionFactory

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
private void initSessionFactory() {
    JschConfigSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(Host host, Session session) {
            session.setConfig("StrictHostKeyChecking", "no");
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            JSch jSch = super.createDefaultJSch(fs);

            // apply customized private key
            if (privateKeyPath != null) {
                jSch.removeAllIdentity();
                jSch.addIdentity(privateKeyPath.toString());
            }

            return jSch;
        }
    };

    transportConfigCallback = transport -> {
        SshTransport sshTransport = (SshTransport) transport;
        sshTransport.setSshSessionFactory(sshSessionFactory);
    };
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:27,代码来源:GitSshClient.java

示例3: getTransportConfigCallback

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
public static TransportConfigCallback getTransportConfigCallback() {
    final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            //session.setPassword(password);
        }
    };
    return new TransportConfigCallback() {

        public void configure(Transport transport) {
            if (transport instanceof TransportHttp)
                return;
            SshTransport sshTransport = (SshTransport) transport;
            sshTransport.setSshSessionFactory(sshSessionFactory);
        }
    };
}
 
开发者ID:warriorframework,项目名称:warrior-jenkins-plugin,代码行数:18,代码来源:WarriorPluginBuilder.java

示例4: pullFromRepository

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
/**
 * Pull repository from current branch and remote branch with same name as current
 *
 * @param git
 *     instance.
 * @param remote
 *     to be used.
 * @param remoteBranch
 *     to use.
 * @param passphrase
 *     to access private key.
 * @param privateKey
 *     file location.
 */
public PullResult pullFromRepository(final Git git, final String remote, String remoteBranch, final String passphrase,
    final Path privateKey) {
    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            session.setUserInfo(new PassphraseUserInfo(passphrase));
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            if (privateKey != null) {
                JSch defaultJSch = super.createDefaultJSch(fs);
                defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
                return defaultJSch;
            } else {
                return super.createDefaultJSch(fs);
            }
        }
    };

    try {
        return git.pull()
            .setRemote(remote)
            .setRemoteBranchName(remoteBranch)
            .setTransportConfigCallback(transport -> {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            })
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:48,代码来源:GitOperations.java

示例5: cloneRepository

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
/**
 * Clones a private remote git repository. Caller is responsible of closing git repository.
 *
 * @param remoteUrl
 *     to connect.
 * @param localPath
 *     where to clone the repo.
 * @param passphrase
 *     to access private key.
 * @param privateKey
 *     file location. If null default (~.ssh/id_rsa) location is used.
 *
 * @return Git instance. Caller is responsible to close the connection.
 */
public Git cloneRepository(final String remoteUrl, final Path localPath, final String passphrase,
    final Path privateKey) {

    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host host, Session session) {
            session.setUserInfo(new PassphraseUserInfo(passphrase));
        }

        @Override
        protected JSch createDefaultJSch(FS fs) throws JSchException {
            if (privateKey != null) {
                JSch defaultJSch = super.createDefaultJSch(fs);
                defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
                return defaultJSch;
            } else {
                return super.createDefaultJSch(fs);
            }
        }
    };

    try {
        return Git.cloneRepository()
            .setURI(remoteUrl)
            .setTransportConfigCallback(transport -> {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            })
            .setDirectory(localPath.toFile())
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:49,代码来源:GitOperations.java

示例6: shouldSetSshSessionFactoryWhenSshTransportReceived

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
@Test
public void shouldSetSshSessionFactoryWhenSshTransportReceived() throws Exception {
  // given
  SshTransport sshTransport = mock(SshTransport.class);
  when(sshKeyProvider.getPrivateKey(anyString())).thenReturn(new byte[0]);
  doAnswer(
          invocation -> {
            TransportConfigCallback callback =
                (TransportConfigCallback) invocation.getArguments()[0];
            callback.configure(sshTransport);
            return null;
          })
      .when(transportCommand)
      .setTransportConfigCallback(any());

  // when
  jGitConnection.executeRemoteCommand("ssh://host.xz/repo.git", transportCommand, null, null);

  // then
  verify(sshTransport).setSshSessionFactory(any());
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:JGitConnectionTest.java

示例7: configureCommand

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
/**
 * Configures the transport of the command to deal with things like SSH
 */
public static <C extends GitCommand> void configureCommand(TransportCommand<C, ?> command, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey) {
    if (sshPrivateKey != null) {
        final CredentialsProvider provider = credentialsProvider;
        command.setTransportConfigCallback(new TransportConfigCallback() {
            @Override
            public void configure(Transport transport) {
                if (transport instanceof SshTransport) {
                    SshTransport sshTransport = (SshTransport) transport;
                    SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
                        @Override
                        protected void configure(OpenSshConfig.Host host, Session session) {
                            session.setConfig("StrictHostKeyChecking", "no");
                            UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
                            session.setUserInfo(userInfo);
                        }

                        @Override
                        protected JSch createDefaultJSch(FS fs) throws JSchException {
                            JSch jsch = super.createDefaultJSch(fs);
                            jsch.removeAllIdentity();
                            String absolutePath = sshPrivateKey.getAbsolutePath();
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Adding identity privateKey: " + sshPrivateKey + " publicKey: " + sshPublicKey);
                            }
                            if (sshPublicKey != null) {
                                jsch.addIdentity(absolutePath, sshPublicKey.getAbsolutePath(), null);
                            } else {
                                jsch.addIdentity(absolutePath);
                            }
                            return jsch;
                        }
                    };
                    sshTransport.setSshSessionFactory(sshSessionFactory);
                }
            }
        });
    }
}
 
开发者ID:fabric8io,项目名称:fabric8-devops,代码行数:42,代码来源:GitHelpers.java

示例8: configure

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
/**
 * Configures the transport to work with ssh-agent if an SSH transport is
 * being used. {@inheritDoc}
 */
@Override
public void configure(final Transport transport) {

    if (transport instanceof SshTransport) {
        final SshTransport sshTransport = (SshTransport) transport;
        final SshSessionFactory sshSessionFactory = new AgentJschConfigSessionFactory(authenticationInfo);
        sshTransport.setSshSessionFactory(sshSessionFactory);
    }
}
 
开发者ID:trajano,项目名称:wagon-git,代码行数:14,代码来源:JSchAgentCapableTransportConfigCallback.java

示例9: cloneRepository

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
public static File cloneRepository(String cloneUrl, String repoPw) throws GitAPIException, JSONException, IOException {
    config = ConfigParser.getConfig();
    File tmpDir = new File("temp_repo");
    String key = null;
    String keyPassPhrase = null;
    if (config.has("privateKey")) {
        key = config.getString("privateKey");
        keyPassPhrase = config.getString("privateKeyPassPhrase");
    }
    // git clone will fail if the directory already exists, even if empty
    if (tmpDir.exists()) {
        FileUtils.deleteDirectory(tmpDir);
    }
    String pw = null;
    if (repoPw != null) {
        pw = repoPw;
    }
    else if (config.has("gitClonePassword")) {
        pw = config.getString("gitClonePassword");
    }
    final String finalKeyPassPhrase = keyPassPhrase;
    final String finalKey = key;

    SshSessionFactory sessionFactory = new CustomJschConfigSessionFactory();

    // use a private key if provided
    if (finalKey != null) {
        SshSessionFactory.setInstance(sessionFactory);
    }

    // use a password if provided
    if (pw != null) {
        final String finalPw = pw;
        SshSessionFactory.setInstance(new JschConfigSessionFactory() {
            @Override
            protected void configure(OpenSshConfig.Host host, Session session) {
                session.setPassword(finalPw);
            }
        });
    }
    SshSessionFactory.setInstance(sessionFactory);
    Git.cloneRepository()
        .setURI(cloneUrl)
        .setDirectory(tmpDir)
        .setTransportConfigCallback(new TransportConfigCallback() {
            @Override
            public void configure(Transport transport) {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sessionFactory);
            }
        })
        .call();

    return tmpDir;
}
 
开发者ID:alianza-dev,项目名称:jenkins-test-job-generator,代码行数:56,代码来源:GitHelper.java

示例10: configure

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
public void configure(Transport tn) {
    Log.d(TAG, "Configuring " + tn);
    if (tn instanceof SshTransport) {
        ((SshTransport) tn).setSshSessionFactory(sshSessionFactory);
    }
}
 
开发者ID:m4rzEE1,项目名称:ninja_chic-,代码行数:7,代码来源:AgitTransportConfig.java

示例11: configure

import org.eclipse.jgit.transport.SshTransport; //导入依赖的package包/类
@Override
public void configure(Transport tn) {
    if (tn instanceof SshTransport) {
        ((SshTransport) tn).setSshSessionFactory(ssh);
    }
}
 
开发者ID:sheimi,项目名称:SGit,代码行数:7,代码来源:SgitTransportCallback.java


注:本文中的org.eclipse.jgit.transport.SshTransport类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。