Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-04-01 01:58:18 +0000
committerMichael Valenta2004-04-01 01:58:18 +0000
commit7d5f3dcffb9d1dcbaaa756b6e3447fe2803d5758 (patch)
treeda52c45625cdfe6c58e2ec92ce0c660e82435670
parenta70ec46d73983adec242df11e155092eafeabd15 (diff)
downloadeclipse.platform.team-7d5f3dcffb9d1dcbaaa756b6e3447fe2803d5758.tar.gz
eclipse.platform.team-7d5f3dcffb9d1dcbaaa756b6e3447fe2803d5758.tar.xz
eclipse.platform.team-7d5f3dcffb9d1dcbaaa756b6e3447fe2803d5758.zip
Initial release of project set capability repalcement for serializer
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java4
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java198
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetSerializationContext.java57
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java31
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java5
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultProjectSetCapability.java75
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java516
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProviderType.java8
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSWorkspaceRoot.java262
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSProjectSetSerializer.java23
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java191
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java30
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties4
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java11
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java35
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/UIProjectSetSerializationContext.java108
16 files changed, 1062 insertions, 496 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java
index f088238db..a9f49ab31 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java
@@ -20,6 +20,10 @@ import org.eclipse.core.runtime.IProgressMonitor;
* Given this String, it can create in the workspace an IProject.
*
* @since 2.0
+ *
+ * @deprecated
+ * Use {@link org.eclipse.team.core.RepositoryProviderType#getProjectSetSerializer()}
+ * to obtain an instance of {@link org.eclipse.team.core.ProjectSetSerializer} instead.
*/
public interface IProjectSetSerializer {
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java
index b8a66559e..4848d2652 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetCapability.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,40 +7,212 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Dan Rubel - project set serializer API
*******************************************************************************/
package org.eclipse.team.core;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
/**
- * This class represents provisional API. A provider is not required to
- * implement this API. Implementers, and those who reference it, do so with the
- * awareness that this class may be removed or substantially changed at future
- * times without warning.
- * <p>
- * The intention is that this class will eventually replace <code>IProjectSetSerializer</code>.
- * At the current time it only complements this API by providing a notification
- * mechanism for informing repository providers when a project set has been
- * created.
+ * An object for serializing and deserializing
+ * references to projects. Given a project, it can produce a
+ * UTF-8 encoded String which can be stored in a file.
+ * Given this String, it can load a project into the workspace.
+ * It also provides a mechanism
+ * by which repository providers can be notified when a project set is created and exported.
*
- * @see IProjectSetSerializer
* @see RepositoryProviderType
*
* @since 2.1
*/
public abstract class ProjectSetCapability {
+
/**
* Notify the provider that a project set has been created at path. Only
* providers identified as having projects in the project set will be
* notified. The project set may or may not be created in a workspace
* project (thus may not be a resource).
*
- * @param File
- * the project set file that was created
+ * @param file the project set file that was created
+ * @param context a UI context object. This object will either be a
+ * com.ibm.swt.widgets.Shell or it will be null.
+ * @param monitor a progress monitor
+ *
+ * @deprecated should use or override
+ * projectSetCreated(File, ProjectSetSerializationContext, IProgressMonitor)
+ * instead
*/
public void projectSetCreated(File file, Object context, IProgressMonitor monitor) {
//default is to do nothing
}
+
+ /**
+ * Notify the provider that a project set has been created at path. Only
+ * providers identified as having projects in the project set will be
+ * notified. The project set may or may not be created in a workspace
+ * project (thus may not be a resource).
+ *
+ * @param file the project set file that was created
+ * @param context
+ * the context in which the references are created
+ * (not <code>null</code>)
+ * @param monitor a progress monitor
+ */
+ public void projectSetCreated(File file, ProjectSetSerializationContext context, IProgressMonitor monitor) {
+ // Invoke old method by default
+ projectSetCreated(file, context.getShell(), monitor);
+ }
+
+ /**
+ * For every project in providerProjects, return an opaque
+ * UTF-8 encoded String to act as a reference to that project.
+ * The format of the String is specific to the provider.
+ * The format of the String must be such that
+ * {@link #addToWorkspace(String[], ProjectSetSerializationContext, IProgressMonitor)}
+ * will be able to consume it and load the corresponding project.
+ * <p>
+ * This default implementation simply throws an exception
+ * indicating that no references can be created.
+ * Subclasses are expected to override.
+ *
+ * @since 3.0
+ *
+ * @param providerProjects
+ * an array of projects for which references are needed
+ * (not <code>null</code> and contains no <code>null</code>s)
+ * @param context
+ * the context in which the references are created
+ * (not <code>null</code>)
+ * @param monitor
+ * a progress monitor or <code>null</code> if none
+ * @return
+ * an array containing exactly the same number of elements
+ * as the providerProjects argument
+ * where each element is a serialized reference string
+ * uniquely identifying the corresponding the project in the providerProjects array
+ * (not <code>null</code> and contains no <code>null</code>s)
+ * @throws TeamException
+ * thrown if there is a reference string cannot be created for a project
+ */
+ public String[] asReference(
+ IProject[] providerProjects,
+ ProjectSetSerializationContext context,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ throw new TeamException("Failed to create project references");
+ }
+
+ /**
+ * For every String in referenceStrings, load the corresponding project into the workspace.
+ * The opaque strings in referenceStrings are guaranteed to have been previously
+ * produced by {@link #asReference(IProject[], ProjectSetSerializationContext, IProgressMonitor)}.
+ * The confirmOverwrite method is called with an array of projects
+ * for which projects of the same name already exists in the workspace.
+ * <p>
+ * Callers from within a UI context should wrapper a call to this method
+ * inside a WorkspaceModifyOperation so that events generated as a result
+ * of this operation are deferred until the outermost operation
+ * has successfully completed.
+ * <p>
+ * This default implementation simply throws an exception
+ * indicating that no projects can be loaded.
+ * Subclasses are expected to override.
+ *
+ * @since 3.0
+ *
+ * @param referenceStrings
+ * an array of referene strings uniquely identifying the projects
+ * (not <code>null</code> and contains no <code>null</code>s)
+ * @param context
+ * the context in which the projects are loaded
+ * (not <code>null</code>)
+ * @param monitor
+ * a progress monitor or <code>null</code> if none
+ * @return IProject[]
+ * an array of projects that were loaded
+ * excluding those projects already existing and not overwritten
+ * (not <code>null</code>, contains no <code>null</code>s)
+ * @throws TeamException
+ * thrown if there is a problem loading a project into the workspace.
+ * If an exception is thrown, then the workspace is left in an unspecified state
+ * where some of the referenced projects may be loaded or partially loaded, and others may not.
+ */
+ public IProject[] addToWorkspace(
+ String[] referenceStrings,
+ ProjectSetSerializationContext context,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ throw new TeamException("Failed to load projects");
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Internal utility methods for subclasses
+ //
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Determine if any of the projects already exist
+ * and confirm which of those projects are to be overwritten.
+ *
+ * @since 3.0
+ *
+ * @param context
+ * the context in which the projects are loaded
+ * (not <code>null</code>)
+ * @param projects
+ * an array of proposed projects to be loaded
+ * (not <code>null</code>, contains no <code>null</code>s)
+ * @return
+ * an array of confirmed projects to be loaded
+ * or <code>null</code> if the operation is to be canceled.
+ * @throws TeamException
+ */
+ protected IProject[] confirmOverwrite(
+ ProjectSetSerializationContext context,
+ IProject[] projects)
+ throws TeamException {
+
+ // Build a collection of existing projects
+
+ final Collection existingProjects = new ArrayList();
+ for (int i = 0; i < projects.length; i++) {
+ IProject eachProj = projects[i];
+ if (eachProj.exists())
+ existingProjects.add(eachProj);
+ }
+ if (existingProjects.size() == 0)
+ return projects;
+
+ // Confirm the overwrite
+
+ IProject[] confirmed =
+ context.confirmOverwrite(
+ (IProject[]) existingProjects.toArray(
+ new IProject[existingProjects.size()]));
+ if (confirmed == null)
+ return null;
+ if (existingProjects.size() == confirmed.length)
+ return projects;
+
+ // Return the amended list of projects to be loaded
+
+ Collection result = new ArrayList(projects.length);
+ result.addAll(Arrays.asList(projects));
+ result.removeAll(existingProjects);
+ for (int i = 0; i < confirmed.length; i++) {
+ IProject eachProj = confirmed[i];
+ if (existingProjects.contains(eachProj))
+ result.add(eachProj);
+ }
+ return (IProject[]) result.toArray(new IProject[result.size()]);
+ }
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetSerializationContext.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetSerializationContext.java
new file mode 100644
index 000000000..c4aacb510
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/ProjectSetSerializationContext.java
@@ -0,0 +1,57 @@
+/**********************************************************************
+ Copyright (c) 2004 Dan Rubel and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Common Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/cpl-v10.html
+
+ Contributors:
+
+ Dan Rubel - initial API and implementation
+
+ **********************************************************************/
+
+package org.eclipse.team.core;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * The context in which project serialization occurs.
+ * The class may be subclasses to represent different serialization contexts.
+ *
+ * @since 3.0
+ */
+public class ProjectSetSerializationContext {
+
+ /**
+ * Given an array of projects that currently exist in the workspace
+ * determine which of those projects should be overwritten.
+ * <p>
+ * This default implementation always returns an empty array
+ * indicating that no existing projects should be overwritten.
+ * Subclasses may override this as appropriate.
+ *
+ * @param projects
+ * an array of projects currently existing in the workspace
+ * that are desired to be overwritten.
+ * (not <code>null</code>, contains no <code>null</code>s)
+ * @return
+ * an array of zero or more projects that should be overwritten
+ * or <code>null</code> if the operation is to be canceled
+ */
+ public IProject[] confirmOverwrite(IProject[] projects) throws TeamException {
+ return new IProject[0];
+ }
+
+ /**
+ * Return a {@link org.eclipse.swt.Shell} if there is a UI context
+ * or <code>null</code> if executing headless.
+ *
+ * @return the shell or <code>null</code>
+ */
+ public Object getShell() {
+ return null;
+ }
+
+}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java
index cb3afd176..b2c105060 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java
@@ -18,6 +18,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.team.internal.core.DefaultProjectSetCapability;
import org.eclipse.team.internal.core.Policy;
import org.eclipse.team.internal.core.TeamPlugin;
@@ -141,19 +142,33 @@ public abstract class RepositoryProviderType {
}
/**
- * Answers the ProjectSetCapability that is intended to implement methods to import and
- * create project sets. If the provider doesn't wish to provide this
+ * Answers an object for serializing and deserializing
+ * of references to projects. Given a project, it can produce a
+ * UTF-8 encoded String which can be stored in a file.
+ * Given this String, it can load a project into the workspace.
+ * It also provides a mechanism
+ * by which repository providers can be notified when a project set is created and exported.
+ * If the provider doesn't wish to provide this
* feature, return null.
* <p>
- * Note that at the current time, the <code>IProjectSetSerializer</code> is still used to import
- * and export project sets. The <code>ProjectSetCapability</code> only provides a mechanism
- * by which repository providers can be notified when a project set is created and exported.
- * In the future, it is intended that IProjectSetSerializer be replaced by <code>IProjectSetSerializer</code>.
+ * Subclasses should override this method to return the appropriate
+ * serializer for the associated repository type.
+ * It is recommended that serializers not have any references to UI classes
+ * so that they can be used in a headless environment.
+ * <p>
+ * At this time, the default implementation wrappers the <code>IProjectSetSerializer</code>
+ * interface if one exists, providing backward compatibility with existing code.
+ * At some time in the future, the <code>IProjectSetSerializer</code> interface will be removed
+ * and the default implementation will revert to having limited functionality.
*
- * @return ProjectSetCapability
+ * @return the project set serializer (or <code>null</code>)
*/
-
public ProjectSetCapability getProjectSetCapability() {
+ // Provide backward compatibility with the old IProjectSetSerializer interface
+ IProjectSetSerializer oldSerializer = Team.getProjectSetSerializer(getID());
+ if (oldSerializer != null)
+ return new DefaultProjectSetCapability(oldSerializer);
+
return null;
}
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java
index bed18e50b..10ac6efcf 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java
@@ -510,6 +510,11 @@ public final class Team {
public static void shutdown() {
TeamPlugin.getPlugin().savePluginPreferences();
}
+ /**
+ * @deprecated
+ * Use {@link org.eclipse.team.core.RepositoryProviderType#getProjectSetSerializer()}
+ * to obtain an instance of {@link org.eclipse.team.core.ProjectSetSerializer} instead.
+ */
public static IProjectSetSerializer getProjectSetSerializer(String id) {
TeamPlugin plugin = TeamPlugin.getPlugin();
if (plugin != null) {
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultProjectSetCapability.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultProjectSetCapability.java
new file mode 100644
index 000000000..61344f077
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultProjectSetCapability.java
@@ -0,0 +1,75 @@
+/**********************************************************************
+ Copyright (c) 2004 Dan Rubel and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Common Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/cpl-v10.html
+
+ Contributors:
+
+ Dan Rubel - initial API and implementation
+
+ **********************************************************************/
+
+package org.eclipse.team.internal.core;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.IProjectSetSerializer;
+import org.eclipse.team.core.ProjectSetCapability;
+import org.eclipse.team.core.ProjectSetSerializationContext;
+import org.eclipse.team.core.TeamException;
+
+/**
+ * An internal class for backward compatibility with the
+ * {@link org.eclipse.team.core.IProjectSetSerializer} interface.
+ *
+ * @since 3.0
+ */
+public class DefaultProjectSetCapability extends ProjectSetCapability {
+
+ /**
+ * The old serialization interface
+ */
+ private IProjectSetSerializer serializer;
+
+ /**
+ * Create a new instance wrappering the specified serializer.
+ *
+ * @param serializer the old serialization interface
+ */
+ public DefaultProjectSetCapability(IProjectSetSerializer serializer) {
+ this.serializer = serializer;
+ }
+
+ /**
+ * Redirect the request to the old serialization interface
+ *
+ * @see IProjectSetSerializer
+ * @see org.eclipse.team.core.ProjectSetCapability#asReference(org.eclipse.core.resources.IProject[], org.eclipse.team.core.ProjectSetSerializationContext, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public String[] asReference(
+ IProject[] providerProjects,
+ ProjectSetSerializationContext context,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ return serializer.asReference(providerProjects, context.getShell(), monitor);
+ }
+
+ /**
+ * Redirect the request to the old serialization interface
+ *
+ * @see IProjectSetSerializer
+ * @see org.eclipse.team.core.ProjectSetCapability#addToWorkspace(java.lang.String[], org.eclipse.team.core.ProjectSetSerializationContext, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IProject[] addToWorkspace(
+ String[] referenceStrings,
+ ProjectSetSerializationContext context,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ return serializer.addToWorkspace(referenceStrings, null, context.getShell(), monitor);
+ }
+
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java
new file mode 100644
index 000000000..c5789642c
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProjectSetCapability.java
@@ -0,0 +1,516 @@
+/**********************************************************************
+ Copyright (c) 2004 Dan Rubel and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Common Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/cpl-v10.html
+
+ Contributors:
+
+ Dan Rubel - initial API and implementation
+
+ **********************************************************************/
+
+package org.eclipse.team.internal.ccvs.core;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.MultiRule;
+import org.eclipse.team.core.ProjectSetCapability;
+import org.eclipse.team.core.ProjectSetSerializationContext;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.ccvs.core.client.Checkout;
+import org.eclipse.team.internal.ccvs.core.client.Command;
+import org.eclipse.team.internal.ccvs.core.client.Request;
+import org.eclipse.team.internal.ccvs.core.client.Session;
+import org.eclipse.team.internal.ccvs.core.client.Update;
+import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
+import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteModule;
+import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
+
+/**
+ * An object for serializing and deserializing
+ * of references to CVS based projects. Given a project, it can produce a
+ * UTF-8 encoded String which can be stored in a file.
+ * Given this String, it can load a project into the workspace.
+ *
+ * @since 3.0
+ */
+public class CVSProjectSetCapability extends ProjectSetCapability {
+
+ /**
+ * Override superclass implementation to return an array of project references.
+ *
+ * @see ProjectSetSerializer#asReference(IProject[], ProjectSetSerializationContext, IProgressMonitor)
+ */
+ public String[] asReference(
+ IProject[] projects,
+ ProjectSetSerializationContext context,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ String[] result = new String[projects.length];
+ for (int i = 0; i < projects.length; i++)
+ result[i] = asReference(projects[i]);
+ return result;
+ }
+
+ /**
+ * Answer a string representing the specified project
+ *
+ * @param project the project (not <code>null</code>)
+ * @return the project reference (not <code>null</code>)
+ * @throws CVSException
+ */
+ private String asReference(IProject project) throws TeamException {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("1.0,"); //$NON-NLS-1$
+
+ CVSTeamProvider provider = (CVSTeamProvider)RepositoryProvider.getProvider(project);
+ CVSWorkspaceRoot root = provider.getCVSWorkspaceRoot();
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(root.getRemoteLocation().getLocation());
+ location.setUserMuteable(true);
+ String repoLocation = location.getLocation();
+ buffer.append(repoLocation);
+ buffer.append(","); //$NON-NLS-1$
+
+ ICVSFolder folder = root.getLocalRoot();
+ FolderSyncInfo syncInfo = folder.getFolderSyncInfo();
+ String module = syncInfo.getRepository();
+ buffer.append(module);
+ buffer.append(","); //$NON-NLS-1$
+
+ String projectName = folder.getName();
+ buffer.append(projectName);
+ CVSTag tag = syncInfo.getTag();
+ if (tag != null) {
+ if (tag.getType() != CVSTag.DATE) {
+ buffer.append(","); //$NON-NLS-1$
+ String tagName = tag.getName();
+ buffer.append(tagName);
+ }
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Override superclass implementation to load the referenced projects into the workspace.
+ *
+ * @see org.eclipse.team.core.ProjectSetSerializer#addToWorkspace(java.lang.String[], org.eclipse.team.core.ProjectSetSerializationContext, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IProject[] addToWorkspace(
+ String[] referenceStrings,
+ ProjectSetSerializationContext context,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ monitor = Policy.monitorFor(monitor);
+ Policy.checkCanceled(monitor);
+
+ // Confirm the projects to be loaded
+ Map infoMap = new HashMap(referenceStrings.length);
+ IProject[] projects = asProjects(referenceStrings, infoMap);
+ projects = confirmOverwrite(context, projects);
+ if (projects == null)
+ return new IProject[0];
+
+ // Load the projects
+ return checkout(projects, infoMap, monitor);
+ }
+
+ /**
+ * Translate the reference strings into projects to be loaded
+ * and build a mapping of project to project load information.
+ *
+ * @param referenceStrings project references
+ * @param infoMap a mapping of project to project load information
+ * @return the projects to be loaded
+ */
+ private IProject[] asProjects(String[] referenceStrings, Map infoMap) throws CVSException {
+ Collection result = new ArrayList();
+ for (int i = 0; i < referenceStrings.length; i++) {
+ StringTokenizer tokenizer = new StringTokenizer(referenceStrings[i], ","); //$NON-NLS-1$
+ String version = tokenizer.nextToken();
+ // If this is a newer version, then ignore it
+ if (!version.equals("1.0")) //$NON-NLS-1$
+ continue;
+ LoadInfo info = new LoadInfo(tokenizer);
+ IProject proj = info.getProject();
+ result.add(proj);
+ infoMap.put(proj, info);
+ }
+ return (IProject[]) result.toArray(new IProject[result.size()]);
+ }
+
+ /**
+ * Checkout projects from the CVS repository
+ *
+ * @param projects the projects to be loaded from the repository
+ * @param infoMap a mapping of project to project load information
+ * @param monitor the progress monitor (not <code>null</code>)
+ */
+ private IProject[] checkout(
+ IProject[] projects,
+ Map infoMap,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ monitor.beginTask("", 1000 * projects.length); //$NON-NLS-1$
+ List result = new ArrayList();
+ try {
+ for (int i = 0; i < projects.length; i++) {
+ if (monitor.isCanceled())
+ break;
+ IProject project = projects[i];
+ LoadInfo info = (LoadInfo) infoMap.get(project);
+ if (info != null && info.checkout(new SubProgressMonitor(monitor, 1000)))
+ result.add(project);
+ }
+ }
+ finally {
+ monitor.done();
+ }
+ return (IProject[])result.toArray(new IProject[result.size()]);
+ }
+
+ /**
+ * Internal class for adding projects to the workspace
+ */
+ class LoadInfo {
+ private final ICVSRepositoryLocation repositoryLocation;
+ private final String module;
+ private final IProject project;
+ private final CVSTag tag;
+
+ /**
+ * Construct a new instance wrappering the specified project reference
+ *
+ * @param projRef the project reference
+ */
+ LoadInfo(StringTokenizer tokenizer) throws CVSException {
+ String repo = tokenizer.nextToken();
+ repositoryLocation = getRepositoryLocationFromString(repo);
+ module = tokenizer.nextToken();
+ String projectName = tokenizer.nextToken();
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (tokenizer.hasMoreTokens()) {
+ String tagName = tokenizer.nextToken();
+ tag = new CVSTag(tagName, CVSTag.BRANCH);
+ }
+ else {
+ tag = null;
+ }
+ }
+
+ /**
+ * Answer the project referenced by this object.
+ * The project may or may not already exist.
+ *
+ * @return the project (not <code>null</code>)
+ */
+ private IProject getProject() {
+ return project;
+ }
+
+ /**
+ * Checkout the project specified by this reference.
+ *
+ * @param monitor project monitor
+ * @return true if loaded, else false
+ * @throws TeamException
+ */
+ boolean checkout(IProgressMonitor monitor) throws TeamException {
+ if (repositoryLocation == null)
+ return false;
+ CVSProjectSetCapability.checkout(
+ repositoryLocation,
+ project,
+ module,
+ tag,
+ monitor);
+ return true;
+ }
+ }
+
+ /**
+ * Extract the CVS repository location information from the specified string
+ *
+ * @param repo the repository location as a string
+ * @return the CVS repository information
+ * @throws CVSException
+ */
+ private static ICVSRepositoryLocation getRepositoryLocationFromString(String repo) throws CVSException {
+ // create the new location
+ ICVSRepositoryLocation newLocation = CVSRepositoryLocation.fromString(repo);
+ if (newLocation.getUsername() == null || newLocation.getUsername().length() == 0) {
+ // look for an existing location that matched
+ ICVSRepositoryLocation[] locations = CVSProviderPlugin.getPlugin().getKnownRepositories();
+ for (int i = 0; i < locations.length; i++) {
+ ICVSRepositoryLocation location = locations[i];
+ if (location.getMethod() == newLocation.getMethod()
+ && location.getHost().equals(newLocation.getHost())
+ && location.getPort() == newLocation.getPort()
+ && location.getRootDirectory().equals(newLocation.getRootDirectory()))
+ return location;
+ }
+ }
+ return newLocation;
+ }
+
+ /**
+ * Checkout a CVS module.
+ *
+ * The provided project represents the target project. Any existing contents
+ * may or may not get overwritten. If project is <code>null</code> then a project
+ * will be created based on the provided sourceModule. If soureModule is null,
+ * then the project name will be used as the module to
+ * check out. If both are absent, an exception is thrown.
+ *
+ * Resources existing in the local file system at the target project location but now
+ * known to the workbench will be overwritten.
+ *
+ * After the successful completion of this method, the project will exist
+ * and be open.
+ */
+ public static void checkout(
+ ICVSRepositoryLocation repository,
+ IProject project,
+ String sourceModule,
+ CVSTag tag,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ if (sourceModule == null)
+ sourceModule = project.getName();
+ checkout(new ICVSRemoteFolder[] { new RemoteFolder(null, repository, sourceModule, tag)},
+ new IProject[] { project }, monitor);
+ }
+
+ /**
+ * Checkout the remote resources into the local workspace. Each resource will
+ * be checked out into the corresponding project. If the corresponding project is
+ * null or if projects is null, the name of the remote resource is used as the name of the project.
+ *
+ * Resources existing in the local file system at the target project location but now
+ * known to the workbench will be overwritten.
+ */
+ public static void checkout(final ICVSRemoteFolder[] resources, final IProject[] projects, final IProgressMonitor monitor) throws TeamException {
+ final TeamException[] eHolder = new TeamException[1];
+ try {
+ IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor pm) throws CoreException {
+ try {
+ pm.beginTask(null, 1000 * resources.length);
+
+ // Get the location of the workspace root
+ ICVSFolder root = CVSWorkspaceRoot.getCVSFolderFor(ResourcesPlugin.getWorkspace().getRoot());
+
+ for (int i=0;i<resources.length;i++) {
+ IProject project = null;
+ RemoteFolder resource = (RemoteFolder)resources[i];
+
+ // Determine the provided target project if there is one
+ if (projects != null)
+ project = projects[i];
+
+ // Determine the remote module to be checked out
+ String moduleName;
+ if (resource instanceof RemoteModule) {
+ moduleName = ((RemoteModule)resource).getName();
+ } else {
+ moduleName = resource.getRepositoryRelativePath();
+ }
+
+ // Open a connection session to the repository
+ ICVSRepositoryLocation repository = resource.getRepository();
+ Session session = new Session(repository, root);
+ try {
+ session.open(Policy.subMonitorFor(pm, 50), false /* read-only */);
+
+ // Determine the local target projects (either the project provider or the module expansions)
+ final Set targetProjects = new HashSet();
+ if (project == null) {
+
+ // Fetch the module expansions
+ IStatus status = Request.EXPAND_MODULES.execute(session, new String[] {moduleName}, Policy.subMonitorFor(pm, 50));
+ if (status.getCode() == CVSStatus.SERVER_ERROR) {
+ throw new CVSServerException(status);
+ }
+
+ // Convert the module expansions to local projects
+ String[] expansions = session.getModuleExpansions();
+ for (int j = 0; j < expansions.length; j++) {
+ targetProjects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(expansions[j]).segment(0)));
+ }
+
+ } else {
+ targetProjects.add(project);
+ }
+
+ // Prepare the target projects to receive resources
+ root.run(new ICVSRunnable() {
+ public void run(IProgressMonitor monitor) throws CVSException {
+ scrubProjects((IProject[]) targetProjects.toArray(new IProject[targetProjects.size()]), monitor);
+ }
+ }, Policy.subMonitorFor(pm, 100));
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ // Add the option to load into the target project if one was supplied
+ if (project != null) {
+ localOptions.add(Checkout.makeDirectoryNameOption(project.getName()));
+ }
+ // Prune empty directories if pruning enabled
+ if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories())
+ localOptions.add(Checkout.PRUNE_EMPTY_DIRECTORIES);
+ // Add the options related to the CVSTag
+ CVSTag tag = resource.getTag();
+ if (tag == null) {
+ // A null tag in a remote resource indicates HEAD
+ tag = CVSTag.DEFAULT;
+ }
+ localOptions.add(Update.makeTagOption(tag));
+
+ // Perform the checkout
+ IStatus status = Command.CHECKOUT.execute(session,
+ Command.NO_GLOBAL_OPTIONS,
+ (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]),
+ new String[]{moduleName},
+ null,
+ Policy.subMonitorFor(pm, 800));
+ if (status.getCode() == CVSStatus.SERVER_ERROR) {
+ // XXX Should we cleanup any partially checked out projects?
+ throw new CVSServerException(status);
+ }
+
+ // Bring the project into the workspace
+ refreshProjects((IProject[])targetProjects.toArray(new IProject[targetProjects.size()]), Policy.subMonitorFor(pm, 100));
+
+ } finally {
+ session.close();
+ }
+ }
+ }
+ catch (TeamException e) {
+ // Pass it outside the workspace runnable
+ eHolder[0] = e;
+ } finally {
+ pm.done();
+ }
+ // CoreException and OperationCanceledException are propagated
+ }
+ };
+ ResourcesPlugin.getWorkspace().run(workspaceRunnable, new MultiRule(projects), 0, monitor);
+ } catch (CoreException e) {
+ throw CVSException.wrapException(e);
+ } finally {
+ monitor.done();
+ }
+ // Re-throw the TeamException, if one occurred
+ if (eHolder[0] != null) {
+ throw eHolder[0];
+ }
+ }
+
+ /*
+ * Bring the provied projects into the workspace
+ */
+ /* internal use only */ static void refreshProjects(IProject[] projects, IProgressMonitor monitor) throws CoreException, TeamException {
+ monitor.beginTask(Policy.bind("CVSProvider.Creating_projects_2"), projects.length * 100); //$NON-NLS-1$
+ try {
+ for (int i = 0; i < projects.length; i++) {
+ IProject project = projects[i];
+ // Register the project with Team
+ RepositoryProvider.map(project, CVSProviderPlugin.getTypeId());
+ CVSTeamProvider provider = (CVSTeamProvider)RepositoryProvider.getProvider(project, CVSProviderPlugin.getTypeId());
+ provider.setWatchEditEnabled(CVSProviderPlugin.getPlugin().isWatchEditEnabled());
+ }
+
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /*
+ * Delete the target projects before checking out
+ */
+ /* internal use only */ static void scrubProjects(IProject[] projects, IProgressMonitor monitor) throws CVSException {
+ if (projects == null) {
+ monitor.done();
+ return;
+ }
+ monitor.beginTask(Policy.bind("CVSProvider.Scrubbing_projects_1"), projects.length * 100); //$NON-NLS-1$
+ try {
+ for (int i=0;i<projects.length;i++) {
+ IProject project = projects[i];
+ if (project != null && project.exists()) {
+ if(!project.isOpen()) {
+ project.open(Policy.subMonitorFor(monitor, 10));
+ }
+ // We do not want to delete the project to avoid a project deletion delta
+ // We do not want to delete the .project to avoid core exceptions
+ monitor.subTask(Policy.bind("CVSProvider.Scrubbing_local_project_1")); //$NON-NLS-1$
+ // unmap the project from any previous repository provider
+ if (RepositoryProvider.getProvider(project) != null)
+ RepositoryProvider.unmap(project);
+ IResource[] children = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
+ IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 80);
+ subMonitor.beginTask(null, children.length * 100);
+ try {
+ for (int j = 0; j < children.length; j++) {
+ if ( ! children[j].getName().equals(".project")) {//$NON-NLS-1$
+ children[j].delete(true /*force*/, Policy.subMonitorFor(subMonitor, 100));
+ }
+ }
+ } finally {
+ subMonitor.done();
+ }
+ } else if (project != null) {
+ // Make sure there is no directory in the local file system.
+ File location = new File(project.getParent().getLocation().toFile(), project.getName());
+ if (location.exists()) {
+ deepDelete(location);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ throw CVSException.wrapException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private static void deepDelete(File resource) {
+ if (resource.isDirectory()) {
+ File[] fileList = resource.listFiles();
+ for (int i = 0; i < fileList.length; i++) {
+ deepDelete(fileList[i]);
+ }
+ }
+ resource.delete();
+ }
+
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProviderType.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProviderType.java
index b59f85a7d..6cdf976eb 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProviderType.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProviderType.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.core;
+import org.eclipse.team.core.ProjectSetCapability;
import org.eclipse.team.core.RepositoryProviderType;
@@ -27,5 +28,10 @@ public class CVSTeamProviderType extends RepositoryProviderType {
return false;
}
-
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.RepositoryProviderType#getProjectSetCapability()
+ */
+ public ProjectSetCapability getProjectSetCapability() {
+ return new CVSProjectSetCapability();
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSWorkspaceRoot.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSWorkspaceRoot.java
index c157a359f..f28fa91df 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSWorkspaceRoot.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSWorkspaceRoot.java
@@ -10,16 +10,29 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.core.resources;
-import java.io.File;
-import java.util.*;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.internal.ccvs.core.*;
-import org.eclipse.team.internal.ccvs.core.client.*;
-import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSStatus;
+import org.eclipse.team.internal.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.client.Request;
+import org.eclipse.team.internal.ccvs.core.client.Session;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
@@ -40,161 +53,6 @@ public class CVSWorkspaceRoot {
public CVSWorkspaceRoot(IContainer resource){
this.localRoot = getCVSFolderFor(resource);
}
-
- /**
- * Checkout a CVS module.
- *
- * The provided project represents the target project. Any existing contents
- * may or may not get overwritten. If project is <code>null</code> then a project
- * will be created based on the provided sourceModule. If soureModule is null,
- * then the project name will be used as the module to
- * check out. If both are absent, an exception is thrown.
- *
- * Resources existing in the local file system at the target project location but now
- * known to the workbench will be overwritten.
- *
- * After the successful completion of this method, the project will exist
- * and be open.
- */
- public static void checkout(
- ICVSRepositoryLocation repository,
- IProject project,
- String sourceModule,
- CVSTag tag,
- IProgressMonitor monitor)
- throws TeamException {
-
- if (sourceModule == null)
- sourceModule = project.getName();
- checkout(new ICVSRemoteFolder[] { new RemoteFolder(null, repository, sourceModule, tag)},
- new IProject[] { project }, monitor);
- }
-
- /**
- * Checkout the remote resources into the local workspace. Each resource will
- * be checked out into the corresponding project. If the corresponding project is
- * null or if projects is null, the name of the remote resource is used as the name of the project.
- *
- * Resources existing in the local file system at the target project location but now
- * known to the workbench will be overwritten.
- */
- public static void checkout(final ICVSRemoteFolder[] resources, final IProject[] projects, final IProgressMonitor monitor) throws TeamException {
- final TeamException[] eHolder = new TeamException[1];
- try {
- IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor pm) throws CoreException {
- try {
- pm.beginTask(null, 1000 * resources.length);
-
- // Get the location of the workspace root
- ICVSFolder root = CVSWorkspaceRoot.getCVSFolderFor(ResourcesPlugin.getWorkspace().getRoot());
-
- for (int i=0;i<resources.length;i++) {
- IProject project = null;
- RemoteFolder resource = (RemoteFolder)resources[i];
-
- // Determine the provided target project if there is one
- if (projects != null)
- project = projects[i];
-
- // Determine the remote module to be checked out
- String moduleName;
- if (resource instanceof RemoteModule) {
- moduleName = ((RemoteModule)resource).getName();
- } else {
- moduleName = resource.getRepositoryRelativePath();
- }
-
- // Open a connection session to the repository
- ICVSRepositoryLocation repository = resource.getRepository();
- Session session = new Session(repository, root);
- try {
- session.open(Policy.subMonitorFor(pm, 50), false /* read-only */);
-
- // Determine the local target projects (either the project provider or the module expansions)
- final Set targetProjects = new HashSet();
- if (project == null) {
-
- // Fetch the module expansions
- IStatus status = Request.EXPAND_MODULES.execute(session, new String[] {moduleName}, Policy.subMonitorFor(pm, 50));
- if (status.getCode() == CVSStatus.SERVER_ERROR) {
- throw new CVSServerException(status);
- }
-
- // Convert the module expansions to local projects
- String[] expansions = session.getModuleExpansions();
- for (int j = 0; j < expansions.length; j++) {
- targetProjects.add(ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(expansions[j]).segment(0)));
- }
-
- } else {
- targetProjects.add(project);
- }
-
- // Prepare the target projects to receive resources
- root.run(new ICVSRunnable() {
- public void run(IProgressMonitor monitor) throws CVSException {
- scrubProjects((IProject[]) targetProjects.toArray(new IProject[targetProjects.size()]), monitor);
- }
- }, Policy.subMonitorFor(pm, 100));
-
- // Build the local options
- List localOptions = new ArrayList();
- // Add the option to load into the target project if one was supplied
- if (project != null) {
- localOptions.add(Checkout.makeDirectoryNameOption(project.getName()));
- }
- // Prune empty directories if pruning enabled
- if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories())
- localOptions.add(Checkout.PRUNE_EMPTY_DIRECTORIES);
- // Add the options related to the CVSTag
- CVSTag tag = resource.getTag();
- if (tag == null) {
- // A null tag in a remote resource indicates HEAD
- tag = CVSTag.DEFAULT;
- }
- localOptions.add(Update.makeTagOption(tag));
-
- // Perform the checkout
- IStatus status = Command.CHECKOUT.execute(session,
- Command.NO_GLOBAL_OPTIONS,
- (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]),
- new String[]{moduleName},
- null,
- Policy.subMonitorFor(pm, 800));
- if (status.getCode() == CVSStatus.SERVER_ERROR) {
- // XXX Should we cleanup any partially checked out projects?
- throw new CVSServerException(status);
- }
-
- // Bring the project into the workspace
- refreshProjects((IProject[])targetProjects.toArray(new IProject[targetProjects.size()]), Policy.subMonitorFor(pm, 100));
-
- } finally {
- session.close();
- }
- }
- }
- catch (TeamException e) {
- // Pass it outside the workspace runnable
- eHolder[0] = e;
- } finally {
- pm.done();
- }
- // CoreException and OperationCanceledException are propagated
- }
- };
- ResourcesPlugin.getWorkspace().run(workspaceRunnable, monitor);
- } catch (CoreException e) {
- throw CVSException.wrapException(e);
- } finally {
- monitor.done();
- }
- // Re-throw the TeamException, if one occurred
- if (eHolder[0] != null) {
- throw eHolder[0];
- }
- }
/**
* Set the sharing for a project to enable it to be used with the CVSTeamProvider.
@@ -252,84 +110,6 @@ public class CVSWorkspaceRoot {
return s.getModuleExpansions();
}
-
- /*
- * Delete the target projects before checking out
- */
- /* internal use only */ static void scrubProjects(IProject[] projects, IProgressMonitor monitor) throws CVSException {
- if (projects == null) {
- monitor.done();
- return;
- }
- monitor.beginTask(Policy.bind("CVSProvider.Scrubbing_projects_1"), projects.length * 100); //$NON-NLS-1$
- try {
- for (int i=0;i<projects.length;i++) {
- IProject project = projects[i];
- if (project != null && project.exists()) {
- if(!project.isOpen()) {
- project.open(Policy.subMonitorFor(monitor, 10));
- }
- // We do not want to delete the project to avoid a project deletion delta
- // We do not want to delete the .project to avoid core exceptions
- monitor.subTask(Policy.bind("CVSProvider.Scrubbing_local_project_1")); //$NON-NLS-1$
- // unmap the project from any previous repository provider
- if (RepositoryProvider.getProvider(project) != null)
- RepositoryProvider.unmap(project);
- IResource[] children = project.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
- IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 80);
- subMonitor.beginTask(null, children.length * 100);
- try {
- for (int j = 0; j < children.length; j++) {
- if ( ! children[j].getName().equals(".project")) {//$NON-NLS-1$
- children[j].delete(true /*force*/, Policy.subMonitorFor(subMonitor, 100));
- }
- }
- } finally {
- subMonitor.done();
- }
- } else if (project != null) {
- // Make sure there is no directory in the local file system.
- File location = new File(project.getParent().getLocation().toFile(), project.getName());
- if (location.exists()) {
- deepDelete(location);
- }
- }
- }
- } catch (CoreException e) {
- throw CVSException.wrapException(e);
- } finally {
- monitor.done();
- }
- }
-
- private static void deepDelete(File resource) {
- if (resource.isDirectory()) {
- File[] fileList = resource.listFiles();
- for (int i = 0; i < fileList.length; i++) {
- deepDelete(fileList[i]);
- }
- }
- resource.delete();
- }
-
- /*
- * Bring the provied projects into the workspace
- */
- /* internal use only */ static void refreshProjects(IProject[] projects, IProgressMonitor monitor) throws CoreException, TeamException {
- monitor.beginTask(Policy.bind("CVSProvider.Creating_projects_2"), projects.length * 100); //$NON-NLS-1$
- try {
- for (int i = 0; i < projects.length; i++) {
- IProject project = projects[i];
- // Register the project with Team
- RepositoryProvider.map(project, CVSProviderPlugin.getTypeId());
- CVSTeamProvider provider = (CVSTeamProvider)RepositoryProvider.getProvider(project, CVSProviderPlugin.getTypeId());
- provider.setWatchEditEnabled(CVSProviderPlugin.getPlugin().isWatchEditEnabled());
- }
-
- } finally {
- monitor.done();
- }
- }
public static ICVSFolder getCVSFolderFor(IContainer resource) {
return new EclipseFolder(resource);
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSProjectSetSerializer.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSProjectSetSerializer.java
index 5b3f536ab..6bd4ae7c6 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSProjectSetSerializer.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSProjectSetSerializer.java
@@ -11,7 +11,9 @@
package org.eclipse.team.internal.ccvs.ui;
import java.lang.reflect.InvocationTargetException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -20,12 +22,21 @@ import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.*;
-import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.team.core.IProjectSetSerializer;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.CVSTeamProvider;
+import org.eclipse.team.internal.ccvs.core.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
+import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
+import org.eclipse.team.internal.ccvs.ui.operations.CheckoutSingleProjectOperation;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
public class CVSProjectSetSerializer implements IProjectSetSerializer {
@@ -142,11 +153,11 @@ public class CVSProjectSetSerializer implements IProjectSetSerializer {
try {
for (int i = 0; i < size; i++) {
if (locations[i] != null) {
- CVSWorkspaceRoot.checkout(locations[i], projects[i], modules[i], tags[i], new SubProgressMonitor(monitor, 1000));
+ ICVSRemoteFolder remote = new RemoteFolder(null, locations[i], modules[i], tags[i]);
+ new CheckoutSingleProjectOperation(null /* no part */, remote, projects[i], null /* location */, true)
+ .run(new SubProgressMonitor(monitor, 1000));
}
}
- } catch (TeamException e) {
- throw new InvocationTargetException(e);
} finally {
monitor.done();
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java
deleted file mode 100644
index b4150835e..000000000
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/AddToWorkspaceAction.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.team.internal.ccvs.ui.actions;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
-import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
-import org.eclipse.team.internal.ccvs.core.client.Checkout;
-import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
-import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ui.dialogs.IPromptCondition;
-import org.eclipse.team.internal.ui.dialogs.PromptingDialog;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-
-/**
- * Add some remote resources to the workspace. Current implementation:
- * -Works only for remote folders
- * -Does not prompt for project name; uses folder name instead
- */
-public class AddToWorkspaceAction extends CVSAction {
- /**
- * Returns the selected remote folders.
- * Remove any module aliases as they may cause problems on checkout this way
- */
- protected ICVSRemoteFolder[] getSelectedRemoteFolders() {
- ICVSRemoteFolder[] allFolders = super.getSelectedRemoteFolders();
- if (allFolders.length == 0) return allFolders;
- ArrayList resources = new ArrayList();
- for (int i = 0; i < allFolders.length; i++) {
- ICVSRemoteFolder folder = allFolders[i];
- if (!Checkout.ALIAS.isElementOf(folder.getLocalOptions())) {
- resources.add(folder);
- }
- }
- return (ICVSRemoteFolder[])resources.toArray(new ICVSRemoteFolder[resources.size()]);
- }
-
- /*
- * @see CVSAction#execute()
- */
- public void execute(IAction action) throws InvocationTargetException, InterruptedException {
- checkoutSelectionIntoWorkspaceDirectory();
- }
-
- protected void checkoutSelectionIntoWorkspaceDirectory() throws InvocationTargetException, InterruptedException {
- run(new WorkspaceModifyOperation() {
- public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
- try {
- ICVSRemoteFolder[] folders = getSelectedRemoteFolders();
-
- List targetProjects = new ArrayList();
- Map targetFolders = new HashMap();
- for (int i = 0; i < folders.length; i++) {
- String name = folders[i].getName();
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- targetFolders.put(name, folders[i]);
- targetProjects.add(project);
- }
-
- IResource[] projects = (IResource[]) targetProjects.toArray(new IResource[targetProjects.size()]);
-
- PromptingDialog prompt = new PromptingDialog(getShell(), projects,
- getOverwriteLocalAndFileSystemPrompt(),
- Policy.bind("ReplaceWithAction.confirmOverwrite"));//$NON-NLS-1$
- projects = prompt.promptForMultiple();
-
- monitor.beginTask(null, 100);
- if (projects.length != 0) {
- IProject[] localFolders = new IProject[projects.length];
- ICVSRemoteFolder[] remoteFolders = new ICVSRemoteFolder[projects.length];
- for (int i = 0; i < projects.length; i++) {
- localFolders[i] = (IProject)projects[i];
- remoteFolders[i] = (ICVSRemoteFolder)targetFolders.get(projects[i].getName());
- }
-
- monitor.setTaskName(getTaskName(remoteFolders));
- CVSWorkspaceRoot.checkout(remoteFolders, localFolders, Policy.subMonitorFor(monitor, 100));
- }
- } catch (TeamException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- }
- }
- }, true /* cancelable */, PROGRESS_DIALOG);
- }
-
- /*
- * @see TeamAction#isEnabled()
- */
- protected boolean isEnabled() throws TeamException {
- ICVSRemoteFolder[] resources = getSelectedRemoteFolders();
- if (resources.length == 0) return false;
- for (int i = 0; i < resources.length; i++) {
- if (resources[i] instanceof ICVSRepositoryLocation) return false;
- }
- return true;
- }
- /**
- * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
- */
- protected String getErrorTitle() {
- return Policy.bind("AddToWorkspaceAction.checkoutFailed"); //$NON-NLS-1$
- }
-
- /*
- * Prompt the user to overwrite any projects that overlap with the module expansions.
- *
- * This is an all or nothing prompt. If the user says no to one project overwrite
- * then the whole operation must be aborted. This is because there is no easy way to
- * map the module expansions back to their remote modules.
- */
- private boolean promptForOverwrite(String[] expansions) throws InterruptedException {
-
- // If the target project exists, prompt the user for overwrite
- Set targetProjects = new HashSet();
- for (int i = 0; i < expansions.length; i++) {
- String string = expansions[i];
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(string).segment(0));
- targetProjects.add(project);
- }
- IResource[] projects = (IResource[]) targetProjects.toArray(new IResource[targetProjects.size()]);
- PromptingDialog prompt = new PromptingDialog(getShell(), projects,
- getOverwriteLocalAndFileSystemPrompt(),
- Policy.bind("ReplaceWithAction.confirmOverwrite"), //$NON-NLS-1$
- true /* all or nothing*/);//$NON-NLS-1$
- return (prompt.promptForMultiple().length == projects.length);
- }
-
- protected static String getTaskName(ICVSRemoteFolder[] remoteFolders) {
- if (remoteFolders.length == 1) {
- ICVSRemoteFolder folder = remoteFolders[0];
- String label = folder.getRepositoryRelativePath();
- if (label.equals(FolderSyncInfo.VIRTUAL_DIRECTORY)) {
- label = folder.getName();
- }
- return Policy.bind("AddToWorkspace.taskName1", label); //$NON-NLS-1$
- }
- else {
- return Policy.bind("AddToWorkspace.taskNameN", new Integer(remoteFolders.length).toString()); //$NON-NLS-1$
- }
- }
-
- protected IPromptCondition getOverwriteLocalAndFileSystemPrompt() {
- return new IPromptCondition() {
- // prompt if resource in workspace exists or exists in local file system
- public boolean needsPrompt(IResource resource) {
- File localLocation = getFileLocation(resource);
- if(resource.exists() || localLocation.exists()) {
- return true;
- }
- return false;
- }
- public String promptMessage(IResource resource) {
- File localLocation = getFileLocation(resource);
- if(resource.exists()) {
- return Policy.bind("AddToWorkspaceAction.thisResourceExists", resource.getName());//$NON-NLS-1$
- } else {
- return Policy.bind("AddToWorkspaceAction.thisExternalFileExists", resource.getName());//$NON-NLS-1$
- }
- }
- private File getFileLocation(IResource resource) {
- return new File(resource.getParent().getLocation().toFile(), resource.getName());
- }
- };
- }
-}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java
index 6aaf7d774..c06aeb4fe 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CheckoutAsAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,19 +16,13 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
-import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.operations.HasProjectMetaFileOperation;
import org.eclipse.team.internal.ccvs.ui.wizards.CheckoutAsWizard;
-/**
- * Add a remote resource to the workspace. Current implementation:
- * -Works only for remote folders
- * -Does not prompt for project name; uses folder name instead
- */
-public class CheckoutAsAction extends AddToWorkspaceAction {
+public class CheckoutAsAction extends CVSAction {
- /*
- * @see IActionDelegate#run(IAction)
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#execute(org.eclipse.jface.action.IAction)
*/
public void execute(IAction action) throws InvocationTargetException, InterruptedException {
ICVSRemoteFolder[] folders = getSelectedRemoteFolders();
@@ -37,22 +31,20 @@ public class CheckoutAsAction extends AddToWorkspaceAction {
dialog.open();
}
+ /*
+ * Return true if the remote project does not have a .project file
+ * so that the checkout wizard will give the option to launch
+ * the New Project wizard
+ */
protected boolean allowProjectConfiguration(ICVSRemoteFolder[] folders) throws InvocationTargetException, InterruptedException {
if (folders.length != 1) return false;
return !HasProjectMetaFileOperation.hasMetaFile(getTargetPart(), folders[0]);
}
- /*
- * @see TeamAction#isEnabled()
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled()
*/
protected boolean isEnabled() throws TeamException {
return getSelectedRemoteFolders().length > 0;
}
-
- /**
- * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
- */
- protected String getErrorTitle() {
- return Policy.bind("CheckoutAsAction.checkoutFailed"); //$NON-NLS-1$
- }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
index 1bc7559b5..8df1e3d6e 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
@@ -38,10 +38,6 @@ AddToVersionControlDialog.title=Add to CVS Version Control
AddToVersionControlDialog.thereIsAnUnaddedResource=There is {0} resource that is not under CVS version control. Do you want to add it?
AddToVersionControlDialog.thereAreUnaddedResources=There are {0} resources that are not under CVS version control. Do you want to add them?
-AddToWorkspaceAction.checkoutFailed=Problems encountered performing checkout
-AddToWorkspaceAction.thisResourceExists=The resource ''{0}'' already exists in the workspace and will be deleted. Proceed?
-AddToWorkspaceAction.thisExternalFileExists=The folder ''{0}'' exists in the local file system and will be deleted. Proceed?
-AddToWorkspaceAction.confirmOverwrite=Confirm Overwrite
CheckoutAction.overlappingModuleExpansions=You have attempted to check out multiple remote modules that expand to the same local resource ''{0}''.
AutoDefineTagsAction.defineTags = Auto-discover tags
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java
index a450c9147..510b9ca66 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java
@@ -32,15 +32,14 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.IProjectSetSerializer;
import org.eclipse.team.core.ProjectSetCapability;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.RepositoryProviderType;
-import org.eclipse.team.core.Team;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.ISharedImages;
+import org.eclipse.team.ui.UIProjectSetSerializationContext;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
@@ -112,6 +111,7 @@ public class ProjectSetExportWizard extends Wizard implements IExportWizard {
}
Shell shell = getShell();
+ UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(getShell());
BufferedWriter writer = null;
try {
@@ -123,6 +123,7 @@ public class ProjectSetExportWizard extends Wizard implements IExportWizard {
writer.newLine();
// For each provider id, do the writing
+
Iterator it = map.keySet().iterator();
monitor.beginTask(null, 1000 * map.keySet().size());
while (it.hasNext()) {
@@ -133,9 +134,9 @@ public class ProjectSetExportWizard extends Wizard implements IExportWizard {
writer.newLine();
List list = (List)map.get(id);
IProject[] projectArray = (IProject[])list.toArray(new IProject[list.size()]);
- IProjectSetSerializer serializer = Team.getProjectSetSerializer(id);
+ ProjectSetCapability serializer = RepositoryProviderType.getProviderType(id).getProjectSetCapability();
if (serializer != null) {
- String[] references = serializer.asReference(projectArray, shell, new SubProgressMonitor(monitor, 990));
+ String[] references = serializer.asReference(projectArray, context, new SubProgressMonitor(monitor, 990));
for (int i = 0; i < references.length; i++) {
writer.write("\t\t<project reference=\""); //$NON-NLS-1$
writer.write(references[i]);
@@ -170,7 +171,7 @@ public class ProjectSetExportWizard extends Wizard implements IExportWizard {
if (type != null) {
ProjectSetCapability capability = type.getProjectSetCapability();
if (capability != null) {
- capability.projectSetCreated(file, shell, new SubProgressMonitor(monitor, 10));
+ capability.projectSetCreated(file, context, new SubProgressMonitor(monitor, 10));
}
}
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java
index 34e57b626..f60a5edc8 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java
@@ -10,11 +10,19 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.wizards;
-import java.io.*;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
-import javax.xml.parsers.*;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -22,10 +30,20 @@ import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.team.core.*;
-import org.eclipse.team.internal.ui.*;
+import org.eclipse.team.core.IProjectSetSerializer;
+import org.eclipse.team.core.ProjectSetCapability;
+import org.eclipse.team.core.RepositoryProviderType;
+import org.eclipse.team.core.Team;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.ui.Policy;
+import org.eclipse.team.internal.ui.ProjectSetContentHandler;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.ISharedImages;
-import org.eclipse.ui.*;
+import org.eclipse.team.ui.UIProjectSetSerializationContext;
+import org.eclipse.ui.IImportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -81,13 +99,14 @@ public class ProjectSetImportWizard extends Wizard implements IImportWizard {
newProjects.addAll(Arrays.asList(projects));
}
} else {
+ UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(getShell());
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String id = (String)it.next();
List references = (List)map.get(id);
- IProjectSetSerializer serializer = Team.getProjectSetSerializer(id);
+ ProjectSetCapability serializer = RepositoryProviderType.getProviderType(id).getProjectSetCapability();
if (serializer != null) {
- IProject[] projects = serializer.addToWorkspace((String[])references.toArray(new String[references.size()]), filename, getShell(), monitor);
+ IProject[] projects = serializer.addToWorkspace((String[])references.toArray(new String[references.size()]), context, monitor);
if (projects != null)
newProjects.addAll(Arrays.asList(projects));
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/UIProjectSetSerializationContext.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/UIProjectSetSerializationContext.java
new file mode 100644
index 000000000..bb7284b92
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/UIProjectSetSerializationContext.java
@@ -0,0 +1,108 @@
+/**********************************************************************
+ Copyright (c) 2004 Dan Rubel and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Common Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/cpl-v10.html
+
+ Contributors:
+
+ Dan Rubel - initial API and implementation
+
+ **********************************************************************/
+
+package org.eclipse.team.ui;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.ProjectSetSerializationContext;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.ui.dialogs.IPromptCondition;
+import org.eclipse.team.internal.ui.dialogs.PromptingDialog;
+
+/**
+ * The UI based context in which project serialization occurs.
+ * The class may be subclasses to represent different UI based serialization contexts.
+ * It is recommended that all UI based serialization contexts
+ * use this class directly or indirectly as their superclass.
+ *
+ * @since 3.0
+ */
+public class UIProjectSetSerializationContext extends ProjectSetSerializationContext {
+
+ /**
+ * The parent shell for this UI context
+ */
+ private final Shell shell;
+
+ /**
+ * Construct a new instance
+ *
+ * @param shell The parent shell for this UI context
+ */
+ public UIProjectSetSerializationContext(Shell shell) {
+ Assert.isNotNull(shell);
+ this.shell = shell;
+ }
+
+ /**
+ * Answer the shell associated with this UI context.
+ *
+ * @return the shell (not <code>null</code>)
+ */
+ public Object getShell() {
+ return shell;
+ }
+
+ /**
+ * Given an array of projects that currently exist in the workspace
+ * prompt the user to determine which of those projects should be overwritten.
+ * <p>
+ * This default implementation prompts the user
+ * to determine which projects should be overwritten.
+ * Subclasses may override this as appropriate.
+ *
+ * @param projects
+ * an array of projects currently existing in the workspace
+ * that are desired to be overwritten.
+ * (not <code>null</code>, contains no <code>null</code>s)
+ * @return
+ * an array of zero or more projects that should be overwritten
+ * or <code>null</code> if the operation is to be canceled
+ *
+ * @see org.eclipse.team.core.ProjectSetSerializationContext#confirmOverwrite(org.eclipse.core.resources.IProject[])
+ */
+ public IProject[] confirmOverwrite(final IProject[] projects) throws TeamException {
+ IPromptCondition prompt = new IPromptCondition() {
+ List resources = Arrays.asList(projects);
+ public boolean needsPrompt(IResource resource) {
+ return resources.contains(resource);
+ }
+ public String promptMessage(IResource resource) {
+ return "Overwrite " + resource.getName();
+ }
+ };
+ PromptingDialog dialog =
+ new PromptingDialog(
+ (Shell)getShell(),
+ projects,
+ prompt,
+ "Overwrite projects?");
+ IResource[] resourcesToOverwrite;
+ try {
+ resourcesToOverwrite = dialog.promptForMultiple();
+ } catch (InterruptedException e) {
+ // Return null indicating that the user canceled the operation
+ return null;
+ }
+ IProject[] projectsToOverwrite = new IProject[resourcesToOverwrite.length];
+ System.arraycopy(resourcesToOverwrite, 0, projectsToOverwrite, 0, resourcesToOverwrite.length);
+ return projectsToOverwrite;
+ }
+
+}

Back to the top