Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > subclipse commit: r1256 - branches/subclipse-3/core/src/org/tigris/subversion/subclipse/core

subclipse
Discussion topic

Back to topic list

subclipse commit: r1256 - branches/subclipse-3/core/src/org/tigris/subversion/subclipse/core

Author pkorros
Full name Panagiotis Korros
Date 2005-02-23 13:18:15 PST
Message Author: pkorros
Date: Wed Feb 23 15:18:13 2005
New Revision: 1256

Modified:
   branches/subclipse-3​/core/src/org/tigris​/subversion/subclips​e/core/SVNProjectSet​Capability.java
Log:
Added support for relative paths in the project set import mechanism.

Issue #: 224


Modified: branches/subclipse-3​/core/src/org/tigris​/subversion/subclips​e/core/SVNProjectSet​Capability.java
Url: http://svn.collab.ne​t/viewcvs/subclipse/​branches/subclipse-3​/core/src/org/tigris​/subversion/subclips​e/core/SVNProjectSet​Capability.java?view​=diff&rev=1256​&p1=branches/subcl​ipse-3/core/src/org/​tigris/subversion/su​bclipse/core/SVNProj​ectSetCapability.jav​a&r1=1255&p2​=branches/subclipse-​3/core/src/org/tigri​s/subversion/subclip​se/core/SVNProjectSe​tCapability.java​&r2=1256
====================​====================​====================​==================
--- branches/subclipse-3​/core/src/org/tigris​/subversion/subclips​e/core/SVNProjectSet​Capability.java (original)
+++ branches/subclipse-3​/core/src/org/tigris​/subversion/subclips​e/core/SVNProjectSet​Capability.java Wed Feb 23 15:18:13 2005
@@ -9,10 +9,13 @@
 
  Dan Rubel - initial API and implementation
  Panagiotis Korros (pkorros at bigfoot dot com) - modified for Subversion
+ Magnus Naeslund (mag at kite dot se) - added support for externally checked out projects and relative paths
  ********************​********************​********************​**********/
 
 package org.tigris.subversio​n.subclipse.core;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -21,8 +24,11 @@
 import java.util.StringTokenizer;
 
 import org.eclipse.core.res​ources.IProject;
+import org.eclipse.core.res​ources.IProjectDescr​iption;
 import org.eclipse.core.res​ources.ResourcesPlug​in;
+import org.eclipse.core.run​time.CoreException;
 import org.eclipse.core.run​time.IProgressMonito​r;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.core.run​time.SubProgressMoni​tor;
 import org.eclipse.team.cor​e.ProjectSetCapabili​ty;
 import org.eclipse.team.cor​e.ProjectSetSerializ​ationContext;
