コード例 #1
0
 public void AnalyzingTarget(IAnalysisContext context)
 {
     foreach (IAnalysisLogger logger in Loggers)
     {
         logger.AnalyzingTarget(context);
     }
 }
コード例 #2
0
 public void Log(ResultKind messageKind, IAnalysisContext context, string message)
 {
     foreach (IResultLogger logger in Loggers)
     {
         logger.Log(messageKind, context, message);
     }
 }
コード例 #3
0
        public static string BuildMessage(IAnalysisContext context, string messageFormat, params string[] arguments)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            // By convention, the first argument is always the target name,
            // which we retrieve from the context
            Debug.Assert(File.Exists(context.TargetUri.LocalPath));
            string targetName = context.TargetUri.GetFileName();

            string[] fullArguments = new string[arguments != null ? arguments.Length + 1 : 1];
            fullArguments[0] = targetName;

            if (fullArguments.Length > 1)
            {
                arguments.CopyTo(fullArguments, 1);
            }

            return String.Format(CultureInfo.InvariantCulture,
                messageFormat, fullArguments);
        }
コード例 #4
0
        public void Log(ResultKind messageKind, IAnalysisContext context, string message)
        {
            switch (messageKind)
            {

                // These result types are optionally emitted
                case ResultKind.Pass:
                case ResultKind.Note:
                case ResultKind.NotApplicable:
                {
                    if (Verbose)
                    {
                        Console.WriteLine(GetMessageText(context, message, messageKind));
                    }
                    break;
                }

                // These result types are alwayss emitted
                case ResultKind.Error:
                case ResultKind.Warning:
                case ResultKind.InternalError:
                case ResultKind.ConfigurationError:
                {
                    Console.WriteLine(GetMessageText(context, message, messageKind));
                    break;
                }

                default:
                {
                    throw new InvalidOperationException();
                }
            }
        }
コード例 #5
0
        public void Log(ResultKind messageKind, IAnalysisContext context, string message)
        {
            switch (messageKind)
            {
                case ResultKind.Pass:
                {
                    PassTargets.Add(context.TargetUri.LocalPath);
                    break;
                }

                case ResultKind.Error:
                {
                    FailTargets.Add(context.TargetUri.LocalPath);
                    break;
                }

                case ResultKind.NotApplicable:
                {
                    NotApplicableTargets.Add(context.TargetUri.LocalPath);
                    break;
                }

                case ResultKind.Note:
                case ResultKind.InternalError:
                case ResultKind.ConfigurationError:
                {
                    throw new NotImplementedException();
                }
                default:
                {
                    throw new InvalidOperationException();
                }
            }
        }
コード例 #6
0
        public void Log(ResultKind messageKind, IAnalysisContext context, string message)
        {
            switch (messageKind)
            {

                case ResultKind.Pass:
                    {
                        break;
                    }

                case ResultKind.Error:
                {
                    break;
                }

                case ResultKind.Warning:
                {
                    break;
                }

                case ResultKind.NotApplicable:
                    {
                        if (context.Rule.Id == NoteDescriptors.InvalidTarget.Id)
                        {
                            _invalidTargetsCount++;
                        }
                        break;
                    }

                case ResultKind.Note:
                {
                    if (context.Rule.Id == NoteDescriptors.AnalyzingTarget.Id)
                    {
                        _targetsCount++;
                    }
                    break;
                }

                case ResultKind.InternalError:
                    {
                        break;
                    }

                case ResultKind.ConfigurationError:
                    {
                        break;
                    }

                default:
                    {
                        throw new InvalidOperationException();
                    }
            }
        }
コード例 #7
0
ファイル: Errors.cs プロジェクト: abdiiwan1841/sarif-sdk
        public static void LogMissingFile(IAnalysisContext context, string fileName)
        {
            context.Rule = Errors.InvalidConfiguration;

            // A required file specified on the command line could not be found:'{0}'.
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.ConfigurationError, context, null,
                                                         nameof(SdkResources.ERR0997_MissingFile),
                                                         fileName));

            context.RuntimeErrors |= RuntimeConditions.MissingFile;
        }
