diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2014-07-03 23:57:18 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2014-07-03 23:57:18 +0400 |
commit | c4f7804fda12518d69c2db3766afcfecdfb5fdc2 (patch) | |
tree | 216cb7f77dd746da92b9aaeb656a8eb1e6a2e253 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools | |
parent | 3e79e5ea9b967926a5ae0709485f0b4cb596897f (diff) | |
parent | 5d5dde2d5992f2b89ccc22c4cdce670d9ea6f07a (diff) |
Merge branch 'aspnet-awesome'
Conflicts:
version-checks
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/CustomToolService.cs | 51 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/MSBuildCustomTool.cs | 55 |
2 files changed, 86 insertions, 20 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/CustomToolService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/CustomToolService.cs index 4897ecb754..78f2292634 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/CustomToolService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/CustomToolService.cs @@ -42,9 +42,9 @@ namespace MonoDevelop.Ide.CustomTools { public static class CustomToolService { - static Dictionary<string,CustomToolExtensionNode> nodes = new Dictionary<string,CustomToolExtensionNode> (); + static readonly Dictionary<string,CustomToolExtensionNode> nodes = new Dictionary<string,CustomToolExtensionNode> (); - static Dictionary<string,IAsyncOperation> runningTasks = new Dictionary<string, IAsyncOperation> (); + static readonly Dictionary<string,IAsyncOperation> runningTasks = new Dictionary<string, IAsyncOperation> (); static CustomToolService () { @@ -79,15 +79,25 @@ namespace MonoDevelop.Ide.CustomTools //forces static ctor to run } - static ISingleFileCustomTool GetGenerator (ProjectFile file) + static ISingleFileCustomTool GetGenerator (string name) { + if (string.IsNullOrEmpty (name)) + return null; + + if (name.StartsWith ("msbuild:", StringComparison.OrdinalIgnoreCase)) { + string target = name.Substring ("msbuild:".Length).Trim (); + if (string.IsNullOrEmpty (target)) + return null; + return new MSBuildCustomTool (target); + } + CustomToolExtensionNode node; - if (!string.IsNullOrEmpty (file.Generator) && nodes.TryGetValue (file.Generator, out node)) { + if (nodes.TryGetValue (name, out node)) { try { return node.Tool; } catch (Exception ex) { - LoggingService.LogError ("Error loading generator '" + file.Generator + "'", ex); - nodes.Remove (file.Generator); + LoggingService.LogError ("Error loading generator '" + name + "'", ex); + nodes.Remove (name); } } return null; @@ -95,7 +105,7 @@ namespace MonoDevelop.Ide.CustomTools public static void Update (ProjectFile file, bool force) { - var tool = GetGenerator (file); + var tool = GetGenerator (file.Generator); if (tool == null) return; @@ -124,7 +134,7 @@ namespace MonoDevelop.Ide.CustomTools var aggOp = new AggregatedOperationMonitor (monitor); try { monitor.BeginTask (GettextCatalog.GetString ("Running generator '{0}' on file '{1}'...", file.Generator, file.Name), 1); - var op = tool.Generate (monitor, file, result); + IAsyncOperation op = tool.Generate (monitor, file, result); runningTasks.Add (file.FilePath, op); aggOp.AddOperation (op); op.Completed += delegate { @@ -172,20 +182,21 @@ namespace MonoDevelop.Ide.CustomTools monitor.ReportError (msg, result.UnhandledException); LoggingService.LogError (msg, result.UnhandledException); } - + genFileName = result.GeneratedFilePath.IsNullOrEmpty? null : result.GeneratedFilePath.ToRelative (file.FilePath.ParentDirectory); - bool validName = !string.IsNullOrEmpty (genFileName) - && genFileName.IndexOfAny (new char[] { '/', '\\' }) < 0 - && FileService.IsValidFileName (genFileName); - - if (!broken && !validName) { - broken = true; - string msg = GettextCatalog.GetString ("The '{0}' code generator output invalid filename '{1}'", - file.Generator, result.GeneratedFilePath); - result.Errors.Add (new CompilerError (file.Name, 0, 0, "", msg)); - monitor.ReportError (msg, null); + if (!string.IsNullOrEmpty (genFileName)) { + bool validName = genFileName.IndexOfAny (new char[] { '/', '\\' }) < 0 + && FileService.IsValidFileName (genFileName); + + if (!broken && !validName) { + broken = true; + string msg = GettextCatalog.GetString ("The '{0}' code generator output invalid filename '{1}'", + file.Generator, result.GeneratedFilePath); + result.Errors.Add (new CompilerError (file.Name, 0, 0, "", msg)); + monitor.ReportError (msg, null); + } } if (result.Errors.Count > 0) { @@ -243,7 +254,7 @@ namespace MonoDevelop.Ide.CustomTools { foreach (ProjectFileEventInfo args in e) { var file = args.ProjectFile; - var tool = GetGenerator (file); + var tool = GetGenerator (file.Generator); if (tool == null) continue; } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/MSBuildCustomTool.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/MSBuildCustomTool.cs new file mode 100644 index 0000000000..1edc9e59fc --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/MSBuildCustomTool.cs @@ -0,0 +1,55 @@ +//
+// MSBuildCustomTool.cs
+//
+// Author:
+// Michael Hutchinson <mhutch@xamarin.com>
+//
+// Copyright (c) 2014 Xamarin Inc.
+//
+// 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 MonoDevelop.Core;
+using MonoDevelop.Projects;
+using System.CodeDom.Compiler;
+
+namespace MonoDevelop.Ide.CustomTools
+{
+ class MSBuildCustomTool : ISingleFileCustomTool
+ {
+ readonly string targetName;
+
+ public MSBuildCustomTool (string targetName)
+ {
+ this.targetName = targetName;
+ }
+
+ public IAsyncOperation Generate (IProgressMonitor monitor, ProjectFile file, SingleFileCustomToolResult result)
+ {
+ return new ThreadAsyncOperation (() => {
+ var buildResult = file.Project.RunTarget (monitor, targetName, IdeApp.Workspace.ActiveConfiguration);
+ foreach (var err in buildResult.Errors) {
+ result.Errors.Add (new CompilerError (err.FileName, err.Line, err.Column, err.ErrorNumber, err.ErrorText) {
+ IsWarning = err.IsWarning
+ });
+ }
+ }, result);
+ }
+ }
+}
+
|