Ejemplo n.º 1
0
        /// <summary>
        /// Downloads SonarQube issues associated to the requested project. Issues are
        /// translated to 'Visual Studio' error items and get their source code file
        /// paths relative to the provided project path.
        /// </summary>
        /// <param name="projectKey">SonarQube project key (not name)</param>
        /// <param name="projectLocalPath">Local directory path which hosts the project source files</param>
        /// <returns></returns>
        public async Task <IEnumerable <ErrorListItem> > GetErrorsAsync(string projectKey, string projectLocalPath)
        {
            IEnumerable <ErrorListItem> errors = Enumerable.Empty <ErrorListItem>();

            if (!_cachedErrors.TryGetValue(projectKey, out errors))
            {
                var issues = await _client.Issues.GetProjectIssues(projectKey);

                errors = issues.Select(issue => new ErrorListItem(_client.SonarQubeApiUrl, issue)).ToList();
                _cachedErrors[projectKey] = errors;
            }

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

            if (!Path.IsPathRooted(errors.First().FileName) && !string.IsNullOrEmpty(projectLocalPath))
            {
                var directories = await DirectorySearcher.GetDirectoriesFastAsync(projectLocalPath);

                var projectRootPath = ResolveProjectRootPath(errors.First().FileName, directories);
                if (!string.IsNullOrEmpty(projectRootPath))
                {
                    errors.ToList().ForEach(x =>
                    {
                        string cleanFilePath = x.FileName.Split(':').Last();
                        x.FileName           = projectRootPath + cleanFilePath;
                    });
                }
            }

            return(errors);
        }
Ejemplo n.º 2
0
        public async Task AsyncRecursiveDirectoryListing()
        {
            using (var a = TemporaryFile.CreateDirectory(Path.Combine(Path.GetTempPath(), "a")))
                using (var aa = TemporaryFile.CreateDirectory(Path.Combine(a.Path, "aa")))
                    using (var ab = TemporaryFile.CreateDirectory(Path.Combine(a.Path, "ab")))
                        using (var aaa = TemporaryFile.CreateDirectory(Path.Combine(aa.Path, "aaa")))
                        {
                            var directories = await DirectorySearcher.GetDirectoriesFastAsync(a.Path);

                            Assert.That(directories.Select(dir => dir.FullName), Is.EquivalentTo(new[] { ab.Path, aaa.Path }));
                        }
        }