}
public BuildProperty (string propertyName, string propertyValue):
- this(propertyName, propertyValue, PropertyType.Global)
+ this (propertyName, propertyValue, PropertyType.Normal)
{
}
return (BuildProperty) this.MemberwiseClone ();
}
- // Evaluate the property.
- internal void Evaluate()
+ internal void Evaluate ()
{
if (FromXml) {
Expression exp = new Expression (parentProject, Value);
}
}
- public static implicit operator string (BuildProperty propertyToCast)
+ public static explicit operator string (BuildProperty propertyToCast)
{
if (propertyToCast == null)
throw new ArgumentNullException ("propertyToCast");
return value;
}
set {
+ this.@value = value;
if (FromXml) {
propertyElement.InnerText = value;
+ } else {
+ finalValue = value;
}
- this.@value = value;
}
}
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);
}
}
+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,
string binPath;
bool buildEnabled;
- BuildPropertyGroup environmentProperties;
EventSource eventSource;
bool buildStarted;
BuildPropertyGroup globalProperties;
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 ()
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]
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)
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;
#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 {
}
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
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)
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]
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
//XmlElement xmlElement;
public Project ()
- : this (null)
+ : this (Engine.GlobalEngine)
{
}
{
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]
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 ()
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) {
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)
if (xmlElement == null)
throw new ArgumentNullException ("xmlElement");
BuildItemGroup big = new BuildItemGroup (xmlElement, this);
- itemGroups.Add (big);
+ ItemGroups.Add (big);
big.Evaluate();
}
if (xmlElement == null)
throw new ArgumentNullException ("xmlElement");
BuildPropertyGroup bpg = new BuildPropertyGroup (xmlElement, this);
- propertyGroups.Add (bpg);
+ PropertyGroups.Add (bpg);
bpg.Evaluate();
}
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);
}
}
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);
- }
- }
}
}
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)
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);
}
}
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"); }
}
}
}
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)
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]
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