You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2017/08/25 06:01:25 UTC

svn commit: r1806125 - /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java

Author: chetanm
Date: Fri Aug 25 06:01:24 2017
New Revision: 1806125

URL: http://svn.apache.org/viewvc?rev=1806125&view=rev
Log:
OAK-6589 - Close the fixture in oak run console

Modified:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java?rev=1806125&r1=1806124&r2=1806125&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/console/Console.java Fri Aug 25 06:01:24 2017
@@ -44,32 +44,31 @@ public class Console {
         Options opts = new Options();
         OptionSet options = opts.parseAndConfigure(parser, args);
 
-
-        NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts);
-
-        List<String> nonOptions = opts.getCommonOpts().getNonOptions();
-        List<String> scriptArgs = nonOptions.size() > 1 ?
-                nonOptions.subList(1, nonOptions.size()) : Collections.emptyList();
-        IO io = new IO();
-
-        if(options.has(quiet)){
-            io.setVerbosity(IO.Verbosity.QUIET);
-        }
-
-        if (!opts.getCommonOpts().isReadWrite()) {
-            io.out.println("Repository connected in read-only mode. Use '--read-write' for write operations");
-        }
-
-        GroovyConsole console =
-                new GroovyConsole(ConsoleSession.create(fixture.getStore(), fixture.getWhiteboard()), new IO(), fixture);
-
         int code = 0;
-        if(!scriptArgs.isEmpty()){
-            code = console.execute(scriptArgs);
-        }
-
-        if(scriptArgs.isEmpty() || options.has(shell)){
-            code = console.run();
+        try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(opts)) {
+            List<String> nonOptions = opts.getCommonOpts().getNonOptions();
+            List<String> scriptArgs = nonOptions.size() > 1 ?
+                    nonOptions.subList(1, nonOptions.size()) : Collections.emptyList();
+            IO io = new IO();
+
+            if (options.has(quiet)) {
+                io.setVerbosity(IO.Verbosity.QUIET);
+            }
+
+            if (!opts.getCommonOpts().isReadWrite()) {
+                io.out.println("Repository connected in read-only mode. Use '--read-write' for write operations");
+            }
+
+            GroovyConsole console =
+                    new GroovyConsole(ConsoleSession.create(fixture.getStore(), fixture.getWhiteboard()), new IO(), fixture);
+
+            if (!scriptArgs.isEmpty()) {
+                code = console.execute(scriptArgs);
+            }
+
+            if (scriptArgs.isEmpty() || options.has(shell)) {
+                code = console.run();
+            }
         }
 
         System.exit(code);