コード例 #8
0
ファイル: Errors.cs プロジェクト: abdiiwan1841/sarif-sdk
        public static RuntimeConditions LogUnhandledEngineException(IAnalysisContext context, Exception ex)
        {
            context.Rule = Errors.AnalysisHalted;

            // An unhandled exception was raised during analysis: {0}
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.InternalError, context, null,
                                                         nameof(SdkResources.ERR0999_UnhandledEngineException),
                                                         ex.ToString()));

            return(RuntimeConditions.ExceptionInEngine);
        }
コード例 #9
0
ファイル: Errors.cs プロジェクト: kleopatra999/sarif-sdk
        public static void LogExceptionLoadingTarget(IAnalysisContext context)
        {
            context.Rule = Errors.InvalidConfiguration;

            // An exception was raised attempting to load analysis target '{0}'. Exception information:
            // {1}
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.ConfigurationError, context, null,
                                                         nameof(SdkResources.ERR0997_ExceptionLoadingAnalysisTarget),
                                                         context.TargetLoadException.ToString()));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingTargetFile;
        }
コード例 #10
0
ファイル: Errors.cs プロジェクト: kleopatra999/sarif-sdk
        public static void LogExceptionLoadingPlugIn(string plugInFilePath, IAnalysisContext context, Exception ex)
        {
            context.Rule      = Errors.InvalidConfiguration;
            context.TargetUri = new Uri(plugInFilePath);

            // An exception was raised attempting to load plug-in '{0}'. Exception information:
            // {1}
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.ConfigurationError, context, null,
                                                         nameof(SdkResources.ERR0997_ExceptionLoadingPlugIn),
                                                         ex.ToString()));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingAnalysisPlugIn;
        }
コード例 #11
0
ファイル: Errors.cs プロジェクト: kleopatra999/sarif-sdk
        public static void LogExceptionAccessingFile(IAnalysisContext context, string fileName, Exception ex)
        {
            context.Rule = Errors.InvalidConfiguration;

            // An exception was raised accessing a file specified on the command-line: '{0}'. Exception information:
            // {1}
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.ConfigurationError, context, null,
                                                         nameof(SdkResources.ERR0997_ExceptionAccessingFile),
                                                         fileName,
                                                         ex.ToString()));

            context.RuntimeErrors |= RuntimeConditions.ExceptionAccessingFile;
        }
コード例 #12
0
ファイル: Errors.cs プロジェクト: kleopatra999/sarif-sdk
        public static void LogExceptionCreatingLogFile(IAnalysisContext context, string fileName, Exception ex)
        {
            context.Rule = Errors.InvalidConfiguration;

            // An exception was raised attempting to create output file: '{0}'. Exception information:
            // {1}
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.ConfigurationError, context, null,
                                                         nameof(SdkResources.ERR0997_ExceptionCreatingLogFile),
                                                         fileName,
                                                         ex.ToString()));

            context.RuntimeErrors |= RuntimeConditions.ExceptionCreatingLogfile;
        }
コード例 #13
0
        public void AnalyzingTarget(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (Verbose)
            {
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture,
                                                SdkResources.MSG001_AnalyzingTarget,
                                                context.TargetUri.GetFileName()));
            }
        }
コード例 #14
0
ファイル: Errors.cs プロジェクト: kleopatra999/sarif-sdk
        public static void LogExceptionLoadingPdb(IAnalysisContext context, string exceptionMessage)
        {
            string ruleName = context.Rule.Name;

            context.Rule = Errors.InvalidConfiguration;

            // '{0}' was not evaluated for check '{1}' as an exception occurred loading its pdb: '{2}'
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.ConfigurationError, context, null,
                                                         nameof(SdkResources.ERR0997_ExceptionLoadingPdb),
                                                         ruleName,
                                                         exceptionMessage));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingPdb;
        }
コード例 #15
0
        public void Log(ResultLevel messageKind, IAnalysisContext context, Region region, string ruleMessageId, params string[] arguments)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Rule != null)
            {
                Rules[context.Rule.Id] = context.Rule;
            }

            ruleMessageId = RuleUtilities.NormalizeRuleMessageId(ruleMessageId, context.Rule.Id);
            LogJsonIssue(messageKind, context.TargetUri.LocalPath, region, context.Rule.Id, ruleMessageId, arguments);
        }
