Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > subclipse commit: r1419 - in trunk/subclipse/core/src/org/tigris/subversion/subclipse/core: commands

subclipse
Discussion topic

Back to topic list

subclipse commit: r1419 - in trunk/subclipse/core/src/org/tigris/subversion/subclipse/core: commands

Author markphip
Full name Mark Phippard
Date 2005-06-28 17:39:34 PDT
Message Author: markphip
Date: Tue Jun 28 19:39:33 2005
New Revision: 1419

Added:
   trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/ISVNNotifyA​dapter.java
Modified:
   trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/OperationMa​nager.java
   trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/commands/CheckoutC​ommand.java

Log:
Make the Checkout progress info more verbose so that you can see stuff is
happening even if you do not show the console view.

Patch from Martin Letenay

As I've mentioned before I think some long operations are too silent and deserve
more information for the waiting user. As first victim I choose Checkout.
 
I've noticed that in CheckoutCommand there was a lot of duplicity by having two
versions of run() and scrubProjects() methods. The two versions were actually
identically, except for the code for monitoring. (And of course the run(monitor)
is also forking runnable interface) Honestly I hate duplicate code so I merged
these methods back to a single one with the monitor argument as optional.
 
According to log message, these non-monitored versions were created to allow to run
them as a background operation.
 
So after I've merged them into single methods, I created a clone of "backgroundable"
run() method with a name runDirectly().

This runDirectly() method is now being called from CheckoutAsProjectOperation.
 
To get the progress messages from the svnClient I added an optional notifyLister
to the OperationManager.

At the moment it only listens for the logMessage().

For the convenience reasons, there is also a ISVNNotifyAdapter there ...
 

Added: trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/ISVNNotifyA​dapter.java
Url: http://svn.collab.ne​t/viewcvs/subclipse/​trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/ISVNNotifyA​dapter.java?rev=1419​
====================​====================​====================​==================
--- (empty file)
+++ trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/ISVNNotifyA​dapter.java Tue Jun 28 19:39:33 2005
@@ -0,0 +1,51 @@
+package org.tigris.subversio​n.subclipse.core.cli​ent;
+
+import java.io.File;
+
+import org.tigris.subversio​n.svnclientadapter.S​VNNodeKind;
+
+public class ISVNNotifyAdapter implements IConsoleListener {
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#se​tCommand(int)
+ */
+ public void setCommand(int command) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#lo​gCommandLine(java.la​ng.String)
+ */
+ public void logCommandLine(String commandLine) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#lo​gMessage(java.lang.S​tring)
+ */
+ public void logMessage(String message) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#lo​gError(java.lang.Str​ing)
+ */
+ public void logError(String message) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#lo​gRevision(long)
+ */
+ public void logRevision(long revision) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#lo​gCompleted(java.lang​.String)
+ */
+ public void logCompleted(String message) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener#on​Notify(java.io.File,​ org.tigris.subversio​n.svnclientadapter.S​VNNodeKind)
+ */
+ public void onNotify(File path, SVNNodeKind kind) {
+ }
+
+}

Modified: trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/OperationMa​nager.java
Url: http://svn.collab.ne​t/viewcvs/subclipse/​trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/OperationMa​nager.java?rev=1419​&p1=trunk/subclip​se/core/src/org/tigr​is/subversion/subcli​pse/core/client/Oper​ationManager.java​&p2=trunk/subclipse​/core/src/org/tigris​/subversion/subclips​e/core/client/Operat​ionManager.java&​r1=1418&r2=1419
====================​====================​====================​==================
--- trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/OperationMa​nager.java (original)
+++ trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/client/OperationMa​nager.java Tue Jun 28 19:39:33 2005
@@ -48,6 +48,9 @@
 
     private ISVNClientAdapter svnClient = null;
 
+ // notify listener where getMessage notifications should be forwarded
+ private ISVNNotifyListener messageNotifyListener = null;
+
     private static OperationManager instance;
 
     /*
@@ -79,6 +82,15 @@
     }
 
     /**
+ * Begins a batch of operations.
+ * Forward notifications to messageNotifyListener
+ */
+ public void beginOperation(ISVNC​lientAdapter svnClient, ISVNNotifyListener messageNotifyListener) {
+ this.messageNotifyListener = messageNotifyListener;
+ beginOperation(svnClient);
+ }
+
+ /**
      * Ends a batch of operations. Pending changes are committed only when the
      * number of calls to endOperation() balances those to beginOperation().
      */
