Fix ws & install path in setup file

+fix typos
+add debug option to cherry-pick command

Change-Id: Ia900f8c50a934c27c59398ddf2dcbcf5671a2ec5
Signed-off-by: Axel Richard <axel.richard@obeo.fr>
diff --git a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/CherryPickApplicationTest.java b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/CherryPickApplicationTest.java
index aa83663..4ecf94a 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/CherryPickApplicationTest.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/CherryPickApplicationTest.java
@@ -894,9 +894,9 @@
 		expected += "hint: by adding them to the index (Team > Add to index) or" + EOL;
 		expected += "hint: by removing them from the index (Team > Remove from index)." + EOL;
 		expected += "hint: Do NOT commit, use one of the following commands instead" + EOL;
-		expected += "hint:  git logical-cherrypick --continue : to continue the cherry pick" + EOL;
-		expected += "hint:  git logical-cherrypick --abort : to abort the cherry pick" + EOL;
-		expected += "hint:  git logical-cherrypick --quit : to skip this commit" + EOL + EOL;
+		expected += "hint:  git logicalcherry-pick --continue : to continue the cherry pick" + EOL;
+		expected += "hint:  git logicalcherry-pick --abort : to abort the cherry pick" + EOL;
+		expected += "hint:  git logicalcherry-pick --quit : to skip this commit" + EOL + EOL;
 		return expected;
 	}
 
diff --git a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/CherryPickArgumentsTest.java b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/CherryPickArgumentsTest.java
index 82eb701..973cbdd 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/CherryPickArgumentsTest.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/CherryPickArgumentsTest.java
@@ -46,13 +46,14 @@
 	protected String getExpectedUsage() {
 		//@formatter:off
 		
-		String usage = "logicalcherry-pick <setup> [<commit> ...] [--abort] [--continue] [--git-dir gitFolderPath] [--help (-h)] [--quit] [--show-stack-trace]" + EOL;
+		String usage = "logicalcherry-pick <setup> [<commit> ...] [--abort] [--continue] [--debug (-d)] [--git-dir gitFolderPath] [--help (-h)] [--quit] [--show-stack-trace]" + EOL;
 		usage += EOL;
 		usage += " <setup>                 : Path to the setup file. The setup file is a Oomph" + EOL;
 		usage += "                           model." +EOL;
 		usage += " <commit>                : Commit IDs to cherry pick." + EOL;
 		usage += " --abort                 : Use this option to abort a in going cherry-pick" + EOL;
 		usage += " --continue              : Use this option to continue a in going cherry-pick" + EOL;
+		usage += " --debug (-d)            : Launched the provisionned eclipse in debug mode." + EOL;
 		usage += " --git-dir gitFolderPath : Path to the .git folder of your repository."+ EOL;
 		usage += " --help (-h)             : Dispays help for this command." + EOL;
 		usage += " --quit                  : Use this option to quit a in going cherry-pick" + EOL;
diff --git a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/MergeArgumentsTest.java b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/MergeArgumentsTest.java
index edd9376..007390d 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/MergeArgumentsTest.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/cmd/MergeArgumentsTest.java
@@ -47,7 +47,7 @@
 				+ " <setup>                 : Path to the setup file. The setup file is a Oomph" + EOL 
 				+ "                           model." +EOL
 				+ " <commit>                : Commit ID or branch name to merge." + EOL 
-				+ " --debug (-d)            : Launched the provisonned eclipse in debug mode."+ EOL
+				+ " --debug (-d)            : Launched the provisionned eclipse in debug mode."+ EOL
 				+ " --git-dir gitFolderPath : Path to the .git folder of your repository."+ EOL
 				+ " --help (-h)             : Dispays help for this command." + EOL 
 				+ " --show-stack-trace      : Use this option to display java stack trace in" + EOL
@@ -249,9 +249,9 @@
 		setCmdLocation(getRepositoryPath().toString());
 
 		Path oomphFolderPath = getTestTmpFolder().resolve("oomphFolder");
-		File newSetupFile = new OomphUserModelBuilder().setInstallationLocation(
-				oomphFolderPath.toString()).setWorkspaceLocation(oomphFolderPath.resolve("ws").toString())
-				.saveTo(getTestTmpFolder().resolve("setup.setup").toString());
+		File newSetupFile = new OomphUserModelBuilder().setInstallationLocation(oomphFolderPath.toString())
+				.setWorkspaceLocation(oomphFolderPath.resolve("ws").toString()).saveTo(
+						getTestTmpFolder().resolve("setup.setup").toString());
 
 		// Creates some content for the first commit.
 		new ProjectBuilder(this) //
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalCherryPickApplication.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalCherryPickApplication.java
index 11bfa79..02b4b09 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalCherryPickApplication.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/LogicalCherryPickApplication.java
@@ -256,9 +256,9 @@
 			msg += "hint: by adding them to the index (Team > Add to index) or" + EOL;
 			msg += "hint: by removing them from the index (Team > Remove from index)." + EOL;
 			msg += "hint: Do NOT commit, use one of the following commands instead" + EOL;
-			msg += "hint:  git logical-cherrypick --continue : to continue the cherry pick" + EOL;
-			msg += "hint:  git logical-cherrypick --abort : to abort the cherry pick" + EOL;
-			msg += "hint:  git logical-cherrypick --quit : to skip this commit" + EOL;
+			msg += "hint:  git logicalcherry-pick --continue : to continue the cherry pick" + EOL;
+			msg += "hint:  git logicalcherry-pick --abort : to abort the cherry pick" + EOL;
+			msg += "hint:  git logicalcherry-pick --quit : to skip this commit" + EOL;
 
 			messageBuilder.append(msg);
 		}
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/AbstractLogicalCommand.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/AbstractLogicalCommand.java
index 09758b0..70148b5 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/AbstractLogicalCommand.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/AbstractLogicalCommand.java
@@ -64,6 +64,7 @@
 import org.eclipse.oomph.setup.ProductCatalog;
 import org.eclipse.oomph.setup.ProductVersion;
 import org.eclipse.oomph.setup.Project;
