List of usage examples for org.eclipse.jgit.api CloneCommand setProgressMonitor
public CloneCommand setProgressMonitor(ProgressMonitor monitor)
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
/** * In lieu of sparse checkout since it's not yet supported in JGit: * https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772 *//*from w w w.j av a 2 s .c om*/ 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(); }
From source file:com.ejwa.gitdepmavenplugin.DownloaderMojo.java
License:Open Source License
private Git clone(Pom pom, GitDependency dependency) throws MojoExecutionException { final CloneCommand c = new CloneCommand(); final String location = dependency.getLocation(); c.setURI(location);/* www .j a va2 s.c o m*/ 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(); }
From source file:com.ejwa.mavengitdepplugin.DownloaderMojo.java
License:Open Source License
private Git clone(POM pom, GitDependency dependency) { final CloneCommand c = new CloneCommand(); c.setURI(dependency.getLocation());// w ww .j a va 2s.co m c.setCloneAllBranches(true); c.setProgressMonitor(new TextProgressMonitor()); final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency); final String version = dependencyHandler.getDependencyVersion(pom); final String tempDirectory = Directory.getTempDirectoryString(dependency.getLocation(), version); c.setDirectory(new File(tempDirectory)); return c.call(); }
From source file:com.fanniemae.ezpie.common.GitOperations.java
License:Open Source License
public String cloneHTTP(String repo_url, String destination, String userID, String password, String branch) throws InvalidRemoteException, TransportException, GitAPIException, URISyntaxException { _repositoryHost = getHost(repo_url); setupProxy();// w w w. ja va2 s .c om File localDir = new File(destination); CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repo_url); cloneCommand.setDirectory(localDir); if (StringUtilities.isNotNullOrEmpty(branch)) cloneCommand.setBranch(branch); if (StringUtilities.isNotNullOrEmpty(userID)) cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userID, password)); try (Writer writer = new StringWriter()) { TextProgressMonitor tpm = new TextProgressMonitor(writer); cloneCommand.setProgressMonitor(tpm); try (Git result = cloneCommand.call()) { } clearProxyAuthenticatorCache(); writer.flush(); return writer.toString(); } catch (IOException e) { throw new PieException("Error while trying to clone the git repository. " + e.getMessage(), e); } }
From source file:com.fanniemae.ezpie.common.GitOperations.java
License:Open Source License
public String cloneSSH(String repo_url, String destination, String privateKey, String password, String branch) { if (_useProxy) { throw new PieException( "Network proxies do not support SSH, please use an http url to clone this repository."); }/* ww w .j a va2 s .c o m*/ final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() { @Override protected void configure(Host host, Session session) { // This still checks existing host keys and will disable "unsafe" // authentication mechanisms if the host key doesn't match. session.setConfig("StrictHostKeyChecking", "no"); } @Override protected JSch createDefaultJSch(FS fs) throws JSchException { JSch defaultJSch = super.createDefaultJSch(fs); defaultJSch.addIdentity(privateKey, password); return defaultJSch; } }; CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repo_url); File dir = new File(destination); cloneCommand.setDirectory(dir); if (StringUtilities.isNotNullOrEmpty(branch)) cloneCommand.setBranch(branch); cloneCommand.setTransportConfigCallback(new TransportConfigCallback() { public void configure(Transport transport) { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(sshSessionFactory); } }); try (Writer writer = new StringWriter()) { TextProgressMonitor tpm = new TextProgressMonitor(writer); cloneCommand.setProgressMonitor(tpm); try (Git result = cloneCommand.call()) { } writer.flush(); return writer.toString(); } catch (IOException | GitAPIException e) { throw new PieException("Error while trying to clone the git repository. " + e.getMessage(), e); } }
From source file:com.googlesource.gerrit.plugins.github.git.GitCloneStep.java
License:Apache License
@Override public void doImport(ProgressMonitor progress) throws GitCloneFailedException, GitDestinationAlreadyExistsException, GitDestinationNotWritableException { CloneCommand clone = new CloneCommand(); String sourceUri = getSourceUri(); clone.setURI(sourceUri);//from w ww .j a v a 2 s . com 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); } }
From source file:com.microsoft.tfs.client.eclipse.ui.egit.importwizard.CloneGitRepositoryCommand.java
License:Open Source License
private boolean cloneRepository(final IProgressMonitor progressMonitor) { final CloneCommand cloneRepository = Git.cloneRepository(); cloneRepository.setCredentialsProvider(credentialsProvider); cloneRepository.setProgressMonitor(new CloneProgress(progressMonitor)); final File workFolder = new File(workingDirectory); if (!workFolder.exists()) { if (!workFolder.mkdirs()) { if (!workFolder.isDirectory()) { final String errorMessageFormat = "Cannot create {0} directory"; //$NON-NLS-1$ throw new RuntimeException(MessageFormat.format(errorMessageFormat, workingDirectory)); }/*w w w . j av a 2 s. c o m*/ } } cloneRepository.setDirectory(new File(workingDirectory)); cloneRepository.setRemote(remoteName); cloneRepository.setURI(URIUtils.encodeQueryIgnoringPercentCharacters(repositoryUrl.toString())); cloneRepository.setCloneAllBranches(true); cloneRepository.setBranchesToClone(Arrays.asList(refs)); cloneRepository.setBranch(defaultRef); cloneRepository.setNoCheckout(false); cloneRepository.setTimeout(timeout); cloneRepository.setCloneSubmodules(cloneSubmodules); try { cloneRepository.call(); if (progressMonitor.isCanceled()) { throw new CanceledException(); } registerClonedRepository(workingDirectory); } catch (final CanceledException e) { throw e; } catch (final Exception e) { logger.error("Error cloning repository:", e); //$NON-NLS-1$ errorMessage = e.getLocalizedMessage(); return false; } return true; }
From source file:com.rimerosolutions.ant.git.tasks.CloneTask.java
License:Apache License
@Override public void execute() { try {/*from w w w . j a va 2 s . c o m*/ CloneCommand cloneCommand = new CloneCommand(); if (branchToTrack != null) { cloneCommand.setBranch(branchToTrack); } if (!branchNames.isEmpty()) { cloneCommand.setBranchesToClone(branchNames); } cloneCommand.setURI(getUri()).setBare(bare).setCloneAllBranches(cloneAllBranches) .setCloneSubmodules(cloneSubModules).setNoCheckout(noCheckout).setDirectory(getDirectory()); setupCredentials(cloneCommand); if (getProgressMonitor() != null) { cloneCommand.setProgressMonitor(getProgressMonitor()); } cloneCommand.call(); } catch (Exception e) { throw new GitBuildException(String.format(MESSAGE_CLONE_FAILED, getUri()), e); } }
From source file:com.romanenco.gitt.git.GitHelper.java
License:Open Source License
/** * Clone remote HTTP/S repo to local file system. * //from w ww . j ava2s . co m * @param url * @param localPath * @param user * @param password * @throws GitError */ public static void clone(String url, String localPath, String user, String password, ProgressMonitor monitor) throws GitError { Log.d(TAG, "Cloning: " + url); CloneCommand clone = Git.cloneRepository(); clone.setTimeout(30); // set time out for bad servers clone.setURI(url); clone.setDirectory(new File(localPath)); if ((user != null) && (password != null)) { UsernamePasswordCredentialsProvider access = new UsernamePasswordCredentialsProvider(user, password); clone.setCredentialsProvider(access); } if (monitor != null) { clone.setProgressMonitor(monitor); } try { FileUtils.deleteDirectory(new File(localPath)); clone.call(); return; } catch (InvalidRemoteException e) { Log.e(TAG, "InvalidRemote", e); GittApp.saveErrorTrace(e); throw new NotGitRepoError(); } catch (TransportException e) { String trace = GittApp.saveErrorTrace(e); if (trace.indexOf("not authorized") != -1) { Log.e(TAG, "Auth", e); throw new AuthFailError(); } Log.e(TAG, "Transport", e); throw new ConnectionError(); } catch (GitAPIException e) { Log.e(TAG, "GitApi", e); GittApp.saveErrorTrace(e); } catch (IOException e) { Log.e(TAG, "IO", e); GittApp.saveErrorTrace(e); } catch (JGitInternalException e) { Log.e(TAG, "GitInternal", e); GittApp.saveErrorTrace(e); if (e.getCause() instanceof NotSupportedException) { throw new ConnectionError(); } else { throw new GitError(); } } throw new GitError(); }
From source file:es.logongas.openshift.ant.impl.OpenShiftUtil.java
License:Apache License
public void gitCloneApplication(String serverUrl, String userName, String password, String domainName, String applicationName, String privateKeyFile, String path) throws GitAPIException { IUser user = getUser(serverUrl, userName, password); IDomain domain = user.getDomain(domainName); IApplication application = domain.getApplicationByName(applicationName); String gitURL = application.getGitUrl(); SshSessionFactory.setInstance(new CustomConfigSessionFactory(privateKeyFile)); CloneCommand cloneCommand = new CloneCommand(); cloneCommand.setURI(gitURL);/*from www . j a va 2s . co m*/ cloneCommand.setDirectory(new File(path)); cloneCommand.setTimeout(20); cloneCommand.setProgressMonitor(new TextProgressMonitor()); cloneCommand.call(); }