/// <summary> /// This method is only meant to be used by the <see cref="Project"/> /// class and <see cref="T:NAnt.Core.Tasks.IncludeTask"/>. /// </summary> internal void InitializeProjectDocument(XmlDocument doc) { // load line and column number information into position map LocationMap.Add(doc); // initialize targets first foreach (XmlNode childNode in doc.DocumentElement.ChildNodes) { // skip non-nant namespace elements and special elements like // comments, pis, text, etc. if (childNode.LocalName.Equals(TargetXml) && childNode.NamespaceURI.Equals(NamespaceManager.LookupNamespace("nant"))) { Target target = new Target(); target.Project = this; target.Parent = this; target.NamespaceManager = NamespaceManager; target.Initialize(childNode); Targets.Add(target); } } // initialize datatypes and execute global tasks foreach (XmlNode childNode in doc.DocumentElement.ChildNodes) { // skip targets that were handled above, skip non-nant namespace // elements and special elements like comments, pis, text, etc. if (!(childNode.NodeType == XmlNodeType.Element) || !childNode.NamespaceURI.Equals(NamespaceManager.LookupNamespace("nant")) || childNode.LocalName.Equals(TargetXml)) { continue; } if (TypeFactory.TaskBuilders.Contains(childNode.Name)) { // create task instance Task task = CreateTask(childNode); task.Parent = this; // execute task task.Execute(); } else if (TypeFactory.DataTypeBuilders.Contains(childNode.Name)) { // we are an datatype declaration DataTypeBase dataType = CreateDataTypeBase(childNode); Log(Level.Debug, "Adding a {0} reference with id '{1}'.", childNode.Name, dataType.ID); if (! DataTypeReferences.Contains(dataType.ID)) { DataTypeReferences.Add(dataType.ID, dataType); } else { DataTypeReferences[dataType.ID] = dataType; // overwrite with the new reference. } } else { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1071"), childNode.Name), LocationMap.GetLocation(childNode)); } } }
private Target CreateMultitaskTarget(Project proj, String multitaskTargetName) { //Create a new target which will contain the tasks from the <multitask> //To preserve line numbers as much as possible, build the Target object //from the XmlNode for this task; it shouldn't work, but it does, since //the Initialize() method for each NAnt element assumes the node being passed to it //is the right type. //Change the 'name' property so the 'target' will be identifiable XmlAttribute name = XmlNode.Attributes["name"]; String oldName = null; if (name == null) { name = XmlNode.OwnerDocument.CreateAttribute("name"); } else { oldName = name.Value; } try { name.Value = multitaskTargetName; XmlNode.Attributes.Append(name); Target targ = new Target(); targ.Project = proj; targ.NamespaceManager = NamespaceManager; targ.Initialize(XmlNode); return targ; } finally { //Restore the previous name if (oldName == null) { XmlNode.Attributes.Remove(name); } else { name.Value = oldName; } } }