This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 78401dc  ARTEMIS-3226 Add version output to cli
     new c47ebb9  This closes #3532
78401dc is described below

commit 78401dcf64522081955168c3125518987905c0ee
Author: Domenico Francesco Bruscino <[email protected]>
AuthorDate: Fri Apr 9 11:23:41 2021 +0200

    ARTEMIS-3226 Add version output to cli
---
 .../org/apache/activemq/artemis/cli/Artemis.java   |  5 ++-
 .../artemis/cli/commands/PrintVersion.java         | 36 ++++++++++++++++++++++
 .../org/apache/activemq/cli/test/ArtemisTest.java  | 10 ++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

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 c00e2e6..e06eac4 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
@@ -31,6 +31,7 @@ import org.apache.activemq.artemis.cli.commands.InputAbstract;
 import org.apache.activemq.artemis.cli.commands.InvalidOptionsError;
 import org.apache.activemq.artemis.cli.commands.Kill;
 import org.apache.activemq.artemis.cli.commands.Mask;
+import org.apache.activemq.artemis.cli.commands.PrintVersion;
 import org.apache.activemq.artemis.cli.commands.check.HelpCheck;
 import org.apache.activemq.artemis.cli.commands.check.NodeCheck;
 import org.apache.activemq.artemis.cli.commands.check.QueueCheck;
@@ -155,7 +156,9 @@ public class Artemis {
 
    private static Cli.CliBuilder<Action> builder(File artemisInstance) {
       String instance = artemisInstance != null ? 
artemisInstance.getAbsolutePath() : System.getProperty("artemis.instance");
-      Cli.CliBuilder<Action> builder = 
Cli.<Action>builder("artemis").withDescription("ActiveMQ Artemis Command 
Line").withCommand(HelpAction.class).withCommand(Producer.class).withCommand(Transfer.class).withCommand(Consumer.class).withCommand(Browse.class).withCommand(Mask.class).withDefaultCommand(HelpAction.class);
+      Cli.CliBuilder<Action> builder = 
Cli.<Action>builder("artemis").withDescription("ActiveMQ Artemis Command Line").
+         
withCommand(HelpAction.class).withCommand(Producer.class).withCommand(Transfer.class).withCommand(Consumer.class).
+         
withCommand(Browse.class).withCommand(Mask.class).withCommand(PrintVersion.class).withDefaultCommand(HelpAction.class);
 
       builder.withGroup("check").withDescription("Check tools group 
(node|queue) (example ./artemis check node)").
          withDefaultCommand(HelpCheck.class).withCommands(NodeCheck.class, 
QueueCheck.class);
diff --git 
a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/PrintVersion.java
 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/PrintVersion.java
new file mode 100644
index 0000000..f442b6e
--- /dev/null
+++ 
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/PrintVersion.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import io.airlift.airline.Command;
+import org.apache.activemq.artemis.core.version.Version;
+import org.apache.activemq.artemis.utils.VersionLoader;
+
+@Command(name = "version", description = "print version information")
+public class PrintVersion extends ActionAbstract {
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      Version version = VersionLoader.getVersion();
+
+      context.out.println("Apache ActiveMQ Artemis " + 
version.getFullVersion());
+      context.out.println("ActiveMQ Artemis home: " + this.getBrokerHome());
+      context.out.println("ActiveMQ Artemis instance: " + 
this.getBrokerInstance());
+
+      return version;
+   }
+}
diff --git 
a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java 
b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
index 59e959f..75cf1ba 100644
--- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
+++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
@@ -60,6 +60,7 @@ import org.apache.activemq.artemis.cli.commands.ActionContext;
 import org.apache.activemq.artemis.cli.commands.Create;
 import org.apache.activemq.artemis.cli.commands.Mask;
 import org.apache.activemq.artemis.cli.commands.Run;
+import org.apache.activemq.artemis.cli.commands.PrintVersion;
 import org.apache.activemq.artemis.cli.commands.queue.StatQueue;
 import org.apache.activemq.artemis.cli.commands.user.AddUser;
 import org.apache.activemq.artemis.cli.commands.user.ListUser;
@@ -74,6 +75,7 @@ import 
org.apache.activemq.artemis.core.security.impl.SecurityStoreImpl;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.server.management.ManagementContext;
+import org.apache.activemq.artemis.core.version.Version;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
 import org.apache.activemq.artemis.nativo.jlibaio.LibaioContext;
@@ -1742,6 +1744,14 @@ public class ArtemisTest extends CliTestBase {
 
    }
 
+   @Test
+   public void testVersionCommand() throws Exception {
+      TestActionContext context = new TestActionContext();
+      PrintVersion printVersion = new PrintVersion();
+      Version result = (Version) printVersion.execute(context);
+      log.debug(context.getStdout());
+   }
+
    //read individual lines from byteStream
    public static ArrayList<String> getOutputLines(TestActionContext context, 
boolean errorOutput) throws IOException {
       byte[] bytes;

Reply via email to