本文整理匯總了Java中org.eclipse.jgit.api.CloneCommand類的典型用法代碼示例。如果您正苦於以下問題:Java CloneCommand類的具體用法?Java CloneCommand怎麽用?Java CloneCommand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CloneCommand類屬於org.eclipse.jgit.api包,在下文中一共展示了CloneCommand類的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: 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();
}
示例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());
}
}
示例4: clone
import org.eclipse.jgit.api.CloneCommand; //導入依賴的package包/類
@Override
public File clone(String branch, boolean noCheckout) throws GitException {
checkGitUrl();
CloneCommand cloneCommand = Git.cloneRepository()
.setURI(gitUrl)
.setNoCheckout(noCheckout)
.setBranch(branch)
.setDirectory(targetDir.toFile());
try (Git git = buildCommand(cloneCommand).call()) {
return git.getRepository().getDirectory();
} catch (GitAPIException e) {
throw new GitException("Fail to clone git repo", e);
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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());
}
}
示例8: cloneRepo
import org.eclipse.jgit.api.CloneCommand; //導入依賴的package包/類
/**
*
* Clones a git repository using the given uri and stores it in the parent directory. Checks out the
* given reference or (if value is null) does not check out a branch
* (which reduces time needed to complete command).
* @param cloneURI the uri to the remote repository
* @param parentDirectory the directory in which to store the git meta directory (".git" directory)
* @param checkoutRef the ref name ("refs/heads/master"), branch name ("master") or tag name ("v1.2.3"). If
* {@code null} is passed, will not checkout a branch.
* @param branchesToClone the branches to clone or all branches if passed a {@code null} value.
* @param monitor reports the progress of the clone command; can be null
* @return the cloned Git repository
* @throws GitAPIException
*/
public static Git cloneRepo(String cloneURI, File parentDirectory, String remoteName,
String checkoutRef, List<String> branchesToClone, ProgressMonitor monitor) throws GitAPIException {
CloneCommand clone = Git.cloneRepository();
if (checkoutRef == null) {
clone.setNoCheckout(true);
} else {
clone.setBranch(checkoutRef);
}
if (branchesToClone == null) {
clone.setCloneAllBranches(true);
} else {
clone.setBranchesToClone(branchesToClone);
}
if (monitor != null) { clone.setProgressMonitor(monitor); }
return clone
.setURI(cloneURI)
.setDirectory(parentDirectory)
.setRemote(remoteName)
.call();
}
示例9: 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;
}
示例10: 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);
}
}
示例11: 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());
}
}
示例12: 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();
}
示例13: 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;
}
示例14: 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;
}
示例15: 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);
}
}