Class representing an event occurring during a build.

An event is built by specifying either a project, a task or a target.

A Project level event will only have a Project reference.

A Target level event will have Project and Target references.

A Task level event will have Project, Target and Task references.

Inheritance: System.EventArgs
Exemplo n.º 1
0
        public void TaskFinished(object sender, BuildEventArgs e)
        {
            var task = (CscTask)e.Task;
            var generator = (GenerateMsBuildTask)sender;
            var projectFileName = String.Format(
                    "{0}{1}{2}.csproj",
                    task.Sources.BaseDirectory.FullName,
                    Path.DirectorySeparatorChar,
                    Path.GetFileNameWithoutExtension(task.OutputFile.Name));

            ProjectRootElement project = null;
            if (!File.Exists(projectFileName))
                project = ProjectRootElement.Create(projectFileName);
            else
                project = ProjectRootElement.Open(projectFileName);
            var projectManipulator = new MB.Project(project);

            project.DefaultTargets = "Build";
            SetKnownProperties(project, task);
            GenerateReferences(project, projectManipulator, task, generator);
            GenerateCompileIncludes(project, projectManipulator, task);
            project.EnsureImportExists("$(MSBuildToolsPath)\\Microsoft.CSharp.targets");

            generator.RegisterProjectInSolution(project);
            project.Save();
        }
 public void BuildFinished(object sender, BuildEventArgs e)
 {
     if (e.Exception == null && e.Project == Project)
     {
         GenerateSolutionFile(Project);
     }
 }
Exemplo n.º 3
0
        private static void OnMessageLogged(object sender, BuildEventArgs e)
        {
            if (Loggers.IsEmpty)
            {
                // tiny race.
                ((Project)sender).MessageLogged -= OnMessageLogged;
                return;
            }

            var msg = FormatMessage(e);
            
            if (msg == null)
                return;
            
            foreach (var log in Loggers)
            {
                try
                {
                    log.Value.WriteLine(msg);
                    log.Value.Flush();
                }
                catch (Exception)
                {
                }
                
            }
        }
