4 // Rolf Bjarne Kvinge (rolf@xamarin.com)
6 // Copyright (C) 2011 Xamarin Inc.
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:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
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.
28 using Microsoft.Build.Evaluation;
30 using System.Collections.Generic;
31 using System.Threading.Tasks;
32 using System.Threading;
34 namespace Microsoft.Build.Execution
36 public class BuildManager
38 public BuildManager ()
42 public BuildManager (string hostName)
44 throw new NotImplementedException ();
47 public void Dispose ()
53 // maybe HostServices related cleanup is expected.
56 readonly TaskFactory<BuildResult> task_factory = new TaskFactory<BuildResult> ();
57 List<BuildSubmission> submissions = new List<BuildSubmission> ();
59 BuildParameters ongoing_build_parameters;
60 BuildSubmission ongoing_build_submission;
62 internal BuildParameters OngoingBuildParameters {
63 get { return ongoing_build_parameters; }
66 public void BeginBuild (BuildParameters parameters)
68 if (ongoing_build_parameters != null)
69 throw new InvalidOperationException ("There is already ongoing build");
70 ongoing_build_parameters = parameters;
72 // FIXME: apply build parameters to this build manager instance.
75 public BuildResult Build (BuildParameters parameters, BuildRequestData requestData)
77 BeginBuild (parameters);
78 return BuildRequest (requestData);
81 public BuildResult BuildRequest (BuildRequestData requestData)
83 var sub = PendBuildRequest (requestData);
85 return sub.BuildResult;
88 public void CancelAllSubmissions ()
90 foreach (var sub in submissions)
95 public void EndBuild ()
97 if (ongoing_build_parameters == null)
98 throw new InvalidOperationException ("Build has not started");
100 for (int i = 0; ongoing_build_submission == null && i < 50; i++)
101 Thread.Sleep (20 * i);
103 while (ongoing_build_submission == null)
105 ongoing_build_submission.WaitHandle.WaitOne ();
107 ongoing_build_submission = null;
108 ongoing_build_parameters = null;
111 Dictionary<Project,ProjectInstance> instances = new Dictionary<Project, ProjectInstance> ();
113 public ProjectInstance GetProjectInstanceForBuild (Project project)
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...
123 return GetProjectInstanceForBuildInternal (project);
126 internal ProjectInstance GetProjectInstanceForBuildInternal (Project project)
129 if (!instances.ContainsKey (project))
130 instances [project] = project.CreateProjectInstance ();
131 return instances [project];
134 public BuildSubmission PendBuildRequest (BuildRequestData requestData)
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);
143 public void ResetCaches ()
145 throw new NotImplementedException ();
148 internal TaskFactory<BuildResult> TaskFactory {
149 get { return task_factory; }
152 static BuildManager default_manager = new BuildManager ();
154 public static BuildManager DefaultBuildManager {
155 get { return default_manager; }