Exemplo n.º 1
0
        public static void Initialize()
        {
            AppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Vsix.Code);
            Directory.CreateDirectory(AppDataFolder);

            CleanupLegacyFolders();

            CoverletUtil.Initialize(AppDataFolder);
            ReportGeneratorUtil.Initialize(AppDataFolder);
            MsTestPlatformUtil.Initialize(AppDataFolder);
            OpenCoverUtil.Initialize(AppDataFolder);
        }
Exemplo n.º 2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            colorThemeService = serviceProvider.GetService(typeof(SVsColorThemeService));
            ThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                dte = (DTE)serviceProvider.GetService(typeof(DTE));
                Assumes.Present(dte);
            });

            CreateAppDataFolder();

            CleanupLegacyFolders();

            CoverletUtil.Initialize(AppDataFolder);
            ReportGeneratorUtil.Initialize(AppDataFolder);
            MsTestPlatformUtil.Initialize(AppDataFolder);
            OpenCoverUtil.Initialize(AppDataFolder);
        }
Exemplo n.º 3
0
        public static void ReloadCoverage(IEnumerable <CoverageProject> projects, bool darkMode)
        {
            // reset

            ClearProcesses();

            HtmlFilePath = null;

            CoverageLines.Clear();

            // process pipeline

            projects = projects
                       .Select(project =>
            {
                project.ProjectFileXElement = XElementUtil.Load(project.ProjectFile, true);
                project.Settings            = GetSettings(project);

                if (!project.Settings.Enabled)
                {
                    project.FailureDescription = $"Disabled";
                    return(project);
                }

                if (string.IsNullOrWhiteSpace(project.ProjectFile))
                {
                    project.FailureDescription = $"Unsupported project type for DLL '{project.TestDllFile}'";
                    return(project);
                }

                project.CoverageOutputFolder = Path.Combine(project.ProjectOutputFolder, "fine-code-coverage");
                project.CoverageOutputFile   = Path.Combine(project.CoverageOutputFolder, "project.coverage.xml");
                project.IsDotNetSdkStyle     = IsDotNetSdkStyle(project);
                project.ReferencedProjects   = GetReferencedProjects(project);
                project.HasExcludeFromCodeCoverageAssemblyAttribute = HasExcludeFromCodeCoverageAssemblyAttribute(project.ProjectFileXElement);
                project.AssemblyName = GetAssemblyName(project.ProjectFileXElement, Path.GetFileNameWithoutExtension(project.ProjectFile));

                project.EnsureEmptyOutputFolder();

                try
                {
                    var legacyOutputFolder = Path.Combine(project.ProjectOutputFolder, "_outputFolder");
                    Directory.Delete(legacyOutputFolder, true);
                }
                catch
                {
                    // ignore
                }

                return(project);
            })
                       .Select(p => p.Step("Run Coverage Tool", project =>
            {
                // run the appropriate cover tool

                if (project.IsDotNetSdkStyle)
                {
                    CoverletUtil.RunCoverlet(project, true);
                }
                else
                {
                    OpenCoverUtil.RunOpenCover(project, true);
                }
            }))
                       .Where(x => !x.HasFailed)
                       .ToArray();

            // project files

            var coverOutputFiles = projects
                                   .Select(x => x.CoverageOutputFile)
                                   .ToArray();

            if (!coverOutputFiles.Any())
            {
                return;
            }

            // run reportGenerator process

            ReportGeneratorUtil.RunReportGenerator(coverOutputFiles, darkMode, out var unifiedHtmlFile, out var unifiedXmlFile, true);

            // update CoverageLines

            CoverageReport = CoberturaUtil.ProcessCoberturaXmlFile(unifiedXmlFile, out var coverageLines);
            CoverageLines  = coverageLines;

            // update HtmlFilePath

            ReportGeneratorUtil.ProcessUnifiedHtmlFile(unifiedHtmlFile, darkMode, out var coverageHtml);
            HtmlFilePath = coverageHtml;
        }
