コード例 #1
0
        protected override void ExecuteTask()
        {
            PropertyTask Property = new PropertyTask(this.PropertyName, this.TextValue.Value, this.ReadOnly, this.Dynamic, this.Overwrite);

            Property.Parent  = this.Parent;
            Property.Project = this.Project;
            Property.Execute();
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Reads the list of global properties specified in the NAnt configuration
        /// file.
        /// </summary>
        /// <param name="propertyNodes">An <see cref="XmlNodeList" /> representing global properties.</param>
        private void ProcessGlobalProperties(XmlNodeList propertyNodes)
        {
            //deals with xml info from the config file, not build document.
            foreach (XmlNode propertyNode in propertyNodes)
            {
                //skip special elements like comments, pis, text, etc.
                if (!(propertyNode.NodeType == XmlNodeType.Element))
                {
                    continue;
                }

                // initialize task
                PropertyTask propertyTask = new PropertyTask();
                propertyTask.Parent           = propertyTask.Project = Project;
                propertyTask.NamespaceManager = NamespaceManager;
                propertyTask.InitializeTaskConfiguration();
                // configure using xml node
                propertyTask.Initialize(propertyNode);
                // execute task
                propertyTask.Execute();
            }
        }
コード例 #4
0
        protected override void ExecuteTask()
        {
            XmlDocument xml = new XmlDocument();

            using (XmlTextReader reader = new XmlTextReader(_propertiesFile))
                xml.Load(reader);

            XmlNodeList properties = xml.GetElementsByTagName("property");

            int counter = 0;

            foreach (XmlNode property in properties)
            {
                string name = string.Empty, value = string.Empty;
                bool   readOnly = false, dynamic = false, overwrite = true;

                if (property.Attributes["name"] != null)
                {
                    name = string.IsNullOrEmpty(property.Attributes["name"].Value)
                        ? string.Empty : property.Attributes["name"].Value;
                }

                if (property.Attributes["value"] != null)
                {
                    value = string.IsNullOrEmpty(property.Attributes["value"].Value)
                        ? string.Empty : property.Attributes["value"].Value;
                }

                if (property.Attributes["readonly"] != null)
                {
                    readOnly = string.IsNullOrEmpty(property.Attributes["readonly"].Value)
                        ? false : GetBooleanValue(property.Attributes["readonly"].Value, false);
                }

                if (property.Attributes["dynamic"] != null)
                {
                    dynamic = string.IsNullOrEmpty(property.Attributes["dynamic"].Value)
                        ? false : GetBooleanValue(property.Attributes["dynamic"].Value, false);
                }

                if (property.Attributes["overwrite"] != null)
                {
                    overwrite = string.IsNullOrEmpty(property.Attributes["overwrite"].Value)
                        ? true : GetBooleanValue(property.Attributes["overwrite"].Value, true);
                }

                if (property.Attributes["projects"] != null && !string.IsNullOrEmpty(property.Attributes["projects"].Value))
                {
                    string[] projects = property.Attributes["projects"].Value.Split(
                        new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    bool propertyBelongsToProject = Array.Exists(projects, delegate(string project)
                    {
                        return((project == Project.ProjectName) || (project.ToLowerInvariant() == "all"));
                    });

                    if (propertyBelongsToProject)
                    {
                        PropertyTask task = new PropertyTask();
                        task.Project          = Project;
                        task.NamespaceManager = NamespaceManager;
                        task.PropertyName     = name;
                        task.Value            = value;
                        task.ReadOnly         = readOnly;
                        task.Dynamic          = dynamic;
                        task.Overwrite        = overwrite;
                        task.Execute();
                        counter += 1;
                    }
                }
                else
                {
                    PropertyTask task = new PropertyTask();
                    task.Project          = Project;
                    task.NamespaceManager = NamespaceManager;
                    task.PropertyName     = name;
                    task.Value            = value;
                    task.ReadOnly         = readOnly;
                    task.Dynamic          = dynamic;
                    task.Overwrite        = overwrite;
                    task.Execute();
                    counter += 1;
                }
            }
            Log(Level.Info, INFO_MSG, counter, _propertiesFile);
        }
コード例 #5
0
        private void CreateProperties(String name, XmlNodeList nodes)
        {
            foreach (XmlNode Child in nodes)
            {
                if (this.NeedToProcessChildren(Child.ChildNodes))
                {
                    String NewName = Child.LocalName;
                    if (!String.IsNullOrEmpty(name))
                    {
                        NewName = String.Format("{0}.{1}", name, Child.LocalName);
                    }

                    this.CreateProperties(NewName, Child.ChildNodes);
                }
                else if (!String.IsNullOrEmpty(Child.InnerText))
                {
                    String value = Child.InnerText.Trim();

                    AttributeList Attributes = new AttributeList(Child.Attributes);

                    Boolean NoTrim = this.GetAttributeValue("notrim", Attributes);

                    if (NoTrim)
                    {
                        value = Child.InnerText;
                    }

                    Boolean @readonly = this.GetAttributeValue("readonly", Attributes);
                    Boolean dynamic   = this.GetAttributeValue("dynamic", Attributes);
                    Boolean overwrite = this.GetAttributeValue("overwrite", Attributes);

                    String NewName = Child.LocalName;
                    if (!String.IsNullOrEmpty(name))
                    {
                        NewName = String.Format("{0}.{1}", name, Child.LocalName);
                    }

                    PropertyTask Property = new PropertyTask(NewName, value, @readonly, dynamic, overwrite);
                    Property.Parent  = this.Parent;
                    Property.Project = this.Project;
                    Property.Execute();
                }
                else if (Child.Attributes.Count > 0)
                {
                    AttributeList Attributes = new AttributeList(Child.Attributes);

                    if (Attributes.Contains("value"))
                    {
                        String value = Attributes["value"].InnerText;

                        Boolean @readonly = this.GetAttributeValue("readonly", Attributes);
                        Boolean dynamic   = this.GetAttributeValue("dynamic", Attributes);
                        Boolean overwrite = this.GetAttributeValue("overwrite", Attributes);

                        String NewName = Child.LocalName;
                        if (!String.IsNullOrEmpty(name))
                        {
                            NewName = String.Format("{0}.{1}", name, Child.LocalName);
                        }

                        PropertyTask Property = new PropertyTask(NewName, value, @readonly, dynamic, overwrite);
                        Property.Parent  = this.Parent;
                        Property.Project = this.Project;
                        Property.Execute();
                    }
                }
            }
        }