コード例 #16
0
ファイル: SarifLogger.cs プロジェクト: tosmolka/sarif-sdk
        public void Log(FailureLevel level, IAnalysisContext context, Region region, string ruleMessageId, params string[] arguments)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            int ruleIndex = -1;

            if (context.Rule != null)
            {
                ruleIndex = LogRule(context.Rule);
            }

            ruleMessageId = RuleUtilities.NormalizeRuleMessageId(ruleMessageId, context.Rule.Id);
            LogJsonIssue(level, context.TargetUri.LocalPath, region, context.Rule.Id, ruleIndex, ruleMessageId, arguments);
        }
コード例 #17
0
        public void AnalyzingTarget(IAnalysisContext context)
        {
            // This code doesn't call through a common helper, such as
            // provided by the SDK Notes class, because we are in a specific
            // logger. If we called through a helper, we'd re-enter
            // through all aggregated loggers.

            // Analyzing target '{0}'...

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string message = string.Format(CultureInfo.InvariantCulture,
                                           SdkResources.MSG001_AnalyzingTarget,
                                           context.TargetUri.GetFileName());

            LogToolNotification(
                new Notification
            {
                Locations = new List <Location>()
                {
                    new Location
                    {
                        PhysicalLocation = new PhysicalLocation
                        {
                            ArtifactLocation = new ArtifactLocation
                            {
                                Uri = context.TargetUri
                            }
                        }
                    }
                },
                Descriptor = new ReportingDescriptorReference
                {
                    Id = Notes.Msg001AnalyzingTarget
                },
                Message = new Message {
                    Text = message
                },
                Level   = FailureLevel.None,
                TimeUtc = DateTime.UtcNow,
            });
        }
コード例 #18
0
ファイル: Errors.cs プロジェクト: Tawnos/sarif-sdk
        public static void LogMissingreportingConfiguration(IAnalysisContext context, string reasonForNotAnalyzing)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Assembly assembly = Assembly.GetEntryAssembly();

            assembly = assembly ?? Assembly.GetExecutingAssembly();
            string exeName = Path.GetFileName(assembly.Location);

            // Check '{0}' was disabled while analyzing '{1}' because the analysis
            // was not configured with required policy ({2}). To resolve this,
            // configure and provide a policy file on the {3} command-line using
            // the --policy argument (recommended), or pass '--config default'
            // to invoke built-in settings. Invoke the {3} 'exportConfig' command
            // to produce an initial configuration file that can be edited, if
            // necessary, and passed back into the tool.
            string message = string.Format(CultureInfo.InvariantCulture, SdkResources.ERR997_MissingReportingConfiguration,
                                           context.Rule.Name,
                                           context.TargetUri.GetFileName(),
                                           reasonForNotAnalyzing,
                                           exeName);

            context.Logger.LogConfigurationNotification(
                new Notification
            {
                PhysicalLocation = new PhysicalLocation
                {
                    ArtifactLocation = new ArtifactLocation
                    {
                        Uri = context.TargetUri
                    },
                },
                Id      = ERR997_MissingReportingConfiguration,
                RuleId  = context.Rule.Id,
                Level   = FailureLevel.Error,
                Message = new Message {
                    Text = message
                }
            });

            context.RuntimeErrors |= RuntimeConditions.RuleMissingRequiredConfiguration;
        }
コード例 #19
0
        public static void LogNotApplicableToSpecifiedTarget(IAnalysisContext context, string reasonForNotAnalyzing)
        {
            string ruleId   = context.Rule.Id;
            string ruleName = context.Rule.Name;

            context.Rule = Notes.InvalidTarget;

            // '{0}' was not evaluated for check '{1}:{2}' as the analysis
            // is not relevant based on observed metadata: {3}.
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.NotApplicable, context, null,
                                                         nameof(SdkResources.MSG1002_InvalidMetadata),
                                                         ruleId,
                                                         ruleName,
                                                         reasonForNotAnalyzing));

            context.RuntimeErrors |= RuntimeConditions.RuleNotApplicableToTarget;
        }
コード例 #20
0
        public static void LogOutputFileAlreadyExists(IAnalysisContext context, string outputFilePath)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_OutputFileAlreadyExists,
                    FailureLevel.Error,
                    exception: null,
                    persistExceptionStack: false,
                    outputFilePath));

            context.RuntimeErrors |= RuntimeConditions.OutputFileAlreadyExists;
        }
