Add build time to jar 79/24379/7
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Thu, 12 Oct 2017 10:59:10 +0000 (16:29 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 20 Nov 2017 08:37:56 +0000 (14:07 +0530)
Issue-Id: CLI-66

Change-Id: I45f524e3e4f0f111fd411f3d9577edb5e3c0d0ed
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
pom.xml

index b3905de..e2d3565 100644 (file)
@@ -269,6 +269,13 @@ public class OnapCommandRegistrar {
             version = OnapCommandConfg.getVersion();
         }
 
+        String buildTime = OnapCommandUtils.findLastBuildTime();
+        if (buildTime!= null && !buildTime.isEmpty()) {
+            buildTime = " [" + buildTime + "]";
+        } else {
+            buildTime = "";
+        }
+
         String configuredProductVersion = this.getEnabledProductVersion();
 
         String errorNote = "";
@@ -281,7 +288,8 @@ public class OnapCommandRegistrar {
             errorNote = "** CUATION: Please configure the enabled product version to use one of " + this.availableProductVersions.toString() + ".";
 
         }
-        return "CLI version               : " + version + "\n"
+
+        return "CLI version               : " + version + buildTime + "\n"
                 + "Available product versions: " + this.availableProductVersions.toString() + "\n"
                 + "Enabled product version   : " + configuredProductVersion + "\n" +
                 errorNote + usageNote;
index d03ee10..ca70827 100644 (file)
@@ -108,6 +108,9 @@ import java.util.Map.Entry;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.UUID;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
 import java.util.stream.Collectors;
 
 import org.onap.cli.fw.OnapCommand;
@@ -1881,5 +1884,29 @@ public class OnapCommandUtils {
             }
         }
     }
+
+    /**
+     * Returns the build time from manifest.mf
+     */
+    public static String findLastBuildTime() {
+        String impBuildDate = "";
+        try
+        {
+            String path = OnapCommandUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+            JarFile jar = new JarFile(path);
+            Manifest manifest = jar.getManifest();
+            jar.close();
+
+            Attributes attributes = manifest.getMainAttributes();
+
+            impBuildDate = attributes.getValue("Build-Time");
+        }
+        catch (IOException e)
+        {
+            //Ignore it as it will never occur
+        }
+
+        return impBuildDate;
+    }
 }
 
diff --git a/pom.xml b/pom.xml
index 18241f9..15d3092 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -32,6 +32,7 @@
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <package.name>cli</package.name>
+        <maven.build.timestamp.format>yyyy-MM-dd HH:mm z</maven.build.timestamp.format>
     </properties>
 
   <modules>
@@ -71,6 +72,9 @@
                             <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                             <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                         </manifest>
+                        <manifestEntries>
+                            <Build-Time>${maven.build.timestamp}</Build-Time>
+                        </manifestEntries>
                     </archive>
                 </configuration>
             </plugin>