Open Repository in try-with-resource

Change-Id: I1db2801764b8da9e2a857dc94e515122920c880f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
index edf3f6c..2b1968c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
@@ -103,21 +103,14 @@
 
   private void export(ReviewDb db, Project.NameKey project, List<Change> changes)
       throws IOException, OrmException {
-    final Repository git;
-    try {
-      git = gitManager.openRepository(project);
-    } catch (RepositoryNotFoundException e) {
-      stderr.println("Unable to open project: " + project.get());
-      return;
-    }
-    try {
+    try (Repository git = gitManager.openRepository(project)) {
       CreateReviewNotes crn = reviewNotesFactory.create(db, project, git);
       crn.createNotes(changes, monitor);
       crn.commitNotes();
+    } catch (RepositoryNotFoundException e) {
+      stderr.println("Unable to open project: " + project.get());
     } catch (ConcurrentRefUpdateException e) {
       stderr.println(e.getMessage());
-    } finally {
-      git.close();
     }
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
index 389195e..d798648 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
@@ -26,7 +26,6 @@
 import com.google.inject.Inject;
 
 import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
-import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Repository;
@@ -95,19 +94,8 @@
 
   private void createReviewNotes(Event e) {
     Project.NameKey projectName = new Project.NameKey(e.getProjectName());
-    Repository git;
-    try {
-      git = repoManager.openRepository(projectName);
-    } catch (RepositoryNotFoundException x) {
-      log.error(x.getMessage(), x);
-      return;
-    } catch (IOException x) {
-      log.error(x.getMessage(), x);
-      return;
-    }
-
-
-    try (ReviewDb reviewDb = schema.open()){
+    try (Repository git = repoManager.openRepository(projectName);
+        ReviewDb reviewDb = schema.open()) {
       CreateReviewNotes crn = reviewNotesFactory.create(
           reviewDb, projectName, git);
       if (e.getRefName().startsWith("refs/heads/")) {
@@ -119,8 +107,6 @@
       }
     } catch (OrmException | IOException | ConcurrentRefUpdateException x) {
       log.error(x.getMessage(), x);
-    } finally {
-      git.close();
     }
   }
 }