コード例 #21
0
        public static string BuildMessage(IAnalysisContext context, string messageFormatString, params string[] arguments)
        {
            // By convention, the first argument is always the target name,
            // which we retrieve from the context
            Debug.Assert(File.Exists(context.TargetUri.LocalPath));
            string targetName = Path.GetFileName(context.TargetUri.LocalPath);

            string[] fullArguments = new string[arguments != null ? arguments.Length + 1 : 1];
            fullArguments[0] = targetName;

            if (fullArguments.Length > 1)
            {
                arguments.CopyTo(fullArguments, 1);
            }

            return(String.Format(CultureInfo.InvariantCulture,
                                 messageFormatString, fullArguments));
        }
コード例 #22
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static RuntimeConditions LogUnhandledEngineException(IAnalysisContext context, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // An unhandled exception was raised during analysis.
            context.Logger.LogToolNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR999UnhandledEngineException,
                    NotificationLevel.Error,
                    exception,
                    true));

            return(RuntimeConditions.ExceptionInEngine);
        }
コード例 #23
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogNoRulesLoaded(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // No analysis rules could be instantiated.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_NoRulesLoaded,
                    NotificationLevel.Error,
                    null,
                    false));

            context.RuntimeErrors |= RuntimeConditions.NoRulesLoaded;
        }
コード例 #24
0
ファイル: Errors.cs プロジェクト: Tawnos/sarif-sdk
        public static void LogAllRulesExplicitlyDisabled(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // All rules were explicitly disabled so there is no work to do.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_AllRulesExplicitlyDisabled,
                    FailureLevel.Error,
                    null,
                    false));

            context.RuntimeErrors |= RuntimeConditions.NoRulesLoaded;
        }
コード例 #25
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogNoValidAnalysisTargets(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // No valid analysis targets were specified.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_NoValidAnalysisTargets,
                    NotificationLevel.Error,
                    null,
                    false));

            context.RuntimeErrors |= RuntimeConditions.NoValidAnalysisTargets;
        }
コード例 #26
0
        public void AnalyzingTarget(IAnalysisContext context)
        {
            this.currentFileHash = context.Hashes.Sha256;

            if (HashToResultsMap.ContainsKey(currentFileHash))
            {
                // We already have results cached for this file. This means that we shouldn't collect
                // any data in calls to Log. These calls are the driver framework 'replaying' the
                // cached results via the aggregated logger instance
                cacheLoggingData = false;
            }
            else
            {
                cacheLoggingData = true;
                HashToNotificationsMap[currentFileHash] = new List <Notification>();
                HashToResultsMap[currentFileHash]       = new List <Tuple <ReportingDescriptor, Result> >();
            }
        }
コード例 #27
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionAccessingFile(IAnalysisContext context, string fileName, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not access a file specified on the command-line: '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionAccessingFile,
                    NotificationLevel.Error,
                    exception,
                    false,
                    fileName));

            context.RuntimeErrors |= RuntimeConditions.ExceptionAccessingFile;
        }
コード例 #28
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogMissingFile(IAnalysisContext context, string fileName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // A required file specified on the command line could not be found: '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_MissingFile,
                    NotificationLevel.Error,
                    null,
                    false,
                    fileName));

            context.RuntimeErrors |= RuntimeConditions.MissingFile;
        }
コード例 #29
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogExceptionAccessingFile(IAnalysisContext context, string fileName, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not access a file specified on the command-line: '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionAccessingFile,
                    NotificationLevel.Error,
                    exception,
                    false,
                    fileName));

            context.RuntimeErrors |= RuntimeConditions.ExceptionAccessingFile;
        }
コード例 #30
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogInvalidInvocationPropertyName(IAnalysisContext context, string propertyName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // '{0}' is not a property of the Invocation object.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_InvalidInvocationPropertyName,
                    NotificationLevel.Error,
                    null,
                    false,
                    propertyName));

            context.RuntimeErrors |= RuntimeConditions.InvalidCommandLineOption;
        }
