From 6be7c157ff79c3d0f757a92560d80a2d6725a928 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sun, 25 Jan 2015 17:16:15 -0600 Subject: [PATCH] (GH-10) Allow .config items in package names Split config file names off of the package names list for further processing. Continue processing normal package names. --- .../services/ChocolateyPackageService.cs | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 0363cc79c8..07c96fa151 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -140,7 +140,11 @@ public void push_run(ChocolateyConfiguration config) public void install_noop(ChocolateyConfiguration config) { - _nugetService.install_noop(config, (pkg) => _powershellService.install_noop(pkg)); + // each package can specify its own configuration values + foreach (var packageConfig in set_config_from_package_names_and_packages_config(config, new ConcurrentDictionary()).or_empty_list_if_null()) + { + _nugetService.install_noop(packageConfig, (pkg) => _powershellService.install_noop(pkg)); + } } public void handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName) @@ -210,10 +214,22 @@ public ConcurrentDictionary install_run(ChocolateyConfigu this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); this.Log().Info(@"By installing you accept licenses for the packages."); - var packageInstalls = _nugetService.install_run( - config, - (packageResult) => handle_package_result(packageResult, config, CommandNameType.install) - ); + + var packageInstalls = new ConcurrentDictionary(); + var originalConfig = config.deep_copy(); + + //each package can specify its own configuration values + foreach (var packageConfig in set_config_from_package_names_and_packages_config(config, packageInstalls).or_empty_list_if_null()) + { + var results = _nugetService.install_run( + config, + (packageResult) => handle_package_result(packageResult, packageConfig, CommandNameType.install) + ); + foreach (var result in results) + { + packageInstalls.GetOrAdd(result.Key, result.Value); + } + } var installFailures = packageInstalls.Count(p => !p.Value.Success); this.Log().Warn(() => @"{0}{1} installed {2}/{3} packages. {4} packages failed.{0}See the log for details.".format_with( @@ -240,6 +256,18 @@ public ConcurrentDictionary install_run(ChocolateyConfigu return packageInstalls; } + private IEnumerable set_config_from_package_names_and_packages_config(ChocolateyConfiguration config, ConcurrentDictionary packageInstalls) + { + // if there are any .config files, split those off of the config. Then return the config without those package names. + foreach (var packageConfigFile in config.PackageNames.Split(new[] {ApplicationParameters.PackageNamesSeparator}, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Where(p => p.Contains(".config")).ToList()) + { + config.PackageNames = config.PackageNames.Replace(packageConfigFile, string.Empty); + + } + + yield return config; + } + public void upgrade_noop(ChocolateyConfiguration config) { _nugetService.upgrade_noop(config, (pkg) => _powershellService.install_noop(pkg));