* Makefile.am:
[monodevelop.git] / extras / MonoDevelop.CodeAnalysis / MonoDevelop.CodeAnalysis.Smokey / SmokeyRunner.cs
blob17b428c8ec84779408fce3556e2aad69f41e307c
1 using System;
2 using System.Diagnostics;
3 using System.Collections.Generic;
4 using System.IO;
5 using System.Reflection;
7 using CA = MonoDevelop.CodeAnalysis;
9 namespace MonoDevelop.CodeAnalysis.Smokey {
11 public class SmokeyRunner : IRunner
13 private static readonly Assembly smokey;
15 static SmokeyRunner ()
17 string assemblyDirectory = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location);
18 smokey = Assembly.LoadFile (Path.Combine (assemblyDirectory, "smokey.exe"));
21 public SmokeyRunner()
25 public IEnumerable<CA.IViolation> Run (string inspectedFile, IEnumerable<CA.IRule> ruleSet)
27 // FIXME: add support for ruleSet parameter
28 // TODO: use MonoDevelop process APIs instead of System.Diagnostics
29 string arguments = "-xml";
31 ProcessStartInfo startInfo = new ProcessStartInfo ("mono");
32 // runtime needs to be defined explicitly (or somewhy 1.1 can be loaded)
33 startInfo.Arguments = string.Format ("--runtime=v2.0.50727 {0} {1} {2}",
34 smokey.CodeBase, arguments, inspectedFile);
35 startInfo.RedirectStandardOutput = true;
36 startInfo.UseShellExecute = false;
38 Process smokeyProcess = null;
39 try {
40 smokeyProcess = Process.Start (startInfo);
41 return SmokeyParser.ParseOutput (smokeyProcess.StandardOutput, ruleSet);
42 } catch (Exception ex) {
43 throw new InvalidOperationException (AddinCatalog.GetString ("Could not run Smokey or parse its output."), ex);
44 } finally {
45 if (smokey != null) smokeyProcess.Dispose ();
49 public static Assembly Smokey {
50 get { return smokey; }
53 public string Id {
54 get { return "SmokeyRunner"; }
57 public string Name {
58 get { return "Smokey"; }