Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
Update all of the ISourceRunners with changes to
IEnumerable<PackageResult>.

* stable:
  (GH-143) Ensure NuGetList streams output

Conflicts:
	src/chocolatey/infrastructure.app/services/INugetService.cs
	src/chocolatey/infrastructure.app/services/NugetService.cs
  • Loading branch information
ferventcoder committed Jun 29, 2015
2 parents b948920 + 73ba21f commit 79ed3af
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,12 @@ public override void Context()
configuration.Sources = ApplicationParameters.PackagesLocation;
configuration.ListCommand.LocalOnly = true;
configuration.AllVersions = true;
var packageResults = new ConcurrentDictionary<string, PackageResult>();
packageResults.GetOrAdd("regular", new PackageResult(package.Object, null));
packageResults.GetOrAdd("pinned", new PackageResult(pinnedPackage.Object, null));
nugetService.Setup(n => n.list_run(It.IsAny<ChocolateyConfiguration>(), false)).Returns(packageResults);
var packageResults = new []
{
new PackageResult(package.Object, null),
new PackageResult(pinnedPackage.Object, null)
};
nugetService.Setup(n => n.list_run(It.IsAny<ChocolateyConfiguration>(), true)).Returns(packageResults);
configuration.PinCommand.Command = PinCommandType.list;
}

Expand Down Expand Up @@ -412,7 +414,7 @@ public void should_call_nuget_service_list_run_when_command_is_list()
configuration.PinCommand.Command = PinCommandType.list;
command.run(configuration);

nugetService.Verify(n => n.list_run(It.IsAny<ChocolateyConfiguration>(), false), Times.Once);
nugetService.Verify(n => n.list_run(It.IsAny<ChocolateyConfiguration>(), true), Times.Once);
}

