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


Java CloneCommand.setDirectory方法代碼示例

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


在下文中一共展示了CloneCommand.setDirectory方法的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 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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: testAnonymousClone

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testAnonymousClone() throws Exception {
	GitBlitSuite.close(ticgitFolder);
	if (ticgitFolder.exists()) {
		FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
	}

	// set push restriction
	RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
	model.accessRestriction = AccessRestrictionType.PUSH;
	model.authorizationControl = AuthorizationControl.NAMED;
	GitBlit.self().updateRepositoryModel(model.name, model, false);
	
	CloneCommand clone = Git.cloneRepository();
	clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
	clone.setDirectory(ticgitFolder);
	clone.setBare(false);
	clone.setCloneAllBranches(true);
	GitBlitSuite.close(clone.call());		
	assertTrue(true);
	
	// restore anonymous repository access
	model.accessRestriction = AccessRestrictionType.NONE;
	model.authorizationControl = AuthorizationControl.NAMED;
	GitBlit.self().updateRepositoryModel(model.name, model, false);
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:27,代碼來源:GitDaemonTest.java

示例9: testClone

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testClone() throws Exception {
	GitBlitSuite.close(ticgitFolder);
	if (ticgitFolder.exists()) {
		FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
	}
	
	CloneCommand clone = Git.cloneRepository();
	clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
	clone.setDirectory(ticgitFolder);
	clone.setBare(false);
	clone.setCloneAllBranches(true);
	clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
	GitBlitSuite.close(clone.call());		
	assertTrue(true);
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:17,代碼來源:GitServletTest.java

示例10: clone

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
private Git clone(Pom pom, GitDependency dependency) throws MojoExecutionException {
	final CloneCommand c = new CloneCommand();
	final String location = dependency.getLocation();

	c.setURI(location);
	c.setCloneAllBranches(true);
	c.setProgressMonitor(new TextProgressMonitor());

	final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);
	final String version = dependencyHandler.getDependencyVersion(pom);
	final String tempDirectory = Directory.getTempDirectoryString(location, version);

	c.setDirectory(new File(tempDirectory));
	return c.call();
}
 
開發者ID:ejwa,項目名稱:gitdep-maven-plugin,代碼行數:16,代碼來源:DownloaderMojo.java

示例11: run

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public void run() throws GitAPIException {
  CloneCommand cloneCommand = Git.cloneRepository();
  cloneCommand.setDirectory(myTargetDirectory);
  cloneCommand.setURI(myUrl);
  cloneCommand.setCredentialsProvider(myCredentialsProvider);
  myGit = cloneCommand.call();
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:9,代碼來源:GitHttpRemoteCommand.java

示例12: testCloneRestrictedRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testCloneRestrictedRepo() throws Exception {
	GitBlitSuite.close(ticgit2Folder);
	if (ticgit2Folder.exists()) {
		FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
	}

	// restrict repository access
	RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
	model.accessRestriction = AccessRestrictionType.CLONE;
	model.authorizationControl = AuthorizationControl.NAMED;
	GitBlit.self().updateRepositoryModel(model.name, model, false);
	
	// delete any existing working folder		
	boolean cloned = false;
	try {
		CloneCommand clone = Git.cloneRepository();
		clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
		clone.setDirectory(ticgit2Folder);
		clone.setBare(false);
		clone.setCloneAllBranches(true);
		GitBlitSuite.close(clone.call());
		cloned = true;
	} catch (Exception e) {
		// swallow the exception which we expect
	}

	assertFalse("Anonymous was able to clone the repository?!", cloned);

	FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE);
	
	// restore anonymous repository access
	model.accessRestriction = AccessRestrictionType.NONE;
	model.authorizationControl = AuthorizationControl.NAMED;
	GitBlit.self().updateRepositoryModel(model.name, model, false);
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:37,代碼來源:GitDaemonTest.java

示例13: testAnonymousPush

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testAnonymousPush() throws Exception {
	GitBlitSuite.close(ticgitFolder);
	if (ticgitFolder.exists()) {
		FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
	}

	// restore anonymous repository access
	RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
	model.accessRestriction = AccessRestrictionType.NONE;
	model.authorizationControl = AuthorizationControl.NAMED;
	GitBlit.self().updateRepositoryModel(model.name, model, false);

	CloneCommand clone = Git.cloneRepository();
	clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
	clone.setDirectory(ticgitFolder);
	clone.setBare(false);
	clone.setCloneAllBranches(true);
	GitBlitSuite.close(clone.call());		
	assertTrue(true);
	
	Git git = Git.open(ticgitFolder);
	File file = new File(ticgitFolder, "TODO");
	OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
	BufferedWriter w = new BufferedWriter(os);
	w.write("// hellol中文 " + new Date().toString() + "\n");
	w.close();
	git.add().addFilepattern(file.getName()).call();
	git.commit().setMessage("test commit").call();
	Iterable<PushResult> results = git.push().setPushAll().call();
	GitBlitSuite.close(git);
	for (PushResult result : results) {
		for (RemoteRefUpdate update : result.getRemoteUpdates()) {
			assertEquals(Status.OK, update.getStatus());
		}
	}
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:38,代碼來源:GitDaemonTest.java

示例14: testPushRestrictedRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testPushRestrictedRepo() throws Exception {
	GitBlitSuite.close(ticgitFolder);
	if (ticgitFolder.exists()) {
		FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
	}

	// restore anonymous repository access
	RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
	model.accessRestriction = AccessRestrictionType.PUSH;
	model.authorizationControl = AuthorizationControl.NAMED;
	GitBlit.self().updateRepositoryModel(model.name, model, false);

	CloneCommand clone = Git.cloneRepository();
	clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
	clone.setDirectory(ticgitFolder);
	clone.setBare(false);
	clone.setCloneAllBranches(true);
	GitBlitSuite.close(clone.call());		
	assertTrue(true);
	
	Git git = Git.open(ticgitFolder);
	File file = new File(ticgitFolder, "TODO");
	OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
	BufferedWriter w = new BufferedWriter(os);
	w.write("// hellol中文 " + new Date().toString() + "\n");
	w.close();
	git.add().addFilepattern(file.getName()).call();
	git.commit().setMessage("test commit").call();
	Iterable<PushResult> results = git.push().setPushAll().call();
	GitBlitSuite.close(git);
	for (PushResult result : results) {
		for (RemoteRefUpdate update : result.getRemoteUpdates()) {
			assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus());
		}
	}
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:38,代碼來源:GitDaemonTest.java

示例15: testPushToNonBareRepository

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testPushToNonBareRepository() throws Exception {
	GitBlitSuite.close(jgit2Folder);
	if (jgit2Folder.exists()) {
		FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY);
	}
	
	CloneCommand clone = Git.cloneRepository();
	clone.setURI(MessageFormat.format("{0}/working/jgit", url));
	clone.setDirectory(jgit2Folder);
	clone.setBare(false);
	clone.setCloneAllBranches(true);
	GitBlitSuite.close(clone.call());
	assertTrue(true);

	Git git = Git.open(jgit2Folder);
	File file = new File(jgit2Folder, "NONBARE");
	OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET);
	BufferedWriter w = new BufferedWriter(os);
	w.write("// " + new Date().toString() + "\n");
	w.close();
	git.add().addFilepattern(file.getName()).call();
	git.commit().setMessage("test commit followed by push to non-bare repository").call();

	Iterable<PushResult> results = git.push().setPushAll().call();
	GitBlitSuite.close(git);
	
	for (PushResult result : results) {
		for (RemoteRefUpdate update : result.getRemoteUpdates()) {
			assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus());
		}
	}
}
 
開發者ID:warpfork,項目名稱:gitblit,代碼行數:34,代碼來源:GitDaemonTest.java


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