2006-03-27 Crestez Leonard <cdleonard@gmail.com>
authorMarek Sieradzki <msierad@mono-cvs.ximian.com>
Tue, 28 Mar 2006 17:37:16 +0000 (17:37 -0000)
committerMarek Sieradzki <msierad@mono-cvs.ximian.com>
Tue, 28 Mar 2006 17:37:16 +0000 (17:37 -0000)
        * ImportCollection.cs, UsingTaskCollection.cs: Cleaned up, switched
        to lists instead of hashtables.
        * Import.cs: Cleaned up, moved importing from Project.cs
        * BuildProperty.cs, BuildPropertyGroup.cs: Minor fixes.
        * Engine.cs: Cleaned up properties.
        * Project.cs: Moved importing to Import.cs, cleaned up properties,
        Separated evaluation and loading.

svn path=/trunk/mcs/; revision=58663

mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildProperty.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildPropertyGroup.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ImportCollection.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UsingTask.cs
mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/UsingTaskCollection.cs

index 50e0877bdf2eb4a364eff640d5ce5fbe007fb58d..6d7a4b682624d1ab8d8a993fe8322038cbd1f342 100644 (file)
@@ -53,7 +53,7 @@ namespace Microsoft.Build.BuildEngine {
                }
 
                public BuildProperty (string propertyName, string propertyValue):
-                       this(propertyName, propertyValue, PropertyType.Global)
+                       this (propertyName, propertyValue, PropertyType.Normal)
                {
                }
 
@@ -86,8 +86,7 @@ namespace Microsoft.Build.BuildEngine {
                        return (BuildProperty) this.MemberwiseClone ();
                }
 
