Example #1
0
        //Get an instance of a logger for a file name
        public static TextFileLogger GetTextFileLogger(string fileName, bool overriteExisting)
        {
            TextFileLogger loggerToReturn = null;

            lock (loggerTable)
            {
                if (loggerTable.ContainsKey(fileName))
                {
                    TextLoggerData data = (TextLoggerData)loggerTable[fileName];
                    data.NumberOfReferences += 1;
                    loggerToReturn           = data.LoggerInstance;
                }
                else
                {
                    TextFileLogger logger = new TextFileLogger();
                    logger.LogFileName = fileName;
                    logger.Init(overriteExisting);

                    TextLoggerData loggerData = new TextLoggerData();
                    loggerData.NumberOfReferences = 1;
                    loggerData.LoggerInstance     = logger;
                    loggerToReturn = logger;

                    loggerTable.Add(fileName, logger);
                }
            }
            return(loggerToReturn);
        }
Example #2
0
        //Logs all the breaking changes in a module as a unit (all cmdlets in the same module appear contiguously)
        private static void LogBreakingChangesInModule(BreakingChangeAttributesInModule moduleData, TextFileLogger logger)
        {
            var textForBreakingChangesInModule = string.Format(BreakingChangeModuleHeaderFormatString, Path.GetFileName(moduleData.ModuleName));

            foreach (var cmdletData in moduleData.CmdletList)
            {
                textForBreakingChangesInModule += string.Format(BreakingChangeCmdletHeaderFormatString, cmdletData.CmdletName);
// TODO: Remove IfDef code
#if !NETSTANDARD
                foreach (GenericBreakingChangeAttribute attribute in cmdletData.BreakingChangeAttributes)
                {
                    textForBreakingChangesInModule += attribute.GetBreakingChangeTextFromAttribute(cmdletData.CmdletType, true) + "\n\n";
                }
#endif
            }

            //Now that we have the text, add it to the log file
            logger.LogMessage(textForBreakingChangesInModule);
        }
Example #3
0
        /// <summary>
        /// Given a set of directory paths containing PowerShell module folders,
        /// analyze the breaking changes in the modules and report any issues
        ///
        /// Filters can be added to find breaking changes for specific modules
        /// </summary>
        /// <param name="cmdletProbingDirs">Set of directory paths containing PowerShell module folders to be checked for breaking changes.</param>
        /// <param name="directoryFilter">Function that filters the directory paths to be checked.</param>
        /// <param name="cmdletFilter">Function that filters the cmdlets to be checked.</param>
        /// <param name="modulesToAnalyze">The set of modules to analyze</param>
        public void Analyze(IEnumerable <string> cmdletProbingDirs, Func <IEnumerable <string>, IEnumerable <string> > directoryFilter, Func <string, bool> cmdletFilter, IEnumerable <string> modulesToAnalyze)
        {
            if (directoryFilter != null)
            {
                cmdletProbingDirs = directoryFilter(cmdletProbingDirs);
            }

            var logFileName = Path.Combine(OutputFilePath, BreakingChangeAttributeReportLoggerName);
            //Init the log file
            var logger = TextFileLogger.GetTextFileLogger(logFileName, CleanBreakingChangesFileBeforeWriting);

            try
            {
                foreach (var baseDirectory in cmdletProbingDirs.Where(s => !s.Contains("ServiceManagement") &&
                                                                      !ModuleFilter.IsAzureStackModule(s) && Directory.Exists(Path.GetFullPath(s))))
                {
                    var probingDirectories = new List <string> {
                        baseDirectory
                    };

                    // Add current directory for probing
                    probingDirectories.AddRange(Directory.EnumerateDirectories(Path.GetFullPath(baseDirectory)));


                    foreach (var directory in probingDirectories)
                    {
                        if (modulesToAnalyze != null &&
                            modulesToAnalyze.Any() &&
                            !modulesToAnalyze.Any(m => directory.EndsWith(m)))
                        {
                            continue;
                        }

                        var cmdlets = GetCmdletsFilesInFolder(directory);
                        if (!cmdlets.Any())
                        {
                            continue;
                        }

                        foreach (var cmdletFileName in cmdlets)
                        {
                            var cmdletFileFullPath = Path.Combine(directory, Path.GetFileName(cmdletFileName));

                            if (!File.Exists(cmdletFileFullPath))
                            {
                                continue;
                            }

// TODO: Remove IfDef
#if NETSTANDARD
                            var proxy = new CmdletBreakingChangeAttributeLoader();
#else
                            var proxy = EnvironmentHelpers.CreateProxy <CmdletBreakingChangeAttributeLoader>(directory, out _appDomain);
#endif
                            var cmdletDataForModule = proxy.GetModuleBreakingChangeAttributes(cmdletFileFullPath);

                            //If there is nothing in this module just continue
                            if (cmdletDataForModule == null)
                            {
                                Console.WriteLine("No breaking change attributes found in module " + cmdletFileName);
                                continue;
                            }

                            if (cmdletFilter != null)
                            {
                                var output = string.Format("Before filter\nmodule cmdlet count: {0}\n",
                                                           cmdletDataForModule.CmdletList.Count);

                                output += string.Format("\nCmdlet file: {0}", cmdletFileFullPath);

                                cmdletDataForModule.FilterCmdlets(cmdletFilter);

                                output += string.Format("After filter\nmodule cmdlet count: {0}\n",
                                                        cmdletDataForModule.CmdletList.Count);

                                foreach (var cmdlet in cmdletDataForModule.CmdletList)
                                {
                                    output += string.Format("\n\tcmdlet - {0}", cmdlet.CmdletName);
                                }

                                Console.WriteLine(output);
                            }

                            LogBreakingChangesInModule(cmdletDataForModule, logger);
// TODO: Remove IfDef code
#if !NETSTANDARD
                            AppDomain.Unload(_appDomain);
#endif
                        }
                    }
                }
            }
            finally
            {
                if (logger != null)
                {
                    TextFileLogger.CloseLogger(logFileName);
                }
            }
        }
        //Logs all the breaking changes in a module as a unit (all cmdlets in the same module appear contigously)
        private void LogBreakingChangesInModule(BreakingChangeAttributesInModule moduleData, TextFileLogger logger)
        {
            string textForBreakingChangesInModule = string.Format(BREAKING_CHANGE_MODUE_HEADER_FORMAT_STRING, Path.GetFileName(moduleData.ModuleName));

            foreach (BreakingChangeAttributesInCmdlet cmdletData in moduleData.CmdletList)
            {
                textForBreakingChangesInModule += string.Format(BREAKING_CHANGE_CMDLET_HEADER_FORMAT_STRING, cmdletData.CmdletName);
#if !NETSTANDARD
                foreach (GenericBreakingChangeAttribute attribute in cmdletData.BreakingChangeAttributes)
                {
                    textForBreakingChangesInModule += attribute.GetBreakingChangeTextFromAttribute(cmdletData.CmdletType, true) + "\n\n";
                }
#endif
            }

            //Now that we have the text, add it to the log file
            logger.LogMessage(textForBreakingChangesInModule);
        }
