From 60ff3350e4190082537c52aeeb8c03aee3767e0b Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 20 Mar 2014 18:20:46 +0100 Subject: [PATCH] [Gendarme] Improve finding included .ignore files When we can't find the include file specified in the .ignore file we also check the directory where the current .ignore file is located. This fixes a problem running the tests from within Visual Studio as outlined in README.vsnet. --- gendarme/console/IgnoreFileList.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/gendarme/console/IgnoreFileList.cs b/gendarme/console/IgnoreFileList.cs index b714ded6e..c4a4fa3b4 100644 --- a/gendarme/console/IgnoreFileList.cs +++ b/gendarme/console/IgnoreFileList.cs @@ -40,6 +40,7 @@ namespace Gendarme { public class IgnoreFileList : BasicIgnoreList { private string current_rule; + private string currentFileName; private Dictionary> assemblies = new Dictionary> (); private Dictionary> types = new Dictionary> (); private Dictionary> methods = new Dictionary> (); @@ -54,24 +55,34 @@ public IgnoreFileList (IRunner runner, string fileName) private void Push (string fileName) { - if (!String.IsNullOrEmpty (fileName) && File.Exists (fileName) && !files.Contains (fileName)) { + if (String.IsNullOrEmpty (fileName)) + return; + + if (File.Exists (fileName) && !files.Contains (fileName)) { files.Push (fileName); } + else { + var directory = Path.GetDirectoryName (currentFileName); + if (!string.IsNullOrEmpty (directory) && !fileName.StartsWith (directory)){ + Push (Path.Combine (directory, fileName)); + } + } } private void Parse () { char [] buffer = new char [4096]; while (files.Count > 0) { - string fileName = files.Pop (); - using (StreamLineReader sr = new StreamLineReader (fileName)) { + currentFileName = files.Pop (); + using (StreamLineReader sr = new StreamLineReader (currentFileName)) { while (!sr.EndOfStream) { int length = sr.ReadLine (buffer, 0, buffer.Length); ProcessLine (buffer, length); } } } - Resolve (); + currentFileName = null; + Resolve(); TearDown (); } @@ -132,7 +143,7 @@ private void ProcessLine (char [] buffer, int length) base.Add (current_rule, NamespaceDefinition.GetDefinition (GetString (buffer, length))); break; case '@': // include file - files.Push (GetString (buffer, length)); + Push (GetString (buffer, length)); break; default: Console.Error.WriteLine ("Bad ignore entry : '{0}'", new string (buffer));