List of usage examples for org.eclipse.jgit.transport Transport applyConfig
public void applyConfig(RemoteConfig cfg)
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); 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. ///*from w ww . j av a2 s .c o m*/ 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); 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(); }/* w w w . j a va2 s .c o m*/ repLog.info("Push to " + uri + " references: " + todo); return tn.push(NullProgressMonitor.INSTANCE, todo); }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository push(final String name) throws GitWrapException { try {/* w w w . j a va 2 s . c o m*/ final StoredConfig config = repository.getConfig(); final RemoteConfig remote = new RemoteConfig(config, name); final List<URIish> pushURIs = remote.getPushURIs(); final List<RefSpec> pushRefSpecs = remote.getPushRefSpecs(); final Collection<RemoteRefUpdate> remoteRefUpdates = Transport.findRemoteRefUpdatesFor(repository, pushRefSpecs, null); for (final URIish uri : pushURIs) { final Collection<RemoteRefUpdate> updates = new ArrayList<RemoteRefUpdate>(); for (final RemoteRefUpdate rru : remoteRefUpdates) { updates.add(new RemoteRefUpdate(rru, null)); } Transport transport = null; try { transport = Transport.open(repository, uri); transport.applyConfig(remote); final PushResult result = transport.push(MONITOR, updates); if (result.getMessages().length() > 0 && LOGGER.isDebugEnabled()) { LOGGER.debug(result.getMessages()); } } finally { if (transport != null) { transport.close(); } } } } catch (final NotSupportedException e) { throw new GitWrapException( "Cannot push to repository: %s. Transport is not supported.\nNested error: %s", e, name, e.getMessage()); } catch (final TransportException e) { throw new GitWrapException("Transport failed for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } catch (final URISyntaxException e) { throw new GitWrapException("Invalid URI for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } catch (final IOException e) { throw new GitWrapException("Transport failed for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } return this; }
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 av a2 s . c om * <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(); }