Merge pull request #303 from ermshiperete/5278
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / BuildProperty.cs
index ff75d989e34cb84a6d2b8110596e4f6254a3d3ec..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
@@ -32,6 +34,8 @@ 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 {
@@ -43,6 +47,7 @@ namespace Microsoft.Build.BuildEngine {
                string          name;
                Project         parentProject;
                PropertyType    propertyType;
+               bool            converting;
 
                BuildProperty ()
                {
@@ -76,7 +81,7 @@ namespace Microsoft.Build.BuildEngine {
                        this.propertyType = PropertyType.Normal;
                        this.parentProject = parentProject;
                        this.name = propertyElement.Name;
-                       this.value = Utilities.UnescapeFromXml (propertyElement.InnerXml);
+                       this.value = MSBuildUtils.UnescapeFromXml (propertyElement.InnerXml);
                        this.isImported = false;
                }
 
@@ -116,27 +121,65 @@ 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, 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);
                }
 
-               internal string ConvertToString (Project project)
+               // 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)
                {
-                       Expression exp = new Expression ();
-                       exp.Parse (Value, true, false);
+                       if (converting) {
+                               // found ref to @this while trying to ConvertToString
+                               // for @this!
+                               return FinalValue;
+                       }
 
-                       return (string) exp.ConvertTo (project, typeof (string));
+                       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)
+               internal ITaskItem[] ConvertToITaskItemArray (Project project, ExpressionOptions options)
                {
-                       Expression exp = new Expression ();
-                       exp.Parse (Value, true, false);
+                       if (converting) {
+                               // found ref to @this while trying to ConvertToITaskItemArray
+                               // for @this!
+                               ITaskItem []items = new ITaskItem [1];
+                               items [0] = new TaskItem (FinalValue);
+                               return items;
+                       }
 
-                       return (ITaskItem[]) exp.ConvertTo (project, typeof (ITaskItem[]));
+                       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 {