/// <summary> /// The convert violations to local. /// </summary> /// <param name="issueList"> /// The issue list. /// </param> /// <param name="diffReport"> /// The diff report. /// </param> /// <param name="currentResource"> /// The current Resource. /// </param> /// <returns> /// The <see> /// <cref>ObservableCollection</cref> /// </see> /// . /// </returns> public static List<Issue> ConvertOpenIssuesToLocalSource(List<Issue> issueList, ArrayList diffReport, Resource currentResource) { var local = new List<Issue>(); if (issueList != null && issueList.Count > 0) { foreach (var issue in issueList) { if (!issue.Component.EndsWith(currentResource.Lname)) { continue; } if (issue.Status != "OPEN" && issue.Status != "REOPENED" && !string.IsNullOrEmpty(issue.Status)) { continue; } var copyOfViolation = issue.DeepCopy(); var convertedKey = EstimateWhereSonarLineIsUsingSourceDifference(issue.Line, diffReport); if (convertedKey < 0) { continue; } copyOfViolation.Line = convertedKey; local.Add(copyOfViolation); } } return new List<Issue>(local.OrderBy(i => i.Line)); }
public void TesRestOfProperties() { var issue = new Issue(); var connector = new SonarRestService(new JsonSonarConnector()); var projectAsso = new Resource { Key = "proj" }; var model = new ExtensionDataModel(this.service, this.vshelper, null) { AssociatedProjectKey = "proj", CommentData = "comment", SelectedIssue = issue, SonarInfo = "ver", SelectedUser = new User { Login = "******" }, DiagnosticMessage = "MessageData", IssuesInViewLocked = false, DisableEditorTags = false, LastReferenceSource = "source", RestService = connector, ServerAnalysis = ExtensionDataModel.AnalysesType.Off, AssociatedProject = projectAsso, }; Assert.AreEqual("Selected Project: proj", model.AssociatedProjectKey); Assert.AreEqual(issue, model.SelectedIssue); Assert.AreEqual("comment", model.CommentData); Assert.AreEqual("login", model.SelectedUser.Login); Assert.AreEqual("ver", model.SonarInfo); Assert.AreEqual("MessageData", model.DiagnosticMessage); Assert.IsFalse(model.IssuesInViewLocked); Assert.IsFalse(model.DisableEditorTags); Assert.AreEqual("source", model.LastReferenceSource); Assert.AreEqual(connector, model.RestService); Assert.AreEqual(ExtensionDataModel.AnalysesType.Off, model.ServerAnalysis); Assert.AreEqual(projectAsso, model.AssociatedProject); }
public void RunsLocalAnalysisWithDummyFile() { var serviceStub = new Mock<IAnalysisPlugin>(); var optionsStub = new Mock<IPluginsOptions>(); var resource = new Resource() { Lang = "c++" }; var configuration = new ConnectionConfiguration(); serviceStub.Setup(control => control.GetPluginControlOptions(configuration)).Returns(optionsStub.Object); optionsStub.Setup(control => control.GetOptions()).Returns(this.options); var localextension = new CxxLocalExtension(serviceStub.Object, configuration); localextension.LocalAnalysisCompleted += this.AnalysisCompleted; var vsitem = new VsProjectItem(string.Empty, this.fileToAnalyse, string.Empty, string.Empty, string.Empty, string.Empty); var thread = localextension.GetFileAnalyserThread(vsitem, resource, new Profile(), string.Empty, false); thread.Start(); thread.Join(); }
public void UpdateCoverageDataForResourceEmtpyDataTest() { var element = new Resource { Date = new DateTime(2000, 1, 1) }; var source = new SourceCoverage(); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { element }) .Repeat.Once(); this.service.Expect( mp => mp.GetCoverageInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(source); var data = new ExtensionDataModel(this.service, this.vshelper, null); Assert.AreEqual(source, data.UpdateCoverageDataForResource("resource", false)); }
/// <summary> /// The get plugin control options. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="project"> /// The project. /// </param> /// <returns> /// The <see cref="IPluginsOptions"/>. /// </returns> public IPluginsOptions GetPluginControlOptions(ConnectionConfiguration configuration, Resource project) { return null; }
/// <summary> /// The get issues for resource from list. /// </summary> /// <param name="resource"> /// The resource. /// </param> /// <param name="list"> /// The list. /// </param> /// <returns> /// The /// <see> /// <cref>List</cref> /// </see> /// . /// </returns> public static List<Issue> GetIssuesForResourceFromList(Resource resource, IEnumerable<Issue> list) { return list.Where(issue => issue.Component.Equals(resource.Key)).ToList(); }
/// <summary> /// The get local analysis extension. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="project"> /// The project. /// </param> /// <param name="sonarVersion"> /// The sonar version. /// </param> /// <returns> /// The <see cref="ILocalAnalyserExtension"/>. /// </returns> public ILocalAnalyserExtension GetLocalAnalysisExtension(ConnectionConfiguration configuration, Resource project, double sonarVersion) { return null; }
/// <summary> /// The set all options for plugin option in application data. /// </summary> /// <param name="pluginKey"> /// The plugin key. /// </param> /// <param name="project"> /// The project. /// </param> /// <param name="options"> /// The options. /// </param> public void WriteAllOptionsForPluginOptionInApplicationData(string pluginKey, Resource project, Dictionary<string, string> options) { this.DeleteOptionsForPlugin(pluginKey, project); foreach (var option in options) { this.WriteOptionInApplicationData(pluginKey, option.Key, option.Value); } }
/// <summary> /// The update configuration. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="project"> /// The project. /// </param> /// <param name="vsenvironmentHelper"> /// The vs environment helper. /// </param> public void UpdateConfiguration(ISonarConfiguration configuration, Resource project, IVsEnvironmentHelper vsenvironmentHelper) { this.conf = configuration; if (this.conf != null) { this.Login(); } this.SelectMainResource(project); this.vshelper = vsenvironmentHelper; }
/// <summary> /// The test window. /// </summary> public void TestWindow() { var mocks = new MockRepository(); var mockHttpReq = mocks.Stub<IHttpSonarConnector>(); var mockVsHelpers = mocks.Stub<IVsEnvironmentHelper>(); var config = new ConnectionConfiguration("serveraddr", "login", "password"); // set expectations using (mocks.Record()) { SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/issues/search?components=resource")) .Return(File.ReadAllText("TestData/issuessearchbycomponent.txt")); SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/users/search")).Return(File.ReadAllText("TestData/userList.txt")); } ISonarRestService service = new SonarRestService(mockHttpReq); var issues = service.GetIssuesInResource(config, "resource"); var associatedProject = new Resource { Key = "core:Common" }; this.model = new ExtensionDataModel(service, mockVsHelpers, associatedProject); var t = new Thread(this.Threadprc); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); }
/// <summary> /// The get plugin to run resource. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="project"> /// The project. /// </param> /// <returns> /// The <see cref="IPlugin"/>. /// </returns> public IPlugin GetPluginToRunResource(ConnectionConfiguration configuration, Resource project) { if (this.loadedPlugins == null) { return null; } var pluginsToUse = this.loadedPlugins.Where(plugin => plugin.IsSupported(configuration, project)).ToList(); return this.PickPluginFromMultipleSupportedPlugins(new ReadOnlyCollection<IPlugin>(pluginsToUse)); }
public void EnableCoverageInEditor() { var data = new ExtensionDataModel(this.service, this.vshelper, null); var sourceCoverage = new SourceCoverage(); var source = new Source { Lines = new List<Line> { new Line { Id = 1, Val = "#include bal" }, new Line { Id = 2, Val = "#include bals" } } }; var element = new Resource { Date = new DateTime(2000, 1, 1) }; this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { element }) .Repeat.Twice(); this.service.Expect( mp => mp.GetSourceForFileResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(source); this.service.Expect( mp => mp.GetCoverageInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(sourceCoverage); element.Key = "resource"; data.ResourceInEditor = element; data.EnableCoverageInEditor = true; Assert.IsTrue(data.EnableCoverageInEditor); Assert.AreEqual(sourceCoverage, data.CoverageInEditor); Assert.AreEqual(element, data.ResourceInEditor); Assert.AreEqual(0, data.CoverageInEditor.BranchHits.Count); Assert.AreEqual(0, data.CoverageInEditor.LinesHits.Count); }
public void UpdateCoverageDataForResourceWithNewDateDataTest() { var element = new Resource(); var newResource = new Resource { Date = DateTime.Now }; var source1 = new SourceCoverage(); source1.SetLineCoverageData("1=0;2=3;2=3"); source1.SetBranchCoverageData("1=0;2=3;2=3", "1=0;2=3;2=3"); var source2 = new SourceCoverage(); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { element }) .Repeat.Once(); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { newResource }); this.service.Expect( mp => mp.GetCoverageInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(source1) .Repeat.Once(); this.service.Expect( mp => mp.GetCoverageInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(source2); var data = new ExtensionDataModel(this.service, this.vshelper, null); data.EnableCoverageInEditor = true; Assert.AreEqual(source1, data.UpdateCoverageDataForResource("resource", false)); Assert.AreEqual(source2, data.UpdateCoverageDataForResource("resource", false)); }
/// <summary> /// The is supported. /// </summary> /// <param name="resource"> /// The resource. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool IsSupported(Resource resource) { return resource != null && resource.Lang.Equals("c++"); }
/// <summary> /// The is supported. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="resource"> /// The resource. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool IsSupported(ISonarConfiguration configuration, Resource resource) { return resource != null && resource.Lang.Equals("c++"); }
/// <summary> /// The update data from server. /// </summary> /// <param name="resource"> /// The resource. /// </param> private void UpdateDataFromServer(Resource resource) { if (this.localEditorCache.IsDataUpdated(resource)) { return; } SourceCoverage newCoverage = this.restService.GetCoverageInResource(this.UserConfiguration, this.resourceInEditor.Key); string newSource = VsSonarUtils.GetLinesFromSource(this.restService.GetSourceForFileResource(this.UserConfiguration, this.resourceInEditor.Key), "\r\n"); List<Issue> newIssues = this.restService.GetIssuesInResource(this.UserConfiguration, this.resourceInEditor.Key); this.localEditorCache.UpdateResourceData(this.ResourceInEditor, newCoverage, newIssues, newSource); }
/// <summary> /// Initializes a new instance of the <see cref="ExtensionDataModel"/> class. /// </summary> /// <param name="restService"> /// The rest Service. /// </param> /// <param name="vsenvironmenthelper"> /// The vsenvironmenthelper. /// </param> /// <param name="associatedProj"> /// The associated Proj. /// </param> public ExtensionDataModel(ISonarRestService restService, IVsEnvironmentHelper vsenvironmenthelper, Resource associatedProj) { this.RestService = restService; this.Vsenvironmenthelper = vsenvironmenthelper; // commands this.InitCommanding(); this.UserTextControlsHeight = new GridLength(0); this.UserControlsHeight = new GridLength(0); this.RestoreUserSettingsInIssuesDataGrid(); this.RestoreUserFilteringOptions(); this.AnalysisTrigger = false; ConnectionConfiguration conf = this.UserConfiguration; if (conf == null) { return; } // start some data List<User> usortedList = restService.GetUserList(conf); if (usortedList != null && usortedList.Count > 0) { this.UsersList = new List<User>(usortedList.OrderBy(i => i.Login)); } List<Resource> projects = restService.GetProjectsList(conf); if (projects != null && projects.Count > 0) { this.ProjectResources = new List<Resource>(projects.OrderBy(i => i.Name)); } this.AssociatedProject = associatedProj; var plugins = this.PluginControl.GetPlugins(); if (plugins != null) { this.ExtensionOptionsData = new ExtensionOptionsModel(this.PluginControl, this); this.LocalAnalyserModule = new SonarLocalAnalyser.SonarLocalAnalyser(new List<IPlugin>(plugins), this.RestService, this.vsenvironmenthelper); this.LocalAnalyserModule.StdOutEvent += this.UpdateOutputMessagesFromPlugin; this.LocalAnalyserModule.LocalAnalysisCompleted += this.UpdateLocalIssues; this.ExtensionOptionsData.Vsenvironmenthelper = this.Vsenvironmenthelper; this.ExtensionOptionsData.ResetUserData(); foreach (var plugin in plugins) { var configuration = ConnectionConfigurationHelpers.GetConnectionConfiguration(this.Vsenvironmenthelper); var controloption = plugin.GetPluginControlOptions(configuration); if (controloption == null) { continue; } var pluginKey = plugin.GetKey(ConnectionConfigurationHelpers.GetConnectionConfiguration(this.Vsenvironmenthelper)); var options = this.Vsenvironmenthelper.ReadAllAvailableOptionsInSettings(pluginKey); controloption.SetOptions(options); } } }
/// <summary> /// The perform solution not open association. /// </summary> /// <param name="resource"> /// The resource. /// </param> public void PerformSolutionNotOpenAssociation(Resource resource) { if (resource != null) { this.AssociatedProjectKey = resource.Key; } else { this.AssociatedProjectKey = string.Empty; } this.associatedProject = resource; this.OnPropertyChanged("AssociatedProject"); }
public IPluginsOptions GetPluginControlOptions(Resource associatedProject) { throw new System.NotImplementedException(); }
public void UpdateIssueDataForResourceWithNewDateDataTestWithCache() { var element = new Resource(); var newResource = new Resource { Date = DateTime.Now }; var newResource1 = new Resource { Date = DateTime.Now }; this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { element }) .Repeat.Once(); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { newResource }); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource1"))) .Return(new List<Resource> { newResource1 }); this.service.Expect( mp => mp.GetIssuesInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"), Arg<bool>.Is.Anything)) .Return(new List<Issue> { new Issue() }) .Repeat.Once(); this.service.Expect( mp => mp.GetIssuesInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"), Arg<bool>.Is.Anything)) .Return(new List<Issue> { new Issue(), new Issue() }); this.service.Expect( mp => mp.GetIssuesInResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource1"), Arg<bool>.Is.Anything)) .Return(new List<Issue> { new Issue() }); var data = new ExtensionDataModel(this.service, this.vshelper, null); Assert.AreEqual(1, data.UpdateIssueDataForResource("resource").Count); Assert.AreEqual(2, data.UpdateIssueDataForResource("resource").Count); Assert.AreEqual(2, data.UpdateIssueDataForResource("resource").Count); Assert.AreEqual(1, data.UpdateIssueDataForResource("resource1").Count); Assert.AreEqual("resource1", data.SelectedCachedElement); data.SelectedCachedElement = "resource1"; Assert.AreEqual(1, data.Issues.Count); data.SelectedCachedElement = "resource"; Assert.AreEqual(2, data.Issues.Count); Assert.AreEqual("resource", data.SelectedCachedElement); }
/// <summary> /// The is supported. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="project"> /// The project. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool IsSupported(ConnectionConfiguration configuration, Resource project) { return true; }
public void UpdateSourceDataForResourceWithNewDateDataTest() { var element = new Resource(); var newResource = new Resource { Date = DateTime.Now }; var source1 = new Source(); var source2 = new Source(); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { element }) .Repeat.Once(); this.service.Expect( mp => mp.GetResourcesData(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(new List<Resource> { newResource }); this.service.Expect( mp => mp.GetSourceForFileResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(source1) .Repeat.Once(); this.service.Expect( mp => mp.GetSourceForFileResource(Arg<ConnectionConfiguration>.Is.Anything, Arg<string>.Is.Equal("resource"))) .Return(source2); var data = new ExtensionDataModel(this.service, this.vshelper, null); Assert.AreEqual(source1, data.UpdateSourceDataForResource("resource", false)); Assert.AreEqual(source2, data.UpdateSourceDataForResource("resource", false)); }
/// <summary> /// The get user control options. /// </summary> /// <param name="projectIn"> /// The project. /// </param> /// <returns> /// The <see cref="UserControl"/>. /// </returns> public UserControl GetUserControlOptions(Resource projectIn) { this.Project = projectIn; return this.cxxControl ?? (this.cxxControl = new CxxUserControl(this)); }
/// <summary> /// Initializes a new instance of the <see cref="ExtensionDataModel"/> class. /// </summary> /// <param name="restService"> /// The rest Service. /// </param> /// <param name="vsenvironmenthelper"> /// The vsenvironmenthelper. /// </param> /// <param name="associatedProj"> /// The associated Proj. /// </param> public ExtensionDataModel( ISonarRestService restService, IVsEnvironmentHelper vsenvironmenthelper, Resource associatedProj) { this.RestService = restService; this.Vsenvironmenthelper = vsenvironmenthelper; // commands this.InitCommanding(); // cache data this.cachedIssuesList = new Dictionary<string, List<Issue>>(); this.cachedIssuesListObs = new List<string>(); this.allSourceData = new Dictionary<string, Source>(); this.allSourceCoverageData = new Dictionary<string, SourceCoverage>(); this.allResourceData = new Dictionary<string, Resource>(); // start some data var usortedList = restService.GetUserList(this.UserConfiguration); if (usortedList != null && usortedList.Count > 0) { this.UsersList = new List<User>(usortedList.OrderBy(i => i.Login)); } var projects = restService.GetProjectsList(this.UserConfiguration); if (projects != null && projects.Count > 0) { this.ProjectResources = new List<Resource>(projects.OrderBy(i => i.Name)); } this.AssociatedProject = associatedProj; this.UserTextControlsHeight = new GridLength(0); this.UserControlsHeight = new GridLength(0); this.IssuesFilterWidth = new GridLength(0); this.ServerAnalysis = AnalysesType.Off; this.RestoreUserSettingsInIssuesDataGrid(); this.RestoreUserFilteringOptions(); }
/// <summary> /// The delete options for plugin. /// </summary> /// <param name="pluginKey"> /// The plugin key. /// </param> /// <param name="project"> /// The project. /// </param> public void DeleteOptionsForPlugin(string pluginKey, Resource project) { if (project == null || string.IsNullOrEmpty(pluginKey)) { return; } IEnumerable<string> content = new List<string>(); var contentWrite = string.Empty; if (File.Exists(this.ApplicationDataUserSettingsFile)) { content = File.ReadLines(this.ApplicationDataUserSettingsFile); } else { Directory.CreateDirectory(Directory.GetParent(this.ApplicationDataUserSettingsFile).ToString()); using (File.Create(this.ApplicationDataUserSettingsFile)) { } } contentWrite = content.Where(line => !line.StartsWith(pluginKey + "=" + project.Key + ".")).Aggregate(contentWrite, (current, line) => current + (line + "\r\n")); using (var writer = new StreamWriter(this.ApplicationDataUserSettingsFile)) { writer.Write(contentWrite); } }
public ILocalAnalyserExtension GetLocalAnalysisExtension(Resource project) { throw new System.NotImplementedException(); }
/// <summary> /// The select main resource. /// </summary> /// <param name="project"> /// The project. /// </param> public void SelectMainResource(Resource project) { if (project == null) { return; } this.SelectedFirstProject = project.Lname + " - " + project.Lang; }
public ILocalAnalyserExtension GetLocalAnalysisExtension(ConnectionConfiguration configuration, Resource project) { throw new System.NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="ProjectFile"/> class. /// </summary> /// <param name="resource"> /// The resource. /// </param> public ProjectFile(Resource resource) { this.Resource = resource; }
/// <summary> /// Initializes a new instance of the <see cref="EditorData"/> class. /// </summary> /// <param name="resource"> /// The resource. /// </param> public EditorData(Resource resource) { this.CoverageData = new Dictionary<int, CoverageElement>(); this.Issues = new List<Issue>(); this.Resource = resource; }