Example #5
0
        /// <summary>
        /// Given a set of directory paths containing PowerShell module folders,
        /// analyze the breaking changes in the modules and report any issues
        ///
        /// Filters can be added to find breaking changes for specific modules
        /// </summary>
        /// <param name="cmdletProbingDirs">Set of directory paths containing PowerShell module folders to be checked for breaking changes.</param>
        /// <param name="directoryFilter">Function that filters the directory paths to be checked.</param>
        /// <param name="cmdletFilter">Function that filters the cmdlets to be checked.</param>
        public void Analyze(IEnumerable <string> cmdletProbingDirs, Func <IEnumerable <string>, IEnumerable <string> > directoryFilter, Func <string, bool> cmdletFilter)
        {
            var savedDirectory = Directory.GetCurrentDirectory();

            if (directoryFilter != null)
            {
                cmdletProbingDirs = directoryFilter(cmdletProbingDirs);
            }

            var logFileName = Path.Combine(OutputFilePath, BreakingChangeAttributeReportLoggerName);
            //Init the log file
            TextFileLogger logger = TextFileLogger.GetTextFileLogger(logFileName, CleanBreakingChangesFileBeforeWriting);

            try
            {
                foreach (var baseDirectory in cmdletProbingDirs.Where(s => !s.Contains("ServiceManagement") &&
                                                                      !s.Contains("Stack") && Directory.Exists(Path.GetFullPath(s))))
                {
                    List <string> probingDirectories = new List <string>();

                    // Add current directory for probing
                    probingDirectories.Add(baseDirectory);
                    probingDirectories.AddRange(Directory.EnumerateDirectories(Path.GetFullPath(baseDirectory)));


                    foreach (var directory in probingDirectories)
                    {
                        IEnumerable <string> cmdlets = GetCmdletsFilesInFolder(directory);
                        if (cmdlets.Any())
                        {
                            foreach (var cmdletFileName in cmdlets)
                            {
                                var cmdletFileFullPath = Path.Combine(directory, Path.GetFileName(cmdletFileName));

                                if (File.Exists(cmdletFileFullPath))
                                {
                                    var proxy =
                                        EnvironmentHelpers.CreateProxy <CmdletBreakingChangeAttributeLoader>(directory, out _appDomain);
                                    var cmdletDataForModule = proxy.GetModuleBreakingChangeAttributes(cmdletFileFullPath);

                                    //If there is nothing in this module just onctinue
                                    if (cmdletDataForModule == null)
                                    {
                                        Console.WriteLine("No breaking change attributes found in module " + cmdletFileName);
                                        continue;
                                    }

                                    if (cmdletFilter != null)
                                    {
                                        string output = string.Format("Before filter\nmodule cmdlet count: {0}\n",
                                                                      cmdletDataForModule.CmdletList.Count);

                                        output += string.Format("\nCmdlet file: {0}", cmdletFileFullPath);

                                        cmdletDataForModule.FilterCmdlets(cmdletFilter);

                                        output += string.Format("After filter\nmodule cmdlet count: {0}\n",
                                                                cmdletDataForModule.CmdletList.Count);

                                        foreach (var cmdlet in cmdletDataForModule.CmdletList)
                                        {
                                            output += string.Format("\n\tcmdlet - {0}", cmdlet.CmdletName);
                                        }

                                        Console.WriteLine(output);
                                    }

                                    LogBreakingChangesInModule(cmdletDataForModule, logger);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (logger != null)
                {
                    TextFileLogger.CloseLogger(logFileName);
                    logger = null;
                }
            }
        }