+import org.eclipse.oomph.setup.SetupFactory;
 import org.eclipse.oomph.setup.SetupPackage;
 import org.eclipse.oomph.setup.SetupTask;
 import org.eclipse.oomph.setup.Trigger;
@@ -246,7 +247,7 @@
 				performer.perform();
 
 				if (!performer.hasSuccessfullyPerformed()) {
-					throw new DiesOn(DeathType.FATAL).displaying("Error durring Oomph operation").ready();
+					throw new DiesOn(DeathType.FATAL).displaying("Error during Oomph operation").ready();
 				}
 			} catch (Die e) {
 				throw e;
@@ -471,7 +472,7 @@
 			startupSetupProject = (Project)startupSetupRoot;
 		} else {
 			throw new DiesOn(SOFTWARE_ERROR).displaying(
-					"The root of the setup file should be a Setup::PROJECT").ready();
+					"The root of the setup file should be a Setup::Project").ready();
 		}
 
 		progressPageLog = new ProgressPageLog(System.out);
@@ -480,8 +481,8 @@
 		Index eclipseSetupIndex = (Index)EcoreUtil.getObjectByType(environmentSetup.getContents(),
 				SetupPackage.Literals.INDEX);
 
-		handleWorkspace(startupSetupProject, eclipseSetupIndex);
-		handleInstallation(startupSetupProject, eclipseSetupIndex);
+		final String wsPath = handleWorkspace(startupSetupProject, eclipseSetupIndex);
+		final String installPath = handleInstallation(startupSetupProject, eclipseSetupIndex);
 
 		EList<ProductCatalog> productCatalogs = eclipseSetupIndex.getProductCatalogs();
 		ProductCatalog catalog = productCatalogs.get(0);
@@ -507,7 +508,7 @@
 			aPerformer = SetupTaskPerformer.create(uriConverter, SetupPrompter.CANCEL, triggerBootstrap,
 					setupContext, false);
 		} catch (Exception e) {
-			throw new DiesOn(DeathType.ERROR).duedTo(e).displaying("Error during processing of setup mdoel")
+			throw new DiesOn(DeathType.ERROR).duedTo(e).displaying("Error during processing of setup model")
 					.ready();
 		}
 		// CHECKSTYLE.ON: IllegalCatch
@@ -518,10 +519,25 @@
 		aPerformer.setOffline(false);
 		aPerformer.setMirrors(true);
 
