activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [3/4] activemq-artemis git commit: ARTEMIS-140 In testing ARTEMIS-116 Found some more holes in the cli.
Date Wed, 17 Jun 2015 02:49:43 GMT
ARTEMIS-140 In testing ARTEMIS-116 Found some more holes in the cli.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/5b2d2a49
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/5b2d2a49
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/5b2d2a49

Branch: refs/heads/master
Commit: 5b2d2a49c4c8997079c9560151144ac62c92de20
Parents: 56ec4ca
Author: John D. Ament <johndament@apache.org>
Authored: Tue Jun 16 20:58:14 2015 -0400
Committer: John D. Ament <johndament@apache.org>
Committed: Tue Jun 16 20:58:14 2015 -0400

----------------------------------------------------------------------
 .../apache/activemq/artemis/cli/Artemis.java    | 13 ++++++------
 .../activemq/artemis/cli/commands/Create.java   | 21 +++++++++++++++++++-
 .../activemq/artemis/test/ArtemisTest.java      | 13 +++++++++++-
 3 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5b2d2a49/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
index 39f60be..137d36c 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
@@ -20,7 +20,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import io.airlift.airline.Cli;
-import io.airlift.airline.ParseException;
 import org.apache.activemq.artemis.cli.commands.Action;
 import org.apache.activemq.artemis.cli.commands.ActionContext;
 import org.apache.activemq.artemis.cli.commands.Create;
@@ -66,18 +65,18 @@ public class Artemis
       {
          parser.parse(args).execute(ActionContext.system());
       }
-      catch (ParseException e)
-      {
-         System.err.println(e.getMessage());
-         System.out.println();
-         parser.parse("help").execute(ActionContext.system());
-      }
       catch (ConfigurationException configException)
       {
          System.err.println(configException.getMessage());
          System.out.println();
          System.out.println("Configuration should be specified as 'scheme:location'. Default
configuration is 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'");
       }
+      catch (RuntimeException re)
+      {
+         System.err.println(re.getMessage());
+         System.out.println();
+         parser.parse("help").execute(ActionContext.system());
+      }
 
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5b2d2a49/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
index c015139..4450657 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
@@ -83,7 +83,7 @@ public class Create extends InputAbstract
    public static final String ETC_CONNECTOR_SETTINGS_TXT = "etc/connector-settings.txt";
    public static final String ETC_BOOTSTRAP_WEB_SETTINGS_TXT = "etc/bootstrap-web-settings.txt";
 
-   @Arguments(description = "The instance directory to hold the broker's configuration and
data", required = true)
+   @Arguments(description = "The instance directory to hold the broker's configuration and
data.  Path must be writable.", required = true)
    File directory;
 
    @Option(name = "--host", description = "The host name of the broker (Default: 0.0.0.0
or input if clustered)")
@@ -412,6 +412,7 @@ public class Create extends InputAbstract
    @Override
    public Object execute(ActionContext context) throws Exception
    {
+      this.checkDirectory();
       super.execute(context);
 
       try
@@ -432,6 +433,24 @@ public class Create extends InputAbstract
       return this.getClass().getResourceAsStream(source);
    }
 
+   /**
+    * Checks that the directory provided either exists and is writable or doesn't exist but
can be created.
+    */
+   private void checkDirectory()
+   {
+      if (!directory.exists())
+      {
+         boolean created = directory.mkdirs();
+         if (!created)
+         {
+            throw new RuntimeException(String.format("Unable to create the path '%s'.", directory));
+         }
+      }
+      else if (!directory.canWrite())
+      {
+         throw new RuntimeException(String.format("The path '%s' is not writable.", directory));
+      }
+   }
 
    public Object run(ActionContext context) throws Exception
    {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5b2d2a49/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java
index 5e02a63..e38ed14 100644
--- a/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java
+++ b/artemis-cli/src/test/java/org/apache/activemq/artemis/test/ArtemisTest.java
@@ -28,9 +28,20 @@ public class ArtemisTest
    @Test
    public void invalidCliDoesntThrowException()
    {
+      testCli("create");
+   }
+
+   @Test
+   public void invalidPathDoesntThrowException()
+   {
+      testCli("create","/rawr");
+   }
+
+   private void testCli(String... args)
+   {
       try
       {
-         Artemis.main(new String[]{"create"});
+         Artemis.main(args);
       }
       catch (Exception e)
       {


Mime
View raw message