1 /*******************************************************************************
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
3 * Copyright (C) 2008, Google Inc.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
10 package org
.eclipse
.egit
.core
.op
;
12 import java
.util
.Collection
;
14 import org
.eclipse
.core
.resources
.IProject
;
15 import org
.eclipse
.core
.resources
.IResource
;
16 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
17 import org
.eclipse
.core
.runtime
.CoreException
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
21 import org
.eclipse
.egit
.core
.Activator
;
22 import org
.eclipse
.egit
.core
.CoreText
;
23 import org
.eclipse
.egit
.core
.GitProvider
;
24 import org
.eclipse
.egit
.core
.project
.GitProjectData
;
25 import org
.eclipse
.egit
.core
.project
.RepositoryFinder
;
26 import org
.eclipse
.egit
.core
.project
.RepositoryMapping
;
27 import org
.eclipse
.osgi
.util
.NLS
;
28 import org
.eclipse
.team
.core
.RepositoryProvider
;
31 * Connects Eclipse to an existing Git repository
33 public class ConnectProviderOperation
implements IWorkspaceRunnable
{
34 private final IProject
[] projects
;
37 * Create a new connection operation to execute within the workspace.
40 * the project to connect to the Git team provider.
42 public ConnectProviderOperation(final IProject proj
) {
43 this(new IProject
[] { proj
});
47 * Create a new connection operation to execute within the workspace.
50 * the projects to connect to the Git team provider.
52 public ConnectProviderOperation(final IProject
[] projects
) {
53 this.projects
= projects
;
56 public void run(IProgressMonitor m
) throws CoreException
{
58 m
= new NullProgressMonitor();
61 m
.beginTask(CoreText
.ConnectProviderOperation_connecting
,
62 100 * projects
.length
);
65 for (IProject project
: projects
) {
66 m
.setTaskName(NLS
.bind(
67 CoreText
.ConnectProviderOperation_ConnectingProject
,
69 Activator
.trace("Locating repository for " + project
); //$NON-NLS-1$
70 Collection
<RepositoryMapping
> repos
= new RepositoryFinder(
71 project
).find(new SubProgressMonitor(m
, 40));
72 if (repos
.size() == 1) {
73 GitProjectData projectData
= new GitProjectData(project
);
75 projectData
.setRepositoryMappings(repos
);
77 } catch (CoreException ce
) {
78 GitProjectData
.delete(project
);
80 } catch (RuntimeException ce
) {
81 GitProjectData
.delete(project
);
85 .map(project
, GitProvider
.class.getName());
86 projectData
= GitProjectData
.get(project
);
87 project
.refreshLocal(IResource
.DEPTH_INFINITE
,
88 new SubProgressMonitor(m
, 50));
92 .trace("Attempted to share project without repository ignored :" //$NON-NLS-1$