Exemplo n.º 1
0
        public static void StyleCopAnalyse(this ICakeContext context, SettingsDelegate settingsDelegate)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (settingsDelegate == null)
            {
                throw new ArgumentNullException(nameof(settingsDelegate));
            }

            StyleCopRunner.Execute(context, settingsDelegate);
        }
Exemplo n.º 2
0
        public TitleBar(Window mainWindow, string windowName, bool isMaximizeAble = false, SettingsDelegate settingsDelegate = null)
        {
            InitializeComponent();

            window = mainWindow;

            if (!isMaximizeAble)
            {
                btnSize.Visibility = Visibility.Hidden;
            }

            if (settingsDelegate == null)
            {
                btnSettings.Visibility = Visibility.Hidden;
            }

            SettingsCreation   = settingsDelegate;
            WindowName.Content = windowName;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts an analysis run.
        /// </summary>
        /// <param name="context">The cake context.</param>
        /// <param name="settingsDelegate">The stylecop setting to use during the analysis.</param>
        public static void Execute(ICakeContext context, SettingsDelegate settingsDelegate)
        {
            settings = settingsDelegate(new StyleCopSettings());

            // need to get pwd for stylecop.dll for stylesheet
            var assemblyDirectory = AssemblyDirectory(Assembly.GetAssembly(typeof(StyleCopSettings)));
            var toolPath          = context.File(assemblyDirectory).Path.GetDirectory();
            var defaultStyleSheet = context.File(toolPath + "/StyleCopStyleSheet.xslt");

            context.Log.Information($"Stylecop: Default stylesheet {context.MakeAbsolute(defaultStyleSheet)}");

            var solutionFile = settings.SolutionFile;
            var settingsFile = settings.SettingsFile?.ToString();
            var outputPath   = settings.ResultsFile?.ToString();
            var addins       = settings.Addins.Count == 0 ? null : settings.Addins.Select(x => x.FullPath).ToList();

            var solutionParser = new SolutionParser(context.FileSystem, context.Environment);
            var projectParser  = new ProjectParser(context.FileSystem, context.Environment);

            var projectPath = solutionFile.MakeAbsolute(context.Environment).GetDirectory();

            context.Log.Information($"Stylecop: Found solution {projectPath.FullPath}");

            StyleCopConsole styleCopConsole = null;

            try
            {
                styleCopConsole = new StyleCopConsole(
                    settingsFile,
                    settings.WriteResultsCache,
                    /* Input Cache Result */
                    outputPath,
                    /* Output file */
                    addins,
                    settings.LoadFromDefaultPath);
            }
            catch (TypeLoadException typeLoadException)
            {
                context.Log.Error($"Error: Stylecop was unable to load an Addin .dll. {typeLoadException.Message}");
                throw;
            }

            var styleCopProjects = new List <CodeProject>();

            var solution = solutionParser.Parse(solutionFile);

            foreach (var solutionProject in solution.Projects.Where(p => p.Type != FOLDER_PROJECT_TYPE_GUID))
            {
                context.Log.Information($"Stylecop: Found project {solutionProject.Path}");
                var project         = projectParser.Parse(solutionProject.Path);
                var styleCopProject = new CodeProject(0, solutionProject.Path.GetDirectory().ToString(), new Configuration(null));
                styleCopProjects.Add(styleCopProject);

                foreach (var projectFile in project.Files)
                {
                    if (projectFile.FilePath.GetExtension() != ".cs")
                    {
                        continue;
                    }

                    context.Log.Debug($"Stylecop: Found file {projectFile.FilePath}");
                    styleCopConsole.Core.Environment.AddSourceCode(styleCopProject, projectFile.FilePath.ToString(), null);
                }
            }

            var handler = new StylecopHandlers(context, settings);

            styleCopConsole.OutputGenerated      += handler.OnOutputGenerated;
            styleCopConsole.ViolationEncountered += handler.ViolationEncountered;
            context.Log.Information($"Stylecop: Starting analysis");
            styleCopConsole.Start(styleCopProjects.ToArray(), settings.FullAnalyze);
            context.Log.Information($"Stylecop: Finished analysis");
            styleCopConsole.OutputGenerated      -= handler.OnOutputGenerated;
            styleCopConsole.ViolationEncountered -= handler.ViolationEncountered;

            if (settings.HtmlReportFile != null)
            {
                settings.HtmlReportFile = settings.HtmlReportFile.MakeAbsolute(context.Environment);

                // copy default resources to output folder
                context.CopyDirectory(context.Directory(toolPath + "/resources"), settings.HtmlReportFile.GetDirectory() + "/resources");

                context.Log.Information($"Stylecop: Creating html report {settings.HtmlReportFile.FullPath}");
                Transform(context, settings.HtmlReportFile, settings.ResultsFile.MakeAbsolute(context.Environment), settings.StyleSheet ?? context.MakeAbsolute(defaultStyleSheet));
            }

            if (handler.TotalViolations > 0 && settings.FailTask)
            {
                throw new Exception($"{handler.TotalViolations} StyleCop violations encountered.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts an analysis run.
        /// </summary>
        /// <param name="context">The cake context.</param>
        /// <param name="settingsDelegate">The stylecop setting to use during the analysis.</param>
        public static void Execute(ICakeContext context, SettingsDelegate settingsDelegate)
        {
            settings = settingsDelegate(new StyleCopSettings());

            // need to get pwd for stylecop.dll for stylesheet
            var assemblyDirectory = AssemblyDirectory(Assembly.GetAssembly(typeof(StyleCopSettings)));
            var toolPath          = context.File(assemblyDirectory).Path.GetDirectory();
            var defaultStyleSheet = context.File(toolPath + "/StyleCopStyleSheet.xslt");

            context.Log.Information($"Stylecop: Default stylesheet {context.MakeAbsolute(defaultStyleSheet)}");

            var styleCopConsole = InitializeStyleCopConsole(context);

            var styleCopProjects = new List <CodeProject>();

            var projectParser = new ProjectParser(context.FileSystem, context.Environment);

            if (settings.SolutionFile != null)
            {
                var solutionFile = settings.SolutionFile;
                var projectPath  = solutionFile.MakeAbsolute(context.Environment).GetDirectory();
                context.Log.Information($"Stylecop: Found solution {projectPath.FullPath}");

                var solutionParser = new SolutionParser(context.FileSystem, context.Environment);
                var solution       = solutionParser.Parse(solutionFile);

                styleCopProjects
                .AddRange(
                    solution.Projects
                    .Where(p => p.Type != FOLDER_PROJECT_TYPE_GUID)
                    .Select(solutionProject =>
                            InitializeProject(context, solutionProject.Path, projectParser, styleCopConsole)));
            }
            else if (settings.ProjectFiles.Count != 0)
            {
                styleCopProjects
                .AddRange(
                    settings.ProjectFiles
                    .Select(
                        projectFile => InitializeProject(context, projectFile, projectParser, styleCopConsole)));
            }
            else
            {
                throw new ArgumentException("Solution or Project file was not included");
            }

            var handler = new StylecopHandlers(context);

            styleCopConsole.OutputGenerated      += handler.OnOutputGenerated;
            styleCopConsole.ViolationEncountered += handler.ViolationEncountered;
            context.Log.Information($"Stylecop: Starting analysis");
            styleCopConsole.Start(styleCopProjects.ToArray(), settings.FullAnalyze);
            context.Log.Information($"Stylecop: Finished analysis");
            styleCopConsole.OutputGenerated      -= handler.OnOutputGenerated;
            styleCopConsole.ViolationEncountered -= handler.ViolationEncountered;

            if (settings.HtmlReportFile != null)
            {
                settings.HtmlReportFile = settings.HtmlReportFile.MakeAbsolute(context.Environment);

                // copy default resources to output folder
                context.CopyDirectory(context.Directory(toolPath + "/resources"), settings.HtmlReportFile.GetDirectory() + "/resources");

                context.Log.Information($"Stylecop: Creating html report {settings.HtmlReportFile.FullPath}");
                Transform(context, settings.HtmlReportFile, settings.ResultsFile.MakeAbsolute(context.Environment), settings.StyleSheet ?? context.MakeAbsolute(defaultStyleSheet));
            }

            if (handler.TotalViolations > 0)
            {
                throw new Exception($"{handler.TotalViolations} StyleCop violations encountered.");
            }
        }