diff --git a/.build/compile.step b/.build/compile.step
index 62aaf4ec6b..49888ddb06 100644
--- a/.build/compile.step
+++ b/.build/compile.step
@@ -75,7 +75,7 @@
if="${platform::is-unix()}"
>
-
+
diff --git a/README.md b/README.md
index c497cc7bf8..e23e79428f 100644
--- a/README.md
+++ b/README.md
@@ -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)
diff --git a/Scenarios.md b/Scenarios.md
index c9767724fb..ba7b16ba85 100644
--- a/Scenarios.md
+++ b/Scenarios.md
@@ -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
@@ -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
diff --git a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj
index f9b8cfa03e..ef8882ad74 100644
--- a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj
+++ b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj
@@ -235,6 +235,12 @@
Always
+
+ Always
+
+
+ Always
+
Always
@@ -479,6 +485,12 @@
Always
+
+ Always
+
+
+ Always
+
Always
diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage/0.9.0/exactpackage.nuspec b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/0.9.0/exactpackage.nuspec
new file mode 100644
index 0000000000..1039ad55cd
--- /dev/null
+++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/0.9.0/exactpackage.nuspec
@@ -0,0 +1,18 @@
+
+
+
+ exactpackage
+ 0.9.0
+ exactpackage
+ __REPLACE_AUTHORS_OF_SOFTWARE__
+ __REPLACE_YOUR_NAME__
+ false
+ __REPLACE__
+ __REPLACE__
+
+ exactpackage admin
+
+
+
+
+
\ No newline at end of file
diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage/0.9.0/tools/purpose.txt b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/0.9.0/tools/purpose.txt
new file mode 100644
index 0000000000..dd51a12ddf
--- /dev/null
+++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/0.9.0/tools/purpose.txt
@@ -0,0 +1 @@
+when running choco list exactpackage -e --all, this package should be in the resulting list.
\ No newline at end of file
diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0-beta1/exactpackage.nuspec b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0-beta1/exactpackage.nuspec
new file mode 100644
index 0000000000..f7b0b361c3
--- /dev/null
+++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0-beta1/exactpackage.nuspec
@@ -0,0 +1,18 @@
+
+
+
+ exactpackage
+ 1.0.0-beta1
+ exactpackage
+ __REPLACE_AUTHORS_OF_SOFTWARE__
+ __REPLACE_YOUR_NAME__
+ false
+ __REPLACE__
+ __REPLACE__
+
+ exactpackage admin
+
+
+
+
+
\ No newline at end of file
diff --git a/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0-beta1/tools/purpose.txt b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0-beta1/tools/purpose.txt
new file mode 100644
index 0000000000..41c610b2e2
--- /dev/null
+++ b/src/chocolatey.tests.integration/context/exactpackage/exactpackage/1.0.0-beta1/tools/purpose.txt
@@ -0,0 +1 @@
+When running choco list exactpackage -a --all --pre, this package should be in the returned results.
\ No newline at end of file
diff --git a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs
index d56fcea538..71416d9fed 100644
--- a/src/chocolatey.tests.integration/scenarios/ListScenarios.cs
+++ b/src/chocolatey.tests.integration/scenarios/ListScenarios.cs
@@ -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
{
@@ -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();
+
+ 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();
+
+ 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");
+ }
+ }
}
}
diff --git a/src/chocolatey/GetChocolatey.cs b/src/chocolatey/GetChocolatey.cs
index 65b80c5755..0ef58b8a68 100644
--- a/src/chocolatey/GetChocolatey.cs
+++ b/src/chocolatey/GetChocolatey.cs
@@ -18,6 +18,7 @@ namespace chocolatey
{
using System;
using System.Collections.Generic;
+ using System.IO;
using System.Reflection;
using infrastructure.licensing;
using SimpleInjector;
@@ -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;
@@ -122,12 +128,24 @@ public class GetChocolatey
/// Initializes a new instance of the class.
///
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() { new Log4NetLog(), _logSinkLogger }));
- _license = License.validate_license();
_container = SimpleInjectorContainer.Container;
+ if (initializeLogging)
+ {
+ string loggingLocation = ApplicationParameters.LoggingLocation;
+ var fileSystem = _container.GetInstance();
+ fileSystem.create_directory_if_not_exists(loggingLocation);
+
+ Log4NetAppenderConfiguration.configure(loggingLocation, excludeLoggerNames: ChocolateyLoggers.Trace.to_string());
+ Log.InitializeWith(new AggregateLog(new List() { new Log4NetLog(), _logSinkLogger }));
+ "chocolatey".Log().Debug("XmlConfiguration is now operational");
+ }
+ _license = License.validate_license();
}
///
@@ -137,8 +155,28 @@ public GetChocolatey()
/// This instance
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 { logger });
+ if (addToExistingLoggers)
+ {
+ aggregateLog = new AggregateLog(new List { logger, Log.GetLoggerFor("chocolatey") });
+ }
+
+ Log.InitializeWith(aggregateLog, resetLoggers: false);
+ if (logExistingMessages)
+ {
+ drain_log_sink(logger);
+ }
+
return this;
}
diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs
index d1c20a2dde..5cf6241370 100644
--- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs
+++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs
@@ -59,17 +59,23 @@ private static IQueryable execute_package_search(ChocolateyConfigurati
isServiceBased = packageRepository is IServiceBasedRepository;
}
- IQueryable results = packageRepository.Search(searchTermLower, configuration.Prerelease);
-
SemanticVersion version = !string.IsNullOrWhiteSpace(configuration.Version) ? new SemanticVersion(configuration.Version) : null;
+ IQueryable 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
{