Implementation of the 2.0 session state model
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / Import.cs
index 3f41bd9c51a7aa66c7ef637ad84957b69f2447f3..62655eab01c641497e827d51a2e1bcf02e2611f4 100644 (file)
@@ -50,20 +50,41 @@ namespace Microsoft.Build.BuildEngine {
                        this.originalProject = originalProject;
 
                        if (ProjectPath == String.Empty)
-                               throw new InvalidProjectFileException ("Project attribute must be specified.");
+                               throw new InvalidProjectFileException ("The required attribute \"Project\" is missing from element <Import>.");
                }
 
                internal void Evaluate ()
                {
-                       string file;
-                       OldExpression exp;
+                       evaluatedProjectPath = EvaluateProjectPath (ProjectPath);
+                       string filename = GetFullPath ();
 
-                       exp = new OldExpression (project);
-                       exp.ParseSource (ProjectPath);
+                       if (EvaluatedProjectPath == String.Empty)
+                               throw new InvalidProjectFileException ("The required attribute \"Project\" is missing from element <Import>.");
                        
-                       file = evaluatedProjectPath = (string) exp.ConvertTo (typeof (string));
+                       if (!File.Exists (filename)) {
+                               throw new InvalidProjectFileException (String.Format ("Imported project: \"{0}\" does not exist.", filename));
+                       }
+                       
+                       ImportedProject importedProject = new ImportedProject ();
+                       importedProject.Load (filename);
 
-                       if (Path.IsPathRooted (EvaluatedProjectPath) == false) {
+                       project.ProcessElements (importedProject.XmlDocument.DocumentElement, importedProject);
+               }
+
+               string EvaluateProjectPath (string file)
+               {
+                       Expression exp;
+
+                       exp = new Expression ();
+                       exp.Parse (file);
+                       return (string) exp.ConvertTo (project, typeof (string));
+               }
+
+               string GetFullPath ()
+               {
+                       string file = EvaluatedProjectPath;
+
+                       if (!Path.IsPathRooted (EvaluatedProjectPath) && project.FullFileName != String.Empty) {
                                string dir;
                                if (originalProject == null)
                                        dir = Path.GetDirectoryName (project.FullFileName);
@@ -71,21 +92,15 @@ namespace Microsoft.Build.BuildEngine {
                                        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);
+                       return file;
                }
                
                public string Condition {
-                       get { return importElement.GetAttribute ("Condition"); }
+                       get {
+                               string s = importElement.GetAttribute ("Condition");
+                               return s == String.Empty ? null : s;
+                       }
                }
                
                public string EvaluatedProjectPath {