/// <summary> /// Adds the elements of a <see cref="BuildListenerCollection"/> to the end of the collection. /// </summary> /// <param name="items">The <see cref="BuildListenerCollection"/> to be added to the end of the collection.</param> public void AddRange(BuildListenerCollection items) { for (int i = 0; (i < items.Count); i = (i + 1)) { Add(items[i]); } }
public LogEventPump(LogEventQueueList queues, BuildListenerCollection handlers) { _queues = queues; _handlers = handlers; _pumpThread = null; _firstException = null; _stop = false; }
/// <summary> /// Replaces existing build event handlers with a handler that enqueues /// build events into this queue /// </summary> /// <param name="proj"></param> public void Install(Project proj, String hideTarget) { _hideTarget = hideTarget; BuildListenerCollection coll = new BuildListenerCollection(); coll.Add(this); proj.DetachBuildListeners(); proj.AttachBuildListeners(coll); }
/// <summary> /// Initializes a new instance of the <see cref="BuildListenerEnumerator"/> class /// with the specified <see cref="BuildListenerCollection"/>. /// </summary> /// <param name="arguments">The collection that should be enumerated.</param> internal BuildListenerEnumerator(BuildListenerCollection arguments) { IEnumerable temp = (IEnumerable) (arguments); _baseEnumerator = temp.GetEnumerator(); }
/// <summary> /// Initializes a new instance of the <see cref="BuildListenerCollection"/> /// class with the specified <see cref="BuildListenerCollection"/> instance. /// </summary> public BuildListenerCollection(BuildListenerCollection value) { AddRange(value); }
/// <summary> /// Creates and executes the embedded (child XML nodes) elements. /// </summary> /// <remarks> /// Skips any element defined by the host <see cref="Task" /> that has /// a <see cref="BuildElementAttribute" /> defined. /// </remarks> protected override void ExecuteChildTasks() { BuildListenerCollection prevBuildListeners = new BuildListenerCollection(Project.BuildListeners); Project.DetachBuildListeners(); try { _logEventQueueList.Clear(); _asyncProjects.Clear(); StartEventPump(prevBuildListeners); InstallNewAutoCloseEventListener(); //Leave the actual execution to the base class //Any errors during the build will throw an exception here try { base.ExecuteChildTasks(); } catch { //Wait for anything running in a child <multitask> element to //finish WaitForAsyncProjects(); //Wait for the event pump to finish StopEventPump(); throw; } //Wait for anything running in a child <multitask> element to //finish WaitForAsyncProjects(); //Wait for the event pump to finish StopEventPump(); } finally { Project.AttachBuildListeners(prevBuildListeners); } }
private void StartEventPump(BuildListenerCollection handlers) { _eventPump = new LogEventPump(_logEventQueueList, handlers); _eventPump.Start(); }
/// <summary> /// Add the listeners specified in the command line arguments, /// along with the default listener, to the specified project. /// </summary> /// <param name="cmdlineOptions">The command-line options.</param> /// <param name="project">The <see cref="Project" /> to add listeners to.</param> private static void AddBuildListeners(CommandLineOptions cmdlineOptions, Project project) { BuildListenerCollection listeners = new BuildListenerCollection(); IBuildLogger buildLogger = null; TextWriter outputWriter = Console.Out; if (cmdlineOptions.LogFile != null) { try { outputWriter = new StreamWriter(new FileStream(cmdlineOptions.LogFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read)); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1005"), cmdlineOptions.LogFile.FullName), Location.UnknownLocation, ex); } } if (cmdlineOptions.LoggerType != null) { try { buildLogger = ConsoleDriver.CreateLogger(cmdlineOptions.LoggerType); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1003"), cmdlineOptions.LoggerType), Location.UnknownLocation, ex); } } // if no logger was specified on the commandline or an error occurred // while creating an instance of the specified logger, use the default // logger. if (buildLogger == null) { buildLogger = new DefaultLogger(); } // only set OutputWriter if build logger does not derive from // DefaultLogger, or if logfile was specified on command-line. // Setting the OutputWriter of the DefaultLogger to Console.Out // would cause issues with unit tests. if (!typeof(DefaultLogger).IsAssignableFrom(buildLogger.GetType()) || cmdlineOptions.LogFile != null) { buildLogger.OutputWriter = outputWriter; } // set threshold of build logger equal to threshold of project buildLogger.Threshold = project.Threshold; // set emacs mode buildLogger.EmacsMode = cmdlineOptions.EmacsMode; // add build logger to listeners collection listeners.Add(buildLogger); // add listeners to listener collection foreach (string listenerTypeName in cmdlineOptions.Listeners) { try { IBuildListener listener = ConsoleDriver.CreateListener(listenerTypeName); listeners.Add(listener); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1002"), listenerTypeName), Location.UnknownLocation, ex); } } // attach listeners to project project.AttachBuildListeners(listeners); }
/// <summary> /// Attaches the specified build listeners to the <see cref="Project" />. /// </summary> /// <param name="listeners">The <see cref="IBuildListener" /> instances to attach to the <see cref="Project" />.</param> /// <remarks> /// The currently attached <see cref="IBuildListener" /> instances will /// be detached before the new <see cref="IBuildListener" /> instances /// are attached. /// </remarks> public void AttachBuildListeners(BuildListenerCollection listeners) { // detach currently attached build listeners DetachBuildListeners(); foreach (IBuildListener listener in listeners) { // hook up listener to project build events BuildStarted += new BuildEventHandler(listener.BuildStarted); BuildFinished += new BuildEventHandler(listener.BuildFinished); TargetStarted += new BuildEventHandler(listener.TargetStarted); TargetFinished += new BuildEventHandler(listener.TargetFinished); TaskStarted += new BuildEventHandler(listener.TaskStarted); TaskFinished += new BuildEventHandler(listener.TaskFinished); MessageLogged += new BuildEventHandler(listener.MessageLogged); // add listener to project listener list BuildListeners.Add(listener); } }
/// <summary> /// Add the listeners specified in the command line arguments, /// along with the default listener, to the specified project. /// </summary> /// <param name="cmdlineOptions">The command-line options.</param> /// <param name="project">The <see cref="Project" /> to add listeners to.</param> private static void AddBuildListeners(CommandLineOptions cmdlineOptions, Project project) { BuildListenerCollection listeners = new BuildListenerCollection(); IBuildLogger buildLogger = null; TextWriter outputWriter = Console.Out; if (cmdlineOptions.LogFile != null) { try { outputWriter = new StreamWriter(new FileStream(cmdlineOptions.LogFile.FullName, FileMode.Create, FileAccess.Write, FileShare.Read)); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1005"), cmdlineOptions.LogFile.FullName), Location.UnknownLocation, ex); } } if (cmdlineOptions.LoggerType != null) { try { buildLogger = ConsoleDriver.CreateLogger(cmdlineOptions.LoggerType); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1003"), cmdlineOptions.LoggerType), Location.UnknownLocation, ex); } } // if no logger was specified on the commandline or an error occurred // while creating an instance of the specified logger, use the default // logger. if (buildLogger == null) { buildLogger = new DefaultLogger(); } // only set OutputWriter if build logger does not derive from // DefaultLogger, or if logfile was specified on command-line. // Setting the OutputWriter of the DefaultLogger to Console.Out // would cause issues with unit tests. if (!(buildLogger is DefaultLogger) || cmdlineOptions.LogFile != null) { buildLogger.OutputWriter = outputWriter; } // set threshold of build logger equal to threshold of project buildLogger.Threshold = project.Threshold; // set emacs mode buildLogger.EmacsMode = cmdlineOptions.EmacsMode; // add build logger to listeners collection listeners.Add(buildLogger); // add listeners to listener collection foreach (string listenerTypeName in cmdlineOptions.Listeners) { try { IBuildListener listener = ConsoleDriver.CreateListener(listenerTypeName); listeners.Add(listener); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1002"), listenerTypeName), Location.UnknownLocation, ex); } } // attach listeners to project project.AttachBuildListeners(listeners); }
/// <summary> /// Initializes a new instance of the <see cref="BuildListenerEnumerator"/> class /// with the specified <see cref="BuildListenerCollection"/>. /// </summary> /// <param name="arguments">The collection that should be enumerated.</param> internal BuildListenerEnumerator(BuildListenerCollection arguments) { IEnumerable temp = (IEnumerable)(arguments); _baseEnumerator = temp.GetEnumerator(); }
/// <summary> /// Add the listeners specified in the command line arguments, /// along with the default listener, to the specified project. /// </summary> private void AddBuildListeners() { Assert.NotNull(_project, "project"); // Create new logger IBuildLogger buildLogger = new GuiLogger(_logger); // set threshold of build logger equal to threshold of project buildLogger.Threshold = _project.Threshold; // add build logger to listeners collection BuildListenerCollection listeners = new BuildListenerCollection(); listeners.Add(buildLogger); // attach listeners to project _project.AttachBuildListeners(listeners); }