From 45cd5a80da70f6c52f19e7c49663ffb0c7cbe856 Mon Sep 17 00:00:00 2001 From: ankit Date: Fri, 19 Feb 2010 11:50:28 +0000 Subject: [PATCH] In class/Microsoft.Build.Engine: * Microsoft.Build.Engine.dll.sources: Add ProjectLoadSettings.cs . In class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine: * Import.cs (Evaluate): Add param @ignoreMissingImports. * Project.cs (Load*): Add overloads with param @projectLoadSettings. (Log*): Mark internal. * ProjectLoadSettings.cs: New. In class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine: * ImportTest.cs (TestMissingImport*): Add new tests for missing import projects. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mcs@152066 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- class/Microsoft.Build.Engine/ChangeLog | 4 ++ .../Microsoft.Build.BuildEngine/ChangeLog | 7 ++++ .../Microsoft.Build.BuildEngine/Import.cs | 9 +++- .../Microsoft.Build.BuildEngine/Project.cs | 27 ++++++++++-- .../ProjectLoadSettings.cs | 38 +++++++++++++++++ .../Microsoft.Build.Engine.dll.sources | 1 + .../Test/Microsoft.Build.BuildEngine/ChangeLog | 5 +++ .../Test/Microsoft.Build.BuildEngine/ImportTest.cs | 49 ++++++++++++++++++++++ 8 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ProjectLoadSettings.cs diff --git a/class/Microsoft.Build.Engine/ChangeLog b/class/Microsoft.Build.Engine/ChangeLog index 2390f6e8d8..0052a5560c 100644 --- a/class/Microsoft.Build.Engine/ChangeLog +++ b/class/Microsoft.Build.Engine/ChangeLog @@ -1,3 +1,7 @@ +2010-02-19 Ankit Jain + + * Microsoft.Build.Engine.dll.sources: Add ProjectLoadSettings.cs . + 2010-01-21 Rodrigo B. de Oliveira * Microsoft.Build.BuildEngine/BuildWhen.cs diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog index ebb6e71809..f588ba8ca3 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog @@ -1,3 +1,10 @@ +2010-02-19 Ankit Jain + + * Import.cs (Evaluate): Add param @ignoreMissingImports. + * Project.cs (Load*): Add overloads with param @projectLoadSettings. + (Log*): Mark internal. + * ProjectLoadSettings.cs: New. + 2010-02-04 Ankit Jain Fix bug #576589. diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs index 8af0798a6e..c35aa810ed 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Import.cs @@ -58,7 +58,7 @@ namespace Microsoft.Build.BuildEngine { } // FIXME: condition - internal void Evaluate () + internal void Evaluate (bool ignoreMissingImports) { string filename = evaluatedProjectPath; // NOTE: it's a hack to transform Microsoft.CSharp.Targets to Microsoft.CSharp.targets @@ -66,7 +66,12 @@ namespace Microsoft.Build.BuildEngine { filename = Path.ChangeExtension (filename, Path.GetExtension (filename)); if (!File.Exists (filename)) { - throw new InvalidProjectFileException (String.Format ("Imported project: \"{0}\" does not exist.", filename)); + if (ignoreMissingImports) { + project.LogWarning (project.FullFileName, "Could not find project file {0}, to import. Ignoring.", filename); + return; + } else { + throw new InvalidProjectFileException (String.Format ("Imported project: \"{0}\" does not exist.", filename)); + } } ImportedProject importedProject = new ImportedProject (); diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs index 7d9ed55622..b5b0b1aa81 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs @@ -77,6 +77,7 @@ namespace Microsoft.Build.BuildEngine { bool building; BuildSettings current_settings; Stack batches; + ProjectLoadSettings project_load_settings; static string extensions_path; @@ -101,6 +102,8 @@ namespace Microsoft.Build.BuildEngine { fullFileName = String.Empty; timeOfLastDirty = DateTime.Now; current_settings = BuildSettings.None; + project_load_settings = ProjectLoadSettings.None; + encoding = null; builtTargetKeys = new List (); @@ -422,6 +425,12 @@ namespace Microsoft.Build.BuildEngine { public void Load (string projectFileName) { + Load (projectFileName, ProjectLoadSettings.None); + } + + public void Load (string projectFileName, ProjectLoadSettings settings) + { + project_load_settings = settings; if (String.IsNullOrEmpty (projectFileName)) throw new ArgumentNullException ("projectFileName"); @@ -455,12 +464,24 @@ namespace Microsoft.Build.BuildEngine { [MonoTODO ("Not tested")] public void Load (TextReader textReader) { + Load (textReader, ProjectLoadSettings.None); + } + + public void Load (TextReader textReader, ProjectLoadSettings projectLoadSettings) + { + project_load_settings = projectLoadSettings; fullFileName = String.Empty; DoLoad (textReader); } public void LoadXml (string projectXml) { + LoadXml (projectXml, ProjectLoadSettings.None); + } + + public void LoadXml (string projectXml, ProjectLoadSettings projectLoadSettings) + { + project_load_settings = projectLoadSettings; fullFileName = String.Empty; DoLoad (new StringReader (projectXml)); MarkProjectAsDirty (); @@ -974,7 +995,7 @@ namespace Microsoft.Build.BuildEngine { } Imports.Add (import); - import.Evaluate (); + import.Evaluate (project_load_settings == ProjectLoadSettings.IgnoreMissingImports); } void AddItemGroup (XmlElement xmlElement, ImportedProject importedProject) @@ -1172,7 +1193,7 @@ namespace Microsoft.Build.BuildEngine { return default (T); } - void LogWarning (string filename, string message, params object[] messageArgs) + internal void LogWarning (string filename, string message, params object[] messageArgs) { BuildWarningEventArgs bwea = new BuildWarningEventArgs ( null, null, filename, 0, 0, 0, 0, String.Format (message, messageArgs), @@ -1180,7 +1201,7 @@ namespace Microsoft.Build.BuildEngine { ParentEngine.EventSource.FireWarningRaised (this, bwea); } - void LogError (string filename, string message, + internal void LogError (string filename, string message, params object[] messageArgs) { BuildErrorEventArgs beea = new BuildErrorEventArgs ( diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ProjectLoadSettings.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ProjectLoadSettings.cs new file mode 100644 index 0000000000..9b89307590 --- /dev/null +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ProjectLoadSettings.cs @@ -0,0 +1,38 @@ +// +// ProjectLoadSettings.cs +// +// Author: +// Ankit Jain (jankit@novell.com) +// +// Copyright 2010 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 +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#if NET_2_0 + +namespace Microsoft.Build.BuildEngine { + + public enum ProjectLoadSettings { + None, + IgnoreMissingImports + } +} + +#endif diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources b/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources index 33c88db1e9..8f429b31a7 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources +++ b/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources @@ -48,6 +48,7 @@ Microsoft.Build.BuildEngine/IReference.cs Microsoft.Build.BuildEngine/ItemReference.cs Microsoft.Build.BuildEngine/MetadataReference.cs Microsoft.Build.BuildEngine/Project.cs +Microsoft.Build.BuildEngine/ProjectLoadSettings.cs Microsoft.Build.BuildEngine/PropertyPosition.cs Microsoft.Build.BuildEngine/PropertyReference.cs Microsoft.Build.BuildEngine/TargetCollection.cs diff --git a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog index 5456954f42..7a11426c77 100644 --- a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog +++ b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog @@ -1,3 +1,8 @@ +2010-02-19 Ankit Jain + + * ImportTest.cs (TestMissingImport*): Add new tests for missing + import projects. + 2010-02-11 Ankit Jain * ImportTest.cs (Add1): Fix test on windows. diff --git a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ImportTest.cs b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ImportTest.cs index 8e1af153ca..c353b04009 100644 --- a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ImportTest.cs +++ b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ImportTest.cs @@ -160,5 +160,54 @@ namespace MonoTests.Microsoft.Build.BuildEngine { Assert.IsTrue (groups [0].IsImported, "A1"); Assert.AreEqual (1, groups [0].Count, "A2"); } + + [Test] + [ExpectedException (typeof (InvalidProjectFileException))] + public void TestMissingImport1 () + { + string documentString = @" + + + "; + + engine = new Engine (Consts.BinPath); + + project = engine.CreateNewProject (); + project.LoadXml (documentString, ProjectLoadSettings.None); + } + + [Test] + public void TestMissingImport2 () + { + string documentString = @" + + + + "; + + engine = new Engine (Consts.BinPath); + + project = engine.CreateNewProject (); + project.LoadXml (documentString, ProjectLoadSettings.IgnoreMissingImports); + + Assert.AreEqual (1, project.Imports.Count, "A1"); + } + + [Test] + [ExpectedException (typeof (InvalidProjectFileException))] + public void TestMissingImportDefault () + { + string documentString = @" + + + + "; + + engine = new Engine (Consts.BinPath); + + project = engine.CreateNewProject (); + project.LoadXml (documentString); + } + } } -- 2.11.4.GIT