KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > maven > versioninfo > VersionInfoPlugin


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.maven.versioninfo;
17
18 import java.net.InetAddress JavaDoc;
19 import java.net.UnknownHostException JavaDoc;
20 import java.util.Properties JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.util.Date JavaDoc;
23 import java.text.DateFormat JavaDoc;
24 import java.text.SimpleDateFormat JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 public class VersionInfoPlugin {
30     public static void generateVersionInfo(String JavaDoc propFilePath, String JavaDoc version) throws IOException JavaDoc {
31         Properties JavaDoc versionInfo = new Properties JavaDoc();
32
33         versionInfo.put("artifact.version", version);
34
35         String JavaDoc hostName;
36         try {
37             hostName = InetAddress.getLocalHost().getHostName();
38         } catch (UnknownHostException JavaDoc 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 JavaDoc dateFormat = (SimpleDateFormat JavaDoc)DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
52         dateFormat.applyPattern("yyyyMMdd");
53         SimpleDateFormat JavaDoc dateTimeFormat = (SimpleDateFormat JavaDoc)DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.US);
54         dateTimeFormat.applyPattern("yyyyMMdd HH:mm:ssZ");
55
56         Date JavaDoc now = new Date JavaDoc();
57         versionInfo.put("build.date", dateFormat.format(now));
58         versionInfo.put("build.datetime", dateTimeFormat.format(now));
59
60         File JavaDoc file = new File JavaDoc(propFilePath);
61         file.getParentFile().mkdirs();
62         FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(file);
63         try {
64             versionInfo.store(fos, "Daisy build & version info");
65         } finally {
66             fos.close();
67         }
68     }
69 }
70
Popular Tags