Correct reference to EPL in source headers
[egit/chris.git] / org.eclipse.egit.core / src / org / eclipse / egit / core / op / ConnectProviderOperation.java
bloba8544184187dbb2242e78a5b40c3806153a21d29
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;
30 /**
31 * Connects Eclipse to an existing Git repository
33 public class ConnectProviderOperation implements IWorkspaceRunnable {
34 private final IProject[] projects;
36 /**
37 * Create a new connection operation to execute within the workspace.
39 * @param proj
40 * the project to connect to the Git team provider.
42 public ConnectProviderOperation(final IProject proj) {
43 this(new IProject[] { proj });
46 /**
47 * Create a new connection operation to execute within the workspace.
49 * @param projects
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 {
57 if (m == null) {
58 m = new NullProgressMonitor();
61 m.beginTask(CoreText.ConnectProviderOperation_connecting,
62 100 * projects.length);
63 try {
65 for (IProject project : projects) {
66 m.setTaskName(NLS.bind(
67 CoreText.ConnectProviderOperation_ConnectingProject,
68 project.getName()));
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);
74 try {
75 projectData.setRepositoryMappings(repos);
76 projectData.store();
77 } catch (CoreException ce) {
78 GitProjectData.delete(project);
79 throw ce;
80 } catch (RuntimeException ce) {
81 GitProjectData.delete(project);
82 throw ce;
84 RepositoryProvider
85 .map(project, GitProvider.class.getName());
86 projectData = GitProjectData.get(project);
87 project.refreshLocal(IResource.DEPTH_INFINITE,
88 new SubProgressMonitor(m, 50));
89 m.worked(10);
90 } else {
91 Activator
92 .trace("Attempted to share project without repository ignored :" //$NON-NLS-1$
93 + project);
94 m.worked(60);
97 } finally {
98 m.done();