internal /*for testing purposes*/ SonarAnalyzerManager(IServiceProvider serviceProvider, Workspace workspace,
                                                               ISolutionAnalysisRequester solutionAnalysisRequester)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

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

            this.workspace = workspace;
            this.activeSolutionBoundTracker = serviceProvider.GetMefService <IActiveSolutionBoundTracker>();

            if (this.activeSolutionBoundTracker == null)
            {
                Debug.Fail($"Could not get {nameof(IActiveSolutionBoundTracker)}");
            }

            this.solutionAnalysisRequester = solutionAnalysisRequester;
            this.activeSolutionBoundTracker.SolutionBindingChanged += this.ActiveSolutionBoundTracker_SolutionBindingChanged;

            SonarAnalysisContext.ShouldAnalysisBeDisabled =
                tree => ShouldAnalysisBeDisabledOnTree(tree);
        }
        public SonarQubeIssuesProvider(ISonarQubeService sonarQubeService,
                                       IActiveSolutionBoundTracker solutionBoundTracker,
                                       ITimerFactory timerFactory)
        {
            if (sonarQubeService == null)
            {
                throw new ArgumentNullException(nameof(sonarQubeService));
            }
            if (solutionBoundTracker == null)
            {
                throw new ArgumentNullException(nameof(solutionBoundTracker));
            }
            if (timerFactory == null)
            {
                throw new ArgumentNullException(nameof(timerFactory));
            }

            this.sonarQubeService    = sonarQubeService;
            this.solutionBoundTacker = solutionBoundTracker;
            this.solutionBoundTacker.SolutionBindingChanged += OnSolutionBoundChanged;

            refreshTimer           = timerFactory.Create();
            refreshTimer.AutoReset = true;
            refreshTimer.Interval  = MillisecondsToWaitBetweenRefresh;
            refreshTimer.Elapsed  += OnRefreshTimerElapsed;

            if (this.solutionBoundTacker.IsActiveSolutionBound)
            {
                SynchronizeSuppressedIssues();
                refreshTimer.Start();
            }
        }
 public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker, ITelemetryDataRepository telemetryRepository,
                         ILogger logger)
     : this(solutionBindingTracker, telemetryRepository, logger,
            new TelemetryClient(), new TelemetryTimer(telemetryRepository, new TimerFactory()),
            new KnownUIContextsWrapper(), DefaultCurrentTimeProvider.Instance)
 {
 }
        internal /*for testing purposes*/ SonarAnalyzerManager(IServiceProvider serviceProvider, Workspace workspace,
            ISolutionAnalysisRequester solutionAnalysisRequester)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

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

            this.workspace = workspace;
            this.activeSolutionBoundTracker = serviceProvider.GetMefService<IActiveSolutionBoundTracker>();

            if (this.activeSolutionBoundTracker == null)
            {
                Debug.Fail($"Could not get {nameof(IActiveSolutionBoundTracker)}");
            }

            this.solutionAnalysisRequester = solutionAnalysisRequester;
            this.activeSolutionBoundTracker.SolutionBindingChanged += this.ActiveSolutionBoundTracker_SolutionBindingChanged;

            SonarAnalysisContext.ShouldAnalysisBeDisabled =
                tree => ShouldAnalysisBeDisabledOnTree(tree);
        }
예제 #5
0
        public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker, ITelemetryDataRepository telemetryRepository, IVsVersionProvider vsVersionProvider,
                                ILogger logger, ITelemetryClient telemetryClient, ITelemetryTimer telemetryTimer, IKnownUIContexts knownUIContexts,
                                ICurrentTimeProvider currentTimeProvider)
        {
            this.solutionBindingTracker = solutionBindingTracker;
            this.telemetryRepository    = telemetryRepository;
            this.logger              = logger;
            this.telemetryClient     = telemetryClient;
            this.telemetryTimer      = telemetryTimer;
            this.knownUIContexts     = knownUIContexts;
            this.currentTimeProvider = currentTimeProvider;

            vsVersion = vsVersionProvider.Version;

            if (this.telemetryRepository.Data.InstallationDate == DateTimeOffset.MinValue)
            {
                this.telemetryRepository.Data.InstallationDate = currentTimeProvider.Now;
                this.telemetryRepository.Save();
            }

            if (IsAnonymousDataShared)
            {
                EnableAllEvents();
            }
        }
        public TaintIssuesBindingMonitor(IActiveSolutionBoundTracker activeSolutionBoundTracker, ITaintIssuesSynchronizer taintIssuesSynchronizer)
        {
            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.taintIssuesSynchronizer    = taintIssuesSynchronizer;

            activeSolutionBoundTracker.SolutionBindingChanged += ActiveSolutionBoundTracker_SolutionBindingChanged;
            activeSolutionBoundTracker.SolutionBindingUpdated += ActiveSolutionBoundTracker_SolutionBindingUpdated;
        }
        public CFamilyRuleConfigProvider(IHost host, IActiveSolutionBoundTracker activeSolutionBoundTracker, IUserSettingsProvider userSettingsProvider,
                                         ILogger logger, ICFamilyRulesConfigProvider sonarWayProvider, IFileSystem fileSystem)
        {
            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.userSettingsProvider       = userSettingsProvider;
            this.logger = logger;

            this.sonarWayProvider = sonarWayProvider;
            this.serializer       = new RulesSettingsSerializer(fileSystem, logger);

            this.effectiveConfigCalculator = new EffectiveRulesConfigCalculator(logger);
        }
예제 #8
0
        public SuppressionManager(IServiceProvider serviceProvider, ITimerFactory timerFactory)
        {
            this.serviceProvider = serviceProvider;

            this.activeSolutionBoundTracker = serviceProvider.GetMefService <IActiveSolutionBoundTracker>();
            this.activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;

            this.sonarQubeService = serviceProvider.GetMefService <ISonarQubeService>();

            this.timerFactory = timerFactory;

            RefreshSuppresionHandling();
        }
        public AnalysisConfigMonitor(IAnalysisRequester analysisRequester,
                                     IUserSettingsProvider userSettingsProvider,             // reports changes to user settings.json
                                     IActiveSolutionBoundTracker activeSolutionBoundTracker, // reports changes to connected mode
                                     ILogger logger)
        {
            this.analysisRequester          = analysisRequester;
            this.userSettingsProvider       = userSettingsProvider;
            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.logger = logger;

            userSettingsProvider.SettingsChanged += OnUserSettingsChanged;
            activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;
            activeSolutionBoundTracker.SolutionBindingUpdated += OnSolutionBindingUpdated;
        }
        internal SuppressedIssuesProvider(IActiveSolutionBoundTracker activeSolutionBoundTracker,
                                          CreateProviderFunc createProviderFunc)
        {
            this.createProviderFunc = createProviderFunc ??
                                      throw new ArgumentNullException(nameof(createProviderFunc));

            this.activeSolutionBoundTracker = activeSolutionBoundTracker ??
                                              throw new ArgumentNullException(nameof(activeSolutionBoundTracker));

            this.activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;
            this.activeSolutionBoundTracker.SolutionBindingUpdated += OnSolutionBindingUpdated;

            Refresh(activeSolutionBoundTracker.CurrentConfiguration);
        }
예제 #11
0
        public AnalysisConfigMonitor(IAnalysisRequester analysisRequester,
                                     IUserSettingsProvider userSettingsProvider,             // reports changes to user settings.json
                                     IActiveSolutionBoundTracker activeSolutionBoundTracker, // reports changes to connected mode
                                     ISuppressedIssuesMonitor suppressedIssuesMonitor,
                                     ILogger logger)
        {
            this.analysisRequester          = analysisRequester;
            this.userSettingsProvider       = userSettingsProvider;
            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.suppressedIssuesMonitor    = suppressedIssuesMonitor;
            this.logger = logger;

            userSettingsProvider.SettingsChanged += OnUserSettingsChanged;
            suppressedIssuesMonitor.SuppressionsUpdateRequested += OnSuppressionsUpdated;
        }
예제 #12
0
        public CFamilyRuleConfigProvider(IHost host, IActiveSolutionBoundTracker activeSolutionBoundTracker, IUserSettingsProvider userSettingsProvider,
                                         ILogger logger, ICFamilyRulesConfigProvider sonarWayProvider, IFileSystem fileSystem)
        {
            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.userSettingsProvider       = userSettingsProvider;
            this.logger = logger;

            solutionInfoProvider = host.GetService <ISolutionRuleSetsInformationProvider>();
            solutionInfoProvider.AssertLocalServiceIsNotNull();

            this.sonarWayProvider = sonarWayProvider;
            this.serializer       = new RulesSettingsSerializer(fileSystem, logger);

            this.effectiveConfigCalculator = new EffectiveRulesConfigCalculator(logger);
        }
        protected override void Initialize()
        {
            AddOptionKey(NotificationDataKey);
            base.Initialize();

            var sonarqubeService = this.GetMefService <ISonarQubeService>();

            notifications = new SonarQubeNotificationService(sonarqubeService,
                                                             new NotificationIndicatorViewModel(), new TimerWrapper {
                Interval = 60000
            }, output);

            activeSolutionBoundTracker = this.GetMefService <IActiveSolutionBoundTracker>();
            activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;
        }
        public SuppressionManager(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            this.serviceProvider = serviceProvider;

            this.activeSolutionBoundTracker = serviceProvider.GetMefService <IActiveSolutionBoundTracker>();
            this.activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;

            this.sonarLintOutput = serviceProvider.GetMefService <ISonarLintOutput>();

            RefreshSuppresionHandling();
        }
        public SonarAnalyzerManager(IActiveSolutionBoundTracker activeSolutionBoundTracker, ISonarQubeService sonarQubeService,
                                    Workspace workspace, IVsSolution vsSolution, ILogger logger)
        {
            if (activeSolutionBoundTracker == null)
            {
                throw new ArgumentNullException(nameof(activeSolutionBoundTracker));
            }

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

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

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

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

            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.sonarQubeService           = sonarQubeService;
            this.workspace  = workspace;
            this.vsSolution = vsSolution;
            this.logger     = logger;
            this.activeSolutionBoundTracker = activeSolutionBoundTracker;

            // Saving previous state so that SonarLint doesn't have to know what's the default state in SonarAnalyzer
            this.previousShouldRegisterContextAction   = SonarAnalysisContext.ShouldRegisterContextAction;
            this.previousShouldExecuteRegisteredAction = SonarAnalysisContext.ShouldExecuteRegisteredAction;
            this.previousShouldDiagnosticBeReported    = SonarAnalysisContext.ShouldDiagnosticBeReported;
            this.previousReportDiagnostic = SonarAnalysisContext.ReportDiagnostic;

            activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;
            activeSolutionBoundTracker.SolutionBindingUpdated += OnSolutionBindingUpdated;

            RefreshWorkflow(this.activeSolutionBoundTracker.CurrentConfiguration);
        }