コード例 #31
0
        public static Result BuildResult(ResultKind messageKind, IAnalysisContext context, Region region, string formatId, params string[] arguments)
        {
            string[] messageArguments = arguments;

            formatId = RuleUtilities.NormalizeFormatId(context.Rule.Id, formatId);

            string targetPath = context.TargetUri?.LocalPath;

            Result result = new Result();

            result.RuleId = context.Rule.Id;

            if (!string.IsNullOrEmpty(targetPath))
            {
                // In the event of an analysis target, we always provide
                // the local path to this item as the 0th argument
                messageArguments    = new string[arguments.Length + 1];
                messageArguments[0] = Path.GetFileName(targetPath);
                arguments.CopyTo(messageArguments, 1);
            }

            result.FormattedRuleMessage = new FormattedRuleMessage()
            {
                FormatId  = formatId,
                Arguments = messageArguments
            };

            result.Kind = messageKind;

            if (targetPath != null)
            {
                result.Locations = new HashSet <Location> {
                    new Sarif.Location {
                        AnalysisTarget = new PhysicalLocation
                        {
                            Uri    = new Uri(targetPath),
                            Region = region
                        }
                    }
                };
            }
            return(result);
        }
コード例 #32
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogExceptionLoadingPlugin(string pluginFilePath, IAnalysisContext context, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not load plug-in '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionLoadingPlugIn,
                    NotificationLevel.Error,
                    exception,
                    false,
                    pluginFilePath));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingAnalysisPlugin;
        }
コード例 #33
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogExceptionLoadingTarget(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not load analysis target '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionLoadingAnalysisTarget,
                    NotificationLevel.Error,
                    context.TargetLoadException,
                    false,
                    context.TargetUri.GetFileName()));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingTargetFile;
        }
コード例 #34
0
ファイル: Errors.cs プロジェクト: jbrotsos/sarif-sdk
        public static void LogExceptionCreatingLogFile(IAnalysisContext context, string fileName, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not create output file: '{0}'
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionCreatingLogFile,
                    NotificationLevel.Error,
                    exception,
                    false,
                    fileName));

            context.RuntimeErrors |= RuntimeConditions.ExceptionCreatingLogFile;
        }
コード例 #35
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionCreatingLogFile(IAnalysisContext context, string fileName, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not create output file: '{0}'
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionCreatingLogFile,
                    NotificationLevel.Error,
                    exception,
                    false,
                    fileName));

            context.RuntimeErrors |= RuntimeConditions.ExceptionCreatingLogFile;
        }
コード例 #36
0
ファイル: RuleUtilities.cs プロジェクト: Microsoft/sarif-sdk
        public static Result BuildResult(ResultLevel level, IAnalysisContext context, Region region, string formatId, params string[] arguments)
        {
            //validating parameters
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            formatId = RuleUtilities.NormalizeFormatId(context.Rule.Id, formatId);

            Result result = new Result
            {
                RuleId = context.Rule.Id,

                FormattedRuleMessage = new FormattedRuleMessage()
                {
                    FormatId = formatId,
                    Arguments = arguments
                },

                Level = level
            };

            string targetPath = context.TargetUri?.LocalPath;
            if (targetPath != null)
            {
                result.Locations = new List<Location> {
                    new Sarif.Location {
                        AnalysisTarget = new PhysicalLocation
                        {
                            Uri = new Uri(targetPath),
                            Region = region
                        }
               }};
            }
            return result;
        }
コード例 #37
0
        public static void LogUnsupportedPlatformForRule(IAnalysisContext context, string ruleId, SupportedPlatform supportedOS, SupportedPlatform currentOS)
        {
            // Rule '{0}' was disabled as it cannot run on the current platform '{1}'.  It can only run on '{2}'.
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string message = string.Format(CultureInfo.InvariantCulture,
                                           SdkResources.WRN998_NotSupportedPlatform,
                                           ruleId,
                                           currentOS,
                                           supportedOS);

            context.Logger.LogConfigurationNotification(
                new Notification
            {
                Locations = new List <Location>
                {
                    new Location
                    {
                        PhysicalLocation = new PhysicalLocation
                        {
                            ArtifactLocation = new ArtifactLocation
                            {
                                Uri = context.TargetUri
                            }
                        }
                    }
                },
                Descriptor = new ReportingDescriptorReference
                {
                    Id = Wrn998_UnsupportedPlatform
                },
                Message = new Message {
                    Text = message
                },
                Level = FailureLevel.Warning,
            });

            context.RuntimeErrors |= RuntimeConditions.RuleCannotRunOnPlatform;
        }
