Initialize() public method

Initializes the SARIF log by emitting properties and other constructs sufficient to being populating a run with results.
public Initialize ( string id, string correlationId ) : void
id string A string that uniquely identifies a run.
correlationId string A global identifier for a run that permits correlation with a larger automation process.
return void
 public void ResultLogJsonWriter_CannotWriteInvocationTwice()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 var run = new Run()
                 {
                     Tool = DefaultTool, Invocations = new[] { s_invocation }
                 };
                 uut.Initialize(run);
                 Assert.Throws <InvalidOperationException>(() => uut.Initialize(run));
             }
 }
Exemplo n.º 2
0
        public SarifLogger(
            TextWriter textWriter,
            LoggingOptions loggingOptions      = DefaultLoggingOptions,
            OptionallyEmittedData dataToInsert = OptionallyEmittedData.None,
            Tool tool = null,
            Run run   = null,
            IEnumerable <string> analysisTargets           = null,
            IEnumerable <string> invocationTokensToRedact  = null,
            IEnumerable <string> invocationPropertiesToLog = null,
            string defaultFileEncoding = null) : this(textWriter, loggingOptions)
        {
            _run = run ?? CreateRun(
                analysisTargets,
                dataToInsert,
                invocationTokensToRedact,
                invocationPropertiesToLog,
                defaultFileEncoding);



            tool = tool ?? Tool.CreateFromAssemblyData();
            SetSarifLoggerVersion(tool);

            _run.Tool     = tool;
            _dataToInsert = dataToInsert;
            _issueLogJsonWriter.Initialize(_run);
        }
Exemplo n.º 3
0
        public SarifLogger(
            TextWriter textWriter,
            LoggingOptions loggingOptions      = DefaultLoggingOptions,
            OptionallyEmittedData dataToInsert = OptionallyEmittedData.None,
            OptionallyEmittedData dataToRemove = OptionallyEmittedData.None,
            Tool tool = null,
            Run run   = null,
            IEnumerable <string> analysisTargets           = null,
            IEnumerable <string> invocationTokensToRedact  = null,
            IEnumerable <string> invocationPropertiesToLog = null,
            string defaultFileEncoding = null) : this(textWriter, loggingOptions)
        {
            if (dataToInsert.HasFlag(OptionallyEmittedData.Hashes))
            {
                AnalysisTargetToHashDataMap = HashUtilities.MultithreadedComputeTargetFileHashes(analysisTargets);
            }

            _run = run ?? CreateRun(
                analysisTargets,
                dataToInsert,
                dataToRemove,
                invocationTokensToRedact,
                invocationPropertiesToLog,
                defaultFileEncoding,
                AnalysisTargetToHashDataMap);

            tool = tool ?? Tool.CreateFromAssemblyData();

            _run.Tool     = tool;
            _dataToInsert = dataToInsert;
            _dataToRemove = dataToRemove;
            _issueLogJsonWriter.Initialize(_run);
        }
