/** * resolve properties inside a properties object * * @param props properties to resolve * @param xmlProp * @param file */ private void resolveAllProperties(Properties props, IXMLElement xmlProp, File file) throws CompilerException { variableSubstitutor.setBracesRequired(true); for (Enumeration e = props.keys(); e.hasMoreElements(); ) { String name = (String) e.nextElement(); String value = props.getProperty(name); int mods = -1; do { StringReader read = new StringReader(value); StringWriter write = new StringWriter(); try { try { mods = variableSubstitutor.substitute(read, write, SubstitutionType.TYPE_AT); } catch (Exception e1) { throw new IOException(e1.getMessage()); } // TODO: check for circular references. We need to know // which // variables were substituted to do that props.put(name, value); } catch (IOException ex) { assertionHelper.parseError(xmlProp, "Faild to load file: " + file.getAbsolutePath(), ex); } } while (mods != 0); } }
/** * Set the property in the project to the value. If the task was give a file, resource or env * attribute here is where it is loaded. * * @param xmlProp */ public void execute(IXMLElement xmlProp) throws CompilerException { File file = null; String name = xmlProp.getAttribute("name"); String value = xmlProp.getAttribute("value"); String environnement = xmlProp.getAttribute("environment"); if (environnement != null && !environnement.endsWith(".")) { environnement += "."; } String prefix = xmlProp.getAttribute("prefix"); if (prefix != null && !prefix.endsWith(".")) { prefix += "."; } String filename = xmlProp.getAttribute("file"); if (filename != null) { file = new File(filename); } if (name != null) { if (value == null) { assertionHelper.parseError(xmlProp, "You must specify a value with the name attribute"); } } else { if (file == null && environnement == null) { assertionHelper.parseError( xmlProp, "You must specify file, or environment when not using the name attribute"); } } if (file == null && prefix != null) { assertionHelper.parseError(xmlProp, "Prefix is only valid when loading from a file "); } if ((name != null) && (value != null)) { addProperty(name, value); } else if (file != null) { loadFile(file, xmlProp, prefix); } else if (environnement != null) { loadEnvironment(environnement, xmlProp, file); } }
/** * load properties from a file * * @param file file to load * @param xmlProp * @param prefix */ private void loadFile(File file, IXMLElement xmlProp, String prefix) throws CompilerException { Properties props = new Properties(); packagerListener.packagerMsg("Loading " + file.getAbsolutePath(), PackagerListener.MSG_VERBOSE); try { if (file.exists()) { FileInputStream fis = new FileInputStream(file); try { props.load(fis); } finally { fis.close(); } addProperties(props, xmlProp, file, prefix); } else { packagerListener.packagerMsg( "Unable to find property file: " + file.getAbsolutePath(), PackagerListener.MSG_VERBOSE); } } catch (IOException ex) { assertionHelper.parseError(xmlProp, "Faild to load file: " + file.getAbsolutePath(), ex); } }