Beispiel #1
0
        /// <summary>
        /// Factory to get logger
        /// </summary>
        /// <param name="loggerName">Name of logger that was either created earlier or needs to be created</param>
        /// <returns>AnalysisLogger</returns>
        private static AnalysisLogger GetLogger(string loggerName)
        {
            //TODO: Once logger is simplified throughout application, factory method can be enabled
            AnalysisLogger log;

            if (!string.IsNullOrEmpty(loggerName))
            {
                if (!LogDictionary.TryGetValue(loggerName, out log))
                {
                    _defaultLogName = loggerName;
                    log             = new AnalysisLogger(Assembly.GetEntryAssembly().Location);
                    LogDictionary.Add(loggerName, log);
                }
            }
            else
            {
                LogDictionary.TryGetValue(_defaultLogName, out log);
            }

            return(log);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            AnalysisLogger analysisLogger = null;

            try
            {
                if (args == null || args.Length < 1)
                {
                    throw new InvalidOperationException("Please pass a valid directory name as the first parameter");
                }

                var installDir = args[0];
                if (!Directory.Exists(installDir))
                {
                    throw new InvalidOperationException("You must pass a valid directory as the first parameter");
                }

                var directories = new List <string>
                {
                    Path.Combine(installDir, @"ResourceManager\AzureResourceManager\"),
                    Path.Combine(installDir, @"ServiceManagement\Azure\"),
                    Path.Combine(installDir, @"Storage\")
                }.Where((d) => Directory.Exists(d)).ToList <string>();

                var  reportsDirectory           = Directory.GetCurrentDirectory();
                bool logReportsDirectoryWarning = true;
                if (args.Length > 1 && Directory.Exists(args[1]))
                {
                    reportsDirectory           = args[1];
                    logReportsDirectoryWarning = false;
                }

                ExceptionsDirectory = Path.Combine(reportsDirectory, "Exceptions");
                bool useExceptions = true;
                if (args.Length > 2)
                {
                    bool.TryParse(args[2], out useExceptions);
                }

                ConsolidateExceptionFiles(ExceptionsDirectory);
                analysisLogger = useExceptions ? new AnalysisLogger(reportsDirectory, ExceptionsDirectory) :
                                 new AnalysisLogger(reportsDirectory);
                bool skipHelp = false;
                if (args.Length > 3)
                {
                    bool.TryParse(args[3], out skipHelp);
                }

                if (!skipHelp)
                {
                    Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
                }

                var modulesToAnalyze = new List <string>();
                if (args.Length > 4)
                {
                    modulesToAnalyze = args[4].Split(';').ToList();
                }

                if (logReportsDirectoryWarning)
                {
                    analysisLogger.WriteWarning("No logger specified in the second parameter, writing reports to {0}",
                                                reportsDirectory);
                }

                foreach (var analyzer in Analyzers)
                {
                    analyzer.Logger = analysisLogger;
                    analysisLogger.WriteMessage("Executing analyzer: {0}", analyzer.Name);
                    analyzer.Analyze(directories, modulesToAnalyze);
                    analysisLogger.WriteMessage("Processing complete for analyzer: {0}", analyzer.Name);
                }

                analysisLogger.WriteReports();
                analysisLogger.CheckForIssues(2);
            }
            catch (Exception ex)
            {
                analysisLogger.WriteError(ex.ToString());
                throw ex;
            }
            finally
            {
                foreach (var exceptionFileName in ExceptionFileNames)
                {
                    var exceptionFilePath = Path.Combine(ExceptionsDirectory, exceptionFileName);
                    if (File.Exists(exceptionFilePath))
                    {
                        File.Delete(exceptionFilePath);
                    }
                }
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            AnalysisLogger analysisLogger = null;

            Console.WriteLine("Analyzer invoked with parameters: {0}", string.Join(" ", args));
            try
            {
                string installDir = null;
                if (args.Any(a => a == "--package-directory" || a == "-p"))
                {
                    int idx = Array.FindIndex(args, a => a == "--package-directory" || a == "-p");
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --package-directory parameter.");
                    }

                    installDir = args[idx + 1];
                }

                if (args == null)
                {
                    throw new InvalidOperationException("No installation directory was provided; please use the --package-directory parameter to provide the value.");
                }
                else if (!Directory.Exists(installDir))
                {
                    throw new InvalidOperationException(string.Format("Please provide a valid installation directory; the provided directory '{0}' could not be found.", installDir));
                }

                var directories = new List <string> {
                    installDir
                }.Where((d) => Directory.Exists(d)).ToList <string>();

                var  reportsDirectory           = Directory.GetCurrentDirectory();
                bool logReportsDirectoryWarning = true;
                if (args.Any(a => a == "--reports-directory" || a == "-r"))
                {
                    int idx = Array.FindIndex(args, a => a == "--reports-directory" || a == "-r");
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --reports-directory parameter.");
                    }

                    reportsDirectory           = args[idx + 1];
                    logReportsDirectoryWarning = false;
                }

                if (!Directory.Exists(reportsDirectory))
                {
                    Directory.CreateDirectory(reportsDirectory);
                }

                var modulesToAnalyze = new List <string>();
                if (args.Any(a => a == "--modules-to-analyze" || a == "-m"))
                {
                    int idx = Array.FindIndex(args, a => a == "--modules-to-analyze" || a == "-m");
                    if (idx + 1 == args.Length)
                    {
                        Console.WriteLine("No value provided for the --modules-to-analyze parameter. Filtering over all built modules.");
                    }
                    else
                    {
                        modulesToAnalyze = args[idx + 1].Split(';').ToList();
                    }
                }

                Analyzers.Add(new SignatureVerifier.SignatureVerifier());
                Analyzers.Add(new BreakingChangeAnalyzer.BreakingChangeAnalyzer());

                var helpOnly = args.Any(a => a == "--help-only" || a == "-h");
                var skipHelp = !helpOnly && args.Any(a => a == "--skip-help" || a == "-s");
                if (helpOnly)
                {
                    Analyzers.Clear();
                }
                if (!skipHelp)
                {
                    Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
                }

                // https://stackoverflow.com/a/9737418/294804
                var assemblyDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
                ExceptionsDirectory = Path.Combine(assemblyDirectory, "Exceptions");
                bool useExceptions = !args.Any(a => a == "--dont-use-exceptions" || a == "-d");
                var  useNetcore    = args.Any(a => a == "--use-netcore" || a == "-u");
                ConsolidateExceptionFiles(ExceptionsDirectory, useNetcore);

                analysisLogger = useExceptions ? new AnalysisLogger(reportsDirectory, ExceptionsDirectory) : new AnalysisLogger(reportsDirectory);
                if (logReportsDirectoryWarning)
                {
                    analysisLogger.WriteWarning("No logger specified in the second parameter, writing reports to {0}", reportsDirectory);
                }

                foreach (var analyzer in Analyzers)
                {
                    analyzer.Logger = analysisLogger;
                    analysisLogger.WriteMessage("Executing analyzer: {0}", analyzer.Name);
                    analyzer.Analyze(directories, modulesToAnalyze);
                    analysisLogger.WriteMessage("Processing complete for analyzer: {0}", analyzer.Name);
                }

                analysisLogger.WriteReports();
                analysisLogger.CheckForIssues(2);
            }
            catch (Exception ex)
            {
                analysisLogger?.WriteError(ex.ToString());
                throw ex;
            }
            finally
            {
                foreach (var exceptionFileName in ExceptionFileNames)
                {
                    var exceptionFilePath = Path.Combine(ExceptionsDirectory, exceptionFileName);
                    if (File.Exists(exceptionFilePath))
                    {
                        File.Delete(exceptionFilePath);
                    }
                }
            }
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            AnalysisLogger analysisLogger = null;

            try
            {
                if (args == null || args.Length < 1)
                {
                    throw new InvalidOperationException("Please pass a valid directory name as the first parameter");
                }

                var installDir = args[0];
                if (!Directory.Exists(installDir))
                {
                    throw new InvalidOperationException("You must pass a valid directory as the first parameter");
                }

                var directories = new List <string>
                {
                    Path.Combine(installDir, @"ResourceManager\AzureResourceManager\"),
                    Path.Combine(installDir, @"ServiceManagement\Azure\"),
                    Path.Combine(installDir, @"Storage\")
                };

                var  reportsDirectory           = Directory.GetCurrentDirectory();
                bool logReportsDirectoryWarning = true;
                if (args.Length > 1 && Directory.Exists(args[1]))
                {
                    reportsDirectory           = args[1];
                    logReportsDirectoryWarning = false;
                }

                var  exceptionsDirectory = Path.Combine(reportsDirectory, "Exceptions");
                bool useExceptions       = true;
                if (args.Length > 2)
                {
                    bool.TryParse(args[2], out useExceptions);
                }

                analysisLogger = useExceptions ? new AnalysisLogger(reportsDirectory, exceptionsDirectory) :
                                 new AnalysisLogger(reportsDirectory);
                if (logReportsDirectoryWarning)
                {
                    analysisLogger.WriteWarning("No logger specified in the second parameter, writing reports to {0}",
                                                reportsDirectory);
                }

                foreach (var analyzer in Analyzers)
                {
                    analyzer.Logger = analysisLogger;
                    analysisLogger.WriteMessage("Executing analyzer: {0}", analyzer.Name);
                    analyzer.Analyze(directories);
                    analysisLogger.WriteMessage("Processing complete for analyzer: {0}", analyzer.Name);
                }

                analysisLogger.WriteReports();
                analysisLogger.CheckForIssues(2);
            }
            catch (Exception ex)
            {
                analysisLogger.WriteError(ex.ToString());
                throw ex;
            }
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            AnalysisLogger analysisLogger = null;

            try
            {
                string installDir = null;
                if (args.Any(a => a == "--package-directory" || a == "-p"))
                {
                    int idx = Array.FindIndex(args, a => a == "--package-directory" || a == "-p");
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --package-directory parameter.");
                    }

                    installDir = args[idx + 1];
                }

                if (args == null)
                {
                    throw new InvalidOperationException("No installation directory was provided; please use the --package-directory parameter to provide the value.");
                }
                else if (!Directory.Exists(installDir))
                {
                    throw new InvalidOperationException(string.Format("Please provide a valid installation directory; the provided directory '{0}' could not be found.", installDir));
                }

                var directories = new List <string>
                {
                    Path.Combine(installDir, @"ResourceManager\AzureResourceManager\"),
                    Path.Combine(installDir, @"ServiceManagement\Azure\"),
                    Path.Combine(installDir, @"Storage\")
                }.Where((d) => Directory.Exists(d)).ToList <string>();

                var  reportsDirectory           = Directory.GetCurrentDirectory();
                bool logReportsDirectoryWarning = true;
                if (args.Any(a => a == "--reports-directory" || a == "-r"))
                {
                    int idx = Array.FindIndex(args, a => a == "--reports-directory" || a == "-r");
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --reports-directory parameter.");
                    }

                    reportsDirectory           = args[idx + 1];
                    logReportsDirectoryWarning = false;
                }

                ExceptionsDirectory = Path.Combine(reportsDirectory, "Exceptions");
                bool useExceptions = !args.Any(a => a == "--dont-use-exceptions" || a == "-d");
                bool skipHelp      = args.Any(a => a == "--skip-help" || a == "-s");

                var modulesToAnalyze = new List <string>();
                if (args.Any(a => a == "--modules-to-analyze" || a == "-m"))
                {
                    int idx = Array.FindIndex(args, a => a == "--modules-to-analyze" || a == "-m");
                    if (idx + 1 == args.Length)
                    {
                        Console.WriteLine("No value provided for the --modules-to-analyze parameter. Filtering over all built modules.");
                    }
                    else
                    {
                        modulesToAnalyze = args[idx + 1].Split(';').ToList();
                    }
                }

                bool useNetcore = args.Any(a => a == "--use-netcore" || a == "-u");
                if (!useNetcore)
                {
                    Analyzers.Add(new SignatureVerifier.SignatureVerifier());
                    Analyzers.Add(new BreakingChangeAnalyzer.BreakingChangeAnalyzer());
                }

                if (!skipHelp && !useNetcore)
                {
                    Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
                }

                ConsolidateExceptionFiles(ExceptionsDirectory, useNetcore);
                analysisLogger = useExceptions ? new AnalysisLogger(reportsDirectory, ExceptionsDirectory) :
                                 new AnalysisLogger(reportsDirectory);

                if (logReportsDirectoryWarning)
                {
                    analysisLogger.WriteWarning("No logger specified in the second parameter, writing reports to {0}",
                                                reportsDirectory);
                }

                foreach (var analyzer in Analyzers)
                {
                    analyzer.Logger = analysisLogger;
                    analysisLogger.WriteMessage("Executing analyzer: {0}", analyzer.Name);
                    analyzer.Analyze(directories, modulesToAnalyze);
                    analysisLogger.WriteMessage("Processing complete for analyzer: {0}", analyzer.Name);
                }

                analysisLogger.WriteReports();
                analysisLogger.CheckForIssues(2);
            }
            catch (Exception ex)
            {
                analysisLogger.WriteError(ex.ToString());
                throw ex;
            }
            finally
            {
                foreach (var exceptionFileName in ExceptionFileNames)
                {
                    var exceptionFilePath = Path.Combine(ExceptionsDirectory, exceptionFileName);
                    if (File.Exists(exceptionFilePath))
                    {
                        File.Delete(exceptionFilePath);
                    }
                }
            }
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            AnalysisLogger analysisLogger = null;

            Console.WriteLine("Analyzer invoked with parameters: {0}", string.Join(" ", args));
            try
            {
                string installDir = null;
                if (args.Any(a => a.Equals("--package-directory") || a.Equals("-p")))
                {
                    int idx = Array.FindIndex(args, a => a.Equals("--package-directory") || a.Equals("-p"));
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --package-directory parameter.");
                    }

                    installDir = args[idx + 1];
                }

                if (args == null)
                {
                    throw new InvalidOperationException("No installation directory was provided; please use the --package-directory parameter to provide the value.");
                }
                else if (!Directory.Exists(installDir))
                {
                    throw new InvalidOperationException(string.Format("Please provide a valid installation directory; the provided directory '{0}' could not be found.", installDir));
                }

                var directories = new List <string> {
                    installDir
                }.Where((d) => Directory.Exists(d)).ToList <string>();

                var  reportsDirectory           = Directory.GetCurrentDirectory();
                bool logReportsDirectoryWarning = true;
                if (args.Any(a => a == "--reports-directory" || a == "-r"))
                {
                    int idx = Array.FindIndex(args, a => a.Equals("--reports-directory") || a.Equals("-r"));
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --reports-directory parameter.");
                    }

                    reportsDirectory           = args[idx + 1];
                    logReportsDirectoryWarning = false;
                }

                if (!Directory.Exists(reportsDirectory))
                {
                    Directory.CreateDirectory(reportsDirectory);
                }

                var modulesToAnalyze = new List <string>();
                if (args.Any(a => a.Equals("--modules-to-analyze") || a.Equals("-m")))
                {
                    int idx = Array.FindIndex(args, a => a.Equals("--modules-to-analyze") || a.Equals("-m"));
                    if (args[idx + 1] == null || args[idx + 1].StartsWith("-"))
                    {
                        Console.WriteLine("No value provided for the --modules-to-analyze parameter. Filtering over all built modules.");
                    }
                    else
                    {
                        var modules = args[idx + 1].Trim(' ', '\'', '"');
                        modulesToAnalyze = modules.Split(';').ToList();
                    }
                }

                foreach (var moduleName in modulesToAnalyze)
                {
                    Console.WriteLine(string.Format("Module: {0}", moduleName));
                }

                // We want to run analyzers separately and different modules for each analyzer. But we also want previous analyzer will not stop the subsequent ones.
                // So we make normal analyzer will not throw exception but write them into files and add a new issue checker to check the exceptions in files and throw them together if there is any.
                bool needToCheckIssue = false;
                if (args.Any(a => a.Equals("--analyzers")))
                {
                    int idx = Array.FindIndex(args, a => a.Equals("--analyzers"));
                    if (idx + 1 == args.Length)
                    {
                        throw new ArgumentException("No value provided for the --package-directory parameter.");
                    }

                    string analyzerNameList = args[idx + 1];
                    foreach (string analyzerName in analyzerNameList.Split(';'))
                    {
                        if (analyzerName.ToLower().Equals("breaking-change"))
                        {
                            Analyzers.Add(new BreakingChangeAnalyzer.BreakingChangeAnalyzer());
                        }
                        if (analyzerName.ToLower().Equals("dependency"))
                        {
                            Analyzers.Add(new DependencyAnalyzer.DependencyAnalyzer());
                        }
                        if (analyzerName.ToLower().Equals("signature"))
                        {
                            Analyzers.Add(new SignatureVerifier.SignatureVerifier());
                        }
                        if (analyzerName.ToLower().Equals("help"))
                        {
                            Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
                        }
                        if (analyzerName.ToLower().Equals("check-error"))
                        {
                            needToCheckIssue = true;
                        }
                    }
                }
                else
                {
                    Analyzers.Add(new BreakingChangeAnalyzer.BreakingChangeAnalyzer());
                    Analyzers.Add(new DependencyAnalyzer.DependencyAnalyzer());
                    Analyzers.Add(new SignatureVerifier.SignatureVerifier());
                    Analyzers.Add(new HelpAnalyzer.HelpAnalyzer());
                    needToCheckIssue = true;
                }

                // https://stackoverflow.com/a/9737418/294804
                var assemblyDirectory = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
                ExceptionsDirectory = Path.Combine(assemblyDirectory, "Exceptions");
                bool useExceptions = !args.Any(a => a.Equals("--dont-use-exceptions") || a.Equals("-d"));
                var  useNetcore    = args.Any(a => a.Equals("--use-netcore") || a.Equals("-u"));
                ConsolidateExceptionFiles(ExceptionsDirectory, useNetcore);

                analysisLogger = useExceptions ? new AnalysisLogger(reportsDirectory, ExceptionsDirectory) : new AnalysisLogger(reportsDirectory);
                if (logReportsDirectoryWarning)
                {
                    analysisLogger.WriteWarning("No logger specified in the second parameter, writing reports to {0}", reportsDirectory);
                }

                foreach (var analyzer in Analyzers)
                {
                    analyzer.Logger = analysisLogger;
                    analysisLogger.WriteMessage("Executing analyzer: {0}", analyzer.Name);
                    analyzer.Analyze(directories, modulesToAnalyze);
                    analysisLogger.WriteMessage("Processing complete for analyzer: {0}", analyzer.Name);
                }

                analysisLogger.WriteReports();
                if (needToCheckIssue)
                {
                    var analyzer = new IssueChecker.IssueChecker();
                    analyzer.Analyze(new[] { reportsDirectory });
                }
            }
            finally
            {
                foreach (var exceptionFileName in ExceptionFileNames)
                {
                    var exceptionFilePath = Path.Combine(ExceptionsDirectory, exceptionFileName);
                    if (File.Exists(exceptionFilePath))
                    {
                        File.Delete(exceptionFilePath);
                    }
                }
            }
        }
 public ReportLogger(string fileName, AnalysisLogger parent)
 {
     _parent     = parent;
     _outputFile = fileName;
 }
 public ReportLogger(string fileName, string exceptionsFilename, AnalysisLogger parent)
 {
     _parent             = parent;
     _outputFile         = fileName;
     _exceptionsFilename = exceptionsFilename;
 }
 public ReportLogger(string fileName, AnalysisLogger parent)
     : this(fileName, null, parent)
 {
 }