Skip to content

Commit

Permalink
(chocolateyGH-10) install from packages.config file
Browse files Browse the repository at this point in the history
If a config file is specified, use that to determine settings for each
package to install. Clone the config and make adjustments based on what
is in the packages.config file for that particular package.
  • Loading branch information
ferventcoder committed Feb 1, 2015
1 parent 2d6ddd2 commit 5bdc256
Showing 1 changed file with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace chocolatey.infrastructure.app.services
using configuration;
using domain;
using filesystem;
using infrastructure.services;
using logging;
using platforms;
using results;
Expand All @@ -37,8 +38,9 @@ public class ChocolateyPackageService : IChocolateyPackageService
private readonly IRegistryService _registryService;
private readonly IChocolateyPackageInformationService _packageInfoService;
private readonly IAutomaticUninstallerService _autoUninstallerService;
private readonly IXmlService _xmlService;

public ChocolateyPackageService(INugetService nugetService, IPowershellService powershellService, IShimGenerationService shimgenService, IFileSystem fileSystem, IRegistryService registryService, IChocolateyPackageInformationService packageInfoService, IAutomaticUninstallerService autoUninstallerService)
public ChocolateyPackageService(INugetService nugetService, IPowershellService powershellService, IShimGenerationService shimgenService, IFileSystem fileSystem, IRegistryService registryService, IChocolateyPackageInformationService packageInfoService, IAutomaticUninstallerService autoUninstallerService, IXmlService xmlService)
{
_nugetService = nugetService;
_powershellService = powershellService;
Expand All @@ -47,6 +49,7 @@ public ChocolateyPackageService(INugetService nugetService, IPowershellService p
_registryService = registryService;
_packageInfoService = packageInfoService;
_autoUninstallerService = autoUninstallerService;
_xmlService = xmlService;
}

public void list_noop(ChocolateyConfiguration config)
Expand Down Expand Up @@ -217,13 +220,11 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu


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,
packageConfig,
(packageResult) => handle_package_result(packageResult, packageConfig, CommandNameType.install)
);
foreach (var result in results)
Expand Down Expand Up @@ -264,21 +265,18 @@ private IEnumerable<ChocolateyConfiguration> set_config_from_package_names_and_p
{
config.PackageNames = config.PackageNames.Replace(packageConfigFile, string.Empty);

foreach (var package in get_packages_from_config(packageConfigFile, packageInstalls).or_empty_list_if_null())
foreach (var packageConfig in get_packages_from_config(packageConfigFile, config, packageInstalls).or_empty_list_if_null())
{
var packageConfig = config.deep_copy();
packageConfig.PackageNames = package;

yield return packageConfig;
}
}

yield return config;
}

private IEnumerable<string> get_packages_from_config(string packageConfigFile, ConcurrentDictionary<string, PackageResult> packageInstalls)
private IEnumerable<ChocolateyConfiguration> get_packages_from_config(string packageConfigFile, ChocolateyConfiguration config, ConcurrentDictionary<string, PackageResult> packageInstalls)
{
IList<string> packages = new List<string>();
IList<ChocolateyConfiguration> packageConfigs = new List<ChocolateyConfiguration>();

if (!_fileSystem.file_exists(_fileSystem.get_full_path(packageConfigFile)))
{
Expand All @@ -287,10 +285,29 @@ private IEnumerable<string> get_packages_from_config(string packageConfigFile, C
var results = packageInstalls.GetOrAdd(packageConfigFile, new PackageResult(packageConfigFile, null, null));
results.Messages.Add(new ResultMessage(ResultType.Error, logMessage));

return packages;
return packageConfigs;
}

var settings = _xmlService.deserialize<PackagesConfigFileSettings>(_fileSystem.get_full_path(packageConfigFile));
foreach (var pkgSettings in settings.Packages.or_empty_list_if_null())
{
if (!pkgSettings.Disabled)
{
var packageConfig = config.deep_copy();
packageConfig.PackageNames = pkgSettings.Id;
packageConfig.Sources = string.IsNullOrWhiteSpace(pkgSettings.Source) ? packageConfig.Sources : pkgSettings.Source;
packageConfig.Version = pkgSettings.Version;
packageConfig.InstallArguments = string.IsNullOrWhiteSpace(pkgSettings.InstallArguments) ? packageConfig.InstallArguments : pkgSettings.InstallArguments;
packageConfig.PackageParameters = string.IsNullOrWhiteSpace(pkgSettings.PackageParameters) ? packageConfig.PackageParameters : pkgSettings.PackageParameters;
if (pkgSettings.ForceX86) packageConfig.ForceX86 = true;
if (pkgSettings.AllowMultipleVersions) packageConfig.AllowMultipleVersions = true;
if (pkgSettings.IgnoreDependencies) packageConfig.IgnoreDependencies = true;

packageConfigs.Add(packageConfig);
}
}

return packages;
return packageConfigs;
}

public void upgrade_noop(ChocolateyConfiguration config)
Expand Down

0 comments on commit 5bdc256

Please sign in to comment.