Revert "Bug 408513 - Change the Sync options menu to include "Sync Active Before"

Revert due to problems found during testing

This reverts commit 167c753a5f49fa6b22fef1165492276465761446.
diff --git a/rdt/org.eclipse.ptp.rdt.sync.cdt.core/src/org/eclipse/ptp/internal/rdt/sync/cdt/core/remotemake/SyncCommandLauncher.java b/rdt/org.eclipse.ptp.rdt.sync.cdt.core/src/org/eclipse/ptp/internal/rdt/sync/cdt/core/remotemake/SyncCommandLauncher.java
index cf0765a..7add4d4 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.cdt.core/src/org/eclipse/ptp/internal/rdt/sync/cdt/core/remotemake/SyncCommandLauncher.java
+++ b/rdt/org.eclipse.ptp.rdt.sync.cdt.core/src/org/eclipse/ptp/internal/rdt/sync/cdt/core/remotemake/SyncCommandLauncher.java
@@ -394,26 +394,12 @@
 		SyncConfig config = SyncConfigManager.getActive(getProject());
 		if (shouldSyncBeforeRun && config.isSyncOnPreBuild()) {
 			switch (SyncManager.getSyncMode(getProject())) {
-			case ACTIVE_BEFORE_BUILD:
-				SyncManager.syncBlocking(null, getProject(), SyncFlag.LR_ONLY, monitor, null);
-				break;
-			
 			case ACTIVE:
-				SyncManager.syncJoin(getProject(),config);
+				SyncManager.syncBlocking(null, getProject(), SyncFlag.LR_ONLY, monitor, null);
 				break;
 
 			case ALL:
-				SyncManager.syncJoin(getProject(),config);
-				break;
-				
-			case NONE:
-				break;
-				
-			case UNAVAILABLE:
-				break;
-				
-			default:
-				// Shouldn't ever happen
+				SyncManager.syncAllBlocking(null, getProject(), SyncFlag.LR_ONLY, null);
 				break;
 			}
 		}
diff --git a/rdt/org.eclipse.ptp.rdt.sync.core/META-INF/MANIFEST.MF b/rdt/org.eclipse.ptp.rdt.sync.core/META-INF/MANIFEST.MF
index a82fe33..3a33d02 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.core/META-INF/MANIFEST.MF
+++ b/rdt/org.eclipse.ptp.rdt.sync.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %Bundle-Name.0
 Bundle-SymbolicName: org.eclipse.ptp.rdt.sync.core;singleton:=true
-Bundle-Version: 4.1.0.qualifier
+Bundle-Version: 4.0.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.core.filesystem,
diff --git a/rdt/org.eclipse.ptp.rdt.sync.core/pom.xml b/rdt/org.eclipse.ptp.rdt.sync.core/pom.xml
index cf0e0e3..059e48a 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.core/pom.xml
+++ b/rdt/org.eclipse.ptp.rdt.sync.core/pom.xml
@@ -11,6 +11,6 @@
   </parent>
 
   <artifactId>org.eclipse.ptp.rdt.sync.core</artifactId>
-  <version>4.1.0-SNAPSHOT</version>
+  <version>4.0.0-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncFlag.java b/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncFlag.java
index b71482b..209fd59 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncFlag.java
+++ b/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncFlag.java
@@ -30,13 +30,7 @@
 	 * Sync remote to local

 	 * @since 4.0

 	 */

-	SYNC_RL,

-	

-	/**

-	 * Wait only

-	 * @since 4.1

-	 */

-	WAIT_FOR_LR;

+	SYNC_RL;

 

 	/**

 	 * Convenience flag set for sync'ing both directions (from local to remote and from remote to local).

diff --git a/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncManager.java b/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncManager.java
index e5ceaff..d2e9c30 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncManager.java
+++ b/rdt/org.eclipse.ptp.rdt.sync.core/src/org/eclipse/ptp/rdt/sync/core/SyncManager.java
@@ -10,7 +10,9 @@
  *******************************************************************************/
 package org.eclipse.ptp.rdt.sync.core;
 
+import java.io.IOException;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -90,20 +92,12 @@
 		}
 	}
 