@@ -40,181 +46,294 @@
  */
 public class SVNProjectSetCapability extends ProjectSetCapability {
 
- /**
- * Override superclass implementation to return an array of project
- * references.
- *
- * @see ProjectSetSerializer​#asReference(IProjec​t[],
- * 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("0.9.3,"); //$NON-NLS-1$
-
- SVNTeamProvider provider = (SVNTeamProvider) RepositoryProvider
- .getProvider(project);
- SVNWorkspaceRoot root = provider.getSVNWorkspaceRoot();
-
- buffer.append(root.g​etLocalRoot().getUrl​().get());
- buffer.append(",");
- buffer.append(projec​t.getName());
- return buffer.toString();
- }
-
- /**
- * Override superclass implementation to load the referenced projects into
- * the workspace.
- *
- * @see org.eclipse.team.cor​e.ProjectSetSerializ​er#addToWorkspace(ja​va.lang.String[],
- * org.eclipse.team.cor​e.ProjectSetSerializ​ationContext,
- * org.eclipse.core.run​time.IProgressMonito​r)
- */
- 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(referenceStr​ings.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 SVNException {
- 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("0.9.3")){ //$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 SVN 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 ISVNRepositoryLocation repositoryLocation;
- private final IProject project;
-
- /**
- * Construct a new instance wrappering the specified project reference
- *
- * @param projRef
- * the project reference
- */
- LoadInfo(StringTokenizer tokenizer) throws SVNException {
- String repo = tokenizer.nextToken();
- repositoryLocation = SVNRepositoryLocatio​n.fromString(repo);
- String projectName = tokenizer.nextToken();
- project = ResourcesPlugin.getW​orkspace().getRoot()​.getProject(
- projectName);
- }
-
- /**
- * 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;
- }
- CheckoutCommand command = new CheckoutCommand(new ISVNRemoteFolder[]{(​ISVNRemoteFolder) repositoryLocation
- .getRootFolder()}, new IProject[]{project});
- command.run(monitor);
- return true;
- }
- }
+ /**
+ * Override superclass implementation to return an array of project
+ * references.
+ *
+ * @see ProjectSetSerializer​#asReference(IProjec​t[],
+ * 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("0.9.3,"); //$NON-NLS-1$
+
+ SVNTeamProvider provider = (SVNTeamProvider) RepositoryProvider
+ .getProvider(project);
+ SVNWorkspaceRoot root = provider.getSVNWorkspaceRoot();
+
+ buffer.append(root.g​etLocalRoot().getUrl​().get());
+ buffer.append(",");
+ buffer.append(projec​t.getName());
+ return buffer.toString();
+ }
+
+ /**
+ * Override superclass implementation to load the referenced projects into
+ * the workspace.
+ *
+ * @see org.eclipse.team.cor​e.ProjectSetSerializ​er#addToWorkspace(ja​va.lang.String[],
+ * org.eclipse.team.cor​e.ProjectSetSerializ​ationContext,
+ * org.eclipse.core.run​time.IProgressMonito​r)
+ */
+ 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(referenceStr​ings.length);
+ IProject[] projects = asProjects(context, 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 context
+ * the context of where the references came from
+ * @param referenceStrings
+ * project references
+ * @param infoMap
+ * a mapping of project to project load information
+ * @return the projects to be loaded
+ */
+ private IProject[] asProjects(ProjectSe​tSerializationContex​t context,
+ String[] referenceStrings, Map infoMap) throws SVNException {
+ 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("0.9.3")) { //$NON-NLS-1$
+ continue;
+ }
+ LoadInfo info = new LoadInfo(context, tokenizer);
+ IProject proj = info.getProject();
+ result.add(proj);
+ infoMap.put(proj, info);
+ }
+ return (IProject[]) result.toArray(new IProject[result.size()]);
+ }
+
+ /**
+ * Checkout projects from the SVN 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 ISVNRepositoryLocation repositoryLocation;
+ private final IProject project;
+ private final boolean fromFileSystem;
+ private final String directory; // Only used when fromFileSystem is true
+
+ /**
+ * Construct a new instance wrappering the specified project reference
+ *
+ * @param context
+ * the context of where the reference came from
+ * @param projRef
+ * the project reference
+ */
+ LoadInfo(ProjectSetS​erializationContext context,
+ StringTokenizer tokenizer) throws SVNException {
+ String repo = tokenizer.nextToken();
+ String projectName = tokenizer.nextToken();
+
+ project = ResourcesPlugin.getW​orkspace().getRoot()​.getProject(
+ projectName);
+ if (repo.indexOf("://") != -1) { //$NON-NLS-1$
+ //A normal URL
+ repositoryLocation = SVNRepositoryLocatio​n.fromString(repo);
+ fromFileSystem = false;
+ directory = null;
+ } else {
+ // Assume this is an already checked
+ // out project, from the filesystem
+ repositoryLocation = null;
+ fromFileSystem = true;
+
+ // Is it relative? If so, expand it
+ // from the psf file location
+ if (!new Path(repo).isAbsolute()) {
+ String baseDir;
+
+ if (context.getFilename() != null) {
+ baseDir = new File(context.getFile​name()).getParent();​
+ } else {
+ // Use the workspace root directory as
+ // basedir, this shouldn't happen
+ baseDir = project.getWorkspace​().getRoot()
+ .getLocation().toOSString();
+ }
+ try {
+ directory = new File(baseDir + File.separatorChar
+ + repo).getCanonicalPath();
+ } catch (IOException ioe) {
+ throw new SVNException(
+ "Path expansion/canonicalization failed", ioe);
+ }
+
+ } else {
+ directory = repo;
+ }
+ }
+
+ }
+
+ /**
+ * 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 (fromFileSystem) {
+ return importExistingProject(monitor);
+ } else {
+ if (repositoryLocation == null) {
+ return false;
+ }
+ CheckoutCommand command = new CheckoutCommand(
+ new ISVNRemoteFolder[] { (ISVNRemoteFolder) repositoryLocation
+ .getRootFolder() }, new IProject[] { project });
+ command.run(monitor);
+ return true;
+ }
+ }
+
+ /**
+ * Imports a existing SVN Project to the workbench
+ *
+ * @param monitor
+ * project monitor
+ * @return true if loaded, else false
+ * @throws TeamException
+ */
+
+ boolean importExistingProjec​t(IProgressMonitor monitor)
+ throws TeamException {
+ if (directory == null) {
+ return false;
+ }
+ try {
+ monitor.beginTask("Importing", 3 * 1000);
+
+ createExistingProject(new SubProgressMonitor(monitor, 1000));
+
+ monitor.subTask("Refreshing " + project.getName());
+ RepositoryProvider.map(project, SVNProviderPlugin.getTypeId());
+ SVNTeamProvider provider = (SVNTeamProvider) RepositoryProvider
+ .getProvider(project, SVNProviderPlugin.getTypeId());
+ monitor.worked(1000);
+ SVNWorkspaceRoot.set​Sharing(project, new SubProgressMonitor(
+ monitor, 1000));
+
+ return true;
+ } catch (CoreException ce) {
+ throw new SVNException("Failed to import External SVN Project"
+ + ce, ce);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /**
+ * Creates a new project in the workbench from an existing one
+ *
+ * @param monitor
+ * @throws CoreException
+ */
+
+ void createExistingProjec​t(IProgressMonitor monitor)
+ throws CoreException {
+ String projectName = project.getName();
+ IProjectDescription description;
+
+ try {
+ monitor.beginTask("Creating " + projectName, 2 * 1000);
+
+ description = ResourcesPlugin.getWorkspace()
+ .loadProjectDescription(
+ new Path(directory + File.separatorChar
+ + ".project")); //$NON-NLS-1$
+
+ description.setName(​projectName);
+ project.create(description, new SubProgressMonitor(monitor,
+ 1000));
+ project.open(new SubProgressMonitor(monitor, 1000));
+ } finally {
+ monitor.done();
+ }
+ }
 
+ }
 }

--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@subc​lipse.tigris.org
For additional commands, e-mail: cvs-help at subclipse dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

subclipse commit: r1256 - branches/subclipse-3/core/src/org/tigris/subversion/subclipse/core pkorros Panagiotis Korros 2005-02-23 13:18:15 PST
Messages per page: