Merge pull request #820 from brendanzagaeski/master
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Execution / BuildResult.cs
1 // BuildResult.cs
2 //
3 // Author:
4 //   Rolf Bjarne Kvinge (rolf@xamarin.com)
5 //
6 // Copyright (C) 2011 Xamarin Inc.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27
28 using System;
29 using System.Collections.Generic;
30 using System.Linq;
31
32 namespace Microsoft.Build.Execution
33 {
34         public class BuildResult
35         {
36                 public BuildResult ()
37                 {
38                         ResultsByTarget = new Dictionary<string, TargetResult> ();
39                 }
40                 
41                 public void AddResultsForTarget (string target, TargetResult result)
42                 {
43                         ResultsByTarget.Add (target, result);
44                 }
45
46                 public bool HasResultsForTarget (string target)
47                 {
48                         return ResultsByTarget.ContainsKey (target);
49                 }
50
51                 public void MergeResults (BuildResult results)
52                 {
53                         if (ConfigurationId != results.ConfigurationId)
54                                 throw new InvalidOperationException ("Argument BuildResults have inconsistent ConfigurationId.");
55                         if (GlobalRequestId != results.GlobalRequestId)
56                                 throw new InvalidOperationException ("Argument BuildResults have inconsistent GlobalRequestId.");
57                         if (NodeRequestId != results.NodeRequestId)
58                                 throw new InvalidOperationException ("Argument BuildResults have inconsistent NodeRequestId.");
59                         if (ParentGlobalRequestId != results.ParentGlobalRequestId)
60                                 throw new InvalidOperationException ("Argument BuildResults have inconsistent ParentGlobalRequestId.");
61                         if (SubmissionId != results.SubmissionId)
62                                 throw new InvalidOperationException ("Argument BuildResults have inconsistent SubmissionId.");
63                         
64                         CircularDependency |= results.CircularDependency;
65                         Exception = Exception ?? results.Exception;
66                         foreach (var p in results.ResultsByTarget)
67                                 ResultsByTarget.Add (p.Key, p.Value);
68                 }
69
70                 public bool CircularDependency { get; internal set; }
71
72                 public int ConfigurationId { get; internal set; }
73
74                 public Exception Exception { get; set; }
75
76                 public int GlobalRequestId { get; internal set; }
77
78                 public ITargetResult this [string target] {
79                         get { return ResultsByTarget [target]; }
80                 }
81
82                 public int NodeRequestId { get; internal set; }
83
84                 BuildResultCode? overall_result;
85                 public BuildResultCode OverallResult {
86                         get {
87                                 if (overall_result == null)
88                                         throw new InvalidOperationException ("Build has not finished");
89                                 return overall_result.Value;
90                         }
91                         internal set { overall_result = value; }
92                 }
93
94                 public int ParentGlobalRequestId { get; internal set; }
95
96                 public IDictionary<string, TargetResult> ResultsByTarget { get; private set; }
97
98                 public int SubmissionId { get; internal set; }
99         }
100 }
101