Exemple #1
0
        private static void exportInstances(Options options, PumaLog pumaLog)
        {
            var outputFullPath = Path.Combine(options.Workspace, options.OutputFile);

            if (File.Exists(outputFullPath))
            {
                Console.WriteLine(string.Format("Output file already exists at location {0}", outputFullPath));
                return;
            }

            switch (options.ReportFormat)
            {
            case ReportFormat.MSBuild:
                exportToTextFile(pumaLog, outputFullPath);
                break;

            case ReportFormat.Sarif:
                exportToSarifFormat(pumaLog, outputFullPath);
                break;

            default:
                Console.WriteLine("Unsupported Report format.");
                break;
            }
        }
Exemple #2
0
        private static PumaLog parseBuildWarnings(Options o)
        {
            PumaLog instancelog = new PumaLog();

            using (FileStream stream = new FileStream(o.BuildFile, FileMode.Open))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    string line = null;
                    while ((line = reader.ReadLine()) != null)
                    {
                        PumaLogEntry instance = parseWarning(line);
                        if (instance != null)
                        {
                            instancelog.Add(instance);
                        }
                    }

                    //Kill the stream
                    reader.Dispose();
                }

                //Kill the stream
                stream.Dispose();
            }

            return(instancelog);
        }
Exemple #3
0
        public void Convert(PumaLog pumaLog, IResultLogWriter output)
        {
            pumaLog = pumaLog ?? throw new ArgumentNullException(nameof(pumaLog));
            output  = output ?? throw new ArgumentNullException(nameof(output));

            var run = new Run()
            {
                Tool = new Tool
                {
                    Name = "Puma Scan"
                }
            };

            output.Initialize(run);

            var results = new List <Result>();

            foreach (PumaLogEntry entry in pumaLog)
            {
                results.Add(CreateResult(entry));
            }

            output.OpenResults();
            output.WriteResults(results);
            output.CloseResults();
        }
Exemple #4
0
 private static void exportToSarifFormat(PumaLog pumaLog, string outputFileName)
 {
     using (var outputTextStream = File.Create(outputFileName))
         using (var outputTextWriter = new StreamWriter(outputTextStream))
             using (var outputJson = new JsonTextWriter(outputTextWriter))
             {
                 outputJson.Formatting = Formatting.Indented;
                 using (var output = new ResultLogJsonWriter(outputJson))
                 {
                     PumaLogConverter converter = new PumaLogConverter();
                     converter.Convert(pumaLog, output);
                 }
             }
 }
Exemple #5
0
        public static void Main(string[] args)
        {
            //Read cmd line args
            Options o = parseArgs(args);

            if (o == null)
            {
                return;
            }

            //Parse instances from the build file
            PumaLog instances = parseBuildWarnings(o);

            //Export instances to a new Jenkins formatted warnings file
            exportInstances(o, instances);
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            ErrorCode status = ErrorCode.Success;

            //Read cmd line args
            Options o = parseArgs(args);

            if (o == null)
            {
                status = ErrorCode.InvalidArguments;
                Environment.Exit((int)status);
            }

            try
            {
                //Parse instances from the build file
                PumaLog instances = parseBuildWarnings(o);

                //Write instances to disk in the requested format
                exportInstances(o, instances);

                //Check threhold requirements
                if (o.Errors != null & o.Errors.Count() > 0)
                {
                    foreach (string error in o.Errors)
                    {
                        if (instances.Any(i => i.RuleId.Equals(error)))
                        {
                            status = ErrorCode.ErrorThreshold;
                            Console.WriteLine($"Error threshold violation: {error}");
                            Console.WriteLine($"Exit code: {(int)status} - {status}");
                            Environment.Exit((int)status);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: { ex.ToString()}");
                Console.WriteLine($"Exit code: {(int)status} - {status}");
                Environment.Exit((int)status);
            }
        }
Exemple #7
0
        private static void exportToTextFile(PumaLog pumaLog, string outputFile)
        {
            using (FileStream stream = new FileStream(outputFile, FileMode.CreateNew))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    foreach (PumaLogEntry pumaLogEntry in pumaLog)
                    {
                        string warning = getBuildWarning(pumaLogEntry);
                        writer.Write(warning);
                        writer.WriteLine();
                    }

                    //Kill the stream
                    writer.Flush();
                    writer.Dispose();
                }

                //Kill the stream
                stream.Dispose();
            }
        }