Skip to content

Commit

Permalink
Merge pull request #2813 from AdmiringWorm/a2787-Deprecate-side-by-si…
Browse files Browse the repository at this point in the history
…de-installs

(#2787) Deprecate side by side installations
  • Loading branch information
corbob authored Sep 20, 2022
2 parents b6dbc3e + fce126a commit f44f65f
Show file tree
Hide file tree
Showing 15 changed files with 289 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/chocolatey.tests.integration/scenarios/InstallScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,22 @@ public void should_contain_a_warning_message_that_it_installed_successfully()
installedSuccessfully.ShouldBeTrue();
}

[Fact]
public void should_contain_a_warning_message_that_installing_package_with_multiple_versions_being_deprecated()
{
const string expected = "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0.";

foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null())
{
if (message.Contains(expected))
{
return;
}
}

Assert.Fail("No warning message about side by side deprecation outputted");
}

[Fact]
public void should_have_a_successful_package_result()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.",
option => configuration.AllowDowngrade = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("i|ignoredependencies|ignore-dependencies",
"IgnoreDependencies - Ignore dependencies when installing package(s). Defaults to false.",
Expand Down Expand Up @@ -254,6 +254,10 @@ prompt. In most cases you can still pass options and switches with one
Starting in v2.0.0 the shortcut `cinst` will be removed and can not be used
to install packages anymore. We recommend you make sure that you always
use the full command going forward (`choco install`).
Side by side installations has been deprecated and will be removed in v2.0.0.
Instead of using side by side installations, distinct packages should be created
if similar functionality is needed going forward.
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("x|forcedependencies|force-dependencies|removedependencies|remove-dependencies",
"RemoveDependencies - Uninstall dependencies when uninstalling package(s). Defaults to false.",
Expand Down Expand Up @@ -208,6 +208,10 @@ to determine how to automatically uninstall software.
Starting in v2.0.0 the shortcut `cuninst` will be removed and can not be used
to uninstall packages anymore. We recommend you make sure that you always
use the full command going forward (`choco uninstall`).
Side by side installations has been deprecated and support for uninstalling such packages will be removed in v2.0.0.
Instead of using side by side installations, distinct packages should be created
if similar functionality is needed going forward.
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.",
option => configuration.AllowDowngrade = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("i|ignoredependencies|ignore-dependencies",
"IgnoreDependencies - Ignore dependencies when upgrading package(s). Defaults to false.",
Expand Down Expand Up @@ -285,6 +285,10 @@ prompt. In most cases you can still pass options and switches with one
Starting in v2.0.0 the shortcut `cup` will be removed and can not be used
to upgrade or install packages anymore. We recommend you make sure that you always
use the full command going forward (`choco upgrade`).
Side by side installations has been deprecated and will be removed in v2.0.0.
Instead of using side by side installations, distinct packages should be created
if similar functionality is needed going forward.
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ private void append_output(StringBuilder propertyValues, string append)
public bool ApplyPackageParametersToDependencies { get; set; }
public bool ApplyInstallArgumentsToDependencies { get; set; }
public bool IgnoreDependencies { get; set; }

[Obsolete("Side by Side installation is deprecated, and is pending removal in v2.0.0")]
public bool AllowMultipleVersions { get; set; }
public bool AllowDowngrade { get; set; }
public bool ForceDependencies { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace chocolatey.infrastructure.app.domain
{
using System;
using NuGet;

public sealed class ChocolateyPackageInformation
Expand All @@ -31,6 +32,8 @@ public ChocolateyPackageInformation(IPackage package)
public string Arguments { get; set; }
public SemanticVersion VersionOverride { get; set; }
public bool HasSilentUninstall { get; set; }

[Obsolete("Side by side installations are deprecated, with removal pending in v2.0.0")]
public bool IsSideBySide { get; set; }
public bool IsPinned { get; set; }
public string ExtraInformation { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace chocolatey.infrastructure.app.nuget
{
using System;
using System.IO;
using NuGet;

Expand All @@ -24,8 +25,16 @@ namespace chocolatey.infrastructure.app.nuget
public sealed class ChocolateyPackagePathResolver : DefaultPackagePathResolver
{
private readonly IFileSystem _nugetFileSystem;

[Obsolete("Side by Side installations are deprecated, and is pending removal in v2.0.0")]
public bool UseSideBySidePaths { get; set; }

public ChocolateyPackagePathResolver(IFileSystem nugetFileSystem)
: this(nugetFileSystem, useSideBySidePaths: false)
{
}

[Obsolete("Initializing using side by side installation enabled is deprecated. Use overload without useSideBySidePaths instead.")]
public ChocolateyPackagePathResolver(IFileSystem nugetFileSystem, bool useSideBySidePaths)
: base(nugetFileSystem, useSideBySidePaths)
{
Expand All @@ -47,6 +56,7 @@ public override string GetPackageDirectory(string packageId, SemanticVersion ver
return GetPackageDirectory(packageId, version, UseSideBySidePaths);
}

[Obsolete("Side by Side installations are deprecated, and is pending removal in v2.0.0")]
public string GetPackageDirectory(string packageId, SemanticVersion version, bool useVersionInPath)
{
string directory = packageId;
Expand Down
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.Generic;
using System.IO;
using System.Text;
using configuration;
Expand All @@ -42,6 +43,10 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation
private const string EXTRA_FILE = ".extra";
private const string VERSION_OVERRIDE_FILE = ".version";

// We need to store the package identifiers we have warned about
// to prevent duplicated outputs.
private HashSet<string> _deprecationWarning = new HashSet<string>();

public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService)
{
_fileSystem = fileSystem;
Expand Down Expand Up @@ -141,6 +146,19 @@ has errored attempting to read it. This file will be renamed to
var extraInfoFile = _fileSystem.combine_paths(pkgStorePath, EXTRA_FILE);
if (_fileSystem.file_exists(extraInfoFile)) packageInformation.ExtraInformation = _fileSystem.read_file(extraInfoFile);

if (packageInformation.IsSideBySide && !_deprecationWarning.Contains(package.Id))
{
var logger = _config.RegularOutput ?
logging.ChocolateyLoggers.Important :
logging.ChocolateyLoggers.LogFileOnly;

this.Log().Warn(logger, @"
{0} has been installed as a side by side installation.
Side by side installations are deprecated and is pending removal in v2.0.0.", package.Id);

_deprecationWarning.Add(package.Id);
}

var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE);
if (_fileSystem.file_exists(versionOverrideFile))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config)
{
if (config.AllowMultipleVersions)
{
this.Log().Warn(ChocolateyLoggers.Important, "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0.");
}

this.Log().Info(is_packages_config_file(config.PackageNames) ? @"Installing from config file:" : @"Installing the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

Expand Down Expand Up @@ -812,6 +817,11 @@ public void upgrade_noop(ChocolateyConfiguration config)

public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfiguration config)
{
if (config.AllowMultipleVersions)
{
this.Log().Warn(ChocolateyLoggers.Important, "Upgrading the same package with multiple versions is deprecated and will be removed in v2.0.0.");
}

this.Log().Info(@"Upgrading the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

Expand Down
11 changes: 11 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ public virtual ConcurrentDictionary<string, PackageResult> get_outdated(Chocolat
packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage));

this.Log().Info("{0}|{1}|{2}|{3}".format_with(installedPackage.Id, installedPackage.Version, latestPackage.Version, isPinned.to_string().to_lower()));

if (pkgInfo.IsSideBySide)
{
var deprecationMessage = @"
{0} v{1} has been installed as a side by side installation.
Side by side installations are deprecated and is pending removal in v2.0.0".format_with(installedPackage.Id, installedPackage.Version);

packageResult.Messages.Add(new ResultMessage(ResultType.Warn, deprecationMessage));
}
}

return outdatedPackages;
Expand Down Expand Up @@ -1265,6 +1274,8 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
{
var pkg = e.Package;

// TODO: Removal special handling for SxS packages once we hit v2.0.0

// this section fires twice sometimes, like for older packages in a sxs install...
var packageResult = packageUninstalls.GetOrAdd(pkg.Id.to_lower() + "." + pkg.Version.to_string(), new PackageResult(pkg, e.InstallPath));
packageResult.InstallLocation = e.InstallPath;
Expand Down
17 changes: 17 additions & 0 deletions tests/chocolatey-tests/choco-info.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,21 @@ Describe "choco info" -Tag Chocolatey, InfoCommand {
$Output.Lines | Should -Contain "${Title}: $Value"
}
}

Context "Listing package information about local side by side installed package" {
BeforeAll {
$null = Invoke-Choco install 'isdependency' --confirm --sxs

$Output = Invoke-Choco info 'isdependency' --local-only
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Outputs a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Contain "isdependency has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}
}
}
17 changes: 17 additions & 0 deletions tests/chocolatey-tests/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Outputs a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Contain "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it installed the package successfully" {
$Output.Lines | Should -Contain "Chocolatey installed 1/1 packages."
}
Expand Down Expand Up @@ -599,6 +603,10 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Outputs a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Contain "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it installed the package successfully" {
$Output.Lines | Should -Contain "Chocolatey installed 1/1 packages."
}
Expand Down Expand Up @@ -629,6 +637,15 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$XML.package.metadata.version | Should -Be "1.0.0"
}

It "Does not output a warning message about side by side installs are deprecated" {
$Output.Lines | Should -Not -Contain "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0." -Because $Output.String
}

It "Does not output a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Not -Contain "installpackage has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Not -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it installed the package successfully" {
$Output.Lines | Should -Contain "Chocolatey installed 1/1 packages."
}
Expand Down
5 changes: 5 additions & 0 deletions tests/chocolatey-tests/choco-list.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ Describe "choco <_>" -ForEach $Command -Tag Chocolatey, ListCommand, SearchComma
It "Shows version <_> of local package" -ForEach @("2.0.0"; "1.1.0") {
$Output.Lines | Should -Contain "isdependency $_"
}

It "Outputs a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Contain "isdependency has been installed as a side by side installation."
$Output.Lines | Should -Contain "Side by side installations are deprecated and is pending removal in v2.0.0."
}
}

Context "Searching packages with Verbose" {
Expand Down
43 changes: 43 additions & 0 deletions tests/chocolatey-tests/choco-uninstall.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Import-Module helpers/common-helpers

Describe "choco uninstall" -Tag Chocolatey, UninstallCommand {
BeforeAll {
Initialize-ChocolateyTestInstall

New-ChocolateyInstallSnapshot
}

AfterAll {
Remove-ChocolateyTestInstall
}

Context "Uninstalling a side-by-side Package" {
BeforeAll {
Restore-ChocolateyInstallSnapshot

$PackageUnderTest = "installpackage"

$null = Invoke-Choco upgrade $PackageUnderTest --confirm --allowmultipleversions

$Output = Invoke-Choco uninstall $PackageUnderTest --confirm
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Removed a package to the lib directory" {
"$env:ChocolateyInstall\lib\$($PackageUnderTest).1.0.0" | Should -Not -Exist
"$env:ChocolateyInstall\lib-bad\$($PackageUnderTest).1.0.0" | Should -Not -Exist
}

It "Outputs a warning message that installed side by side package is deprecated" {
$Output.Lines | Should -Contain "$PackageUnderTest has been installed as a side by side installation." -Because $Output.String
$Output.Lines | Should -Contain "Side by side installations are deprecated and is pending removal in v2.0.0." -Because $Output.String
}

It "Outputs a message indicating that it uninstalled the package successfully" {
$Output.Lines | Should -Contain "Chocolatey uninstalled 1/1 packages." -Because $Output.String
}
}
}
Loading

0 comments on commit f44f65f

Please sign in to comment.