From af509932853c3b5bcc145a4108d506ad321fc320 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 1 Oct 2019 12:24:48 +0200 Subject: [PATCH] Support for --version, fixes #2 --- pom.xml | 6 +++++ .../org/jboss/fuse/mvnd/daemon/Client.java | 22 ++++++++++++++++++ .../jboss/fuse/mvnd/daemon/build.properties | 23 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/main/resources/org/jboss/fuse/mvnd/daemon/build.properties diff --git a/pom.xml b/pom.xml index 80c5bafd..495b7beb 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,12 @@ + + + ${basedir}/src/main/resources + true + + io.takari.maven.plugins diff --git a/src/main/java/org/jboss/fuse/mvnd/daemon/Client.java b/src/main/java/org/jboss/fuse/mvnd/daemon/Client.java index a41622bd..8b413391 100644 --- a/src/main/java/org/jboss/fuse/mvnd/daemon/Client.java +++ b/src/main/java/org/jboss/fuse/mvnd/daemon/Client.java @@ -15,17 +15,21 @@ */ package org.jboss.fuse.mvnd.daemon; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.LinkedHashMap; import java.util.List; +import java.util.Properties; import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.maven.cli.CLIReportingUtils; import org.jboss.fuse.mvnd.daemon.Message.BuildEvent; import org.jboss.fuse.mvnd.daemon.Message.BuildMessage; import org.jboss.fuse.mvnd.daemon.Message.MessageSerializer; @@ -51,6 +55,24 @@ public class Client { LOGGER.debug("Starting client"); List args = new ArrayList<>(Arrays.asList(argv)); + // Print version if needed + boolean version = args.remove("-v") || args.remove("--version"); + boolean showVersion = args.contains("-V") || args.contains("--show-version"); + boolean debug = args.contains("-X") || args.contains("--debug"); + if (version || showVersion || debug) { + Properties props = new Properties(); + try (InputStream is = Client.class.getResourceAsStream("build.properties")) { + props.load(is); + } + String v = buffer().strong( "Maven Daemon " + props.getProperty("version") ).toString() + + System.getProperty( "line.separator" ) + + CLIReportingUtils.showVersion(); + System.out.println(v); + if (version) { + return; + } + } + Path javaHome = Layout.javaHome(); DaemonRegistry registry = DaemonRegistry.getDefault(); diff --git a/src/main/resources/org/jboss/fuse/mvnd/daemon/build.properties b/src/main/resources/org/jboss/fuse/mvnd/daemon/build.properties new file mode 100644 index 00000000..d15784a7 --- /dev/null +++ b/src/main/resources/org/jboss/fuse/mvnd/daemon/build.properties @@ -0,0 +1,23 @@ +# 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. + +buildNumber=${buildNumber} +timestamp=${timestamp} +version=${project.version} +distributionId=${distributionId} +distributionShortName=${distributionShortName} +distributionName=${distributionName} \ No newline at end of file