List of usage examples for org.eclipse.jgit.api Git cloneRepository
public static CloneCommand cloneRepository()
From source file:org.wso2.developerstudio.appfactory.core.repository.JgitRepoManager.java
License:Open Source License
public void gitClone() throws InvalidRemoteException, TransportException, GitAPIException, IOException { Git.cloneRepository().setCredentialsProvider(provider).setURI(remotePath).setDirectory(new File(localPath)) .call();/*w ww . j a va2 s. co m*/ setRepoAuthor(); }
From source file:org.wso2.security.tools.dependencycheck.scanner.handler.GitHandler.java
License:Open Source License
/** * Clone from GitHub and returns a {@link Git} object. If the URL is related to a private * repository, GitHub account credentials should be given * * @param gitURL GitHub URL to clone the product. By default master branch is cloned. If a specific branch or * tag to be cloned, the specified URL for the branch or tag should be given * @param username GitHub user name if the product is in a private repository * @param password GitHub password if the product is in private repository * @param filePath Set directory to clone the product * @return {@link Git} object//ww w . j a va2s. c o m * @throws GitAPIException Exceptions thrown by {@link org.eclipse.jgit} */ public static Git gitClone(String gitURL, String username, String password, String filePath) throws GitAPIException { String branch = "master"; if (gitURL.contains("/tree/")) { branch = gitURL.substring(gitURL.lastIndexOf("/") + 1); gitURL = gitURL.substring(0, gitURL.indexOf("/tree/")); } CloneCommand cloneCommand = Git.cloneRepository() .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))).setURI(gitURL) .setDirectory(new File(filePath)).setBranch(branch); if (username != null && password != null) { cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)); } return cloneCommand.call(); }
From source file:org.wso2.security.tools.scanner.dependency.js.reportpublisher.GitUploader.java
License:Open Source License
/** * Constructor to create GitUploader.//ww w.j a v a2s. c om * In this call GitUploader instance created with username, password and artifact url. * Meanwhile It clones the artifact repo from github. If the cloned repository exists in local directory * pull command will execute. * * @param gitUploaderProperties This object holds the value of username, password, and repository URL where the scan * reports should be uploaded. * @throws GitAPIException Exception occurred when clone or pull action executed. * @throws FileHandlerException Exception occurred while creating directory. */ public GitUploader(GitUploaderProperties gitUploaderProperties) throws GitAPIException, FileHandlerException { super(); this.gitUploaderProperties = gitUploaderProperties; File artifactFile = new File(JSScannerConstants.SECURITY_ARTIFACT_HOME); if (!artifactFile.exists()) { CommonUtils.createDirectory(artifactFile); gitRepo = Git.cloneRepository().setURI(gitUploaderProperties.getRepoURL()) .setDirectory(new File(artifactFile.getAbsolutePath())) .setCredentialsProvider(new UsernamePasswordCredentialsProvider( new String(gitUploaderProperties.getGitUsername()), new String(gitUploaderProperties.getGitPassword()))) .call(); log.info("[JS_SEC_DAILY_SCAN] " + "Security artifact repo cloned successfully."); } else { // If cloned repository exists in local directory, pull command will be executed, if (gitPull(artifactFile)) { log.error("[JS_SEC_DAILY_SCAN] " + "Security artifact repo pull action successful."); } } }
From source file:org.xwiki.git.internal.DefaultGitManager.java
License:Open Source License
@Override public Repository getRepository(String repositoryURI, String localDirectoryName) { Repository repository;/*from w w w . j a v a 2s . c om*/ File localGitDirectory = new File(this.environment.getPermanentDirectory(), "git"); File localDirectory = new File(localGitDirectory, localDirectoryName); File gitDirectory = new File(localDirectory, ".git"); this.logger.debug("Local Git repository is at [{}]", gitDirectory); FileRepositoryBuilder builder = new FileRepositoryBuilder(); try { // Step 1: Initialize Git environment repository = builder.setGitDir(gitDirectory).readEnvironment().findGitDir().build(); Git git = new Git(repository); // Step 2: Verify if the directory exists and isn't empty. if (!gitDirectory.exists()) { // Step 2.1: Need to clone the remote repository since it doesn't exist git.cloneRepository().setDirectory(localDirectory).setURI(repositoryURI).call(); } } catch (Exception e) { throw new RuntimeException(String.format("Failed to execute Git command in [%s]", gitDirectory), e); } return repository; }
From source file:org.xwiki.git.internal.GitScriptService.java
License:Open Source License
/** * Clone a Git repository by storing it locally in the XWiki Permanent directory. If the repository is already * cloned, no action is done.//from w w w .j av a 2 s . com * * @param repositoryURI the URI to the Git repository to clone (eg "git://github.com/xwiki/xwiki-commons.git") * @param localDirectoryName the name of the directory where the Git repository will be cloned (this directory is * relative to the permanent directory * @return the cloned Repository instance */ public Repository getRepository(String repositoryURI, String localDirectoryName) { Repository repository; File localDirectory = new File(this.environment.getPermanentDirectory(), "git/" + localDirectoryName); File gitDirectory = new File(localDirectory, ".git"); this.logger.debug("Local Git repository is at [{}]", gitDirectory); FileRepositoryBuilder builder = new FileRepositoryBuilder(); try { // Step 1: Initialize Git environment repository = builder.setGitDir(gitDirectory).readEnvironment().findGitDir().build(); Git git = new Git(repository); // Step 2: Verify if the directory exists and isn't empty. if (!gitDirectory.exists()) { // Step 2.1: Need to clone the remote repository since it doesn't exist git.cloneRepository().setDirectory(localDirectory).setURI(repositoryURI).call(); } } catch (Exception e) { throw new RuntimeException(String.format("Failed to execute Git command in [%s]", gitDirectory), e); } return repository; }
From source file:org.yakindu.sct.examples.wizard.service.git.GitRepositoryExampleService.java
License:Open Source License
protected IStatus cloneRepository(IProgressMonitor monitor) { String repoURL = getPreference(ExamplesPreferenceConstants.REMOTE_LOCATION); String remoteBranch = getPreference(ExamplesPreferenceConstants.REMOTE_BRANCH); Git call = null;/* w w w . j a v a 2 s .co m*/ java.nio.file.Path storageLocation = getStorageLocation(); try { call = Git.cloneRepository().setURI(repoURL).setDirectory(storageLocation.toFile()) .setProgressMonitor(new EclipseGitProgressTransformer(monitor)).setBranch(remoteBranch).call(); } catch (GitAPIException e) { try { deleteFolder(storageLocation); } catch (IOException ex) { ex.printStackTrace(); } return new Status(IStatus.ERROR, ExampleActivator.PLUGIN_ID, "Unable to clone repository " + repoURL + "!"); } finally { if (call != null) call.close(); if (monitor.isCanceled()) { try { deleteFolder(storageLocation); } catch (IOException e) { e.printStackTrace(); } } } return Status.OK_STATUS; }
From source file:org.z2env.gitcr.test.TestGitTools.java
License:Apache License
@Test public void testSshClone() throws Exception { File tmpFile = null;/*from w w w .j av a 2s. co m*/ try { tmpFile = File.createTempFile("TestGitTools_", ".tmp"); tmpFile.delete(); Git.cloneRepository().setURI("ssh://zfabrik@z2-environment.net/~/git/z2-core").setDirectory(tmpFile) .call(); assertValid(isValidRepository(new URIish(tmpFile.getCanonicalPath()))); } finally { if (tmpFile != null) { FileUtils.delete(tmpFile); } } }
From source file:org.zanata.sync.jobs.plugin.git.service.impl.GitSyncService.java
License:Open Source License
private static Git doGitClone(String repoUrl, File destPath, Credentials credentials) throws GitAPIException { destPath.mkdirs();//from w w w . j a v a2 s . c o m CloneCommand clone = Git.cloneRepository(); setUserIfProvided(clone, credentials).setBare(false).setCloneAllBranches(true).setDirectory(destPath) .setURI(repoUrl); Git git = clone.call(); log.info("git clone finished: {} -> {}", repoUrl, destPath); return git; }
From source file:org.zanata.sync.plugin.git.service.impl.GitSyncService.java
License:Open Source License
private void doGitClone(String repoUrl, File destPath) { destPath.mkdirs();/*from w ww . j av a 2 s .c o m*/ CloneCommand clone = Git.cloneRepository(); clone.setBare(false); clone.setCloneAllBranches(false); clone.setDirectory(destPath).setURI(repoUrl); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider( getCredentials().getUsername(), getCredentials().getSecret()); clone.setCredentialsProvider(user); try { clone.call(); } catch (GitAPIException e) { throw new RepoSyncException(e); } }
From source file:playRepository.GitRepository.java
License:Apache License
/** * Clones a Git repository.//from ww w . java2 s .c o m * * Creates a bare repository and copies all branches from the origin * repository into the bare repository. * * @param gitUrl the url of the origin repository * @param forkingProject the project of the cloned repository * @throws GitAPIException * @throws IOException * * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_bare_repository">bare repository</a> */ public static void cloneRepository(String gitUrl, Project forkingProject) throws GitAPIException { Git.cloneRepository().setURI(gitUrl).setDirectory(getGitDirectory(forkingProject)).setCloneAllBranches(true) .setBare(true).call(); }