Exemplo n.º 4
0
        public static void ReloadCoverage(IEnumerable <CoverageProject> projects, bool darkMode)
        {
            // reset

            ClearProcesses();

            HtmlFilePath = null;

            CoverageLines.Clear();

            // process pipeline

            projects = projects
                       .Select(project =>
            {
                project.Settings = GetSettings(project);

                if (!project.Settings.Enabled)
                {
                    project.FailureDescription = $"Disabled";
                    return(project);
                }

                if (string.IsNullOrWhiteSpace(project.ProjectFile))
                {
                    project.FailureDescription = $"Unsupported project type for DLL '{project.TestDllFileInOutputFolder}'";
                    return(project);
                }

                project.WorkOutputFolder        = Path.Combine(project.WorkFolder, "_outputfolder");
                project.CoverToolOutputFile     = Path.Combine(project.WorkOutputFolder, "_cover.tool.xml");
                project.TestDllFileInWorkFolder = Path.Combine(project.WorkFolder, Path.GetFileName(project.TestDllFileInOutputFolder));
                project.IsDotNetSdkStyle        = IsDotNetSdkStyle(project);

                return(project);
            })
                       .Select(p => p.Step("Ensure Work Folder Exists", project =>
            {
                // create folders

                var logs = new List <string>();

                if (!Directory.Exists(project.WorkFolder))
                {
                    Directory.CreateDirectory(project.WorkFolder);
                    logs.Add($"Created : {project.WorkFolder}");
                }

                if (!Directory.Exists(project.WorkOutputFolder))
                {
                    Directory.CreateDirectory(project.WorkOutputFolder);
                    logs.Add($"Created : {project.WorkOutputFolder}");
                }

                //Logger.LogWithoutTitle(logs);
            }))
                       .Select(p => p.Step("Synchronize Output Files To Work Folder", project =>
            {
                // sync files from output folder to work folder where we do the analysis

                var logs = FileSynchronizationUtil.Synchronize(project.ProjectOutputFolder, project.WorkFolder);

                //Logger.LogWithoutTitle(logs);
            }))
                       .Select(p => p.Step("Run Coverage Tool", project =>
            {
                // run the appropriate cover tool

                if (project.IsDotNetSdkStyle)
                {
                    CoverletUtil.RunCoverlet(project, true);
                }
                else
                {
                    OpenCoverUtil.RunOpenCover(project, true);
                }
            }))
                       .Where(x => !x.HasFailed)
                       .ToArray();

            // project files

            var coverOutputFiles = projects
                                   .Select(x => x.CoverToolOutputFile)
                                   .ToArray();

            if (!coverOutputFiles.Any())
            {
                return;
            }

            // run reportGenerator process

            ReportGeneratorUtil.RunReportGenerator(coverOutputFiles, darkMode, out var unifiedHtmlFile, out var unifiedXmlFile, true);

            // update CoverageLines

            CoberturaUtil.ProcessCoberturaXmlFile(unifiedXmlFile, out var coverageLines);
            CoverageLines = coverageLines;

            // update HtmlFilePath

            ReportGeneratorUtil.ProcessCoberturaHtmlFile(unifiedHtmlFile, darkMode, out var coverageHtml);
            HtmlFilePath = coverageHtml;
        }
Exemplo n.º 5
0
        private static void ReloadCoverage(List <CoverageProject> projects)
        {
            Logger.Log("================================== START ==================================");

            Reset();

            var coverageTask = System.Threading.Tasks.Task.Run(async() =>
            {
                // process pipeline

                await PrepareCoverageProjectsAsync(projects);

                foreach (var project in projects)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    await project.StepAsync("Run Coverage Tool", RunCoverToolAsync);
                }

                var passedProjects = projects.Where(x => !x.HasFailed);

                var coverOutputFiles = passedProjects
                                       .Select(x => x.CoverageOutputFile)
                                       .ToArray();

                if (coverOutputFiles.Any())
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    // run reportGenerator process

                    var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase);

                    var result = await ReportGeneratorUtil.RunReportGeneratorAsync(coverOutputFiles, darkMode, true);

                    if (result.Success)
                    {
                        // update CoverageLines

                        CoverageReport = CoberturaUtil.ProcessCoberturaXmlFile(result.UnifiedXmlFile, out var coverageLines);
                        CoverageLines  = coverageLines;
                        // update HtmlFilePath

                        ReportGeneratorUtil.ProcessUnifiedHtmlFile(result.UnifiedHtmlFile, darkMode, out var htmlFilePath);
                        HtmlFilePath = htmlFilePath;
                    }

                    // update margins

                    {
                        UpdateMarginTagsEventArgs updateMarginTagsEventArgs = null;

                        try
                        {
                            updateMarginTagsEventArgs = new UpdateMarginTagsEventArgs
                            {
                            };
                        }
                        catch
                        {
                            // ignore
                        }
                        finally
                        {
                            UpdateMarginTags?.Invoke(updateMarginTagsEventArgs);
                        }
                    }

                    // update output window

                    {
                        UpdateOutputWindowEventArgs updateOutputWindowEventArgs = null;

                        try
                        {
                            if (!string.IsNullOrEmpty(HtmlFilePath))
                            {
                                updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs
                                {
                                    HtmlContent = File.ReadAllText(HtmlFilePath)
                                };
                            }
                        }
                        catch
                        {
                            // ignore
                        }
                        finally
                        {
                            UpdateOutputWindow?.Invoke(updateOutputWindowEventArgs);
                        }
                    }
                }


                // log

                Logger.Log("================================== DONE ===================================");

                cancellationTokenSource.Dispose();
                cancellationTokenSource = null;
            }, cancellationToken);
        }