1 /*******************************************************************************
2 * Copyright (c) 2010 SAP AG.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.fetch
;
13 import java
.io
.IOException
;
14 import java
.net
.URISyntaxException
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.core
.runtime
.jobs
.Job
;
20 import org
.eclipse
.egit
.core
.EclipseGitProgressTransformer
;
21 import org
.eclipse
.egit
.ui
.Activator
;
22 import org
.eclipse
.egit
.ui
.UIText
;
23 import org
.eclipse
.jface
.dialogs
.Dialog
;
24 import org
.eclipse
.jgit
.errors
.NotSupportedException
;
25 import org
.eclipse
.jgit
.errors
.TransportException
;
26 import org
.eclipse
.jgit
.lib
.Repository
;
27 import org
.eclipse
.jgit
.transport
.FetchResult
;
28 import org
.eclipse
.jgit
.transport
.RemoteConfig
;
29 import org
.eclipse
.jgit
.transport
.Transport
;
30 import org
.eclipse
.osgi
.util
.NLS
;
31 import org
.eclipse
.swt
.widgets
.Shell
;
32 import org
.eclipse
.ui
.PlatformUI
;
35 * Fetches from a remote as configured
37 public class FetchConfiguredRemoteAction
{
39 private final Repository repository
;
41 private final String remoteName
;
44 * The default constructor
47 * a {@link Repository}
49 * the name of a remote as configured for fetching
51 public FetchConfiguredRemoteAction(Repository repository
, String remoteName
) {
52 this.repository
= repository
;
53 this.remoteName
= remoteName
;
61 * a shell may be null; if provided, a pop up will be displayed
62 * indicating the fetch result; if Exceptions occur, these will
66 public void run(final Shell shell
) {
67 final RemoteConfig config
;
68 Exception prepareException
= null;
69 final Transport transport
;
71 config
= new RemoteConfig(repository
.getConfig(), remoteName
);
72 if (config
.getURIs().isEmpty()) {
73 throw new IOException(
75 UIText
.FetchConfiguredRemoteAction_NoUrisDefinedMessage
,
78 if (config
.getFetchRefSpecs().isEmpty()) {
79 throw new IOException(
81 UIText
.FetchConfiguredRemoteAction_NoSpecsDefinedMessage
,
84 transport
= Transport
.open(repository
, config
);
85 } catch (URISyntaxException e
) {
88 } catch (IOException e
) {
92 if (prepareException
!= null)
93 Activator
.handleError(prepareException
.getMessage(),
94 prepareException
, shell
!= null);
98 "Fetch from " + repository
.getDirectory().getParentFile().getName() + " - " + remoteName
) { //$NON-NLS-1$ //$NON-NLS-2$
101 protected IStatus
run(IProgressMonitor monitor
) {
102 final FetchResult result
;
103 Exception fetchException
= null;
105 result
= transport
.fetch(new EclipseGitProgressTransformer(
106 monitor
), config
.getFetchRefSpecs());
107 } catch (final NotSupportedException e
) {
109 return new Status(IStatus
.ERROR
, Activator
.getPluginId(),
110 UIText
.FetchWizard_fetchNotSupported
, e
);
111 } catch (final TransportException e
) {
112 if (monitor
.isCanceled())
113 return Status
.CANCEL_STATUS
;
115 return new Status(IStatus
.ERROR
, Activator
.getPluginId(),
116 UIText
.FetchWizard_transportError
, e
);
118 if (fetchException
!= null)
119 Activator
.handleError(fetchException
.getMessage(),
120 fetchException
, shell
!= null);
123 PlatformUI
.getWorkbench().getDisplay().asyncExec(
126 Dialog dialog
= new FetchResultDialog(
127 shell
, repository
, result
,
128 repository
.getDirectory()
129 .getParentFile().getName()
130 + " - " + remoteName
); //$NON-NLS-1$
135 return Status
.OK_STATUS
;