/// <summary> /// Installs the tools. /// </summary> /// <param name="cxxwrapper">The cxx wrapper.</param> private void InstallTools(string cxxwrapper) { bool canInstall = QuestionUser.GetInput("this will install any third party tools using Chocolatey, elevated rights will be requested. Do you want to proceed?"); if (canInstall) { using (var process = new Process()) { process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = cxxwrapper; process.StartInfo.Arguments = "/i"; process.Start(); process.WaitForExit(); } } else { MessageDisplayBox.DisplayMessage( "External tools have not been installed.", "Tools will be installed when the wrapper for preview and full analysis runs. " + "If you dont have permissions, the recommended way is to define tools paths in a configuration file in your home folder.", helpurl: "https://github.com/jmecsoftware/sonar-cxx-msbuild-tasks#using-the-wrapper-behind-proxy-or-were-admin-rights-are-not-available"); } }
/// <summary> /// Called when [source control command]. /// </summary> private void OnSetExclusionsMenuCommand() { if (this.assignProject == null) { MessageDisplayBox.DisplayMessage("Effort can only be adjusted if project is associated"); return; } if (this.model.SelectedItems == null || this.model.SelectedItems.Count == 0) { return; } try { Resource projectToUse = SetExclusionsMenu.GetMainProject(this.assignProject, this.availableProjects); if (this.CommandText.Equals("adjust effort")) { this.AdjustEffortForRule(); } } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "SetSqaleMenu", Data = "Failed to perform operation: " + ex.Message }); this.manager.ReportException(ex); } }
/// <summary> /// Called when [source control command]. /// </summary> private void OnShowMoreInfoCommand() { if (this.model.SelectedItems == null || this.model.SelectedItems.Count == 0) { return; } try { if (this.CommandText.Equals("More Info")) { if (!string.IsNullOrEmpty(this.model.SelectedIssue.HelpUrl)) { this.vshelper.NavigateToResource(this.model.SelectedIssue.HelpUrl); } else { MessageDisplayBox.DisplayMessage("Issue does not have help URL defined."); } } } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "MoreInfoMenu", Data = "Failed to perform operation: " + ex.Message }); this.manager.ReportException(ex); } }
/// <summary> /// Called when [automatic import local diagnostics command]. /// </summary> private void OnAutoImportLocalDiagnosticsCommand() { if (!this.model.VerifyExistenceOfRoslynPlugin()) { MessageDisplayBox.DisplayMessage( "Adding new diagnostics analyzers requires Roslyn plugin installed in your SonarQube server. " + "Administer Quality Profiles and Gates and Provision Projects permissions must be available to user.", helpurl: "https://visualstudiogallery.msdn.microsoft.com/7fc312c3-f1ab-49f8-b286-dbf7fff37305"); return; } if (this.model.Profile == null) { MessageDisplayBox.DisplayMessage( "Auto detection only available when a solution is associated with a sonar project."); return; } var result = this.model.AutoDetectInstalledAnalysers(); if (string.IsNullOrEmpty(result)) { MessageDisplayBox.DisplayMessage( "Rules have been created in SonarQube. Please use tools > sqale editor to enabled them or use the Roslyn Plugin to automatically sync those against your project. ", helpurl: "https://visualstudiogallery.msdn.microsoft.com/7fc312c3-f1ab-49f8-b286-dbf7fff37305"); } else { MessageDisplayBox.DisplayMessage(result); } }
/// <summary> /// Called when [install new DLL command]. /// </summary> private void OnInstallNewDllCommand() { using (var filedialog = new OpenFileDialog { InitialDirectory = this.model.SourceDir, Filter = @"dlls|*.dll", Title = "Select dll available in project folder." }) { DialogResult result = filedialog.ShowDialog(); if (result == DialogResult.OK) { if (!File.Exists(filedialog.FileName)) { UserExceptionMessageBox.ShowException("Error Choosing File, File Does not exits", null); return; } if (!this.model.VerifyExistenceOfRoslynPlugin()) { MessageDisplayBox.DisplayMessage( "Adding new diagnostics analyzers requires Roslyn plugin installed in your SonarQube server." + "Administration rights, Administer Quality Profiles and Gates and Provision Projects permissions must be available to user.", helpurl: "https://visualstudiogallery.msdn.microsoft.com/7fc312c3-f1ab-49f8-b286-dbf7fff37305"); return; } if (this.model.AddNewRoslynPack(filedialog.FileName, true)) { this.SyncDiagInView(); MessageDisplayBox.DisplayMessage( "Rules have been created in SonarQube. Please use tools > sqale editor to enabled them or use the Roslyn Plugin to automatically sync those against your project. ", helpurl: "https://visualstudiogallery.msdn.microsoft.com/7fc312c3-f1ab-49f8-b286-dbf7fff37305"); } } } }
private void OnGetTokenCommand(object obj) { if (string.IsNullOrEmpty(this.ServerAddress)) { MessageDisplayBox.DisplayMessage("Address not defined, please set adress before trying to generate token"); return; } this.visualStudioHelper.NavigateToResource(this.ServerAddress + "/account/security"); }
/// <summary> /// Called when [source control command]. /// </summary> private void OnSourceControlCommand() { if (this.assignProject == null) { MessageDisplayBox.DisplayMessage("Source control only available when a project is associated."); return; } if (this.model.SelectedItems == null || this.model.SelectedItems.Count == 0) { return; } try { if (this.CommandText.Equals("assign to committer")) { var users = this.rest.GetUserList(AuthtenticationHelper.AuthToken); var issues = this.model.SelectedItems; foreach (var issue in issues) { this.AssignIssueToUser(users, issue as Issue); } return; } if (this.CommandText.Equals("show commit message")) { var issue = this.model.SelectedItems[0] as Issue; var translatedPath = this.tranlator.TranslateKey(issue.Component, this.vshelper, this.assignProject.BranchName); var blameLine = this.sourceControl.GetBlameByLine(translatedPath, issue.Line); if (blameLine != null) { string message = string.Format("Author:\t\t {0}\r\nEmail:\t\t {1}\r\nCommit Date:\t {2}\r\nHash:\t\t {3}", blameLine.Author, blameLine.Email, blameLine.Date, blameLine.Guid); string summary = blameLine.Summary; MessageDisplayBox.DisplayMessage(message, summary); } } } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "SourceControlMenu", Data = "Failed to perform operation: " + ex.Message }); this.manager.ReportException(ex); } }
/// <summary> /// Called when [download wrapper command]. /// </summary> private void OnDownloadWrapperCommand() { if (string.IsNullOrEmpty(this.CxxWrapperVersion)) { MessageDisplayBox.DisplayMessage( "Version cannot be empty, be sure to use tab in release page of the wrapper.", helpurl: "https://github.com/jmecsoftware/sonar-cxx-msbuild-tasks/releases"); return; } var installPath = Path.Combine(this.configurationHelper.ApplicationPath, "Wrapper", this.CxxWrapperVersion); if (!File.Exists(Path.Combine(installPath, "CxxSonarQubeMsbuidRunner.exe"))) { var urldownload = "https://github.com/jmecsoftware/sonar-cxx-msbuild-tasks/releases/download/" + this.CxxWrapperVersion + "/CxxSonarQubeMsbuidRunner.zip"; var tmpFile = Path.Combine(this.configurationHelper.ApplicationPath, "CxxSonarQubeMsbuidRunner.zip"); try { using (var client = new WebClient()) { if (File.Exists(tmpFile)) { File.Delete(tmpFile); } client.DownloadFile(urldownload, tmpFile); ZipFile.ExtractToDirectory(tmpFile, installPath); } if (!File.Exists(Path.Combine(installPath, "CxxSonarQubeMsbuidRunner.exe"))) { MessageDisplayBox.DisplayMessage( "Wrapper installation failed, expected in " + Path.Combine(installPath, "CxxSonarQubeMsbuidRunner.exe") + " : download manually and unzip to that folder", helpurl: "https://github.com/jmecsoftware/sonar-cxx-msbuild-tasks/releases"); return; } } catch (Exception ex) { MessageDisplayBox.DisplayMessage( "Wrapper installation failed : " + ex.Message + " please be sure you have access to url. If not download manually and change the wrapper path.", helpurl: "https://github.com/jmecsoftware/sonar-cxx-msbuild-tasks/releases"); } } this.WrapperPath = Path.Combine(installPath, "CxxSonarQubeMsbuidRunner.exe"); MessageDisplayBox.DisplayMessage("Wrapper installed in " + Path.Combine(installPath, "CxxSonarQubeMsbuidRunner.exe") + " : Dont forget to save or apply."); this.InstallTools(Path.Combine(installPath, "CxxSonarQubeMsbuidRunner.exe")); }
/// <summary> /// Verifies the change status replies. /// </summary> /// <param name="replies">The replies.</param> /// <param name="message">The message.</param> private void VerifyChangeStatusReplies(System.Collections.Generic.Dictionary <string, System.Net.HttpStatusCode> replies, string message) { bool operationOk = true; foreach (var reply in replies) { this.manager.ReportMessage(new Message { Id = "ChangeStatusMenu", Data = message + " : " + reply.Key + " : " + reply.Value }); if (reply.Value != System.Net.HttpStatusCode.OK) { operationOk = false; } } if (!operationOk) { MessageDisplayBox.DisplayMessage(message + " Failed For Some or All Issues", "Make sure you have permissions, see VSSonarOutput window for more details"); } }
/// <summary> /// Selects the issue tracker plugin. /// </summary> private void SelectIssueTrackerPlugin() { int cnt = 0; var builder = new StringBuilder(); foreach (IPlugin plugin in this.IssueTrackerPlugins) { if (plugin.GetPluginDescription().Enabled) { this.issueTrackerPlugin = plugin as IIssueTrackerPlugin; builder.AppendLine("Plugin Enabled: " + plugin.GetPluginDescription().Name); cnt++; } } if (cnt > 1) { MessageDisplayBox.DisplayMessage("More than on issue tracker plugin is enabled, make sure only one pluing is enabled", builder.ToString()); this.issueTrackerPlugin = null; } }
/// <summary> /// Called when [attache to issue tracker]. /// </summary> private void OnAttachToIssueTracker() { if (this.model.SelectedItems == null || this.model.SelectedItems.Count == 0) { return; } try { if (this.CommandText.Equals("new issue and attach")) { var issues = this.model.SelectedItems.Cast <Issue>().ToList(); string id = string.Empty; var replydata = this.issueTrackerPlugin.AttachToNewDefect(issues, out id); // update issues foreach (var issue in issues) { issue.IssueTrackerId = id; } if (string.IsNullOrEmpty(replydata)) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to create defect" }); return; } var builder = new StringBuilder(); builder.AppendLine(CommentMessageForIssue + id); builder.AppendLine(replydata); this.rest.CommentOnIssues(this.config, issues, builder.ToString()); } if (this.CommandText.Equals("attach to existent")) { var id = PromptUserData.Prompt("Enter Item Id", "Issue Tracker Id"); if (string.IsNullOrEmpty(id)) { return; } try { var issues = this.model.SelectedItems.Cast <Issue>().ToList(); var replydata = this.issueTrackerPlugin.AttachToExistentDefect(issues, id); if (string.IsNullOrEmpty(replydata)) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to attach to defect" }); return; } // update issues foreach (var issue in issues) { issue.IssueTrackerId = id; } var builder = new StringBuilder(); builder.AppendLine(CommentMessageForIssue + id); builder.AppendLine(replydata); this.rest.CommentOnIssues(this.config, issues, builder.ToString()); } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to attach to defect: " + ex.Message }); this.manager.ReportException(ex); return; } } if (this.CommandText.Equals("show info")) { var id = this.parent.CommandText; if (!this.parent.parent.defectCache.ContainsKey(id)) { try { var defect = this.issueTrackerPlugin.GetDefect(id); this.parent.parent.defectCache.Add(id, defect); } catch (Exception ex) { this.manager.ReportMessage(new Message { Id = "IssueTrackerMenu", Data = "Failed to get info for defect: " + ex.Message }); this.manager.ReportException(ex); return; } } var item = this.parent.parent.defectCache[id]; string message = string.Format("Summary:\t\t {0}\r\nStatus:\t\t {1}\r\nId:\t {2}\r\n", item.Summary, item.Status, item.Id); MessageDisplayBox.DisplayMessage(message, string.Empty); } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Perform Operation in Plan: " + ex.Message + " please check vs output log for detailed information", ex); } }