コード例 #38
0
ファイル: Errors.cs プロジェクト: yazici/sarif-sdk
        public static void LogNoRulesLoaded(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // No analysis rules could be instantiated.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_NoRulesLoaded,
                    ruleId: null,
                    FailureLevel.Error,
                    exception: null,
                    persistExceptionStack: false,
                    messageFormat: null));

            context.RuntimeErrors |= RuntimeConditions.NoRulesLoaded;
        }
コード例 #39
0
        public static void LogNotApplicableToSpecifiedTarget(IAnalysisContext context, string reasonForNotAnalyzing)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Debug.Assert(context.TargetUri != null);

            // '{0}' was not evaluated for check '{1}' because the analysis
            // is not relevant for the following reason: {2}.
            context.Logger.Log(context.Rule,
                               RuleUtilities.BuildResult(ResultKind.NotApplicable, context, null,
                                                         nameof(SdkResources.NotApplicable_InvalidMetadata),
                                                         context.TargetUri.GetFileName(),
                                                         context.Rule.Name,
                                                         reasonForNotAnalyzing));

            context.RuntimeErrors |= RuntimeConditions.RuleNotApplicableToTarget;
        }
コード例 #40
0
ファイル: Notes.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogNotApplicableToSpecifiedTarget(IAnalysisContext context, string reasonForNotAnalyzing)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Debug.Assert(context.TargetUri != null);

            // '{0}' was not evaluated for check '{1}' as the analysis
            // is not relevant based on observed metadata: {2}.
            context.Logger.Log(context.Rule,
                RuleUtilities.BuildResult(ResultLevel.NotApplicable, context, null,
                    nameof(SdkResources.NotApplicable_InvalidMetadata),
                    context.TargetUri.GetFileName(),
                    context.Rule.Name,
                    reasonForNotAnalyzing));

            context.RuntimeErrors |= RuntimeConditions.RuleNotApplicableToTarget;
        }
コード例 #41
0
ファイル: Warnings.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionInvalidTarget(IAnalysisContext context)
        {
            // '{0}' was not analyzed as it does not appear to be a valid file type for analysis.
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string message = string.Format(CultureInfo.InvariantCulture,
                SdkResources.WRN997_InvalidTarget,
                context.TargetUri.GetFileName());

            context.Logger.LogConfigurationNotification(
                new Notification
                {
                    PhysicalLocation = new PhysicalLocation { Uri = context.TargetUri },
                    Id = Wrn997InvalidTarget,
                    Message = message,
                    Level = NotificationLevel.Note,
                });

            context.RuntimeErrors |= RuntimeConditions.TargetNotValidToAnalyze;
        }
コード例 #42
0
ファイル: SarifLogger.cs プロジェクト: Microsoft/sarif-sdk
        public void Log(ResultLevel messageKind, IAnalysisContext context, Region region, string formatId, params string[] arguments)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Rule != null)
            {
                Rules[context.Rule.Id] = context.Rule;
            }

            formatId = RuleUtilities.NormalizeFormatId(context.Rule.Id, formatId);
            LogJsonIssue(messageKind, context.TargetUri.LocalPath, region, context.Rule.Id, formatId, arguments);
        }
コード例 #43
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionLoadingPlugin(string pluginFilePath, IAnalysisContext context, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not load plug-in '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionLoadingPlugIn,
                    NotificationLevel.Error,
                    exception,
                    false,
                    pluginFilePath));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingAnalysisPlugin;
        }
