當前位置: 首頁>>代碼示例>>Java>>正文


Java CloneCommand.call方法代碼示例

本文整理匯總了Java中org.eclipse.jgit.api.CloneCommand.call方法的典型用法代碼示例。如果您正苦於以下問題:Java CloneCommand.call方法的具體用法?Java CloneCommand.call怎麽用?Java CloneCommand.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jgit.api.CloneCommand的用法示例。


在下文中一共展示了CloneCommand.call方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: load

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的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: execute

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private void execute() throws InvalidRemoteException, TransportException, GitAPIException, IOException {
    setProxy();
    
    CloneCommand cmd = Git.cloneRepository()
                          .setURI(config.getRemoteUrl());
    
    if (config.getLocalPath() != "") {
        cmd.setDirectory(new File(config.getLocalPath()));
    }
    
    Git git = cmd.call();
    
    // Set proxy setting to repository config.
    StoredConfig gitConfig = git.getRepository().getConfig();
    gitConfig.setString("remote", "origin", "proxy", config.getProxyAddress());
    gitConfig.save();
    
    git.getRepository().close();
}
 
開發者ID:rabitarochan,項目名稱:jgit-proxy-clone,代碼行數:20,代碼來源:Main.java

示例3: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的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

示例4: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的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

示例5: assertGitCloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
 * Asserts that we can git clone the given repository
 */
public static Git assertGitCloneRepo(String cloneUrl, File outputFolder) throws GitAPIException, IOException {
    LOG.info("Cloning git repo: " + cloneUrl + " to folder: " + outputFolder);

    Files.recursiveDelete(outputFolder);
    outputFolder.mkdirs();

    CloneCommand command = Git.cloneRepository();
    command = command.setCloneAllBranches(false).setURI(cloneUrl).setDirectory(outputFolder).setRemote("origin");

    Git git;
    try {
        git = command.call();
    } catch (Exception e) {
        LOG.error("Failed to git clone remote repo " + cloneUrl + " due: " + e.getMessage(), e);
        throw e;
    }
    return git;
}
 
開發者ID:fabric8io,項目名稱:fabric8-forge,代碼行數:22,代碼來源:ForgeClientAsserts.java

示例6: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的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.info("cloneRepo took " + watch.taken());
    }
}
 
開發者ID:fabric8io,項目名稱:fabric8-forge,代碼行數:24,代碼來源:ProjectFileSystem.java

示例7: fetchMaterial

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public String fetchMaterial(FetchMaterialTask task) {
    String errorMessage = null;
    String materialPath = Paths.get(AgentConfiguration.getInstallInfo().getAgentPipelinesDir(), task.getPipelineName(), task.getDestination()).toString();
    GitMaterial definition = (GitMaterial) task.getMaterialDefinition();
    CloneCommand clone = Git.cloneRepository();
    clone.setURI(definition.getRepositoryUrl());
    clone.setBranch(definition.getBranch());
    clone.setDirectory(new File(materialPath));
    clone.setCloneSubmodules(true);
    UsernamePasswordCredentialsProvider credentials = this.handleCredentials(definition);
    clone.setCredentialsProvider(credentials);
    try {
        Git git = clone.call();
        git.close();
    } catch (GitAPIException e) {
        errorMessage = e.getMessage();
    }

    return errorMessage;
}
 
開發者ID:rndsolutions,項目名稱:hawkcd,代碼行數:22,代碼來源:GitMaterialService.java

示例8: clone

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
 * Clones repository, which is defined by provided repository URI.
 *
 * @param repositoryName into which repository
 * @param cloneUrl url of cloned repository
 * @param username for get access to clone
 * @param password for get access to clone
 */
public void clone(String repositoryName, String cloneUrl, String username, String password)
{
    RepositoryContext repositoryContext = repositoryByName.get(repositoryName);

    try
    {
        CloneCommand cloneCommand = Git.cloneRepository();
        cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
        cloneCommand.setURI(cloneUrl);
        cloneCommand.setDirectory(repositoryContext.repository.getDirectory().getParentFile());
        cloneCommand.call();

    }
    catch (GitAPIException e)
    {
        throw new RuntimeException(e);
    }
}
 
開發者ID:edgehosting,項目名稱:jira-dvcs-connector,代碼行數:27,代碼來源:GitTestSupport.java

示例9: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey, String remote) {
    // clone the repo!
    boolean cloneAll = false;
    LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath());
    CloneCommand command = Git.cloneRepository();
    GitHelpers.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey);
    command = command.setCredentialsProvider(credentialsProvider).
            setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote);

    try {
        command.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());
    }
}
 
開發者ID:fabric8io,項目名稱:fabric8-devops,代碼行數:17,代碼來源:GitBuildConfigProcessor.java

示例10: obtainRepository

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
 * Clones the repository into the desired folder and returns
 * the JGit Repository object.
 *
 * @throws GitAPIException if the `git clone` call fails.
 */