Exemplo n.º 4
0
 public void TaskFinished(object sender, BuildEventArgs e)
 {
     // resources embedded in csc tasks are already handled
     if (typeof(CscTask) != e.Task.Parent.GetType())
     {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 5
0
        public void BuildStarted(Object sender, BuildEventArgs be)
        {
            autoTrace = be.Project.Properties.Contains("trace.ant.disableAutoTrace") && be.Project.Properties["trace.ant.disableAutoTrace"].Equals("true", StringComparison.InvariantCultureIgnoreCase);

            TraceManager.BeginTrace();
            if (autoTrace)
                TraceManager.Trace.BeginEntry(String.Format("Start build '{0}'.", be.Project.ProjectName), severityType.INFO);
        }
Exemplo n.º 6
0
 public LogEvent(String sourceName, Object sender, BuildEventArgs args, LogEventType eventType)
 {
     _sourceName = sourceName;
     _sender = sender;
     _args = args;
     _eventType = eventType;
     _exception = null;
 }
 public void TaskFinished(object sender, BuildEventArgs e)
 {
     if (e.Exception == null && !string.IsNullOrEmpty(e.Task.Name))
     {
         if (taskTranslators.ContainsKey(e.Task.Name))
         {
             taskTranslators[e.Task.Name].TaskFinished(this, e);
         }
     }
 }
Exemplo n.º 8
0
        public void TaskStarted(object sender, BuildEventArgs e) {
            _taskStartedFired = true;

            if (e.Task != null) {
                if (_executedTasks.ContainsKey(e.Task.Name)) {
                    _executedTasks[e.Task.Name] = ((int) _executedTasks[e.Task.Name]) + 1;
                } else {
                    _executedTasks.Add(e.Task.Name, 1);
                }
            }
        }
Exemplo n.º 9
0
        public void TargetStarted(object sender, BuildEventArgs e) {
            _targetStartedFired = true;

            if (e.Target != null) {
                if (_executedTargets.ContainsKey(e.Target.Name)) {
                    _executedTargets[e.Target.Name] = ((int) _executedTargets[e.Target.Name]) + 1;
                } else {
                    _executedTargets.Add(e.Target.Name, 1);
                }
                _targetStartTimes[e.Target.Name] = DateTime.UtcNow;
            }
        }
Exemplo n.º 10
0
        public void BuildStarted(object sender, BuildEventArgs e)
        {
            string host = e.Project.Properties[PROP_HOST];

            if (host == null) {
                host = DEFAULT_HOST;
            }

            string port = e.Project.Properties[PROP_PORT];

            if (port == null) {
                port = DEFAULT_PORT;
            }

            int portInt = int.Parse(port);

            reporter = new UdpBuildReporter(host, portInt);

            report("BUILD_STARTED", e);
        }
Exemplo n.º 11
0
        public void ParseMessage(BuildEventArgs e, out MessagePriority priority, out string file, out int lineNumber, out string code, out string message)
        {
            switch(e.MessageLevel) {
                case Level.Warning: priority = MessagePriority.WARNING; break;
                case Level.Error: priority = MessagePriority.ERROR; break;
                default: priority = MessagePriority.INFO; break;
            }

            file = null;
            code = null;
            lineNumber = 0;
            message = e.Message;

            Match match = messageRegex.Match(message);
            if (match.Success)
            {
                if (match.Groups["category"].Value == "warning")
                {
                    priority = MessagePriority.WARNING;
                }
                else
                {
                    priority = MessagePriority.ERROR;
                }

                file = match.Groups["file"].Value;

                string lineString = match.Groups["line"].Value;
                if (lineString != "")
                {
                    lineNumber = int.Parse(lineString);
                }

                code = match.Groups["code"].Value;
                message = match.Groups["message"].Value;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Outputs an indented message to the build log if its priority is 
        /// greather than or equal to the <see cref="Threshold" /> of the 
        /// logger.
        /// </summary>
        /// <param name="e">The event to output.</param>
        private void OutputMessage(BuildEventArgs e)
        {
            int indentationLength = 0;

            if (e.Project != null) {
                indentationLength = e.Project.IndentationLevel * e.Project.IndentationSize;
            }

            OutputMessage(e, indentationLength);
        }
Exemplo n.º 13
0
 private static BuildEventArgs CreateBuildEvent(Level messageLevel, string message)
 {
     BuildEventArgs buildEvent = new BuildEventArgs();
     buildEvent.MessageLevel = messageLevel;
     buildEvent.Message = message;
     return buildEvent;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Signals that a task has started.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 public virtual void TaskStarted(object sender, BuildEventArgs e)
 {
 }
Exemplo n.º 15
0
 /// <summary>
 /// Signals that a task has finished.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 /// <remarks>
 /// This event will still be fired if an error occurred during the build.
 /// </remarks>
 public virtual void TaskFinished(object sender, BuildEventArgs e)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// Signals that a task has finished.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 /// <remarks>
 /// This event will still be fired if an error occurred during the build.
 /// </remarks>
 public virtual void TaskFinished(object sender, BuildEventArgs e)
 {
 }
Exemplo n.º 17
0
 public void MessageLogged(object sender, BuildEventArgs e)
 {
     Enqueue(new LogEvent(_src, sender, e, LogEventType.MessageLogged));
 }
Exemplo n.º 18
0
 public void TaskFinished(object sender, BuildEventArgs e)
 {
     Enqueue(new LogEvent(_src, sender, e, LogEventType.TaskFinished));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Signals that a task has finished.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 /// <remarks>
 /// This event will still be fired if an error occurred during the build.
 /// </remarks>
 public void TaskFinished(object sender, BuildEventArgs e)
 {
     lock (_xmlWriter) {
         // output total target duration
         WriteDuration();
         // close task element
         _xmlWriter.WriteEndElement();
         _xmlWriter.Flush();
     }
 }
Exemplo n.º 20
0
 /// <summary>
 /// Signals that a build has started.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 /// <remarks>
 /// This event is fired before any targets have started.
 /// </remarks>
 public void BuildStarted(object sender, BuildEventArgs e)
 {
     lock (_xmlWriter) {
         _stopWatchStack.PushStart();
         _xmlWriter.WriteStartElement(Elements.BuildResults);
         _xmlWriter.WriteAttributeString(Attributes.Project, e.Project.ProjectName);
     }
     // add an item to the project stack
     _projectStack.Push(null);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Signals that a build has started.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 /// <remarks>
 /// This event is fired before any targets have started.
 /// </remarks>
 public virtual void BuildStarted(object sender, BuildEventArgs e)
 {
     _buildReports.Push(new BuildReport(DateTime.Now));
 }
Exemplo n.º 22
0
        /// <summary>
        /// Signals that the last target has finished.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        /// <remarks>
        /// This event will still be fired if an error occurred during the build.
        /// </remarks>
        public virtual void BuildFinished(object sender, BuildEventArgs e)
        {
            Exception error            = e.Exception;
            int       indentationLevel = 0;

            if (e.Project != null)
            {
                indentationLevel = e.Project.IndentationLevel * e.Project.IndentationSize;
            }

            BuildReport report = (BuildReport)_buildReports.Pop();

            if (error == null)
            {
                OutputMessage(Level.Info, string.Empty, indentationLevel);
                if (report.Errors == 0 && report.Warnings == 0)
                {
                    OutputMessage(Level.Info, "BUILD SUCCEEDED", indentationLevel);
                }
                else
                {
                    OutputMessage(Level.Info, string.Format(CultureInfo.InvariantCulture,
                                                            ResourceUtils.GetString("String_BuildSucceeded"),
                                                            report.Errors, report.Warnings), indentationLevel);
                }
                OutputMessage(Level.Info, string.Empty, indentationLevel);
            }
            else
            {
                OutputMessage(Level.Error, string.Empty, indentationLevel);
                if (report.Errors == 0 && report.Warnings == 0)
                {
                    OutputMessage(Level.Error, "BUILD FAILED", indentationLevel);
                }
                else
                {
                    OutputMessage(Level.Info, string.Format(CultureInfo.InvariantCulture,
                                                            ResourceUtils.GetString("String_BuildFailed"),
                                                            report.Errors, report.Warnings), indentationLevel);
                }
                OutputMessage(Level.Error, string.Empty, indentationLevel);

                if (error is BuildException)
                {
                    if (Threshold <= Level.Verbose)
                    {
                        OutputMessage(Level.Error, error.ToString(), indentationLevel);
                    }
                    else
                    {
                        if (error.Message != null)
                        {
                            OutputMessage(Level.Error, error.Message, indentationLevel);
                        }

                        // output nested exceptions
                        Exception nestedException           = error.InnerException;
                        int       exceptionIndentationLevel = indentationLevel;
                        int       indentShift = 4; //e.Project.IndentationSize;
                        while (nestedException != null && !StringUtils.IsNullOrEmpty(nestedException.Message))
                        {
                            exceptionIndentationLevel += indentShift;
                            OutputMessage(Level.Error, nestedException.Message, exceptionIndentationLevel);
                            nestedException = nestedException.InnerException;
                        }
                    }
                }
                else
                {
                    OutputMessage(Level.Error, "INTERNAL ERROR", indentationLevel);
                    OutputMessage(Level.Error, string.Empty, indentationLevel);
                    OutputMessage(Level.Error, error.ToString(), indentationLevel);
                    OutputMessage(Level.Error, string.Empty, indentationLevel);
                    OutputMessage(Level.Error, "Please send bug report to [email protected].", indentationLevel);
                }

                OutputMessage(Level.Error, string.Empty, indentationLevel);
            }

            // output total build time
            TimeSpan buildTime = DateTime.Now - report.StartTime;

            OutputMessage(Level.Info, string.Format(CultureInfo.InvariantCulture,
                                                    ResourceUtils.GetString("String_TotalTime") + Environment.NewLine,
                                                    Math.Round(buildTime.TotalSeconds, 1)), indentationLevel);

            // make sure all messages are written to the underlying storage
            Flush();
        }
Exemplo n.º 23
0
 /// <summary>
 /// Signals that a task has started.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 public virtual void TaskStarted(object sender, BuildEventArgs e)
 {
 }
Exemplo n.º 24
0
        /// <summary>
        /// Outputs an indented message to the build log if its priority is 
        /// greather than or equal to the <see cref="Threshold" /> of the 
        /// logger.
        /// </summary>
        /// <param name="e">The event to output.</param>
        /// <param name="indentationLength">TODO</param>
        private void OutputMessage(BuildEventArgs e, int indentationLength)
        {
            if (!_stopped && (e.MessageLevel >= Threshold)) {
                if (OutputWriter == null) {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                        "Tried to write to an invalid FileLogListener instance '{0}'!",
                        Name), Location.UnknownLocation);
                }

                string txt = e.Message;

                // beautify the message a bit
                txt = txt.Replace("\t", " "); // replace tabs with spaces
                txt = txt.Replace("\r", ""); // get rid of carriage returns

                // split the message by lines - the separator is "\n" since we've eliminated
                // \r characters
                string[] lines = txt.Split('\n');
                string label = String.Empty;

                if (e.Task != null && !EmacsMode) {
                    label = "[" + e.Task.Name + "] ";
                    label = label.PadLeft(e.Project.IndentationSize);
                }

                if (indentationLength > 0) {
                    label = new String(' ', indentationLength) + label;
                }

                foreach (string line in lines) {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(label);
                    sb.Append(line);

                    string indentedMessage = sb.ToString();

                    OutputWriter.WriteLine(indentedMessage);

                    Log(indentedMessage);
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Signals that the last target has finished.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        /// <remarks>
        /// This event will still be fired if an error occurred during the build.
        /// </remarks>
        public virtual void BuildFinished(object sender, BuildEventArgs e)
        {
            Exception error = e.Exception;
            int indentationLevel = 0;

            if (e.Project != null) {
                indentationLevel = e.Project.IndentationLevel * e.Project.IndentationSize;
            }

            if (error == null) {
                OutputMessage(Level.Info, "", indentationLevel);
                OutputMessage(Level.Info, "BUILD SUCCEEDED", indentationLevel);
                OutputMessage(Level.Info, "", indentationLevel);
            } else {
                OutputMessage(Level.Error, "", indentationLevel);
                OutputMessage(Level.Error, "BUILD FAILED", indentationLevel);
                OutputMessage(Level.Error, "", indentationLevel);

                if (error is BuildException) {
                    if (Threshold <= Level.Verbose) {
                        OutputMessage(Level.Error, error.ToString(), indentationLevel);
                    } else {
                        if (error.Message != null) {
                            OutputMessage(Level.Error, error.Message, indentationLevel);
                        }
                        if (error.InnerException != null && error.InnerException.Message != null) {
                            OutputMessage(Level.Error, error.InnerException.Message, indentationLevel);
                        }
                    }
                } else {
                    OutputMessage(Level.Error, "INTERNAL ERROR", indentationLevel);
                    OutputMessage(Level.Error, "", indentationLevel);
                    OutputMessage(Level.Error, error.ToString(), indentationLevel);
                    OutputMessage(Level.Error, "", indentationLevel);
                    OutputMessage(Level.Error, "Please send bug report to [email protected].", indentationLevel);
                }

                OutputMessage(Level.Info, "", indentationLevel);
            }

            // make sure all messages are written to the underlying storage
            Flush();
        }
Exemplo n.º 26
0
 public void TargetStarted(object sender, BuildEventArgs e)
 {
     if (e.Target != null && e.Target.Name == _hideTarget) {
         return;
     }
     Enqueue(new LogEvent(_src, sender, e, LogEventType.TargetStarted));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Signals that a message has been logged.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 /// <remarks>
 /// Only messages with a priority higher or equal to the threshold of
 /// the logger will actually be output in the build log.
 /// </remarks>
 public virtual void MessageLogged(object sender, BuildEventArgs e)
 {
     // output the message
     OutputMessage(e);
 }
Exemplo n.º 28
0
 public void BuildStarted(object sender, BuildEventArgs e)
 {
     Enqueue(new LogEvent(_src, sender, e, LogEventType.BuildStarted));
 }
Exemplo n.º 29
0
        /// <summary>
        /// Signals that a target has started.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        public virtual void TargetStarted(object sender, BuildEventArgs e)
        {
            int indentationLevel = 0;

            if (e.Project != null) {
                indentationLevel = e.Project.IndentationLevel * e.Project.IndentationSize;
            }

            if (e.Target != null) {
                OutputMessage(Level.Info, string.Empty, indentationLevel);
                OutputMessage(Level.Info, string.Format(CultureInfo.InvariantCulture,
                    "{0}:", e.Target.Name), indentationLevel);
                OutputMessage(Level.Info, string.Empty, indentationLevel);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Signals that the last target has finished.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        /// <remarks>
        /// This event will still be fired if an error occurred during the build.
        /// </remarks>
        public void BuildFinished(object sender, BuildEventArgs e)
        {
            lock (_xmlWriter) {
                if (e.Exception != null) {
                    _xmlWriter.WriteStartElement("failure");
                    WriteErrorNode(e.Exception);
                    _xmlWriter.WriteEndElement();
                }

                // output total build duration
                WriteDuration();

                // close buildresults node
                _xmlWriter.WriteEndElement();
                _xmlWriter.Flush();
            }

            // remove an item from the project stack
            _projectStack.Pop();

            // check if there are still nested projects executing
            if (_projectStack.Count != 0) {
                // do not yet persist build results, as the main project is
                // not finished yet
                return;
            }

            try {
                // write results to file
                if (OutputWriter != null) {
                    OutputWriter.Write(_buffer.ToString());
                    OutputWriter.Flush();
                }
                else { // Xmlogger is used as BuildListener
                    string outFileName = e.Project.Properties["XmlLogger.file"];
                    if (outFileName == null) {
                        outFileName = "log.xml";
                    }
                    // convert to full path relative to project base directory
                    outFileName = e.Project.GetFullPath(outFileName);
                    // write build log to file
                    using (StreamWriter writer = new StreamWriter(new FileStream(outFileName, FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8)) {
                        writer.Write(_buffer.ToString());
                    }
                }
            }
            catch (Exception ex) {
                throw new BuildException("Unable to write to log file.", ex);
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Signals that the last target has finished, and send an e-mail with
        /// the build results.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        public override void BuildFinished(object sender, BuildEventArgs e)
        {
            base.BuildFinished(sender, e);

            // remove an item from the project stack
            _projectStack.Pop();

            // check if there are still nested projects executing
            if (_projectStack.Count != 0)
            {
                // do not yet send the mail, as it should only be sent when the
                // main project is finished
                return;
            }

            Encoding           bodyEncoding = null;
            Project            project      = e.Project;
            PropertyDictionary properties   = project.Properties;

            bool   success = (e.Exception == null);
            string prefix  = success ? "success" : "failure";

            try {
                string propertyValue = GetPropertyValue(properties, prefix + ".notify", "true");

                bool notify = true;

                try {
                    notify = Convert.ToBoolean(propertyValue, CultureInfo.InvariantCulture);
                } catch {
                    notify = true;
                }

                propertyValue = GetPropertyValue(properties, "body.encoding", "");

                try {
                    if (propertyValue != null && propertyValue.Length > 0)
                    {
                        bodyEncoding = Encoding.GetEncoding(propertyValue);
                    }
                } catch {
                    // ignore invalid encoding
                }

                if (!notify)
                {
                    return;
                }

                MailMessage mailMessage = new MailMessage();
                mailMessage.From    = GetPropertyValue(properties, "from", null);
                mailMessage.To      = GetPropertyValue(properties, prefix + ".to", null);
                mailMessage.Subject = GetPropertyValue(properties, prefix + ".subject",
                                                       (success) ? "Build Success" : "Build Failure");
                mailMessage.Body = _buffer.ToString();

                if (bodyEncoding != null)
                {
                    mailMessage.BodyEncoding = bodyEncoding;
                }

                // send the message
                SmtpMail.SmtpServer = GetPropertyValue(properties, "mailhost", "localhost");
                SmtpMail.Send(mailMessage);
            } catch (Exception ex) {
                Console.WriteLine("MailLogger failed to send e-mail!");
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Signals that a message has been logged.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        /// <remarks>
        /// Only messages with a priority higher or equal to the threshold of 
        /// the logger will actually be output in the build log.
        /// </remarks>
        public void MessageLogged(object sender, BuildEventArgs e)
        {
            if (e.MessageLevel >= Threshold) {
                string rawMessage = StripFormatting(e.Message.Trim());
                if (IsJustWhiteSpace(rawMessage)) {
                    return;
                }

                lock (_xmlWriter) {
                    _xmlWriter.WriteStartElement(Elements.Message);

                    // write message level as attribute
                    _xmlWriter.WriteAttributeString(Attributes.MessageLevel, e.MessageLevel.ToString());

                    if (IsValidXml(rawMessage)) {
                        rawMessage = Regex.Replace(rawMessage, @"<\?.*\?>", string.Empty);
                        _xmlWriter.WriteRaw(rawMessage);
                    }
                    else {
                        _xmlWriter.WriteCData(StripCData(rawMessage));
                    }
                    _xmlWriter.WriteEndElement();
                    _xmlWriter.Flush();
                }
            }
        }
Exemplo n.º 33
0
        /// <summary>
        /// Signals that a message has been logged.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
        /// <remarks>
        /// Only messages with a priority higher or equal to the threshold of 
        /// the logger will actually be output in the build log.
        /// </remarks>
        public virtual void MessageLogged(object sender, BuildEventArgs e)
        {
            if (_buildReports.Count > 0) {
                if (e.MessageLevel == Level.Error) {
                    BuildReport report = (BuildReport) _buildReports.Peek();
                    report.Errors++;
                } else if (e.MessageLevel == Level.Warning) {
                    BuildReport report = (BuildReport) _buildReports.Peek();
                    report.Warnings++;
                }
            }

            // output the message
            OutputMessage(e);
        }
Exemplo n.º 34
0
 /// <summary>
 /// Signals that a task has started.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A <see cref="BuildEventArgs" /> object that contains the event data.</param>
 public void TaskStarted(object sender, BuildEventArgs e)
 {
     lock (_xmlWriter) {
         _stopWatchStack.PushStart();
         _xmlWriter.WriteStartElement(Elements.Task);
         WriteNameAttribute(e.Task.Name);
         _xmlWriter.Flush();
     }
 }
Exemplo n.º 35
0
        /// <summary>
        /// Outputs an indented message to the build log if its priority is 
        /// greather than or equal to the <see cref="Threshold" /> of the 
        /// logger.
        /// </summary>
        /// <param name="e">The event to output.</param>
        /// <param name="indentationLength">The number of characters that the message should be indented.</param>
        private void OutputMessage(BuildEventArgs e, int indentationLength)
        {
            if (e.MessageLevel >= Threshold) {
                string txt = e.Message;

                // beautify the message a bit
                txt = txt.Replace("\t", " "); // replace tabs with spaces
                txt = txt.Replace("\r", ""); // get rid of carriage returns

                // split the message by lines - the separator is "\n" since we've eliminated
                // \r characters
                string[] lines = txt.Split('\n');
                string label = String.Empty;

                if (e.Task != null && !EmacsMode) {
                    label = "[" + e.Task.Name + "] ";
                    label = label.PadLeft(e.Project.IndentationSize);
                }

                if (indentationLength > 0) {
                    label = new String(' ', indentationLength) + label;
                }

                foreach (string line in lines) {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(label);
                    sb.Append(line);

                    string indentedMessage = sb.ToString();

                    // output the message to the console
                    Console.Out.WriteLine(indentedMessage);

                    // if an OutputWriter was set, write the message to it
                    if (OutputWriter != null) {
                        OutputWriter.WriteLine(indentedMessage);
                    }

                    Log(indentedMessage);
                }
            }
        }