Exemplo n.º 4
0
        public SarifLogger(
            TextWriter textWriter,
            LogFilePersistenceOptions logFilePersistenceOptions = DefaultLogFilePersistenceOptions,
            OptionallyEmittedData dataToInsert = OptionallyEmittedData.None,
            OptionallyEmittedData dataToRemove = OptionallyEmittedData.None,
            Tool tool = null,
            Run run   = null,
            IEnumerable <string> analysisTargets           = null,
            IEnumerable <string> invocationTokensToRedact  = null,
            IEnumerable <string> invocationPropertiesToLog = null,
            string defaultFileEncoding        = null,
            bool closeWriterOnDispose         = true,
            IEnumerable <FailureLevel> levels = null,
            IEnumerable <ResultKind> kinds    = null) : this(textWriter, logFilePersistenceOptions, closeWriterOnDispose, levels, kinds)
        {
            if (dataToInsert.HasFlag(OptionallyEmittedData.Hashes))
            {
                AnalysisTargetToHashDataMap = HashUtilities.MultithreadedComputeTargetFileHashes(analysisTargets);
            }

            _run = run ?? new Run();

            if (dataToInsert.HasFlag(OptionallyEmittedData.RegionSnippets) || dataToInsert.HasFlag(OptionallyEmittedData.ContextRegionSnippets))
            {
                _insertOptionalDataVisitor = new InsertOptionalDataVisitor(dataToInsert, _run);
            }

            EnhanceRun(
                analysisTargets,
                dataToInsert,
                dataToRemove,
                invocationTokensToRedact,
                invocationPropertiesToLog,
                defaultFileEncoding,
                AnalysisTargetToHashDataMap);

            tool = tool ?? Tool.CreateFromAssemblyData();

            _run.Tool     = tool;
            _dataToInsert = dataToInsert;
            _dataToRemove = dataToRemove;
            _issueLogJsonWriter.Initialize(_run);

            // Map existing Rules to ensure duplicates aren't created
            if (_run.Tool.Driver?.Rules != null)
            {
                for (int i = 0; i < _run.Tool.Driver.Rules.Count; ++i)
                {
                    RuleToIndexMap[_run.Tool.Driver.Rules[i]] = i;
                }
            }

            _persistArtifacts =
                (_dataToInsert & OptionallyEmittedData.Hashes) != 0 ||
                (_dataToInsert & OptionallyEmittedData.TextFiles) != 0 ||
                (_dataToInsert & OptionallyEmittedData.BinaryFiles) != 0;
        }
 public void ResultLogJsonWriter_CannotWriteToolToDisposedWriter()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 uut.Dispose();
                 Assert.Throws <InvalidOperationException>(() => uut.Initialize(new Run()
                 {
                     Tool = DefaultTool
                 }));
             }
 }
Exemplo n.º 6
0
 public void ResultLogJsonWriter_CannotWriteConfigurationNotificationsTwice()
 {
     using (var str = new StringWriter())
         using (var json = new JsonTextWriter(str))
             using (var uut = new ResultLogJsonWriter(json))
             {
                 var run = new Run()
                 {
                     Tool = DefaultTool
                 };
                 uut.Initialize(run);
                 uut.WriteConfigurationNotifications(s_notifications);
                 Assert.Throws <InvalidOperationException>(() => uut.WriteConfigurationNotifications(s_notifications));
             }
 }
Exemplo n.º 7
0
        public SarifLogger(
            TextWriter textWriter,
            LoggingOptions loggingOptions      = DefaultLoggingOptions,
            OptionallyEmittedData dataToInsert = OptionallyEmittedData.None,
            OptionallyEmittedData dataToRemove = OptionallyEmittedData.None,
            Tool tool = null,
            Run run   = null,
            IEnumerable <string> analysisTargets           = null,
            IEnumerable <string> invocationTokensToRedact  = null,
            IEnumerable <string> invocationPropertiesToLog = null,
            string defaultFileEncoding = null,
            bool closeWriterOnDispose  = true) : this(textWriter, loggingOptions, closeWriterOnDispose)
        {
            if (dataToInsert.HasFlag(OptionallyEmittedData.Hashes))
            {
                AnalysisTargetToHashDataMap = HashUtilities.MultithreadedComputeTargetFileHashes(analysisTargets);
            }

            _run = run ?? CreateRun(
                analysisTargets,
                dataToInsert,
                dataToRemove,
                invocationTokensToRedact,
                invocationPropertiesToLog,
                defaultFileEncoding,
                AnalysisTargetToHashDataMap);

            tool = tool ?? Tool.CreateFromAssemblyData();

            _run.Tool     = tool;
            _dataToInsert = dataToInsert;
            _dataToRemove = dataToRemove;
            _issueLogJsonWriter.Initialize(_run);

            // Map existing Rules to ensure duplicates aren't created
            if (_run.Tool.Driver?.Rules != null)
            {
                for (int i = 0; i < _run.Tool.Driver.Rules.Count; ++i)
                {
                    RuleToIndexMap[_run.Tool.Driver.Rules[i]] = i;
                }
            }
        }