-               // Evaluate the property.
-               internal void Evaluate()
+               internal void Evaluate ()
                {
                        if (FromXml) {
                                Expression exp = new Expression (parentProject, Value);
@@ -96,7 +95,7 @@ namespace Microsoft.Build.BuildEngine {
                        }
                }
 
-               public static implicit operator string (BuildProperty propertyToCast)
+               public static explicit operator string (BuildProperty propertyToCast)
                {
                        if (propertyToCast == null)
                                throw new ArgumentNullException ("propertyToCast");
@@ -138,10 +137,12 @@ namespace Microsoft.Build.BuildEngine {
                                return value;
                        }
                        set {
+                               this.@value = value;
                                if (FromXml) {
                                        propertyElement.InnerText = value;
+                               } else {
+                                       finalValue = value;
                                }
-                               this.@value = value;
                        }
                }
 
index 43d92822f2261ad984926749df4ee4373745f1c5..3214ffc986a9978ef3d792aade61eb2407179c2c 100644 (file)
@@ -185,9 +185,13 @@ namespace Microsoft.Build.BuildEngine {
                
                public string Condition {
                        get {
+                               if (!FromXml)
+                                       return String.Empty;
                                return propertyGroup.GetAttribute ("Condition");
                        }
                        set {
+                               if (!FromXml)
+                                       throw new InvalidOperationException ("Can only set condition on xml elements.");
                                propertyGroup.SetAttribute ("Condition", value);
                        }
                }
index dd27c4dadac2f5fc3840d408406515019f9ff46e..38a1996f991a92f254554452596079ff6e9f261b 100644 (file)
@@ -1,3 +1,13 @@
+2006-03-27  Crestez Leonard  <cdleonard@gmail.com>
+
+       * ImportCollection.cs, UsingTaskCollection.cs: Cleaned up, switched
+       to lists instead of hashtables.
+       * Import.cs: Cleaned up, moved importing from Project.cs
+       * BuildProperty.cs, BuildPropertyGroup.cs: Minor fixes.
+       * Engine.cs: Cleaned up properties.
+       * Project.cs: Moved importing to Import.cs, cleaned up properties,
+       Separated evaluation and loading.
+       
 2006-03-21  Crestez Leonard  <cdleonard@gmail.com>
 
        * Target.cs, TaskEngine.cs, BuildItemGroup.cs, BuildItem.cs,
index 4d1d42126535a8aee7e91a9ad03701c2dd615bb6..d3aadcc5c43de3bb761b34f5f9b367b07e5be9c4 100644 (file)
@@ -36,7 +36,6 @@ namespace Microsoft.Build.BuildEngine {
                
                string                  binPath;
                bool                    buildEnabled;
-               BuildPropertyGroup      environmentProperties;
                EventSource             eventSource;
                bool                    buildStarted;
                BuildPropertyGroup      globalProperties;
@@ -44,15 +43,14 @@ namespace Microsoft.Build.BuildEngine {
                IList                   loggers;
                bool                    onlyLogCriticalEvents;
                IDictionary             projects;
-               BuildPropertyGroup      reservedProperties;
 
-               // FIXME: GlobalEngine static property uses this but what about GlobalEngineAccessor?
+               // FIXME
                static Engine           globalEngine;
                static Version          version;
 
                static Engine ()
                {
-                       version = new Version("0.1");
+                       version = new Version ("0.1");
                }
                
                public Engine ()
@@ -69,9 +67,7 @@ namespace Microsoft.Build.BuildEngine {
                        this.eventSource = new EventSource ();
                        this.loggers = new ArrayList ();
                        this.buildStarted = false;
-                       this.LoadEnvironmentProperties ();
-                       this.reservedProperties = new BuildPropertyGroup ();
-                       this.reservedProperties.AddProperty (new BuildProperty ("MSBuildBinPath", binPath, PropertyType.Reserved));
+                       this.globalProperties = new BuildPropertyGroup ();
                }
                
                [MonoTODO]
@@ -179,20 +175,7 @@ namespace Microsoft.Build.BuildEngine {
 
                public Project CreateNewProject ()
                {
-                       if (buildStarted == false) {
-                               LogBuildStarted ();
-                               buildStarted = true;
-                       }
-                       Project p = new Project (this);
-                       p.EnvironmentProperties = this.environmentProperties;
-                       p.ReservedProperties = this.reservedProperties;
-                       if (globalProperties != null) {
-                               BuildPropertyGroup bpg = new BuildPropertyGroup ();
-                               foreach (BuildProperty bp in globalProperties)
-                                       bpg.AddProperty (bp.Clone (false));
-                               p.GlobalProperties = bpg;
-                       }
-                       return p;
+                       return new Project (this);
                }
 
                public Project GetLoadedProject (string projectFullFileName)
@@ -228,17 +211,6 @@ namespace Microsoft.Build.BuildEngine {
                        loggers.Clear ();
                }
                
-               private void LoadEnvironmentProperties ()
-               {
-                       environmentProperties = new BuildPropertyGroup ();
-                       IDictionary environment = Environment.GetEnvironmentVariables ();
-                       foreach (DictionaryEntry de in environment) {
-                               BuildProperty bp;
-                               bp = new BuildProperty ((string) de.Key, (string) de.Value, PropertyType.Environment);
-                               environmentProperties.AddProperty (bp);
-                       }
-               }
-               
                private void LogProjectStarted (Project project, string[] targetNames)
                {
                        ProjectStartedEventArgs psea;
index c2faa67dcba1b02c29a057bc6e44d49368a0a37a..42a18441c6cf5a5d187aa2b508e9f73fc9616ad4 100644 (file)
 #if NET_2_0
 
 using System;
+using System.IO;
 using System.Xml;
 
 namespace Microsoft.Build.BuildEngine {
        public class Import {
-       
-               XmlAttribute    condition;
-               string          evaluatedProjectPath;
                XmlElement      importElement;
-               bool            isImported;
-               XmlAttribute    projectPath;
-               
+               Project         project;
+               ImportedProject originalProject;
+               string          evaluatedProjectPath;
        
-               internal Import (XmlElement importElement, bool isImported)
+               internal Import (XmlElement importElement, Project project, ImportedProject originalProject)
                {
                        if (importElement == null)
                                throw new ArgumentNullException ("importElement");
+                       if (project == null)
+                               throw new ArgumentNullException ("project");
                
+                       this.project = project;
                        this.importElement = importElement;
-                       this.isImported = isImported;
-                       this.condition = importElement.GetAttributeNode ("Condition");
-                       this.projectPath = importElement.GetAttributeNode ("ProjectPath");
-                       // FIXME: evaluate this
-                       this.evaluatedProjectPath = projectPath.Value;
+                       this.originalProject = originalProject;
+
+                       if (ProjectPath == String.Empty)
+                               throw new InvalidProjectFileException ("Project attribute must be specified.");
+               }
+
+               internal void Evaluate ()
+               {
+                       string file;
+                       Expression exp;
+
+                       exp = new Expression (project, ProjectPath);
+                       file = evaluatedProjectPath = (string) exp.ToNonArray (typeof (string));
+
+                       if (Path.IsPathRooted (EvaluatedProjectPath) == false) {
+                               string dir;
+                               if (originalProject == null)
+                                       dir = Path.GetDirectoryName (project.FullFileName);
+                               else
+                                       dir = Path.GetDirectoryName (originalProject.FullFileName);
+                               file = Path.Combine (dir, EvaluatedProjectPath);
+                       }
+
+                       // FIXME: loggers anybody?
+                       if (!File.Exists (file)) {
+                               Console.WriteLine ("Imported file {0} doesn't exist.", file);
+                               return;
+                       }
+                       
+                       ImportedProject importedProject = new ImportedProject ();
+                       importedProject.Load (file);
+                       // FIXME: UGLY HACK
+                       project.ProcessElements (importedProject.XmlDocument.DocumentElement, importedProject);
                }
                
                public string Condition {
-                       get { return condition.Value; }
+                       get { return importElement.GetAttribute ("Condition"); }
                }
                
                public string EvaluatedProjectPath {
@@ -62,13 +91,13 @@ namespace Microsoft.Build.BuildEngine {
                }
                
                public bool IsImported {
-                       get { return isImported; }
+                       get { return originalProject != null; }
                }
                
                public string ProjectPath {
-                       get { return evaluatedProjectPath; }
+                       get { return importElement.GetAttribute ("Project"); }
                }
        }
 }
 
-#endif
\ No newline at end of file
+#endif
index 762ad875c44157c0bd93ae487696d293b6e2eae3..ff0e6b48cfff76b2af4c22d0d84f3640cc6e859a 100644 (file)
@@ -35,13 +35,13 @@ using System.Xml;
 namespace Microsoft.Build.BuildEngine {
        public class ImportCollection : ICollection, IEnumerable {
                
-               IDictionary     imports;
+               IList           imports;
                Project         parentProject;
                
                internal ImportCollection (Project parentProject)
                {
                        this.parentProject = parentProject;
-                       this.imports = new Hashtable ();
+                       this.imports = new ArrayList ();
                }
                
                internal void Add (Import import)
@@ -49,10 +49,10 @@ namespace Microsoft.Build.BuildEngine {
                        if (import == null)
                                throw new ArgumentNullException ("import");
                        
-                       if (imports.Contains (import.EvaluatedProjectPath))
+                       if (imports.Contains (import))
                                throw new InvalidOperationException ("Import already added.");
                        
-                       imports.Add (import.EvaluatedProjectPath, import);
+                       imports.Add (import);
                }
                
                [MonoTODO]
@@ -79,14 +79,10 @@ namespace Microsoft.Build.BuildEngine {
                        get { return false; }
                }
                
-               internal Import this [string index] {
-                       get { return (Import) imports [index]; }
-               }
-               
                public object SyncRoot {
                        get { return this; }
                }
        }
 }
 
-#endif
\ No newline at end of file
+#endif
index 35be709e3e2b4361c87e42dc2768f738c95941f0..bc0ebdbb1d40de48239a4b3a30fe3432e87bfd98 100644 (file)
@@ -75,7 +75,7 @@ namespace Microsoft.Build.BuildEngine {
                //XmlElement                    xmlElement;
 
                public Project ()
-                       : this (null)
+                       : this (Engine.GlobalEngine)
                {
                }
 
@@ -83,16 +83,21 @@ namespace Microsoft.Build.BuildEngine {
                {
                        parentEngine  = engine;
                        xmlDocument = new XmlDocument ();
-                       evaluatedItems = new BuildItemGroup (null, this);
-                       evaluatedItemsIgnoringCondition = new BuildItemGroup (null, this);
-                       evaluatedItemsByName = CollectionsUtil.CreateCaseInsensitiveHashtable ();
-                       evaluatedItemsByNameIgnoringCondition = CollectionsUtil.CreateCaseInsensitiveHashtable ();
-                       evaluatedProperties = new BuildPropertyGroup ();
                        groups = new GroupingCollection ();
+                       imports = new ImportCollection (this);
+                       usingTasks = new UsingTaskCollection (this);
                        itemGroups = new BuildItemGroupCollection (groups);
                        propertyGroups = new BuildPropertyGroupCollection (groups);
                        targets = new TargetCollection (this);
                        taskDatabase = new TaskDatabase ();
+                       globalProperties = new BuildPropertyGroup ();
+
+                       foreach (BuildProperty bp in parentEngine.GlobalProperties) {
+                               GlobalProperties.AddProperty (bp.Clone (true));
+                       }
+
+                       // You can evaluate an empty project.
+                       Evaluate ();
                }
 
                [MonoTODO]
@@ -275,6 +280,45 @@ namespace Microsoft.Build.BuildEngine {
                        ProcessElements (xmlElement, null);
                        
                        isDirty = false;
+                       Evaluate();
+               }
+
+               private void InitializeProperties ()
+               {
+                       BuildProperty bp;
+
+                       foreach (BuildProperty gp in GlobalProperties) {
+                               bp = new BuildProperty (gp.Name, gp.Value, PropertyType.Global);
+                               EvaluatedProperties.AddProperty (bp);
+                       }
+                       
+                       foreach (DictionaryEntry de in Environment.GetEnvironmentVariables ()) {
+                               bp = new BuildProperty ((string) de.Key, (string) de.Value, PropertyType.Environment);
+                               EvaluatedProperties.AddProperty (bp);
+                       }
+
+                       bp = new BuildProperty ("MSBuildBinPath", parentEngine.BinPath, PropertyType.Reserved);
+                       EvaluatedProperties.AddProperty (bp);
+               }
+
+               internal void Evaluate ()
+               {
+                       evaluatedItems = new BuildItemGroup (null, this);
+                       evaluatedItemsIgnoringCondition = new BuildItemGroup (null, this);
+                       evaluatedItemsByName = CollectionsUtil.CreateCaseInsensitiveHashtable ();
+                       evaluatedItemsByNameIgnoringCondition = CollectionsUtil.CreateCaseInsensitiveHashtable ();
+                       evaluatedProperties = new BuildPropertyGroup ();
+
+                       InitializeProperties ();
+
+                       foreach (BuildPropertyGroup bpg in PropertyGroups)
+                               bpg.Evaluate ();
+                       foreach (Import import in Imports)
+                               import.Evaluate ();
+                       foreach (BuildItemGroup big in ItemGroups)
+                               big.Evaluate ();
+                       foreach (UsingTask usingTask in UsingTasks)
+                               usingTask.Evaluate ();
                }
 
                public void MarkProjectAsDirty ()
@@ -428,7 +472,7 @@ namespace Microsoft.Build.BuildEngine {
                        throw new NotImplementedException ();
                }
 
-               private void ProcessElements (XmlElement rootElement, ImportedProject ip)
+               internal void ProcessElements (XmlElement rootElement, ImportedProject ip)
                {
                        foreach (XmlNode xn in rootElement.ChildNodes) {
                                if (xn is XmlElement) {
@@ -496,40 +540,17 @@ namespace Microsoft.Build.BuildEngine {
                private void AddUsingTask (XmlElement xmlElement, ImportedProject importedProject)
                {
                        UsingTask usingTask;
-                       
+
                        usingTask = new UsingTask (xmlElement, this, importedProject);
-                       usingTask.Evaluate ();
+                       UsingTasks.Add (usingTask);
                }
                
                private void AddImport (XmlElement xmlElement, ImportedProject importingProject)
                {
-                       if (xmlElement == null)
-                               throw new ArgumentNullException ("xmlElement");
-                       
-                       string importedFile;
-                       Expression importedFileExpr;
-
-                       importedFileExpr = new Expression (this, xmlElement.GetAttribute ("Project"));
-                       importedFile = (string) importedFileExpr.ToNonArray (typeof (string));
-                       
-                       if (importedFile == String.Empty)
-                               throw new InvalidProjectFileException ("Project attribute must be specified.");
-                       
-                       if (Path.IsPathRooted (importedFile) == false) {
-                               if (importingProject == null)
-                                       importedFile = Path.Combine (Path.GetDirectoryName (fullFileName), importedFile);
-                               else
-                                       importedFile = Path.Combine (Path.GetDirectoryName (importingProject.FullFileName), importedFile);
-                       }
+                       Import import;
                        
-                       ImportedProject importedProject = new ImportedProject ();
-                       try {
-                               importedProject.Load (importedFile);
-                               ProcessElements (importedProject.XmlDocument.DocumentElement, importedProject);
-                       }
-                       catch (Exception ex) {
-                               Console.WriteLine (ex);
-                       }
+                       import = new Import (xmlElement, this, importingProject);
+                       Imports.Add (import);
                }
                
                private void AddItemGroup (XmlElement xmlElement)
@@ -537,7 +558,7 @@ namespace Microsoft.Build.BuildEngine {
                        if (xmlElement == null)
                                throw new ArgumentNullException ("xmlElement");
                        BuildItemGroup big = new BuildItemGroup (xmlElement, this);
-                       itemGroups.Add (big);
+                       ItemGroups.Add (big);
                        big.Evaluate();
                }
                
@@ -546,7 +567,7 @@ namespace Microsoft.Build.BuildEngine {
                        if (xmlElement == null)
                                throw new ArgumentNullException ("xmlElement");
                        BuildPropertyGroup bpg = new BuildPropertyGroup (xmlElement, this);
-                       propertyGroups.Add (bpg);
+                       PropertyGroups.Add (bpg);
                        bpg.Evaluate();
                }
                
@@ -612,9 +633,13 @@ namespace Microsoft.Build.BuildEngine {
                public BuildPropertyGroup GlobalProperties {
                        get { return globalProperties; }
                        set {
+                               if (value == null) {
+                                       throw new ArgumentNullException ("value");
+                               }
+                               if (value.FromXml) {
+                                       throw new InvalidOperationException ("Can't do that.");
+                               }
                                globalProperties = value;
-                               foreach (BuildProperty bp in globalProperties)
-                                       evaluatedProperties.AddProperty (bp);
                        }
                }
 
@@ -673,22 +698,6 @@ namespace Microsoft.Build.BuildEngine {
                internal TaskDatabase TaskDatabase {
                        get { return taskDatabase; }
                }
-               
-               internal BuildPropertyGroup EnvironmentProperties {
-                       set {
-                               environmentProperties = value;
-                               foreach (BuildProperty bp in environmentProperties)
-                                       evaluatedProperties.AddProperty (bp);
-                       }
-               }
-               
-               internal BuildPropertyGroup ReservedProperties {
-                       set {
-                               reservedProperties = value;
-                               foreach (BuildProperty bp in reservedProperties)
-                                       evaluatedProperties.AddProperty (bp);
-                       }
-               }
        }
 }
 
index 41857d7f3326ce5556fe76274cdabe49b0cd85b5..ada963e0b0769a2386bbd297a6e76b5ba60ec046 100644 (file)
@@ -49,9 +49,9 @@ namespace Microsoft.Build.BuildEngine {
                        this.usingTaskElement = usingTaskElement;
                        
                        if (project == null)
-                               throw new ArgumentNullException("project");
+                               throw new ArgumentNullException ("project");
                        if (usingTaskElement == null)
-                               throw new ArgumentNullException("usingTaskElement");
+                               throw new ArgumentNullException ("usingTaskElement");
                        if (AssemblyName == String.Empty && AssemblyFile == String.Empty)
                                throw new InvalidProjectFileException ("AssemblyName or AssemblyFile attribute must be specified.");
                        if (TaskName == String.Empty)
@@ -69,9 +69,9 @@ namespace Microsoft.Build.BuildEngine {
                                if (Path.IsPathRooted (filename) == false) {
                                        string ffn;
                                        if (importedProject != null) {
-                                               ffn = Path.GetDirectoryName(importedProject.FullFileName);
+                                               ffn = Path.GetDirectoryName (importedProject.FullFileName);
                                        } else {
-                                               ffn = Path.GetDirectoryName(project.FullFileName);
+                                               ffn = Path.GetDirectoryName (project.FullFileName);
                                        }
                                        filename = Path.Combine (ffn, filename);
                                }
@@ -87,19 +87,19 @@ namespace Microsoft.Build.BuildEngine {
                }
                
                public string AssemblyFile {
-                       get { return usingTaskElement.GetAttribute("AssemblyFile"); }
+                       get { return usingTaskElement.GetAttribute ("AssemblyFile"); }
                }
                
                public string AssemblyName {
-                       get { return usingTaskElement.GetAttribute("AssemblyName"); }
+                       get { return usingTaskElement.GetAttribute ("AssemblyName"); }
                }
                
                public string Condition {
-                       get { return usingTaskElement.GetAttribute("Condition"); }
+                       get { return usingTaskElement.GetAttribute ("Condition"); }
                }
                
                public string TaskName {
-                       get { return usingTaskElement.GetAttribute("TaskName"); }
+                       get { return usingTaskElement.GetAttribute ("TaskName"); }
                }
        }
 }
index dfb5c223fd18a0894f14cf0cd6397ee86cf785df..e5ae83f1663fda65b853480b467430ccc94dd86d 100644 (file)
@@ -35,11 +35,12 @@ namespace Microsoft.Build.BuildEngine {
        public class UsingTaskCollection : ICollection, IEnumerable {
        
                Project         parentProject;
-               IDictionary     usingTasks;
+               IList           usingTasks;
                
                internal UsingTaskCollection (Project parentProject)
                {
                        this.parentProject = parentProject;
+                       usingTasks = new ArrayList ();
                }
                
                internal void Add (UsingTask usingTask)
@@ -47,10 +48,10 @@ namespace Microsoft.Build.BuildEngine {
                        if (usingTask == null)
                                throw new ArgumentNullException ("usingTask");
                        
-                       if (usingTasks.Contains (usingTask.TaskName))
+                       if (usingTasks.Contains (usingTask))
                                throw new InvalidOperationException ("Task already registered.");
                        
-                       usingTasks.Add (usingTask.TaskName, usingTask);
+                       usingTasks.Add (usingTask);
                }
                
                [MonoTODO]
@@ -77,14 +78,10 @@ namespace Microsoft.Build.BuildEngine {
                        get { return false; }
                }
                
-               internal UsingTask this [int index] {
-                       get { return (UsingTask) usingTasks [index]; }
-               }
-               
                public object SyncRoot {
                        get { return this; }
                }
        }
 }
 
-#endif
\ No newline at end of file
+#endif