public StyleCopRunner()
 {
     this.violations      = new Dictionary <string, List <Violation> >();
     this.environment     = new ObjectBasedEnvironment(this.SourceCodeFactory, this.SettingsFactory);
     this.configuration   = new Configuration(new[] { "DEBUG", "TRACE" });
     this.styleCopConsole = new StyleCopObjectConsole(this.environment, null, null, true);
     this.styleCopConsole.ViolationEncountered += this.OnViolationEncountered;
 }
 public void Dispose()
 {
     this.styleCopConsole.ViolationEncountered -= this.OnViolationEncountered;
     this.styleCopConsole = null;
     this.environment     = null;
     this.configuration   = null;
     this.violations      = null;
 }
Beispiel #3
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// A new StyleCopCore object.
        /// </returns>
        public static StyleCopCore Create()
        {
            StyleCopTrace.In();

            ProjectSettingsFactory projectSettingsFactory = new ProjectSettingsFactory();
            SourceCodeFactory      sourceCodeFactory      = new SourceCodeFactory();

            ObjectBasedEnvironment environment = new ObjectBasedEnvironment(sourceCodeFactory.Create, projectSettingsFactory.Create);

            StyleCopObjectConsole styleCop = new StyleCopObjectConsole(environment, null, null, true);

            projectSettingsFactory.StyleCopCore = styleCop.Core;

            return(StyleCopTrace.Out(styleCop.Core));
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <returns>
        /// A new StyleCopCore object.
        /// </returns>
        public static StyleCopCore Create()
        {
            StyleCopTrace.In();

            ProjectSettingsFactory projectSettingsFactory = new ProjectSettingsFactory();
            SourceCodeFactory sourceCodeFactory = new SourceCodeFactory();

            ObjectBasedEnvironment environment = new ObjectBasedEnvironment(sourceCodeFactory.Create, projectSettingsFactory.Create);

            StyleCopObjectConsole styleCop = new StyleCopObjectConsole(environment, null, null, true);

            projectSettingsFactory.StyleCopCore = styleCop.Core;

            return StyleCopTrace.Out(styleCop.Core);
        }
        public void TestObjectBasedSourceCodeWithNoSettings()
        {
            ObjectBasedEnvironment environment = new ObjectBasedEnvironment(this.SourceCodeFactory, this.ProjectSettingsFactory);

            StyleCopObjectConsole styleCop = new StyleCopObjectConsole(environment, null, new[] { "%projectroot%\\test\\testbin" }, false);

            // Create the configuration.
            Configuration configuration = new Configuration(null);

            // Create a CodeProject.
            CodeProject project = new CodeProject(0, null, configuration);
            styleCop.Core.Environment.AddSourceCode(project, "source1.cs", 0);
            styleCop.Core.Environment.AddSourceCode(project, "source2.cs", 1);
            styleCop.Core.Environment.AddSourceCode(project, "source3.cs", 2);

            styleCop.Start(new[] { project });
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="lifetime">
        /// The lifetime.
        /// </param>
        /// <param name="fileSystemTracker">
        /// The file System Tracker.
        /// </param>
        /// <returns>
        /// A new StyleCopCore object.
        /// </returns>
        public static StyleCopCore Create(Lifetime lifetime, IFileSystemTracker fileSystemTracker)
        {
            StyleCopTrace.In();

            ProjectSettingsFactory projectSettingsFactory = new ProjectSettingsFactory(lifetime, fileSystemTracker);
            SourceCodeFactory sourceCodeFactory = new SourceCodeFactory();

            ObjectBasedEnvironment environment = new ObjectBasedEnvironment(sourceCodeFactory.Create, projectSettingsFactory.Create);

            // TODO: Is there a nicer way of finding out the ReSharper install location?
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), @"Extensions\StyleCop.StyleCop\StyleCopAddIns");
            string[] paths = { path };
            StyleCopObjectConsole styleCop = new StyleCopObjectConsole(environment, null, paths, false);

            projectSettingsFactory.StyleCopCore = styleCop.Core;

            return StyleCopTrace.Out(styleCop.Core);
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="lifetime">
        /// The lifetime.
        /// </param>
        /// <param name="settingsStore">The settings store.</param>
        /// <param name="fileSystemTracker">
        /// The file System Tracker.
        /// </param>
        /// <returns>
        /// A new StyleCopCore object.
        /// </returns>
        public static StyleCopCore Create(Lifetime lifetime, ISettingsStore settingsStore, IFileSystemTracker fileSystemTracker)
        {
            StyleCopTrace.In();

            ProjectSettingsFactory projectSettingsFactory = new ProjectSettingsFactory(lifetime, fileSystemTracker);
            SourceCodeFactory      sourceCodeFactory      = new SourceCodeFactory();

            ObjectBasedEnvironment environment = new ObjectBasedEnvironment(
                sourceCodeFactory.Create,
                projectSettingsFactory.Create);

            IContextBoundSettingsStore settings = settingsStore.BindToContextTransient(ContextRange.ApplicationWide);
            bool   pluginsEnabled = settings.GetValue((StyleCopOptionsSettingsKey options) => options.PluginsEnabled);
            string pluginsPath    = settings.GetValue((StyleCopOptionsSettingsKey options) => options.PluginsPath);

            // TODO: Is there a nicer way of finding out the ReSharper install location?
            string standardPath =
                FileSystemPath.Parse(Assembly.GetCallingAssembly().Location)
                .Directory.Combine(@"Extensions\StyleCop.StyleCop\StyleCopAddins")
                .FullPath;

            var paths = new List <string> {
                standardPath
            };

            if (pluginsEnabled && !string.IsNullOrEmpty(pluginsPath))
            {
                paths.Add(pluginsPath);
            }

            StyleCopObjectConsole styleCop = new StyleCopObjectConsole(environment, null, paths, false);

            projectSettingsFactory.StyleCopCore = styleCop.Core;

            return(StyleCopTrace.Out(styleCop.Core));
        }