/// <summary> /// Runs the XML as NAnt project and returns the console output as a /// string. /// </summary> /// <param name="xml">XML representing the build file contents.</param> /// <param name="level">The build output threshold.</param> /// <param name="listener">A <see cref="IBuildListener" /> to which all build events will be dispatched.</param> /// <returns> /// The console output. /// </returns> public string RunBuild(string xml, Level level, IBuildListener listener) { Project project = CreateFilebasedProject(xml, level); //use Project.AttachBuildListeners to attach. IBuildListener[] listners = { listener }; project.AttachBuildListeners(new BuildListenerCollection(listners)); // execute the project return(ExecuteProject(project)); }
private void PassEventToHandler(LogEvent evt, IBuildListener bl) { switch (evt.EventType) { case LogEventType.TargetFinished: bl.TargetFinished(evt.Sender, evt.Args); break; case LogEventType.MessageLogged: bl.MessageLogged(evt.Sender, evt.Args); break; case LogEventType.BuildStarted: bl.BuildStarted(evt.Sender, evt.Args); break; case LogEventType.BuildFinished: bl.BuildFinished(evt.Sender, evt.Args); break; case LogEventType.TaskFinished: bl.TaskFinished(evt.Sender, evt.Args); break; case LogEventType.TargetStarted: bl.TargetStarted(evt.Sender, evt.Args); break; case LogEventType.TaskStarted: bl.TaskStarted(evt.Sender, evt.Args); break; case LogEventType.Exception: //If this is the first exception, save it if (_firstException == null) { _firstException = evt.Exception; } //Report this in the form of a message BuildEventArgs e = new BuildEventArgs(evt.Project); e.Exception = evt.Exception; e.MessageLevel = Level.Error; e.Message = String.Format("Error running async task: {0}", evt.Exception.Message); bl.MessageLogged(evt.Project, e); break; } }
public static IBuildListener CreateListener(string typeName) { Type listenerType = ReflectionUtils.GetTypeFromString(typeName, false); if (listenerType == null) { throw new TypeLoadException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA1006"), typeName)); } object listener = Activator.CreateInstance(listenerType); IBuildListener buildListener = listener as IBuildListener; if (buildListener != null) { return(buildListener); } throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "{0} does not implement {1}.", listener.GetType().FullName, typeof(IBuildListener).FullName)); }
/// <summary> /// Retrieves the index of a specified <see cref="IBuildListener"/> object in the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> object for which the index is returned.</param> /// <returns> /// The index of the specified <see cref="IBuildListener"/>. If the <see cref="IBuildListener"/> is not currently a member of the collection, it returns -1. /// </returns> public int IndexOf(IBuildListener item) { return base.List.IndexOf(item); }
/// <summary> /// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.</param> /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param> public void CopyTo(IBuildListener[] array, int index) { base.List.CopyTo(array, index); }
/// <summary> /// Determines whether a <see cref="IBuildListener"/> is in the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> to locate in the collection.</param> /// <returns> /// <see langword="true" /> if <paramref name="item"/> is found in the /// collection; otherwise, <see langword="false" />. /// </returns> public bool Contains(IBuildListener item) { return base.List.Contains(item); }
/// <summary> /// Adds the elements of a <see cref="IBuildListener"/> array to the end of the collection. /// </summary> /// <param name="items">The array of <see cref="IBuildListener"/> elements to be added to the end of the collection.</param> public void AddRange(IBuildListener[] items) { for (int i = 0; (i < items.Length); i = (i + 1)) { Add(items[i]); } }
/// <summary> /// Adds a <see cref="IBuildListener"/> to the end of the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> to be added to the end of the collection.</param> /// <returns>The position into which the new element was inserted.</returns> public int Add(IBuildListener item) { return base.List.Add(item); }
/// <summary> /// Initializes a new instance of the <see cref="BuildListenerCollection"/> /// class with the specified array of <see cref="IBuildListener"/> instances. /// </summary> public BuildListenerCollection(IBuildListener[] value) { AddRange(value); }
/// <summary> /// Retrieves the index of a specified <see cref="IBuildListener"/> object in the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> object for which the index is returned.</param> /// <returns> /// The index of the specified <see cref="IBuildListener"/>. If the <see cref="IBuildListener"/> is not currently a member of the collection, it returns -1. /// </returns> public int IndexOf(IBuildListener item) { return(base.List.IndexOf(item)); }
/// <summary> /// Adds a <see cref="IBuildListener"/> to the end of the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> to be added to the end of the collection.</param> /// <returns>The position into which the new element was inserted.</returns> public int Add(IBuildListener item) { return(base.List.Add(item)); }
/// <summary> /// Runs the XML as a NAnt project and returns the console output as a /// string. /// </summary> /// <param name="xml">XML representing the build file contents.</param> /// <param name="listener">A <see cref="IBuildListener" /> to which all build events will be dispatched.</param> /// <returns> /// The console output. /// </returns> public string RunBuild(string xml, IBuildListener listener) { return RunBuild(xml, Level.Info, listener); }
/// <summary> /// Runs the XML as NAnt project and returns the console output as a /// string. /// </summary> /// <param name="xml">XML representing the build file contents.</param> /// <param name="level">The build output threshold.</param> /// <param name="listener">A <see cref="IBuildListener" /> to which all build events will be dispatched.</param> /// <returns> /// The console output. /// </returns> public string RunBuild(string xml, Level level, IBuildListener listener) { Project project = CreateFilebasedProject(xml, level); //use Project.AttachBuildListeners to attach. IBuildListener[] listners = {listener}; project.AttachBuildListeners(new BuildListenerCollection(listners)); // execute the project return ExecuteProject(project); }
/// <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> /// Removes a member from the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> to remove from the collection.</param> public void Remove(IBuildListener item) { base.List.Remove(item); }
/// <summary> /// Inserts a <see cref="IBuildListener"/> into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="IBuildListener"/> to insert.</param> public void Insert(int index, IBuildListener item) { base.List.Insert(index, item); }
/// <summary> /// Runs the XML as a NAnt project and returns the console output as a /// string. /// </summary> /// <param name="xml">XML representing the build file contents.</param> /// <param name="listener">A <see cref="IBuildListener" /> to which all build events will be dispatched.</param> /// <returns> /// The console output. /// </returns> public string RunBuild(string xml, IBuildListener listener) { return(RunBuild(xml, Level.Info, listener)); }
/// <summary> /// Determines whether a <see cref="IBuildListener"/> is in the collection. /// </summary> /// <param name="item">The <see cref="IBuildListener"/> to locate in the collection.</param> /// <returns> /// <see langword="true" /> if <paramref name="item"/> is found in the /// collection; otherwise, <see langword="false" />. /// </returns> public bool Contains(IBuildListener item) { return(base.List.Contains(item)); }