[Pending("NuGet is killing me with extension methods. Need to find proper item to mock out to return the package object.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ public void run(ChocolateyConfiguration configuration)

public void list_pins(IPackageManager packageManager, ChocolateyConfiguration config)
{
var localPackages = _nugetService.list_run(config, logResults: false);
foreach (var pkg in localPackages.or_empty_list_if_null())
foreach (var pkg in _nugetService.list_run(config, logResults: true))
{
var pkgInfo = _packageInfoService.get_package_information(pkg.Value.Package);
var pkgInfo = _packageInfoService.get_package_information(pkg.Package);
if (pkgInfo != null && pkgInfo.IsPinned)
{
this.Log().Info(() => "{0}|{1}".format_with(pkgInfo.Package.Id, pkgInfo.Package.Version));
Expand Down
12 changes: 6 additions & 6 deletions src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace chocolatey.infrastructure.app.nuget

// ReSharper disable InconsistentNaming

public sealed class NugetList
public static class NugetList
{
public static IEnumerable<IPackage> GetPackages(ChocolateyConfiguration configuration, ILogger nugetLogger)
{
Expand All @@ -31,7 +31,7 @@ public static IEnumerable<IPackage> GetPackages(ChocolateyConfiguration configur

if (configuration.AllVersions)
{
return results.Where(PackageExtensions.IsListed).OrderBy(p => p.Id).ToList();
return results.Where(PackageExtensions.IsListed).OrderBy(p => p.Id);
}

if (configuration.Prerelease && packageRepository.SupportsPrereleasePackages)
Expand All @@ -44,10 +44,10 @@ public static IEnumerable<IPackage> GetPackages(ChocolateyConfiguration configur
}

return results.OrderBy(p => p.Id)
.AsEnumerable()
.Where(PackageExtensions.IsListed)
.Where(p => configuration.Prerelease || p.IsReleaseVersion())
.distinct_last(PackageEqualityComparer.Id, PackageComparer.Version).ToList();
.AsEnumerable()
.Where(PackageExtensions.IsListed)
.Where(p => configuration.Prerelease || p.IsReleaseVersion())
.distinct_last(PackageEqualityComparer.Id, PackageComparer.Version);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void list_run(ChocolateyConfiguration config, bool logResults)
{
if (config.RegularOutput)
{
this.Log().Warn(() => @"{0} packages {1}.".format_with(list.Count, config.ListCommand.LocalOnly ? "installed" : "found"));
this.Log().Warn(() => @"{0} packages {1}.".format_with(list.Count(), config.ListCommand.LocalOnly ? "installed" : "found"));

if (config.ListCommand.LocalOnly && config.ListCommand.IncludeRegistryPrograms)
{
Expand All @@ -119,14 +119,14 @@ public void list_run(ChocolateyConfiguration config, bool logResults)
}
}

private void report_registry_programs(ChocolateyConfiguration config, ConcurrentDictionary<string, PackageResult> list)
private void report_registry_programs(ChocolateyConfiguration config, IEnumerable<PackageResult> list)
{
var itemsToRemoveFromMachine = new List<string>();
foreach (var packageResult in list)
{
if (packageResult.Value != null && packageResult.Value.Package != null)
if (packageResult != null && packageResult.Package != null)
{
var pkginfo = _packageInfoService.get_package_information(packageResult.Value.Package);
var pkginfo = _packageInfoService.get_package_information(packageResult.Package);
if (pkginfo.RegistrySnapshot == null)
{
continue;
Expand Down
5 changes: 3 additions & 2 deletions src/chocolatey/infrastructure.app/services/CygwinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace chocolatey.infrastructure.app.services
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Win32;
using configuration;
Expand Down Expand Up @@ -140,7 +141,7 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action<P

var localPackages = _nugetService.list_run(runnerConfig, logResults: false);

if (!localPackages.ContainsKey(CYGWIN_PACKAGE))
if (!localPackages.Any(p => p.Name.is_equal_to(CYGWIN_PACKAGE)))
{
runnerConfig.PackageNames = CYGWIN_PACKAGE;
runnerConfig.Sources = ApplicationParameters.ChocolateyCommunityFeedSource;
Expand Down Expand Up @@ -183,7 +184,7 @@ public void list_noop(ChocolateyConfiguration config)
this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement list".format_with(APP_NAME));
}

public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
{
throw new NotImplementedException("{0} does not implement list".format_with(APP_NAME));
}
Expand Down
3 changes: 2 additions & 1 deletion src/chocolatey/infrastructure.app/services/ISourceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace chocolatey.infrastructure.app.services
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using configuration;
using domain;
using results;
Expand Down Expand Up @@ -50,7 +51,7 @@ public interface ISourceRunner
/// <param name="config">The configuration.</param>
/// <param name="logResults">Should results be logged?</param>
/// <returns></returns>
ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults);
IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults);

/// <summary>
/// Run install in noop mode
Expand Down
28 changes: 10 additions & 18 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,34 @@ public void list_noop(ChocolateyConfiguration config)
));
}

public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults = true)
public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);

if (config.RegularOutput) this.Log().Debug(() => "Running list with the following filter = '{0}'".format_with(config.Input));

var packages = NugetList.GetPackages(config, _nugetLogger).ToList();

if (config.RegularOutput) this.Log().Debug(() => "--- Start of List ---");
foreach (var package in packages.or_empty_list_if_null())
foreach (var package in NugetList.GetPackages(config, _nugetLogger))
{
var pkg = package; // for lamda access
if (logResults)
{
if (config.RegularOutput)
{
this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0} {1}".format_with(package.Id, package.Version.to_string()));
if (config.Verbose) this.Log().Info(() => " {0}{1} Description: {2}{1} Tags: {3}{1} Number of Downloads: {4}{1}".format_with(package.Title.escape_curly_braces(), Environment.NewLine, package.Description.escape_curly_braces(), package.Tags.escape_curly_braces(), package.DownloadCount <= 0 ? "n/a" : package.DownloadCount.to_string()));
// Maintainer(s):{3}{1} | package.Owners.join(", ") - null at the moment
this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0} {1}".format_with(pkg.Id, pkg.Version.to_string()));
if (config.Verbose) this.Log().Info(() => " {0}{1} Description: {2}{1} Tags: {3}{1} Number of Downloads: {4}{1}".format_with(pkg.Title.escape_curly_braces(), Environment.NewLine, pkg.Description.escape_curly_braces(), pkg.Tags.escape_curly_braces(), pkg.DownloadCount <= 0 ? "n/a" : pkg.DownloadCount.to_string()));
// Maintainer(s):{3}{1} | pkg.Owners.join(", ") - null at the moment
}
else
{
this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0}|{1}".format_with(package.Id, package.Version.to_string()));
this.Log().Info(config.Verbose ? ChocolateyLoggers.Important : ChocolateyLoggers.Normal, () => "{0}|{1}".format_with(pkg.Id, pkg.Version.to_string()));
}
}
else
{
this.Log().Debug(() => "{0} {1}".format_with(package.Id, package.Version.to_string()));
this.Log().Debug(() => "{0} {1}".format_with(pkg.Id, pkg.Version.to_string()));
}

packageResults.GetOrAdd(package.Id, new PackageResult(package, null));
yield return new PackageResult(pkg, null);
}
if (config.RegularOutput) this.Log().Debug(() => "--- End of List ---");

return packageResults;
}

public void pack_noop(ChocolateyConfiguration config)
Expand Down Expand Up @@ -1044,13 +1038,11 @@ private void set_package_names_if_all_is_specified(ChocolateyConfiguration confi
var input = config.Input;
config.Input = string.Empty;

var localPackages = list_run(config, logResults: false);

config.PackageNames = list_run(config, logResults: false).Select(p => p.Name).@join(ApplicationParameters.PackageNamesSeparator);
config.Input = input;
config.Noop = noop;
config.Prerelease = pre;
config.Sources = sources;
config.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator, localPackages.Select((p) => p.Key).or_empty_list_if_null());

if (customAction != null) customAction.Invoke();
}
Expand Down
7 changes: 4 additions & 3 deletions src/chocolatey/infrastructure.app/services/PythonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Win32;
using configuration;
Expand Down Expand Up @@ -178,7 +179,7 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action<P

var localPackages = _nugetService.list_run(runnerConfig, logResults: false);

if (!localPackages.ContainsKey(PYTHON_PACKAGE))
if (!localPackages.Any(p => p.Name.is_equal_to(PYTHON_PACKAGE)))
{
runnerConfig.PackageNames = PYTHON_PACKAGE;
runnerConfig.Sources = ApplicationParameters.ChocolateyCommunityFeedSource;
Expand Down Expand Up @@ -269,11 +270,11 @@ public void list_noop(ChocolateyConfiguration config)
this.Log().Info("Would have run '{0} {1}'".format_with(_exePath, args));
}

public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
{
set_executable_path_if_not_set();
var args = build_args(config, _listArguments);
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var packageResults = new List<PackageResult>();

Environment.ExitCode = _commandExecutor.execute(
_exePath,
Expand Down
7 changes: 4 additions & 3 deletions src/chocolatey/infrastructure.app/services/RubyGemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using configuration;
using domain;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action<P

var localPackages = _nugetService.list_run(runnerConfig, logResults: false);

if (!localPackages.ContainsKey(RUBY_PACKAGE) && !localPackages.ContainsKey(RUBY_PORTABLE_PACKAGE))
if (!localPackages.Any(p => p.Name.is_equal_to(RUBY_PACKAGE) || p.Name.is_equal_to(RUBY_PORTABLE_PACKAGE)))
{
runnerConfig.Sources = ApplicationParameters.ChocolateyCommunityFeedSource;

Expand All @@ -130,9 +131,9 @@ public void list_noop(ChocolateyConfiguration config)
this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH, args));
}

public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var packageResults = new List<PackageResult>();
var args = ExternalCommandArgsBuilder.build_arguments(config, _listArguments);

Environment.ExitCode = _commandExecutor.execute(
Expand Down
7 changes: 4 additions & 3 deletions src/chocolatey/infrastructure.app/services/WebPiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace chocolatey.infrastructure.app.services
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using configuration;
using domain;
Expand Down Expand Up @@ -109,7 +110,7 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action<P

var localPackages = _nugetService.list_run(runnerConfig, logResults: false);

if (!localPackages.ContainsKey(WEB_PI_PACKAGE))
if (!localPackages.Any(p => p.Name.is_equal_to(WEB_PI_PACKAGE)))
{
runnerConfig.Sources = ApplicationParameters.ChocolateyCommunityFeedSource;

Expand All @@ -126,9 +127,9 @@ public void list_noop(ChocolateyConfiguration config)
this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH, args));
}

public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var packageResults = new List<PackageResult>();
var args = ExternalCommandArgsBuilder.build_arguments(config, _listArguments);

//var whereToStartRecording = "---";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public void list_noop(ChocolateyConfiguration config)
this.Log().Info("Would have run '{0} {1}'".format_with(_exePath, args));
}

public ConcurrentDictionary<string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
public IEnumerable<PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
{
set_executable_path_if_not_set();
var args = build_args(config, _listArguments);
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var packageResults = new List<PackageResult>();

Environment.ExitCode = _commandExecutor.execute(
_exePath,
Expand Down

0 comments on commit 79ed3af

Please sign in to comment.