Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2015-05-18 08:45:58 +0000
committerAxel Richard2015-05-22 09:19:41 +0000
commitdeee9421a2cb9cf718c45e2f52714863343e4aa6 (patch)
tree98b3553fca8730215080784edc5c733c40ade343
parent6e16132a3d9994db4fa775b0eb6b92388d568837 (diff)
downloadorg.eclipse.emf.compare-cli-deee9421a2cb9cf718c45e2f52714863343e4aa6.tar.gz
org.eclipse.emf.compare-cli-deee9421a2cb9cf718c45e2f52714863343e4aa6.tar.xz
org.eclipse.emf.compare-cli-deee9421a2cb9cf718c45e2f52714863343e4aa6.zip
[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>
-rw-r--r--org.eclipse.emf.compare.git.pgm-parent/targetPlatforms/org.eclipse.emf.compare.git.pgm.target5
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/CherryPickApplicationTest.java4
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm.tests/src/org/eclipse/emf/compare/git/pgm/internal/app/MergeApplicationTest.java2
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/AbstractLogicalApplication.java5
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/app/RebaseApplication.java7
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RefHandler.java7
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/args/RevCommitHandler.java11
-rw-r--r--plugins/org.eclipse.emf.compare.git.pgm/src/org/eclipse/emf/compare/git/pgm/internal/util/GitUtils.java8
8 files changed, 18 insertions, 31 deletions
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 @@ public class CherryPickApplicationTest extends AbstractApplicationTest {
contextSetup.setupCHE003();
runCherryPick(Returns.COMPLETE, "branch_b");
- assertOutputMessageEnd(getCompleteMessage("[" + getShortId("HEAD") + "] Adds class 1"));
+ assertOutputMessageEnd("Complete." + EOL);
}
/**
@@ -187,7 +187,7 @@ public class CherryPickApplicationTest extends AbstractApplicationTest {
* @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 @@ public class MergeApplicationTest extends AbstractApplicationTest {
* @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 @@ public abstract class AbstractLogicalApplication implements IApplication {
*/
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 @@ public class RebaseApplication extends AbstractLogicalApplication {
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 @@ public class RefHandler extends OptionHandler<Ref> {
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 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
* @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 @@ public class RevCommitHandler extends OptionHandler<RevCommit> {
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 final class GitUtils {
*/
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();
}
}

Back to the top