public static int Run(RewriteOptions rewriteOptions) { try { rewriteOptions = ValidateOptions(rewriteOptions); SarifLog actualLog = MultitoolFileHelpers.ReadSarifFile(rewriteOptions.InputFilePath); LoggingOptions loggingOptions = rewriteOptions.ConvertToLoggingOptions(); SarifLog reformattedLog = new ReformattingVisitor(loggingOptions).VisitSarifLog(actualLog); string fileName = GetOutputFileName(rewriteOptions); var formatting = rewriteOptions.PrettyPrint ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None; MultitoolFileHelpers.WriteSarifFile(reformattedLog, fileName, formatting); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(1); } return(0); }
public static int Run(RewriteOptions rewriteOptions) { try { rewriteOptions = ValidateOptions(rewriteOptions); string fileName = GetOutputFileName(rewriteOptions); Newtonsoft.Json.Formatting formatting = rewriteOptions.PrettyPrint ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None; JsonSerializerSettings settings = new JsonSerializerSettings() { ContractResolver = SarifContractResolver.Instance, Formatting = Newtonsoft.Json.Formatting.Indented }; string sarifText = File.ReadAllText(rewriteOptions.InputFilePath); SarifLog actualLog = JsonConvert.DeserializeObject <SarifLog>(sarifText, settings); LoggingOptions loggingOptions = rewriteOptions.ConvertToLoggingOptions(); SarifLog reformattedLog = new ReformattingVisitor(loggingOptions).VisitSarifLog(actualLog); File.WriteAllText(fileName, JsonConvert.SerializeObject(reformattedLog, settings)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(1); } return(0); }
public static int Run(RewriteOptions rewriteOptions) { try { rewriteOptions = ValidateOptions(rewriteOptions); SarifLog actualLog = MultitoolFileHelpers.ReadSarifFile <SarifLog>(rewriteOptions.InputFilePath); OptionallyEmittedData dataToInsert = OptionallyEmittedData.None; if (rewriteOptions.DataToInsert != null) { Array.ForEach(rewriteOptions.DataToInsert, data => dataToInsert |= data); } SarifLog reformattedLog = new ReformattingVisitor(dataToInsert).VisitSarifLog(actualLog); string fileName = CommandUtilities.GetTransformedOutputFileName(rewriteOptions); var formatting = rewriteOptions.PrettyPrint ? Formatting.Indented : Formatting.None; MultitoolFileHelpers.WriteSarifFile(reformattedLog, fileName, formatting); } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(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); }
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); }
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. OptionallyEmittedData dataToInsert = OptionallyEmittedData.None; if (mergeOptions.DataToInsert != null) { Array.ForEach(mergeOptions.DataToInsert, data => dataToInsert |= data); } SarifLog reformattedLog = new ReformattingVisitor(dataToInsert).VisitSarifLog(combinedLog); // Write output to file. string outputName = Path.Combine(mergeOptions.OutputFolderPath, GetOutputFileName(mergeOptions)); var formatting = mergeOptions.PrettyPrint ? Formatting.Indented : Formatting.None; Directory.CreateDirectory(mergeOptions.OutputFolderPath); MultitoolFileHelpers.WriteSarifFile(reformattedLog, outputName, formatting); } catch (Exception ex) { Console.WriteLine(ex); return(1); } return(0); }