示例#1
0
        /// <summary>
        /// Returns a full path to the include file. Relative paths are expanded relative to the current rule set file.
        /// </summary>
        /// <param name="parent">The parent of this rule set include</param>
        private string GetIncludePath(RuleSet parent)
        {
            List<string> found = new List<string>();
            string expandedPath = PortableShim.Environment.ExpandEnvironmentVariables(_includePath);

            // If a full path is specified then use it
            if (Path.IsPathRooted(expandedPath))
            {
                if (PortableShim.File.Exists(expandedPath))
                {
                    found.Add(expandedPath);
                }
            }

            // If the current rule set is backed by a file then try to find the include file relative to it
            if (parent != null && !string.IsNullOrEmpty(parent.FilePath))
            {
                string local = Path.Combine(Path.GetDirectoryName(parent.FilePath), expandedPath);
                if (PortableShim.File.Exists(local))
                {
                    found.Add(local);
                }
            }

            // If we still couldn't find it then throw an exception;
            if (found.Count == 0)
            {
                throw new FileNotFoundException(string.Format(CodeAnalysisResources.FailedToResolveRuleSetName, _includePath), _includePath);
            }

            // Return the canonical full path
            Debug.Assert(found.Count > 0);
            return PortableShim.Path.GetFullPath(found[0]);
        }
示例#2
0
        /// <summary>
        /// Returns a full path to the include file. Relative paths are expanded relative to the current rule set file.
        /// </summary>
        /// <param name="parent">The parent of this rule set include</param>
        private string GetIncludePath(RuleSet parent)
        {
            var resolvedIncludePath = ResolveIncludePath(_includePath, parent?.FilePath);

            // If we still couldn't find it then throw an exception;
            if (resolvedIncludePath == null)
            {
                throw new FileNotFoundException(string.Format(CodeAnalysisResources.FailedToResolveRuleSetName, _includePath), _includePath);
            }

            // Return the canonical full path
            return PortableShim.Path.GetFullPath(resolvedIncludePath);
        }
示例#3
0
        /// <summary>
        /// Gets the RuleSet associated with this ruleset include
        /// </summary>
        /// <param name="parent">The parent of this ruleset include</param>
        public RuleSet LoadRuleSet(RuleSet parent)
        {
            // Try to load the rule set
            RuleSet ruleSet = null;
            Exception ex = null;

            string path = _includePath;
            try
            {
                path = GetIncludePath(parent);
                ruleSet = RuleSetProcessor.LoadFromFile(path);
            }
            catch (ArgumentException e)
            { ex = e; }
            catch (FileNotFoundException)
            {
                // The compiler uses the same rule set files as FxCop, but doesn't have all of
                // the same logic for resolving included files. For the moment, just ignore any
                // includes we can't resolve.
            }
            catch (IOException e)
            { ex = e; }
            catch (UriFormatException e)
            { ex = e; }
            catch (SecurityException e)
            { ex = e; }
            catch (UnauthorizedAccessException e)
            { ex = e; }
            catch (XmlException e)
            { ex = e; }
            catch (InvalidRuleSetException e)
            { ex = e; }

            if (ex != null)
            {
                throw new InvalidRuleSetException(string.Format(CodeAnalysisResources.InvalidRuleSetInclude, path, ex.Message));
            }

            return ruleSet;
        }
示例#4
0
        /// <summary>
        /// Gets the RuleSet associated with this ruleset include
        /// </summary>
        /// <param name="parent">The parent of this ruleset include</param>
        public RuleSet LoadRuleSet(RuleSet parent)
        {
            // Try to load the rule set
            RuleSet ruleSet = null;
            Exception ex = null;

            string path = includePath;
            try
            {
                path = GetIncludePath(parent);
                ruleSet = RuleSetProcessor.LoadFromFile(path);
            }
            catch (ArgumentException e)
            { ex = e; }
            catch (FileNotFoundException e)
            { ex = e; }
            catch (IOException e)
            { ex = e; }
            catch (UriFormatException e)
            { ex = e; }
            catch (SecurityException e)
            { ex = e; }
            catch (UnauthorizedAccessException e)
            { ex = e; }
            catch (XmlException e)
            { ex = e; }
            catch (InvalidRuleSetException e)
            { ex = e; }

            if (ex != null)
            {
                throw new InvalidRuleSetException(string.Format(CodeAnalysisResources.InvalidRuleSetInclude, path, ex.Message));
            }

            return ruleSet;
        }
示例#5
0
 private static void CheckExpectedDiagnosticLevel(MSCA.RuleSet ruleset, string ruleId,
                                                  MSCA.ReportDiagnostic expected)
 {
     ruleset.SpecificDiagnosticOptions.Keys.Contains(ruleId).Should().BeTrue();
     ruleset.SpecificDiagnosticOptions[ruleId].Should().Be(expected);
 }
示例#6
0
 internal ReportDiagnostic GetDiagnosticOptionsFromRulesetFile(string fullPath, out Dictionary <string, ReportDiagnostic> diagnosticOptions, IList <Diagnostic> diagnostics)
 {
     return(RuleSet.GetDiagnosticOptionsFromRulesetFile(fullPath, out diagnosticOptions, diagnostics, _messageProvider));
 }
 internal ReportDiagnostic GetDiagnosticOptionsFromRulesetFile(Dictionary <string, ReportDiagnostic> diagnosticOptions, IList <Diagnostic> diagnostics, string path, string baseDirectory)
 {
     return(RuleSet.GetDiagnosticOptionsFromRulesetFile(diagnosticOptions, path, baseDirectory, diagnostics, _messageProvider));
 }