[Swift-commit] r7916 - in branches/release-0.95/src: . org/griphyn/vdl/karajan org/griphyn/vdl/util

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Thu Jun 12 21:10:23 CDT 2014


Author: hategan
Date: 2014-06-12 21:10:23 -0500 (Thu, 12 Jun 2014)
New Revision: 7916

Modified:
   branches/release-0.95/src/
   branches/release-0.95/src/org/griphyn/vdl/karajan/Loader.java
   branches/release-0.95/src/org/griphyn/vdl/util/ConfigPropertyType.java
   branches/release-0.95/src/org/griphyn/vdl/util/VDL2Config.java
Log:
port of properties fix take II from trunk


Property changes on: branches/release-0.95/src
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/release-0.94/src:6283-6619,6999-7001,7125
/trunk/src:6214,6255,6275-6618
   + /branches/release-0.94/src:6283-6619,6999-7001,7125
/trunk/src:6214,6255,6275-6618,7913,7915

Modified: branches/release-0.95/src/org/griphyn/vdl/karajan/Loader.java
===================================================================
--- branches/release-0.95/src/org/griphyn/vdl/karajan/Loader.java	2014-06-13 02:05:17 UTC (rev 7915)
+++ branches/release-0.95/src/org/griphyn/vdl/karajan/Loader.java	2014-06-13 02:10:23 UTC (rev 7916)
@@ -110,9 +110,10 @@
             checkValidProject(project);
             String projectName = projectName(project);
        
-            setupLogging(ap, projectName, runID);
             VDL2Config config = loadConfig(ap);
             addCommandLineProperties(config, ap);
+            config.validateProperties();
+            setupLogging(ap, projectName, runID);
             logBasicInfo(argv, runID, config);
             debugSitesText(config);
             debugTCText(config);
@@ -472,14 +473,12 @@
 
     private static void addCommandLineProperties(VDL2Config config,
             ArgumentParser ap) {
+        config.setCurrentFile("<command line>");
         Map<String, PropInfo> desc = VDL2ConfigProperties.getPropertyDescriptions();
         for (Map.Entry<String, PropInfo> e : desc.entrySet()) {
             String name = e.getKey();
             if (ap.isPresent(name)) {
             	String value = ap.getStringValue(name);
-            	if (logger.isDebugEnabled()) {
-            	    logger.debug("setting: " + name + " to: " + value);
-            	}
             	config.setProperty(name, value);
             }
         }

Modified: branches/release-0.95/src/org/griphyn/vdl/util/ConfigPropertyType.java
===================================================================
--- branches/release-0.95/src/org/griphyn/vdl/util/ConfigPropertyType.java	2014-06-13 02:05:17 UTC (rev 7915)
+++ branches/release-0.95/src/org/griphyn/vdl/util/ConfigPropertyType.java	2014-06-13 02:10:23 UTC (rev 7916)
@@ -27,7 +27,7 @@
         return new Choices(values);
     }
     
-    public abstract void checkValue(String propName, String value);
+    public abstract void checkValue(String propName, String value, String source);
     
     private static String pp(Collection<String> c) {
         StringBuilder sb = new StringBuilder();
@@ -54,9 +54,9 @@
         }
 
         @Override
