aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Bertacco2011-09-30 04:01:47 (EDT)
committerRenato Bertacco2011-09-30 04:01:47 (EDT)
commitd206ba60d2f0496fb381a65a871c7d218fa80258 (patch)
tree5030a4b6dc69c961173c4cbfa917e6791685e968
parentb3bcce3379c58527e562e5ad961b33e040d9c2c2 (diff)
downloadegit-d206ba60d2f0496fb381a65a871c7d218fa80258.zip
egit-d206ba60d2f0496fb381a65a871c7d218fa80258.tar.gz
egit-d206ba60d2f0496fb381a65a871c7d218fa80258.tar.bz2
Perform project creation within a workspace operation.refs/changes/08/4308/2
Originally, when using a GIT Team Project Set to setup a new workspace (which would eventually contain many projects) if auto-build was enabled, Eclipse would start building too early when the workspace is not yet complete, leading to annoying build errors. Now the execution within a workspace operation ensures that the build is not started before all projects are created/imported. Bug: 358530 Change-Id: Ic69e9cf01bf20dc567590370b5cbfc1ee3030631 Signed-off-by: Renato Bertacco <renato.bertacco@finantix.com>
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java176
1 files changed, 94 insertions, 82 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java
index 6719fd0..940db65 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/GitProjectSetCapability.java
@@ -29,6 +29,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -154,92 +155,103 @@ public final class GitProjectSetCapability extends ProjectSetCapability {
public IProject[] addToWorkspace(final String[] referenceStrings,
final ProjectSetSerializationContext context,
final IProgressMonitor monitor) throws TeamException {
- final Map<URIish, Map<String, Set<ProjectReference>>> repositories =
- new LinkedHashMap<URIish, Map<String, Set<ProjectReference>>>();
- for (final String reference : referenceStrings) {
- try {
- final ProjectReference projectReference = new ProjectReference(
- reference);
- Map<String, Set<ProjectReference>> repositoryBranches = repositories
- .get(projectReference.repository);
- if (repositoryBranches == null) {
- repositoryBranches = new HashMap<String, Set<ProjectReference>>();
- repositories.put(projectReference.repository,
- repositoryBranches);
- }
- Set<ProjectReference> projectReferences = repositoryBranches.get(projectReference.branch);
- if (projectReferences == null) {
- projectReferences = new TreeSet<ProjectReference>(new ProjectReferenceComparator());
- repositoryBranches.put(projectReference.branch, projectReferences);
- }
-
- projectReferences.add(projectReference);
- } catch (final IllegalArgumentException e) {
- throw new TeamException(reference, e);
- } catch (final URISyntaxException e) {
- throw new TeamException(reference, e);
- }
- }
final ArrayList<IProject> importedProjects = new ArrayList<IProject>();
- for (final Map.Entry<URIish, Map<String, Set<ProjectReference>>> entry : repositories.entrySet()) {
- final URIish gitUrl = entry.getKey();
- final Map<String, Set<ProjectReference>> branches = entry.getValue();
-
- for (final Map.Entry<String, Set<ProjectReference>> branchEntry : branches.entrySet()) {
- final String branch = branchEntry.getKey();
- final Set<ProjectReference> projects = branchEntry.getValue();
-
- try {
- final IPath workDir = getWorkingDir(gitUrl, branch,
- branches.keySet());
- if (workDir.toFile().exists()) {
- final Collection<String> projectNames = new LinkedList<String>();
- for (final ProjectReference projectReference : projects)
- projectNames.add(projectReference.projectDir);
- throw new TeamException(NLS.bind(
- CoreText.GitProjectSetCapability_CloneToExistingDirectory,
- new Object[] { workDir, projectNames, gitUrl }));
+
+ try{
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor wsOpMonitor) throws CoreException {
+ final Map<URIish, Map<String, Set<ProjectReference>>> repositories =
+ new LinkedHashMap<URIish, Map<String, Set<ProjectReference>>>();
+ for (final String reference : referenceStrings) {
+ try {
+ final ProjectReference projectReference = new ProjectReference(
+ reference);
+ Map<String, Set<ProjectReference>> repositoryBranches = repositories
+ .get(projectReference.repository);
+ if (repositoryBranches == null) {
+ repositoryBranches = new HashMap<String, Set<ProjectReference>>();
+ repositories.put(projectReference.repository,
+ repositoryBranches);
+ }
+ Set<ProjectReference> projectReferences = repositoryBranches.get(projectReference.branch);
+ if (projectReferences == null) {
+ projectReferences = new TreeSet<ProjectReference>(new ProjectReferenceComparator());
+ repositoryBranches.put(projectReference.branch, projectReferences);
+ }
+
+ projectReferences.add(projectReference);
+ } catch (final IllegalArgumentException e) {
+ throw new TeamException(reference, e);
+ } catch (final URISyntaxException e) {
+ throw new TeamException(reference, e);
+ }
}
+ for (final Map.Entry<URIish, Map<String, Set<ProjectReference>>> entry : repositories.entrySet()) {
+ final URIish gitUrl = entry.getKey();
+ final Map<String, Set<ProjectReference>> branches = entry.getValue();
- int timeout = 60;
- String refName = Constants.R_HEADS + branch;
- final CloneOperation cloneOperation = new CloneOperation(
- gitUrl, true, null, workDir.toFile(), refName,
- Constants.DEFAULT_REMOTE_NAME, timeout);
- cloneOperation.run(monitor);
-
- final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile();
-
- Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryPath);
-
- // import projects from the current repository to workspace
- final IWorkspace workspace = ResourcesPlugin.getWorkspace();
- final IWorkspaceRoot root = workspace.getRoot();
- for (final ProjectReference projectToImport : projects) {
- final IPath projectDir = workDir
- .append(projectToImport.projectDir);
- final IProjectDescription projectDescription = workspace
- .loadProjectDescription(projectDir
- .append(IProjectDescription.DESCRIPTION_FILE_NAME));
- final IProject project = root
- .getProject(projectDescription.getName());
- project.create(projectDescription, monitor);
- importedProjects.add(project);
-
- project.open(monitor);
- final ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(
- project, repositoryPath);
- connectProviderOperation.execute(monitor);
+ for (final Map.Entry<String, Set<ProjectReference>> branchEntry : branches.entrySet()) {
+ final String branch = branchEntry.getKey();
+ final Set<ProjectReference> projects = branchEntry.getValue();
+
+ try {
+ final IPath workDir = getWorkingDir(gitUrl, branch,
+ branches.keySet());
+ if (workDir.toFile().exists()) {
+ final Collection<String> projectNames = new LinkedList<String>();
+ for (final ProjectReference projectReference : projects)
+ projectNames.add(projectReference.projectDir);
+ throw new TeamException(NLS.bind(
+ CoreText.GitProjectSetCapability_CloneToExistingDirectory,
+ new Object[] { workDir, projectNames, gitUrl }));
+ }
+
+ int timeout = 60;
+ String refName = Constants.R_HEADS + branch;
+ final CloneOperation cloneOperation = new CloneOperation(
+ gitUrl, true, null, workDir.toFile(), refName,
+ Constants.DEFAULT_REMOTE_NAME, timeout);
+ cloneOperation.run(wsOpMonitor);
+
+ final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile();
+
+ Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryPath);
+
+ // import projects from the current repository to workspace
+ final IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IWorkspaceRoot root = workspace.getRoot();
+ for (final ProjectReference projectToImport : projects) {
+ final IPath projectDir = workDir
+ .append(projectToImport.projectDir);
+ final IProjectDescription projectDescription = workspace
+ .loadProjectDescription(projectDir
+ .append(IProjectDescription.DESCRIPTION_FILE_NAME));
+ final IProject project = root
+ .getProject(projectDescription.getName());
+ project.create(projectDescription, wsOpMonitor);
+ importedProjects.add(project);
+
+ project.open(wsOpMonitor);
+ final ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(
+ project, repositoryPath);
+ connectProviderOperation.execute(wsOpMonitor);
+ }
+ } catch (final InvocationTargetException e) {
+ throw TeamException.asTeamException(e);
+ } catch (final CoreException e) {
+ throw TeamException.asTeamException(e);
+ } catch (final InterruptedException e) {
+ // was canceled by user
+ importedProjects.clear();
+ }
+ }
}
- } catch (final InvocationTargetException e) {
- throw TeamException.asTeamException(e);
- } catch (final CoreException e) {
- throw TeamException.asTeamException(e);
- } catch (final InterruptedException e) {
- // was canceled by user
- return new IProject[0];
+
}
- }
+ }, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, monitor);
+ } catch (CoreException e) {
+ throw TeamException.asTeamException(e);
}
final IProject[] result = importedProjects
.toArray(new IProject[importedProjects.size()]);
@@ -265,4 +277,4 @@ public final class GitProjectSetCapability extends ProjectSetCapability {
return workDir;
}
-}
+} \ No newline at end of file