private bool IsFullyBoundProject(ISolutionRuleSetsInformationProvider ruleSetInfoProvider, IRuleSetSerializer ruleSetSerializer,
                                         BindingConfiguration binding, Project project, Core.Language language)
        {
            Debug.Assert(binding != null);
            Debug.Assert(project != null);

            // If solution is not bound/is missing a rules configuration file, no need to go further
            var slnLevelBindingConfigFilepath = CalculateSonarQubeSolutionBindingConfigPath(ruleSetInfoProvider, binding, language);

            if (!fileSystem.File.Exists(slnLevelBindingConfigFilepath))
            {
                return(false);
            }

            if (!BindingRefactoringDumpingGround.IsProjectLevelBindingRequired(project))
            {
                return(true); // nothing else to check
            }

            // Projects that required project-level binding should be using RuleSets for configuration,
            // so we assume that the solution-level config file is a ruleset.
            RuleSet sonarQubeRuleSet = ruleSetSerializer.LoadRuleSet(slnLevelBindingConfigFilepath);

            if (sonarQubeRuleSet == null)
            {
                return(false);
            }

            RuleSetDeclaration[] declarations = ruleSetInfoProvider.GetProjectRuleSetsDeclarations(project).ToArray();
            return(declarations.Length > 0 && // Need at least one
                   declarations.All(declaration => this.IsRuleSetBound(ruleSetSerializer, project, declaration, sonarQubeRuleSet)));
        }
 private static string CalculateSonarQubeSolutionBindingConfigPath(ISolutionRuleSetsInformationProvider ruleSetInfoProvider, BindingConfiguration binding, Core.Language language)
 => ruleSetInfoProvider.CalculateSolutionSonarQubeRuleSetFilePath(
     binding.Project.ProjectKey,
     language,
     binding.Mode);
Beispiel #3
0
        public static string Prepare(string JSON, string classname, Core.Language language, string aNamespace, bool pascal, string propertyAttribute, bool hasGetSet = false)
        {
            if (string.IsNullOrEmpty(JSON))
            {
                return(null);
            }

            ICodeWriter writer;

            switch (language)
            {
            case Language.CSharp:
                writer = new CSharpCodeWriter();
                break;

            case Language.VisualBasic:
                writer = new VisualBasicCodeWriter();
                break;

            case Language.TypeScript:
                writer = new TypeScriptCodeWriter();
                break;

            case Language.Sql:
                writer = new SqlCodeWriter();
                break;

            case Language.Java:
                writer = new JavaCodeWriter();
                break;

            case Language.PHP:
                writer = new PhpCodeWriter();
                break;

            default:
                throw new NotImplementedException("This language does not yet exists");
            }
            ;


            var gen = new JsonClassGenerator();

            gen.Example                 = JSON;
            gen.InternalVisibility      = false;
            gen.CodeWriter              = writer;
            gen.ExplicitDeserialization = false;
            if (!string.IsNullOrEmpty(aNamespace))
            {
                gen.Namespace = aNamespace;
            }
            else
            {
                gen.Namespace = null;
            }

            gen.NoHelperClass      = false;
            gen.SecondaryNamespace = null;
            gen.UseProperties      = ((int)language != 5 && (int)language != 6) || hasGetSet;
            gen.MainClass          = classname;
            gen.UsePascalCase      = pascal;
            gen.PropertyAttribute  = propertyAttribute;

            gen.UseNestedClasses           = !string.IsNullOrEmpty(aNamespace);
            gen.ApplyObfuscationAttributes = false;
            gen.SingleFile = true;
            gen.ExamplesInDocumentation = false;

            gen.TargetFolder = null;
            gen.SingleFile   = true;

            using (var sw = new StringWriter())
            {
                gen.OutputStream = sw;
                gen.GenerateClasses();
                sw.Flush();

                return(sw.ToString());
            }
        }