예제 #16
0
        public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker, ITelemetryDataRepository telemetryRepository,
                                ILogger logger, ITelemetryClient telemetryClient, ITelemetryTimer telemetryTimer, IKnownUIContexts knownUIContexts)
        {
            if (solutionBindingTracker == null)
            {
                throw new ArgumentNullException(nameof(solutionBindingTracker));
            }
            if (telemetryRepository == null)
            {
                throw new ArgumentNullException(nameof(telemetryRepository));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (telemetryClient == null)
            {
                throw new ArgumentNullException(nameof(telemetryClient));
            }
            if (telemetryTimer == null)
            {
                throw new ArgumentNullException(nameof(telemetryTimer));
            }
            if (knownUIContexts == null)
            {
                throw new ArgumentNullException(nameof(knownUIContexts));
            }

            this.solutionBindingTracker = solutionBindingTracker;
            this.telemetryClient        = telemetryClient;
            this.logger              = logger;
            this.telemetryTimer      = telemetryTimer;
            this.telemetryRepository = telemetryRepository;
            this.knownUIContexts     = knownUIContexts;

            if (this.telemetryRepository.Data.InstallationDate == DateTimeOffset.MinValue)
            {
                this.telemetryRepository.Data.InstallationDate = DateTimeOffset.Now; // TODO: Use some mockable clock
                this.telemetryRepository.Save();
            }

            if (IsAnonymousDataShared)
            {
                EnableAllEvents();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DisableRuleCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        /// <param name="menuCommandService">Command service to add command to, not null.</param>
        internal /* for testing */ DisableRuleCommand(IMenuCommandService menuCommandService, IErrorList errorList,
                                                      IUserSettingsProvider userSettingsProvider, IActiveSolutionBoundTracker activeSolutionBoundTracker, ILogger logger)
        {
            if (menuCommandService == null)
            {
                throw new ArgumentNullException(nameof(menuCommandService));
            }
            this.errorList                  = errorList ?? throw new ArgumentNullException(nameof(errorList));
            this.userSettingsProvider       = userSettingsProvider ?? throw new ArgumentNullException(nameof(userSettingsProvider));
            this.activeSolutionBoundTracker = activeSolutionBoundTracker ?? throw new ArgumentNullException(nameof(activeSolutionBoundTracker));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            var menuCommandID = new CommandID(CommandSet, CommandId);

            menuItem = new OleMenuCommand(Execute, null, QueryStatus, menuCommandID);
            menuCommandService.AddCommand(menuItem);
        }
        public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker,
                                ITelemetryDataRepository telemetryRepository, ITelemetryClient telemetryClient)
        {
            if (solutionBindingTracker == null)
            {
                throw new ArgumentNullException(nameof(solutionBindingTracker));
            }
            if (telemetryRepository == null)
            {
                throw new ArgumentNullException(nameof(telemetryRepository));
            }
            if (telemetryClient == null)
            {
                throw new ArgumentNullException(nameof(telemetryClient));
            }

            this.solutionBindingTracker = solutionBindingTracker;
            this.telemetryClient        = telemetryClient;
            this.telemetryRepository    = telemetryRepository;

            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "msenv.dll");

            visualStudioVersion = File.Exists(path)
                ? FileVersionInfo.GetVersionInfo(path).ProductVersion
                : string.Empty;

            if (this.telemetryRepository.Data.InstallationDate == DateTime.MinValue)
            {
                this.telemetryRepository.Data.InstallationDate = DateTime.Now;
                this.telemetryRepository.Save();
            }

            this.tryUploadDataTimer = new Timer {
                Interval = MillisecondsToWaitBetweenUpload, AutoReset = true
            };
            this.firstCallDelayer = new Timer(DelayBeforeFirstUpload)
            {
                AutoReset = false
            };

            if (IsAnonymousDataShared)
            {
                EnableAllEvents();
            }
        }
예제 #19
0
        internal /* for testing purposes */ DeprecatedSonarRuleSetManager(IActiveSolutionBoundTracker activeSolutionBoundTracker,
                                                                          IActiveSolutionTracker activeSolutionTracker, IProjectSystemHelper projectSystemHelper,
                                                                          ISolutionRuleSetsInformationProvider ruleSetProvider, ILogger logger)
        {
            if (activeSolutionBoundTracker == null)
            {
                throw new ArgumentNullException(nameof(activeSolutionBoundTracker));
            }

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

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

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

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

            this.activeSolutionBoundTracker = activeSolutionBoundTracker;
            this.activeSolutionTracker      = activeSolutionTracker;
            this.projectSystemHelper        = projectSystemHelper;
            this.ruleSetProvider            = ruleSetProvider;
            this.logger = logger;

            this.activeSolutionBoundTracker.SolutionBindingChanged += OnSolutionBindingChanged;
            this.activeSolutionTracker.ActiveSolutionChanged       += OnActiveSolutionChanged;

            if (this.activeSolutionBoundTracker.CurrentConfiguration != null &&
                this.activeSolutionBoundTracker.CurrentConfiguration.Mode != NewConnectedMode.SonarLintMode.LegacyConnected)
            {
                WarnIfAnyProjectHasSonarRuleSet();
            }
        }
예제 #20
0
        private async System.Threading.Tasks.Task InitAsync()
        {
            // Working on background thread...
            Debug.Assert(!ThreadHelper.CheckAccess());

            var sonarqubeService = await this.GetMefServiceAsync <ISonarQubeService>();

            logger = await this.GetMefServiceAsync <ILogger>();

            logger.WriteLine(Resources.Strings.Notifications_Initializing);

            AddOptionKey(NotificationDataKey);

            var telemetryManager = await this.GetMefServiceAsync <IServerNotificationsTelemetryManager>();

            var vsBrowserService = await this.GetMefServiceAsync <IVsBrowserService>();

            notifications = new SonarQubeNotificationService(sonarqubeService,
                                                             new NotificationIndicatorViewModel(telemetryManager, vsBrowserService), new TimerWrapper {
                Interval = 60000
            }, logger);

            // Initialising the UI elements has to be on the main thread
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            SafePerformOpOnUIThread(() =>
            {
                // Creating the tracker might indirectly cause UI-related MEF components to be
                // created, so this needs to be done on the UI thread just in case.
                activeSolutionBoundTracker = this.GetMefService <IActiveSolutionBoundTracker>();

                // A bound solution might already have completed loading. If so, we need to
                // trigger the load of the options from the solution file
                if (activeSolutionBoundTracker.CurrentConfiguration.Mode != SonarLintMode.Standalone)
                {
                    var solutionPersistence = (IVsSolutionPersistence)this.GetService(typeof(SVsSolutionPersistence));
                    solutionPersistence.LoadPackageUserOpts(this, NotificationDataKey);
                }

                PerformUIInitialisation();
                logger.WriteLine(Resources.Strings.Notifications_InitializationComplete);
            });
        }
        public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker,
                                ITelemetryDataRepository telemetryRepository, ITelemetryClient telemetryClient)
        {
            if (solutionBindingTracker == null)
            {
                throw new ArgumentNullException(nameof(solutionBindingTracker));
            }
            if (telemetryRepository == null)
            {
                throw new ArgumentNullException(nameof(telemetryRepository));
            }
            if (telemetryClient == null)
            {
                throw new ArgumentNullException(nameof(telemetryClient));
            }

            this.solutionBindingTracker = solutionBindingTracker;
            this.telemetryClient        = telemetryClient;
            this.telemetryRepository    = telemetryRepository;

            if (this.telemetryRepository.Data.InstallationDate == DateTime.MinValue)
            {
                this.telemetryRepository.Data.InstallationDate = DateTime.Now;
                this.telemetryRepository.Save();
            }

            this.tryUploadDataTimer = new Timer {
                Interval = MillisecondsToWaitBetweenUpload, AutoReset = true
            };
            this.firstCallDelayer = new Timer(DelayBeforeFirstUpload)
            {
                AutoReset = false
            };

            if (IsAnonymousDataShared)
            {
                EnableAllEvents();
            }
        }
        public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker, ITelemetryDataRepository telemetryRepository,
                                ILogger logger, ITelemetryClient telemetryClient, ITelemetryTimer telemetryTimer, IKnownUIContexts knownUIContexts,
                                ICurrentTimeProvider currentTimeProvider)
        {
            this.solutionBindingTracker = solutionBindingTracker ?? throw new ArgumentNullException(nameof(solutionBindingTracker));
            this.telemetryRepository    = telemetryRepository ?? throw new ArgumentNullException(nameof(telemetryRepository));
            this.logger              = logger ?? throw new ArgumentNullException(nameof(logger));
            this.telemetryClient     = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
            this.telemetryTimer      = telemetryTimer ?? throw new ArgumentNullException(nameof(telemetryTimer));
            this.knownUIContexts     = knownUIContexts ?? throw new ArgumentNullException(nameof(knownUIContexts));
            this.currentTimeProvider = currentTimeProvider ?? throw new ArgumentNullException(nameof(currentTimeProvider));

            if (this.telemetryRepository.Data.InstallationDate == DateTimeOffset.MinValue)
            {
                this.telemetryRepository.Data.InstallationDate = currentTimeProvider.Now;
                this.telemetryRepository.Save();
            }

            if (IsAnonymousDataShared)
            {
                EnableAllEvents();
            }
        }