コード例 #44
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogMissingRuleConfiguration(IAnalysisContext context, string reasonForNotAnalyzing)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Assembly assembly = Assembly.GetEntryAssembly();
            assembly = assembly ?? Assembly.GetExecutingAssembly();
            string exeName = Path.GetFileName(assembly.Location);

            // Check '{0}' was disabled while analyzing '{1}' because the analysis
            // was not configured with required policy ({2}). To resolve this,
            // configure and provide a policy file on the {3} command-line using
            // the --policy argument (recommended), or pass '--config default'
            // to invoke built-in settings. Invoke the {3} 'exportConfig' command
            // to produce an initial configuration file that can be edited, if
            // necessary, and passed back into the tool.
            string message = string.Format(CultureInfo.InvariantCulture, SdkResources.ERR997_MissingRuleConfiguration,
                context.Rule.Name,
                context.TargetUri.GetFileName(),
                reasonForNotAnalyzing,
                exeName);

            context.Logger.LogConfigurationNotification(
                new Notification
                {
                    PhysicalLocation = new PhysicalLocation { Uri = context.TargetUri },
                    Id = ERR997_MissingRuleConfiguration,
                    RuleId = context.Rule.Id,
                    Level = NotificationLevel.Error,
                    Message = message
                });

            context.RuntimeErrors |= RuntimeConditions.RuleMissingRequiredConfiguration;
        }
コード例 #45
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogMissingFile(IAnalysisContext context, string fileName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // A required file specified on the command line could not be found: '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_MissingFile,
                    NotificationLevel.Error,
                    null,
                    false,
                    fileName));

            context.RuntimeErrors |= RuntimeConditions.MissingFile;
        }
コード例 #46
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionInstantiatingSkimmers(
            IAnalysisContext context,
            IEnumerable<Assembly> skimmerAssemblies,
            Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string plugins = string.Join(", ",
                skimmerAssemblies.Select(sa => '"' +  Path.GetFileName(sa.Location) + '"'));

            // Could not instantiate skimmers from the following plugins: {0}
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionInstantiatingSkimmers,
                    NotificationLevel.Error,
                    exception,
                    false,
                    plugins));

            context.RuntimeErrors |= RuntimeConditions.ExceptionInstantiatingSkimmers;
        }
コード例 #47
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogNoRulesLoaded(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // No analysis rules could be instantiated.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_NoRulesLoaded,
                    NotificationLevel.Error,
                    null,
                    false));

            context.RuntimeErrors |= RuntimeConditions.NoRulesLoaded;
        }
コード例 #48
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static RuntimeConditions LogUnhandledEngineException(IAnalysisContext context, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // An unhandled exception was raised during analysis.
            context.Logger.LogToolNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR999UnhandledEngineException,
                    NotificationLevel.Error,
                    exception,
                    true));

            return RuntimeConditions.ExceptionInEngine;
        }
コード例 #49
0
ファイル: CommonCodeProcessor.cs プロジェクト: vlapchenko/nfx
 protected CommonCodeProcessor(IAnalysisContext context, MessageList messages = null, bool throwErrors = false)
 {
       m_Context = context;
       m_Messages = messages ?? (context!=null? context.Messages : null);
       m_ThrowErrors = throwErrors;
 }
コード例 #50
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogUnhandledExceptionInitializingRule(IAnalysisContext context, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // An unhandled exception was encountered initializing check '{0}', which
            // has been disabled for the remainder of the analysis.
            context.Logger.LogToolNotification(
                CreateNotification(
                context.TargetUri,
                ERR998_ExceptionInInitialize,
                context.Rule.Id,
                NotificationLevel.Error,
                exception,
                true,
                context.Rule.Name));

            context.RuntimeErrors |= RuntimeConditions.ExceptionInSkimmerInitialize;
        }
コード例 #51
0
ファイル: LaconfigLanguage.cs プロジェクト: itadapter/nfx
 public override ILexer MakeLexer(IAnalysisContext context, SourceCodeRef srcRef, ISourceText source, MessageList messages = null, bool throwErrors = false)
 {
     return new LaconfigLexer(context, srcRef, source, messages, throwErrors);
 }
コード例 #52
0
ファイル: SarifLogger.cs プロジェクト: Microsoft/sarif-sdk
        public void AnalyzingTarget(IAnalysisContext context)
        {
            // This code doesn't call through a common helper, such as
            // provided by the SDK Notes class, because we are in a specific
            // logger. If we called through a helper, we'd re-enter
            // through all aggregated loggers.

            // Analyzing target '{0}'...

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string message = string.Format(CultureInfo.InvariantCulture,
                SdkResources.MSG001_AnalyzingTarget,
                context.TargetUri.GetFileName());

            LogToolNotification(
                new Notification
                {
                    PhysicalLocation = new PhysicalLocation { Uri = context.TargetUri },
                    Id = Notes.Msg001AnalyzingTarget,
                    Message = message,
                    Level = NotificationLevel.Note,
                    Time = DateTime.UtcNow,
                });
        }