@@ -104,6 +116,7 @@
             }
         } finally {
             lock.release();
+ messageNotifyListener = null;
         }
     }
 
@@ -164,6 +177,10 @@
     }
 
     public void logMessage(String message) {
+ if (messageNotifyListener != null)
+ {
+ messageNotifyListene​r.logMessage(message​);
+ }
     }
 
     public void setCommand(int command) {

Modified: trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/commands/CheckoutC​ommand.java
Url: http://svn.collab.ne​t/viewcvs/subclipse/​trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/commands/CheckoutC​ommand.java?rev=1419​&p1=trunk/subcli​pse/core/src/org/tig​ris/subversion/subcl​ipse/core/commands/C​heckoutCommand.java​&p2=trunk/subclip​se/core/src/org/tigr​is/subversion/subcli​pse/core/commands/Ch​eckoutCommand.java​&r1=1418&r2=14​19
====================​====================​====================​==================
--- trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/commands/CheckoutC​ommand.java (original)
+++ trunk/subclipse/core​/src/org/tigris/subv​ersion/subclipse/cor​e/commands/CheckoutC​ommand.java Tue Jun 28 19:39:33 2005
@@ -1,388 +1,305 @@
-/******************​********************​********************​********************​
- * 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 the following URL:
- * http://www.eclipse.o​rg/legal/cpl-v10.htm​l
- * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
- *
- * All Rights are Reserved by the various authors.
- ********************​********************​********************​*******************/​
-package org.tigris.subversio​n.subclipse.core.com​mands;
-
-import java.io.File;
-
-import org.eclipse.core.res​ources.IContainer;
-import org.eclipse.core.res​ources.IFile;
-import org.eclipse.core.res​ources.IProject;
-import org.eclipse.core.res​ources.IResource;
-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.team.cor​e.RepositoryProvider​;
-import org.eclipse.team.cor​e.TeamException;
-import org.tigris.subversio​n.subclipse.core.ISV​NLocalFolder;
-import org.tigris.subversio​n.subclipse.core.ISV​NRemoteFolder;
-import org.tigris.subversio​n.subclipse.core.ISV​NRunnable;
-import org.tigris.subversio​n.subclipse.core.Pol​icy;
-import org.tigris.subversio​n.subclipse.core.SVN​Exception;
-import org.tigris.subversio​n.subclipse.core.SVN​ProviderPlugin;
-import org.tigris.subversio​n.subclipse.core.cli​ent.OperationManager​;
-import org.tigris.subversio​n.subclipse.core.res​ources.RemoteFolder;​
-import org.tigris.subversio​n.subclipse.core.res​ources.SVNWorkspaceR​oot;
-import org.tigris.subversio​n.svnclientadapter.I​SVNClientAdapter;
-import org.tigris.subversio​n.svnclientadapter.I​SVNDirEntry;
-import org.tigris.subversio​n.svnclientadapter.S​VNClientException;
-import org.tigris.subversio​n.svnclientadapter.S​VNNodeKind;
-import org.tigris.subversio​n.svnclientadapter.S​VNRevision;
-
-/**
- * Checkout the remote resources into the local workspace as projects. Each
- * resource will be checked out into the corresponding project. You can use
- * getProject to get a project for a given remote Folder
- *
- * Resources existing in the local file system at the target project location
- * but now known to the workbench will be overwritten.
- *
- * @author cedric chabanois (cchab at tigris.org)
- */
-public class CheckoutCommand implements ISVNCommand {
-
- private ISVNRemoteFolder[] resources;
-
- private IProject[] projects;
-
- public CheckoutCommand(ISVN​RemoteFolder[] resources, IProject[] projects) {
- this.resources = resources;
- this.projects = projects;
- }
-
- public void run() throws SVNException {
- ISVNLocalFolder root = SVNWorkspaceRoot
- .getSVNFolderFor(Res​ourcesPlugin.getWork​space()
- .getRoot());
- try {
- // Prepare the target projects to receive resources
- scrubProjects(projects);
- for (int i = 0; i < resources.length; i++) {
- IProject project = null;
- RemoteFolder resource = (RemoteFolder) resources[i];
-
- project = projects[i];
- boolean deleteDotProject = false;
- // Perform the checkout
- ISVNClientAdapter svnClient = resource.getRepository()
- .getSVNClient();
-
- // check if the remote project has a .project file
- ISVNDirEntry[] rootFiles = svnClient.getList(resource
- .getUrl(), SVNRevision.HEAD, false);
- for (int j = 0; j < rootFiles.length; j++) {
- if ((rootFiles[j].getNodeKind() == SVNNodeKind.FILE)
- && (".project".equals(rootFiles[j]
- .getPath()))) {
- deleteDotProject = true;
- }
- }
-
- File destPath;
- if (project.getLocation() == null) {
- // project.getLocation is null if the project does
- // not exist in the workspace
- destPath = new File(root.getIResource()
- .getLocation().toFile(), project.getName());
- try {
- // we create the directory corresponding to the
- // project and we open it
- project.create(null);
- project.open(null);
- } catch (CoreException e1) {
- throw new SVNException("Cannot create project to checkout to", e1);
- }
-
-
- } else {
- destPath = project.getLocation().toFile();
- }
-
- //delete the project file if the flag gets set.
- //fix for 54
- if (deleteDotProject) {
-
- IFile projectFile = project.getFile(".project");
- if (projectFile != null) {
- try {
- // delete the project file, force, no history,
- // without progress monitor
- projectFile.delete(true, false, null);
- } catch (CoreException e1) {
- throw new SVNException("Cannot delete .project before checkout",e1);
- }
- }
- }
-
- OperationManager operationHandler = OperationManager
- .getInstance();
- try {
- operationHandler.beg​inOperation(svnClien​t);
- svnClient.checkout(r​esource.getUrl(), destPath,
- SVNRevision.HEAD, true);
- } catch (SVNClientException e) {
- throw new SVNException("cannot checkout");
- } finally {
- operationHandler.end​Operation();
- }
-
- // Bring the project into the workspace
- refreshProjects(new IProject[] { project }, null);
- } //for
- } catch (SVNClientException ce) {
- throw new SVNException("Error Getting Dir list", ce);
- }
- }
-
- /*
- * Delete the target projects before checking out
- */
- private void scrubProjects(IProject[] projects)
- throws SVNException {
- if (projects == null) return;
- try {
- for (int i = 0; i < projects.length; i++) {
- IProject project = projects[i];
- if (project != null && project.exists()) {
- if (!project.isOpen()) {
- project.open(null);
- }
- // 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
-
- // unmap the project from any previous repository provider
- if (RepositoryProvider.​getProvider(project)​ != null)
- RepositoryProvider.u​nmap(project);
- IResource[] children = project
- .members(IContainer.​INCLUDE_TEAM_PRIVATE​_MEMBERS);
- try {
- for (int j = 0; j < children.length; j++) {
- if (!children[j].getNam​e().equals(".project​")) {//$NON-NLS-1$
- children[j].delete(true /* force */, null);
- }
- }
- } finally {
- // subMonitor.done();
- }
- } else if (project != null) {
- // Make sure there is no directory in the local file system.
- File location = new File(project.getPare​nt().getLocation()
- .toFile(), project.getName());
- if (location.exists()) {
- deepDelete(location);
- }
- }
- }
- } catch (CoreException e) {
- throw SVNException.wrapException(e);
- } finally {
-// monitor.done();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.tigris.subversio​n.subclipse.core.com​mands.ISVNCommand#ru​n(org.eclipse.core.r​untime.IProgressMoni​tor)
- */
- public void run(IProgressMonitor monitor) throws SVNException {
- SVNProviderPlugin.run(new ISVNRunnable() {
- public void run(IProgressMonitor pm) throws SVNException {
- pm.beginTask(null, 1000 * resources.length);
-
- // Get the location of the workspace root
- ISVNLocalFolder root = SVNWorkspaceRoot
- .getSVNFolderFor(Res​ourcesPlugin.getWork​space()
- .getRoot());
-
- try {
- // Prepare the target projects to receive resources
- scrubProjects(projects, Policy.subMonitorFor(pm, 100));
-
- for (int i = 0; i < resources.length; i++) {
- IProject project = null;
- RemoteFolder resource = (RemoteFolder) resources[i];
-
- project = projects[i];
- boolean deleteDotProject = false;
- // Perform the checkout
- ISVNClientAdapter svnClient = resource.getRepository()
- .getSVNClient();
-
- // check if the remote project has a .project file
- ISVNDirEntry[] rootFiles = svnClient.getList(resource
- .getUrl(), SVNRevision.HEAD, false);
- for (int j = 0; j < rootFiles.length; j++) {
- if ((rootFiles[j].getNodeKind() == SVNNodeKind.FILE)
- && (".project".equals(rootFiles[j]
- .getPath()))) {
- deleteDotProject = true;
- }
- }
-
- File destPath;
- if (project.getLocation() == null) {
- // project.getLocation is null if the project does
- // not exist in the workspace
- destPath = new File(root.getIResource()
- .getLocation().toFile(), project.getName());
- try {
- // we create the directory corresponding to the
- // project and we open it
- project.create(null);
- project.open(null);
- } catch (CoreException e1) {
- throw new SVNException("Cannot create project to checkout to", e1);
- }
-
-
- } else {
- destPath = project.getLocation().toFile();
- }
-
- //delete the project file if the flag gets set.
- //fix for 54
- if (deleteDotProject) {
-
- IFile projectFile = project.getFile(".project");
- if (projectFile != null) {
- try {
- // delete the project file, force, no history,
- // without progress monitor
- projectFile.delete(true, false, null);
- } catch (CoreException e1) {
- throw new SVNException("Cannot delete .project before checkout",e1);
- }
- }
- }
-
- OperationManager operationHandler = OperationManager
- .getInstance();
- try {
- operationHandler.beg​inOperation(svnClien​t);
- svnClient.checkout(r​esource.getUrl(), destPath,
- SVNRevision.HEAD, true);
- pm.worked(800);
- } catch (SVNClientException e) {
- throw new SVNException("cannot checkout");
- } finally {
- operationHandler.end​Operation();
- }
-
- // Bring the project into the workspace
- refreshProjects(new IProject[] { project }, Policy
- .subMonitorFor(pm, 100));
- } //for
- } catch (SVNClientException ce) {
- throw new SVNException("Error Getting Dir list", ce);
- } finally {
- pm.done();
- }
- } // run
- }, Policy.monitorFor(monitor));
- }
-
- /*
- * Delete the target projects before checking out
- */
- private void scrubProjects(IProject[] projects, IProgressMonitor monitor)
- throws SVNException {
- if (projects == null) {
- monitor.done();
- return;
- }
- monitor
- .beginTask(
- Policy.bind("SVNProv​ider.Scrubbing_proje​cts_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(monito​r, 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("SVNProvider.S​crubbing_local_proje​ct_1")); //$NON-NLS-1$
- // unmap the project from any previous repository provider
- if (RepositoryProvider.​getProvider(project)​ != null)
- RepositoryProvider.u​nmap(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].getNam​e().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.getPare​nt().getLocation()
- .toFile(), project.getName());
- if (location.exists()) {
- deepDelete(location);
- }
- }
- }
- } catch (CoreException e) {
- throw SVNException.wrapException(e);
- } finally {
- monitor.done();
- }
- }
-
- /*
- * delete a folder recursively
- */
- private 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 provided projects into the workspace
- */
- private void refreshProjects(IProject[] projects, IProgressMonitor monitor)
- throws SVNException {
- if (monitor != null)
- monitor.beginTask(
- Policy.bind("SVNProv​ider.Creating_projec​ts_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, SVNProviderPlugin.getTypeId());
- RepositoryProvider.g​etProvider(project, SVNProviderPlugin
- .getTypeId());
- }
- } catch (TeamException e) {
- throw new SVNException("Cannot map the project with svn provider",e);
- } finally {
- if (monitor != null) monitor.done();
- }
- }
-
+/******************​********************​********************​********************​
+ * 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 the following URL:
+ * http://www.eclipse.o​rg/legal/cpl-v10.htm​l
+ * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
+ *
+ * All Rights are Reserved by the various authors.
+ ********************​********************​********************​*******************/​
+package org.tigris.subversio​n.subclipse.core.com​mands;
+
+import java.io.File;
+
+import org.eclipse.core.res​ources.IContainer;
+import org.eclipse.core.res​ources.IFile;
+import org.eclipse.core.res​ources.IProject;
+import org.eclipse.core.res​ources.IResource;
+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.team.cor​e.RepositoryProvider​;
+import org.eclipse.team.cor​e.TeamException;
+import org.tigris.subversio​n.subclipse.core.ISV​NLocalFolder;
+import org.tigris.subversio​n.subclipse.core.ISV​NRemoteFolder;
+import org.tigris.subversio​n.subclipse.core.ISV​NRunnable;
+import org.tigris.subversio​n.subclipse.core.Pol​icy;
+import org.tigris.subversio​n.subclipse.core.SVN​Exception;
+import org.tigris.subversio​n.subclipse.core.SVN​ProviderPlugin;
+import org.tigris.subversio​n.subclipse.core.cli​ent.ISVNNotifyAdapte​r;
+import org.tigris.subversio​n.subclipse.core.cli​ent.OperationManager​;
+import org.tigris.subversio​n.subclipse.core.res​ources.RemoteFolder;​
+import org.tigris.subversio​n.subclipse.core.res​ources.SVNWorkspaceR​oot;
+import org.tigris.subversio​n.svnclientadapter.I​SVNClientAdapter;
+import org.tigris.subversio​n.svnclientadapter.I​SVNDirEntry;
+import org.tigris.subversio​n.svnclientadapter.I​SVNNotifyListener;
+import org.tigris.subversio​n.svnclientadapter.S​VNClientException;
+import org.tigris.subversio​n.svnclientadapter.S​VNNodeKind;
+import org.tigris.subversio​n.svnclientadapter.S​VNRevision;
+
+/**
+ * Checkout the remote resources into the local workspace as projects. Each
+ * resource will be checked out into the corresponding project. You can use
+ * getProject to get a project for a given remote Folder
+ *
+ * Resources existing in the local file system at the target project location
+ * but now known to the workbench will be overwritten.
+ *
+ * @author cedric chabanois (cchab at tigris.org)
+ */
+public class CheckoutCommand implements ISVNCommand {
+
+ private ISVNRemoteFolder[] resources;
+
+ private IProject[] projects;
+
+ public CheckoutCommand(ISVN​RemoteFolder[] resources, IProject[] projects) {
+ this.resources = resources;
+ this.projects = projects;
+ }
+
+ public void run() throws SVNException {
+ basicRun(null);
+ }
+
+ public void runDirectly(IProgressMonitor pm) throws SVNException {
+ basicRun(pm);
+ }
+
+ private void basicRun(final IProgressMonitor pm) throws SVNException {
+ if (pm != null)
+ {
+ pm.beginTask(null, 1000 * resources.length);
+ }
+
+ // Get the location of the workspace root
+ ISVNLocalFolder root = SVNWorkspaceRoot.get​SVNFolderFor(Resourc​esPlugin
+ .getWorkspace().getRoot());
+
+ try {
+ // Prepare the target projects to receive resources
+ scrubProjects(projects, (pm != null) ? Policy
+ .subMonitorFor(pm, 100) : null);
+
+ for (int i = 0; i < resources.length; i++) {
+ IProject project = null;
+ RemoteFolder resource = (RemoteFolder) resources[i];
+
+ project = projects[i];
+ boolean deleteDotProject = false;
+ // Perform the checkout
+ ISVNClientAdapter svnClient = resource.getRepository()
+ .getSVNClient();
+
+ // check if the remote project has a .project file
+ ISVNDirEntry[] rootFiles = svnClient.getList(re​source.getUrl(),
+ SVNRevision.HEAD, false);
+ for (int j = 0; j < rootFiles.length; j++) {
+ if ((rootFiles[j].getNodeKind() == SVNNodeKind.FILE)
+ && (".project".equals(r​ootFiles[j].getPath(​)))) {
+ deleteDotProject = true;
+ }
+ }
+
+ File destPath;
+ if (project.getLocation() == null) {
+ // project.getLocation is null if the project does
+ // not exist in the workspace
+ destPath = new File(root.getIResour​ce().getLocation()
+ .toFile(), project.getName());
+ try {
+ // we create the directory corresponding to the
+ // project and we open it
+ project.create(null);
+ project.open(null);
+ } catch (CoreException e1) {
+ throw new SVNException(
+ "Cannot create project to checkout to", e1);
+ }
+
+ } else {
+ destPath = project.getLocation().toFile();
+ }
+
+ //delete the project file if the flag gets set.
+ //fix for 54
+ if (deleteDotProject) {
+
+ IFile projectFile = project.getFile(".project");
+ if (projectFile != null) {
+ try {
+ // delete the project file, force, no history,
+ // without progress monitor
+ projectFile.delete(true, false, null);
+ } catch (CoreException e1) {
+ throw new SVNException(
+ "Cannot delete .project before checkout",
+ e1);
+ }
+ }
+ }
+
+ OperationManager operationHandler = OperationManager
+ .getInstance();
+ ISVNNotifyListener notifyListener = new ISVNNotifyAdapter() {
+ public void logMessage(String message) {
+ if (pm != null)
+ {
+ pm.subTask(message);
+ }
+ }
+ };
+ try {
+ operationHandler.beg​inOperation(svnClien​t, notifyListener);
+ svnClient.checkout(r​esource.getUrl(), destPath,
+ SVNRevision.HEAD, true);
+ if (pm != null) {
+ pm.worked(800);
+ }
+ } catch (SVNClientException e) {
+ throw new SVNException("cannot checkout");
+ } finally {
+ operationHandler.end​Operation();
+ }
+
+ // Bring the project into the workspace
+ refreshProjects(new IProject[] { project },
+ (pm != null) ? Policy.subMonitorFor(pm, 100) : null);
+ } //for
+ } catch (SVNClientException ce) {
+ throw new SVNException("Error Getting Dir list", ce);
+ } finally {
+ if (pm != null) {
+ pm.done();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.tigris.subversio​n.subclipse.core.com​mands.ISVNCommand#ru​n(org.eclipse.core.r​untime.IProgressMoni​tor)
+ */
+ public void run(IProgressMonitor monitor) throws SVNException {
+ SVNProviderPlugin.run(new ISVNRunnable() {
+ public void run(IProgressMonitor pm) throws SVNException {
+ basicRun(pm);
+ } // run
+ }, Policy.monitorFor(monitor));
+ }
+
+ /*
+ * Delete the target projects before checking out
+ * @param monitor - may be null !
+ */
+ private void scrubProjects(IProject[] projects, IProgressMonitor monitor)
+ throws SVNException {
+ if (projects == null) {
+ if (monitor !=null)
+ {
+ monitor.done();
+ }
+ return;
+ }
+ if (monitor != null)
+ {
+ monitor
+ .beginTask(
+ Policy.bind("SVNProv​ider.Scrubbing_proje​cts_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((monitor != null) ? Policy.subMonitorFor(monitor, 10) : null);
+ }
+ // 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
+ if (monitor != null)
+ {
+ monitor.subTask(Policy
+ .bind("SVNProvider.S​crubbing_local_proje​ct_1")); //$NON-NLS-1$
+ }
+ // unmap the project from any previous repository provider
+ if (RepositoryProvider.​getProvider(project)​ != null)
+ RepositoryProvider.u​nmap(project);
+ IResource[] children = project
+ .members(IContainer.​INCLUDE_TEAM_PRIVATE​_MEMBERS);
+ IProgressMonitor subMonitor = (monitor != null) ? Policy.subMonitorFor(monitor,
+ 80) : null;
+ if (subMonitor != null)
+ {
+ subMonitor.beginTask(null, children.length * 100);
+ }
+ try {
+ for (int j = 0; j < children.length; j++) {
+ if (!children[j].getNam​e().equals(".project​")) {//$NON-NLS-1$
+ children[j].delete(true /* force */, (subMonitor != null) ? Policy
+ .subMonitorFor(subMonitor, 100) : null);
+ }
+ }
+ } finally {
+ if (subMonitor != null)
+ {
+ subMonitor.done();
+ }
+ }
+ } else if (project != null) {
+ // Make sure there is no directory in the local file system.
+ File location = new File(project.getPare​nt().getLocation()
+ .toFile(), project.getName());
+ if (location.exists()) {
+ deepDelete(location);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ throw SVNException.wrapException(e);
+ } finally {
+ if (monitor != null)
+ {
+ monitor.done();
+ }
+ }
+ }
+
+ /*
+ * delete a folder recursively
+ */
+ private 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 provided projects into the workspace
+ */
+ private void refreshProjects(IProject[] projects, IProgressMonitor monitor)
+ throws SVNException {
+ if (monitor != null)
+ monitor.beginTask(
+ Policy.bind("SVNProv​ider.Creating_projec​ts_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, SVNProviderPlugin.getTypeId());
+ RepositoryProvider.g​etProvider(project, SVNProviderPlugin
+ .getTypeId());
+ }
+ } catch (TeamException e) {
+ throw new SVNException("Cannot map the project with svn provider",e);
+ } finally {
+ if (monitor != null) monitor.done();
+ }
+ }
+
 }

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

Messages

Show all messages in topic

subclipse commit: r1419 - in trunk/subclipse/core/src/org/tigris/subversion/subclipse/core: commands markphip Mark Phippard 2005-06-28 17:39:34 PDT
Messages per page: