List of usage examples for org.eclipse.jgit.transport NetRCCredentialsProvider NetRCCredentialsProvider
public NetRCCredentialsProvider()
Constructor for NetRCCredentialsProvider.
From source file:com.google.devtools.build.lib.bazel.repository.GitCloneFunction.java
License:Open Source License
@Nullable @Override/* w w w. j av a 2 s . co m*/ public SkyValue compute(SkyKey skyKey, Environment env) throws RepositoryFunctionException { GitRepositoryDescriptor descriptor = (GitRepositoryDescriptor) skyKey.argument(); Git git = null; try { if (descriptor.directory.exists()) { if (isUpToDate(descriptor)) { return new HttpDownloadValue(descriptor.directory); } try { FileSystemUtils.deleteTree(descriptor.directory); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } } git = Git.cloneRepository().setURI(descriptor.remote) .setCredentialsProvider(new NetRCCredentialsProvider()) .setDirectory(descriptor.directory.getPathFile()).setCloneSubmodules(false).setNoCheckout(true) .setProgressMonitor(new GitProgressMonitor("Cloning " + descriptor.remote, reporter)).call(); git.checkout().setCreateBranch(true).setName("bazel-checkout").setStartPoint(descriptor.checkout) .call(); // Using CloneCommand.setCloneSubmodules() results in SubmoduleInitCommand and // SubmoduleUpdateCommand to be called recursively for all submodules. This is not // desirable for repositories, such as github.com/rust-lang/rust-installer, which // recursively includes itself as a submodule, which would result in an infinite // loop if submodules are cloned recursively. For now, limit submodules to only // the first level. if (descriptor.initSubmodules && !git.submoduleInit().call().isEmpty()) { git.submoduleUpdate() .setProgressMonitor( new GitProgressMonitor("Cloning submodules for " + descriptor.remote, reporter)) .call(); } } catch (InvalidRemoteException e) { throw new RepositoryFunctionException(new IOException("Invalid Git repository URI: " + e.getMessage()), Transience.PERSISTENT); } catch (RefNotFoundException | InvalidRefNameException e) { throw new RepositoryFunctionException( new IOException("Invalid branch, tag, or commit: " + e.getMessage()), Transience.PERSISTENT); } catch (GitAPIException e) { throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.TRANSIENT); } finally { if (git != null) { git.close(); } } return new HttpDownloadValue(descriptor.directory); }
From source file:com.google.devtools.build.lib.bazel.repository.GitCloner.java
License:Open Source License
public static SkyValue clone(Rule rule, Path outputDirectory, EventHandler eventHandler, Map<String, String> clientEnvironment) throws RepositoryFunctionException { WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule); if (mapper.isAttributeValueExplicitlySpecified("commit") == mapper .isAttributeValueExplicitlySpecified("tag")) { throw new RepositoryFunctionException( new EvalException(rule.getLocation(), "One of either commit or tag must be defined"), Transience.PERSISTENT);//from w w w . ja v a 2 s .c o m } GitRepositoryDescriptor descriptor; String startingPoint; try { if (mapper.isAttributeValueExplicitlySpecified("commit")) { startingPoint = mapper.get("commit", Type.STRING); } else { startingPoint = "tags/" + mapper.get("tag", Type.STRING); } descriptor = new GitRepositoryDescriptor(mapper.get("remote", Type.STRING), startingPoint, mapper.get("init_submodules", Type.BOOLEAN), outputDirectory); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } // Setup proxy if remote is http or https if (descriptor.remote != null && Ascii.toLowerCase(descriptor.remote).startsWith("http")) { try { new ProxyHelper(clientEnvironment).createProxyIfNeeded(new URL(descriptor.remote)); } catch (IOException ie) { throw new RepositoryFunctionException(ie, Transience.TRANSIENT); } } Git git = null; try { if (descriptor.directory.exists()) { if (isUpToDate(descriptor)) { return new HttpDownloadValue(descriptor.directory); } try { FileSystemUtils.deleteTree(descriptor.directory); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } } git = Git.cloneRepository().setURI(descriptor.remote) .setCredentialsProvider(new NetRCCredentialsProvider()) .setDirectory(descriptor.directory.getPathFile()).setCloneSubmodules(false).setNoCheckout(true) .setProgressMonitor(new GitProgressMonitor("Cloning " + descriptor.remote, eventHandler)) .call(); git.checkout().setCreateBranch(true).setName("bazel-checkout").setStartPoint(descriptor.checkout) .call(); // Using CloneCommand.setCloneSubmodules() results in SubmoduleInitCommand and // SubmoduleUpdateCommand to be called recursively for all submodules. This is not // desirable for repositories, such as github.com/rust-lang/rust-installer, which // recursively includes itself as a submodule, which would result in an infinite // loop if submodules are cloned recursively. For now, limit submodules to only // the first level. if (descriptor.initSubmodules && !git.submoduleInit().call().isEmpty()) { git.submoduleUpdate() .setProgressMonitor( new GitProgressMonitor("Cloning submodules for " + descriptor.remote, eventHandler)) .call(); } } catch (InvalidRemoteException e) { throw new RepositoryFunctionException(new IOException("Invalid Git repository URI: " + e.getMessage()), Transience.PERSISTENT); } catch (RefNotFoundException | InvalidRefNameException e) { throw new RepositoryFunctionException( new IOException("Invalid branch, tag, or commit: " + e.getMessage()), Transience.PERSISTENT); } catch (GitAPIException e) { // This is a sad attempt to actually get a useful error message out of jGit, which will bury // the actual (useful) cause of the exception under several throws. StringBuilder errmsg = new StringBuilder(); errmsg.append(e.getMessage()); Throwable throwable = e; while (throwable.getCause() != null) { throwable = throwable.getCause(); errmsg.append(" caused by " + throwable.getMessage()); } throw new RepositoryFunctionException(new IOException("Error cloning repository: " + errmsg), Transience.PERSISTENT); } catch (JGitInternalException e) { // This is a lame catch-all for jgit throwing RuntimeExceptions all over the place because, // as the docs put it, "a lot of exceptions are so low-level that is is unlikely that the // caller of the command can handle them effectively." Thanks, jgit. throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.PERSISTENT); } finally { if (git != null) { git.close(); } } return new HttpDownloadValue(descriptor.directory); }
From source file:com.mooregreatsoftware.gitprocess.lib.Pusher.java
License:Apache License
private static ThePushResult doJGitPush(GitLib gitLib, Branch localBranch, String remoteBranchName, boolean forcePush, String remoteName) { final Iterable<PushResult> pushResults = Try.of(() -> gitLib.jgit().push().setRemote(remoteName) .setRefSpecs(new RefSpec(localBranch.shortName() + ":" + remoteBranchName)).setForce(forcePush) .setCredentialsProvider(new ChainingCredentialsProvider(new NetRCCredentialsProvider())) .setTransportConfigCallback(new GitTransportConfigCallback()).call()).get(); return new JGitPushResult(pushResults); }
From source file:org.jboss.arquillian.ce.template.TemplateCEContainer.java
License:Open Source License
protected String commitDeployment(Archive<?> archive) throws Exception { String name = newName(archive); File dir = dockerAdapter.getDir(archive); try (GitAdapter git = GitAdapter.cloneRepository(dir, configuration.getGitRepository(true)) .prepare("deployments/" + name)) { dockerAdapter.exportAsZip(new File(dir, "deployments"), archive, name); CredentialsProvider cp;/*from w w w. j ava2 s. co m*/ if (configuration.isNetRC()) { cp = new NetRCCredentialsProvider(); } else { cp = new UsernamePasswordCredentialsProvider(configuration.getGitUsername(), configuration.getGitPassword()); } git.setCredentials(cp).add("deployments").commit().push(); } return name; }