Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 5348 Details for
Bug 38048
IProjectSetSerializer cannot be used in headless environment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
new serializer support for team.core
bug_38048_new_serializer_team_core.txt (text/plain), 17.25 KB, created by
Dan Rubel
on 2003-07-04 11:27:14 EDT
(
hide
)
Description:
new serializer support for team.core
Filename:
MIME Type:
Creator:
Dan Rubel
Created:
2003-07-04 11:27:14 EDT
Size:
17.25 KB
patch
obsolete
>Index: org/eclipse/team/core/IProjectSetSerializer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.team.core/src/org/eclipse/team/core/IProjectSetSerializer.java,v >retrieving revision 1.6 >diff -u -r1.6 IProjectSetSerializer.java >--- org/eclipse/team/core/IProjectSetSerializer.java 10 Mar 2003 21:54:49 -0000 1.6 >+++ org/eclipse/team/core/IProjectSetSerializer.java 4 Jul 2003 14:13:29 -0000 >@@ -20,6 +20,10 @@ > * 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 { >Index: org/eclipse/team/core/RepositoryProviderType.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.team.core/src/org/eclipse/team/core/RepositoryProviderType.java,v >retrieving revision 1.11 >diff -u -r1.11 RepositoryProviderType.java >--- org/eclipse/team/core/RepositoryProviderType.java 17 Jun 2003 20:04:58 -0000 1.11 >+++ org/eclipse/team/core/RepositoryProviderType.java 4 Jul 2003 14:13:29 -0000 >@@ -156,4 +156,33 @@ > public ProjectSetCapability getProjectSetCapability() { > return null; > } >+ >+ /** >+ * 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. >+ * <p> >+ * 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 the serializer (not <code>null</code>) >+ * @since 3.0 >+ */ >+ public ProjectSetSerializer getProjectSetSerializer() { >+ >+ // Provide backward compatibility with the old IProjectSetSerializer interface >+ IProjectSetSerializer oldSerializer = Team.getProjectSetSerializer(getID()); >+ if (oldSerializer != null) >+ return new DefaultProjectSetSerializer(oldSerializer); >+ >+ return new ProjectSetSerializer(); >+ } > } >Index: org/eclipse/team/core/Team.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.team.core/src/org/eclipse/team/core/Team.java,v >retrieving revision 1.32 >diff -u -r1.32 Team.java >--- org/eclipse/team/core/Team.java 17 Jun 2003 20:04:58 -0000 1.32 >+++ org/eclipse/team/core/Team.java 4 Jul 2003 14:13:32 -0000 >@@ -610,6 +610,11 @@ > 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) { >Index: src/org/eclipse/team/core/DefaultProjectSetSerializer.java >=================================================================== >RCS file: src/org/eclipse/team/core/DefaultProjectSetSerializer.java >diff -N src/org/eclipse/team/core/DefaultProjectSetSerializer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/core/DefaultProjectSetSerializer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+package org.eclipse.team.core; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.IProgressMonitor; >+ >+/** >+ * An internal class for backward compatibility with the >+ * {@link org.eclipse.team.core.IProjectSetSerializer} interface. >+ * >+ * @since 3.0 >+ */ >+final class DefaultProjectSetSerializer extends ProjectSetSerializer { >+ >+ /** >+ * The old serialization interface >+ */ >+ private IProjectSetSerializer serializer; >+ >+ /** >+ * Create a new instance wrappering the specified serializer. >+ * >+ * @param serializer the old serialization interface >+ */ >+ public DefaultProjectSetSerializer(IProjectSetSerializer serializer) { >+ this.serializer = serializer; >+ } >+ >+ /** >+ * Redirect the request to the old serialization interface >+ * >+ * @see IProjectSetSerializer >+ * @see org.eclipse.team.core.ProjectSetSerializer#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.getIProjectSetSerializerContext(), monitor); >+ } >+ >+ /** >+ * Redirect the request to the old serialization interface >+ * >+ * @see IProjectSetSerializer >+ * @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 { >+ >+ return serializer.addToWorkspace(referenceStrings, null, context.getIProjectSetSerializerContext(), monitor); >+ } >+ >+} >Index: src/org/eclipse/team/core/ProjectSetSerializationContext.java >=================================================================== >RCS file: src/org/eclipse/team/core/ProjectSetSerializationContext.java >diff -N src/org/eclipse/team/core/ProjectSetSerializationContext.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/core/ProjectSetSerializationContext.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,72 @@ >+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]; >+ } >+ >+ /** >+ * Given an array of projects to be loaded in the workspace >+ * determine where those projects should be located. >+ * <p> >+ * This default implementation always returns an array of <code>null</code>s >+ * indicating that all projects should be loaded in their default locations. >+ * >+ * @param projects >+ * An array of projects to be loaded into the workspace. >+ * A project with this name may or may not already exist in the workspace. >+ * (not <code>null</code>, contains no <code>null</code>s) >+ * @return >+ * An array containing the same number of elements as the projects array >+ * or <code>null</code> if the operation should be canceled. >+ * Each element in the array is either an absolute path >+ * indicating the location where the corresponding project should be loaded >+ * or a <code>null</code> indicating that the corresponding project >+ * should be loaded in its default location in the workspace. >+ */ >+ public IPath[] getLocalProjectLocations(IProject[] projects) { >+ return new IPath[projects.length]; >+ } >+ >+ /** >+ * Return a shell if there is a UI context >+ * or <code>null</code> if executing headless. >+ * >+ * @return the shell or <code>null</code> >+ * >+ * @deprecated >+ * This method exist solely for backward compatibility >+ * with the {@link IProjectSetSerializer} interface >+ * and should not be used for any other purpose. >+ */ >+ public Object getIProjectSetSerializerContext() { >+ return null; >+ } >+ >+} >Index: src/org/eclipse/team/core/ProjectSetSerializer.java >=================================================================== >RCS file: src/org/eclipse/team/core/ProjectSetSerializer.java >diff -N src/org/eclipse/team/core/ProjectSetSerializer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/core/ProjectSetSerializer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,218 @@ >+package org.eclipse.team.core; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Collection; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IProjectDescription; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.SubProgressMonitor; >+ >+/** >+ * 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. >+ * >+ * @since 3.0 >+ */ >+public class ProjectSetSerializer { >+ >+ /** >+ * 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. >+ * >+ * @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. >+ * >+ * @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. >+ * >+ * @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()]); >+ } >+ >+ /** >+ * Determine the locations for the projects to be loaded >+ * and create any project that does not already exist. >+ * >+ * @param context the serialization context >+ * @param projects the projects to be created >+ * @param monitor the progress monitor (not <code>null</code>) >+ * @return >+ * an array of projects that were created or already existed >+ * or <code>null</code> if the operation should be canceled >+ */ >+ protected IProject[] createProjects( >+ ProjectSetSerializationContext context, >+ IProject[] projects, >+ IProgressMonitor monitor) >+ throws TeamException { >+ >+ // Retrieve the preferred project locations >+ IPath[] locations = context.getLocalProjectLocations(projects); >+ if (locations == null) >+ return null; >+ >+ // Create the projects that do not already exist >+ monitor.beginTask("", projects.length); //$NON-NLS-1$ >+ for (int i = 0; i < projects.length; i++) { >+ if (monitor.isCanceled()) >+ return null; >+ IProject eachProject = projects[i]; >+ IPath eachLocation = locations[i]; >+ if (eachProject.exists()) { >+ // The project location of an existing project cannot be changed, >+ // so if the current location is different than the intended location >+ // then in the future the project could be deleted and recreated >+ // ... but do nothing for now >+ } >+ else { >+ IProjectDescription desc = >+ ResourcesPlugin.getWorkspace().newProjectDescription( >+ eachProject.getName()); >+ desc.setLocation(eachLocation); >+ try { >+ eachProject.create(desc, new SubProgressMonitor(monitor, 1)); >+ } >+ catch (CoreException e) { >+ throw new TeamException(e.getMessage(), e); >+ } >+ } >+ } >+ monitor.done(); >+ return projects; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 38048
:
5348
|
5349
|
5350
|
5351
|
7396