Fix API: remove non-existent property in .NET (copy-paste bad).
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Execution / BuildManager.cs
1 // BuildManager.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 Microsoft.Build.Evaluation;
29 using System;
30 using System.Collections.Generic;
31 using System.Threading.Tasks;
32 using System.Threading;
33
34 namespace Microsoft.Build.Execution
35 {
36         public class BuildManager
37         {
38                 public BuildManager ()
39                 {
40                 }
41
42                 public BuildManager (string hostName)
43                 {
44                         throw new NotImplementedException ();
45                 }
46                 
47                 public void Dispose ()
48                 {
49                 }
50
51                 ~BuildManager ()
52                 {
53                         // maybe HostServices related cleanup is expected.
54                 }
55
56                 readonly TaskFactory<BuildResult> task_factory = new TaskFactory<BuildResult> ();
57                 List<BuildSubmission> submissions = new List<BuildSubmission> ();
58                 
59                 BuildParameters ongoing_build_parameters;
60                 BuildSubmission ongoing_build_submission;
61                 
62                 internal BuildParameters OngoingBuildParameters {
63                         get { return ongoing_build_parameters; }
64                 }
65
66                 public void BeginBuild (BuildParameters parameters)
67                 {
68                         if (ongoing_build_parameters != null)
69                                 throw new InvalidOperationException ("There is already ongoing build");
70                         ongoing_build_parameters = parameters;
71                         
72                         // FIXME: apply build parameters to this build manager instance.
73                 }
74
75                 public BuildResult Build (BuildParameters parameters, BuildRequestData requestData)
76                 {
77                         BeginBuild (parameters);
78                         return BuildRequest (requestData);
79                 }
80
81                 public BuildResult BuildRequest (BuildRequestData requestData)
82                 {
83                         var sub = PendBuildRequest (requestData);
84                         sub.Execute ();
85                         return sub.BuildResult;
86                 }
87                 
88                 public void CancelAllSubmissions ()
89                 {
90                         foreach (var sub in submissions)
91                                 sub.Cancel ();
92                         submissions.Clear ();
93                 }
94
95                 public void EndBuild ()
96                 {
97                         if (ongoing_build_parameters == null)
98                                 throw new InvalidOperationException ("Build has not started");
99                         // spin wait
100                         for (int i = 0; ongoing_build_submission == null && i < 50; i++)
101                                 Thread.Sleep (20 * i);
102                         // long wait...
103                         while (ongoing_build_submission == null)
104                                 Thread.Sleep (500);
105                         ongoing_build_submission.WaitHandle.WaitOne ();
106                         
107                         ongoing_build_submission = null;
108                         ongoing_build_parameters = null;
109                 }
110                 
111                 Dictionary<Project,ProjectInstance> instances = new Dictionary<Project, ProjectInstance> ();
112
113                 public ProjectInstance GetProjectInstanceForBuild (Project project)
114                 {
115                         if (project == null)
116                                 throw new ArgumentNullException ("project");
117                         if (project.FullPath == null)
118                                 throw new ArgumentNullException ("project", "FullPath parameter in the project cannot be null.");
119                         if (project.FullPath == string.Empty)
120                                 throw new ArgumentException ("FullPath parameter in the project cannot be empty.", "project");
121                         // other than that, any invalid path character is accepted...
122                         
123                         return GetProjectInstanceForBuildInternal (project);
124                 }
125                         
126                 internal ProjectInstance GetProjectInstanceForBuildInternal (Project project)
127                 {
128                         ProjectInstance ret;
129                         if (!instances.ContainsKey (project))
130                                 instances [project] = project.CreateProjectInstance ();
131                         return instances [project];
132                 }
133
134                 public BuildSubmission PendBuildRequest (BuildRequestData requestData)
135                 {
136                         if (ongoing_build_parameters == null)
137                                 throw new InvalidOperationException ("This method cannot be called before calling BeginBuild method.");
138                         var sub = new BuildSubmission (this, requestData);
139                         submissions.Add (sub);
140                         return sub;
141                 }
142
143                 public void ResetCaches ()
144                 {
145                         throw new NotImplementedException ();
146                 }
147
148                 internal TaskFactory<BuildResult> TaskFactory {
149                         get { return task_factory; }
150                 }
151                 
152                 static BuildManager default_manager = new BuildManager ();
153
154                 public static BuildManager DefaultBuildManager {
155                         get { return default_manager; }
156                 }
157         }
158 }
159