List of usage examples for org.eclipse.jgit.transport RemoteConfig getPushURIs
public List<URIish> getPushURIs()
From source file:com.genuitec.eclipse.gerrit.tools.internal.fbranches.BranchingUtils.java
License:Open Source License
public static PushOperationSpecification setupPush(Repository repository, String refSpec) throws IOException, URISyntaxException { PushOperationSpecification spec = new PushOperationSpecification(); Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(repository, Collections.singletonList(new RefSpec(refSpec)), null); RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); for (URIish uri : config.getPushURIs()) { spec.addURIRefUpdates(uri, updates); break;/*from ww w. j ava 2 s .com*/ } if (spec.getURIsNumber() == 0) { for (URIish uri : config.getURIs()) { spec.addURIRefUpdates(uri, updates); break; } } if (spec.getURIsNumber() == 0) { throw new RuntimeException("Cannot find URI for push"); } return spec; }
From source file:com.genuitec.eclipse.gerrit.tools.utils.GerritUtils.java
License:Open Source License
public static String getGerritProjectName(Repository repository) { try {// w w w . j a va2 s. c o m RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$ List<URIish> urls = new ArrayList<URIish>(config.getPushURIs()); urls.addAll(config.getURIs()); for (URIish uri : urls) { if (uri.getPort() == 29418) { //Gerrit refspec String path = uri.getPath(); while (path.startsWith("/")) { //$NON-NLS-1$ path = path.substring(1); } return path; } break; } } catch (Exception e) { GerritToolsPlugin.getDefault().log(e); } return null; }
From source file:com.genuitec.eclipse.gerrit.tools.utils.GerritUtils.java
License:Open Source License
public static String getGerritURL(Repository repository) { String best = null;//from ww w . jav a2s.c o m try { RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$ List<URIish> urls = new ArrayList<URIish>(config.getPushURIs()); urls.addAll(config.getURIs()); for (URIish uri : urls) { best = "https://" + uri.getHost(); //$NON-NLS-1$ if (uri.getPort() == 29418) { //Gerrit refspec return best; } break; } } catch (Exception e) { GerritToolsPlugin.getDefault().log(e); } return best; }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository push(final String name) throws GitWrapException { try {//from ww w . j av a 2s.co 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.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository setPushTarget(final String name, final String uri, final boolean heads, final boolean tags) throws GitWrapException { try {//w ww .j a v a 2 s . co m final RemoteConfig remote = new RemoteConfig(repository.getConfig(), name); final URIish uriish = new URIish(uri); final List<URIish> uris = remote.getURIs(); if (uris == null || !uris.contains(uriish)) { remote.addURI(uriish); } final List<URIish> pushURIs = remote.getPushURIs(); if (pushURIs == null || !pushURIs.contains(uriish)) { remote.addPushURI(uriish); } final List<RefSpec> pushRefSpecs = remote.getPushRefSpecs(); if (heads) { final RefSpec headSpec = new RefSpec("+" + Constants.R_HEADS + "*:" + Constants.R_HEADS + "*"); if (pushRefSpecs == null || !pushRefSpecs.contains(headSpec)) { remote.addPushRefSpec(headSpec); } } if (tags) { final RefSpec tagSpec = new RefSpec("+" + Constants.R_TAGS + "*:" + Constants.R_TAGS + "*"); if (pushRefSpecs == null || !pushRefSpecs.contains(tagSpec)) { remote.addPushRefSpec(tagSpec); } } remote.update(repository.getConfig()); repository.getConfig().save(); } catch (final URISyntaxException e) { throw new GitWrapException("Invalid URI-ish: %s. Nested error: %s", e, uri, e.getMessage()); } catch (final IOException e) { throw new GitWrapException("Failed to write Git config: %s", e, e.getMessage()); } return this; }
From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * Configure the pushURI for Gerrit//from w w w .j a v a2 s . c o m * * @param remoteConfig * the remote configuration to add this to * @param pushURI * the pushURI to configure */ public static void configurePushURI(RemoteConfig remoteConfig, URIish pushURI) { List<URIish> pushURIs = new ArrayList<URIish>(remoteConfig.getPushURIs()); for (URIish urIish : pushURIs) { remoteConfig.removePushURI(urIish); } remoteConfig.addPushURI(pushURI); }
From source file:org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.java
License:Open Source License
private String getTextForRemoteConfig(final RemoteConfig rc) { final StringBuilder sb = new StringBuilder(rc.getName()); sb.append(": "); //$NON-NLS-1$ boolean first = true; List<URIish> uris;/*w ww . j a v a 2 s.co m*/ if (selectionType == SelectionType.FETCH) uris = rc.getURIs(); else { uris = rc.getPushURIs(); // if no push URIs are defined, use fetch URIs instead if (uris.isEmpty()) uris = rc.getURIs(); } for (final URIish u : uris) { final String uString = u.toString(); if (first) first = false; else { sb.append(", "); //$NON-NLS-1$ if (sb.length() + uString.length() > REMOTE_CONFIG_TEXT_MAX_LENGTH) { sb.append("..."); //$NON-NLS-1$ break; } } sb.append(uString); } return sb.toString(); }
From source file:org.eclipse.egit.ui.internal.components.RepositorySelectionPage.java
License:Open Source License
private List<RemoteConfig> getUsableConfigs(final List<RemoteConfig> remotes) { if (remotes == null) return null; List<RemoteConfig> result = new ArrayList<RemoteConfig>(); for (RemoteConfig config : remotes) if ((sourceSelection && !config.getURIs().isEmpty() || !sourceSelection && (!config.getPushURIs().isEmpty() || !config.getURIs().isEmpty()))) result.add(config);//w ww. ja v a2 s . c o m if (!result.isEmpty()) return result; return null; }
From source file:org.eclipse.egit.ui.internal.components.RepositorySelectionPage.java
License:Open Source License
private String getTextForRemoteConfig(final RemoteConfig rc) { final StringBuilder sb = new StringBuilder(rc.getName()); sb.append(": "); //$NON-NLS-1$ boolean first = true; List<URIish> uris;// ww w .j a v a2 s. com if (sourceSelection) { uris = rc.getURIs(); } else { uris = rc.getPushURIs(); // if no push URIs are defined, use fetch URIs instead if (uris.isEmpty()) { uris = rc.getURIs(); } } for (final URIish u : uris) { final String uString = u.toString(); if (first) first = false; else { sb.append(", "); //$NON-NLS-1$ if (sb.length() + uString.length() > REMOTE_CONFIG_TEXT_MAX_LENGTH) { sb.append("..."); //$NON-NLS-1$ break; } } sb.append(uString); } return sb.toString(); }
From source file:org.eclipse.egit.ui.internal.fetch.FetchGerritChangePage.java
License:Open Source License
public void createControl(Composite parent) { Clipboard clipboard = new Clipboard(parent.getDisplay()); String clipText = (String) clipboard.getContents(TextTransfer.getInstance()); String defaultUri = null;/*w w w.j a va 2 s .c o m*/ String defaultCommand = null; String defaultChange = null; if (clipText != null) { final String pattern = "git fetch (\\w+:\\S+) (refs/changes/\\d+/\\d+/\\d+) && git (\\w+) FETCH_HEAD"; //$NON-NLS-1$ Matcher matcher = Pattern.compile(pattern).matcher(clipText); if (matcher.matches()) { defaultUri = matcher.group(1); defaultChange = matcher.group(2); defaultCommand = matcher.group(3); } } Composite main = new Composite(parent, SWT.NONE); main.setLayout(new GridLayout(2, false)); GridDataFactory.fillDefaults().grab(true, true).applyTo(main); new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_UriLabel); uriCombo = new Combo(main, SWT.DROP_DOWN); GridDataFactory.fillDefaults().grab(true, false).applyTo(uriCombo); uriCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { changeRefs = null; } }); new Label(main, SWT.NONE).setText(UIText.FetchGerritChangePage_ChangeLabel); refText = new Text(main, SWT.BORDER); if (defaultChange != null) refText.setText(defaultChange); GridDataFactory.fillDefaults().grab(true, false).applyTo(refText); addRefContentProposalToText(refText); Group checkoutGroup = new Group(main, SWT.SHADOW_ETCHED_IN); checkoutGroup.setLayout(new GridLayout(2, false)); GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(checkoutGroup); checkoutGroup.setText(UIText.FetchGerritChangePage_AfterFetchGroup); // radio: create local branch createBranch = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(createBranch); createBranch.setText(UIText.FetchGerritChangePage_LocalBranchRadio); createBranch.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); branchTextlabel = new Label(checkoutGroup, SWT.NONE); GridDataFactory.defaultsFor(branchTextlabel).exclude(false).applyTo(branchTextlabel); branchTextlabel.setText(UIText.FetchGerritChangePage_BranchNameText); branchText = new Text(checkoutGroup, SWT.SINGLE | SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).applyTo(branchText); branchText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { checkPage(); } }); // radio: create tag createTag = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(createTag); createTag.setText(UIText.FetchGerritChangePage_TagRadio); createTag.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); tagTextlabel = new Label(checkoutGroup, SWT.NONE); GridDataFactory.defaultsFor(tagTextlabel).exclude(true).applyTo(tagTextlabel); tagTextlabel.setText(UIText.FetchGerritChangePage_TagNameText); tagText = new Text(checkoutGroup, SWT.SINGLE | SWT.BORDER); GridDataFactory.fillDefaults().exclude(true).grab(true, false).applyTo(tagText); tagText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { checkPage(); } }); // radio: checkout FETCH_HEAD checkout = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(checkout); checkout.setText(UIText.FetchGerritChangePage_CheckoutRadio); checkout.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); // radio: don't checkout dontCheckout = new Button(checkoutGroup, SWT.RADIO); GridDataFactory.fillDefaults().span(2, 1).applyTo(checkout); dontCheckout.setText(UIText.FetchGerritChangePage_UpdateRadio); dontCheckout.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); if ("checkout".equals(defaultCommand)) //$NON-NLS-1$ checkout.setSelection(true); else createBranch.setSelection(true); warningAdditionalRefNotActive = new Composite(main, SWT.NONE); GridDataFactory.fillDefaults().span(2, 1).grab(true, false).exclude(true) .applyTo(warningAdditionalRefNotActive); warningAdditionalRefNotActive.setLayout(new GridLayout(2, false)); warningAdditionalRefNotActive.setVisible(false); activateAdditionalRefs = new Button(warningAdditionalRefNotActive, SWT.CHECK); activateAdditionalRefs.setText(UIText.FetchGerritChangePage_ActivateAdditionalRefsButton); activateAdditionalRefs.setToolTipText(UIText.FetchGerritChangePage_ActivateAdditionalRefsTooltip); refText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { Change change = Change.fromRef(refText.getText()); if (change != null) { branchText.setText(NLS.bind(UIText.FetchGerritChangePage_SuggestedRefNamePattern, change.getChangeNumber(), change.getPatchSetNumber())); tagText.setText(branchText.getText()); } else { branchText.setText(""); //$NON-NLS-1$ tagText.setText(""); //$NON-NLS-1$ } checkPage(); } }); // get all available URIs from the repository SortedSet<String> uris = new TreeSet<String>(); try { for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository.getConfig())) { if (rc.getURIs().size() > 0) uris.add(rc.getURIs().get(0).toPrivateString()); for (URIish u : rc.getPushURIs()) uris.add(u.toPrivateString()); } } catch (URISyntaxException e) { Activator.handleError(e.getMessage(), e, false); setErrorMessage(e.getMessage()); } for (String aUri : uris) uriCombo.add(aUri); if (defaultUri != null) uriCombo.setText(defaultUri); else selectLastUsedUri(); refText.setFocus(); Dialog.applyDialogFont(main); setControl(main); checkPage(); }