public OutputParserResult ParseOutput(IEnumerable <string> inputLines)
        {
            OutputParserResult parserResult = new OutputParserResult();

            if (inputLines == null)
            {
                return(parserResult);
            }

            List <string> outputLines     = new List <string>();
            List <string> processingLines = new List <string>();

            processingLines.AddRange(inputLines);

            foreach (string line in processingLines)
            {
                TaskError error = IsErrorMatch(line);

                if (error != null)
                {
                    parserResult.ErrorList.Add(error);
                }
                else
                {
                    outputLines.Add(line);
                }
            }

            parserResult.OutputLines = outputLines;
            return(parserResult);
        }
        public OutputParserResult ParseOutput(IEnumerable <string> inputLines)
        {
            OutputParserResult parserResult = new OutputParserResult();

            if (inputLines == null)
            {
                return(parserResult);
            }


            parserResult.OutputLines = ParseOutputInternal(inputLines, parserResult);

            return(parserResult);
        }
Ejemplo n.º 3
0
        public OutputParserResult ParseOutput(IEnumerable <string> inputLines)
        {
            OutputParserResult parserResult = new OutputParserResult();

            if (inputLines == null)
            {
                return(parserResult);
            }

            List <string> outputLines = new List <string>();

            foreach (var line in inputLines)
            {
                var cleanLine = _colorSwitchRegex.Replace(line, "");

                if (cleanLine.Contains(":\\"))
                {
                    var trimmed = cleanLine.Trim();
                    if (File.Exists(trimmed))
                    {
                        _lastFile = trimmed;
                    }
                }

                // If there is no file name, proceed to next line
                if (string.IsNullOrEmpty(_lastFile))
                {
                    outputLines.Add(line);
                    continue;
                }

                Match match = _regex.Match(cleanLine);

                if (match.Success)
                {
                    TaskError error = TaskHelpers.CreateErrorFromRegex(match, _lastFile);
                    parserResult.ErrorList.Add(error);
                }
                else
                {
                    outputLines.Add(line);
                }
            }

            parserResult.OutputLines = outputLines;

            return(parserResult);
        }
        private static List <IErrorListItem> RemoveErrorDuplicates(ITaskRunnerNode task,
                                                                   string projectName,
                                                                   OutputParserResult parserOutput,
                                                                   OutputErrorSnapshot currentSnapshot)
        {
            List <IErrorListItem> newErrors = new List <IErrorListItem>();

            foreach (IErrorListItem error in parserOutput.ErrorList)
            {
                error.ProjectName = projectName;
                error.ErrorSource = task.Name;
                error.Filename    = Path.Combine(task.Command.WorkingDirectory, error.Filename);
                error.Command     = task.Command;

                if (!currentSnapshot.Errors.Contains(error))
                {
                    newErrors.Add(error);
                }
            }

            return(newErrors);
        }
        /// <summary>
        /// Handles the command output (inputLines) and generates errors as appropriate.
        /// </summary>
        /// <param name="task">Task being executed</param>
        /// <param name="projectName">Project name of the task</param>
        /// <param name="inputLines">Set of command output messages to be parsed</param>
        /// <returns></returns>
        public IEnumerable <string> HandleLines(ITaskRunnerNode task, string projectName, IEnumerable <string> lines)
        {
            bool errorListNeedsUpdate = false;

            // Remove existing Factory errors associated with the running task after idle time
            if (_timer.ElapsedMilliseconds > 1000)
            {
                _factory.ClearErrors(task);
                errorListNeedsUpdate = true;
            }


            OutputParserResult parserOutput = _outputParser.ParseOutput(lines);

            if (parserOutput != null && parserOutput.ErrorList.Count() > 0)
            {
                OutputErrorSnapshot   currentSnapshot = _factory.CurrentSnapshot as OutputErrorSnapshot;
                List <IErrorListItem> newErrors       = RemoveErrorDuplicates(task, projectName, parserOutput, currentSnapshot);

                if (newErrors.Count > 0)
                {
                    _factory.AddErrorItems(newErrors);
                    errorListNeedsUpdate = true;
                }
            }

            // Only update the errors list if Factory errors has changed.
            if (errorListNeedsUpdate)
            {
                UpdateErrorsList();
            }

            // Reset and start the timer to measure new elapsed time between new line(s) inputs
            _timer.Reset();
            _timer.Start();

            return(parserOutput.OutputLines);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Parses a collection of strings and returns a OutputParserResult
        /// with the set of parsed errors and set of "unmatched" lines to be passed along to the
        /// next listeners
        /// </summary>
        /// <param name="inputLines"></param>
        /// <returns></returns>
        public OutputParserResult ParseOutput(IEnumerable <string> inputLines)
        {
            OutputParserResult parserResult = new OutputParserResult();

            if (inputLines == null)
            {
                return(parserResult);
            }

            List <string> outputLines     = new List <string>();
            List <string> processingLines = new List <string>();

            processingLines.AddRange(_linesBuffer);
            processingLines.AddRange(inputLines);

            for (int index = _linesBuffer.Count; index < processingLines.Count; index++)
            {
                LineType lineType = ParseLine(processingLines[index]);
                switch (lineType)
                {
                case LineType.NoMatch:
                    if (_isBuffering)
                    {
                        outputLines.AddRange(_linesBuffer);
                        outputLines.Add(processingLines[index]);

                        _isBuffering = false;
                        _linesBuffer.Clear();
                        _errorsBuffer.Clear();
                        _previousFileName = "";
                    }
                    else
                    {
                        outputLines.Add(processingLines[index]);
                    }

                    break;

                case LineType.FileInfo:
                    _isBuffering = true;
                    _linesBuffer.Add(processingLines[index]);

                    break;

                case LineType.LineColumnInfo:
                    if (_isBuffering)
                    {
                        _linesBuffer.Add(processingLines[index]);
                    }
                    else
                    {
                        outputLines.Add(processingLines[index]);
                    }
                    break;

                case LineType.SummaryInfo:
                    if (_isBuffering)
                    {
                        parserResult.ErrorList.AddRange(GenerateErrorListItems());

                        _isBuffering = false;
                        _linesBuffer.Clear();
                        _errorsBuffer.Clear();
                        _previousFileName = "";
                    }
                    else
                    {
                        outputLines.Add(processingLines[index]);
                    }
                    break;
                }
            }

            parserResult.OutputLines = outputLines;
            return(parserResult);
        }
        private IEnumerable <string> ParseOutputInternal(IEnumerable <string> inputLines, OutputParserResult parserResult)
        {
            foreach (var line in inputLines)
            {
                bool matchFound = false;

                if (line.Length < 200)
                {
                    var cleanLine = _colorSwitchRegex.Replace(line, string.Empty);

                    foreach (var regex in _regexes)
                    {
                        Match match = regex.Match(cleanLine);

                        if (match.Success)
                        {
                            TaskError error = TaskHelpers.CreateErrorFromRegex(match);
                            parserResult.ErrorList.Add(error);
                            matchFound = true;
                            break;
                        }
                    }
                }

                if (!matchFound)
                {
                    yield return(line);
                }
            }
        }