-        public void checkValue(String propName, String value) {
+        public void checkValue(String propName, String value, String source) {
             if (!choices.contains(value)) {
-                throw new IllegalArgumentException("Invalid value '" + value + "' for property '" + 
+                throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" + 
                     propName + "'. Valid values are: " + pp(choices));
             }
         }
@@ -64,19 +64,19 @@
     
     private static class CPTString extends ConfigPropertyType {
         @Override
-        public void checkValue(String propName, String value) {
+        public void checkValue(String propName, String value, String source) {
             // all values accepted
         }
     }
     
     private static class Int extends ConfigPropertyType {
         @Override
-        public void checkValue(String propName, String value) {
+        public void checkValue(String propName, String value, String source) {
             try {
                 Integer.parseInt(value);
             }
             catch (NumberFormatException e) {
-                throw new IllegalArgumentException("Invalid value '" + value + "' for property '" + 
+                throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" + 
                     propName + "'. Must be an integer");
             }
         }
@@ -84,12 +84,12 @@
     
     private static class CPTFloat extends ConfigPropertyType {
         @Override
-        public void checkValue(String propName, String value) {
+        public void checkValue(String propName, String value, String source) {
             try {
                 Double.parseDouble(value);
             }
             catch (NumberFormatException e) {
-                throw new IllegalArgumentException("Invalid value '" + value + "' for property '" + 
+                throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" + 
                     propName + "'. Must be a floating point number.");
             }
         }
@@ -97,10 +97,10 @@
     
     private static class CPTFile extends ConfigPropertyType {
         @Override
-        public void checkValue(String propName, String value) {
+        public void checkValue(String propName, String value, String source) {
             File f = new File(value);
             if (!f.exists()) {
-                throw new IllegalArgumentException("Invalid value '" + value + "' for property '" + 
+                throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" + 
                     propName + "'. File does not exist.");
             }
         }

Modified: branches/release-0.95/src/org/griphyn/vdl/util/VDL2Config.java
===================================================================
--- branches/release-0.95/src/org/griphyn/vdl/util/VDL2Config.java	2014-06-13 02:05:17 UTC (rev 7915)
+++ branches/release-0.95/src/org/griphyn/vdl/util/VDL2Config.java	2014-06-13 02:10:23 UTC (rev 7916)
@@ -80,16 +80,18 @@
 		c.load(file);
 		config = c;
 		config.check();
-		config.validateProperties();
 		return config;
 	}
 
 	private List<String> files, tried;
 	private Map<Object, ConfigPropertyType> types;
+	private Map<Object, String> propertySource;
+	private String currentFile;
 
 	private VDL2Config() {
 		files = new LinkedList<String>();
 		tried = new LinkedList<String>();
+		propertySource = new HashMap<Object, String>();
 		types = new HashMap<Object, ConfigPropertyType>();
 		put(VDL2ConfigProperties.POOL_FILE, "${swift.home}/etc/sites.xml", ConfigPropertyType.FILE);
 		put(VDL2ConfigProperties.TC_FILE, "${swift.home}/etc/tc.data", ConfigPropertyType.FILE);
@@ -132,9 +134,11 @@
 	private VDL2Config(VDL2Config other) {
 		this.putAll(other);
 		this.files.addAll(other.files);
+		this.propertySource.putAll(other.propertySource);
 	}
 
 	protected void load(String file) throws IOException {
+	    this.currentFile = file;
 		tried.add(file);
 		File f = new File(file);
 		if (f.exists()) {
@@ -155,7 +159,7 @@
 		}
 	}
 
-	private void validateProperties() {
+	public void validateProperties() {
 	    for (Map.Entry<Object, Object> e : this.entrySet()) {
 	        checkType(e.getKey(), e.getValue());
 	    }
@@ -181,6 +185,7 @@
 	 * occur.
 	 */
 	public synchronized Object put(Object key, Object value) {
+	    propertySource.put(key, currentFile);
 		String svalue = (String) value;
 		if (svalue.indexOf("${") == -1) {
 			return super.put(key, value);
@@ -223,7 +228,7 @@
 	private void checkType(Object key, Object value) {
 	    ConfigPropertyType type = types.get(key);
 	    if (type != null) {
-	        type.checkValue((String) key, (String) value);
+	        type.checkValue((String) key, (String) value, propertySource.get(key));
 	    }
     }
 
@@ -287,6 +292,8 @@
 	public Object clone() {
 		VDL2Config conf = new VDL2Config();
 		conf.putAll(this);
+		conf.files.addAll(files);
+        conf.propertySource.putAll(propertySource);
 		return conf;
 	}
 
@@ -305,4 +312,8 @@
 		}
 		return getProperty(name);
 	}
+
+    public void setCurrentFile(String f) {
+        this.currentFile = f;
+    }
 }




More information about the Swift-commit mailing list