Ejemplo n.º 1
0
        public void IsBindingRequired_ProjectHasTwoLanguages_ReturnsIfAllLanguagesHaveConfigFiles(bool isFirstLanguageBound, bool isSecondLanguageBound, bool expectedResult)
        {
            var projectMock = new ProjectMock("c:\\test.csproj");

            projectMock.SetProjectKind(new Guid(ProjectSystemHelper.CppProjectKind));

            var bindingConfiguration = new BindingConfiguration(new BoundSonarQubeProject(new Uri("http://test.com"), "key", "name"),
                                                                SonarLintMode.Connected, "c:\\");

            var cppFilePath = bindingConfiguration.BuildPathUnderConfigDirectory(Language.Cpp.FileSuffixAndExtension);
            var cFilePath   = bindingConfiguration.BuildPathUnderConfigDirectory(Language.C.FileSuffixAndExtension);

            fileSystemMock
            .Setup(x => x.File.Exists(cppFilePath))
            .Returns(isFirstLanguageBound);

            if (isFirstLanguageBound)
            {
                fileSystemMock
                .Setup(x => x.File.Exists(cFilePath))
                .Returns(isSecondLanguageBound);
            }

            var result = testSubject.IsBindingRequired(bindingConfiguration, projectMock);

            result.Should().Be(expectedResult);

            fileSystemMock.VerifyAll();
        }
        private RulesSettings FindConnectedModeSettings(string languageKey, BindingConfiguration binding)
        {
            var language = Language.GetLanguageFromLanguageKey(languageKey);

            Debug.Assert(language != null, $"Unknown language key: {languageKey}");

            if (language != null)
            {
                var filePath = binding.BuildPathUnderConfigDirectory(language.FileSuffixAndExtension);
                var settings = serializer.SafeLoad(filePath);
                return(settings);
            }
            return(null);
        }
        public bool IsBindingRequired(BindingConfiguration binding, Project project)
        {
            Debug.Assert(binding != null);
            Debug.Assert(project != null);

            var languages = ProjectToLanguageMapper.GetAllBindingLanguagesForProject(project);

            languages = languages.Where(x => x.Equals(Language.C) || x.Equals(Language.Cpp));

            return(languages.Any(language =>
            {
                var slnLevelBindingConfigFilepath = binding.BuildPathUnderConfigDirectory(language.FileSuffixAndExtension);

                return !fileSystem.File.Exists(slnLevelBindingConfigFilepath);
            }));
        }
Ejemplo n.º 4
0
        // ISSUE : this method is doing too many things
        private RuleSetInformation[] CheckSlnLevelConfigExistsAndReturnAllProjectRuleSetsForAllConfigurations(BindingConfiguration bindingConfiguration)
        {
            var projectSystem = this.serviceProvider.GetService <IProjectSystemHelper>();

            projectSystem.AssertLocalServiceIsNotNull();

            var ruleSetInfoProvider = this.serviceProvider.GetService <ISolutionRuleSetsInformationProvider>();

            ruleSetInfoProvider.AssertLocalServiceIsNotNull();

            var projectRuleSetAggregation = new Dictionary <string, RuleSetInformation>(StringComparer.OrdinalIgnoreCase);

            foreach (Project project in projectSystem.GetFilteredSolutionProjects())
            {
                // Solution-level checks (done here because the expected solution-level config
                // depends on the languages supported by the project that exist)
                string baselineRuleSet = bindingConfiguration.BuildPathUnderConfigDirectory(ProjectToLanguageMapper.GetLanguageForProject(project).FileSuffixAndExtension);

                if (!fileSystem.File.Exists(baselineRuleSet))
                {
                    this.WriteWarning(Strings.ExpectedRuleSetNotFound, baselineRuleSet, project.FullName);
                    continue;
                }

                if (projectBinderFactory.Get(project) is CSharpVBProjectBinder)
                {
                    foreach (var declaration in ruleSetInfoProvider.GetProjectRuleSetsDeclarations(project))
                    {
                        string projectRuleSet =
                            CalculateProjectRuleSetFullPath(ruleSetInfoProvider, declaration);

                        this.AddOrUpdateAggregatedRuleSetInformation(projectRuleSetAggregation, baselineRuleSet,
                                                                     declaration, projectRuleSet);
                    }
                }
            }

            return(projectRuleSetAggregation.Values.ToArray());
        }
        public async Task <IBindingConfig> GetConfigurationAsync(SonarQubeQualityProfile qualityProfile, Language language, BindingConfiguration bindingConfiguration, CancellationToken cancellationToken)
        {
            if (!IsLanguageSupported(language))
            {
                throw new ArgumentOutOfRangeException(nameof(language));
            }

            var result = await WebServiceHelper.SafeServiceCallAsync(
                () => sonarQubeService.GetAllRulesAsync(qualityProfile.Key, cancellationToken), logger);

            if (result == null)
            {
                return(null);
            }

            cancellationToken.ThrowIfCancellationRequested();

            var settings         = CreateRulesSettingsFromQPRules(result);
            var settingsFilePath = bindingConfiguration.BuildPathUnderConfigDirectory(language.FileSuffixAndExtension);

            var configFile = new CFamilyBindingConfig(settings, settingsFilePath);

            return(configFile);
        }
Ejemplo n.º 6
0
        private string GetSolutionAdditionalFilePath(BindingConfiguration bindingConfiguration)
        {
            var directory = bindingConfiguration.BuildPathUnderConfigDirectory();

            return(Path.Combine(directory, Language.CSharp.Id, "SonarLint.xml"));
        }
Ejemplo n.º 7
0
 private string GetSolutionRulesetPath(BindingConfiguration bindingConfiguration)
 {
     return(bindingConfiguration.BuildPathUnderConfigDirectory(Language.CSharp.FileSuffixAndExtension));
 }
        internal static string GetSolutionAdditionalFilePath(Language language, BindingConfiguration bindingConfiguration)
        {
            var additionalFilePathDirectory = bindingConfiguration.BuildPathUnderConfigDirectory();

            return(Path.Combine(additionalFilePathDirectory, language.Id, "SonarLint.xml"));
        }
 internal static string GetSolutionRuleSetFilePath(Language language, BindingConfiguration bindingConfiguration)
 {
     return(bindingConfiguration.BuildPathUnderConfigDirectory(language.FileSuffixAndExtension));
 }