lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r779683 - /lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java
Date Thu, 28 May 2009 17:27:57 GMT
Author: mikemccand
Date: Thu May 28 17:27:57 2009
New Revision: 779683

URL: http://svn.apache.org/viewvc?rev=779683&view=rev
Log:
LUCENE-1666: use LucenePackage to get version from JAR's manifest, if available

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java?rev=779683&r1=779682&r2=779683&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java Thu May 28 17:27:57 2009
@@ -17,10 +17,7 @@
  * limitations under the License.
  */
 
-import java.util.jar.Manifest;
-import java.util.jar.Attributes;
-import java.io.InputStream;
-import java.net.URL;
+import org.apache.lucene.LucenePackage;
 
 /**
  * Some useful constants.
@@ -54,38 +51,17 @@
   public static final String OS_VERSION = System.getProperty("os.version");
   public static final String JAVA_VENDOR = System.getProperty("java.vendor");
 
-  public static final String LUCENE_VERSION;
-
   public static final String LUCENE_MAIN_VERSION = "2.9";
 
+  public static final String LUCENE_VERSION;
   static {
-    String v = LUCENE_MAIN_VERSION + "-dev";
-    try {
-      // TODO: this should have worked, but doesn't seem to?
-      // Package.getPackage("org.apache.lucene.util").getImplementationVersion();
-      String classContainer = Constants.class.getProtectionDomain().getCodeSource().getLocation().toString();
-      URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
-      InputStream s = manifestUrl.openStream();
-      try {
-        Manifest manifest = new Manifest(s);
-        Attributes attr = manifest.getMainAttributes();
-        String value = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
-        if (value != null) {
-          if (value.indexOf(LUCENE_MAIN_VERSION) == -1) {
-            v = value + " [" + LUCENE_MAIN_VERSION + "]";
-          } else {
-            v = value;
-          }
-        }
-      } finally {
-        if (s != null) {
-          s.close();
-        }
-      }
-    } catch (Throwable t) {
-      // ignore
+    Package pkg = LucenePackage.get();
+    String v = (pkg == null) ? null : pkg.getImplementationVersion();
+    if (v == null) {
+      v = LUCENE_MAIN_VERSION + "-dev";
+    } else if (v.indexOf(LUCENE_MAIN_VERSION) == -1) {
+      v = v + " [" + LUCENE_MAIN_VERSION + "]";
     }
-
     LUCENE_VERSION = v;
   }
 }



Mime
View raw message