1 21 22 package org.apache.derbyBuild; 23 import java.util.Properties ; 24 import java.io.FileInputStream ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.File ; 28 29 import java.util.StringTokenizer ; 30 import java.util.Properties ; 31 import java.util.Enumeration ; 32 33 34 60 61 public class propertyconfig { 62 63 public static String header = 64 "######## This is a generated file, do not edit.\n" + 65 "#\n# This file is generated as by propertyConfig\n" + 66 "#\n"; 67 68 public static String footer = 69 "\n######## This is a generated file, do not edit.\n"; 70 71 public static void main(String [] args) throws IOException 72 { 73 if (args.length != 3) 74 printUsageAndExit(); 75 76 File masterfile = new File (args[0]); 77 File outputfile = new File (args[2]); 78 79 if (!masterfile.exists()) 80 printUsageAndExit(); 81 82 Properties masterProp = new Properties (); 84 FileInputStream is = new FileInputStream (masterfile); 85 86 try 87 { 88 masterProp.load(is); 89 } 90 finally 91 { 92 if (is != null) 93 is.close(); 94 } 95 96 process(masterProp, args[1], outputfile); 97 } 98 99 111 private static void process(Properties moduleList, String config, 112 File outputfile) 113 throws IOException 114 { 115 Properties outputProp = new Properties (); 116 117 for (Enumeration e = moduleList.propertyNames(); e.hasMoreElements(); ) 121 { 122 String key = (String ) e.nextElement(); 123 if (key.startsWith("derby.module.")) 124 { 125 String tag = key.substring("derby.module.".length()); 126 127 String configKey = "cloudscape.config.".concat(tag); 129 String configProp = moduleList.getProperty(configKey); 130 131 boolean match = false; 132 133 if (configProp != null) 134 { 135 StringTokenizer st = new StringTokenizer (configProp, ","); 136 while(st.hasMoreTokens()) 137 { 138 139 String s = st.nextToken().trim(); 140 141 if (s.equalsIgnoreCase("all") && 144 !configProp.trim().equals("all")) 145 { 146 System.out.println("illegal config specification " 147 + key); 148 System.exit(3); 149 } 150 151 if (s.equalsIgnoreCase("none") && 154 !configProp.trim().equals("none")) 155 { 156 System.out.println("illegal config specification " 157 + key); 158 System.exit(4); 159 } 160 161 if (s.equalsIgnoreCase(config) || 162 s.equalsIgnoreCase("all")) 163 { 164 match = true; 165 break; 166 } 167 } 168 } 169 else 170 { 171 System.out.println("Need config specification for " + key); 173 System.exit(2); 174 } 175 176 if (match) 177 { 178 181 outputProp.put(key, moduleList.getProperty(key)); 183 184 187 String envKey = "derby.env.classes.".concat(tag); 189 if (moduleList.getProperty(envKey) != null) 190 outputProp.put(envKey, moduleList.getProperty(envKey)); 191 192 envKey = "derby.env.jdk.".concat(tag); 219 220 if (moduleList.getProperty(envKey) != null) 221 { 222 boolean saveEnvKey = true; 225 226 if (tag.endsWith("J1") || tag.endsWith("J2")) 229 { 230 int length = tag.length() - 2; 235 String alternateTag = tag.substring(0, length); 236 237 if (tag.endsWith("J1")) 238 alternateTag += "J2"; 239 else 240 alternateTag += "J1"; 241 242 248 String alternateImplKey = 249 "derby.module."+ alternateTag; 250 String alternateJDKEnv = 251 "derby.env.jdk."+ alternateTag; 252 String alternateImplConfigKey = 253 "cloudscape.config."+alternateTag; 254 255 262 if ((moduleList.getProperty(alternateImplKey) != null) && 263 (moduleList.getProperty(alternateJDKEnv) != null) && 264 (moduleList.getProperty(alternateImplConfigKey) != null)) 265 { 266 String alternateConfigProp = 270 moduleList.getProperty(alternateImplConfigKey); 271 272 StringTokenizer st2 = new 280 StringTokenizer (alternateConfigProp, ","); 281 282 boolean ok = false; 283 while(st2.hasMoreTokens()) 284 { 285 String s = st2.nextToken().trim(); 286 287 if (s.equalsIgnoreCase(config) || 288 s.equalsIgnoreCase("all")) 289 { 290 ok = true; 291 break; 292 } 293 } 294 if (!ok) 297 saveEnvKey = false; 298 } 299 } 300 301 if (saveEnvKey) 302 outputProp.put(envKey, moduleList.getProperty(envKey)); 303 } 304 305 306 307 } 310 } 311 } 312 313 FileOutputStream os = new FileOutputStream (outputfile); 314 try 315 { 316 outputProp.save(os, 317 header. 318 concat("# config is ").concat(config). 319 concat(footer)); 320 } 321 finally 322 { 323 if (os != null) 324 os.close(); 325 } 326 } 327 328 329 private static void printUsageAndExit() 330 { 331 StringBuffer buf = new StringBuffer (400); 332 333 buf.append("Usage propertyConfig <masterFile> <config> <outputFile>\n") 334 .append("masterFile must be a pre-existing properties file ") 335 .append("containing all the modules properites\n") 336 .append("config must be a configuration defined in ") 337 .append("org.apache.derby.modules.properties.\n") 338 .append("outputFile must not be a pre-existing properties file.\n\n") 339 .append("propertyConfig will generate the outputFile based on") 340 .append("the masterfile and the configuration specified.") 341 .append("\n\nE.g., java propertyConfig dbms.properties cloudsync dbms.cloudsync.properties\n"); 342 343 344 System.out.println(buf.toString()); 345 System.exit(1); 346 } 347 } 348 | Popular Tags |