[jboss-svn-commits] JBL Code SVN: r29831 - labs/jbosstm/trunk/common/classes/com/arjuna/common/util.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 27 06:43:08 EDT 2009


Author: jhalliday
Date: 2009-10-27 06:43:07 -0400 (Tue, 27 Oct 2009)
New Revision: 29831

Modified:
   labs/jbosstm/trunk/common/classes/com/arjuna/common/util/ConfigurationInfo.java
Log:
Fix for MANIFEST.MF finding code. JBTM-628


Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/ConfigurationInfo.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/ConfigurationInfo.java	2009-10-27 10:41:58 UTC (rev 29830)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/ConfigurationInfo.java	2009-10-27 10:43:07 UTC (rev 29831)
@@ -77,14 +77,23 @@
 
     // initialize build time properties from data in the jar's META-INF/MANIFEST.MF
     private static void getBuildTimeProperties() {
-        
-        // our classloader's classpath may contain more than one .jar, each with a manifest.
-        // we need to ensure we get our own .jar's manifest, even if the jar is not first on the path.
+        /*
+        our classloader's classpath may contain more than one .jar, each with a manifest.
+        we need to ensure we get our own .jar's manifest, even if the jar is not first on the path.
+        we also need to deal with vfs, which does weird things to pathToThisClass e.g.
+          normal: jar:file:/foo/bar.jar!/com/arjuna/common/util/ConfigurationInfo.class
+          vfszip:/foo/bar.jar/com/arjuna/common/util/ConfigurationInfo.class
+        In short, this path finding code is magic and should be approached very cautiously.
+         */
         String classFileName = ConfigurationInfo.class.getSimpleName()+".class";
         String pathToThisClass = ConfigurationInfo.class.getResource(classFileName).toString();
-        int mark = pathToThisClass.indexOf("!") ;
-        String pathToManifest = (pathToThisClass.substring(0,mark+1))+"/META-INF/MANIFEST.MF";
+        // we need to strip off the class name bit so we can replace it with the manifest name: 
+        int suffixLength = ("/"+ConfigurationInfo.class.getCanonicalName()+".class").length();
+        // now derive the path to the .jar which contains the class and thus hopefully the right manifest:
+        String basePath = pathToThisClass.substring(0, pathToThisClass.length()-suffixLength);
 
+        String pathToManifest = basePath+"/META-INF/MANIFEST.MF";
+
         InputStream is = null;
         try {
             is = new URL(pathToManifest).openStream();



More information about the jboss-svn-commits mailing list