protected InstallerCreationCommand(MSIBase msi, NAnt.Core.Task task, Location location, XmlNode node) {
     this.msi = msi;
     this.task = task;
     this.location = location;
     this.node = node;
     guidCounter = msi.output.GetHashCode();
 }
示例#2
0
 public void Test_Constructor_FileNameLineColumn() {
     Location l = new Location(_tempFileName, 2, 5);
     Assert.IsNotNull(l);
     Assert.AreEqual(2, l.LineNumber);
     Assert.AreEqual(5, l.ColumnNumber);
     Assert.AreEqual(_tempFileName, l.FileName);
 }
示例#3
0
 public void Test_ToString()
 {
     Location location = new Location(_tempFileName, 2, 5);
     string expected = _tempFileName + "(2,5):";
     string actual = location.ToString();
     Assert.AreEqual(expected, actual);
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Element" /> class
 /// from the specified element.
 /// </summary>
 /// <param name="e">The element that should be used to create a new instance of the <see cref="Element" /> class.</param>
 protected Element(Element e)
     : this()
 {
     _location = e._location;
     _project = e._project;
     _xmlNode = e._xmlNode;
     _nsMgr = e._nsMgr;
 }
示例#5
0
 public void Test_Constructor_UriFileName() {
     Uri uri = new Uri("file://" + _tempFileName);
     Location l = new Location(uri.ToString(), 3, 6);
     Assert.IsNotNull(l);
     Assert.AreEqual(3, l.LineNumber);
     Assert.AreEqual(6, l.ColumnNumber);
     Assert.AreEqual(_tempFileName, l.FileName);
 }
示例#6
0
文件: Element.cs 项目: RoastBoy/nant
        /// <summary>
        /// Performs initialization using the given set of properties.
        /// </summary>
        internal void Initialize(XmlNode elementNode, PropertyDictionary properties, FrameworkInfo framework) {
            if (Project == null) {
                throw new InvalidOperationException("Element has invalid Project property.");
            }

            // save position in buildfile for reporting useful error messages.
            try {
                _location = Project.LocationMap.GetLocation(elementNode);
            } catch (ArgumentException ex) {
                logger.Warn("Location of Element node could be located.", ex);
            }

            InitializeXml(elementNode, properties, framework);
            
            // If the current instance implements IConditional, check to make sure
            // that IfDefined is true and UnlessDefined is false before initializing
            // the rest of this instance
            IConditional c = this as IConditional;
            if (c != null && !(c.IfDefined && !c.UnlessDefined))
            {
                return;
            }
            
            // allow inherited classes a chance to do some custom initialization
            InitializeElement(elementNode);
            Initialize();
        }
示例#7
0
        /// <summary>
        /// Evaluates the given expression string and returns the result
        /// </summary>
        /// <param name="input"></param>
        /// <param name="location"></param>
        /// <param name="state"></param>
        /// <param name="visiting"></param>
        /// <returns></returns>
        private string EvaluateEmbeddedExpressions(string input, Location location, Hashtable state, Stack visiting)
        {
            if (input == null) {
                return null;
            }

            if (input.IndexOf('$') < 0) {
                return input;
            }

            try {
                StringBuilder output = new StringBuilder(input.Length);

                ExpressionTokenizer tokenizer = new ExpressionTokenizer();
                ExpressionEvaluator eval = new ExpressionEvaluator(Project, this, state, visiting);

                tokenizer.IgnoreWhitespace = false;
                tokenizer.SingleCharacterMode = true;
                tokenizer.InitTokenizer(input);

                while (tokenizer.CurrentToken != ExpressionTokenizer.TokenType.EOF) {
                    if (tokenizer.CurrentToken == ExpressionTokenizer.TokenType.Dollar) {
                        tokenizer.GetNextToken();
                        if (tokenizer.CurrentToken == ExpressionTokenizer.TokenType.LeftCurlyBrace) {
                            tokenizer.IgnoreWhitespace = true;
                            tokenizer.SingleCharacterMode = false;
                            tokenizer.GetNextToken();

                            string val = Convert.ToString(eval.Evaluate(tokenizer), CultureInfo.InvariantCulture);
                            output.Append(val);
                            tokenizer.IgnoreWhitespace = false;

                            if (tokenizer.CurrentToken != ExpressionTokenizer.TokenType.RightCurlyBrace) {
                                throw new ExpressionParseException("'}' expected", tokenizer.CurrentPosition.CharIndex);
                            }
                            tokenizer.SingleCharacterMode = true;
                            tokenizer.GetNextToken();
                        } else {
                            output.Append('$');
                            if (tokenizer.CurrentToken != ExpressionTokenizer.TokenType.EOF) {
                                output.Append(tokenizer.TokenText);
                                tokenizer.GetNextToken();
                            }
                        }
                    } else {
                        output.Append(tokenizer.TokenText);
                        tokenizer.GetNextToken();
                    }
                }
                return output.ToString();
            } catch (ExpressionParseException ex) {
                StringBuilder errorMessage = new StringBuilder();
                string reformattedInput = input;

                // replace CR, LF and TAB with a space
                reformattedInput = reformattedInput.Replace('\n', ' ');
                reformattedInput = reformattedInput.Replace('\r', ' ');
                reformattedInput = reformattedInput.Replace('\t', ' ');

                errorMessage.Append(ex.Message);
                errorMessage.Append(Environment.NewLine);

                string label = "Expression: ";

                errorMessage.Append(label);
                errorMessage.Append(reformattedInput);

                int p0 = ex.StartPos;
                int p1 = ex.EndPos;

                if (p0 != -1 || p1 != -1) {
                    errorMessage.Append(Environment.NewLine);
                    if (p1 == -1)
                        p1 = p0 + 1;

                    for (int i = 0; i < p0 + label.Length; ++i)
                        errorMessage.Append(' ');
                    for (int i = p0; i < p1; ++i)
                        errorMessage.Append('^');
                }

                throw new BuildException(errorMessage.ToString(), location,
                    ex.InnerException);
            }
        }
示例#8
0
 private static void ValidatePropertyValue(object value, Location location)
 {
     if (value != null) {
         if (!(value is string)) {
             throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
                 ResourceUtils.GetString("NA1066"), value.GetType()),
                 "value");
         }
     } else {
         // TODO: verify this
         // throw new ArgumentException("Property value '" + propertyName + "' must not be null", "value");
         return;
     }
 }
 public FTPTaskException(string msg, Location loc)
     : base(msg, loc)
 {
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildException" /> class
 /// with a descriptive message and the location in the build file that 
 /// caused the exception.
 /// </summary>
 /// <param name="message">A descriptive message to include with the exception.</param>
 /// <param name="location">The location in the build file where the exception occured.</param>
 public BuildException(String message, Location location)
     : base(message)
 {
     _location = location;
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildException" /> class
 /// with a descriptive message, the location in the build file and an 
 /// instance of the exception that is the cause of the current exception.
 /// </summary>
 /// <param name="message">A descriptive message to include with the exception.</param>
 /// <param name="location">The location in the build file where the exception occured.</param>
 /// <param name="innerException">A nested exception that is the cause of the current exception.</param>
 public BuildException(String message, Location location, Exception innerException)
     : base(message, innerException)
 {
     _location = location;
 }
示例#12
0
文件: Project.cs 项目: skolima/NAnt
 /// <summary>
 /// Expands a <see cref="string" /> from known properties.
 /// </summary>
 /// <param name="input">The <see cref="string" /> with replacement tokens.</param>
 /// <param name="location">The location in the build file. Used to throw more accurate exceptions.</param>
 /// <returns>The expanded and replaced <see cref="string" />.</returns>
 public string ExpandProperties(string input, Location location)
 {
     return Properties.ExpandProperties(input, location);
 }
示例#13
0
 public MsmCreationCommand(msm msi, Task task, Location location, XmlNode node)
     : base(msi, task, location, node) {
 }
示例#14
0
        private static void ValidatePropertyValue(string name, object value, Location loc) 
        {
            CultureInfo ci = CultureInfo.InvariantCulture;

            try
            {
                if (value == null)
                {
                    throw new ArgumentException(String.Format(ci,
                        ResourceUtils.GetString("NA1194"), name));
                }

                if (!(value is string))
                {
                    throw new ArgumentException(String.Format(ci,
                        ResourceUtils.GetString("NA1066"), value.GetType()),
                        "value");
                }
            }
            catch (Exception x)
            {
                throw new BuildException("Property value validation failed: ", loc, x);
            }
        }
示例#15
0
 public FTPTaskException(string msg, Location loc, System.Exception InnerEx)
     : base(msg, loc, InnerEx)
 {
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationException" /> 
 /// class with a descriptive message, the location in the build file and 
 /// an instance of the exception that is the cause of the current 
 /// exception.
 /// </summary>
 /// <param name="message">A descriptive message to include with the exception.</param>
 /// <param name="location">The location in the build file where the exception occured.</param>
 /// <param name="innerException">A nested exception that is the cause of the current exception.</param>
 public ValidationException(String message, Location location, Exception innerException)
     : base(message, location, innerException)
 {
 }
示例#17
0
文件: Project.cs 项目: skolima/NAnt
        /// <summary>
        /// Creates a new <see cref="XmlDocument" /> based on the project 
        /// definition.
        /// </summary>
        /// <param name="uriOrFilePath">
        /// <para>The full path to the build file.</para>
        /// <para>This can be of any form that <see cref="M:XmlDocument.Load(string)" /> accepts.</para>
        /// </param>
        /// <returns>
        /// An <see cref="XmlDocument" /> based on the specified project 
        /// definition.
        /// </returns>
        private XmlDocument LoadBuildFile(string uriOrFilePath)
        {
            string path = uriOrFilePath;

            //if the source is not a valid uri, pass it thru.
            //if the source is a file uri, pass the localpath of it thru.
            try {
                Uri testURI = new Uri(uriOrFilePath);

                if (testURI.IsFile) {
                    path = testURI.LocalPath;
                }
            } catch (Exception ex) {
                logger.Debug("Error creating URI in project constructor. Moving on... ", ex);
            } finally {
                if (path == null) {
                    path = uriOrFilePath;
                }
            }

            XmlDocument doc = new XmlDocument();

            try {
                doc.Load(path);
            } catch (XmlException ex) {
                Location location = new Location(path, ex.LineNumber, ex.LinePosition);
                throw new BuildException("Error loading buildfile.", location, ex);
            } catch (Exception ex) {
                Location location = new Location(path);
                throw new BuildException("Error loading buildfile.", location, ex);
            }
            return doc;
        }
示例#18
0
 /// <summary>
 /// Expands a <see cref="string" /> from known properties.
 /// </summary>
 /// <param name="input">The replacement tokens.</param>
 /// <param name="location">The <see cref="Location" /> to pass through for any exceptions.</param>
 /// <returns>The expanded and replaced string.</returns>
 public string ExpandProperties(string input, Location location)
 {
     Hashtable state = new Hashtable();
     Stack visiting = new Stack();
     return ExpandProperties(input, location, state, visiting);
 }
示例#19
0
        /// <summary>
        /// Returns the <see cref="Location"/> in the XML file for the given node.
        /// </summary>
        /// <remarks>
        /// The <paramref name="node" /> must be from an <see cref="XmlDocument" /> 
        /// that has been added to the map.
        /// </remarks>
        public Location GetLocation(XmlNode node) {
            // check for non-backed documents
            if (String.IsNullOrEmpty(node.BaseURI))
                return Location.UnknownLocation; // return empty location because we have a fileless node.

            // convert URI to absolute URI
            Uri uri = new Uri(node.BaseURI);
            string fileName = uri.AbsoluteUri;

            if (!FileIsMapped(fileName)) {
                throw new ArgumentException("Xml node has not been mapped.");
            }

            // find xpath for node
            Hashtable map = (Hashtable) _fileMap[fileName];
            string xpath = GetXPathFromNode(node);
            if (!map.ContainsKey(xpath)) {
                throw new ArgumentException("Xml node has not been mapped.");
            }

            TextPosition pos = (TextPosition) map[xpath];
            Location location = new Location(fileName, pos.Line, pos.Column);
            return location;
        }
示例#20
0
 /// <summary>
 /// Expands a <see cref="string" /> from known properties.
 /// </summary>
 /// <param name="input">The replacement tokens.</param>
 /// <param name="location">The <see cref="Location" /> to pass through for any exceptions.</param>
 /// <param name="state">A mapping from properties to states. The states in question are "VISITING" and "VISITED". Must not be <see langword="null" />.</param>
 /// <param name="visiting">A stack of properties which are currently being visited. Must not be <see langword="null" />.</param>
 /// <returns>The expanded and replaced string.</returns>
 internal string ExpandProperties(string input, Location location, Hashtable state, Stack visiting)
 {
     return EvaluateEmbeddedExpressions(input, location, state, visiting);
 }
示例#21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildException" /> class 
 /// with serialized data.
 /// </summary>
 /// <param name="info">The <see cref="SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
 /// <param name="context">The <see cref="StreamingContext" /> that contains contextual information about the source or destination.</param>
 protected BuildException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     _location = info.GetValue("Location", _location.GetType()) as Location;
 }
示例#22
0
        private static void ValidatePropertyName(string propertyName, Location location)
        {
            const string propertyNamePattern = "^[_A-Za-z0-9][_A-Za-z0-9\\-.]*$";

            // validate property name
            //
            if (!Regex.IsMatch(propertyName, propertyNamePattern)) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    ResourceUtils.GetString("NA1064"), propertyName), location);
            }
            if (propertyName.EndsWith("-") || propertyName.EndsWith(".")) {
                // this additional rule helps simplify the regex pattern
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                    ResourceUtils.GetString("NA1064"), propertyName), location);
            }
        }
