private void LoadFile(FilterChain filterChain) { string content = null; try { content = FileUtils.ReadFile(File.FullName, filterChain, Encoding); } catch (IOException ex) { throw new BuildException("The properties file could not be read.", Location, ex); } PropertyDictionary properties = Project.Properties; PropertyTask propertyTask = new PropertyTask(); propertyTask.Parent = this; propertyTask.Project = Project; using (StringReader sr = new StringReader(content)) { string line = sr.ReadLine(); int current_line = 0; while (line != null) { current_line++; // skip empty lines and comments if (String.IsNullOrEmpty(line) || line.StartsWith("#")) { line = sr.ReadLine(); continue; } int equals_pos = line.IndexOf('='); if (equals_pos == -1) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Invalid property defined on line {0}.", current_line), Location); } string name = line.Substring(0, equals_pos).Trim(); string value = line.Substring(equals_pos + 1, line.Length - equals_pos - 1).Trim(); string expandedValue = properties.ExpandProperties(value, Location); propertyTask.PropertyName = name; propertyTask.Value = expandedValue; propertyTask.Execute(); line = sr.ReadLine(); } } }
private static void SetUpProperties(ArrayList attributeList, Task task, XmlNode xml, PropertyDictionary oldPropertyValues) { PropertyDictionary projectProperties = task.Project.Properties; StringBuilder logMessage = new StringBuilder(); foreach (MacroAttribute macroAttribute in attributeList) { string attributeName = macroAttribute.name; XmlAttribute xmlAttribute = xml.Attributes[attributeName]; string value = null; if (xmlAttribute != null) { value = projectProperties.ExpandProperties(xmlAttribute.Value, null); } else if (macroAttribute.defaultValue != null) { value = macroAttribute.defaultValue; } string localPropertyName = macroAttribute.LocalPropertyName; task.Log(Level.Debug, "Setting property " + localPropertyName + " to " + value); if (logMessage.Length > 0) { logMessage.Append(", "); } logMessage.Append(localPropertyName); logMessage.Append(" = '"); logMessage.Append(value); logMessage.Append("'"); if (projectProperties.Contains(localPropertyName)) { oldPropertyValues.Add(localPropertyName, projectProperties[localPropertyName]); projectProperties.Remove(localPropertyName); } if (value != null) { projectProperties.Add(localPropertyName, value); } } task.Log(Level.Info, logMessage.ToString()); }