diff options
author | Mathias Kinzler | 2011-02-02 08:53:21 +0000 |
---|---|---|
committer | Chris Aniszczyk | 2011-02-02 15:24:07 +0000 |
commit | c5148168b9d0ac1e8163e133a8aaf81528bc1bd9 (patch) | |
tree | efac1b04c6412637f0aa2eb218aba76923d76cf4 | |
parent | 42bca4063c27acde74e047c534a9bb1c8a82d80f (diff) | |
download | egit-c5148168b9d0ac1e8163e133a8aaf81528bc1bd9.tar.gz egit-c5148168b9d0ac1e8163e133a8aaf81528bc1bd9.tar.xz egit-c5148168b9d0ac1e8163e133a8aaf81528bc1bd9.zip |
Simplify Fetch and Push first part: Refactor fetch and push operations
These operation are refactored for later use for the simple fetch and
push actions. A FetchOperationResult is introduced similar to the
PushOperationResult in order to be able to handle TransportExceptions
similarly to the push use case.
Change-Id: If09dda6bd14cc6146d33e9ceb75b4ff574b836fd
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
12 files changed, 164 insertions, 111 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/FetchOperationResult.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/FetchOperationResult.java new file mode 100644 index 0000000000..a5f5e5b078 --- /dev/null +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/FetchOperationResult.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.core.op; + +import org.eclipse.jgit.transport.FetchResult; +import org.eclipse.jgit.transport.URIish; + +/** + * Stores the result of a fetch operation + */ +public class FetchOperationResult { + private final URIish uri; + + private final FetchResult fetchResult; + + private final String fetchErrorMessage; + + /** + * @param uri + * @param result + */ + public FetchOperationResult(URIish uri, FetchResult result) { + this.uri = uri; + this.fetchResult = result; + this.fetchErrorMessage = null; + } + + /** + * @param uri + * @param errorMessage + */ + public FetchOperationResult(URIish uri, String errorMessage) { + this.uri = uri; + this.fetchResult = null; + this.fetchErrorMessage = errorMessage; + } + + /** + * @return the URI + * + */ + public URIish getURI() { + return uri; + } + + /** + * @return the result + */ + public FetchResult getFetchResult() { + return fetchResult; + } + + /** + * @return the error message + */ + public String getErrorMessage() { + return fetchErrorMessage; + } +} diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperationResult.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperationResult.java index 037d708f36..4caa0c6155 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperationResult.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperationResult.java @@ -36,7 +36,7 @@ public class PushOperationResult { /** * Construct empty push operation result. */ - PushOperationResult() { + public PushOperationResult() { this.urisEntries = new LinkedHashMap<URIish, Entry>(); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index 54fc6229c9..c92e7a5cf1 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -1853,12 +1853,6 @@ public class UIText extends NLS { public static String FetchAction_wrongURIMessage; /** */ - public static String FetchConfiguredRemoteAction_NoSpecsDefinedMessage; - - /** */ - public static String FetchConfiguredRemoteAction_NoUrisDefinedMessage; - - /** */ public static String FetchOperationUI_FetchJobName; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPage.java index b8f1296681..8a6e2de83f 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPage.java @@ -69,8 +69,6 @@ public class RefSpecPage extends WizardPage { private String transportError; - private String configName; - private UserPasswordCredentials credentials; private String helpContext = null; @@ -155,15 +153,6 @@ public class RefSpecPage extends WizardPage { } /** - * Special mode: the configuration is determined by the wizard - * - * @param configName - */ - public void setConfigName(String configName) { - this.configName = configName; - } - - /** * @return ref specifications as selected by user. Returned collection is a * copy, so it may be modified by caller. */ @@ -279,19 +268,14 @@ public class RefSpecPage extends WizardPage { } this.validatedRepoSelection = newRepoSelection; - final String actRemoteName; - if (configName == null) - actRemoteName = validatedRepoSelection.getConfigName(); - else - actRemoteName = configName; specsPanel.setAssistanceData(local, listRemotesOp.getRemoteRefs(), - actRemoteName); + currentRepoSelection.getConfig()); if (newRepoSelection.isConfigSelected()) { saveButton.setVisible(true); saveButton.setText(NLS.bind(UIText.RefSpecPage_saveSpecifications, - actRemoteName)); + currentRepoSelection.getConfigName())); saveButton.getParent().layout(); if (!pushPage) { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java index ac87613de8..fd137420ff 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RefSpecPanel.java @@ -9,7 +9,6 @@ package org.eclipse.egit.ui.internal.components; import java.io.IOException; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -23,12 +22,9 @@ import java.util.Set; import java.util.TreeSet; import java.util.regex.Pattern; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIIcons; import org.eclipse.egit.ui.UIText; -import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.fieldassist.ComboContentAdapter; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.jface.fieldassist.ControlDecoration; @@ -50,6 +46,14 @@ import org.eclipse.jface.viewers.IElementComparer; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.FetchConnection; +import org.eclipse.jgit.transport.RefSpec; +import org.eclipse.jgit.transport.RemoteConfig; +import org.eclipse.jgit.transport.Transport; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -75,14 +79,6 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.transport.FetchConnection; -import org.eclipse.jgit.transport.RefSpec; -import org.eclipse.jgit.transport.RemoteConfig; -import org.eclipse.jgit.transport.Transport; /** * This class provides universal panel for editing list of {@link RefSpec} - @@ -262,7 +258,7 @@ public class RefSpecPanel { private Repository localDb; - private String remoteName; + private RemoteConfig remoteConfig; private Set<String> localRefNames = Collections.emptySet(); @@ -307,7 +303,7 @@ public class RefSpecPanel { * <p> * Panel is created with an empty model, with no provided assistant. It * can't be used by user until - * {@link #setAssistanceData(Repository, Collection, String)} method is + * {@link #setAssistanceData(Repository, Collection, RemoteConfig)} method is * called, and to this time is disabled. * * @param parent @@ -361,17 +357,12 @@ public class RefSpecPanel { * collection of remote refs as advertised by remote repository. * Typically they are collected by {@link FetchConnection} * implementation. - * @param remoteName - * optional name for remote configuration, if edited - * specification list is related to this remote configuration. - * Can be null. When not null, panel is filled with default - * fetch/push specifications for this remote configuration. + * @param config */ public void setAssistanceData(final Repository localRepo, - final Collection<Ref> remoteRefs, final String remoteName) { + final Collection<Ref> remoteRefs, RemoteConfig config) { this.localDb = localRepo; - this.remoteName = remoteName; - + this.remoteConfig = config; final List<RefContentProposal> remoteProposals = createContentProposals( remoteRefs, null); remoteProposalProvider.setProposals(remoteProposals); @@ -409,36 +400,26 @@ public class RefSpecPanel { validateDeleteCreationPanel(); } - try { - if (remoteName == null) - predefinedConfigured = Collections.emptyList(); - else { - final RemoteConfig rc = new RemoteConfig(localDb.getConfig(), - remoteName); - if (pushSpecs) - predefinedConfigured = rc.getPushRefSpecs(); - else - predefinedConfigured = rc.getFetchRefSpecs(); - for (final RefSpec spec : predefinedConfigured) - addRefSpec(spec); - } - } catch (URISyntaxException e) { - predefinedConfigured = null; - ErrorDialog.openError(panel.getShell(), - UIText.RefSpecPanel_errorRemoteConfigTitle, - UIText.RefSpecPanel_errorRemoteConfigDescription, - new Status(IStatus.ERROR, Activator.getPluginId(), 0, e - .getMessage(), e)); + if (remoteConfig == null) + predefinedConfigured = Collections.emptyList(); + else { + if (pushSpecs) + predefinedConfigured = remoteConfig.getPushRefSpecs(); + else + predefinedConfigured = remoteConfig.getFetchRefSpecs(); + for (final RefSpec spec : predefinedConfigured) + addRefSpec(spec); } + updateAddPredefinedButton(addConfiguredButton, predefinedConfigured); if (pushSpecs) predefinedBranches = Transport.REFSPEC_PUSH_ALL; else { final String r; - if (remoteName == null) + if (remoteConfig == null) r = UIText.RefSpecPanel_refChooseRemoteName; else - r = remoteName; + r = remoteConfig.getName(); predefinedBranches = new RefSpec("refs/heads/*:refs/remotes/" //$NON-NLS-1$ + r + "/*"); //$NON-NLS-1$ } @@ -1387,8 +1368,8 @@ public class RefSpecPanel { return; } } - if (remoteName != null && src.startsWith(Constants.R_HEADS)) { - final String newDst = Constants.R_REMOTES + remoteName + '/' + if (remoteConfig != null && src.startsWith(Constants.R_HEADS)) { + final String newDst = Constants.R_REMOTES + remoteConfig + '/' + src.substring(Constants.R_HEADS.length()); creationDstCombo.setText(newDst); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultDialog.java index 03902d9c57..c6423ecf8a 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultDialog.java @@ -8,9 +8,9 @@ *******************************************************************************/ package org.eclipse.egit.ui.internal.fetch; +import org.eclipse.egit.core.op.FetchOperationResult; import org.eclipse.egit.ui.UIText; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.FetchResult; import org.eclipse.osgi.util.NLS; @@ -18,21 +18,35 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; /** * Dialog displaying result of fetch operation. */ -public class FetchResultDialog extends Dialog { +public class FetchResultDialog extends TitleAreaDialog { private final Repository localDb; - private final FetchResult result; + private final FetchOperationResult result; private final String sourceString; /** + * @param parentShell + * @param localDb + * @param result + * @param sourceString + */ + public FetchResultDialog(final Shell parentShell, final Repository localDb, + final FetchOperationResult result, final String sourceString) { + super(parentShell); + setShellStyle(getShellStyle() | SWT.RESIZE); + this.localDb = localDb; + this.result = result; + this.sourceString = sourceString; + } + + /** * Shows this dialog asynchronously * * @param repository @@ -67,33 +81,28 @@ public class FetchResultDialog extends Dialog { super(parentShell); setShellStyle(getShellStyle() | SWT.RESIZE); this.localDb = localDb; - this.result = result; + this.result = new FetchOperationResult(result.getURI(), result); this.sourceString = sourceString; } @Override - protected void createButtonsForButtonBar(final Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, - true); - } - - @Override public Control createDialogArea(final Composite parent) { final Composite composite = (Composite) super.createDialogArea(parent); - final Label label = new Label(composite, SWT.NONE); - final String text; - if (!result.getTrackingRefUpdates().isEmpty()) - text = NLS.bind(UIText.FetchResultDialog_labelNonEmptyResult, - sourceString); - else - text = NLS.bind(UIText.FetchResultDialog_labelEmptyResult, - sourceString); - label.setText(text); - label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + setTitle(NLS.bind(UIText.FetchResultDialog_labelNonEmptyResult, + sourceString)); + + if (result.getErrorMessage() != null) + setErrorMessage(result.getErrorMessage()); + else if (result.getFetchResult() != null + && result.getFetchResult().getTrackingRefUpdates().isEmpty()) { + setMessage(NLS.bind(UIText.FetchResultDialog_labelEmptyResult, + sourceString)); + } final FetchResultTable table = new FetchResultTable(composite); - table.setData(localDb, result); + if (result.getFetchResult() != null) + table.setData(localDb, result.getFetchResult()); final Control tableControl = table.getControl(); final GridData tableLayout = new GridData(SWT.FILL, SWT.FILL, true, true); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/job/JobUtil.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/job/JobUtil.java index 5ea96d2c66..7ff18ee919 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/job/JobUtil.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/job/JobUtil.java @@ -12,9 +12,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeListener; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.egit.core.op.IEGitOperation; -import org.eclipse.egit.ui.Activator; /** * Utility class for scheduling jobs @@ -30,14 +30,26 @@ public class JobUtil { */ public static void scheduleUserJob(final IEGitOperation op, String jobName, final Object jobFamily) { + scheduleUserJob(op, jobName, jobFamily, null); + } + + /** + * Schedule a user job that executes an EGit operation + * + * @param op + * @param jobName + * @param jobFamily + * @param jobChangeListener + */ + public static void scheduleUserJob(final IEGitOperation op, String jobName, + final Object jobFamily, IJobChangeListener jobChangeListener) { Job job = new Job(jobName) { @Override protected IStatus run(IProgressMonitor monitor) { try { op.execute(monitor); } catch (CoreException e) { - return Activator.createErrorStatus(e.getStatus() - .getMessage(), e); + return e.getStatus(); } return Status.OK_STATUS; } @@ -51,6 +63,8 @@ public class JobUtil { }; job.setRule(op.getSchedulingRule()); job.setUser(true); + if (jobChangeListener != null) + job.addJobChangeListener(jobChangeListener); job.schedule(); } } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushConfiguredRemoteAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushConfiguredRemoteAction.java index 8ebd278e21..7ab05bd42a 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushConfiguredRemoteAction.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushConfiguredRemoteAction.java @@ -142,7 +142,6 @@ public class PushConfiguredRemoteAction { } - }; job.setUser(true); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/ConfigureRemoteWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/ConfigureRemoteWizard.java index 1fc004f97f..f83010c5d5 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/ConfigureRemoteWizard.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/ConfigureRemoteWizard.java @@ -67,7 +67,6 @@ public class ConfigureRemoteWizard extends Wizard { configureFetchUriPage.getUri() .toPrivateString()); monitor.beginTask(taskName, IProgressMonitor.UNKNOWN); - configureFetchSpecPage.setConfigName(myRemoteName); configureFetchSpecPage .setSelection(new RepositorySelection( configureFetchUriPage.getUri(), null)); @@ -97,7 +96,6 @@ public class ConfigureRemoteWizard extends Wizard { .toPrivateString()); monitor.beginTask(taskName, IProgressMonitor.UNKNOWN); // use the first URI - configurePushSpecPage.setConfigName(myRemoteName); configurePushSpecPage .setSelection(new RepositorySelection( configurePushUriPage.getAllUris() diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java index 63420ef89f..26d84b1640 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/FetchConfiguredRemoteCommand.java @@ -29,16 +29,18 @@ public class FetchConfiguredRemoteCommand extends public Object execute(ExecutionEvent event) throws ExecutionException { FetchNode node = getSelectedNodes(event).get(0); RemoteNode remote = (RemoteNode) node.getParent(); + + RemoteConfig config; try { - RemoteConfig config = new RemoteConfig(node.getRepository() - .getConfig(), remote.getObject()); - int timeout = Activator.getDefault().getPreferenceStore().getInt( - UIPreferences.REMOTE_CONNECTION_TIMEOUT); - new FetchOperationUI(node.getRepository(), config, timeout, false) - .start(); + config = new RemoteConfig(node.getRepository().getConfig(), remote + .getObject()); } catch (URISyntaxException e) { - throw new ExecutionException(e.getMessage(), e); + throw new ExecutionException(e.getMessage()); } + new FetchOperationUI(node.getRepository(), config, Activator + .getDefault().getPreferenceStore().getInt( + UIPreferences.REMOTE_CONNECTION_TIMEOUT), false) + .start(); return null; } } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java index 799a07aee8..edf79ae628 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/PushConfiguredRemoteCommand.java @@ -10,11 +10,14 @@ *******************************************************************************/ package org.eclipse.egit.ui.internal.repository.tree.command; +import java.net.URISyntaxException; + import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.egit.ui.internal.push.PushConfiguredRemoteAction; import org.eclipse.egit.ui.internal.repository.tree.PushNode; import org.eclipse.egit.ui.internal.repository.tree.RemoteNode; +import org.eclipse.jgit.transport.RemoteConfig; /** * Pushes to the remote @@ -24,8 +27,14 @@ public class PushConfiguredRemoteCommand extends public Object execute(ExecutionEvent event) throws ExecutionException { PushNode node = getSelectedNodes(event).get(0); RemoteNode remote = (RemoteNode) node.getParent(); - - new PushConfiguredRemoteAction(node.getRepository(), remote.getObject()) + RemoteConfig config; + try { + config = new RemoteConfig(node.getRepository().getConfig(), remote + .getObject()); + } catch (URISyntaxException e) { + throw new ExecutionException(e.getMessage()); + } + new PushConfiguredRemoteAction(node.getRepository(), config.getName()) .run(getShell(event), false); return null; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 5ca648a988..fc79d32061 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -609,8 +609,6 @@ ResultDialog_label=Pushed to {0} FetchAction_wrongURITitle=Corrupted Configuration FetchAction_wrongURIMessage=Remote repositories URIs configuration is corrupted. -FetchConfiguredRemoteAction_NoSpecsDefinedMessage=No Fetch specs defined for remote {0} -FetchConfiguredRemoteAction_NoUrisDefinedMessage=No Fetch URIs defined for remote {0} FetchOperationUI_FetchJobName=Fetch from {0} FetchResultDialog_labelEmptyResult=No ref to fetch from {0} - everything up to date. |