Index: src/org/polarion/team/svn/connector/javahl/JavaHLConnector.java =================================================================== --- src/org/polarion/team/svn/connector/javahl/JavaHLConnector.java (revision 20055) +++ src/org/polarion/team/svn/connector/javahl/JavaHLConnector.java (working copy) @@ -15,11 +15,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; +import java.util.*; import org.eclipse.team.svn.core.connector.ISVNAnnotationCallback; import org.eclipse.team.svn.core.connector.ISVNChangeListCallback; @@ -67,6 +63,9 @@ * @author Alexander Gurov */ public class JavaHLConnector implements ISVNConnector { + + protected static ProgressMonitorWrapperThread monitorWrapperThread; + protected SVNClient client; protected ISVNCredentialsPrompt prompt; protected Notify2Composite composite; @@ -101,7 +100,6 @@ } } - public void setUsername(String username) { this.client.username(username == null ? "" : username); } @@ -584,7 +582,8 @@ protected void mergeStatus(SVNEntryReference reference1, SVNEntryRevisionReference reference2, SVNRevisionRange []revisions, String path, int depth, long options, ISVNMergeStatusCallback cb, ISVNProgressMonitor monitor) throws SVNConnectorException { final LinkedHashMap tmp = new LinkedHashMap(); ProgressMonitorWrapper wrapper = new ProgressMonitorWrapper(monitor) { - public void notify(SVNNotification arg0) { + @Override + public void notify(SVNNotification arg0) { super.notify(arg0); // only for 1.4 clients: override duplicate changes tmp.put(arg0.path, arg0); @@ -1240,7 +1239,60 @@ return new ISVNProgressMonitor.ItemState(arg0.path, arg0.action, arg0.kind, arg0.mimeType, arg0.contentState, arg0.propState, arg0.revision); } - protected class ProgressMonitorWrapper extends Thread implements ISVNNotificationCallback { + protected static class ProgressMonitorWrapperThread extends Thread { + + private final List monitors = new ArrayList(); + + + public ProgressMonitorWrapperThread() { + super("Progress Monitor Wrapper Thread"); + } + + public void add(ProgressMonitorWrapper monitor) { + synchronized (monitors) { + monitors.add(monitor); + monitors.notify(); + } + } + + public void remove(ProgressMonitorWrapper monitor) { + synchronized (monitors) { + monitors.remove(monitor); + } + } + + private void checkForActivityCancelled() { + synchronized (monitors) { + for(ProgressMonitorWrapper monitor: monitors) { + + if (monitor.monitor.isActivityCancelled()) { + monitor.cancel(); + } + + } + } + } + + @Override + public void run() { + try { + while (!this.isInterrupted()) { + checkForActivityCancelled(); + Thread.sleep(100); + synchronized (monitors) { + if (monitors.isEmpty()) { + monitors.wait(); + } + } + } + } catch (InterruptedException ex) { + + } + } + + } + + protected class ProgressMonitorWrapper implements ISVNNotificationCallback { protected ISVNProgressMonitor monitor; protected int current; protected String errorMessage; @@ -1250,7 +1302,14 @@ this.current = 0; } - public String getErrorMessage() { + public void cancel() { + try { + JavaHLConnector.this.client.cancelOperation(); + } catch (Exception e) { + } + } + + public String getErrorMessage() { return this.errorMessage; } @@ -1263,19 +1322,14 @@ } } - public void run() { - try { - while (!this.monitor.isActivityCancelled() && !this.isInterrupted()) { - Thread.sleep(100); - } - } - catch (InterruptedException ex) { - - } - if (this.monitor.isActivityCancelled()) { - try {JavaHLConnector.this.client.cancelOperation();} catch (Exception ex) {} - } + public void start() { + getMonitorWrapperThread().add(this); } + + public void interrupt() { + getMonitorWrapperThread().remove(this); + } + } protected class RepositoryInfoPrompt implements PromptUserPassword3 { @@ -1347,5 +1401,13 @@ } } + + protected synchronized ProgressMonitorWrapperThread getMonitorWrapperThread() { + if (monitorWrapperThread == null) { + monitorWrapperThread = new ProgressMonitorWrapperThread(); + monitorWrapperThread.start(); + } + return monitorWrapperThread; + } }