예제 #1
0
        public static int Run(MergeOptions mergeOptions)
        {
            try
            {
                var sarifFiles = MultitoolFileHelpers.CreateTargetsSet(mergeOptions.TargetFileSpecifiers, mergeOptions.Recurse);

                var allRuns = ParseFiles(sarifFiles);

                // Build one SarifLog with all the Runs.
                SarifLog combinedLog = allRuns.Merge();

                // Reformat the SARIF log if we need to.
                LoggingOptions loggingOptions = mergeOptions.ConvertToLoggingOptions();
                SarifLog       reformattedLog = new ReformattingVisitor(loggingOptions).VisitSarifLog(combinedLog);

                // Write output to file.
                string outputName = Path.Combine(mergeOptions.OutputFolderPath, GetOutputFileName(mergeOptions));

                var formatting = mergeOptions.PrettyPrint
                    ? Newtonsoft.Json.Formatting.Indented
                    : Newtonsoft.Json.Formatting.None;

                Directory.CreateDirectory(mergeOptions.OutputFolderPath);
                MultitoolFileHelpers.WriteSarifFile(reformattedLog, outputName, formatting);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(1);
            }
            return(0);
        }
예제 #2
0
        public static int Run(MergeOptions mergeOptions)
        {
            var sarifFiles = GetSarifFiles(mergeOptions);

            var allRuns = GetAllRuns(sarifFiles);

            // Build one SarifLog with all the Runs.
            SarifLog combinedLog = new SarifLog(SarifVersion.OneZeroZero.ConvertToSchemaUri(),
                                                SarifVersion.OneZeroZero, allRuns);

            // Write output to file.
            string outputName = GetOutputFileName(mergeOptions);
            var    formatting = mergeOptions.PrettyPrint
                ? Newtonsoft.Json.Formatting.Indented
                : Newtonsoft.Json.Formatting.None;
            var settings = new JsonSerializerSettings
            {
                ContractResolver = SarifContractResolver.Instance,
                Formatting       = formatting
            };
            LoggingOptions loggingOptions = mergeOptions.ConvertToLoggingOptions();
            SarifLog       reformattedLog = new ReformattingVisitor(loggingOptions).VisitSarifLog(combinedLog);

            File.WriteAllText(outputName, JsonConvert.SerializeObject(reformattedLog, settings));

            return(0);
        }