ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r781817 - in /ode/branches/APACHE_ODE_1.X: ./ utils/src/main/java/org/apache/ode/utils/ utils/src/test/java/org/apache/ode/utils/ utils/src/test/resources/
Date Thu, 04 Jun 2009 18:11:52 GMT
Author: midon
Date: Thu Jun  4 18:11:52 2009
New Revision: 781817

URL: http://svn.apache.org/viewvc?rev=781817&view=rev
Log:
ODE-619: property names must not start with 'system.' nor 'env.

Added:
    ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-bad.properties
Modified:
    ode/branches/APACHE_ODE_1.X/Rakefile
    ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
    ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java

Modified: ode/branches/APACHE_ODE_1.X/Rakefile
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/Rakefile?rev=781817&r1=781816&r2=781817&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/Rakefile (original)
+++ ode/branches/APACHE_ODE_1.X/Rakefile Thu Jun  4 18:11:52 2009
@@ -520,7 +520,7 @@
 
   desc "ODE Utils"
   define "utils" do
-    compile.with AXIOM, AXIS2_ALL, COMMONS.collections, COMMONS.logging, COMMONS.pool, COMMONS.httpclient,
COMMONS.codec, LOG4J, XERCES, JAVAX.stream, WSDL4J, SAXON
+    compile.with AXIOM, AXIS2_ALL, COMMONS.lang, COMMONS.collections, COMMONS.logging, COMMONS.pool,
COMMONS.httpclient, COMMONS.codec, LOG4J, XERCES, JAVAX.stream, WSDL4J, SAXON
     test.exclude "*TestResources"
     package :jar
   end

Modified: ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java?rev=781817&r1=781816&r2=781817&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
(original)
+++ ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/HierarchicalProperties.java
Thu Jun  4 18:11:52 2009
@@ -23,21 +23,15 @@
 import org.apache.commons.collections.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
 import org.apache.ode.utils.fs.FileUtils;
 
 import javax.xml.namespace.QName;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
 import java.util.Properties;
-import java.util.Set;
-import java.util.Arrays;
-import java.util.List;
 
 /**
  * This class load a list of regular property files (order matters). The main feature is
that property can
@@ -81,7 +75,7 @@
  * <p>
  * If a property name ends with ".file" or ".path", the assumption is made that the associated
value is a path and as such is resolved against the path of the file it was loaded from.
  * </p>
- * This class is not thread-safe.
+ * Assigned properties must not start with 'system.' or 'env.'. These prefix are reserved
to access system properties and environment variables.
  *
  * @author <a href="mailto:midon@intalio.com">Alexis Midon</a>
  */
@@ -154,7 +148,7 @@
         for (File file : files) loadFile(file);
     }
 
-    public void loadFile(File file) throws IOException {
+    private void loadFile(File file) throws IOException {
         if (!file.exists()) {
             if (log.isDebugEnabled()) log.debug("File does not exist [" + file + "]");
             return;
@@ -169,6 +163,8 @@
             fis.close();
         }
 
+        validatePropertyNames(props, file);
+
         // gather all aliases
         Map<String, String> nsByAlias = new HashMap<String, String>();
 
@@ -178,7 +174,6 @@
             String key = (String) e.getKey();
             String value = (String) e.getValue();
 
-
             // replace any env variables by its value
             value = SystemUtils.replaceSystemProperties(value);
             props.put(key, value);
@@ -245,6 +240,17 @@
         }
     }
 
+    private void validatePropertyNames(Properties props, File file) {
+        List invalids = new ArrayList();
+        for (Iterator<Object> it = props.keySet().iterator(); it.hasNext();) {
+            String name = (String) it.next();
+            if(name.startsWith("system.") || name.startsWith("env.")) invalids.add(name);
+        }
+        if(!invalids.isEmpty()){
+            throw new IllegalArgumentException("Property files cannot define properties starting
with 'system.' nor 'env.' File="+file+". Invalid names="+StringUtils.join(invalids, ","));
+        }
+    }
+
 
     /**
      * Clear all content. If {@link #loadFiles()} is not invoked later, all returned values
will be null.

Modified: ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java?rev=781817&r1=781816&r2=781817&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
(original)
+++ ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/HierarchicalPropertiesTest.java
Thu Jun  4 18:11:52 2009
@@ -23,9 +23,8 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.net.URISyntaxException;
 
 import org.apache.ode.utils.fs.FileUtils;
 
@@ -77,6 +76,18 @@
 
     }
 
+    public void testReservedNames() {
+        String s = "Property files cannot define properties starting with ";
+        try {
+            HierarchicalProperties f = new HierarchicalProperties(new File(getClass().getResource("/hierarchical-bad.properties").toURI()));
+            fail(s);
+        } catch (Exception e) {
+            assertTrue(s, e.getMessage().contains(s));
+            assertTrue(s, e.getMessage().contains("system.foo"));
+            assertTrue(s, e.getMessage().contains("env.BAR"));
+        }
+    }
+
     public void testWithNoFile() throws IOException {
         File file = new File("/a-file-that-does-not-exist");
         Map m = new HierarchicalProperties(file).getProperties("an-uri", "a-service", "a-port");

Added: ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-bad.properties
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-bad.properties?rev=781817&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-bad.properties (added)
+++ ode/branches/APACHE_ODE_1.X/utils/src/test/resources/hierarchical-bad.properties Thu Jun
 4 18:11:52 2009
@@ -0,0 +1,4 @@
+
+
+system.foo=bar
+env.BAR=foo



Mime
View raw message