示例#23
0
        /// <summary>
        /// Performs initialization using the given set of properties.
        /// </summary>
        internal void Initialize(XmlNode elementNode, PropertyDictionary properties, FrameworkInfo framework)
        {
            if (Project == null) {
                throw new InvalidOperationException("Element has invalid Project property.");
            }

            // save position in buildfile for reporting useful error messages.
            try {
                _location = Project.LocationMap.GetLocation(elementNode);
            } catch (ArgumentException ex) {
                logger.Warn("Location of Element node could be located.", ex);
            }

            InitializeXml(elementNode, properties, framework);

            // allow inherited classes a chance to do some custom initialization
            InitializeElement(elementNode);
            Initialize();
        }
示例#24
0
        /// <summary>
        /// Creates a new <see cref="XmlDocument" /> based on the project 
        /// definition.
        /// </summary>
        /// <param name="source">The source of the document.<para>Any form that is valid for <see cref="XmlDocument.Load(string)" /> can be used here.</para></param>
        /// <returns>
        /// An <see cref="XmlDocument" /> based on the specified project 
        /// definition.
        /// </returns>
        private XmlDocument LoadBuildFile(string source)
        {
            XmlDocument doc = new XmlDocument();

            try {
                doc.Load(source);
            } catch (XmlException ex) {
                Location location = new Location(source, ex.LineNumber, ex.LinePosition);

                throw new BuildException("Error loading buildfile.", location, ex);
            } catch (Exception ex) {
                Location location = new Location(source);

                throw new BuildException("Error loading buildfile.", location, ex);
            }
            return doc;
        }