diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2014-04-01 14:48:20 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@xamarin.com> | 2014-04-01 14:48:20 +0400 |
commit | f88a7bec0c504f47decf3394b80bb8710645bb49 (patch) | |
tree | 5b50f1d98102ff0159a2808c031a183508c0cd21 /main/src/core/MonoDevelop.Core | |
parent | a2fb44c4a2d66ffd94584023ccdc365a5545f37f (diff) |
[Core] New extensibility methods
Add api for checking if a project supports a specific target.
Propagate calls to SolutionItem.GetService to the underlying
solution item handler.
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
9 files changed, 160 insertions, 14 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ISolutionItemHandler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ISolutionItemHandler.cs index adef0bf5d4..83b0603b79 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ISolutionItemHandler.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ISolutionItemHandler.cs @@ -80,5 +80,19 @@ namespace MonoDevelop.Projects.Extensions /// Hint about which part of the solution item has been modified. This will typically be the property name. /// </param> void OnModified (string hint); + + /// <summary> + /// Gets a service instance of a given type + /// </summary> + /// <returns> + /// The service. + /// </returns> + /// <param name='t'> + /// Type of the service + /// </param> + /// <remarks> + /// This method looks for an imlpementation of a service of the given type. + /// </remarks> + object GetService (Type t); } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemHandler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemHandler.cs index 56391bd52f..835a0c2d92 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemHandler.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemHandler.cs @@ -82,5 +82,10 @@ namespace MonoDevelop.Projects.Extensions public virtual void OnModified (string hint) { } + + public virtual object GetService (Type t) + { + return null; + } } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildHandler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildHandler.cs index ac0a6f3467..29e862cb26 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildHandler.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildHandler.cs @@ -151,5 +151,22 @@ namespace MonoDevelop.Projects.Formats.MSBuild { customSlnData = item; } + + /// <summary> + /// Gets a service instance of a given type + /// </summary> + /// <returns> + /// The service. + /// </returns> + /// <param name='t'> + /// Type of the service + /// </param> + /// <remarks> + /// This method looks for an imlpementation of a service of the given type. + /// </remarks> + public virtual object GetService (Type t) + { + return null; + } } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IBuildTarget.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IBuildTarget.cs index 3a3a3c0304..a6a601a44c 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IBuildTarget.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IBuildTarget.cs @@ -35,6 +35,7 @@ namespace MonoDevelop.Projects public interface IBuildTarget: IWorkspaceObject { BuildResult RunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration); + bool CanRunTarget (string target, ConfigurationSelector configuration); void Execute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration); bool CanExecute (ExecutionContext context, ConfigurationSelector configuration); bool NeedsBuilding (ConfigurationSelector configuration); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs index a5aa5415c6..20a4ef4c71 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs @@ -643,11 +643,16 @@ namespace MonoDevelop.Projects { Dictionary <SolutionItem,bool> needsBuildingCache; - public override object GetService (IBuildTarget item, Type type) + public override object GetService (SolutionItem item, Type type) { - return null; + return item.OnGetService (type); } + public override object GetService (WorkspaceItem item, Type type) + { + return item.OnGetService (type); + } + public override void Save (IProgressMonitor monitor, SolutionEntityItem entry) { FileService.RequestFileEdit (entry.GetItemFiles (false)); @@ -700,6 +705,16 @@ namespace MonoDevelop.Projects return res; } + public override bool CanRunTarget (IBuildTarget item, string target, ConfigurationSelector configuration) + { + if (item is WorkspaceItem) + return ((WorkspaceItem)item).OnGetCanRunTarget (target, configuration); + else if (item is SolutionItem) + return ((SolutionItem)item).OnGetCanRunTarget (target, configuration); + else + throw new InvalidOperationException ("Unknown item type: " + item); + } + public override void Execute (IProgressMonitor monitor, IBuildTarget item, ExecutionContext context, ConfigurationSelector configuration) { if (item is SolutionEntityItem) { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs index bfa738ae61..501ff2d088 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectServiceExtension.cs @@ -54,7 +54,15 @@ namespace MonoDevelop.Projects return true; } - public virtual object GetService (IBuildTarget item, Type type) + 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; @@ -120,6 +128,34 @@ namespace MonoDevelop.Projects return GetNext (item).RunTarget (monitor, item, target, configuration); } + public virtual bool CanRunTarget (IBuildTarget item, string target, ConfigurationSelector configuration) + { + if (item is SolutionEntityItem) + return CanRunTarget ((SolutionEntityItem)item, target, configuration); + else if (item is WorkspaceItem) + return CanRunTarget ((WorkspaceItem) item, target, configuration); + else + return GetNext (item).CanRunTarget (item, target, configuration); + } + + protected virtual bool CanRunTarget (SolutionEntityItem item, string target, ConfigurationSelector configuration) + { + return GetNext (item).CanRunTarget ((IBuildTarget) item, target, configuration); + } + + protected virtual bool CanRunTarget (Solution solution, string target, ConfigurationSelector configuration) + { + return GetNext (solution).CanRunTarget ((IBuildTarget) solution, target, configuration); + } + + protected virtual bool CanRunTarget (WorkspaceItem item, string target, ConfigurationSelector configuration) + { + if (item is Solution) + return CanRunTarget ((Solution) item, target, configuration); + else + return GetNext (item).CanRunTarget ((IBuildTarget) item, target, configuration); + } + protected virtual void Clean (IProgressMonitor monitor, IBuildTarget item, ConfigurationSelector configuration) { if (item is SolutionEntityItem) @@ -173,7 +209,7 @@ namespace MonoDevelop.Projects { 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) @@ -360,6 +396,11 @@ namespace MonoDevelop.Projects return false; } + public bool CanRunTarget (string target, ConfigurationSelector configuration) + { + return false; + } + public bool NeedsBuilding (ConfigurationSelector configuration) { return false; diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionFolder.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionFolder.cs index cd98fda4ae..093f346b58 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionFolder.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionFolder.cs @@ -1007,6 +1007,11 @@ namespace MonoDevelop.Projects public void Dispose () { } + + public object GetService (Type t) + { + return null; + } } public class SolutionFolderFileCollection: System.Collections.ObjectModel.Collection<FilePath> diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs index 488dd2d19d..d857407711 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs @@ -160,14 +160,9 @@ namespace MonoDevelop.Projects /// </param> /// <remarks> /// This method looks for an imlpementation of a service of the given type. - /// The default implementation this instance if the type is an interface - /// implemented by this instance. Otherwise, it looks for a service in - /// the project extension chain. /// </remarks> public virtual object GetService (Type t) { - if (t.IsInstanceOfType (this)) - return this; return Services.ProjectService.GetExtensionChain (this).GetService (this, t); } @@ -478,6 +473,21 @@ namespace MonoDevelop.Projects return Services.ProjectService.GetExtensionChain (this).RunTarget (monitor, this, target, configuration); } + public bool CanRunTarget (string target, ConfigurationSelector configuration) + { + return Services.ProjectService.GetExtensionChain (this).CanRunTarget (this, target, configuration); + } + + public bool CanBuild (ConfigurationSelector configuration) + { + return CanRunTarget (ProjectService.BuildTarget, configuration); + } + + public bool CanClean (ConfigurationSelector configuration) + { + return CanRunTarget (ProjectService.CleanTarget, configuration); + } + /// <summary> /// Cleans the files produced by this solution item /// </summary> @@ -602,7 +612,7 @@ namespace MonoDevelop.Projects return true; return false; } - + /// <summary> /// Gets the time of the last build /// </summary> @@ -1050,6 +1060,11 @@ namespace MonoDevelop.Projects return DateTime.MinValue; } + internal protected virtual bool OnGetCanRunTarget (string target, ConfigurationSelector configuration) + { + return true; + } + /// <summary> /// Determines whether this solution item can be executed using the specified context and configuration. /// </summary> @@ -1075,7 +1090,12 @@ namespace MonoDevelop.Projects protected virtual void OnBoundToSolution () { } - + + internal protected virtual object OnGetService (Type t) + { + return ItemHandler.GetService (t); + } + /// <summary> /// Occurs when the name of the item changes /// </summary> diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceItem.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceItem.cs index df27e2c77a..bd941749a3 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceItem.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/WorkspaceItem.cs @@ -163,8 +163,6 @@ namespace MonoDevelop.Projects public virtual object GetService (Type t) { - if (t.IsInstanceOfType (this)) - return this; return Services.ProjectService.GetExtensionChain (this).GetService (this, t); } @@ -249,6 +247,16 @@ namespace MonoDevelop.Projects return Services.ProjectService.GetExtensionChain (this).RunTarget (monitor, this, target, configuration); } + public bool CanBuild (ConfigurationSelector configuration) + { + return CanRunTarget (ProjectService.BuildTarget, configuration); + } + + public bool CanClean (ConfigurationSelector configuration) + { + return CanRunTarget (ProjectService.CleanTarget, configuration); + } + public void Clean (IProgressMonitor monitor, string configuration) { Clean (monitor, (SolutionConfigurationSelector) configuration); @@ -259,6 +267,16 @@ namespace MonoDevelop.Projects Services.ProjectService.GetExtensionChain (this).RunTarget (monitor, this, ProjectService.CleanTarget, configuration); } + public bool CanRunTarget (string target, string configuration) + { + return CanRunTarget (target, (SolutionConfigurationSelector) configuration); + } + + public bool CanRunTarget (string target, ConfigurationSelector configuration) + { + return Services.ProjectService.GetExtensionChain (this).CanRunTarget (this, target, configuration); + } + public BuildResult Build (IProgressMonitor monitor, string configuration) { return InternalBuild (monitor, (SolutionConfigurationSelector) configuration); @@ -408,6 +426,11 @@ namespace MonoDevelop.Projects return null; } + internal protected virtual bool OnGetCanRunTarget (string target, ConfigurationSelector configuration) + { + return true; + } + protected virtual void OnClean (IProgressMonitor monitor, ConfigurationSelector configuration) { } @@ -562,7 +585,12 @@ namespace MonoDevelop.Projects if (NameChanged != null) NameChanged (this, e); } - + + internal protected virtual object OnGetService (Type t) + { + return null; + } + protected void NotifyModified () { OnModified (new WorkspaceItemEventArgs (this)); |