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


Java Git.cloneRepository方法代码示例

本文整理汇总了Java中org.eclipse.jgit.api.Git.cloneRepository方法的典型用法代码示例。如果您正苦于以下问题:Java Git.cloneRepository方法的具体用法?Java Git.cloneRepository怎么用?Java Git.cloneRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jgit.api.Git的用法示例。


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

示例1: load

import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
/**
 * 从指定的git仓库地址(目前仅支持http和https)和文件名获取资源,通过UsernameCredential支持鉴权
 * @return 资源的字符串
 * @throws Exception 资源不存在或网络不通
 */
@Override
public String load() throws Exception {
    //本地临时目录,用户存放clone的代码
    String tempDirPath = localPath + "/iaac.aliyun.tmp_" + new Date().getTime();
    File tempDir = new File(tempDirPath);
    tempDir.mkdirs();
    String result = null;
    try {
        CloneCommand clone = Git.cloneRepository();
        clone.setURI(url);
        clone.setBranch(this.branch);
        clone.setDirectory(tempDir);

        //设置鉴权
        if (this.credential != null) {
            UsernamePasswordCredentialsProvider usernamePasswordCredentialsProvider = new
                    UsernamePasswordCredentialsProvider(this.credential.getUsername(), this.credential.getPassword());
            //git仓库地址
            clone.setCredentialsProvider(usernamePasswordCredentialsProvider);
        }
        //执行clone
        Git git = clone.call();
        //从本地路径中获取指定的文件
        File file = new File(tempDir.getAbsolutePath() + "/" + this.fileName);
        //返回文件的字符串
        result = FileUtils.readFileToString(file, "utf-8");
    } catch (Exception e) {
        throw e;
    } finally {
        //清除本地的git临时目录
        FileUtils.deleteDirectory(tempDir);
    }
    return result;
}
 
开发者ID:peterchen82,项目名称:iaac4j.aliyun,代码行数:40,代码来源:GitLoader.java

示例2: cloneRepo

import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider,
                             final File sshPrivateKey, final File sshPublicKey, String remote, String tag) {
    StopWatch watch = new StopWatch();

    // clone the repo!
    boolean cloneAll = true;
    LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath()
                     + " cloneAllBranches: " + cloneAll);
    CloneCommand command = Git.cloneRepository();
    GitUtils.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey);
    command = command.setCredentialsProvider(credentialsProvider).
            setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote);

    try {
        Git git = command.call();
        if (tag != null) {
            git.checkout().setName(tag).call();
        }
    } catch (Throwable e) {
        LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e);
        throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage());
    } finally {
        LOG.debug("cloneRepo took " + watch.taken());
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:26,代码来源:JenkinsPipelineLibrary.java

示例3: cloneRepo

import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public boolean cloneRepo( String directory, String uri ) {
  CloneCommand cmd = Git.cloneRepository();
  cmd.setDirectory( new File( directory ) );
  cmd.setURI( uri );
  cmd.setCredentialsProvider( credentialsProvider );
  try {
    Git git = cmd.call();
    git.close();
    return true;
  } catch ( Exception e ) {
    if ( ( e instanceof TransportException )
        && ( ( e.getMessage().contains( "Authentication is required but no CredentialsProvider has been registered" )
          || e.getMessage().contains( "not authorized" ) ) ) ) {
      if ( promptUsernamePassword() ) {
        return cloneRepo( directory, uri );
      }
    } else {
      showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
    }
  }
  return false;
}
 
开发者ID:HiromuHota,项目名称:pdi-git-plugin,代码行数:23,代码来源:UIGit.java

示例4: cloneRepo

import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public Git cloneRepo(CloneRepoAttributes attributes) throws GitAPIException {
    CloneCommand command = Git.cloneRepository();
    String gitUri = attributes.getUri();

    UserDetails userDetails = attributes.getUserDetails();
    CredentialsProvider credentialsProvider = userDetails.createCredentialsProvider();
    GitUtils.configureCommand(command, credentialsProvider, userDetails.getSshPrivateKey(), userDetails.getSshPublicKey());

    command = command.setCredentialsProvider(credentialsProvider).
            setCloneAllBranches(attributes.isCloneAll()).
            setURI(gitUri).
            setDirectory(attributes.getDirectory()).setRemote(attributes.getRemote());

    return command.call();
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:16,代码来源:GitProvider.java

示例5: GitRepoCloner

import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public GitRepoCloner() {
    cloneCommand = Git.cloneRepository();
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:4,代码来源:GitRepoCloner.java


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