本文整理匯總了Java中org.eclipse.jgit.api.CloneCommand.setCredentialsProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java CloneCommand.setCredentialsProvider方法的具體用法?Java CloneCommand.setCredentialsProvider怎麽用?Java CloneCommand.setCredentialsProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.api.CloneCommand
的用法示例。
在下文中一共展示了CloneCommand.setCredentialsProvider方法的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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: call
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
public Git call(final GitOperationsStep gitOperationsStep, Git git,
CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder)
throws InvalidRemoteException, TransportException, GitAPIException {
CloneCommand cc = Git.cloneRepository().setURI(gitRepoUrl)
.setDirectory(gitRepoFolder);
if (!Const.isEmpty(this.branchName)) {
cc = cc.setBranch(gitOperationsStep
.environmentSubstitute(this.branchName));
}
cc.setCloneAllBranches(this.cloneAllBranches).setCloneSubmodules(
this.cloneSubModules);
if (cp != null) {
cc.setCredentialsProvider(cp);
}
return cc.setBare(false).call();
}
示例7: 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);
}
示例8: cloneRepo
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
public void cloneRepo(String branch) throws Exception {
CloneCommand cloneCommand = Git.cloneRepository().setURI(repositoryUrl).setDirectory(localRepo.getDirectory().getParentFile());
if (branch != null)
cloneCommand.setBranch(branch);
if (credentialsProvider != null)
cloneCommand.setCredentialsProvider(credentialsProvider);
cloneCommand.call();
}
示例9: cloneNoCheckout
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
* In lieu of sparse checkout since it's not yet supported in JGit:
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772
*/
public void cloneNoCheckout(boolean withProgress) throws Exception {
CloneCommand clone = Git.cloneRepository().setURI(repositoryUrl).setDirectory(localRepo.getDirectory().getParentFile()).setNoCheckout(true);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442029
if (credentialsProvider != null)
clone.setCredentialsProvider(credentialsProvider);
if (withProgress)
clone.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)));
clone.call();
}
示例10: 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();
}
示例11: testBogusLoginClone
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testBogusLoginClone() throws Exception {
// restrict repository access
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.CLONE;
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);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("bogus", "bogus"));
GitBlitSuite.close(clone.call());
cloned = true;
} catch (Exception e) {
// swallow the exception which we expect
}
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
GitBlit.self().updateRepositoryModel(model.name, model, false);
assertFalse("Bogus login cloned a repository?!", cloned);
}
示例12: 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);
}
RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git");
model.accessRestriction = AccessRestrictionType.NONE;
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);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
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());
}
}
}
示例13: testSubfolderPush
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testSubfolderPush() throws Exception {
GitBlitSuite.close(jgitFolder);
if (jgitFolder.exists()) {
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/test/jgit.git", url));
clone.setDirectory(jgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
GitBlitSuite.close(clone.call());
assertTrue(true);
Git git = Git.open(jgitFolder);
File file = new File(jgitFolder, "TODO");
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").call();
Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.OK, update.getStatus());
}
}
}
示例14: testPushToNonBareRepository
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Test
public void testPushToNonBareRepository() throws Exception {
CloneCommand clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/working/jgit", url));
clone.setDirectory(jgit2Folder);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password));
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().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call();
GitBlitSuite.close(git);
for (PushResult result : results) {
for (RemoteRefUpdate update : result.getRemoteUpdates()) {
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus());
}
}
}
示例15: execute
import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public void execute(Wandora wandora, Context context) {
if(cloneUI == null) {
cloneUI = new CloneUI();
}
cloneUI.setUsername(getUsername());
cloneUI.setPassword(getPassword());
cloneUI.openInDialog();
if(cloneUI.wasAccepted()) {
setDefaultLogger();
setLogTitle("Git clone");
String cloneUrl = cloneUI.getCloneUrl();
String destinationDirectory = cloneUI.getDestinationDirectory();
String username = cloneUI.getUsername();
String password = cloneUI.getPassword();
setUsername(username);
setPassword(password);
log("Cloning git repository from "+cloneUrl);
try {
CloneCommand clone = Git.cloneRepository();
clone.setURI(cloneUrl);
clone.setDirectory(new File(destinationDirectory));
if(isNotEmpty(username)) {
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( username, password );
clone.setCredentialsProvider(credentialsProvider);
}
clone.call();
if(cloneUI.getOpenProject()) {
log("Opening project.");
LoadWandoraProject loadProject = new LoadWandoraProject(destinationDirectory);
loadProject.setToolLogger(this);
loadProject.execute(wandora, context);
}
log("Ready.");
}
catch (GitAPIException ex) {
log(ex.toString());
}
catch (Exception e) {
log(e);
}
setState(WAIT);
}
}