1 16 package org.outerj.daisy.maven.versioninfo; 17 18 import java.net.InetAddress ; 19 import java.net.UnknownHostException ; 20 import java.util.Properties ; 21 import java.util.Locale ; 22 import java.util.Date ; 23 import java.text.DateFormat ; 24 import java.text.SimpleDateFormat ; 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.IOException ; 28 29 public class VersionInfoPlugin { 30 public static void generateVersionInfo(String propFilePath, String version) throws IOException { 31 Properties versionInfo = new Properties (); 32 33 versionInfo.put("artifact.version", version); 34 35 String hostName; 36 try { 37 hostName = InetAddress.getLocalHost().getHostName(); 38 } catch (UnknownHostException e) { 39 hostName = "Unknown"; 40 } 41 versionInfo.put("build.hostname", hostName); 42 43 versionInfo.put("build.user.name", System.getProperty("user.name")); 44 versionInfo.put("build.os.name", System.getProperty("os.name")); 45 versionInfo.put("build.os.arch", System.getProperty("os.arch")); 46 versionInfo.put("build.os.version", System.getProperty("os.version")); 47 versionInfo.put("build.java.vm.version", System.getProperty("java.vm.version")); 48 versionInfo.put("build.java.vm.vendor", System.getProperty("java.vm.vendor")); 49 versionInfo.put("build.java.vm.name", System.getProperty("java.vm.name")); 50 51 SimpleDateFormat dateFormat = (SimpleDateFormat )DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); 52 dateFormat.applyPattern("yyyyMMdd"); 53 SimpleDateFormat dateTimeFormat = (SimpleDateFormat )DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.US); 54 dateTimeFormat.applyPattern("yyyyMMdd HH:mm:ssZ"); 55 56 Date now = new Date (); 57 versionInfo.put("build.date", dateFormat.format(now)); 58 versionInfo.put("build.datetime", dateTimeFormat.format(now)); 59 60 File file = new File (propFilePath); 61 file.getParentFile().mkdirs(); 62 FileOutputStream fos = new FileOutputStream (file); 63 try { 64 versionInfo.store(fos, "Daisy build & version info"); 65 } finally { 66 fos.close(); 67 } 68 } 69 } 70 | Popular Tags |