From 29afc8c39dc1c0407ab038d3f213e65a9927eb60 Mon Sep 17 00:00:00 2001 From: Rain Sallow Date: Thu, 16 Mar 2023 09:20:45 -0400 Subject: [PATCH] (#2788) Remove side-by-side installs This functionality is deprecated and we're removing it for v2.0. --- .../helpers/ChocolateyTabExpansion.ps1 | 4 +- src/chocolatey.tests.integration/Scenario.cs | 7 +- .../context/testing.packages.config | 2 +- .../scenarios/InstallScenarios.cs | 505 ------------------ .../scenarios/UpgradeScenarios.cs | 286 ---------- src/chocolatey.tests/TinySpec.cs | 9 - .../commands/ChocolateyInstallCommandSpecs.cs | 12 - .../commands/ChocolateyUpgradeCommandSpecs.cs | 12 - src/chocolatey/chocolatey.csproj | 1 + .../ApplicationParameters.cs | 1 - .../builders/ConfigurationBuilder.cs | 1 - .../commands/ChocolateyCommandBase.cs | 47 ++ .../commands/ChocolateyInstallCommand.cs | 45 +- .../commands/ChocolateyUninstallCommand.cs | 26 +- .../commands/ChocolateyUpgradeCommand.cs | 26 +- .../configuration/ChocolateyConfiguration.cs | 4 - .../PackagesConfigFilePackageSetting.cs | 3 - .../domain/ChocolateyPackageInformation.cs | 3 - .../nuget/ChocolateyPackagePathResolver.cs | 53 +- .../infrastructure.app/nuget/NugetCommon.cs | 6 +- .../ChocolateyPackageInformationService.cs | 25 +- .../services/ChocolateyPackageService.cs | 16 - .../services/NugetService.cs | 112 +--- .../commands/choco-info.Tests.ps1 | 18 - .../commands/choco-install.Tests.ps1 | 2 +- .../commands/choco-removed.Tests.ps1 | 37 ++ .../commands/choco-uninstall.Tests.ps1 | 30 -- 27 files changed, 191 insertions(+), 1102 deletions(-) create mode 100644 src/chocolatey/infrastructure.app/commands/ChocolateyCommandBase.cs diff --git a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 index b147604df..28d7345ac 100644 --- a/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 +++ b/src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1 @@ -53,10 +53,10 @@ $commandOptions = @{ list = "--lo --id-only --pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user='' --password='' --local-only --prerelease --include-programs --page='' --page-size='' --order-by-popularity --download-cache-only --disable-package-repository-optimizations" + $proListOptions + $allcommands search = "--pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user='' --password='' --local-only --prerelease --include-programs --page='' --page-size='' --order-by-popularity --download-cache-only --disable-package-repository-optimizations" + $proListOptions + $allcommands info = "--pre --lo --source='' --user='' --password='' --local-only --prerelease --disable-package-repository-optimizations" + $proInfoOptions + $allcommands - install = "-y -whatif -? --pre --version= --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --user='' --password='' --prerelease --forcex86 --not-silent --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --allow-downgrade --force-dependencies --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --allow-multiple-versions --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --stop-on-first-package-failure --disable-package-repository-optimizations --pin" + $proInstallUpgradeOptions + $allcommands + install = "-y -whatif -? --pre --version= --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --user='' --password='' --prerelease --forcex86 --not-silent --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --allow-downgrade --force-dependencies --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --stop-on-first-package-failure --disable-package-repository-optimizations --pin" + $proInstallUpgradeOptions + $allcommands pin = "--name='' --version='' -?" + $proPinOptions + $allcommands outdated = "-? --source='' --user='' --password='' --ignore-pinned --ignore-unfound --pre --prerelease --disable-package-repository-optimizations" + $proOutdatedOptions + $allcommands - upgrade = "-y -whatif -? --pre --version='' --except='' --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --user='' --password='' --prerelease --forcex86 --not-silent --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --allow-downgrade --allow-multiple-versions --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --exclude-prerelease --stop-on-first-package-failure --use-remembered-options --ignore-remembered-options --skip-when-not-installed --install-if-not-installed --disable-package-repository-optimizations --pin" + $proInstallUpgradeOptions + $proUpgradeOptions + $allcommands + upgrade = "-y -whatif -? --pre --version='' --except='' --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --user='' --password='' --prerelease --forcex86 --not-silent --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --allow-downgrade --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --exclude-prerelease --stop-on-first-package-failure --use-remembered-options --ignore-remembered-options --skip-when-not-installed --install-if-not-installed --disable-package-repository-optimizations --pin" + $proInstallUpgradeOptions + $proUpgradeOptions + $allcommands uninstall = "-y -whatif -? --force-dependencies --remove-dependencies --all-versions --source='windowsfeatures' --version= --uninstall-arguments='' --override-arguments --not-silent --params='' --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --use-autouninstaller --skip-autouninstaller --fail-on-autouninstaller --ignore-autouninstaller-failure --stop-on-first-package-failure" + $proUninstallOptions + $allcommands new = "--template-name='' --output-directory='' --automaticpackage --version='' --maintainer='' packageversion='' maintainername='' maintainerrepo='' installertype='' url='' url64='' silentargs='' --use-built-in-template -?" + $proNewOptions + $allcommands pack = "--version='' --output-directory='' -?" + $allcommands diff --git a/src/chocolatey.tests.integration/Scenario.cs b/src/chocolatey.tests.integration/Scenario.cs index d26d3cc9f..ec830096d 100644 --- a/src/chocolatey.tests.integration/Scenario.cs +++ b/src/chocolatey.tests.integration/Scenario.cs @@ -209,6 +209,11 @@ public static void create_directory(string directoryPath) _fileSystem.create_directory(directoryPath); } + public static void move_directory(string path, string newPath) + { + _fileSystem.move_directory(path, newPath); + } + public static void add_changed_version_package_to_source_location(ChocolateyConfiguration config, string pattern, string newVersion) { _fileSystem.create_directory_if_not_exists(config.Sources); @@ -278,11 +283,9 @@ private static ChocolateyConfiguration baseline_configuration() config.Information.IsProcessElevated = true; config.Information.IsLicensedVersion = false; config.AcceptLicense = true; - config.AllowMultipleVersions = false; config.AllowUnofficialBuild = true; config.CacheLocation = _fileSystem.get_full_path(_fileSystem.combine_paths(get_top_level(), "cache")); config.CommandExecutionTimeoutSeconds = 2700; - config.ContainsLegacyPackageInstalls = false; config.Force = false; config.ForceDependencies = false; config.ForceX86 = false; diff --git a/src/chocolatey.tests.integration/context/testing.packages.config b/src/chocolatey.tests.integration/context/testing.packages.config index b5abd7bb7..7d55e7a3c 100644 --- a/src/chocolatey.tests.integration/context/testing.packages.config +++ b/src/chocolatey.tests.integration/context/testing.packages.config @@ -5,7 +5,7 @@ \ No newline at end of file diff --git a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs index 98a825d1b..8e3b83ea7 100644 --- a/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs @@ -1432,511 +1432,6 @@ public void should_have_expected_error_in_package_result() } } - [Categories.SideBySide] - public class when_installing_a_side_by_side_package : ScenariosBase - { - private PackageResult packageResult; - - public override void Context() - { - base.Context(); - Configuration.AllowMultipleVersions = true; - } - - public override void Because() - { - Results = Service.install_run(Configuration); - packageResult = Results.FirstOrDefault().Value; - } - - [Fact] - public void should_install_where_install_location_reports() - { - DirectoryAssert.Exists(packageResult.InstallLocation); - } - - [Fact] - public void should_install_a_package_in_the_lib_directory() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames) + ".1.0.0"; - - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_put_version_in_nupkg_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + ".1.0.0" + NuGetConstants.PackageExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact, Pending("Will be removed together with side by side removal"), Broken] - public void should_put_version_in_nuspec_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + ".1.0.0" + NuGetConstants.ManifestExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact] - public void should_not_have_nupkg_without_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + NuGetConstants.PackageExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact, Pending("Broken, will be removed together with side by side install"), Broken] - public void should_not_have_nuspec_without_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + NuGetConstants.ManifestExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact] - public void should_contain_a_warning_message_that_it_installed_successfully() - { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - 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() - { - packageResult.Success.ShouldBeTrue(); - } - - [Fact] - public void should_not_have_inconclusive_package_result() - { - packageResult.Inconclusive.ShouldBeFalse(); - } - - [Fact] - public void should_not_have_warning_package_result() - { - packageResult.Warning.ShouldBeFalse(); - } - - [Fact] - public void config_should_match_package_result_name() - { - packageResult.Name.ShouldEqual(Configuration.PackageNames); - } - - [Fact] - public void should_have_a_version_of_one_dot_zero_dot_zero() - { - packageResult.Version.ShouldEqual("1.0.0"); - } - } - - [Categories.SideBySide] - public class when_switching_a_normal_package_to_a_side_by_side_package : ScenariosBase - { - private PackageResult packageResult; - - public override void Context() - { - base.Context(); - Scenario.install_package(Configuration, "installpackage", "1.0.0"); - Configuration.AllowMultipleVersions = true; - Configuration.Force = true; - } - - public override void Because() - { - Results = Service.install_run(Configuration); - packageResult = Results.FirstOrDefault().Value; - } - - [Fact] - public void should_install_where_install_location_reports() - { - DirectoryAssert.Exists(packageResult.InstallLocation); - } - - [Fact] - public void should_install_a_package_in_the_lib_directory() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames) + ".1.0.0"; - - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_put_version_in_nupkg_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + ".1.0.0" + NuGetConstants.PackageExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact, Pending("Should be removed together with side by side installation"), Broken] - public void should_put_version_in_nuspec_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + ".1.0.0" + NuGetConstants.ManifestExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact] - public void should_not_have_nupkg_without_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + NuGetConstants.PackageExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact, Pending("Should be removed together with side by side installation"), Broken] - public void should_not_have_nuspec_without_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.0.0"), - (Configuration.PackageNames + NuGetConstants.ManifestExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact] - public void should_contain_a_warning_message_that_it_installed_successfully() - { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.ShouldBeTrue(); - } - - [Fact] - public void should_have_a_successful_package_result() - { - packageResult.Success.ShouldBeTrue(); - } - - [Fact] - public void should_not_have_inconclusive_package_result() - { - packageResult.Inconclusive.ShouldBeFalse(); - } - - [Fact] - public void should_not_have_warning_package_result() - { - packageResult.Warning.ShouldBeFalse(); - } - - [Fact] - public void config_should_match_package_result_name() - { - packageResult.Name.ShouldEqual(Configuration.PackageNames); - } - - [Fact] - public void should_have_a_version_of_one_dot_zero_dot_zero() - { - packageResult.Version.ShouldEqual("1.0.0"); - } - } - - [Categories.SideBySide] - public class when_installing_an_older_version_side_by_side_with_a_newer_version : ScenariosBase - { - private PackageResult packageResult; - - public override void Context() - { - base.Context(); - Configuration.PackageNames = Configuration.Input = "isdependency"; - Scenario.add_packages_to_source_location(Configuration, Configuration.Input + "*" + NuGetConstants.PackageExtension); - Scenario.install_package(Configuration, "isdependency", "2.0.0"); - Configuration.AllowMultipleVersions = true; - Configuration.Version = "1.1.0"; - } - - public override void Because() - { - Results = Service.install_run(Configuration); - packageResult = Results.FirstOrDefault().Value; - } - - [Fact] - public void should_install_where_install_location_reports() - { - DirectoryAssert.Exists(packageResult.InstallLocation); - } - - [Fact] - public void should_install_a_package_in_the_lib_directory() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames) + ".1.1.0"; - - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_put_version_in_nupkg_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.1.0"), - (Configuration.PackageNames + ".1.1.0" + NuGetConstants.PackageExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact, Pending("Should be removed together with side by side installation"), Broken] - public void should_put_version_in_nuspec_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.1.0"), - (Configuration.PackageNames + ".1.1.0" + NuGetConstants.ManifestExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact] - public void should_not_have_nupkg_without_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.1.0"), - (Configuration.PackageNames + NuGetConstants.PackageExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact, Pending("Should be removed together with side by side installation"), Broken] - public void should_not_have_nuspec_without_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - (Configuration.PackageNames + ".1.1.0"), - (Configuration.PackageNames + NuGetConstants.ManifestExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact] - public void should_contain_a_warning_message_that_it_installed_successfully() - { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.ShouldBeTrue(); - } - - [Fact] - public void should_have_a_successful_package_result() - { - packageResult.Success.ShouldBeTrue(); - } - - [Fact] - public void should_not_have_inconclusive_package_result() - { - packageResult.Inconclusive.ShouldBeFalse(); - } - - [Fact] - public void should_not_have_warning_package_result() - { - packageResult.Warning.ShouldBeFalse(); - } - - [Fact] - public void config_should_match_package_result_name() - { - packageResult.Name.ShouldEqual(Configuration.PackageNames); - } - - [Fact] - public void should_have_a_version_of_one_dot_one_dot_zero() - { - packageResult.Version.ShouldEqual("1.1.0"); - } - } - - [Categories.SideBySide] - public class when_switching_a_side_by_side_package_to_a_normal_package : ScenariosBase - { - private PackageResult packageResult; - - public override void Context() - { - base.Context(); - Configuration.AllowMultipleVersions = true; - Scenario.install_package(Configuration, "installpackage", "1.0.0"); - Configuration.AllowMultipleVersions = false; - Configuration.Force = true; - } - - public override void Because() - { - Results = Service.install_run(Configuration); - packageResult = Results.FirstOrDefault().Value; - } - - [Fact] - public void should_install_where_install_location_reports() - { - DirectoryAssert.Exists(packageResult.InstallLocation); - } - - [Fact] - public void should_install_a_package_in_the_lib_directory() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames); - - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_remove_version_directory_in_the_lib_directory() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames + ".1.0.0"); - - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_not_put_version_in_nupkg_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - Configuration.PackageNames, - (Configuration.PackageNames + NuGetConstants.PackageExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact] - public void should_not_put_version_in_nuspec_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - Configuration.PackageNames, - (Configuration.PackageNames + NuGetConstants.ManifestExtension)); - - FileAssert.Exists(packageFile); - } - - [Fact] - public void should_not_have_nupkg_with_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - Configuration.PackageNames, - (Configuration.PackageNames + ".1.0.0" + NuGetConstants.PackageExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact] - public void should_not_have_nuspec_with_version_in_filename() - { - var packageFile = Path.Combine( - Scenario.get_top_level(), "lib", - Configuration.PackageNames, - (Configuration.PackageNames + ".1.0.0" + NuGetConstants.ManifestExtension)); - - FileAssert.DoesNotExist(packageFile); - } - - [Fact] - public void should_contain_a_warning_message_that_it_installed_successfully() - { - bool installedSuccessfully = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) - { - if (message.Contains("1/1")) installedSuccessfully = true; - } - - installedSuccessfully.ShouldBeTrue(); - } - - [Fact] - public void should_have_a_successful_package_result() - { - packageResult.Success.ShouldBeTrue(); - } - - [Fact] - public void should_not_have_inconclusive_package_result() - { - packageResult.Inconclusive.ShouldBeFalse(); - } - - [Fact] - public void should_not_have_warning_package_result() - { - packageResult.Warning.ShouldBeFalse(); - } - - [Fact] - public void config_should_match_package_result_name() - { - packageResult.Name.ShouldEqual(Configuration.PackageNames); - } - - [Fact] - public void should_have_a_version_of_one_dot_zero_dot_zero() - { - packageResult.Version.ShouldEqual("1.0.0"); - } - } - public class when_installing_a_package_with_dependencies_happy : ScenariosBase { public override void Context() diff --git a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs index 3ed7a8ae5..0eaab5708 100644 --- a/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/UpgradeScenarios.cs @@ -3074,152 +3074,6 @@ public void should_not_have_warning_package_result() } } - public class when_upgrading_a_dependency_legacy_folder_version : ScenariosBase - { - public override void Context() - { - base.Context(); - Configuration.PackageNames = Configuration.Input = "isdependency"; - Scenario.add_packages_to_source_location(Configuration, "hasdependency.*" + NuGetConstants.PackageExtension); - Scenario.add_packages_to_source_location(Configuration, "isdependency.1*" + NuGetConstants.PackageExtension); - Scenario.add_packages_to_source_location(Configuration, "isexactversiondependency*" + NuGetConstants.PackageExtension); - Configuration.AllowMultipleVersions = true; - Scenario.install_package(Configuration, "isdependency", "1.0.0"); - Scenario.install_package(Configuration, "hasdependency", "1.0.0"); - Configuration.AllowMultipleVersions = false; - - string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey"); - if (Directory.Exists(dotChocolatey)) - { - try - { - Directory.Delete(dotChocolatey, recursive: true); - } - catch (Exception) - { - Thread.Sleep(2000); - Directory.Delete(dotChocolatey, recursive: true); - } - } - } - - public override void Because() - { - Results = Service.upgrade_run(Configuration); - } - - [Fact] - public void should_upgrade_the_package() - { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); - using (var packageReader = new PackageArchiveReader(packageFile)) - { - packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.1.0"); - } - } - - [Fact] - public void should_remove_the_legacy_folder_version_of_the_package() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency.1.0.0"); - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_replace_the_legacy_folder_version_of_the_package_with_a_lib_package_folder_that_has_no_version() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency"); - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_not_upgrade_the_parent_package() - { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency.1.0.0", "hasdependency.1.0.0.nupkg"); - using (var packageReader = new PackageArchiveReader(packageFile)) - { - packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.0.0"); - } - } - - [Fact] - public void should_not_add_a_versionless_parent_package_folder_to_the_lib_dir() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency"); - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_leave_the_parent_package_as_legacy_folder() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency.1.0.0"); - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_not_upgrade_the_exact_version_dependency() - { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency.1.0.0", "isexactversiondependency.1.0.0.nupkg"); - using (var packageReader = new PackageArchiveReader(packageFile)) - { - packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("1.0.0"); - } - } - - [Fact] - public void should_leave_the_exact_version_package_as_legacy_folder() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency.1.0.0"); - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_not_add_a_versionless_exact_version_package_folder_to_the_lib_dir() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency"); - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_contain_a_message_the_dependency_upgraded_successfully() - { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) - { - if (message.Contains("upgraded 1/1")) expectedMessage = true; - } - - expectedMessage.ShouldBeTrue(); - } - - [Fact] - public void should_have_a_successful_package_result() - { - foreach (var packageResult in Results) - { - packageResult.Value.Success.ShouldBeTrue(); - } - } - - [Fact] - public void should_not_have_inconclusive_package_result() - { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.ShouldBeFalse(); - } - } - - [Fact] - public void should_not_have_warning_package_result() - { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.ShouldBeFalse(); - } - } - } - public class when_upgrading_a_dependency_with_parent_that_depends_on_a_range_less_than_upgrade_version : ScenariosBase { public override void Context() @@ -3824,146 +3678,6 @@ public void should_have_outputted_expected_error_message() } } - public class when_upgrading_a_legacy_folder_dependency_with_parent_that_depends_on_a_range_less_than_upgrade_version : ScenariosBase - { - public override void Context() - { - base.Context(); - Configuration.PackageNames = Configuration.Input = "isdependency"; - Scenario.add_packages_to_source_location(Configuration, "hasdependency.*" + NuGetConstants.PackageExtension); - Scenario.add_packages_to_source_location(Configuration, "isdependency.*" + NuGetConstants.PackageExtension); - Scenario.add_packages_to_source_location(Configuration, "isexactversiondependency*" + NuGetConstants.PackageExtension); - Configuration.AllowMultipleVersions = true; - Scenario.install_package(Configuration, "isdependency", "1.0.0"); - Scenario.install_package(Configuration, "hasdependency", "1.0.0"); - Configuration.AllowMultipleVersions = false; - - string dotChocolatey = Path.Combine(Scenario.get_top_level(), ".chocolatey"); - if (Directory.Exists(dotChocolatey)) - { - Directory.Delete(dotChocolatey, recursive: true); - } - } - - public override void Because() - { - Results = Service.upgrade_run(Configuration); - } - - [Fact] - public void should_upgrade_the_package() - { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg"); - using (var packageReader = new PackageArchiveReader(packageFile)) - { - packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.1.0"); - } - } - - [Fact] - public void should_remove_the_legacy_folder_version_of_the_package() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency.1.0.0"); - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_replace_the_legacy_folder_version_of_the_package_with_a_lib_package_folder_that_has_no_version() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isdependency"); - DirectoryAssert.Exists(packageDir); - } - - [Fact] - public void should_upgrade_the_parent_package_to_highest_version_that_meets_new_dependency_version() - { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency", "hasdependency.nupkg"); - using (var packageReader = new PackageArchiveReader(packageFile)) - { - packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.1.0"); - } - } - - [Fact] - public void should_replace_the_legacy_folder_version_of_the_parent_package_with_a_lib_package_folder_that_has_no_version() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency"); - DirectoryAssert.Exists(packageDir); - } - - [Fact] - //[Pending("Legacy packages are left when implicit - GH-117")] - public void should_remove_the_legacy_folder_version_of_the_parent_package() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "hasdependency.1.0.0"); - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_upgrade_the_exact_version_dependency() - { - var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg"); - using (var packageReader = new PackageArchiveReader(packageFile)) - { - packageReader.NuspecReader.GetVersion().to_string().ShouldEqual("2.0.0"); - } - } - - [Fact] - public void should_replace_the_legacy_folder_version_of_the_exact_version_package_with_a_lib_package_folder_that_has_no_version() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency"); - DirectoryAssert.Exists(packageDir); - } - - [Fact] - //[Pending("Legacy packages are left when implicit - GH-117")] - public void should_remove_the_legacy_folder_version_of_the_exact_version_package() - { - var packageDir = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency.1.0.0"); - DirectoryAssert.DoesNotExist(packageDir); - } - - [Fact] - public void should_contain_a_message_that_everything_upgraded_successfully() - { - bool expectedMessage = false; - foreach (var message in MockLogger.MessagesFor(LogLevel.Warn).or_empty_list_if_null()) - { - if (message.Contains("upgraded 3/3")) expectedMessage = true; - } - - expectedMessage.ShouldBeTrue(); - } - - [Fact] - public void should_have_a_successful_package_result() - { - foreach (var packageResult in Results) - { - packageResult.Value.Success.ShouldBeTrue(); - } - } - - [Fact] - public void should_not_have_inconclusive_package_result() - { - foreach (var packageResult in Results) - { - packageResult.Value.Inconclusive.ShouldBeFalse(); - } - } - - [Fact] - public void should_not_have_warning_package_result() - { - foreach (var packageResult in Results) - { - packageResult.Value.Warning.ShouldBeFalse(); - } - } - } - public class when_upgrading_a_package_with_config_transforms : ScenariosBase { private PackageResult _packageResult; diff --git a/src/chocolatey.tests/TinySpec.cs b/src/chocolatey.tests/TinySpec.cs index 0f05f941b..546eb7226 100644 --- a/src/chocolatey.tests/TinySpec.cs +++ b/src/chocolatey.tests/TinySpec.cs @@ -208,15 +208,6 @@ public ExceptionHandlingAttribute() } } - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)] - public sealed class SideBySideAttribute : CategoryAttribute - { - public SideBySideAttribute() - : base("Side-by-Side") - { - } - } - /// /// Attribute used to define a test class or method as belonging to source priorities. /// diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs index 9eb359f23..f010beb6c 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyInstallCommandSpecs.cs @@ -165,18 +165,6 @@ public void should_add_applyInstallArgumentsToDependencies_to_the_option_set() optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue(); } - [Fact] - public void should_add_allowmultipleversions_to_the_option_set() - { - optionSet.Contains("allowmultipleversions").ShouldBeTrue(); - } - - [Fact] - public void should_add_short_version_of_allowmultipleversions_to_the_option_set() - { - optionSet.Contains("m").ShouldBeTrue(); - } - [Fact] public void should_add_ignoredependencies_to_the_option_set() { diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs index 5fe367a9e..c95a9328d 100644 --- a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs +++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyUpgradeCommandSpecs.cs @@ -159,18 +159,6 @@ public void should_add_applyInstallArgumentsToDependencies_to_the_option_set() optionSet.Contains("apply-install-arguments-to-dependencies").ShouldBeTrue(); } - [Fact] - public void should_add_allowmultipleversions_to_the_option_set() - { - optionSet.Contains("allowmultipleversions").ShouldBeTrue(); - } - - [Fact] - public void should_add_short_version_of_allowmultipleversions_to_the_option_set() - { - optionSet.Contains("m").ShouldBeTrue(); - } - [Fact] public void should_add_ignoredependencies_to_the_option_set() { diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index c620bd15a..5dcfe3334 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -203,6 +203,7 @@ + diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index 7adf72112..0dec85e10 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -184,7 +184,6 @@ public static class Tools public static class ConfigSettings { public static readonly string CacheLocation = "cacheLocation"; - public static readonly string ContainsLegacyPackageInstalls = "containsLegacyPackageInstalls"; public static readonly string CommandExecutionTimeoutSeconds = "commandExecutionTimeoutSeconds"; public static readonly string Proxy = "proxy"; public static readonly string ProxyUser = "proxyUser"; diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs index 3d86802a8..c67603686 100644 --- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs +++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs @@ -259,7 +259,6 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS } config.WebRequestTimeoutSeconds = webRequestTimeoutSeconds; - config.ContainsLegacyPackageInstalls = set_config_item(ApplicationParameters.ConfigSettings.ContainsLegacyPackageInstalls, configFileSettings, "true", "Install has packages installed prior to 0.9.9 series.").is_equal_to(bool.TrueString); config.Proxy.Location = set_config_item(ApplicationParameters.ConfigSettings.Proxy, configFileSettings, string.Empty, "Explicit proxy location. Available in 0.9.9.9+."); config.Proxy.User = set_config_item(ApplicationParameters.ConfigSettings.ProxyUser, configFileSettings, string.Empty, "Optional proxy user. Available in 0.9.9.9+."); config.Proxy.EncryptedPassword = set_config_item(ApplicationParameters.ConfigSettings.ProxyPassword, configFileSettings, string.Empty, "Optional proxy password. Encrypted. Available in 0.9.9.9+."); diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyCommandBase.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyCommandBase.cs new file mode 100644 index 000000000..6a253e51a --- /dev/null +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyCommandBase.cs @@ -0,0 +1,47 @@ +// Copyright © 2023 Chocolatey Software, Inc +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Collections.Generic; +using System.Linq; + +namespace chocolatey.infrastructure.app.commands +{ + /// + /// A base class for any Chocolatey commands which need to utilise shared logic. + /// + public abstract class ChocolateyCommandBase + { + /// + /// Emit a warning to the use if any of the options which are known to be deprecated are found in the . + /// + /// The list of unrecognised and unparsed options. + /// The list of options which are known to be removed and should be warned for. + protected virtual void warn_for_removed_options(IEnumerable unparsedOptions, IEnumerable removedOptions) + { + if (!unparsedOptions.or_empty_list_if_null().Any() || !removedOptions.or_empty_list_if_null().Any()) + { + return; + } + + foreach (var removed in removedOptions) + { + if (unparsedOptions.Contains(removed)) + { + this.Log().Warn("The {0} option is no longer supported.", removed); + } + } + } + } +} diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs index 7897de876..061dce98a 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs @@ -27,10 +27,22 @@ namespace chocolatey.infrastructure.app.commands using services; [CommandFor("install", "installs packages using configured sources")] - public class ChocolateyInstallCommand : ICommand + public class ChocolateyInstallCommand : ChocolateyCommandBase, ICommand { private readonly IChocolateyPackageService _packageService; + private readonly string[] _removedOptions = new[] + { + "-m", + "-sxs", + "--sidebyside", + "--side-by-side", + "--allowmultiple", + "--allow-multiple", + "--allowmultipleversions", + "--allow-multiple-versions", + }; + public ChocolateyInstallCommand(IChocolateyPackageService packageService) { _packageService = packageService; @@ -72,9 +84,6 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("allowdowngrade|allow-downgrade", "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. (DEPRECATED)", - option => configuration.AllowMultipleVersions = option != null) .Add("i|ignoredependencies|ignore-dependencies", "IgnoreDependencies - Ignore dependencies when installing package(s). Defaults to false.", option => configuration.IgnoreDependencies = option != null) @@ -196,6 +205,11 @@ public virtual void handle_additional_argument_parsing(IList unparsedArg { configuration.Input = string.Join(" ", unparsedArguments); configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.to_string(), unparsedArguments.Where(arg => !arg.StartsWith("-"))); + + if (configuration.RegularOutput) + { + warn_for_removed_options(unparsedArguments.Where(arg => arg.StartsWith("-")), _removedOptions); + } } public virtual void handle_validation(ChocolateyConfiguration configuration) @@ -258,10 +272,6 @@ 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"); @@ -308,21 +318,6 @@ choco install nodejs.install --version 0.10.35 choco install choco install -Install multiple versions of a package using -m (AllowMultiple versions) - - choco install ruby --version 1.9.3.55100 -my - choco install ruby --version 2.0.0.59800 -my - choco install ruby --version 2.1.5 -my - -What is `-my`? See option bundling in the command reference - (`choco -?`). - -NOTE: All of these will add to PATH variable. We'll be adding a special - option to not allow PATH changes. Until then you will need to manually - go modify Path to just one Ruby and then use something like uru - (https://bitbucket.org/jonforums/uru) or pik - (https://community.chocolatey.org/packages/pik) to switch between versions. - NOTE: See scripting in the command reference (`choco -?`) for how to write proper scripts and integrations. @@ -381,8 +376,8 @@ Chocolatey Professional showing private download cache and virus scan diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs index 50835e0a0..1e0a21639 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs @@ -27,10 +27,22 @@ namespace chocolatey.infrastructure.app.commands using services; [CommandFor("uninstall", "uninstalls a package")] - public class ChocolateyUninstallCommand : ICommand + public class ChocolateyUninstallCommand : ChocolateyCommandBase, ICommand { private readonly IChocolateyPackageService _packageService; + private readonly string[] _removedOptions = new[] + { + "-m", + "-sxs", + "--sidebyside", + "--side-by-side", + "--allowmultiple", + "--allow-multiple", + "--allowmultipleversions", + "--allow-multiple-versions", + }; + public ChocolateyUninstallCommand(IChocolateyPackageService packageService) { _packageService = packageService; @@ -66,9 +78,6 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies", "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. (DEPRECATED)", - option => configuration.AllowMultipleVersions = option != null) .Add("x|forcedependencies|force-dependencies|removedependencies|remove-dependencies", "RemoveDependencies - Uninstall dependencies when uninstalling package(s). Defaults to false.", option => configuration.ForceDependencies = option != null) @@ -144,6 +153,11 @@ public virtual void handle_additional_argument_parsing(IList unparsedArg { configuration.Input = string.Join(" ", unparsedArguments); configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.to_string(), unparsedArguments.Where(arg => !arg.StartsWith("-"))); + + if (configuration.RegularOutput) + { + warn_for_removed_options(unparsedArguments.Where(arg => arg.StartsWith("-")), _removedOptions); + } } public virtual void handle_validation(ChocolateyConfiguration configuration) @@ -212,10 +226,6 @@ 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"); diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 592f6cacc..694fdeffa 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -27,10 +27,22 @@ namespace chocolatey.infrastructure.app.commands using services; [CommandFor("upgrade", "upgrades packages from various sources")] - public class ChocolateyUpgradeCommand : ICommand + public class ChocolateyUpgradeCommand : ChocolateyCommandBase, ICommand { private readonly IChocolateyPackageService _packageService; + private readonly string[] _removedOptions = new[] + { + "-m", + "-sxs", + "--sidebyside", + "--side-by-side", + "--allowmultiple", + "--allow-multiple", + "--allowmultipleversions", + "--allow-multiple-versions", + }; + public ChocolateyUpgradeCommand(IChocolateyPackageService packageService) { _packageService = packageService; @@ -72,9 +84,6 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon .Add("allowdowngrade|allow-downgrade", "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. (DEPRECATED)", - option => configuration.AllowMultipleVersions = option != null) .Add("i|ignoredependencies|ignore-dependencies", "IgnoreDependencies - Ignore dependencies when upgrading package(s). Defaults to false.", option => configuration.IgnoreDependencies = option != null) @@ -233,6 +242,11 @@ public virtual void handle_additional_argument_parsing(IList unparsedArg { configuration.Input = string.Join(" ", unparsedArguments); configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.to_string(), unparsedArguments.Where(arg => !arg.StartsWith("-"))); + + if (configuration.RegularOutput) + { + warn_for_removed_options(unparsedArguments.Where(arg => arg.StartsWith("-")), _removedOptions); + } } public virtual void handle_validation(ChocolateyConfiguration configuration) @@ -289,10 +303,6 @@ 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"); diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index f827bafdc..14f129689 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -242,7 +242,6 @@ private void append_output(StringBuilder propertyValues, string append) // configuration set variables public string CacheLocation { get; set; } - public bool ContainsLegacyPackageInstalls { get; set; } public int CommandExecutionTimeoutSeconds { get; set; } public int WebRequestTimeoutSeconds { get; set; } public string DefaultTemplateName { get; set; } @@ -332,9 +331,6 @@ private void append_output(StringBuilder propertyValues, string append) 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; } public string DownloadChecksum { get; set; } diff --git a/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs b/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs index ee4d5b0d0..5c4e8d5c1 100644 --- a/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs +++ b/src/chocolatey/infrastructure.app/configuration/PackagesConfigFilePackageSetting.cs @@ -50,9 +50,6 @@ public sealed class PackagesConfigFilePackageSetting [XmlAttribute(AttributeName = "forceX86")] public bool ForceX86 { get; set; } - [XmlAttribute(AttributeName = "allowMultipleVersions")] - public bool AllowMultipleVersions { get; set; } - [XmlAttribute(AttributeName = "ignoreDependencies")] public bool IgnoreDependencies { get; set; } diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index 0b10bb66d..3fb1f5fe5 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -34,9 +34,6 @@ public ChocolateyPackageInformation(IPackageMetadata package) public string Arguments { get; set; } public NuGetVersion 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; } } diff --git a/src/chocolatey/infrastructure.app/nuget/ChocolateyPackagePathResolver.cs b/src/chocolatey/infrastructure.app/nuget/ChocolateyPackagePathResolver.cs index 9068d18ab..3533bce2d 100644 --- a/src/chocolatey/infrastructure.app/nuget/ChocolateyPackagePathResolver.cs +++ b/src/chocolatey/infrastructure.app/nuget/ChocolateyPackagePathResolver.cs @@ -30,64 +30,27 @@ namespace chocolatey.infrastructure.app.nuget public sealed class ChocolateyPackagePathResolver : PackagePathResolver { public string RootDirectory { get; set; } - public new bool UseSideBySidePaths { get; set; } private IFileSystem _filesystem; - public ChocolateyPackagePathResolver(string rootDirectory, IFileSystem filesystem, bool useSideBySidePaths) - : base(rootDirectory, useSideBySidePaths) + public ChocolateyPackagePathResolver(string rootDirectory, IFileSystem filesystem) + : base(rootDirectory, useSideBySidePaths: false) { RootDirectory = rootDirectory; - UseSideBySidePaths = useSideBySidePaths; _filesystem = filesystem; } public override string GetInstallPath(PackageIdentity packageIdentity) - { - if (UseSideBySidePaths) - { - return Path.Combine(RootDirectory, GetPackageDirectory(packageIdentity, useVersionInPath: true)); - } - else - { - var packageVersionPath = Path.Combine(RootDirectory, GetPackageDirectory(packageIdentity, useVersionInPath: true)); - if (_filesystem.directory_exists(packageVersionPath)) return packageVersionPath; - + => GetInstallPath(packageIdentity.Id); - return Path.Combine(RootDirectory, GetPackageDirectory(packageIdentity, false)); - } - } + public string GetInstallPath(string packageId) + => _filesystem.combine_paths(RootDirectory, packageId); + [Obsolete("This overload will be removed in a future version.")] public string GetInstallPath(string id, NuGetVersion version) - { - return GetInstallPath(new PackageIdentity(id, version)); - } - - [Obsolete("Side by Side installations are deprecated, and is pending removal in v2.0.0")] - public override string GetPackageDirectoryName(PackageIdentity packageIdentity) - { - return GetPackageDirectory(packageIdentity, UseSideBySidePaths); - } - - public string GetPackageDirectory(PackageIdentity packageIdentity, bool useVersionInPath) - { - string directory = packageIdentity.Id; - if (useVersionInPath) - { - directory += "." + packageIdentity.Version.to_string(); - } - - return directory; - } + => GetInstallPath(id); public override string GetPackageFileName(PackageIdentity packageIdentity) - { - string fileNameBase = packageIdentity.Id; - if (UseSideBySidePaths) - { - fileNameBase += "." + packageIdentity.Version.to_string(); - } - return fileNameBase + NuGetConstants.PackageExtension; - } + => packageIdentity.Id + NuGetConstants.PackageExtension; } // ReSharper restore InconsistentNaming diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index 1406554cc..3d15fca15 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -71,9 +71,13 @@ private static IConsole Console get { return _console.Value; } } + [Obsolete("This overload is obsolete and will be removed in a future version.")] public static ChocolateyPackagePathResolver GetPathResolver(ChocolateyConfiguration configuration, IFileSystem nugetPackagesFileSystem) + => GetPathResolver(nugetPackagesFileSystem); + + public static ChocolateyPackagePathResolver GetPathResolver(IFileSystem nugetPackagesFileSystem) { - return new ChocolateyPackagePathResolver(ApplicationParameters.PackagesLocation, nugetPackagesFileSystem, configuration.AllowMultipleVersions); + return new ChocolateyPackagePathResolver(ApplicationParameters.PackagesLocation, nugetPackagesFileSystem); } public static void ClearRepositoriesCache() diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index dce18232e..d40bd93d0 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -141,26 +141,12 @@ has errored attempting to read it. This file will be renamed to ); packageInformation.HasSilentUninstall = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE)); - packageInformation.IsSideBySide = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE)); packageInformation.IsPinned = _fileSystem.file_exists(_fileSystem.combine_paths(pkgStorePath, PIN_FILE)); var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE); if (_fileSystem.file_exists(argsFile)) packageInformation.Arguments = _fileSystem.read_file(argsFile); 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)) { @@ -248,14 +234,9 @@ public void save_package_information(ChocolateyPackageInformation packageInforma { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE), string.Empty, Encoding.ASCII); } - if (packageInformation.IsSideBySide) - { - _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE), string.Empty, Encoding.ASCII); - } - else - { - _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE)); - } + + // Legacy side-by-side installation data cleanup + _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE)); if (packageInformation.IsPinned) { diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 0f6cacdd8..ad9811e28 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -513,10 +513,6 @@ private void create_ignore_files_for_executables(string installLocation, bool is protected virtual ChocolateyPackageInformation get_package_information(PackageResult packageResult, ChocolateyConfiguration config) { var pkgInfo = _packageInfoService.get_package_information(packageResult.PackageMetadata); - if (config.AllowMultipleVersions) - { - pkgInfo.IsSideBySide = true; - } return pkgInfo; } @@ -547,7 +543,6 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p if (config.ApplyPackageParametersToDependencies) arguments.Append(" --apply-package-parameters-to-dependencies"); if (config.AllowDowngrade) arguments.Append(" --allow-downgrade"); - if (config.AllowMultipleVersions) arguments.Append(" --allow-multiple-versions"); // most times folks won't want to skip automation scripts on upgrade //if (config.SkipPackageInstallProvider) arguments.Append(" --skip-automation-scripts"); @@ -581,11 +576,6 @@ public virtual ConcurrentDictionary install_run(Chocolate { validate_package_names(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)); @@ -746,7 +736,6 @@ private IEnumerable get_packages_from_config(string pac 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; if (pkgSettings.ApplyInstallArgumentsToDependencies) packageConfig.ApplyInstallArgumentsToDependencies = true; if (pkgSettings.ApplyPackageParametersToDependencies) packageConfig.ApplyPackageParametersToDependencies = true; @@ -831,11 +820,6 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate { validate_package_names(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)); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 502ddb9ab..94020704d 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -474,7 +474,7 @@ public virtual ConcurrentDictionary install_run(Chocolate var sourceCacheContext = new ChocolateySourceCacheContext(config); var remoteRepositories = NugetCommon.GetRemoteRepositories(config, _nugetLogger, _fileSystem); var localRepositorySource = NugetCommon.GetLocalRepository(); - var pathResolver = NugetCommon.GetPathResolver(config, _fileSystem); + var pathResolver = NugetCommon.GetPathResolver(_fileSystem); var nugetProject = new FolderNuGetProject(ApplicationParameters.PackagesLocation, pathResolver, NuGetFramework.AnyFramework); var projectContext = new ChocolateyNuGetProjectContext(config, _nugetLogger); @@ -534,7 +534,6 @@ public virtual ConcurrentDictionary install_run(Chocolate var sourcePackageDependencyInfos = new HashSet(PackageIdentityComparer.Default); var localPackageToRemoveDependencyInfos = new HashSet(PackageIdentityComparer.Default); - //todo: #2577 get smarter about realizing multiple versions have been installed before and allowing that var installedPackage = allLocalPackages.FirstOrDefault(p => p.Name.Equals(packageName)); if (Platform.get_platform() != PlatformType.Windows && !packageName.EndsWith(".template")) @@ -564,9 +563,9 @@ public virtual ConcurrentDictionary install_run(Chocolate latestPackageVersion = installedPackage.PackageMetadata.Version; } - if (installedPackage != null && version != null && version < installedPackage.PackageMetadata.Version && !config.AllowMultipleVersions && !config.AllowDowngrade) + if (installedPackage != null && version != null && version < installedPackage.PackageMetadata.Version && !config.AllowDowngrade) { - string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to install older versions, or use --side-by-side to allow multiple versions.".format_with(installedPackage.Name, installedPackage.Version, Environment.NewLine); + string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to install older versions.".format_with(installedPackage.Name, installedPackage.Version, Environment.NewLine); var nullResult = packageResultsToReturn.GetOrAdd(packageName, installedPackage); nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage)); this.Log().Error(ChocolateyLoggers.Important, logMessage); @@ -707,20 +706,14 @@ Version was specified as '{0}'. It is possible that version resolvedPackages = dependencyResolver.Resolve(resolverContext, CancellationToken.None) .Select(p => sourcePackageDependencyInfos.Single(x => PackageIdentityComparer.Default.Equals(x, p))); - if (!config.ForceDependencies) { var identitiesToUninstall = packagesToUninstall.Select(x => x.Identity); resolvedPackages = resolvedPackages.Where(p => !(localPackagesDependencyInfos.Contains(p) && !identitiesToUninstall.Contains(p))); - if (!config.AllowMultipleVersions) - { - // If forcing dependencies, then dependencies already added to packages to remove - // If allow multiple is added, then new version of dependency will be added side by side - // If neither, then package needs to be removed so it can be upgraded to the new version required by the parent - - packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase))); - } + // If forcing dependencies, then dependencies already added to packages to remove. + // If not forcing dependencies, then package needs to be removed so it can be upgraded to the new version required by the parent + packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase))); } } catch (NuGetResolverConstraintException ex) @@ -1036,15 +1029,14 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate continue; } - //Needs to be set here to ensure that the path resolver has the side by side option set correctly. set_package_config_for_upgrade(config, pkgInfo); - var pathResolver = NugetCommon.GetPathResolver(config, _fileSystem); + var pathResolver = NugetCommon.GetPathResolver(_fileSystem); var nugetProject = new FolderNuGetProject(ApplicationParameters.PackagesLocation, pathResolver, NuGetFramework.AnyFramework); - if (version != null && version < installedPackage.PackageMetadata.Version && !config.AllowMultipleVersions && !config.AllowDowngrade) + if (version != null && version < installedPackage.PackageMetadata.Version && !config.AllowDowngrade) { - string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to upgrade to older versions, or use side by side to allow multiple versions.".format_with(installedPackage.PackageMetadata.Id, installedPackage.Version, Environment.NewLine); - var nullResult = packageResultsToReturn.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id, installedPackage.PackageMetadata.Version))); + string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to upgrade to older versions.".format_with(installedPackage.PackageMetadata.Id, installedPackage.Version, Environment.NewLine); + var nullResult = packageResultsToReturn.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id))); nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage)); this.Log().Error(ChocolateyLoggers.Important, logMessage); continue; @@ -1092,11 +1084,6 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate continue; } - if (pkgInfo != null && pkgInfo.IsSideBySide) - { - //todo: #103 get smarter about realizing multiple versions have been installed before and allowing that - } - var packageResult = packageResultsToReturn.GetOrAdd(packageName, new PackageResult(availablePackage, pathResolver.GetInstallPath(availablePackage.Identity))); if (installedPackage.PackageMetadata.Version > availablePackage.Identity.Version && (!config.AllowDowngrade || (config.AllowDowngrade && version == null))) { @@ -1301,14 +1288,9 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate var identitiesToUninstall = packagesToUninstall.Select(x => x.Identity); resolvedPackages = resolvedPackages.Where(p => !(localPackagesDependencyInfos.Contains(p) && !identitiesToUninstall.Contains(p))); - if (!config.AllowMultipleVersions) - { - // If forcing dependencies, then dependencies already added to packages to remove - // If allow multiple is added, then new version of dependency will be added side by side - // If neither, then package needs to be removed so it can be upgraded to the new version required by the parent - - packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase))); - } + // If forcing dependencies, then dependencies already added to packages to remove. + // If not forcing dependencies, then package needs to be removed so it can be upgraded to the new version required by the parent + packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase))); } } catch (NuGetResolverConstraintException ex) @@ -1490,7 +1472,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat { var remoteRepositories = NugetCommon.GetRemoteRepositories(config, _nugetLogger, _fileSystem); - var pathResolver = NugetCommon.GetPathResolver(config, _fileSystem); + var pathResolver = NugetCommon.GetPathResolver(_fileSystem); var outdatedPackages = new ConcurrentDictionary(); @@ -1516,7 +1498,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat if (isPinned && config.OutdatedCommand.IgnorePinned) { string pinnedLogMessage = "{0} is pinned. Skipping pinned package.".format_with(packageName); - var pinnedPackageResult = outdatedPackages.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id, installedPackage.PackageMetadata.Version))); + var pinnedPackageResult = outdatedPackages.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id))); pinnedPackageResult.Messages.Add(new ResultMessage(ResultType.Debug, pinnedLogMessage)); pinnedPackageResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, pinnedLogMessage)); @@ -1536,7 +1518,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat if (config.Features.IgnoreUnfoundPackagesOnUpgradeOutdated) continue; string unfoundLogMessage = "{0} was not found with the source(s) listed.{1} Source(s): \"{2}\"".format_with(packageName, Environment.NewLine, config.Sources); - var unfoundResult = outdatedPackages.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id, installedPackage.PackageMetadata.Version))); + var unfoundResult = outdatedPackages.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id))); unfoundResult.Messages.Add(new ResultMessage(ResultType.Warn, unfoundLogMessage)); unfoundResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, unfoundLogMessage)); @@ -1552,15 +1534,6 @@ public virtual ConcurrentDictionary get_outdated(Chocolat packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage)); this.Log().Info("{0}|{1}|{2}|{3}".format_with(installedPackage.Name, installedPackage.Version, latestPackage.Identity.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.Name, installedPackage.Version); - - packageResult.Messages.Add(new ResultMessage(ResultType.Warn, deprecationMessage)); - } } // Reset the configuration again once we are completely done with the processing of @@ -1788,19 +1761,12 @@ private void validate_nuspec(string nuspecFilePath, ChocolateyConfiguration conf private string get_install_directory(ChocolateyConfiguration config, IPackageMetadata installedPackage) { - - var pathResolver = NugetCommon.GetPathResolver(config, _fileSystem); + var pathResolver = NugetCommon.GetPathResolver(_fileSystem); var installDirectory = pathResolver.GetInstallPath(new PackageIdentity(installedPackage.Id, installedPackage.Version)); + if (!_fileSystem.directory_exists(installDirectory)) { - var chocoPathResolver = pathResolver as ChocolateyPackagePathResolver; - if (chocoPathResolver != null) - { - chocoPathResolver.UseSideBySidePaths = !chocoPathResolver.UseSideBySidePaths; - installDirectory = chocoPathResolver.GetInstallPath(new PackageIdentity(installedPackage.Id, installedPackage.Version)); - } - - if (!_fileSystem.directory_exists(installDirectory)) return null; + return null; } return installDirectory; @@ -1818,30 +1784,6 @@ protected virtual void ensure_package_files_have_compatible_attributes(Chocolate _filesService.ensure_compatible_file_attributes(installDirectory, config); } - [Obsolete("This overload is obsolete and will be removed in a future version.")] - public virtual void rename_legacy_package_version(ChocolateyConfiguration config, IPackageMetadata installedPackage, ChocolateyPackageInformation pkgInfo) - => normalize_package_legacy_folder_name(config, installedPackage, pkgInfo); - - protected virtual void normalize_package_legacy_folder_name(ChocolateyConfiguration config, IPackageMetadata installedPackage, ChocolateyPackageInformation pkgInfo) - { - if (pkgInfo != null && pkgInfo.IsSideBySide) return; - - var installDirectory = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id); - if (!_fileSystem.directory_exists(installDirectory)) - { - // if the folder has a version on it, we need to rename the folder first. - var pathResolver = new ChocolateyPackagePathResolver(ApplicationParameters.PackagesLocation, _fileSystem, useSideBySidePaths: true); - installDirectory = pathResolver.GetInstallPath(new PackageIdentity(installedPackage.Id, installedPackage.Version)); - if (_fileSystem.directory_exists(installDirectory)) - { - FaultTolerance.try_catch_with_logging_exception( - () => _fileSystem.move_directory(installDirectory, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id)), - "Error during old package rename"); - } - } - - } - [Obsolete("This overload is obsolete and will be removed in a future version.")] public virtual void backup_existing_version(ChocolateyConfiguration config, IPackageMetadata installedPackage, ChocolateyPackageInformation packageInfo) => backup_existing_version(config, packageInfo); @@ -2281,7 +2223,7 @@ public virtual ConcurrentDictionary uninstall_run(Chocola { var logMessage = "{0} not uninstalled. An error occurred during uninstall:{1} {2}".format_with(packageName, Environment.NewLine, ex.Message); this.Log().Error(ChocolateyLoggers.Important, logMessage); - var result = packageResultsToReturn.GetOrAdd(packageToUninstall.Name + "." + packageToUninstall.Version.to_string(), new PackageResult(packageToUninstall.PackageMetadata, pathResolver.GetInstallPath(packageToUninstall.PackageMetadata.Id, packageToUninstall.PackageMetadata.Version))); + var result = packageResultsToReturn.GetOrAdd(packageToUninstall.Name + "." + packageToUninstall.Version.to_string(), new PackageResult(packageToUninstall.PackageMetadata, pathResolver.GetInstallPath(packageToUninstall.PackageMetadata.Id))); result.Messages.Add(new ResultMessage(ResultType.Error, logMessage)); if (result.ExitCode == 0) result.ExitCode = 1; if (config.Features.StopOnFirstPackageFailure) @@ -2295,7 +2237,7 @@ public virtual ConcurrentDictionary uninstall_run(Chocola else { // continue action won't be found b/c we are not actually uninstalling (this is noop) - var result = packageResultsToReturn.GetOrAdd(installedPackage.Name + "." + installedPackage.Version.to_string(), new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id, installedPackage.PackageMetadata.Version))); + var result = packageResultsToReturn.GetOrAdd(installedPackage.Name + "." + installedPackage.Version.to_string(), new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id))); if (continueAction != null) continueAction.Invoke(result, config); } } @@ -2374,7 +2316,6 @@ protected void backup_existing_package_files(ChocolateyConfiguration config, IPa { remove_rollback_directory_if_exists(package.Id); ensure_package_files_have_compatible_attributes(config, package); - normalize_package_legacy_folder_name(config, package, packageInformation); backup_existing_version(config, packageInformation); remove_shim_directors(config, package); } @@ -2388,10 +2329,9 @@ protected void backup_existing_package_files(ChocolateyConfiguration config, IPa private void ensure_nupkg_is_removed(IPackageMetadata removedPackage, ChocolateyPackageInformation pkgInfo) { this.Log().Debug(ChocolateyLoggers.Verbose, "Removing nupkg if it still exists."); - var isSideBySide = pkgInfo != null && pkgInfo.IsSideBySide; - var nupkgFile = "{0}{1}.nupkg".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty); - var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, "{0}{1}".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty)); + var nupkgFile = "{0}.nupkg".format_with(removedPackage.Id); + var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, removedPackage.Id); var nupkg = _fileSystem.combine_paths(installDir, nupkgFile); if (!_fileSystem.file_exists(nupkg)) return; @@ -2424,8 +2364,7 @@ private void fix_nuspec_casing(IPackageSearchMetadata packageMetadata, string pa public virtual void remove_installation_files_unsafe(IPackageMetadata removedPackage, ChocolateyPackageInformation pkgInfo) { this.Log().Debug(ChocolateyLoggers.Verbose, "Ensuring removal of installation files."); - var isSideBySide = pkgInfo != null && pkgInfo.IsSideBySide; - var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, "{0}{1}".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty)); + var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, removedPackage.Id); if (_fileSystem.directory_exists(installDir) && pkgInfo != null && pkgInfo.FilesSnapshot != null) { @@ -2459,8 +2398,7 @@ public virtual void remove_installation_files_unsafe(IPackageMetadata removedPac public virtual void remove_installation_files(IPackageMetadata removedPackage, ChocolateyPackageInformation pkgInfo) { this.Log().Debug(ChocolateyLoggers.Verbose, "Ensuring removal of installation files."); - var isSideBySide = pkgInfo != null && pkgInfo.IsSideBySide; - var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, "{0}{1}".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty)); + var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, removedPackage.Id); if (_fileSystem.directory_exists(installDir) && pkgInfo != null && pkgInfo.FilesSnapshot != null) { diff --git a/tests/chocolatey-tests/commands/choco-info.Tests.ps1 b/tests/chocolatey-tests/commands/choco-info.Tests.ps1 index e45838a22..7fc0a27af 100644 --- a/tests/chocolatey-tests/commands/choco-info.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-info.Tests.ps1 @@ -145,24 +145,6 @@ Describe "choco info" -Tag Chocolatey, InfoCommand { } } - Context "Listing package information about local side by side installed package" { - BeforeAll { - Restore-ChocolateyInstallSnapshot - $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 - } - } - # This needs to be the last test in this block, to ensure NuGet configurations aren't being created. Test-NuGetPaths } diff --git a/tests/chocolatey-tests/commands/choco-install.Tests.ps1 b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 index 15a42f3a5..002f85feb 100644 --- a/tests/chocolatey-tests/commands/choco-install.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-install.Tests.ps1 @@ -159,7 +159,7 @@ Describe "choco install" -Tag Chocolatey, InstallCommand { diff --git a/tests/chocolatey-tests/commands/choco-removed.Tests.ps1 b/tests/chocolatey-tests/commands/choco-removed.Tests.ps1 index 91ff20972..222a0fb04 100644 --- a/tests/chocolatey-tests/commands/choco-removed.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-removed.Tests.ps1 @@ -127,4 +127,41 @@ exit $command.Count $Output.Lines | Should -Contain "Unknown command --remove. Setting to list." } } + + Context 'Ensure --allow-multiple removed from Chocolatey' -Tag InstallCommand, UpgradeCommand, UninstallCommand, AllowMultiple -Foreach @( + @{ Command = 'install' } + @{ Command = 'update' } + @{ Command = 'uninstall' } + ){ + BeforeAll { + $package = 'upgradepackage' + $options = @( + '--version' + if ($Command -in 'upgrade', 'uninstall') { + '1.1.0' + } + else { + '1.0.0' + } + '--allow-multiple' + ) + + $Output = Invoke-Choco $Command $package @options + } + + It 'Exits with Success (0)' { + $Output.ExitCode | Should -Be 0 -Because $Output.String + } + + It 'Does not use a versioned package folder' -Skip:($Command -eq 'upgrade') { + $expectedPath = Join-Path $env:ChocolateyInstall -ChildPath 'lib' | + Join-Path -ChildPath $package + + $expectedPath | Should -Exist -Because 'choco should use the unversioned package folder path.' + } + + It 'Emits a warning for the removed option' { + $Output.Lines | Should -Contain 'The --allow-multiple option is no longer supported.' + } + } } diff --git a/tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 b/tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 index ed9aae184..c2935bc25 100644 --- a/tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 +++ b/tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 @@ -12,36 +12,6 @@ Describe "choco uninstall" -Tag Chocolatey, UninstallCommand { 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 - } - } - Context "Uninstalling package that makes use of new Get Chocolatey Path helper" { BeforeAll { Restore-ChocolateyInstallSnapshot