Exemplo n.º 1
0
        /// <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">Logging options that configure output.</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));
            }

            LogicalLocationsDictionary.Clear();

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

            ISet <Result> results;

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

            var tool = new Tool
            {
                Name = "AndroidStudio"
            };

            var fileInfoFactory = new FileInfoFactory(null, dataToInsert);
            Dictionary <string, FileData> fileDictionary = fileInfoFactory.Create(results);

            var run = new Run()
            {
                Tool = tool
            };

            output.Initialize(run);

            if (fileDictionary != null && fileDictionary.Any())
            {
                output.WriteFiles(fileDictionary);
            }

            if (LogicalLocationsDictionary != null && LogicalLocationsDictionary.Any())
            {
                output.WriteLogicalLocations(LogicalLocationsDictionary);
            }

            output.OpenResults();
            output.WriteResults(results);
            output.CloseResults();
        }
Exemplo n.º 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));

            LogicalLocationsDictionary.Clear();

            var tool = new Tool
            {
                Name     = ToolFormat.PREfast,
                FullName = "PREfast Code Analysis"
            };

            var run = new Run()
            {
                Tool = tool
            };

            output.Initialize(run);

            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 fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension, dataToInsert);
                Dictionary <string, FileData> fileDictionary = fileInfoFactory.Create(results);

                if (fileDictionary?.Any() == true)
                {
                    output.WriteFiles(fileDictionary);
                }

                if (LogicalLocationsDictionary != null && LogicalLocationsDictionary.Any())
                {
                    output.WriteLogicalLocations(LogicalLocationsDictionary);
                }

                output.OpenResults();
                output.WriteResults(results);
                output.CloseResults();
            }
        }
        /// <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>
        public override void Convert(Stream input, IResultLogWriter output)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

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

            LogicalLocationsDictionary.Clear();

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

            ISet <Result> results;

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

            var tool = new Tool
            {
                Name = "AndroidStudio"
            };

            var fileInfoFactory = new FileInfoFactory(uri => MimeType.Java);
            Dictionary <string, IList <FileData> > fileDictionary = fileInfoFactory.Create(results);

            output.WriteTool(tool);

            if (fileDictionary != null && fileDictionary.Any())
            {
                output.WriteFiles(fileDictionary);
            }

            if (LogicalLocationsDictionary != null && LogicalLocationsDictionary.Any())
            {
                output.WriteLogicalLocations(LogicalLocationsDictionary);
            }

            output.OpenResults();
            output.WriteResults(results);
            output.CloseResults();
        }
Exemplo n.º 4
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)));
            }

            LogicalLocationsDictionary.Clear();

            var context = new FxCopLogReader.Context();

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

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

            Tool tool = new Tool
            {
                Name = "FxCop"
            };

            var fileInfoFactory = new FileInfoFactory(MimeType.DetermineFromFileExtension, dataToInsert);
            Dictionary <string, FileData> fileDictionary = fileInfoFactory.Create(results);

            var run = new Run()
            {
                Tool = tool
            };

            output.Initialize(run);

            if (fileDictionary != null && fileDictionary.Any())
            {
                output.WriteFiles(fileDictionary);
            }

            if (LogicalLocationsDictionary != null && LogicalLocationsDictionary.Any())
            {
                output.WriteLogicalLocations(LogicalLocationsDictionary);
            }

            output.OpenResults();
            output.WriteResults(results);
            output.CloseResults();
        }