Exemplo n.º 1
0
 public DependencyRuleSet(CheckerContext checkerContext, string fullRuleFilename,
                          IDictionary <string, string> defines,
                          IDictionary <string, Macro> macros)
     : this(checkerContext) {
     _defines = new SortedDictionary <string, string>(defines, new LengthComparer());
     _macros  = new SortedDictionary <string, Macro>(macros, new LengthComparer());
     if (!LoadRules(fullRuleFilename))
     {
         throw new ApplicationException("Could not load rules from " + fullRuleFilename);
     }
 }
Exemplo n.º 2
0
        private int AnalyzeAssembly(CheckerContext checkerContext, string assemblyFilename)
        {
            var dependencyFilename = Path.GetFileName(assemblyFilename) + ".dep";

            try {
                Log.WriteInfo("Analyzing " + assemblyFilename);
                using (var assemblyContext = checkerContext.OpenAssemblyContext(Path.GetFileName(assemblyFilename))) {
                    DependencyRuleSet ruleSetForAssembly = checkerContext.Load(dependencyFilename, _options.Directories);
                    if (ruleSetForAssembly == null && !String.IsNullOrEmpty(_options.DefaultRuleSetFile))
                    {
                        ruleSetForAssembly = checkerContext.Create(new DirectoryInfo("."), _options.DefaultRuleSetFile);
                    }
                    if (ruleSetForAssembly == null)
                    {
                        Log.WriteError(dependencyFilename +
                                       " not found in -d and -s directories, and no default rule set provided by -x");
                        return(6);
                    }
                    else
                    {
                        try {
                            IEnumerable <Dependency>          dependencies = DependencyReader.GetDependencies(assemblyFilename);
                            IEnumerable <DependencyRuleGroup> groups       = ruleSetForAssembly.ExtractDependencyGroups();
                            bool success = _checker.Check(assemblyContext, groups, dependencies, _options.ShowUnusedQuestionableRules);
                            if (!success)
                            {
                                return(3);
                            }
                            if (_options.DotFilename != null)
                            {
                                _grapher.Graph(ruleSetForAssembly, dependencies);
                            }
                        } catch (FileNotFoundException ex) {
                            Log.WriteError("Input file " + ex.FileName + " not found");
                            return(4);
                        }
                    }
                }
            } catch (FileLoadException ex2) {
                Log.WriteError(ex2.Message);
                return(2);
            }
            return(0);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor for test cases.
 /// </summary>
 public DependencyRuleSet(CheckerContext checkerContext)
 {
     _checkerContext = checkerContext;
     _mainRuleGroup  = new DependencyRuleGroup("");
     _ruleGroups.Add(_mainRuleGroup);
 }
Exemplo n.º 4
0
 private int AnalyzeAssembly(CheckerContext checkerContext, string assemblyFilename)
 {
     string dependencyFilename = Path.GetFileName(assemblyFilename) + ".dep";
     try {
         Log.WriteInfo("Analyzing " + assemblyFilename);
         using (var assemblyContext = checkerContext.OpenAssemblyContext(Path.GetFileName(assemblyFilename))) {
             DependencyRuleSet ruleSetForAssembly = checkerContext.Load(dependencyFilename, _options.Directories);
             if (ruleSetForAssembly == null && !String.IsNullOrEmpty(_options.DefaultRuleSetFile)) {
                 ruleSetForAssembly = checkerContext.Create(new DirectoryInfo("."), _options.DefaultRuleSetFile);
             }
             if (ruleSetForAssembly == null) {
                 Log.WriteError(dependencyFilename +
                                " not found in -d and -s directories, and no default rule set provided by -x");
                 return 6;
             } else {
                 try {
                     IEnumerable<Dependency> dependencies = DependencyReader.GetDependencies(assemblyFilename,
                         createCodeDependencies: !_options.CheckOnlyAssemblyDependencies,
                         createAssemblyDependencies: ruleSetForAssembly.ContainsAssemblyRule);
                     IEnumerable<DependencyRuleGroup> groups = ruleSetForAssembly.ExtractDependencyGroups();
                     bool success = _checker.Check(assemblyContext, groups, dependencies, _options.ShowUnusedQuestionableRules);
                     if (!success) {
                         return 3;
                     }
                     if (_options.DotFilename != null) {
                         _grapher.Graph(ruleSetForAssembly, dependencies);
                     }
                 } catch (FileNotFoundException ex) {
                     Log.WriteError("Input file " + ex.FileName + " not found");
                     return 4;
                 }
             }
         }
     } catch (FileLoadException ex2) {
         Log.WriteError(ex2.Message);
         return 2;
     }
     return 0;
 }