/// <summary>
        /// Converts an Android Studio formatted log as input into a SARIF SarifLog using the output.
        /// </summary>
        /// <param name="input">The Android Studio formatted log.</param>
        /// <param name="output">The SarifLog to write the output to.</param>
        /// <param name="dataToInsert">Optionally emitted properties that should be written to log.</param>
        public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

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

            LogicalLocations.Clear();

            XmlReaderSettings settings = new XmlReaderSettings
            {
                IgnoreWhitespace             = true,
                IgnoreComments               = true,
                IgnoreProcessingInstructions = true,
                NameTable     = _nameTable,
                DtdProcessing = DtdProcessing.Ignore,
                XmlResolver   = null
            };

            IList <Result> results;

            using (XmlReader xmlReader = XmlReader.Create(input, settings))
            {
                results = ProcessAndroidStudioLog(xmlReader);
            }

            var run = new Run()
            {
                Tool = new Tool {
                    Driver = new ToolComponent {
                        Name = ToolName
                    }
                },
                ColumnKind       = ColumnKind.Utf16CodeUnits,
                LogicalLocations = this.LogicalLocations,
            };

            PersistResults(output, results, run);
        }
Exemple #2
0
        public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert)
        {
            input  = input ?? throw new ArgumentNullException(nameof(input));
            output = output ?? throw new ArgumentNullException(nameof(output));

            LogicalLocations.Clear();


            XmlReaderSettings settings = new XmlReaderSettings
            {
                DtdProcessing = DtdProcessing.Ignore,
                XmlResolver   = null
            };

            var serializer = new XmlSerializer(typeof(DefectList));

            using (var reader = XmlReader.Create(input, settings))
            {
                var defectList = (DefectList)serializer.Deserialize(reader);
                var results    = new List <Result>();
                foreach (Defect entry in defectList.Defects)
                {
                    results.Add(CreateResult(entry));
                }

                var run = new Run()
                {
                    Tool = new Tool
                    {
                        Driver = new ToolComponent
                        {
                            Name = ToolName, FullName = "PREfast Code Analysis"
                        }
                    },
                    ColumnKind       = ColumnKind.Utf16CodeUnits,
                    LogicalLocations = LogicalLocations
                };

                PersistResults(output, results, run);
            }
        }
Exemple #3
0
        /// <summary>
        /// Convert FxCop log to SARIF format stream
        /// </summary>
        /// <param name="input">FxCop log stream</param>
        /// <param name="output">output stream</param>
        /// <param name="dataToInsert">Optionally emitted properties that should be written to log.</param>
        public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert)
        {
            if (input == null)
            {
                throw (new ArgumentNullException(nameof(input)));
            }

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

            LogicalLocations.Clear();

            var context = new FxCopLogReader.Context();

            var results = new List <Result>();
            var rules   = new List <ReportingDescriptor>();
            var reader  = new FxCopLogReader();

            reader.RuleRead   += (FxCopLogReader.Context current) => { rules.Add(CreateRule(current)); };
            reader.ResultRead += (FxCopLogReader.Context current) => { results.Add(CreateResult(current)); };
            reader.Read(context, input);

            var run = new Run()
            {
                Tool = new Tool
                {
                    Driver = new ToolComponent
                    {
                        Name  = ToolName,
                        Rules = rules
                    }
                },
            };

            PersistResults(output, results, run);

            output.WriteLogicalLocations(LogicalLocations);
        }