-	// ACTIVE: Sync with current active configuration after saving
-	// ACTIVE_BEFORE_BUILD: Don't sync after saving, instead sync just before building
-	// ALL: Sync with all configurations after saving
+	// ACTIVE: Sync with current active configuration
+	// ALL: Sync with all configurations
 	// NONE: Do not transfer files but still call sync and do bookkeeping
 	// UNAVAILABLE: Do not call sync. (Used internally during project creation and deletion.)
 	public static enum SyncMode {
-		/**
-		 * @since 4.1
-		 */
-		ACTIVE_BEFORE_BUILD,
-		ACTIVE,
-		ALL,
-		NONE,
-		UNAVAILABLE
+		ACTIVE, ALL, NONE, UNAVAILABLE
 	};
 
 	private static final String SYNC_MODE_KEY = "sync-mode"; //$NON-NLS-1$
@@ -618,21 +612,6 @@
 			ISyncExceptionHandler seHandler) throws CoreException {
 		return sync(delta, project, syncFlags, true, true, seHandler, monitor);
 	}
-	
-	/**
-	 * Wait until there are no synchronizations pending for this project/location pair.
-	 * @param project
-	 * @param config
-	 * @throws CoreException 
-	 * @since 4.1
-	 */
-	public static void syncJoin(IProject project,SyncConfig config) throws CoreException {
-		String currentSyncServiceId = config.getSyncProviderId();
-		ISynchronizeService syncService = SyncManager.getSyncService(currentSyncServiceId);
-		Set<SyncFlag> syncFlags = new HashSet<SyncFlag>();
-		syncFlags.add(SyncFlag.WAIT_FOR_LR);
-		syncService.synchronize(project, config.getRemoteLocation(), null, null, syncFlags);
-	}
 
 	// Static class - do not allow creating of instances
 	private SyncManager() {
diff --git a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/internal/rdt/sync/git/core/GitSyncService.java b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/internal/rdt/sync/git/core/GitSyncService.java
index b5d6858..f53bb43 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/internal/rdt/sync/git/core/GitSyncService.java
+++ b/rdt/org.eclipse.ptp.rdt.sync.git.core/src/org/eclipse/ptp/internal/rdt/sync/git/core/GitSyncService.java
@@ -19,6 +19,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.eclipse.core.resources.IFile;
@@ -58,36 +59,13 @@
 	// Implement storage of local JGit repositories and Git repositories.
 	private static final Map<IPath, JGitRepo> localDirectoryToJGitRepoMap = new HashMap<IPath, JGitRepo>();
 	private static final Map<RemoteLocation, GitRepo> remoteLocationToGitRepoMap = new HashMap<RemoteLocation, GitRepo>();
-	
-	private static class SyncInt {
-		private int value;
-		public SyncInt(int initialValue) {
-			value = initialValue;
-		}
-		public synchronized int get() {
-			return value;
-		}
-		public synchronized int incrementAndGet() {
-			return ++value;
-		}
-		public synchronized int decrementAndGet() {
-			--value;
-			notifyAll();
-			return value;
-		}
-		public synchronized void waitForZero() throws InterruptedException {
-			while(value != 0) {
-				wait();
-			}
-		}
-	}
 
 	// Variables for managing sync threads
 	private static final ReentrantLock syncLock = new ReentrantLock();
-	private static final ConcurrentMap<ProjectAndRemoteLocationPair, SyncInt> syncLRPending =
-			new ConcurrentHashMap<ProjectAndRemoteLocationPair, SyncInt>();
-	private static final ConcurrentMap<ProjectAndRemoteLocationPair, SyncInt> syncRLPending =
-			new ConcurrentHashMap<ProjectAndRemoteLocationPair, SyncInt>();
+	private static final ConcurrentMap<ProjectAndRemoteLocationPair, AtomicLong> syncLRPending =
+			new ConcurrentHashMap<ProjectAndRemoteLocationPair, AtomicLong>();
+	private static final ConcurrentMap<ProjectAndRemoteLocationPair, AtomicLong> syncRLPending =
+			new ConcurrentHashMap<ProjectAndRemoteLocationPair, AtomicLong>();
 
 	// Entry indicates that the remote location has a clean (up-to-date) file filter for the project
 	private static final Set<LocalAndRemoteLocationPair> cleanFileFilterMap = new HashSet<LocalAndRemoteLocationPair>();
@@ -95,7 +73,7 @@
 	private static final Set<LocalAndRemoteLocationPair> localChangesPushed = new HashSet<LocalAndRemoteLocationPair>();
 
 	// Boilerplate class for IPath and RemoteLocation Pair
-	private static class LocalAndRemoteLocationPair {
+	private class LocalAndRemoteLocationPair {
 		IPath localDir;
 		RemoteLocation remoteLoc;
 
@@ -123,6 +101,7 @@
 		public int hashCode() {
 			final int prime = 31;
 			int result = 1;
+			result = prime * result + getOuterType().hashCode();
 			result = prime * result
 					+ ((localDir == null) ? 0 : localDir.hashCode());
 			result = prime * result
@@ -142,6 +121,9 @@
 				return false;
 			}
 			LocalAndRemoteLocationPair other = (LocalAndRemoteLocationPair) obj;
+			if (!getOuterType().equals(other.getOuterType())) {
+				return false;
+			}
 			if (localDir == null) {
 				if (other.localDir != null) {
 					return false;
@@ -158,10 +140,14 @@
 			}
 			return true;
 		}
+
+		private GitSyncService getOuterType() {
+			return GitSyncService.this;
+		}
 	}
 
 	// Boilerplate class for IProject and RemoteLocation Pair
-	private static class ProjectAndRemoteLocationPair {
+	private class ProjectAndRemoteLocationPair {
 		IProject project;
 		RemoteLocation remoteLoc;
 
@@ -181,6 +167,7 @@
 		public int hashCode() {
 			final int prime = 31;
 			int result = 1;
+			result = prime * result + getOuterType().hashCode();
 			result = prime * result
 					+ ((project == null) ? 0 : project.hashCode());
 			result = prime * result
@@ -200,6 +187,9 @@
 				return false;
 			}
 			ProjectAndRemoteLocationPair other = (ProjectAndRemoteLocationPair) obj;
+			if (!getOuterType().equals(other.getOuterType())) {
+				return false;
+			}
 			if (project == null) {
 				if (other.project != null) {
 					return false;
@@ -216,6 +206,10 @@
 			}
 			return true;
 		}
+
+		private GitSyncService getOuterType() {
+			return GitSyncService.this;
+		}
 	}
 
 	/**
@@ -432,24 +426,7 @@
 		if (project == null || rl == null) {
 			throw new NullPointerException();
 		}
-		// Make a copy to protect against the remote location
-		// being changed by another thread.
 		RemoteLocation remoteLoc = new RemoteLocation(rl);
-
-		ProjectAndRemoteLocationPair syncTarget = new ProjectAndRemoteLocationPair(project, remoteLoc);
-		if(syncFlags.contains(SyncFlag.WAIT_FOR_LR)) {
-			try {
-				SyncInt si = syncLRPending.get(syncTarget);
-				if (si != null) {
-					si.waitForZero();
-				}
-			} catch (InterruptedException e) {
-				// This shouldn't happen.
-				Activator.log(e);
-			}
-			return;
-		}
-		
 		RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 100);
 
 		try {
@@ -466,13 +443,14 @@
 			 * cases, we want to ensure repos are synchronized regardless of the passed delta, which can be set to null.
 			 */
 			
+			ProjectAndRemoteLocationPair syncTarget = new ProjectAndRemoteLocationPair(project, remoteLoc);
 		    Boolean syncLR = syncFlags.contains(SyncFlag.SYNC_LR);
 		    Boolean syncRL = syncFlags.contains(SyncFlag.SYNC_RL);
 			Set<SyncFlag> modifiedSyncFlags = new HashSet<SyncFlag>(syncFlags);
 
 			// Do not sync LR (local-to-remote) if another thread is already waiting to do it.
 			if (syncLR) {
-				SyncInt threadCount = syncLRPending.putIfAbsent(syncTarget, new SyncInt(1));
+				AtomicLong threadCount = syncLRPending.putIfAbsent(syncTarget, new AtomicLong(1));
 				if (threadCount != null) {
 					if (threadCount.get() > 0) {
 						syncLR = false;
@@ -485,7 +463,7 @@
 
 			// Do not sync RL (remote-to-local) if another thread is already waiting to do it.
 			if (syncRL) {
-				SyncInt threadCount = syncRLPending.putIfAbsent(syncTarget, new SyncInt(1));
+				AtomicLong threadCount = syncRLPending.putIfAbsent(syncTarget, new AtomicLong(1));
 				if (threadCount != null) {
 					if (threadCount.get() > 0) {
 						syncRL = false;
@@ -512,12 +490,12 @@
 				throw new CoreException(new Status(IStatus.CANCEL, Activator.PLUGIN_ID, Messages.GitSyncService_5));
 			} finally {
 				if (syncLR) {
-					SyncInt LRPending = syncLRPending.get(syncTarget);
+					AtomicLong LRPending = syncLRPending.get(syncTarget);
 					assert(LRPending != null) : Messages.GitSyncService_20;
 					LRPending.decrementAndGet();
 				}
 				if (syncRL) {
-					SyncInt RLPending = syncRLPending.get(syncTarget);
+					AtomicLong RLPending = syncRLPending.get(syncTarget);
 					assert(RLPending != null) : Messages.GitSyncService_21;
 					RLPending.decrementAndGet();
 				}
@@ -809,4 +787,4 @@
     	}, "Set repository as derived thread"); //$NON-NLS-1$
     	setDerivedThread.start();
     }
-}
+}
\ No newline at end of file
diff --git a/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.properties b/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.properties
index 8af62ad..c3c8a47 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.properties
+++ b/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.properties
@@ -30,11 +30,10 @@
 SetActive.name = Set Active
 AutoSync.name = Auto-Sync (Global)
 AutoSyncSettings.name = Auto-Sync Settings
-SyncActive.name = Sync Active After Save
-SyncActiveBeforeBuild.name = Sync Active Before Build
-SyncAll.name = Sync All After Save
+SyncActive.name = Sync Active
+SyncAll.name = Sync All
 SyncNone.name = Sync None
 ManageSync.name = Manage...
 SynchronizedProjectsPreferencePage.name = Synchronized Projects
 FileFilteringPreferencePage.name = File Filtering
-SyncCommand.tooltip=Synchronize the selected project
+SyncCommand.tooltip=Synchronize the selected project
\ No newline at end of file
diff --git a/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.xml b/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.xml
index 4b6402b..48d2ee6 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.xml
+++ b/rdt/org.eclipse.ptp.rdt.sync.ui/plugin.xml
@@ -135,15 +135,6 @@
                </command>
                <command
                      commandId="org.eclipse.ptp.rdt.sync.ui.SyncCommand"
-                     label="%SyncActiveBeforeBuild.name"
-                     style="radio">
-                  <parameter
-                        name="org.eclipse.ptp.rdt.sync.ui.syncCommand.syncModeParameter"
-                        value="set_active_before_build">
-                  </parameter>
-               </command>
-               <command
-                     commandId="org.eclipse.ptp.rdt.sync.ui.SyncCommand"
                      label="%SyncAll.name"
                      style="radio">
                   <parameter
diff --git a/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/ResourceChangeListener.java b/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/ResourceChangeListener.java
index e5e9742..a69f7f4 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/ResourceChangeListener.java
+++ b/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/ResourceChangeListener.java
@@ -12,6 +12,9 @@
  *******************************************************************************/
 package org.eclipse.ptp.internal.rdt.sync.ui;
 
+import java.util.EnumSet;
+import java.util.Set;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResourceChangeEvent;
 import org.eclipse.core.resources.IResourceChangeListener;
@@ -59,8 +62,6 @@
 				}
 				return;
 			}
-			if(!SyncManager.getSyncAuto())
-				return;
 			for (IResourceDelta delta : event.getDelta().getAffectedChildren()) {
 				IProject project = delta.getResource().getProject();
 				if (project == null) {
@@ -68,18 +69,27 @@
 				}
 				if (RemoteSyncNature.hasNature(project)) {
 					SyncMode syncMode = SyncManager.getSyncMode(project);
+					boolean syncOn = true;
+					if (!(SyncManager.getSyncAuto()) || syncMode == SyncMode.NONE) {
+						syncOn = false;
+					}
 					SyncConfig syncConfig = SyncConfigManager.getActive(project);
 					/*
 					 * syncConfig can be null when sync nature is added to the project as this generates a resource change event
 					 */
 					if (syncConfig != null) {
 						try {
+							Set<SyncFlag> f = SyncFlag.RL_ONLY;
 							if (delta.getKind() == IResourceDelta.CHANGED && syncConfig.isSyncOnSave()) {
 								// Do a local-to-remote sync to update any changes reported in delta.
-								if (syncMode == SyncMode.ALL) {
-									SyncManager.syncAll(delta, project, SyncFlag.LR_ONLY, new CommonSyncExceptionHandler(true,false));
+								if ((syncMode == SyncMode.UNAVAILABLE) || (!syncOn)) {
+									continue;
+								} else if (syncMode == SyncMode.ALL) {
+									SyncManager.syncAll(delta, project, SyncFlag.LR_ONLY, new CommonSyncExceptionHandler(true,
+											false));
 								} else if (syncMode == SyncMode.ACTIVE) {
-									SyncManager.sync(delta, project, SyncFlag.LR_ONLY, new CommonSyncExceptionHandler(true, false));
+									SyncManager
+											.sync(delta, project, SyncFlag.LR_ONLY, new CommonSyncExceptionHandler(true, false));
 								}
 							}
 						} catch (CoreException e) {
@@ -93,4 +103,4 @@
 			}
 		}
 	};
-}
+}
\ No newline at end of file
diff --git a/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/menus/SyncMenuOperation.java b/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/menus/SyncMenuOperation.java
index 810fcb4..20c2ce6 100644
--- a/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/menus/SyncMenuOperation.java
+++ b/rdt/org.eclipse.ptp.rdt.sync.ui/src/org/eclipse/ptp/internal/rdt/sync/ui/menus/SyncMenuOperation.java
@@ -49,7 +49,6 @@
 	private static final String syncAllCommand = "sync_all"; //$NON-NLS-1$
 	private static final String setNoneCommand = "set_none"; //$NON-NLS-1$
 	private static final String setActiveCommand = "set_active"; //$NON-NLS-1$
-	private static final String setActiveBeforeBuildCommand = "set_active_before_build"; //$NON-NLS-1$
 	private static final String setAllCommand = "set_all"; //$NON-NLS-1$
 	private static final String syncAutoCommand = "sync_auto"; //$NON-NLS-1$
 	private static final String syncFileList = "sync_file_list"; //$NON-NLS-1$
@@ -91,8 +90,6 @@
 				SyncManager.syncAll(null, project, SyncFlag.BOTH, syncExceptionHandler);
 			} else if (command.equals(setNoneCommand)) {
 				SyncManager.setSyncMode(project, SyncMode.NONE);
-			} else if (command.equals(setActiveBeforeBuildCommand)) {
-				SyncManager.setSyncMode(project, SyncMode.ACTIVE_BEFORE_BUILD);
 			} else if (command.equals(syncAutoCommand)) {
 				SyncManager.setSyncAuto(!(SyncManager.getSyncAuto()));
 				// If user switches to automatic sync'ing, go ahead and sync based on current setting for project
@@ -200,9 +197,8 @@
 
 		SyncMode syncMode = SyncManager.getSyncMode(project);
 		if ((command.equals(setActiveCommand) && syncMode == SyncMode.ACTIVE)
-				|| (command.equals(setActiveBeforeBuildCommand) && syncMode == SyncMode.ACTIVE_BEFORE_BUILD)
 				|| (command.equals(setAllCommand) && syncMode == SyncMode.ALL)
-				|| (command.equals(setNoneCommand) && (syncMode == SyncMode.NONE|| syncMode == SyncMode.UNAVAILABLE))
+				|| (command.equals(setNoneCommand) && (syncMode == SyncMode.NONE || syncMode == SyncMode.UNAVAILABLE))
 				|| (command.equals(syncAutoCommand) && SyncManager.getSyncAuto())) {
 			element.setChecked(true);
 		} else {