protected void obtainRepository(String remoteURL) throws GitAPIException, IOException,
        CancelledAuthorizationException {
    CloneCommand cloneCommand = Git.cloneRepository();
    cloneCommand.setURI(remoteURL);
    myWrapAuthentication(cloneCommand);
    File destination = this.localPath.toFile();
    cloneCommand.setDirectory(destination);
    Git cloneCall = cloneCommand.call();

    cloneCall.close();
    repo = cloneCall.getRepository();
    setup();
}
 
開發者ID:dmusican,項目名稱:Elegit,代碼行數:20,代碼來源:ClonedRepoHelper.java

示例11: createGitRepository

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
 * Creates a repository on GitHub and in a local temporary directory. This is a one time operation as
 * once it is created on GitHub and locally it cannot be recreated.
 */
public File createGitRepository(String repositoryName) throws IOException {
    RepositoryService service = new RepositoryService();
    service.getClient().setOAuth2Token(oAuthToken);
    Repository repository = new Repository();
    repository.setName(repositoryName);
    repository = service.createRepository(repository);
    repositoryLocation = repository.getHtmlUrl();

    CloneCommand cloneCommand = Git.cloneRepository()
            .setURI(repository.getCloneUrl())
            .setDirectory(localGitDirectory);
    addAuth(cloneCommand);
    try {
        localRepository = cloneCommand.call();
    } catch (GitAPIException e) {
        throw new IOException("Error cloning to local file system", e);
    }
    return localGitDirectory;
}
 
開發者ID:WASdev,項目名稱:tool.accelerate.core,代碼行數:24,代碼來源:GitHubConnector.java

示例12: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private static boolean cloneRepo(TargetCommit cloneCommit, String customCommit) {
    CloneCommand cloneCommand = new CloneCommand()
            .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
            .setDirectory(new File(ROOT_DIR))
            .setURI("https://github.com/SpongePowered/SpongeVanilla.git")
            .setBranchesToClone(Collections.singleton("refs/heads/master"))
            .setBranch("refs/heads/master")
            .setCloneSubmodules(true);
    try {
        Git git = cloneCommand.call();
        
        if (cloneCommit == TargetCommit.CUSTOM) {
            git.checkout().setName(customCommit).call();
            
            git.submoduleInit().call();
            git.submoduleUpdate().setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))).call();
        }
        
        return true;
    } catch (GitAPIException e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:modwizcode,項目名稱:VanillaBuild,代碼行數:25,代碼來源:VanillaBuildMain.java

示例13: doImport

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public void doImport(ProgressMonitor progress)
    throws GitCloneFailedException, GitDestinationAlreadyExistsException,
        GitDestinationNotWritableException {
  CloneCommand clone = new CloneCommand();
  clone.setCredentialsProvider(getRepository().getCredentialsProvider());
  String sourceUri = getSourceUri();
  clone.setURI(sourceUri);
  clone.setBare(true);
  clone.setDirectory(destinationDirectory);
  if (progress != null) {
    clone.setProgressMonitor(progress);
  }
  try {
    LOG.info(sourceUri + "| Clone into " + destinationDirectory);
    clone.call();
  } catch (Throwable e) {
    throw new GitCloneFailedException(sourceUri, e);
  }
}
 
開發者ID:GerritCodeReview,項目名稱:plugins_github,代碼行數:21,代碼來源:GitCloneStep.java

示例14: to

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public void to(Path path) throws Git.Err {
	LOG.info(() -> String.format("Cloning %s into %s...", url, path.toString()));
	CloneCommand cloner = org.eclipse.jgit.api.Git.cloneRepository()
			.setURI(url)
			.setCredentialsProvider(new GitCredentialsProvider(
					CredentialHandlers.handlerMap()
			))
			.setProgressMonitor(
					enableOutput
							? new TextProgressMonitor()
							: NullProgressMonitor.INSTANCE
			)
			.setDirectory(path.toFile());
	branchName.ifPresent(cloner::setBranch);
	try {
		cloner.call();
	} catch (GitAPIException e) {
		throw new Git.Err(url, path.toString(), e);
	}
}
 
開發者ID:nyrkovalex,項目名稱:get.me,代碼行數:22,代碼來源:GitCloneCommand.java

示例15: cloneTargetRepository

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private Git cloneTargetRepository() {
    File path = calculateRepositoryStoragePath(request);
    if(!path.mkdirs()) {
        throw new RuntimeException("Could not create path " + path);
    }

    notifier.message("Cloning repository from GitHub " + request.getTarget().toHttpsURL());
    CloneCommand command = Git.cloneRepository()
                .setBranch(request.getTarget().getBranch())
                .setCloneAllBranches(true)
                .setDirectory(path)
                .setURI(request.getTarget().toHttpsURL())
                .setProgressMonitor(new NotificationProgressMonitor(request, notification, progress));
    try {
        return command.call();
    } catch(Exception e) {
        notifier.message("Failed to clone repository " + e.getMessage());
        throw new RuntimeException("Could not clone source repository " + request.getTarget().toHttpsURL(), e);
    }
}
 
開發者ID:aslakknutsen,項目名稱:github-merge,代碼行數:21,代碼來源:GitService.java


注:本文中的org.eclipse.jgit.api.CloneCommand.call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。