[CLI] Use try-with-resources to avoid leaks with RevWalk

Also Update tests

Change-Id: If10141aadacce92230d82b3b87a69ec8313a9b10
Signed-off-by: Axel Richard <axel.richard@obeo.fr>
diff --git a/org.eclipse.emf.compare.git.pgm-parent/targetPlatforms/org.eclipse.emf.compare.git.pgm.target b/org.eclipse.emf.compare.git.pgm-parent/targetPlatforms/org.eclipse.emf.compare.git.pgm.target
index 848c973..94d235a 100644
--- a/org.eclipse.emf.compare.git.pgm-parent/targetPlatforms/org.eclipse.emf.compare.git.pgm.target
+++ b/org.eclipse.emf.compare.git.pgm-parent/targetPlatforms/org.eclipse.emf.compare.git.pgm.target
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <?pde?>
 <!-- generated with https://github.com/mbarbero/fr.obeo.releng.targetplatform -->
-<target name="EMF Compare Git PGM target platform" sequenceNumber="1431334798">
+<target name="EMF Compare Git PGM target platform" sequenceNumber="1431506007">
   <locations>
     <location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
       <unit id="org.eclipse.egit.feature.group" version="0.0.0"/>
@@ -13,7 +13,8 @@
       <unit id="org.eclipse.emf.compare.uml2.feature.group" version="0.0.0"/>
       <unit id="org.eclipse.emf.compare.diagram.gmf.feature.group" version="0.0.0"/>
       <unit id="org.eclipse.emf.compare.diagram.papyrus.feature.group" version="0.0.0"/>
-      <repository location="http://download.eclipse.org/modeling/emf/compare/updates/nightly/latest"/>
+      <unit id="org.eclipse.emf.compare.egit.feature.group" version="0.0.0"/>
+      <repository location="http://download.eclipse.org/modeling/emf/compare/updates/logical/emf.compare/nightly/latest/"/>
     </location>
     <location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
       <unit id="org.eclipse.oomph.util" version="0.0.0"/>
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 a499606..cede079 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
@@ -55,7 +55,7 @@
 		contextSetup.setupCHE003();
 		runCherryPick(Returns.COMPLETE, "branch_b");
 
-		assertOutputMessageEnd(getCompleteMessage("[" + getShortId("HEAD") + "] Adds class 1"));
+		assertOutputMessageEnd("Complete." + EOL);
 	}
 
 	/**
@@ -187,7 +187,7 @@
 	 * @see ContextSetup#setupREB011()
 	 * @throws Exception
 	 */
-	// @Test
+	@Test
 	public void testCHE011() throws Exception {
 		contextSetup = new ContextSetup(getGit(), getTestTmpFolder());
 		contextSetup.setupREB011();
diff --git a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/MergeApplicationTest.java b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/MergeApplicationTest.java
index 853e175..d8ea4f8 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/MergeApplicationTest.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/MergeApplicationTest.java
@@ -423,7 +423,7 @@
 	 * @see ContextSetup#setupREB011()
 	 * @throws Exception
 	 */
-	// @Test
+	@Test
 	public void testMER011() throws Exception {
 		contextSetup = new ContextSetup(getGit(), getTestTmpFolder());
 		contextSetup.setupREB011();
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/AbstractLogicalApplication.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/AbstractLogicalApplication.java
index ea7815f..83a87cb 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/AbstractLogicalApplication.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/AbstractLogicalApplication.java
@@ -318,12 +318,9 @@
 	 */
 	protected AbstractTreeIterator getTreeIterator(Repository repository, ObjectId id) throws IOException {
 		final CanonicalTreeParser p = new CanonicalTreeParser();
-		final ObjectReader or = repository.newObjectReader();
-		try {
+		try (ObjectReader or = repository.newObjectReader()) {
 			p.reset(or, new RevWalk(repository).parseTree(id));
 			return p;
-		} finally {
-			or.release();
 		}
 	}
 
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/RebaseApplication.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/RebaseApplication.java
index a0ce7a1..1fe66fa 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/RebaseApplication.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/RebaseApplication.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -185,14 +185,11 @@
 		if (objectId instanceof RevCommit) {
 			return (RevCommit)objectId;
 		} else {
-			RevWalk revWalk = new RevWalk(repo);
-			try {
+			try (RevWalk revWalk = new RevWalk(repo)) {
 				return revWalk.parseCommit(objectId);
 			} catch (IOException e) {
 				throw new DiesOn(DeathType.FATAL).displaying("Invalid ref " + ref.getName()).duedTo(e)
 						.ready();
-			} finally {
-				revWalk.release();
 			}
 		}
 	}
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefHandler.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefHandler.java
index 1de2512..2047268 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefHandler.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -87,14 +87,11 @@
 					throw new ArgumentValidationError(owner, "bad revision '" + refName + "'.");
 				}
 				// Checks that the resolved object is a RevCommit
-				RevWalk revWalk = new RevWalk(repo);
-				try {
+				try (RevWalk revWalk = new RevWalk(repo)) {
 					RevCommit commitId = revWalk.parseCommit(objectID);
 					ref = new ObjectIdRef.Unpeeled(Storage.LOOSE, commitId.getName(), commitId);
 				} catch (IOException e) {
 					throw new ArgumentValidationError(owner, "bad revision '" + refName + "'.");
-				} finally {
-					revWalk.release();
 				}
 			}
 
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RevCommitHandler.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RevCommitHandler.java
index 53c5b3b..af7ef62 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RevCommitHandler.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RevCommitHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -45,8 +45,7 @@
 	 * @param setter
 	 *            {@link OptionHandler#setter}
 	 */
-	public RevCommitHandler(CmdLineParser parser, OptionDef option,
-			Setter<? super ObjectId> setter) {
+	public RevCommitHandler(CmdLineParser parser, OptionDef option, Setter<? super ObjectId> setter) {
 		super(parser, option, setter);
 		Preconditions.checkArgument(parser instanceof CmdLineParserRepositoryBuilder);
 	}
@@ -68,14 +67,12 @@
 			if (objectID == null) {
 				throw new ArgumentValidationError(owner, "bad revision '" + ref + "'.");
 			}
-			RevWalk revWalk = new RevWalk(repo);
-			try {
+
+			try (RevWalk revWalk = new RevWalk(repo)) {
 				RevCommit commitId = revWalk.parseCommit(objectID);
 				setter.addValue(commitId);
 			} catch (IOException e) {
 				throw new ArgumentValidationError(owner, "bad revision '" + ref + "'.");
-			} finally {
-				revWalk.release();
 			}
 
 		} catch (Die e) {
diff --git a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/GitUtils.java b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/GitUtils.java
index 616ad52..142fe02 100644
--- a/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/GitUtils.java
+++ b/plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/GitUtils.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 Obeo.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -53,11 +53,9 @@
 	 */
 	public static List<RevCommit> getCommitsBetween(Repository repo, ObjectId from, ObjectId to)
 			throws IOException {
-		RevWalk revWak = new RevWalk(repo);
-		try {
+
+		try (RevWalk revWak = new RevWalk(repo)) {
 			return RevWalkUtils.find(revWak, revWak.parseCommit(from), revWak.parseCommit(to));
-		} finally {
-			revWak.release();
 		}
 	}