Ejemplo n.º 1
0
        /// <summary>
        /// Interface implementation for converting a stream in Fortify FPR format to a stream in
        /// SARIF format.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
        /// <param name="input">Stream in Fortify FPR format.</param>
        /// <param name="output">Stream in SARIF format.</param>
        /// <param name="loggingOptions">Logging options that configure output.</param>
        public override void Convert(Stream input, IResultLogWriter output, LoggingOptions loggingOptions)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var tool = new Tool
            {
                Name = FortifyToolName
            };

            _invocation = new Invocation();
            _results.Clear();
            _toolNotifications.Clear();
            _fileDictionary.Clear();
            _ruleDictionary.Clear();
            _aclToSnippetIdDictionary.Clear();
            _resultToSnippetIdDictionary.Clear();
            _snippetIdToSnippetTextDictionary.Clear();

            ParseFprFile(input);
            AddMessagesToResults();
            AddSnippetsToResults();
            AddSnippetsToAnnotatedCodeLocations();

            output.Initialize(id: _runId, automationId: _automationId);

            output.WriteTool(tool);
            output.WriteInvocation(_invocation);

            if (_fileDictionary.Any())
            {
                output.WriteFiles(_fileDictionary);
            }

            output.OpenResults();
            output.WriteResults(_results);
            output.CloseResults();

            if (_ruleDictionary.Any())
            {
                output.WriteRules(_ruleDictionary);
            }

            if (_toolNotifications.Any())
            {
                output.WriteToolNotifications(_toolNotifications);
            }
        }