List of usage examples for org.eclipse.jgit.transport RefSpec setDestination
public RefSpec setDestination(String destination)
From source file:com.google.gerrit.server.git.PushReplication.java
License:Apache License
private List<ReplicationConfig> allConfigs(final SitePaths site) throws ConfigInvalidException, IOException { final FileBasedConfig cfg = new FileBasedConfig(site.replication_config, FS.DETECTED); if (!cfg.getFile().exists()) { log.warn("No " + cfg.getFile() + "; not replicating"); return Collections.emptyList(); }/*from w w w . j ava 2 s .co m*/ if (cfg.getFile().length() == 0) { log.info("Empty " + cfg.getFile() + "; not replicating"); return Collections.emptyList(); } try { cfg.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException("Config file " + cfg.getFile() + " is invalid: " + e.getMessage(), e); } catch (IOException e) { throw new IOException("Cannot read " + cfg.getFile() + ": " + e.getMessage(), e); } final List<ReplicationConfig> r = new ArrayList<ReplicationConfig>(); for (final RemoteConfig c : allRemotes(cfg)) { if (c.getURIs().isEmpty()) { continue; } for (final URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException("remote." + c.getName() + ".url" + " \"" + u + "\" lacks ${name} placeholder in " + cfg.getFile()); } } // In case if refspec destination for push is not set then we assume it is // equal to source for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { RefSpec spec = new RefSpec(); spec = spec.setSourceDestination("refs/*", "refs/*"); spec = spec.setForceUpdate(true); c.addPushRefSpec(spec); } r.add(new ReplicationConfig(injector, workQueue, c, cfg, database, replicationUserFactory)); } return Collections.unmodifiableList(r); }
From source file:com.googlesource.gerrit.plugins.github.replication.GitHubDestinations.java
License:Apache License
private List<Destination> getDestinations(File cfgPath) throws ConfigInvalidException, IOException { FileBasedConfig cfg = new FileBasedConfig(cfgPath, FS.DETECTED); if (!cfg.getFile().exists() || cfg.getFile().length() == 0) { return Collections.emptyList(); }//ww w .j a va 2s. c o m try { cfg.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException( String.format("Config file %s is invalid: %s", cfg.getFile(), e.getMessage()), e); } catch (IOException e) { throw new IOException(String.format("Cannot read %s: %s", cfg.getFile(), e.getMessage()), e); } ImmutableList.Builder<Destination> dest = ImmutableList.builder(); for (RemoteConfig c : allRemotes(cfg)) { if (c.getURIs().isEmpty()) { continue; } for (URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException(String.format( "remote.%s.url \"%s\" lacks ${name} placeholder in %s", c.getName(), u, cfg.getFile())); } } // If destination for push is not set assume equal to source. for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { c.addPushRefSpec(new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(true)); } dest.add(new Destination(injector, c, cfg, database, replicationUserFactory, pluginUser, gitRepositoryManager, groupBackend)); } return dest.build(); }
From source file:com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig.java
License:Apache License
private List<Destination> allDestinations() throws ConfigInvalidException, IOException { if (!config.getFile().exists()) { log.warn("Config file " + config.getFile() + " does not exist; not replicating"); return Collections.emptyList(); }//from w w w .ja v a 2 s . c om if (config.getFile().length() == 0) { log.info("Config file " + config.getFile() + " is empty; not replicating"); return Collections.emptyList(); } try { config.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException( String.format("Config file %s is invalid: %s", config.getFile(), e.getMessage()), e); } catch (IOException e) { throw new IOException(String.format("Cannot read %s: %s", config.getFile(), e.getMessage()), e); } replicateAllOnPluginStart = config.getBoolean("gerrit", "replicateOnStartup", true); defaultForceUpdate = config.getBoolean("gerrit", "defaultForceUpdate", false); ImmutableList.Builder<Destination> dest = ImmutableList.builder(); for (RemoteConfig c : allRemotes(config)) { if (c.getURIs().isEmpty()) { continue; } // If destination for push is not set assume equal to source. for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { c.addPushRefSpec( new RefSpec().setSourceDestination("refs/*", "refs/*").setForceUpdate(defaultForceUpdate)); } Destination destination = new Destination(injector, new DestinationConfiguration(c, config), replicationUserFactory, pluginUser, gitRepositoryManager, groupBackend, stateLog, groupIncludeCache); if (!destination.isSingleProjectMatch()) { for (URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException( String.format("remote.%s.url \"%s\" lacks ${name} placeholder in %s", c.getName(), u, config.getFile())); } } } dest.add(destination); } return dest.build(); }
From source file:org.eclipse.egit.ui.internal.push.RefSpecDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite main = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(main); main.setLayout(new GridLayout(2, false)); URIish uriToCheck;//from w w w. ja v a2s . c o m if (pushMode) { if (config.getPushURIs().isEmpty()) uriToCheck = config.getURIs().get(0); else uriToCheck = config.getPushURIs().get(0); } else uriToCheck = config.getURIs().get(0); final RefContentAssistProvider assistProvider = new RefContentAssistProvider(repo, uriToCheck, getShell()); // source Label sourceLabel = new Label(main, SWT.NONE); if (pushMode) sourceLabel.setText(UIText.RefSpecDialog_SourceBranchPushLabel); else sourceLabel.setText(UIText.RefSpecDialog_SourceBranchFetchLabel); sourceText = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sourceText); if (spec != null && spec.getSource() != null) sourceText.setText(spec.getSource()); sourceText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (sourceText.isFocusControl()) if (autoSuggestDestination) { String name = sourceText.getText(); if (name.startsWith(Constants.R_HEADS)) name = name.substring(Constants.R_HEADS.length()); else if (name.startsWith(Constants.R_TAGS)) name = name.substring(Constants.R_TAGS.length()); RefSpec sourceChanged = getSpec().setSource(sourceText.getText()); setSpec(sourceChanged.setDestination(Constants.R_REMOTES + config.getName() + '/' + name)); } else setSpec(getSpec().setSource(sourceText.getText())); } }); // content assist for source UIUtils.addRefContentProposalToText(sourceText, repo, new IRefListProvider() { public List<Ref> getRefList() { return assistProvider.getRefsForContentAssist(true, pushMode); } }); // suggest remote tracking branch if (!pushMode) { final Button autoSuggest = new Button(main, SWT.CHECK); GridDataFactory.fillDefaults().span(2, 1).applyTo(autoSuggest); autoSuggest.setText(UIText.RefSpecDialog_AutoSuggestCheckbox); autoSuggest.setSelection(true); autoSuggest.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { autoSuggestDestination = autoSuggest.getSelection(); } }); } // destination Label destinationLabel = new Label(main, SWT.NONE); if (pushMode) destinationLabel.setText(UIText.RefSpecDialog_DestinationPushLabel); else destinationLabel.setText(UIText.RefSpecDialog_DestinationFetchLabel); destinationText = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(destinationText); if (spec != null && spec.getDestination() != null) destinationText.setText(spec.getDestination()); destinationText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (destinationText.isFocusControl()) setSpec(getSpec().setDestination(destinationText.getText())); } }); // content assist for destination UIUtils.addRefContentProposalToText(destinationText, repo, new IRefListProvider() { public List<Ref> getRefList() { return assistProvider.getRefsForContentAssist(false, pushMode); } }); // force update forceButton = new Button(main, SWT.CHECK); forceButton.setText(UIText.RefSpecDialog_ForceUpdateCheckbox); GridDataFactory.fillDefaults().span(2, 1).applyTo(forceButton); if (spec != null) forceButton.setSelection(spec.isForceUpdate()); forceButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (getSpec().isForceUpdate() == forceButton.getSelection()) return; setSpec(getSpec().setForceUpdate(forceButton.getSelection())); } }); // RefSpec as String Label stringLabel = new Label(main, SWT.NONE); stringLabel.setText(UIText.RefSpecDialog_SpecificationLabel); specString = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(specString); if (spec != null) specString.setText(spec.toString()); specString.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (!specString.isFocusControl() || getSpec().toString().equals(specString.getText())) return; setSpec(new RefSpec(specString.getText())); } }); applyDialogFont(main); return main; }