From d078e5d655905a0614e6849599e945c7c386d361 Mon Sep 17 00:00:00 2001 From: Andreas Mosti Date: Thu, 28 Jul 2016 12:23:29 +0200 Subject: [PATCH] (GH-878) Installation with .config file prints packages in file Previously when running choco install with a .config file as parameter the output would say ''Installing the following packages:'' followed by the path to the .config file. This change prints out that a .config file is being used, as well as listing the packages set for installation. --- Scenarios.md | 4 +++- .../scenarios/InstallScenarios.cs | 24 +++++++++++++++++++ .../services/ChocolateyPackageService.cs | 12 ++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Scenarios.md b/Scenarios.md index 8143248da0..a515601028 100644 --- a/Scenarios.md +++ b/Scenarios.md @@ -1,6 +1,6 @@ ## Chocolatey Usage Scenarios -### ChocolateyInstallCommand [ 35 Scenario(s), 291 Observation(s) ] +### ChocolateyInstallCommand [ 35 Scenario(s), 293 Observation(s) ] #### when force installing a package that depends on an unavailable newer version of an installed dependency forcing dependencies @@ -362,6 +362,8 @@ * should not have a successful package result for missing package * should not have inconclusive package result * should not have warning package result + * should print out package from config file in message + * should specify config file is being used in message #### when noop installing a package diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index e7d9e732fc..93e71a31da 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -435,6 +435,30 @@ public void should_not_have_warning_package_result() packageResult.Value.Warning.ShouldBeFalse(); } } + + [Fact] + public void should_specify_config_file_is_being_used_in_message() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) + { + if (message.Contains("Installing from config file:")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } + + [Fact] + public void should_print_out_package_from_config_file_in_message() + { + bool expectedMessage = false; + foreach (var message in MockLogger.MessagesFor(LogLevel.Info).or_empty_list_if_null()) + { + if (message.Contains("installpackage")) expectedMessage = true; + } + + expectedMessage.ShouldBeTrue(); + } } [Concern(typeof(ChocolateyInstallCommand))] diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 907d28c968..4a013aadda 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -422,7 +422,7 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p public ConcurrentDictionary install_run(ChocolateyConfiguration config) { - this.Log().Info(@"Installing the following packages:"); + this.Log().Info(is_packages_config_file(config) ? @"Installing from config file:" : @"Installing the following packages:"); this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); var packageInstalls = new ConcurrentDictionary(); @@ -446,6 +446,7 @@ public ConcurrentDictionary install_run(ChocolateyConfigu { action = (packageResult) => handle_package_result(packageResult, packageConfig, CommandNameType.install); } + var results = perform_source_runner_function(packageConfig, r => r.install_run(packageConfig, action)); foreach (var result in results) @@ -524,13 +525,18 @@ private IEnumerable set_config_from_package_names_and_p foreach (var packageConfig in get_packages_from_config(packageConfigFile, config, packageInstalls).or_empty_list_if_null()) { - yield return packageConfig; + yield return packageConfig; } } yield return config; } + private bool is_packages_config_file(ChocolateyConfiguration config) + { + return config.PackageNames.Split(new[] {ApplicationParameters.PackageNamesSeparator}, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Any(p => p.EndsWith(".config")); + } + private IEnumerable get_packages_from_config(string packageConfigFile, ChocolateyConfiguration config, ConcurrentDictionary packageInstalls) { IList packageConfigs = new List(); @@ -546,6 +552,7 @@ private IEnumerable get_packages_from_config(string pac } var settings = _xmlService.deserialize(_fileSystem.get_full_path(packageConfigFile)); + this.Log().Info(@"Installing the following packages:"); foreach (var pkgSettings in settings.Packages.or_empty_list_if_null()) { if (!pkgSettings.Disabled) @@ -560,6 +567,7 @@ private IEnumerable get_packages_from_config(string pac if (pkgSettings.AllowMultipleVersions) packageConfig.AllowMultipleVersions = true; if (pkgSettings.IgnoreDependencies) packageConfig.IgnoreDependencies = true; + this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(packageConfig.PackageNames)); packageConfigs.Add(packageConfig); } }