List of usage examples for org.eclipse.jgit.transport Transport setCredentialsProvider
public void setCredentialsProvider(CredentialsProvider credentialsProvider)
From source file:com.gmail.cjbooms.thesis.pythonappengine.server.git.GitCommandsServiceImpl.java
License:Open Source License
/** * Push Changes to a Remote Repository//from w w w . j a v a2 s .co m * * @param pathToLocalRepository Root Location Of Repository or Project * @param remoteRepoURL The URL of the Remote Repository to push to * @param userName The remote login user name * @param password The remote login password * @throws IOException, GitAPIException, URISyntaxException */ public void pushLocalCommitsToRemoteRepository(String pathToLocalRepository, String remoteRepoURL, String userName, String password) throws IOException { File repositoryDirectory = new File(pathToLocalRepository); Git localGitRepositoryRef = Git.open(repositoryDirectory); Repository localRepository = localGitRepositoryRef.getRepository(); URIish remoteURI = null; try { remoteURI = new URIish(remoteRepoURL); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage()); } Transport t = Transport.open(localRepository, remoteURI); ((TransportHttp) t).setUseSmartHttp(true); RemoteRefUpdate remoteRefUpdate = new RemoteRefUpdate(localRepository, localRepository.getRef("master"), "refs/heads/master", true, "refs/heads/master", null); t.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password)); t.push(NullProgressMonitor.INSTANCE, Collections.singleton(remoteRefUpdate)); }
From source file:com.gmail.cjbooms.thesis.pythonappengine.server.git.GitCommandsServiceImpl.java
License:Open Source License
/** * Pull changes from Remote Repository/* www. j av a 2 s. co m*/ * * @param pathToLocalRepository Root Location Of Repository or Project * @param remoteRepoURL The URL of the Remote Repository to push to * @param userName The remote login user name * @param password The remote login password * @throws IOException, GitAPIException, URISyntaxException */ public void pullChangesFromRemoteRepository(String pathToLocalRepository, String remoteRepoURL, String userName, String password) throws IOException { File repositoryDirectory = new File(pathToLocalRepository); Git localGitRepositoryRef = Git.open(repositoryDirectory); Repository localRepository = localGitRepositoryRef.getRepository(); URIish remoteURI = null; try { remoteURI = new URIish(remoteRepoURL); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage()); } Transport t = Transport.open(localRepository, remoteURI); ((TransportHttp) t).setUseSmartHttp(true); t.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password)); RefSpec refSpec = new RefSpec("+refs/heads/*:refs/heads/*"); t.fetch(NullProgressMonitor.INSTANCE, Collections.singleton(refSpec)); }
From source file:com.google.gerrit.server.git.PushOp.java
License:Apache License
private PushResult pushVia(final Transport tn) throws IOException, NotSupportedException, TransportException { tn.applyConfig(config);//w w w .j av a 2 s .c o m tn.setCredentialsProvider(credentialsProvider); final List<RemoteRefUpdate> todo = generateUpdates(tn); if (todo.isEmpty()) { // If we have no commands selected, we have nothing to do. // Calling JGit at this point would just redo the work we // already did, and come up with the same answer. Instead // send back an empty result. // return new PushResult(); } return tn.push(NullProgressMonitor.INSTANCE, todo); }
From source file:com.googlesource.gerrit.plugins.replication.PushOne.java
License:Apache License
private PushResult pushVia(Transport tn) throws IOException, NotSupportedException, TransportException { tn.applyConfig(config);// w w w . j a va 2 s. c o m tn.setCredentialsProvider(credentialsProvider); List<RemoteRefUpdate> todo = generateUpdates(tn); if (todo.isEmpty()) { // If we have no commands selected, we have nothing to do. // Calling JGit at this point would just redo the work we // already did, and come up with the same answer. Instead // send back an empty result. return new PushResult(); } repLog.info("Push to " + uri + " references: " + todo); return tn.push(NullProgressMonitor.INSTANCE, todo); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.TransportFactoryImpl.java
License:Apache License
public Transport createTransport(@NotNull final Repository r, @NotNull final URIish url, @NotNull final AuthSettings authSettings, final int timeoutSeconds) throws NotSupportedException, VcsException { try {/*from w ww . ja v a2 s .co m*/ checkUrl(url); URIish preparedURI = prepareURI(url); final Transport t = Transport.open(r, preparedURI); t.setCredentialsProvider(authSettings.toCredentialsProvider()); if (t instanceof SshTransport) { SshTransport ssh = (SshTransport) t; ssh.setSshSessionFactory(getSshSessionFactory(authSettings, url)); } t.setTimeout(timeoutSeconds); return t; } catch (TransportException e) { throw new VcsException("Cannot create transport", e); } }
From source file:org.eclipse.egit.core.op.CloneOperation.java
License:Open Source License
private void doFetch(final IProgressMonitor monitor) throws NotSupportedException, TransportException { final Transport tn = Transport.open(local, remoteConfig); if (credentialsProvider != null) tn.setCredentialsProvider(credentialsProvider); tn.setTimeout(this.timeout); try {// ww w. j ava 2s . c o m final EclipseGitProgressTransformer pm; pm = new EclipseGitProgressTransformer(monitor); fetchResult = tn.fetch(pm, null); } finally { tn.close(); } }
From source file:org.eclipse.egit.core.op.ListRemoteOperation.java
License:Open Source License
/** * @param pm//from w w w . jav a 2 s .c om * the monitor to be used for reporting progress and responding * to cancellation. The monitor is never <code>null</code> * @throws InvocationTargetException * @throws InterruptedException */ public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { Transport transport = null; Connection connection = null; try { transport = Transport.open(localDb, uri); if (credentialsProvider != null) transport.setCredentialsProvider(credentialsProvider); transport.setTimeout(this.timeout); if (pm != null) pm.beginTask(CoreText.ListRemoteOperation_title, IProgressMonitor.UNKNOWN); connection = transport.openFetch(); remoteRefsMap = connection.getRefsMap(); } catch (NotSupportedException e) { throw new InvocationTargetException(e); } catch (TransportException e) { throw new InvocationTargetException(e); } finally { if (connection != null) connection.close(); if (transport != null) transport.close(); if (pm != null) pm.done(); } }
From source file:org.eclipse.egit.core.op.PushOperation.java
License:Open Source License
/** * Execute operation and store result. Operation is executed independently * on each remote repository.//from w ww .j a va 2 s . c o m * <p> * * @param actMonitor * the monitor to be used for reporting progress and responding * to cancellation. The monitor is never <code>null</code> * * @throws InvocationTargetException * Cause of this exceptions may include * {@link TransportException}, {@link NotSupportedException} or * some unexpected {@link RuntimeException}. */ public void run(IProgressMonitor actMonitor) throws InvocationTargetException { if (operationResult != null) throw new IllegalStateException(CoreText.OperationAlreadyExecuted); for (URIish uri : this.specification.getURIs()) { for (RemoteRefUpdate update : this.specification.getRefUpdates(uri)) if (update.getStatus() != Status.NOT_ATTEMPTED) throw new IllegalStateException(CoreText.RemoteRefUpdateCantBeReused); } IProgressMonitor monitor; if (actMonitor == null) monitor = new NullProgressMonitor(); else monitor = actMonitor; final int totalWork = specification.getURIsNumber() * WORK_UNITS_PER_TRANSPORT; if (dryRun) monitor.beginTask(CoreText.PushOperation_taskNameDryRun, totalWork); else monitor.beginTask(CoreText.PushOperation_taskNameNormalRun, totalWork); operationResult = new PushOperationResult(); for (final URIish uri : specification.getURIs()) { final SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, WORK_UNITS_PER_TRANSPORT, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); Transport transport = null; try { if (monitor.isCanceled()) { operationResult.addOperationResult(uri, CoreText.PushOperation_resultCancelled); continue; } transport = Transport.open(localDb, uri); if (credentialsProvider != null) transport.setCredentialsProvider(credentialsProvider); transport.setTimeout(this.timeout); if (rc != null) transport.applyConfig(rc); transport.setDryRun(dryRun); final EclipseGitProgressTransformer gitSubMonitor = new EclipseGitProgressTransformer(subMonitor); final PushResult pr = transport.push(gitSubMonitor, specification.getRefUpdates(uri)); operationResult.addOperationResult(uri, pr); monitor.worked(WORK_UNITS_PER_TRANSPORT); } catch (final NoRemoteRepositoryException e) { operationResult.addOperationResult(uri, NLS.bind(CoreText.PushOperation_resultNoServiceError, e.getMessage())); } catch (final TransportException e) { operationResult.addOperationResult(uri, NLS.bind(CoreText.PushOperation_resultTransportError, e.getMessage())); } catch (final NotSupportedException e) { operationResult.addOperationResult(uri, NLS.bind(CoreText.PushOperation_resultNotSupported, e.getMessage())); } finally { if (transport != null) { transport.close(); } // Dirty trick to get things always working. subMonitor.beginTask("", WORK_UNITS_PER_TRANSPORT); //$NON-NLS-1$ subMonitor.done(); subMonitor.done(); } } monitor.done(); }
From source file:org.eclipse.egit.ui.internal.fetch.FetchWizard.java
License:Open Source License
@Override public boolean performFinish() { if (repoPage.getSelection().isConfigSelected() && refSpecPage.isSaveRequested()) saveConfig();//from w w w . j a v a2 s. c om if (repoPage.getStoreInSecureStore()) { if (!SecureStoreUtils.storeCredentials(repoPage.getCredentials(), repoPage.getSelection().getURI())) return false; } final Transport transport; final RepositorySelection repoSelection = repoPage.getSelection(); try { if (repoSelection.isConfigSelected()) transport = Transport.open(localDb, repoSelection.getConfig()); else transport = Transport.open(localDb, repoSelection.getURI(false)); } catch (final NotSupportedException e) { ErrorDialog.openError(getShell(), UIText.FetchWizard_transportNotSupportedTitle, UIText.FetchWizard_transportNotSupportedMessage, new Status(IStatus.ERROR, org.eclipse.egit.ui.Activator.getPluginId(), e.getMessage(), e)); return false; } UserPasswordCredentials credentials = repoPage.getCredentials(); if (credentials != null) transport.setCredentialsProvider( new UsernamePasswordCredentialsProvider(credentials.getUser(), credentials.getPassword())); transport.setTagOpt(refSpecPage.getTagOpt()); final Job fetchJob = new FetchJob(transport, refSpecPage.getRefSpecs(), getSourceString()); fetchJob.setUser(true); fetchJob.schedule(); repoPage.saveUriInPrefs(); return true; }
From source file:org.kuali.student.git.importer.JGitPushMain.java
License:Educational Community License
private static void configure(Transport transport, String username, String password) { if (username != null && password != null) transport.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)); // wait 30 seconds transport.setTimeout(30);// www .j a v a 2s . c om }