Esempio n. 1
0
        /// <summary>
        /// Handler which enumerates issues for a Sonar project
        /// </summary>
        /// <param name="project">SonarQube project to query</param>
        /// <returns>Awaitable task which enumerates associated errors</returns>
        private async Task OnItemSelectAsync(SonarQubeProject project)
        {
            _projectPathsManager.TryGetValue(project.Key, out string projectLocalPath);

            IEnumerable <ErrorListItem> errors;

            try
            {
                errors = await _errorListProvider.GetErrorsAsync(project.Key, projectLocalPath);
            }
            catch
            {
                TeamExplorer.ShowNotification($"Failed to download issues for \"{project.Name}\".",
                                              NotificationType.Error, NotificationFlags.None, null, SonarErrorsNotificationId);

                return;
            }

            TeamExplorer.HideNotification(SonarErrorsNotificationId);

            if (errors.Any())
            {
                if (!Path.IsPathRooted(errors.First().FileName))
                {
                    TeamExplorer.ShowNotification("Unable to resolve local file path for issues. Make sure project local path is correctly configured.",
                                                  NotificationType.Warning, NotificationFlags.None, null, FilePathResolutionNotificationId);
                }
                else
                {
                    TeamExplorer.HideNotification(FilePathResolutionNotificationId);
                }
            }

            ErrorTable.CleanAllErrors();
            ErrorTable.AddErrors(project.Name, errors);

            _projectIssuesInView = project.Key;
        }
Esempio n. 2
0
        public async Task SonarQubeIssueToErrorListCategoryMap(string issueType,
                                                               string issueSeverity,
                                                               string expectedErrorCategopry,
                                                               __VSERRORCATEGORY expectedErrorSeverity)
        {
            var componentsClient = new Mock <IComponentsClient>();

            componentsClient.
            Setup(i => i.GetAllProjects()).
            Returns(Task.FromResult(new List <SonarQubeProject>()
            {
                new SonarQubeProject()
                {
                    Key  = "A",
                    Name = "Project A"
                },
            }));

            var issuesClient = new Mock <IIssuesClient>();

            issuesClient.
            Setup(i => i.GetProjectIssues(It.Is <string>(key => key == "A"))).
            Returns(Task.FromResult(new List <SonarQubeIssue>()
            {
                new SonarQubeIssue()
                {
                    Rule      = "other:QACPP.3030",
                    Severity  = issueSeverity,
                    Component = "A:git/proj-a/src/a.cpp",
                    Line      = 182,
                    Message   = "QACPP[1:3030]  This expression casts between two pointer types.",
                    Type      = issueType
                },
            }));

            var client = new Mock <ISonarQubeClient>();

            client.SetupGet(i => i.SonarQubeApiUrl).Returns(new Uri("https://server.com/"));
            client.SetupGet(i => i.Components).Returns(componentsClient.Object);
            client.SetupGet(i => i.Issues).Returns(issuesClient.Object);

            var provider = new ErrorListProvider(client.Object);
            var errors   = await provider.GetErrorsAsync("A", null);

            var expected = new List <ErrorListItem>()
            {
                new ErrorListItem()
                {
                    ProjectName      = "",
                    FileName         = "git\\proj-a\\src\\a.cpp",
                    Line             = 181,
                    Message          = "This expression casts between two pointer types.",
                    ErrorCode        = "QACPP3030",
                    ErrorCodeToolTip = "Get help for 'QACPP3030'",
                    ErrorCategory    = expectedErrorCategopry,
                    Severity         = expectedErrorSeverity
                },
            };

            Assert.That(errors, Is.EqualTo(expected).Using(new ErrorListItemComparer()));
        }