Exemplo n.º 1
0
        public string WriteSolutionBinding(BoundSonarQubeProject binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            ISourceControlledFileSystem sccFileSystem = this.serviceProvider.GetService <ISourceControlledFileSystem>();

            sccFileSystem.AssertLocalServiceIsNotNull();

            string configFile = this.GetSonarQubeConfigurationFilePath();

            if (string.IsNullOrWhiteSpace(configFile))
            {
                return(null);
            }

            sccFileSystem.QueueFileWrite(configFile, () =>
            {
                if (this.WriteBindingInformation(configFile, binding))
                {
                    this.AddSolutionItemFile(configFile);
                    this.RemoveSolutionItemFile(configFile);
                    return(true);
                }

                return(false);
            });

            return(configFile);
        }
        public bool Write(string configFilePath, BoundSonarQubeProject binding, Predicate <string> onSuccessfulFileWrite)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            if (string.IsNullOrEmpty(configFilePath))
            {
                return(false);
            }

            sccFileSystem.QueueFileWrite(configFilePath, () =>
            {
                if (solutionBindingFileLoader.Save(configFilePath, binding))
                {
                    credentialsLoader.Save(binding.Credentials, binding.ServerUri);

                    return(onSuccessfulFileWrite(configFilePath));
                }

                return(false);
            });

            return(true);
        }
        public string WriteSolutionBinding(BoundSonarQubeProject binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            string configFile = this.GetFullConfigurationFilePath();

            if (string.IsNullOrWhiteSpace(configFile))
            {
                return(null);
            }

            sccFileSystem.QueueFileWrite(configFile, () =>
            {
                if (this.WriteBindingInformation(configFile, binding))
                {
                    return(OnSuccessfulFileWrite(configFile));
                }

                return(false);
            });

            return(configFile);
        }
        private void OnFixConflicts(IEnumerable <ProjectRuleSetConflict> conflicts)
        {
            if (this.OnFixConflictsStatus(conflicts))
            {
                var componentModel = host.GetService <SComponentModel, IComponentModel>();
                TelemetryLoggerAccessor.GetLogger(componentModel)?.ReportEvent(TelemetryEvent.FixConflictsCommandCalled);

                IRuleSetInspector inspector = this.host.GetService <IRuleSetInspector>();
                inspector.AssertLocalServiceIsNotNull();

                ISourceControlledFileSystem sccFileSystem = this.host.GetService <ISourceControlledFileSystem>();
                sccFileSystem.AssertLocalServiceIsNotNull();

                IRuleSetSerializer ruleSetSerializer = this.host.GetService <IRuleSetSerializer>();
                ruleSetSerializer.AssertLocalServiceIsNotNull();

                var fixedConflictsMap = new Dictionary <RuleSetInformation, FixedRuleSetInfo>();
                foreach (RuleSetInformation ruleSetInfo in conflicts.Select(c => c.RuleSetInfo))
                {
                    FixedRuleSetInfo fixInfo = inspector.FixConflictingRules(ruleSetInfo.BaselineFilePath, ruleSetInfo.RuleSetFilePath, ruleSetInfo.RuleSetDirectories);
                    Debug.Assert(fixInfo != null);

                    fixedConflictsMap[ruleSetInfo] = fixInfo;

                    sccFileSystem.QueueFileWrite(fixInfo.FixedRuleSet.FilePath, () =>
                    {
                        ruleSetSerializer.WriteRuleSetFile(fixInfo.FixedRuleSet, fixInfo.FixedRuleSet.FilePath);

                        return(true);
                    });
                }

                this.WriteFixSummaryToOutputWindow(fixedConflictsMap);

                if (sccFileSystem.WriteQueuedFiles())
                {
                    this.Clear();
                }
                else
                {
                    Debug.Fail("Failed to write one or more of the queued files");
                }
            }
        }