diff options
author | Michael Valenta | 2004-04-07 14:33:00 +0000 |
---|---|---|
committer | Michael Valenta | 2004-04-07 14:33:00 +0000 |
commit | 4bdcf7bdb476a121a4c91eae20564eff89557f83 (patch) | |
tree | 87381f8314162cab9fa37e6b083dc1e574b15643 | |
parent | 5350a9a2fdffc58cd908f49c0e7ca3468059712e (diff) | |
download | eclipse.platform.team-4bdcf7bdb476a121a4c91eae20564eff89557f83.tar.gz eclipse.platform.team-4bdcf7bdb476a121a4c91eae20564eff89557f83.tar.xz eclipse.platform.team-4bdcf7bdb476a121a4c91eae20564eff89557f83.zip |
38048: IProjectSetSerializer cannot be used in headless environment
7 files changed, 572 insertions, 462 deletions
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 8721bb8d8..0df9965f0 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 |