コード例 #1
0
        internal CSharpVBBindingOperation(IServiceProvider serviceProvider,
                                          Project project,
                                          ICSharpVBBindingConfig cSharpVBBindingConfig,
                                          IFileSystem fileSystem,
                                          IAdditionalFileConflictChecker additionalFileConflictChecker,
                                          IRuleSetReferenceChecker ruleSetReferenceChecker)
        {
            this.serviceProvider               = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            this.initializedProject            = project ?? throw new ArgumentNullException(nameof(project));
            this.cSharpVBBindingConfig         = cSharpVBBindingConfig ?? throw new ArgumentNullException(nameof(cSharpVBBindingConfig));
            this.fileSystem                    = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
            this.additionalFileConflictChecker = additionalFileConflictChecker ?? throw new ArgumentNullException(nameof(additionalFileConflictChecker));
            this.ruleSetReferenceChecker       = ruleSetReferenceChecker ?? throw new ArgumentNullException(nameof(ruleSetReferenceChecker));

            this.sourceControlledFileSystem = this.serviceProvider.GetService <ISourceControlledFileSystem>();
            this.sourceControlledFileSystem.AssertLocalServiceIsNotNull();

            this.ruleSetSerializer = this.serviceProvider.GetService <IRuleSetSerializer>();
            this.ruleSetSerializer.AssertLocalServiceIsNotNull();
        }
        /// <summary>
        /// Queues a write to a project-level SonarQube <see cref="RuleSet"/> file in the <param name="projectRoot"/> directory.
        /// </summary>
        /// <param name="projectFullPath">The absolute full path to the project</param>
        /// <param name="ruleSetFileName">The rule set file name</param>
        /// <param name="solutionRuleSet\">Full path of the parent solution-level SonarQube rule set</param>
        /// <returns>Full file path of the file that we expect to write to</returns>
        internal /*for testing purposes*/ string QueueWriteProjectLevelRuleSet(string projectFullPath, string ruleSetFileName, ICSharpVBBindingConfig cSharpVBBindingConfig, string currentRuleSetPath)
        {
            if (IsDefaultMicrosoftRuleSet(currentRuleSetPath))
            {
                return(cSharpVBBindingConfig.RuleSet.Path);
            }

            Debug.Assert(!string.IsNullOrWhiteSpace(projectFullPath));
            Debug.Assert(!string.IsNullOrWhiteSpace(ruleSetFileName));

            string projectRoot = Path.GetDirectoryName(projectFullPath);
            string ruleSetRoot = PathHelper.ForceDirectoryEnding(projectRoot);

            string  existingRuleSetPath;
            RuleSet existingRuleSet;

            if (this.TryUpdateExistingProjectRuleSet(cSharpVBBindingConfig.RuleSet.Path, ruleSetRoot, currentRuleSetPath, out existingRuleSetPath, out existingRuleSet))
            {
                Debug.Assert(existingRuleSetPath != null);
                Debug.Assert(existingRuleSet != null);

                // Pend update
                this.sourceControlledFileSystem.QueueFileWrite(existingRuleSetPath, () =>
                {
                    existingRuleSet.WriteToFile(existingRuleSetPath);
                    return(true);
                });

                return(existingRuleSetPath);
            }

            // Create a new project level rule set
            var     solutionIncludePath = PathHelper.CalculateRelativePath(ruleSetRoot, cSharpVBBindingConfig.RuleSet.Path);
            RuleSet newRuleSet          = GenerateNewProjectRuleSet(solutionIncludePath, currentRuleSetPath, cSharpVBBindingConfig.RuleSet.Content.Name);
            string  newRuleSetPath      = this.GenerateNewProjectRuleSetPath(ruleSetRoot, ruleSetFileName);

            // Pend new
            this.sourceControlledFileSystem.QueueFileWrite(newRuleSetPath, () =>
            {
                this.ruleSetSerializer.WriteRuleSetFile(newRuleSet, newRuleSetPath);
                return(true);
            });

            return(newRuleSetPath);
        }
コード例 #3
0
 public CSharpVBBindingOperation(IServiceProvider serviceProvider, Project project, ICSharpVBBindingConfig cSharpVBBindingConfig, ILogger logger)
     : this(serviceProvider, project, cSharpVBBindingConfig, new FileSystem(), new AdditionalFileConflictChecker(), new RuleSetReferenceChecker(serviceProvider, logger))
 {
 }