Пример #1
0
 static void ApplyOverrides(AppSettings appSettings, CompareCommand command)
 {
     appSettings.AdditionalRulesPath = command.AdditionalRulesPath ?? appSettings.AdditionalRulesPath;
     appSettings.IncludeHeader       = command.IncludeHeader ?? appSettings.IncludeHeader;
     appSettings.OmitDisclaimer      = command.OmitDisclaimer ?? appSettings.OmitDisclaimer;
     appSettings.AssumeChanges       = command.AssumeChanges ?? appSettings.AssumeChanges;
     appSettings.Framework           = command.Framework ?? appSettings.Framework;
 }
Пример #2
0
        static void ConfigureServices(IConfiguration config, CompareCommand command)
        {
            var builder = new ContainerBuilder();

            var appSettings = config.GetSection("settings").Get <AppSettings>() ?? new AppSettings();

            ApplyOverrides(appSettings, command);

            builder.RegisterInstance(appSettings).AsSelf();
            var nugetConfig = config.GetSection("nuget").Get <NugetConfiguration>();

            if (nugetConfig?.RepositoryUrl == null)
            {
                Console.WriteLine("Nuget repository missing from configuration.");
                Environment.Exit(1);
            }
            builder.RegisterInstance(nugetConfig).AsSelf();

            builder.RegisterModule(new AppModule(appSettings));
            builder.RegisterModule(new ExternalRuleModule(appSettings));

            _container = builder.Build();
        }
Пример #3
0
        static async Task Compare(CompareCommand command)
        {
            var config = BuildConfiguration(command.Configuration);

            ConfigureServices(config, command);

            var validationResult = command.Validate();

            if (validationResult != null)
            {
                Console.WriteLine($"Error:\n\t{validationResult}");
                Environment.Exit(1);
            }

            var runner = _container.Resolve <CompareCommandRunner>();
            var report = await runner.Compare(command);

            if (!string.IsNullOrWhiteSpace(command.OutputPath))
            {
                await File.WriteAllTextAsync(command.OutputPath, report);
            }
            Console.WriteLine(report);
        }
Пример #4
0
        public async Task <string> Compare(CompareCommand command)
        {
            string report = null;
            AssemblyPublicInterface localAssembly = null;
            var comments = new List <string>();

            try
            {
                localAssembly = AssemblyPublicInterface.Load(command.FullAssemblyPath);

                var bytes = await _nugetClient.GetAssemblyBytesFromPackage(command.PackageName, command.AssemblyFileName, localAssembly.Framework, comments);

                if (bytes == null)
                {
                    return($"An error has current processing your request:\n\n" +
                           $"- {string.Join("\n- ", comments)}");
                }

                var onlineAssembly = AssemblyPublicInterface.Load(bytes);

                var result = _analyzer.AnalyzeVersions(localAssembly, onlineAssembly);

                if (result.ActualBump != result.CalculatedBump)
                {
                    comments = result.GetAllComments();
                    if (_settings.IncludeHeader)
                    {
                        report = command.AssemblyFileName == command.PackageName
                                                        ? $"# {command.AssemblyFileName}\n\n"
                                                        : $"# {command.AssemblyFileName} ( {command.PackageName} )\n\n";
                    }
                    if (!_settings.OmitDisclaimer)
                    {
                        report += "*This is a sanity check that indicates whether the change is more severe than intended.  " +
                                  "It is not foolproof as not all changes can be detected by analyzing the public interface of an " +
                                  "assembly.  Therefore the results of this check are to be considered as a suggestion.  You may determine " +
                                  "that a particular change warrants a more severe version bump than is suggested by this check.*\n\n" +
                                  "**Please use your best judgment when updating the version.  You know your change better than this check can.**\n\n";
                    }
                    report += $"## Summary\n\n" +
                              $"Actual new version: `{localAssembly.Version}` ({result.ActualBump})\n" +
                              $"Suggested new version: `{onlineAssembly.Version.GetSuggestedVersion(result.CalculatedBump)}` ({result.CalculatedBump}).\n";
                    if (comments.Any())
                    {
                        report += $"\n## Details\n\n" +
                                  $"- {string.Join("\n- ", comments)}\n";
                    }
                }
            }
            catch (Exception e)
            {
                var sb    = new StringBuilder();
                var which = localAssembly == null ? "built" : "online";
                sb.AppendLine($"An error occurred while attempting to load the {which} assembly.  Analysis cannot continue.");
                sb.AppendLine("Exception:");
                sb.AppendLine(e.Message);
                sb.AppendLine(e.StackTrace);
                if (e.InnerException != null)
                {
                    sb.AppendLine("Inner Exception:");
                    sb.AppendLine(e.InnerException.Message);
                    sb.AppendLine(e.InnerException.StackTrace);
                }

                report = sb.ToString();
            }

            return(report);
        }