Ejemplo n.º 1
0
        public bool TryGetQualityProfile(ConnectionInformation serverConnection, ProjectInformation project, Language language, CancellationToken token, out QualityProfile profile)
        {
            if (serverConnection == null)
            {
                throw new ArgumentNullException(nameof(serverConnection));
            }

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

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

            if (!language.IsSupported)
            {
                throw new ArgumentOutOfRangeException(nameof(language));
            }

            profile = this.SafeUseHttpClient <QualityProfile>(serverConnection,
                                                              async client =>
            {
                QualityProfile qp = await DownloadQualityProfile(client, project, language, token);
                if (qp == null)
                {
                    return(null);
                }

                QualityProfileChangeLog changeLog = await DownloadQualityProfileChangeLog(client, qp, token);
                if (changeLog != null)
                {
                    qp.QualityProfileTimestamp = changeLog.Events.SingleOrDefault()?.Date;
                }

                return(qp);
            });

            return(profile != null);
        }
Ejemplo n.º 2
0
        public bool TryGetExportProfile(ConnectionInformation connectionInformation, QualityProfile profile, Language language, CancellationToken token, out RoslynExportProfile export)
        {
            if (connectionInformation == null)
            {
                throw new ArgumentNullException(nameof(connectionInformation));
            }

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

            if (!language.IsSupported)
            {
                throw new ArgumentOutOfRangeException(nameof(language));
            }

            export = this.SafeUseHttpClient <RoslynExportProfile>(connectionInformation,
                                                                  client => DownloadQualityProfileExport(client, profile, language, token));

            return(export != null);
        }
            private bool HasProfileChanged(QualityProfile newProfileInfo, ApplicableQualityProfile oldProfileInfo)
            {
                if (!QualityProfile.KeyComparer.Equals(oldProfileInfo.ProfileKey, newProfileInfo.Key))
                {
                    VsShellUtils.WriteToSonarLintOutputPane(this.host, Strings.SonarLintProfileCheckDifferentProfile);
                    return true; // The profile change to a different one
                }

                if (oldProfileInfo.ProfileTimestamp != newProfileInfo.QualityProfileTimestamp)
                {
                    VsShellUtils.WriteToSonarLintOutputPane(this.host, Strings.SonarLintProfileCheckProfileUpdated);
                    return true; // The profile was updated
                }

                return false;
            }
        private QualityProfile ConfigureProfileExport(RoslynExportProfile export, Language language)
        {
            var profile = new QualityProfile { Language = SonarQubeServiceWrapper.GetServerLanguageKey(language) };
            this.sonarQubeService.ReturnProfile[language] = profile;
            this.sonarQubeService.ReturnExport[profile] = export;

            return profile;
        }
        private void UpdateDownloadedSonarQubeQualityProfile(RuleSet ruleSet, QualityProfile qualityProfile)
        {
            ruleSet.NonLocalizedDisplayName = string.Format(Strings.SonarQubeRuleSetNameFormat, this.project.Name, qualityProfile.Name);

            var ruleSetDescriptionBuilder = new StringBuilder();
            ruleSetDescriptionBuilder.AppendLine(ruleSet.Description);
            ruleSetDescriptionBuilder.AppendFormat(Strings.SonarQubeQualityProfilePageUrlFormat, this.connectionInformation.ServerUri, qualityProfile.Key);
            ruleSet.NonLocalizedDescription = ruleSetDescriptionBuilder.ToString();

            ruleSet.WriteToFile(ruleSet.FilePath);
        }
        bool ISonarQubeServiceWrapper.TryGetQualityProfile(ConnectionInformation serverConnection, ProjectInformation project, Language language, CancellationToken token, out QualityProfile profile)
        {
            profile = null;

            if (this.AllowConnections && !token.IsCancellationRequested)
            {
                this.AssertExpectedConnection(serverConnection);

                this.AssertExpectedProjectInformation(project);

                this.ReturnProfile.TryGetValue(language, out profile);
            }

            return profile != null;
        }
        bool ISonarQubeServiceWrapper.TryGetExportProfile(ConnectionInformation serverConnection, QualityProfile profile, Language language, CancellationToken token, out RoslynExportProfile export)
        {
            this.AssertExpectedConnection(serverConnection);

            Assert.IsNotNull(profile, "QualityProfile is expected");

            this.GetExportAction?.Invoke();

            export = null;
            this.ReturnExport.TryGetValue(profile, out export);

            QualityProfile profile2;
            this.ReturnProfile.TryGetValue(language, out profile2);
            Assert.AreSame(profile2, profile, "Unexpected profile for language");

            return export != null;
        }
Ejemplo n.º 8
0
        private async Task <QualityProfileChangeLog> DownloadQualityProfileChangeLog(HttpClient client, QualityProfile profile, CancellationToken token)
        {
            string api = CreateQualityProfileChangeLogUrl(profile);
            HttpResponseMessage response = await InvokeGetRequest(client, api, token, ensureSuccess : false);

            // The service doesn't exist on older versions, and it's not absolutely mandatory since we can work
            // without the information provided, only with reduced functionality.
            if (response.IsSuccessStatusCode)
            {
                return(await ProcessJsonResponse <QualityProfileChangeLog>(response, token));
            }
            else
            {
                VsShellUtils.WriteToSonarLintOutputPane(this.serviceProvider, Strings.SonarQubeOptionalServiceFailed, QualityProfileChangeLogAPI, (int)response.StatusCode);
                return(null);
            }
        }
Ejemplo n.º 9
0
 internal /*for testing purposes*/ static string CreateQualityProfileChangeLogUrl(QualityProfile profile)
 {
     // Results are in descending order, so setting the page size to 1 will improve performance
     return(AppendQueryString(QualityProfileChangeLogAPI, "?profileKey={0}&ps=1", profile.Key));
 }
Ejemplo n.º 10
0
        private static async Task <RoslynExportProfile> DownloadQualityProfileExport(HttpClient client, QualityProfile profile, Language language, CancellationToken token)
        {
            var    roslynExporterName = CreateRoslynExporterName(language);
            string api = CreateQualityProfileExportUrl(profile, language, roslynExporterName);
            HttpResponseMessage response = await InvokeGetRequest(client, api, token);

            using (Stream stream = await response.Content.ReadAsStreamAsync())
                using (var reader = new StreamReader(stream))
                {
                    return(RoslynExportProfile.Load(reader));
                }
        }
Ejemplo n.º 11
0
 internal /*for testing purposes*/ static string CreateQualityProfileExportUrl(QualityProfile profile, Language language, string exporter)
 {
     // TODO: why name and not key? why language is needed at all, profiles are per language
     return(AppendQueryString(QualityProfileExportAPI, "?name={0}&language={1}&format={2}", profile.Name, GetServerLanguageKey(language), exporter));
 }