예제 #23
0
        private static MenuCommand CreateDisableRuleMenuCommand(IErrorList errorList, IUserSettingsProvider userSettingsProvider, IActiveSolutionBoundTracker solutionTracker, ILogger logger)
        {
            var dummyMenuService = new DummyMenuCommandService();

            new DisableRuleCommand(dummyMenuService, errorList, userSettingsProvider, solutionTracker, logger);

            dummyMenuService.AddedMenuCommands.Count.Should().Be(1);
            return(dummyMenuService.AddedMenuCommands[0]);
        }
예제 #24
0
 public CFamilyRuleConfigProvider(IHost host, IActiveSolutionBoundTracker activeSolutionBoundTracker, IUserSettingsProvider userSettingsProvider, ILogger logger)
     : this(host, activeSolutionBoundTracker, userSettingsProvider, logger,
            new CFamilySonarWayRulesConfigProvider(CFamilyShared.CFamilyFilesDirectory),
            new FileSystem())
 {
 }
예제 #25
0
 public TelemetryManager(IActiveSolutionBoundTracker solutionBindingTracker, ITelemetryDataRepository telemetryRepository)
     : this(solutionBindingTracker, telemetryRepository, new TelemetryClient(),
            new TelemetryTimer(telemetryRepository, new TimerFactory()), new KnownUIContextsWrapper())
 {
 }
 public SuppressedIssuesProvider(IActiveSolutionBoundTracker activeSolutionBoundTracker,
                                 ISonarQubeService sonarQubeService,
                                 ILogger logger)
     : this(activeSolutionBoundTracker, GetCreateProviderFunc(sonarQubeService, logger))
 {
 }