From 78401dcf64522081955168c3125518987905c0ee Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Fri, 9 Apr 2021 11:23:41 +0200 Subject: [PATCH] ARTEMIS-3226 Add version output to cli --- .../apache/activemq/artemis/cli/Artemis.java | 5 ++- .../artemis/cli/commands/PrintVersion.java | 36 +++++++++++++++++++ .../apache/activemq/cli/test/ArtemisTest.java | 10 ++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/PrintVersion.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 c00e2e6fc0..e06eac49da 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 builder(File artemisInstance) { String instance = artemisInstance != null ? artemisInstance.getAbsolutePath() : System.getProperty("artemis.instance"); - Cli.CliBuilder builder = Cli.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 builder = Cli.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 0000000000..f442b6e948 --- /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 59e959f304..75cf1baf34 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 getOutputLines(TestActionContext context, boolean errorOutput) throws IOException { byte[] bytes;