Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (maint) Remove unnecessary whitespace
  (#2304) Fix list --exact -a for prereleases
  (#2124) Add ability to initialize without logging
  (#2313) Add argument to call to NuGet.exe
  (doc) fix typo in Readme
  • Loading branch information
gep13 committed Aug 19, 2021
2 parents af3e8c9 + 85d522f commit c967779
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .build/compile.step
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
if="${platform::is-unix()}"
>
<arg value='"${app.nuget}"' />
<arg value='restore "${solution.path}"' />
<arg value='restore "${solution.path}" -DisableParallelProcessing' />
</exec>
</target>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ If you are using a [commercial edition of Chocolatey](https://chocolatey.org/com
## Information
* [Chocolatey Website and Community Package Repository](https://community.chocolatey.org)
* [Mailing List](http://groups.google.com/group/chocolatey) / [Release Announcements Only Mailing List](https://groups.google.com/group/chocolatey-announce) / [Build Status Mailing List](http://groups.google.com/group/chocolatey-build-status)
* [Twitter](https://twitter.com/chocolateynuget) / [Facebook](https://www.facebook.com/ChocolateySoftware) / [Github](https://github.com/chocolatey)
* [Twitter](https://twitter.com/chocolateynuget) / [Facebook](https://www.facebook.com/ChocolateySoftware) / [GitHub](https://github.com/chocolatey)
* [Blog](https://blog.chocolatey.org/) / [Newsletter](https://chocolatey.us8.list-manage1.com/subscribe?u=86a6d80146a0da7f2223712e4&id=73b018498d)
* [Documentation](https://docs.chocolatey.org/en-us/) / [Support](https://chocolatey.org/support)

Expand Down
16 changes: 15 additions & 1 deletion Scenarios.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
* should not have inconclusive package result
* should not have warning package result

### ChocolateyListCommand [ 11 Scenario(s), 48 Observation(s) ]
### ChocolateyListCommand [ 13 Scenario(s), 56 Observation(s) ]

#### when listing local packages

Expand Down Expand Up @@ -448,6 +448,20 @@
* should contain packages and versions with a space between them
* should not contain packages that do not match

#### when searching for all packages including prerelease with exact id

* should find all versions in descending order
* should find only packages with exact id
* should find three results
* should not error

#### when searching for all packages with exact id

* should find all non prerelease versions in descending order
* should find only packages with exact id
* should find two results
* should not error

#### when searching for an exact package

* should contain a summary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@
<None Include="context\exactpackage\exactpackage.dontfind\1.0.0\exactpackage.dontfind.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\exactpackage\exactpackage\0.9.0\exactpackage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\exactpackage\exactpackage\1.0.0-beta1\exactpackage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="context\exactpackage\exactpackage\1.0.0\exactpackage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -479,6 +485,12 @@
<Content Include="context\exactpackage\exactpackage.dontfind\1.0.0\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="context\exactpackage\exactpackage\0.9.0\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="context\exactpackage\exactpackage\1.0.0-beta1\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="context\exactpackage\exactpackage\1.0.0\tools\purpose.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>exactpackage</id>
<version>0.9.0</version>
<title>exactpackage</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>exactpackage admin</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
when running choco list exactpackage -e --all, this package should be in the resulting list.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>exactpackage</id>
<version>1.0.0-beta1</version>
<title>exactpackage</title>
<authors>__REPLACE_AUTHORS_OF_SOFTWARE__</authors>
<owners>__REPLACE_YOUR_NAME__</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>__REPLACE__</description>
<summary>__REPLACE__</summary>
<releaseNotes />
<tags>exactpackage admin</tags>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When running choco list exactpackage -a --all --pre, this package should be in the returned results.
103 changes: 101 additions & 2 deletions src/chocolatey.tests.integration/scenarios/ListScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ public void should_contain_debugging_messages()
MockLogger.contains_message("Start of List", LogLevel.Debug).ShouldBeTrue();
MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue();
}
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_searching_for_an_exact_package_with_zero_results : ScenariosBase
{
Expand Down Expand Up @@ -553,5 +553,104 @@ public void should_contain_debugging_messages()
MockLogger.contains_message("End of List", LogLevel.Debug).ShouldBeTrue();
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_searching_for_all_packages_with_exact_id : ScenariosBase
{
public override void Context()
{
Configuration = Scenario.list();
Scenario.reset(Configuration);
Scenario.add_packages_to_source_location(Configuration, "exactpackage*" + Constants.PackageExtension);
Service = NUnitSetup.Container.GetInstance<IChocolateyPackageService>();

Configuration.ListCommand.Exact = true;
Configuration.AllVersions = true;
Configuration.Input = Configuration.PackageNames = "exactpackage";
}

public override void Because()
{
MockLogger.reset();
Results = Service.list_run(Configuration).ToList();
}

[Fact]
public void should_not_error()
{
// nothing necessary here
}

[Fact]
public void should_find_two_results()
{
Results.Count.ShouldEqual(2);
}

[Fact]
public void should_find_only_packages_with_exact_id()
{
Results[0].Package.Id.ShouldEqual("exactpackage");
Results[1].Package.Id.ShouldEqual("exactpackage");
}

[Fact]
public void should_find_all_non_prerelease_versions_in_descending_order()
{
Results[0].Package.Version.ToNormalizedString().ShouldEqual("1.0.0");
Results[1].Package.Version.ToNormalizedString().ShouldEqual("0.9.0");
}
}

[Concern(typeof(ChocolateyListCommand))]
public class when_searching_for_all_packages_including_prerelease_with_exact_id : ScenariosBase
{
public override void Context()
{
Configuration = Scenario.list();
Scenario.reset(Configuration);
Scenario.add_packages_to_source_location(Configuration, "exactpackage*" + Constants.PackageExtension);
Service = NUnitSetup.Container.GetInstance<IChocolateyPackageService>();

Configuration.ListCommand.Exact = true;
Configuration.AllVersions = true;
Configuration.Prerelease = true;
Configuration.Input = Configuration.PackageNames = "exactpackage";
}

public override void Because()
{
MockLogger.reset();
Results = Service.list_run(Configuration).ToList();
}

[Fact]
public void should_not_error()
{
// nothing necessary here
}

[Fact]
public void should_find_three_results()
{
Results.Count.ShouldEqual(3);
}

[Fact]
public void should_find_only_packages_with_exact_id()
{
Results[0].Package.Id.ShouldEqual("exactpackage");
Results[1].Package.Id.ShouldEqual("exactpackage");
Results[2].Package.Id.ShouldEqual("exactpackage");
}

[Fact]
public void should_find_all_versions_in_descending_order()
{
Results[0].Package.Version.ToNormalizedString().ShouldEqual("1.0.0");
Results[1].Package.Version.ToNormalizedString().ShouldEqual("1.0.0-beta1");
Results[2].Package.Version.ToNormalizedString().ShouldEqual("0.9.0");
}
}
}
}
56 changes: 47 additions & 9 deletions src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace chocolatey
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using infrastructure.licensing;
using SimpleInjector;
Expand Down Expand Up @@ -47,16 +48,21 @@ public static class Lets
{
private static readonly log4net.ILog _logger = LogManager.GetLogger(typeof(Lets));

private static GetChocolatey set_up()
private static GetChocolatey set_up(bool initializeLogging)
{
add_assembly_resolver();

return new GetChocolatey();
return new GetChocolatey(initializeLogging);
}

public static GetChocolatey GetChocolatey()
{
return GlobalMutex.enter(() => set_up(), 10);
return GetChocolatey(initializeLogging: true);
}

public static GetChocolatey GetChocolatey(bool initializeLogging)
{
return GlobalMutex.enter(() => set_up(initializeLogging), 10);
}

private static ResolveEventHandler _handler = null;
Expand Down Expand Up @@ -122,12 +128,24 @@ public class GetChocolatey
/// Initializes a new instance of the <see cref="GetChocolatey"/> class.
/// </summary>
public GetChocolatey()
: this(initializeLogging: true)
{
}

public GetChocolatey(bool initializeLogging)
{
Log4NetAppenderConfiguration.configure(null, excludeLoggerNames: ChocolateyLoggers.Trace.to_string());
Bootstrap.initialize();
Log.InitializeWith(new AggregateLog(new List<ILog>() { new Log4NetLog(), _logSinkLogger }));
_license = License.validate_license();
_container = SimpleInjectorContainer.Container;
if (initializeLogging)
{
string loggingLocation = ApplicationParameters.LoggingLocation;
var fileSystem = _container.GetInstance<IFileSystem>();
fileSystem.create_directory_if_not_exists(loggingLocation);

Log4NetAppenderConfiguration.configure(loggingLocation, excludeLoggerNames: ChocolateyLoggers.Trace.to_string());
Log.InitializeWith(new AggregateLog(new List<ILog>() { new Log4NetLog(), _logSinkLogger }));
"chocolatey".Log().Debug("XmlConfiguration is now operational");
}
_license = License.validate_license();
}

/// <summary>
Expand All @@ -137,8 +155,28 @@ public GetChocolatey()
/// <returns>This <see cref="GetChocolatey"/> instance</returns>
public GetChocolatey SetCustomLogging(ILog logger)
{
Log.InitializeWith(logger, resetLoggers: false);
drain_log_sink(logger);
return SetCustomLogging(logger, logExistingMessages: true, addToExistingLoggers: false);
}

public GetChocolatey SetCustomLogging(ILog logger, bool logExistingMessages)
{
return SetCustomLogging(logger, logExistingMessages, addToExistingLoggers: false);
}

public GetChocolatey SetCustomLogging(ILog logger, bool logExistingMessages, bool addToExistingLoggers)
{
var aggregateLog = new AggregateLog(new List<ILog> { logger });
if (addToExistingLoggers)
{
aggregateLog = new AggregateLog(new List<ILog> { logger, Log.GetLoggerFor("chocolatey") });
}

Log.InitializeWith(aggregateLog, resetLoggers: false);
if (logExistingMessages)
{
drain_log_sink(logger);
}

return this;
}

Expand Down
14 changes: 10 additions & 4 deletions src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ private static IQueryable<IPackage> execute_package_search(ChocolateyConfigurati
isServiceBased = packageRepository is IServiceBasedRepository;
}

IQueryable<IPackage> results = packageRepository.Search(searchTermLower, configuration.Prerelease);

SemanticVersion version = !string.IsNullOrWhiteSpace(configuration.Version) ? new SemanticVersion(configuration.Version) : null;
IQueryable<IPackage> results;

if (configuration.ListCommand.Exact)
if (!configuration.ListCommand.Exact)
{
results = packageRepository.Search(searchTermLower, configuration.Prerelease);
}
else
{
if (configuration.AllVersions)
{
// convert from a search to getting packages by id.
// search based on lower case id - similar to PackageRepositoryExtensions.FindPackagesByIdCore()
results = packageRepository.GetPackages().Where(x => x.Id.ToLower() == searchTermLower);
results = packageRepository.GetPackages().Where(p => p.Id.ToLower() == searchTermLower)
.AsEnumerable()
.Where(p => configuration.Prerelease || p.IsReleaseVersion())
.AsQueryable();
}
else
{
Expand Down

0 comments on commit c967779

Please sign in to comment.