Update of /var/cvs/src/org/mmbase
In directory james.mmbase.org:/tmp/cvs-serv4336

Modified Files:
        Version.java 
Log Message:
We take the build-date from the manifest now


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase


Index: Version.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/Version.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- Version.java        29 Oct 2008 20:57:14 -0000      1.48
+++ Version.java        4 Apr 2009 09:44:11 -0000       1.49
@@ -10,6 +10,11 @@
 package org.mmbase;
 
 import java.io.*;
+import java.util.jar.*;
+import java.net.*;
+
+import org.mmbase.util.logging.Logger;
+import org.mmbase.util.logging.Logging;
 
 /**
  * MMBase version reporter. The only goal of this class is providing the 
current version of
@@ -17,10 +22,12 @@
  *
  * @author Daniel Ockeloen
  * @author Michiel Meeuwissen
- * @version $Id: Version.java,v 1.48 2008/10/29 20:57:14 michiel Exp $
+ * @version $Id: Version.java,v 1.49 2009/04/04 09:44:11 michiel Exp $
  */
 public class Version {
 
+    private static final Logger log = Logging.getLoggerInstance(Version.class);
+
     /**
      * Get Version Control tag
      * @return version Control tag
@@ -75,18 +82,12 @@
      */
     public static String getBuildDate() {
         String resource = "";
-        InputStream builddate = 
Version.class.getResourceAsStream("builddate.properties");
-        if (builddate != null) {
-            try {
-                BufferedReader buffer = new BufferedReader(new 
InputStreamReader(builddate));
-                resource =  buffer.readLine();
-                buffer.close();
-            } catch (IOException e) {
-                // error
-                resource = "" + e;
-            }
+        Manifest manifest = getManifest();
+        if (manifest != null) {
+            return manifest.getAttributes("org/mmbase").getValue("Build-Date");
+        } else {
+            return "";
         }
-        return resource;
     }
 
     /**
@@ -116,6 +117,7 @@
         return "";
     };
 
+
     /**
      * Returns the version of this MMBase.
      * @return version of this MMBase
@@ -131,6 +133,33 @@
     }
 
 
+    private static final String VERSION_CLASS = "org/mmbase/Version.class";
+    private static Manifest manifest;
+    private static boolean manifestLoaded = false;
+    /**
+     * Returns the Manifest of the jar in which this version is contained. Or 
<code>null</code> if
+     * it is not in a jar.
+     * @since MMBase-1.9.1
+     */
+    public static Manifest getManifest() {
+        if (! manifestLoaded) {
+            try {
+                URL url = 
Version.class.getClassLoader().getResource(VERSION_CLASS);
+                String u = url.toString();
+                String[] parts = u.split("!", 2);
+                if (parts.length == 2) {
+                    URL jarUrl = new URL(parts[0] + "!/");
+                    JarURLConnection jarConnection = 
(JarURLConnection)jarUrl.openConnection();
+                    manifest = jarConnection.getManifest();
+                }
+            } catch (IOException ioe) {
+                log.warn(ioe);
+            }
+            manifestLoaded = true;
+        }
+        return manifest;
+    }
+
     /**
      * Prints the version of this mmbase on stdout.
      * can be usefull on command line:
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to