Skip to content

Commit

Permalink
(chocolateyGH-10) Allow .config items in package names
Browse files Browse the repository at this point in the history
Split config file names off of the package names list for further
processing. Continue processing normal package names.
  • Loading branch information
ferventcoder committed Jan 25, 2015
1 parent 66c7d4d commit 24d0fa9
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,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<string, PackageResult>()).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)
Expand Down Expand Up @@ -211,10 +215,22 @@ public ConcurrentDictionary<string, PackageResult> 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<string, PackageResult>();
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(
Expand All @@ -241,6 +257,18 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
return packageInstalls;
}

private IEnumerable<ChocolateyConfiguration> set_config_from_package_names_and_packages_config(ChocolateyConfiguration config, ConcurrentDictionary<string, PackageResult> 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));
Expand Down Expand Up @@ -307,7 +335,7 @@ public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfi

if (!config.SkipPackageInstallProvider)
{
_powershellService.uninstall(config, packageResult);
_powershellService.uninstall(config, packageResult);
}

_autoUninstallerService.run(packageResult, config);
Expand Down

0 comments on commit 24d0fa9

Please sign in to comment.