コード例 #53
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static RuntimeConditions LogUnhandledRuleExceptionAnalyzingTarget(
            HashSet<string> disabledSkimmers,
            IAnalysisContext context,
            Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // An unhandled exception was encountered analyzing '{0}' for check '{1}',
            // which has been disabled for the remainder of the analysis.The
            // exception may have resulted from a problem related to parsing
            // image metadata and not specific to the rule, however.
            context.Logger.LogToolNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR998_ExceptionInAnalyze,
                    context.Rule.Id,
                    NotificationLevel.Error,
                    exception,
                    true,
                    context.TargetUri.GetFileName(),
                    context.Rule.Name));

            if (disabledSkimmers != null) { disabledSkimmers.Add(context.Rule.Id); }

            return RuntimeConditions.ExceptionInSkimmerAnalyze;
        }
コード例 #54
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogUnhandledRuleExceptionAssessingTargetApplicability(
            HashSet<string> disabledSkimmers,
            IAnalysisContext context,
            Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // An unhandled exception was raised attempting to determine whether '{0}'
            // is a valid analysis target for check '{1}' (which has been disabled
            // for the remainder of the analysis). The exception may have resulted
            // from a problem related to parsing image metadata and not specific to
            // the rule, however.
            context.Logger.LogToolNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR998_ExceptionInCanAnalyze,
                    context.Rule.Id,
                    NotificationLevel.Error,
                    exception,
                    true,
                    context.TargetUri.GetFileName(),
                    context.Rule.Name));

            if (disabledSkimmers != null) { disabledSkimmers.Add(context.Rule.Id); }

            context.RuntimeErrors |= RuntimeConditions.ExceptionRaisedInSkimmerCanAnalyze;
        }
コード例 #55
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionLoadingPdb(IAnalysisContext context, Exception exception)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // '{0}' was not evaluated for check '{1}' because its PDB could not be loaded.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionLoadingPdb,
                    context.Rule.Id,
                    NotificationLevel.Error,
                    exception,
                    false,
                    context.TargetUri.GetFileName(),
                    context.Rule.Name));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingPdb;
        }
コード例 #56
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogTargetParseError(IAnalysisContext context, Region region, string message)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // {0}({1}): error {2}: {3}
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR1000_ParseError,
                    NotificationLevel.Error,
                    null,
                    false,
                    context.TargetUri.LocalPath,
                    region.FormatForVisualStudio(),
                    ERR1000_ParseError,
                    message));

            context.RuntimeErrors |= RuntimeConditions.TargetParseError;
        }
コード例 #57
0
ファイル: ConsoleLogger.cs プロジェクト: Microsoft/sarif-sdk
        public void AnalyzingTarget(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (Verbose)
            {
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture,
                    SdkResources.MSG001_AnalyzingTarget,
                        context.TargetUri.GetFileName()));
            }
        }
コード例 #58
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogNoValidAnalysisTargets(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // No valid analysis targets were specified.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_NoValidAnalysisTargets,
                    NotificationLevel.Error,
                    null,
                    false));

            context.RuntimeErrors |= RuntimeConditions.NoValidAnalysisTargets;
        }
コード例 #59
0
ファイル: Errors.cs プロジェクト: Microsoft/sarif-sdk
        public static void LogExceptionLoadingTarget(IAnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Could not load analysis target '{0}'.
            context.Logger.LogConfigurationNotification(
                CreateNotification(
                    context.TargetUri,
                    ERR997_ExceptionLoadingAnalysisTarget,
                    NotificationLevel.Error,
                    context.TargetLoadException,
                    false,
                    context.TargetUri.GetFileName()));

            context.RuntimeErrors |= RuntimeConditions.ExceptionLoadingTargetFile;
        }
コード例 #60
0
ファイル: CommonCodeProcessor.cs プロジェクト: vlapchenko/nfx
 protected SourceRefCommonCodeProcessor(IAnalysisContext context, SourceCodeRef srcRef, MessageList messages = null, bool throwErrors = false) :
     base(context, messages, throwErrors)
 {
     m_SourceCodeReference = srcRef;
 }