-		final String installationPath = getInstallationPath(startupSetupProject);
-		if (installationPathContainsExistingEclipse(installationPath)) {
+		if (installationPathContainsExistingEclipse(installPath)) {
 			aPerformer.getTriggeredSetupTasks().clear();
-			progressPageLog.log("Existing eclipse environment found at : " + installationPath); //$NON-NLS-1$
+			progressPageLog.log("Existing eclipse environment found at : " + installPath); //$NON-NLS-1$
+			// Add installation task and workspace task.
+			InstallationTask installationTask = SetupFactory.eINSTANCE.createInstallationTask();
+			installationTask.setLocation(installPath);
+			aPerformer.getTriggeredSetupTasks().add(installationTask);
+			WorkspaceTask workspaceTask = SetupFactory.eINSTANCE.createWorkspaceTask();
+			workspaceTask.setLocation(wsPath);
+			aPerformer.getTriggeredSetupTasks().add(workspaceTask);
+		} else {
+			// Ensure we use user installation and workspace paths
+			for (SetupTask setupTask : aPerformer.getTriggeredSetupTasks()) {
+				if (setupTask instanceof WorkspaceTask) {
+					((WorkspaceTask)setupTask).setLocation(wsPath);
+				} else if (setupTask instanceof InstallationTask) {
+					((InstallationTask)setupTask).setLocation(installPath);
+				}
+			}
 		}
 
 		return aPerformer;
@@ -579,12 +595,13 @@
 	 *            the root object of the user model.
 	 * @param index
 	 *            the root object of the environment model.
+	 * @return the workspace path.
 	 * @throws IOException
 	 *             e
 	 * @throws Die
 	 *             e
 	 */
-	private void handleWorkspace(Project project, Index index) throws IOException, Die {
+	private String handleWorkspace(Project project, Index index) throws IOException, Die {
 		final String workspaceLocation;
 		if (modelDefinesWorkspacePath(project)) {
 			workspaceLocation = getWorkspacePath(project);
@@ -596,10 +613,11 @@
 			for (SetupTask setupTask : productCatalog.getSetupTasks()) {
 				if (setupTask instanceof WorkspaceTask) {
 					((WorkspaceTask)setupTask).setLocation(workspaceLocation);
-					return;
+					break;
 				}
 			}
 		}
+		return workspaceLocation;
 	}
 
 	/**
@@ -609,12 +627,13 @@
 	 *            the root object of the user model.
 	 * @param index
 	 *            the root object of the environment model.
+	 * @return the installation path.
 	 * @throws IOException
 	 *             e
 	 * @throws Die
 	 *             e
 	 */
-	private void handleInstallation(Project project, Index index) throws IOException, Die {
+	private String handleInstallation(Project project, Index index) throws IOException, Die {
 		final String installationLocation;
 		if (modelDefinesWorkspacePath(project)) {
 			installationLocation = getInstallationPath(project);
@@ -626,10 +645,11 @@
 			for (SetupTask setupTask : productCatalog.getSetupTasks()) {
 				if (setupTask instanceof InstallationTask) {
 					((InstallationTask)setupTask).setLocation(installationLocation);
-					return;
+					break;
 				}
 			}
 		}
+		return installationLocation;
 	}
 
 	/**
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalCherryPickCommand.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalCherryPickCommand.java
index 884cbf7..6e2d45f 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalCherryPickCommand.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalCherryPickCommand.java
@@ -52,6 +52,9 @@
 	/** Command name. */
 	static final String LOGICAL_CHERRY_PICK_CMD_NAME = "logicalcherry-pick"; //$NON-NLS-1$
 
+	/** Id of the logicalcherry-pick application. */
+	static final String LOGICAL_CHERRYPICK_APP_ID = "emf.compare.git.logicalcherry-pick"; //$NON-NLS-1$
+
 	/** Quit option key. */
 	static final String QUIT_OPT = "--quit"; //$NON-NLS-1$
 
@@ -61,9 +64,6 @@
 	/** Continue option key. */
 	static final String CONTINUE_OPT = "--continue"; //$NON-NLS-1$
 
-	/** Id of the logicalcherry-pick application. */
-	static final String LOGICALCHERRYPICK_APP_ID = "emf.compare.git.logicalcherry-pick"; //$NON-NLS-1$
-
 	/** Tab character. */
 	private static final String TAB = "\t"; //$NON-NLS-1$
 
@@ -83,6 +83,10 @@
 	@Option(required = false, name = QUIT_OPT, usage = "Use this option to quit a in going cherry-pick")
 	private boolean quitOpt;
 
+	/** Option debug. */
+	@Option(name = "--debug", usage = "Launched the provisionned eclipse in debug mode.", aliases = {"-d" })
+	private boolean debug;
+
 	@Override
 	protected Integer internalRun() throws Die, IOException {
 
@@ -97,8 +101,9 @@
 
 		//@formatter:off
 		LogicalApplicationLauncher launcher = new LogicalApplicationLauncher(out())
-				.setApplicationName(LOGICALCHERRYPICK_APP_ID)
+				.setApplicationName(LOGICAL_CHERRYPICK_APP_ID)
 				.setEclipsePath(eclipsePath)
+				.debug(debug)
 				.setSetupFilePath(setupFileAbsolutePath)
 				.setWorkspaceLocation(workspacePath)
 				.setRepositoryPath(getRepository().getDirectory().getAbsolutePath())
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java
index f25ed84..dbc95da 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalDiffCommand.java
@@ -46,8 +46,8 @@
 	 */
 	static final String LOGICAL_DIFF_CMD_NAME = "logicaldiff"; //$NON-NLS-1$
 
-	/** Command name. */
-	private static final String LOGICALDIFF_APP_ID = "emf.compare.git.logicaldiff"; //$NON-NLS-1$
+	/** Id of the logicaldiff application. */
+	private static final String LOGICAL_DIFF_APP_ID = "emf.compare.git.logicaldiff"; //$NON-NLS-1$
 
 	/**
 	 * Holds the reference from which the differences should be displayed.
@@ -84,7 +84,7 @@
 
 		//@formatter:off
 		LogicalApplicationLauncher launcher = new LogicalApplicationLauncher(out())
-				.setApplicationName(LOGICALDIFF_APP_ID)
+				.setApplicationName(LOGICAL_DIFF_APP_ID)
 				.setEclipsePath(eclipsePath)
 				.setSetupFilePath(setupFileAbsolutePath)
 				.setWorkspaceLocation(workspacePath)
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java
index e3da949..1287bdf 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/cmd/LogicalMergeCommand.java
@@ -42,14 +42,14 @@
 @SuppressWarnings("restriction")
 public class LogicalMergeCommand extends AbstractLogicalCommand {
 
-	/** Id of the logicalmerge application. */
-	static final String LOGICALMERGE_APP_ID = "emf.compare.git.logicalmerge"; //$NON-NLS-1$
-
 	/**
 	 * Command name.
 	 */
 	static final String LOGICAL_MERGE_CMD_NAME = "logicalmerge"; //$NON-NLS-1$
 
+	/** Id of the logicalmerge application. */
+	static final String LOGICAL_MERGE_APP_ID = "emf.compare.git.logicalmerge"; //$NON-NLS-1$
+
 	/**
 	 * Holds a ObjectId that need to be merged.
 	 */
@@ -65,7 +65,7 @@
 	/**
 	 * Option debug.
 	 */
-	@Option(name = "--debug", usage = "Launched the provisonned eclipse in debug mode.", aliases = {"-d" })
+	@Option(name = "--debug", usage = "Launched the provisionned eclipse in debug mode.", aliases = {"-d" })
 	private boolean debug;
 
 	/**
@@ -87,7 +87,7 @@
 
 		//@formatter:off
 		LogicalApplicationLauncher launcher = new LogicalApplicationLauncher(out())
-				.setApplicationName(LOGICALMERGE_APP_ID)
+				.setApplicationName(LOGICAL_MERGE_APP_ID)
 				.setEclipsePath(eclipsePath)
 				.debug(debug)
 				.setSetupFilePath(setupFileAbsolutePath)
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/LogicalApplicationLauncher.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/LogicalApplicationLauncher.java
index f8a21f0..9845c43 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/LogicalApplicationLauncher.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/LogicalApplicationLauncher.java
@@ -70,7 +70,7 @@
 	/** Path to the workspace. */
 	private String workspaceLocation;
 
-	/** Debut option. */
+	/** Debug option. */
 	private boolean debug;
 
 	/**