Merge pull request #303 from ermshiperete/5278
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / BuildProperty.cs
index 013a0d75691e2f2e119e1d13ec370bcdcb834de9..62caeda9edbf65629c676554e72c7d44be9087b0 100644 (file)
@@ -3,8 +3,10 @@
 //
 // Author:
 //   Marek Sieradzki (marek.sieradzki@gmail.com)
+//   Ankit Jain (jankit@novell.com)
 // 
 // (C) 2005 Marek Sieradzki
+// Copyright 2009 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -31,6 +33,10 @@ using System;
 using System.Text;
 using System.Xml;
 
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+using Mono.XBuild.Utilities;
+
 namespace Microsoft.Build.BuildEngine {
        public class BuildProperty {
        
@@ -41,6 +47,7 @@ namespace Microsoft.Build.BuildEngine {
                string          name;
                Project         parentProject;
                PropertyType    propertyType;
+               bool            converting;
 
                BuildProperty ()
                {
@@ -74,7 +81,7 @@ namespace Microsoft.Build.BuildEngine {
                        this.propertyType = PropertyType.Normal;
                        this.parentProject = parentProject;
                        this.name = propertyElement.Name;
-                       this.value = propertyElement.InnerText;
+                       this.value = MSBuildUtils.UnescapeFromXml (propertyElement.InnerXml);
                        this.isImported = false;
                }
 
@@ -114,13 +121,67 @@ namespace Microsoft.Build.BuildEngine {
                {
                        BuildProperty evaluated = new BuildProperty (Name, Value);
 
+                       // In evaluate phase, properties are not expanded
                        Expression exp = new Expression ();
-                       exp.Parse (Value, false);
-                       evaluated.finalValue = (string) exp.ConvertTo (parentProject, typeof (string));
+                       exp.Parse (Value, ParseOptions.None);
+                       evaluated.finalValue = (string) exp.ConvertTo (parentProject, typeof (string),
+                                       ExpressionOptions.DoNotExpandItemRefs);
 
                        parentProject.EvaluatedProperties.AddProperty (evaluated);
                }
 
+               // during property's eval phase, this is never reached, as PropertyReference
+               // handles the eval case
+               //
+               // during item's eval phase, we have expand: true, that's what we
+               // do here..
+               //
+               // during non-eval, expand: true
+               // So, its always true here
+               internal string ConvertToString (Project project, ExpressionOptions options)
+               {
+                       if (converting) {
+                               // found ref to @this while trying to ConvertToString
+                               // for @this!
+                               return FinalValue;
+                       }
+
+                       converting = true;
+                       try {
+                               Expression exp = new Expression ();
+
+                               // in non-evaluation phase, properties are always expanded
+                               exp.Parse (FinalValue, options == ExpressionOptions.ExpandItemRefs ?
+                                                       ParseOptions.AllowItems : ParseOptions.None);
+                               return (string) exp.ConvertTo (project, typeof (string), options);
+                       } finally {
+                               converting = false;
+                       }
+               }
+
+               internal ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options)
+               {
+                       if (converting) {
+                               // found ref to @this while trying to ConvertToITaskItemArray
+                               // for @this!
+                               ITaskItem []items = new ITaskItem [1];
+                               items [0] = new TaskItem (FinalValue);
+                               return items;
+                       }
+
+                       converting = true;
+                       try {
+                               Expression exp = new Expression ();
+
+                               // in non-evaluation phase, properties are always expanded
+                               exp.Parse (FinalValue, ParseOptions.Split | (options == ExpressionOptions.ExpandItemRefs ?
+                                                       ParseOptions.AllowItems : ParseOptions.None));
+                               return (ITaskItem[]) exp.ConvertTo (project, typeof (ITaskItem[]), options);
+                       } finally {
+                               converting = false;
+                       }
+               }
+
                internal bool FromXml {
                        get {
                                return propertyElement != null;
@@ -166,7 +227,7 @@ namespace Microsoft.Build.BuildEngine {
                        set {
                                this.@value = value;
                                if (FromXml) {
-                                       propertyElement.InnerText = value;
+                                       propertyElement.InnerXml = value;
                                } else {
                                        finalValue = value;
                                }