1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
// ProjectServiceExtension.cs
//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
//
// Copyright (c) 2007 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.
//
//
using System;
using System.Collections.Generic;
using MonoDevelop.Core;
using MonoDevelop.Projects.Extensions;
using MonoDevelop.Core.Execution;
namespace MonoDevelop.Projects
{
public class ProjectServiceExtension
{
internal ProjectServiceExtension Next;
Stack<ItemLoadCallback> loadCallbackStack = new Stack<ItemLoadCallback> ();
Stack<ItemCompileCallback> compileCallbackStack = new Stack<ItemCompileCallback> ();
internal ProjectServiceExtension GetNext (IBuildTarget item)
{
if (Next.SupportsItem (item))
return Next;
else
return Next.GetNext (item);
}
public virtual bool SupportsItem (IBuildTarget item)
{
return true;
}
public virtual object GetService (SolutionItem item, Type type)
{
if (type.IsInstanceOfType (this))
return this;
else
return GetNext (item).GetService (item, type);
}
public virtual object GetService (WorkspaceItem item, Type type)
{
if (type.IsInstanceOfType (this))
return this;
else
return GetNext (item).GetService (item, type);
}
public virtual void Save (IProgressMonitor monitor, SolutionEntityItem item)
{
GetNext (item).Save (monitor, item);
}
public virtual void Save (IProgressMonitor monitor, WorkspaceItem item)
{
GetNext (item).Save (monitor, item);
}
public virtual List<FilePath> GetItemFiles (SolutionEntityItem item, bool includeReferencedFiles)
{
return GetNext (item).GetItemFiles (item, includeReferencedFiles);
}
public virtual bool IsSolutionItemFile (string fileName)
{
return GetNext (UnknownItem.Instance).IsSolutionItemFile (fileName);
}
public virtual bool IsWorkspaceItemFile (string fileName)
{
return GetNext (UnknownItem.Instance).IsWorkspaceItemFile (fileName);
}
internal virtual SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, ItemLoadCallback callback)
{
loadCallbackStack.Push (callback);
try {
SolutionEntityItem res = LoadSolutionItem (monitor, fileName);
return res;
} finally {
loadCallbackStack.Pop ();
}
}
protected virtual SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName)
{
return GetNext (UnknownItem.Instance).LoadSolutionItem (monitor, fileName, loadCallbackStack.Peek ());
}
public virtual WorkspaceItem LoadWorkspaceItem (IProgressMonitor monitor, string fileName)
{
return GetNext (UnknownItem.Instance).LoadWorkspaceItem (monitor, fileName);
}
public virtual BuildResult RunTarget (IProgressMonitor monitor, IBuildTarget item, string target, ConfigurationSelector configuration)
{
if (target == ProjectService.BuildTarget)
return Build (monitor, item, configuration);
else if (target == ProjectService.CleanTarget) {
Clean (monitor, item, configuration);
return null;
}
else
return GetNext (item).RunTarget (monitor, item, target, configuration);
}
public virtual bool SupportsTarget (IBuildTarget item, string target)
{
if (item is SolutionEntityItem)
return SupportsTarget ((SolutionEntityItem)item, target);
else if (item is WorkspaceItem)
return SupportsTarget ((WorkspaceItem) item, target);
else
return GetNext (item).SupportsTarget (item, target);
}
protected virtual bool SupportsTarget (SolutionEntityItem item, string target)
{
return GetNext (item).SupportsTarget ((IBuildTarget) item, target);
}
protected virtual bool SupportsTarget (Solution solution, string target)
{
return GetNext (solution).SupportsTarget ((IBuildTarget) solution, target);
}
protected virtual bool SupportsTarget (WorkspaceItem item, string target)
{
if (item is Solution)
return SupportsTarget ((Solution) item, target);
else
return GetNext (item).SupportsTarget ((IBuildTarget) item, target);
}
protected virtual void Clean (IProgressMonitor monitor, IBuildTarget item, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
Clean (monitor, (SolutionEntityItem) item, configuration);
else if (item is WorkspaceItem)
Clean (monitor, (WorkspaceItem) item, configuration);
else
GetNext (item).RunTarget (monitor, item, ProjectService.CleanTarget, configuration);
}
protected virtual void Clean (IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
{
GetNext (item).RunTarget (monitor, item, ProjectService.CleanTarget, configuration);
}
protected virtual void Clean (IProgressMonitor monitor, Solution item, ConfigurationSelector configuration)
{
GetNext (item).RunTarget (monitor, item, ProjectService.CleanTarget, configuration);
}
protected virtual void Clean (IProgressMonitor monitor, WorkspaceItem item, ConfigurationSelector configuration)
{
if (item is Solution)
Clean (monitor, (Solution) item, configuration);
else
GetNext (item).RunTarget (monitor, item, ProjectService.CleanTarget, configuration);
}
protected virtual BuildResult Build (IProgressMonitor monitor, IBuildTarget item, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
return Build (monitor, (SolutionEntityItem) item, configuration);
if (item is WorkspaceItem)
return Build (monitor, (WorkspaceItem) item, configuration);
return GetNext (item).RunTarget (monitor, item, ProjectService.BuildTarget, configuration);
}
protected virtual BuildResult Build (IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
{
return GetNext (item).RunTarget (monitor, item, ProjectService.BuildTarget, configuration);
}
protected virtual BuildResult Build (IProgressMonitor monitor, WorkspaceItem item, ConfigurationSelector configuration)
{
if (item is Solution)
return Build (monitor, (Solution) item, configuration);
return GetNext (item).RunTarget (monitor, item, ProjectService.BuildTarget, configuration);
}
protected virtual BuildResult Build (IProgressMonitor monitor, Solution solution, ConfigurationSelector configuration)
{
return GetNext (solution).RunTarget (monitor, solution, ProjectService.BuildTarget, configuration);
}
public virtual void Execute (IProgressMonitor monitor, IBuildTarget item, ExecutionContext context, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
Execute (monitor, (SolutionEntityItem)item, context, configuration);
else if (item is WorkspaceItem)
Execute (monitor, (WorkspaceItem) item, context, configuration);
else
GetNext (item).Execute (monitor, item, context, configuration);
}
protected virtual void Execute (IProgressMonitor monitor, SolutionEntityItem item, ExecutionContext context, ConfigurationSelector configuration)
{
GetNext (item).Execute (monitor, (IBuildTarget) item, context, configuration);
}
protected virtual void Execute (IProgressMonitor monitor, Solution solution, ExecutionContext context, ConfigurationSelector configuration)
{
GetNext (solution).Execute (monitor, (IBuildTarget) solution, context, configuration);
}
protected virtual void Execute (IProgressMonitor monitor, WorkspaceItem item, ExecutionContext context, ConfigurationSelector configuration)
{
if (item is Solution)
Execute (monitor, (Solution) item, context, configuration);
else
GetNext (item).Execute (monitor, (IBuildTarget) item, context, configuration);
}
public virtual bool CanExecute (IBuildTarget item, ExecutionContext context, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
return CanExecute ((SolutionEntityItem)item, context, configuration);
else if (item is WorkspaceItem)
return CanExecute ((WorkspaceItem) item, context, configuration);
else
return GetNext (item).CanExecute (item, context, configuration);
}
protected virtual bool CanExecute (SolutionEntityItem item, ExecutionContext context, ConfigurationSelector configuration)
{
return GetNext (item).CanExecute ((IBuildTarget) item, context, configuration);
}
protected virtual bool CanExecute (Solution solution, ExecutionContext context, ConfigurationSelector configuration)
{
return GetNext (solution).CanExecute ((IBuildTarget) solution, context, configuration);
}
protected virtual bool CanExecute (WorkspaceItem item, ExecutionContext context, ConfigurationSelector configuration)
{
if (item is Solution)
return CanExecute ((Solution) item, context, configuration);
else
return GetNext (item).CanExecute ((IBuildTarget) item, context, configuration);
}
public virtual IEnumerable<ExecutionTarget> GetExecutionTargets (IBuildTarget item, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
return GetExecutionTargets ((SolutionEntityItem)item, configuration);
else if (item is WorkspaceItem)
return GetExecutionTargets ((WorkspaceItem) item, configuration);
else
return GetNext (item).GetExecutionTargets (item, configuration);
}
protected virtual IEnumerable<ExecutionTarget> GetExecutionTargets (SolutionEntityItem item, ConfigurationSelector configuration)
{
return GetNext (item).GetExecutionTargets ((IBuildTarget) item, configuration);
}
protected virtual IEnumerable<ExecutionTarget> GetExecutionTargets (Solution solution, ConfigurationSelector configuration)
{
return GetNext (solution).GetExecutionTargets ((IBuildTarget) solution, configuration);
}
protected virtual IEnumerable<ExecutionTarget> GetExecutionTargets (WorkspaceItem item, ConfigurationSelector configuration)
{
if (item is Solution)
return GetExecutionTargets ((Solution) item, configuration);
else
return GetNext (item).GetExecutionTargets ((IBuildTarget) item, configuration);
}
public virtual bool GetNeedsBuilding (IBuildTarget item, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
return GetNeedsBuilding ((SolutionEntityItem) item, configuration);
if (item is WorkspaceItem)
return GetNeedsBuilding ((WorkspaceItem) item, configuration);
return GetNext (item).GetNeedsBuilding (item, configuration);
}
protected virtual bool GetNeedsBuilding (SolutionEntityItem item, ConfigurationSelector configuration)
{
return GetNext (item).GetNeedsBuilding ((IBuildTarget) item, configuration);
}
protected virtual bool GetNeedsBuilding (Solution item, ConfigurationSelector configuration)
{
return GetNext (item).GetNeedsBuilding ((IBuildTarget) item, configuration);
}
protected virtual bool GetNeedsBuilding (WorkspaceItem item, ConfigurationSelector configuration)
{
if (item is Solution)
return GetNeedsBuilding ((Solution) item, configuration);
return GetNext (item).GetNeedsBuilding ((IBuildTarget) item, configuration);
}
public virtual void SetNeedsBuilding (IBuildTarget item, bool val, ConfigurationSelector configuration)
{
if (item is SolutionEntityItem)
SetNeedsBuilding ((SolutionEntityItem) item, val, configuration);
else if (item is WorkspaceItem)
SetNeedsBuilding ((WorkspaceItem) item, val, configuration);
else
GetNext (item).SetNeedsBuilding (item, val, configuration);
}
protected virtual void SetNeedsBuilding (SolutionEntityItem item, bool val, ConfigurationSelector configuration)
{
GetNext (item).SetNeedsBuilding ((IBuildTarget) item, val, configuration);
}
protected virtual void SetNeedsBuilding (Solution item, bool val, ConfigurationSelector configuration)
{
GetNext (item).SetNeedsBuilding ((IBuildTarget) item, val, configuration);
}
protected virtual void SetNeedsBuilding (WorkspaceItem item, bool val, ConfigurationSelector configuration)
{
if (item is Solution)
SetNeedsBuilding ((Solution) item, val, configuration);
else
GetNext (item).SetNeedsBuilding ((IBuildTarget) item, val, configuration);
}
internal virtual BuildResult Compile (IProgressMonitor monitor, SolutionEntityItem item, BuildData buildData, ItemCompileCallback callback)
{
compileCallbackStack.Push (callback);
try {
BuildResult res = Compile (monitor, item, buildData);
return res;
} finally {
compileCallbackStack.Pop ();
}
}
protected virtual BuildResult Compile (IProgressMonitor monitor, SolutionEntityItem item, BuildData buildData)
{
return GetNext (item).Compile (monitor, item, buildData, compileCallbackStack.Peek ());
}
public virtual IEnumerable<string> GetReferencedAssemblies (DotNetProject project, ConfigurationSelector configuration, bool includeProjectReferences)
{
return GetNext (project).GetReferencedAssemblies (project, configuration, includeProjectReferences);
}
}
public class BuildData
{
public ProjectItemCollection Items { get; internal set; }
public DotNetProjectConfiguration Configuration { get; internal set; }
public ConfigurationSelector ConfigurationSelector { get; internal set; }
}
class UnknownItem: IBuildTarget
{
public static UnknownItem Instance = new UnknownItem ();
public BuildResult RunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration)
{
return new BuildResult ();
}
public void Execute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration)
{
throw new System.NotImplementedException();
}
public bool CanExecute (ExecutionContext context, ConfigurationSelector configuration)
{
return false;
}
public bool SupportsTarget (string target)
{
return false;
}
public bool NeedsBuilding (ConfigurationSelector configuration)
{
return false;
}
public void SetNeedsBuilding (bool needsBuilding, ConfigurationSelector configuration)
{
}
public void Save (IProgressMonitor monitor)
{
}
public string Name {
get { return "Unknown"; }
set { }
}
public FilePath ItemDirectory {
get { return FilePath.Empty; }
}
public FilePath BaseDirectory {
get { return FilePath.Empty; }
set { }
}
public void Dispose ()
{
}
public System.Collections.IDictionary ExtendedProperties {
get { return null; }
}
}
}
|