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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Mar 22 09:38:36 EDT 2011


Author: jhalliday
Date: 2011-03-22 09:38:36 -0400 (Tue, 22 Mar 2011)
New Revision: 36861

Modified:
   labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java
   labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java
Log:
Fix handling of property files within archives on the classpath. JBTM-775


Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java	2011-03-21 20:03:35 UTC (rev 36860)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/FileLocator.java	2011-03-22 13:38:36 UTC (rev 36861)
@@ -54,14 +54,12 @@
 {
     /**
      * Locate the specific file.
-     * Return the (URL decoded) absolute pathname to the file or null.
+     * Return the file path or uri (if a resource within an archive on the classpath) or throw FileNotFoundExcpetion.
      */
     static String locateFile (String findFile, ClassLoader classLoader) throws FileNotFoundException
     {
         URL url;
         String fullPathName;
-        StringBuffer decodedPathName;
-        int pos, len, start;
 
         if (findFile == null)
             throw new FileNotFoundException("locateFile: null file name");
@@ -78,37 +76,8 @@
             return fullPathName;
 
         if ((url = locateByResource(findFile, classLoader)) != null)
-        {
-            /*
-        * The URL that we receive from getResource /might/ have ' '
-        * (space) characters converted to "%20" strings.  However,
-        * it doesn't have other URL encoding (e.g '+' characters are
-        * kept intact), so we'll just convert all "%20" strings to
-        * ' ' characters and hope for the best.
-        */
-            fullPathName = url.getFile();
-            pos = 0;
-            len = fullPathName.length();
-            start = 0;
-            decodedPathName = new StringBuffer();
+            return url.toString(); // no special decode handling any more.
 
-            while ((pos = fullPathName.indexOf(pct20, start)) != -1) {
-                decodedPathName.append(fullPathName.substring(start, pos));
-                decodedPathName.append(' ');
-                start = pos + pct20len;
-            }
-
-            if (start < len)
-                decodedPathName.append(fullPathName.substring(start, len));
-
-            fullPathName=decodedPathName.toString();
-
-            if (platformIsWindows())
-                fullPathName = fullPathName.substring(1, fullPathName.length());
-
-            return fullPathName;
-        }
-
         throw new FileNotFoundException("locateFile: file not found: " + findFile);
     }
 

Modified: labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java
===================================================================
--- labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java	2011-03-21 20:03:35 UTC (rev 36860)
+++ labs/jbosstm/trunk/common/classes/com/arjuna/common/util/propertyservice/PropertiesFactory.java	2011-03-22 13:38:36 UTC (rev 36861)
@@ -67,17 +67,11 @@
      */
     public static Properties getPropertiesFromFile(String propertyFileName, ClassLoader classLoader)
     {
-        String filepath = null;
+        String propertiesSourceUri = null;
         try
         {
-            // Convert the possibly relative path into a canonical path, using FileLocator.
             // This is the point where the search path is applied - user.dir (pwd), user.home, java.home, classpath
-            filepath = com.arjuna.common.util.propertyservice.FileLocator.locateFile(propertyFileName, classLoader);
-            File propertyFile = new File(filepath);
-            if(!propertyFile.exists() || !propertyFile.isFile()) {
-                throw new RuntimeException("invalid property file "+filepath);
-            }
-            filepath = propertyFile.getCanonicalPath();
+            propertiesSourceUri = com.arjuna.common.util.propertyservice.FileLocator.locateFile(propertyFileName, classLoader);
         }
         catch(FileNotFoundException fileNotFoundException)
         {
@@ -88,22 +82,22 @@
             if(url == null) {
                 throw new RuntimeException("missing property file "+propertyFileName);
             } else {
-                filepath = url.toString();
+                propertiesSourceUri = url.toString();
             }
         }
         catch (IOException e)
         {
-            throw new RuntimeException("invalid property file "+filepath, e);
+            throw new RuntimeException("invalid property file "+propertiesSourceUri, e);
         }
 
         Properties properties = null;
 
         try {
-            properties = loadFromFile(filepath);
+            properties = loadFromFile(propertiesSourceUri);
             properties = applySystemProperties(properties);
 
         } catch(Exception e) {
-            throw new RuntimeException("unable to load properties from file "+filepath, e);
+            throw new RuntimeException("unable to load properties from "+propertiesSourceUri, e);
         }
 
         return properties;
@@ -133,6 +127,7 @@
         if( new File(uri).exists() ) {
             inputStream = new FileInputStream(uri);
         } else {
+            // it's probably a file embedded in a .jar
             inputStream = new URL(uri).openStream();
         }
 



More information about the jboss-svn-commits mailing list