async Task<BuildResult> RebuildAsync (IBuildTarget entry, ProgressMonitor monitor, OperationContext operationContext) { ITimeTracker tt = Counters.BuildItemTimer.BeginTiming ("Rebuilding " + entry.Name); try { OnStartClean (monitor, tt); var res = await CleanAsync (entry, monitor, tt, true, operationContext); if (res.HasErrors) { tt.End (); monitor.Dispose (); return res; } if (StartBuild != null) { BeginBuild (monitor, tt, true); } return await BuildSolutionItemAsync (entry, monitor, tt, operationContext:operationContext); } finally { tt.End (); } }
void BuildDone (ProgressMonitor monitor, BuildResult result, IBuildTarget entry, ITimeTracker tt) { TaskListEntry[] tasks = null; tt.Trace ("Begin reporting build result"); try { if (result != null) { lastResult = result; monitor.Log.WriteLine (); monitor.Log.WriteLine (GettextCatalog.GetString ("---------------------- Done ----------------------")); tt.Trace ("Updating task service"); tasks = new TaskListEntry [result.Errors.Count]; for (int n=0; n<tasks.Length; n++) { tasks [n] = new TaskListEntry (result.Errors [n]); tasks [n].Owner = this; } TaskService.Errors.AddRange (tasks); TaskService.Errors.ResetLocationList (); IdeApp.Workbench.ActiveLocationList = TaskService.Errors; tt.Trace ("Reporting result"); string errorString = GettextCatalog.GetPluralString("{0} error", "{0} errors", result.ErrorCount, result.ErrorCount); string warningString = GettextCatalog.GetPluralString("{0} warning", "{0} warnings", result.WarningCount, result.WarningCount); if (monitor.CancellationToken.IsCancellationRequested) { monitor.ReportError (GettextCatalog.GetString ("Build canceled."), null); } else if (result.ErrorCount == 0 && result.WarningCount == 0 && lastResult.FailedBuildCount == 0) { monitor.ReportSuccess (GettextCatalog.GetString ("Build successful.")); } else if (result.ErrorCount == 0 && result.WarningCount > 0) { monitor.ReportWarning(GettextCatalog.GetString("Build: ") + errorString + ", " + warningString); } else if (result.ErrorCount > 0) { monitor.ReportError(GettextCatalog.GetString("Build: ") + errorString + ", " + warningString, null); } else { monitor.ReportError(GettextCatalog.GetString("Build failed."), null); } tt.Trace ("End build event"); OnEndBuild (monitor, lastResult.FailedBuildCount == 0, lastResult, entry as SolutionFolderItem); } else { tt.Trace ("End build event"); OnEndBuild (monitor, false); } tt.Trace ("Showing results pad"); try { Pad errorsPad = IdeApp.Workbench.GetPad<MonoDevelop.Ide.Gui.Pads.ErrorListPad> (); switch (IdeApp.Preferences.ShowErrorPadAfterBuild.Value) { case BuildResultStates.Always: if (!errorsPad.Visible) errorsPad.IsOpenedAutomatically = true; errorsPad.Visible = true; errorsPad.BringToFront (); break; case BuildResultStates.Never: break; case BuildResultStates.OnErrors: if (TaskService.Errors.Any (task => task.Severity == TaskSeverity.Error)) goto case BuildResultStates.Always; goto case BuildResultStates.Never; case BuildResultStates.OnErrorsOrWarnings: if (TaskService.Errors.Any (task => task.Severity == TaskSeverity.Error || task.Severity == TaskSeverity.Warning)) goto case BuildResultStates.Always; goto case BuildResultStates.Never; } } catch {} if (tasks != null) { TaskListEntry jumpTask = null; switch (IdeApp.Preferences.JumpToFirstErrorOrWarning.Value) { case JumpToFirst.Error: jumpTask = tasks.FirstOrDefault (t => t.Severity == TaskSeverity.Error && TaskStore.IsProjectTaskFile (t)); break; case JumpToFirst.ErrorOrWarning: jumpTask = tasks.FirstOrDefault (t => (t.Severity == TaskSeverity.Error || t.Severity == TaskSeverity.Warning) && TaskStore.IsProjectTaskFile (t)); break; } if (jumpTask != null) { tt.Trace ("Jumping to first result position"); jumpTask.JumpToPosition (); } } } finally { monitor.Dispose (); tt.End (); } }
async Task ExecuteSolutionItemAsync (ProgressMonitor monitor, IBuildTarget entry, ExecutionContext context) { try { OnBeforeStartProject (); await entry.Execute (monitor, context, IdeApp.Workspace.ActiveConfiguration); } catch (Exception ex) { monitor.ReportError (GettextCatalog.GetString ("Execution failed."), ex); LoggingService.LogError ("Execution failed", ex); } finally { monitor.Dispose (); } }
void CleanDone (ProgressMonitor monitor, IBuildTarget entry, ITimeTracker tt) { tt.Trace ("Begin reporting clean result"); try { monitor.Log.WriteLine (); monitor.Log.WriteLine (GettextCatalog.GetString ("---------------------- Done ----------------------")); tt.Trace ("Reporting result"); monitor.ReportSuccess (GettextCatalog.GetString ("Clean successful.")); OnEndClean (monitor, tt); } finally { monitor.Dispose (); tt.End (); } }
static void WriteSummaryResults (ProgressMonitor monitor, int succeeded, int warnings, int errors) { monitor.Log.WriteLine (); int total = succeeded + warnings + errors; //this might not be correct for languages where pluralization affects the other arguments //but gettext doesn't really have an answer for sentences with multiple plurals monitor.Log.WriteLine ( GettextCatalog.GetPluralString ( "{0} file processed total. {1} generated successfully, {2} with warnings, {3} with errors", "{0} files processed total. {1} generated successfully, {2} with warnings, {3} with errors", total, total, succeeded, warnings, errors) ); //ends the root task monitor.EndTask (); if (errors > 0) monitor.ReportError (GettextCatalog.GetString ("Errors in file generation."), null); else if (warnings > 0) monitor.ReportSuccess (GettextCatalog.GetString ("Warnings in file generation.")); else monitor.ReportSuccess (GettextCatalog.GetString ("Generated files successfully.")); monitor.Dispose (); }
static bool UpdateCompleted (ProgressMonitor monitor, ProjectFile file, ProjectFile genFile, SingleFileCustomToolResult result, bool runMultipleFiles) { monitor.EndTask (); if (monitor.CancellationToken.IsCancellationRequested) { monitor.ReportError (GettextCatalog.GetString ("Cancelled"), null); monitor.Dispose (); return false; } string genFileName; try { bool broken = false; if (result.UnhandledException != null) { broken = true; string msg = GettextCatalog.GetString ("The '{0}' code generator crashed", file.Generator); result.Errors.Add (new CompilerError (file.Name, 0, 0, "", msg + ": " + result.UnhandledException.Message)); monitor.ReportError (msg, result.UnhandledException); LoggingService.LogError (msg, result.UnhandledException); } genFileName = result.GeneratedFilePath.IsNullOrEmpty? null : result.GeneratedFilePath.ToRelative (file.FilePath.ParentDirectory); if (!string.IsNullOrEmpty (genFileName)) { bool validName = genFileName.IndexOfAny (new [] { '/', '\\' }) < 0 && FileService.IsValidFileName (genFileName); if (!broken && !validName) { broken = true; string msg = GettextCatalog.GetString ("The '{0}' code generator output invalid filename '{1}'", file.Generator, result.GeneratedFilePath); result.Errors.Add (new CompilerError (file.Name, 0, 0, "", msg)); monitor.ReportError (msg, null); } } if (result.Errors.Count > 0) { DispatchService.GuiDispatch (delegate { foreach (CompilerError err in result.Errors) TaskService.Errors.Add (new TaskListEntry (file.FilePath, err.ErrorText, err.Column, err.Line, err.IsWarning? TaskSeverity.Warning : TaskSeverity.Error, TaskPriority.Normal, file.Project.ParentSolution, file)); }); } if (broken) return true; if (!runMultipleFiles) { if (result.Success) monitor.ReportSuccess ("Generated file successfully."); else if (result.SuccessWithWarnings) monitor.ReportSuccess ("Warnings in file generation."); else monitor.ReportError ("Errors in file generation.", null); } } finally { if (!runMultipleFiles) monitor.Dispose (); } if (result.GeneratedFilePath.IsNullOrEmpty || !File.Exists (result.GeneratedFilePath)) return true; // broadcast a change event so text editors etc reload the file FileService.NotifyFileChanged (result.GeneratedFilePath); // add file to project, update file properties, etc Gtk.Application.Invoke (async delegate { bool projectChanged = false; if (genFile == null) { genFile = file.Project.AddFile (result.GeneratedFilePath, result.OverrideBuildAction); projectChanged = true; } else if (result.GeneratedFilePath != genFile.FilePath) { genFile.Name = result.GeneratedFilePath; projectChanged = true; } if (file.LastGenOutput != genFileName) { file.LastGenOutput = genFileName; projectChanged = true; } if (genFile.DependsOn != file.FilePath.FileName) { genFile.DependsOn = file.FilePath.FileName; projectChanged = true; } if (projectChanged) await IdeApp.ProjectOperations.SaveAsync (file.Project); }); return true; }
async Task ExecuteSolutionItemAsync (ProgressMonitor monitor, IBuildTarget entry, ExecutionContext context, ConfigurationSelector configuration, RunConfiguration runConfiguration) { try { OnBeforeStartProject (); if (entry is IRunTarget) await ((IRunTarget)entry).Execute (monitor, context, configuration, runConfiguration); else await entry.Execute (monitor, context, configuration); } catch (Exception ex) { monitor.ReportError (GettextCatalog.GetString ("Execution failed."), ex); LoggingService.LogError ("Execution failed", ex); } finally { monitor.Dispose (); } }
void UpdateTranslationsAsync (ProgressMonitor monitor, TranslationProject project, Translation translation) { try { project.UpdateTranslations (monitor, translation); Gtk.Application.Invoke (delegate { POEditorWidget.ReloadWidgets (); }); } catch (Exception ex) { monitor.ReportError (GettextCatalog.GetString ("Translation update failed."), ex); } finally { monitor.Log.WriteLine (); monitor.Log.WriteLine (GettextCatalog.GetString ("---------------------- Done ----------------------")); monitor.Dispose (); } }
async Task AddXwtFromGithubAsync (Solution solution, string newProjectName, bool createSubmodule, ProgressMonitor monitor) { try { var gitUrl = "https://github.com/" + (string.IsNullOrEmpty (Parameters ["XwtGithubRepository"]) ? Parameters ["XwtGithubRepository"] : "mono/xwt") + ".git"; var gitBranch = Parameters ["XwtGithubBranch"]; if (gitBranch == String.Empty) gitBranch = "master"; var gitRepo = VersionControlService.GetRepository (solution) as GitRepository; var xwt_proj = solution.FindProjectByName ("Xwt") as DotNetProject; if (xwt_proj != null && xwt_proj.ItemId.ToUpper () != "{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}") { xwt_proj = null; foreach (var item in solution.GetAllProjectsWithFlavor<DotNetProjectExtension>()) { if (item.ItemId.ToUpper () == "{92494904-35FA-4DC9-BDE9-3A3E87AC49D3}") { xwt_proj = item as DotNetProject; break; } } } var xwt_path = xwt_proj == null ? solution.BaseDirectory.Combine ("Xwt") : xwt_proj.BaseDirectory.ParentDirectory; monitor.BeginTask ("Configuring Xwt References...", 3); if (xwt_proj == null && !Directory.Exists (xwt_path)) { monitor.BeginTask ("Cloning Xwt into " + xwt_path + "...", 1); if (createSubmodule && gitRepo != null) { monitor.BeginTask ("Initializing Xwt submodule in " + xwt_path + "...", 1); var repo = new FileRepository (gitRepo.RootPath.Combine (".git")); var git = new Git (repo); try { using (var gm = new GitMonitor (monitor)) { var add_submodule = git.SubmoduleAdd (); add_submodule.SetPath ("Xwt"); add_submodule.SetURI (gitUrl); add_submodule.SetProgressMonitor (gm); add_submodule.Call (); var submodule = new GitRepository (VersionControlService.GetVersionControlSystems ().First (id => id.Name == "Git"), gitRepo.RootPath.Combine ("Xwt"), gitUrl); var submoduleRemote = submodule.GetCurrentRemote (); submodule.Fetch (monitor, submoduleRemote); if (submodule.GetCurrentBranch () != gitBranch) { submodule.CreateBranch (gitBranch, submoduleRemote + "/" + gitBranch, "refs/remotes/" + submoduleRemote + "/" + gitBranch); submodule.SwitchToBranch (monitor, gitBranch); } } } catch { Directory.Delete (xwt_path, true); throw; } monitor.EndTask (); } else { var repo = new GitRepository (); repo.Url = gitUrl; repo.Checkout (xwt_path, true, monitor); var remote = repo.GetCurrentRemote (); repo.Fetch (monitor, remote); if (repo.GetCurrentBranch () != gitBranch) { repo.CreateBranch (gitBranch, remote + "/" + gitBranch, "refs/remotes/" + remote + "/" + gitBranch); repo.SwitchToBranch (monitor, gitBranch); } } monitor.EndTask (); } SolutionFolder xwt_folder; if (xwt_proj != null) xwt_folder = xwt_proj.ParentFolder; else { xwt_folder = new SolutionFolder (); xwt_folder.Name = "Xwt"; } solution.RootFolder.Items.Add (xwt_folder); monitor.Step (1); monitor.BeginTask ("Adding Xwt Projects to Solution...", 7); if (xwt_proj == null && File.Exists (xwt_path.Combine ("Xwt", "Xwt.csproj"))) { xwt_proj = await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt", "Xwt.csproj") ) as DotNetProject; } if (xwt_proj == null) throw new InvalidOperationException ("Xwt project not found"); monitor.Step (1); var xwt_gtk_proj = solution.FindProjectByName ("Xwt.Gtk") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.Gtk", "Xwt.Gtk.csproj") ) as DotNetProject; monitor.Step (1); var xwt_gtk_win_proj = solution.FindProjectByName ("Xwt.Gtk.Windows") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.Gtk.Windows", "Xwt.Gtk.Windows.csproj") ) as DotNetProject; monitor.Step (1); var xwt_gtk_mac_proj = solution.FindProjectByName ("Xwt.Gtk.Mac") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.Gtk.Mac", "Xwt.Gtk.Mac.csproj") ) as DotNetProject; monitor.Step (1); var xwt_gtk3_proj = solution.FindProjectByName ("Xwt.Gtk3") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.Gtk", "Xwt.Gtk3.csproj") ) as DotNetProject; monitor.Step (1); var xwt_wpf_proj = solution.FindProjectByName ("Xwt.WPF") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.WPF", "Xwt.WPF.csproj") ) as DotNetProject; monitor.Step (1); var xwt_mac_proj = solution.FindProjectByName ("Xwt.Mac") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.Mac", "Xwt.Mac.csproj") ) as DotNetProject; monitor.Step (1); var xwt_xammac_proj = solution.FindProjectByName ("Xwt.XamMac") ?? await IdeApp.ProjectOperations.AddSolutionItem ( xwt_folder, xwt_path.Combine ("Xwt.XamMac", "Xwt.XamMac.csproj") ) as DotNetProject; monitor.EndTask (); monitor.Step (1); monitor.BeginTask ("Adding Xwt References...", solution.Items.Count); foreach (var item in solution.Items) { var project = item as DotNetProject; if (project != null) { if (project.Name == newProjectName || project.Name.StartsWith (newProjectName + ".", StringComparison.Ordinal)) project.References.Add (ProjectReference.CreateProjectReference (xwt_proj)); if (project.Name == newProjectName + ".Desktop") { if (Platform.IsWindows) { project.References.Add (ProjectReference.CreateProjectReference (xwt_wpf_proj)); project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_proj)); project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_win_proj)); } else if (Platform.IsLinux) { project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_proj)); project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk3_proj)); } else if (Platform.IsMac) { project.References.Add (ProjectReference.CreateProjectReference (xwt_xammac_proj)); project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_proj)); project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_mac_proj)); } } if (project.Name == newProjectName + ".Gtk2") { project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_proj)); if (Platform.IsWindows) { project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_win_proj)); } else if (Platform.IsMac) { project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk_mac_proj)); } } if (project.Name == newProjectName + ".Wpf") { project.References.Add (ProjectReference.CreateProjectReference (xwt_wpf_proj)); } if (project.Name == newProjectName + ".Gtk3") { project.References.Add (ProjectReference.CreateProjectReference (xwt_gtk3_proj)); } if (project.Name == newProjectName + ".Mac") { project.References.Add (ProjectReference.CreateProjectReference (xwt_mac_proj)); } if (project.Name == newProjectName + ".XamMac") { project.References.Add (ProjectReference.CreateProjectReference (xwt_xammac_proj)); } } monitor.Step (1); } monitor.EndTask (); monitor.EndTask (); monitor.ReportSuccess ("Xwt Repository initialized successfully"); await IdeApp.Workspace.SaveAsync (monitor); } catch (Exception e) { string msg = GettextCatalog.GetString ("Adding Xwt reference failed: "); monitor.ReportError (msg, e); MessageService.ShowError (msg, e); } finally { monitor.Dispose (); } }
void BuildDone (ProgressMonitor monitor, BuildResult result, IBuildTarget entry, ITimeTracker tt) { TaskListEntry[] tasks = null; tt.Trace ("Begin reporting build result"); try { if (result != null) { lastResult = result; monitor.Log.WriteLine (); monitor.Log.WriteLine (GettextCatalog.GetString ("---------------------- Done ----------------------")); tt.Trace ("Updating task service"); tasks = ReportErrors (result); tt.Trace ("Reporting result"); string errorString = GettextCatalog.GetPluralString("{0} error", "{0} errors", result.ErrorCount, result.ErrorCount); string warningString = GettextCatalog.GetPluralString("{0} warning", "{0} warnings", result.WarningCount, result.WarningCount); if (monitor.CancellationToken.IsCancellationRequested) { monitor.ReportError (GettextCatalog.GetString ("Build canceled."), null); } else if (result.ErrorCount == 0 && result.WarningCount == 0 && lastResult.FailedBuildCount == 0) { monitor.ReportSuccess (GettextCatalog.GetString ("Build successful.")); } else if (result.ErrorCount == 0 && result.WarningCount > 0) { monitor.ReportWarning(GettextCatalog.GetString("Build: ") + errorString + ", " + warningString); } else if (result.ErrorCount > 0) { monitor.ReportError(GettextCatalog.GetString("Build: ") + errorString + ", " + warningString, null); } else { monitor.ReportError(GettextCatalog.GetString("Build failed."), null); } tt.Trace ("End build event"); OnEndBuild (monitor, lastResult.FailedBuildCount == 0, lastResult, entry as SolutionFolderItem); } else { tt.Trace ("End build event"); OnEndBuild (monitor, false); } tt.Trace ("Showing results pad"); ShowErrorsPadIfNecessary (); if (tasks != null) { TaskListEntry jumpTask = null; switch (IdeApp.Preferences.JumpToFirstErrorOrWarning.Value) { case JumpToFirst.Error: jumpTask = tasks.FirstOrDefault (t => t.Severity == TaskSeverity.Error && TaskStore.IsProjectTaskFile (t)); break; case JumpToFirst.ErrorOrWarning: jumpTask = tasks.FirstOrDefault (t => (t.Severity == TaskSeverity.Error || t.Severity == TaskSeverity.Warning) && TaskStore.IsProjectTaskFile (t)); break; } if (jumpTask != null) { tt.Trace ("Jumping to first result position"); jumpTask.JumpToPosition (); } } } finally { monitor.Dispose (); tt.End (); } }
void CleanDone (ProgressMonitor monitor, BuildResult result, IBuildTarget entry, ITimeTracker tt) { tt.Trace ("Begin reporting clean result"); try { if (result != null) { monitor.Log.WriteLine (); monitor.Log.WriteLine (GettextCatalog.GetString ("---------------------- Done ----------------------")); tt.Trace ("Updating task service"); ReportErrors (result); tt.Trace ("Reporting result"); string errorString = GettextCatalog.GetPluralString ("{0} error", "{0} errors", result.ErrorCount, result.ErrorCount); string warningString = GettextCatalog.GetPluralString ("{0} warning", "{0} warnings", result.WarningCount, result.WarningCount); if (monitor.CancellationToken.IsCancellationRequested) { monitor.ReportError (GettextCatalog.GetString ("Clean canceled."), null); } else if (result.ErrorCount == 0 && result.WarningCount == 0 && result.FailedBuildCount == 0) { monitor.ReportSuccess (GettextCatalog.GetString ("Clean successful.")); } else if (result.ErrorCount == 0 && result.WarningCount > 0) { monitor.ReportWarning (GettextCatalog.GetString ("Clean: ") + errorString + ", " + warningString); } else if (result.ErrorCount > 0) { monitor.ReportError (GettextCatalog.GetString ("Clean: ") + errorString + ", " + warningString, null); } else { monitor.ReportError (GettextCatalog.GetString ("Clean failed."), null); } } OnEndClean (monitor, tt); tt.Trace ("Showing results pad"); ShowErrorsPadIfNecessary (); } finally { monitor.Dispose (); tt.End (); } }