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 * See LICENSE for the full license text, also available.
8 *******************************************************************************/
9 package org
.spearce
.egit
.core
.op
;
11 import java
.util
.Collection
;
13 import org
.eclipse
.core
.resources
.IProject
;
14 import org
.eclipse
.core
.resources
.IResource
;
15 import org
.eclipse
.core
.resources
.IWorkspaceRunnable
;
16 import org
.eclipse
.core
.runtime
.CoreException
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
20 import org
.eclipse
.osgi
.util
.NLS
;
21 import org
.eclipse
.team
.core
.RepositoryProvider
;
22 import org
.spearce
.egit
.core
.Activator
;
23 import org
.spearce
.egit
.core
.CoreText
;
24 import org
.spearce
.egit
.core
.GitProvider
;
25 import org
.spearce
.egit
.core
.project
.GitProjectData
;
26 import org
.spearce
.egit
.core
.project
.RepositoryFinder
;
27 import org
.spearce
.egit
.core
.project
.RepositoryMapping
;
30 * Connects Eclipse to an existing Git repository
32 public class ConnectProviderOperation
implements IWorkspaceRunnable
{
33 private final IProject
[] projects
;
36 * Create a new connection operation to execute within the workspace.
39 * the project to connect to the Git team provider.
41 public ConnectProviderOperation(final IProject proj
) {
42 this(new IProject
[] { proj
});
46 * Create a new connection operation to execute within the workspace.
49 * the projects to connect to the Git team provider.
51 public ConnectProviderOperation(final IProject
[] projects
) {
52 this.projects
= projects
;
55 public void run(IProgressMonitor m
) throws CoreException
{
57 m
= new NullProgressMonitor();
60 m
.beginTask(CoreText
.ConnectProviderOperation_connecting
,
61 100 * projects
.length
);
64 for (IProject project
: projects
) {
65 m
.setTaskName(NLS
.bind(
66 CoreText
.ConnectProviderOperation_ConnectingProject
,
68 Activator
.trace("Locating repository for " + project
); //$NON-NLS-1$
69 Collection
<RepositoryMapping
> repos
= new RepositoryFinder(
70 project
).find(new SubProgressMonitor(m
, 40));
71 if (repos
.size() == 1) {
72 GitProjectData projectData
= new GitProjectData(project
);
74 projectData
.setRepositoryMappings(repos
);
76 } catch (CoreException ce
) {
77 GitProjectData
.delete(project
);
79 } catch (RuntimeException ce
) {
80 GitProjectData
.delete(project
);
84 .map(project
, GitProvider
.class.getName());
85 projectData
= GitProjectData
.get(project
);
86 project
.refreshLocal(IResource
.DEPTH_INFINITE
,
87 new SubProgressMonitor(m
, 50));
91 .trace("Attempted to share project without repository ignored :" //$NON-NLS-1$