diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index 72b119cfdc..8436efd2e7 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -171,6 +171,10 @@ + + + + @@ -205,6 +209,7 @@ + diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs index 8a40ef9c4f..1972e09b6f 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyPinCommand.cs @@ -27,6 +27,7 @@ namespace chocolatey.infrastructure.app.commands using infrastructure.commands; using infrastructure.configuration; using logging; + using mockups; using nuget; using NuGet.Common; using NuGet.Versioning; @@ -147,7 +148,7 @@ public virtual void noop(ChocolateyConfiguration configuration) public virtual void run(ChocolateyConfiguration configuration) { - var packageManager = NugetCommon.GetPackageManager(configuration, _nugetLogger, + /*var packageManager = NugetCommon.GetPackageManager(configuration, _nugetLogger, new PackageDownloader(), installSuccessAction: null, uninstallSuccessAction: null, @@ -161,9 +162,9 @@ public virtual void run(ChocolateyConfiguration configuration) case PinCommandType.remove: set_pin(packageManager, configuration); break; - } + }*/ } - + /* public virtual void list_pins(IPackageManager packageManager, ChocolateyConfiguration config) { var input = config.Input; @@ -189,7 +190,7 @@ public virtual void set_pin(IPackageManager packageManager, ChocolateyConfigurat var addingAPin = config.PinCommand.Command == PinCommandType.add; this.Log().Info("Trying to {0} a pin for {1}".format_with(config.PinCommand.Command.to_string(), config.PinCommand.Name)); var versionUnspecified = string.IsNullOrWhiteSpace(config.Version); - SemanticVersion semanticVersion = versionUnspecified ? null : new SemanticVersion(config.Version); + SemanticVersion semanticVersion = versionUnspecified ? null : new SemanticVersion(SemanticVersion.Parse(config.Version)); IPackage installedPackage = packageManager.LocalRepository.FindPackage(config.PinCommand.Name, semanticVersion); if (installedPackage == null) { @@ -222,7 +223,7 @@ public virtual void set_pin(IPackageManager packageManager, ChocolateyConfigurat this.Log().Warn(NO_CHANGE_MESSAGE); } } - + */ public virtual bool may_require_admin_access() { var config = Config.get_configuration_settings(); diff --git a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs index 48de84c50f..9b51b9da3a 100644 --- a/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs +++ b/src/chocolatey/infrastructure.app/domain/ChocolateyPackageInformation.cs @@ -16,7 +16,10 @@ namespace chocolatey.infrastructure.app.domain { + using mockups; using NuGet; + using NuGet.Versioning; + using results; public sealed class ChocolateyPackageInformation { diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index ed4f4aff1e..fab859d3b5 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -28,6 +28,7 @@ namespace chocolatey.infrastructure.app.nuget using configuration; using filesystem; using logging; + using mockups; using NuGet.Common; using NuGet.Configuration; using NuGet.Packaging; @@ -52,23 +53,9 @@ private static IConsole Console get { return _console.Value; } } - public static IFileSystem GetNuGetFileSystem(ChocolateyConfiguration configuration, ILogger nugetLogger) - { - return new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation) { Logger = nugetLogger }; - } - - public static IPackagePathResolver GetPathResolver(ChocolateyConfiguration configuration, IFileSystem nugetPackagesFileSystem) - { - return new ChocolateyPackagePathResolver(nugetPackagesFileSystem, configuration.AllowMultipleVersions); - } - - public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem, ILogger nugetLogger) - { - return new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem) { Logger = nugetLogger, PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec }; - } - - public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader) + public static void GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader) { + /* if (configuration.Features.ShowDownloadProgress) { packageDownloader.ProgressAvailable += (sender, e) => @@ -172,18 +159,18 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con ResolveDependenciesVertically = true }; - return repository; + return repository; */ } // keep this here for the licensed edition for now - public static IPackageManager GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, Action installSuccessAction, Action uninstallSuccessAction, bool addUninstallHandler) + public static void GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, Action installSuccessAction, Action uninstallSuccessAction, bool addUninstallHandler) { - return GetPackageManager(configuration, nugetLogger, new PackageDownloader(), installSuccessAction, uninstallSuccessAction, addUninstallHandler); + // return GetPackageManager(configuration, nugetLogger, new PackageDownloader(), installSuccessAction, uninstallSuccessAction, addUninstallHandler); } - public static IPackageManager GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader, Action installSuccessAction, Action uninstallSuccessAction, bool addUninstallHandler) + public static void GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader, Action installSuccessAction, Action uninstallSuccessAction, bool addUninstallHandler) { - IFileSystem nugetPackagesFileSystem = GetNuGetFileSystem(configuration, nugetLogger); + /* IFileSystem nugetPackagesFileSystem = GetNuGetFileSystem(configuration, nugetLogger); IPackagePathResolver pathResolver = GetPathResolver(configuration, nugetPackagesFileSystem); var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger, packageDownloader), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem, nugetLogger)) { @@ -245,7 +232,7 @@ public static IPackageManager GetPackageManager(ChocolateyConfiguration configur }; } - return packageManager; + return packageManager; */ } } diff --git a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs index c612f2072d..c6bbb01faa 100644 --- a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs +++ b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs @@ -61,7 +61,7 @@ public void RegisterComponents(Container container) //nuget container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); - container.Register(Lifestyle.Singleton); + //container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); container.Register(Lifestyle.Singleton); diff --git a/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs b/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs index 50544c22f7..b32019e89f 100644 --- a/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs +++ b/src/chocolatey/infrastructure.app/services/AutomaticUninstallerService.cs @@ -71,6 +71,7 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config) } } + /* var pkgInfo = _packageInfoService.get_package_information(packageResult.Package); if (pkgInfo.RegistrySnapshot == null) { @@ -104,6 +105,7 @@ public void run(PackageResult packageResult, ChocolateyConfiguration config) var packageCacheLocation = _fileSystem.combine_paths(_fileSystem.get_full_path(config.CacheLocation), package.Id, package.Version.to_string()); remove(key, config, packageResult, packageCacheLocation); } + */ } public void remove(RegistryApplicationKey key, ChocolateyConfiguration config, PackageResult packageResult, string packageCacheLocation) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs index d9b220fd46..269dc3efbd 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageInformationService.cs @@ -23,7 +23,9 @@ namespace chocolatey.infrastructure.app.services using NuGet; using domain; using infrastructure.configuration; + using mockups; using NuGet.Versioning; + using results; using tolerance; using IFileSystem = filesystem.IFileSystem; @@ -149,7 +151,7 @@ has errored attempting to read it. This file will be renamed to FaultTolerance.try_catch_with_logging_exception( () => { - packageInformation.VersionOverride = new SemanticVersion(_fileSystem.read_file(versionOverrideFile).trim_safe()); + packageInformation.VersionOverride = new SemanticVersion(SemanticVersion.Parse(_fileSystem.read_file(versionOverrideFile).trim_safe())); }, "Unable to read version override file", throwError: false, diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 8ee3274d08..ae6b00d872 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -31,6 +31,7 @@ namespace chocolatey.infrastructure.app.services using infrastructure.events; using infrastructure.services; using logging; + using mockups; using NuGet; using nuget; using platforms; @@ -1046,7 +1047,7 @@ public virtual void handle_package_uninstall(PackageResult packageResult, Chocol private void uninstall_cleanup(ChocolateyConfiguration config, PackageResult packageResult) { - if (config.Features.RemovePackageInformationOnUninstall) _packageInfoService.remove_package_information(packageResult.Package); + //if (config.Features.RemovePackageInformationOnUninstall) _packageInfoService.remove_package_information(packageResult.Package); ensure_bad_package_path_is_clean(config, packageResult); remove_rollback_if_exists(packageResult); diff --git a/src/chocolatey/infrastructure.app/services/IChocolateyPackageInformationService.cs b/src/chocolatey/infrastructure.app/services/IChocolateyPackageInformationService.cs index d09004e9f6..d1ccdeb427 100644 --- a/src/chocolatey/infrastructure.app/services/IChocolateyPackageInformationService.cs +++ b/src/chocolatey/infrastructure.app/services/IChocolateyPackageInformationService.cs @@ -17,6 +17,7 @@ namespace chocolatey.infrastructure.app.services { using domain; + using mockups; using NuGet; public interface IChocolateyPackageInformationService diff --git a/src/chocolatey/infrastructure.app/services/IPowershellService.cs b/src/chocolatey/infrastructure.app/services/IPowershellService.cs index 7729643c02..e4c8b9d326 100644 --- a/src/chocolatey/infrastructure.app/services/IPowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/IPowershellService.cs @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.app.services using System; using System.Management.Automation.Runspaces; using configuration; + using mockups; using NuGet; using results; diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 7d6672265c..7fab59b79b 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -38,6 +38,7 @@ namespace chocolatey.infrastructure.app.services using Environment = System.Environment; using IFileSystem = filesystem.IFileSystem; using chocolatey.infrastructure.app.utility; + using mockups; using NuGet.Common; using NuGet.Configuration; using NuGet.PackageManagement; @@ -52,7 +53,7 @@ public class NugetService : INugetService private readonly ILogger _nugetLogger; private readonly IChocolateyPackageInformationService _packageInfoService; private readonly IFilesService _filesService; - private readonly IPackageDownloader _packageDownloader; + //private readonly PackageDownloader _packageDownloader; private readonly Lazy datetime_initializer = new Lazy(() => new DateTime()); private IDateTime DateTime @@ -68,13 +69,12 @@ private IDateTime DateTime /// Package information service /// The files service /// The downloader used to download packages - public NugetService(IFileSystem fileSystem, ILogger nugetLogger, IChocolateyPackageInformationService packageInfoService, IFilesService filesService, IPackageDownloader packageDownloader) + public NugetService(IFileSystem fileSystem, ILogger nugetLogger, IChocolateyPackageInformationService packageInfoService, IFilesService filesService) { _fileSystem = fileSystem; _nugetLogger = nugetLogger; _packageInfoService = packageInfoService; _filesService = filesService; - _packageDownloader = packageDownloader; } public SourceType SourceType @@ -89,6 +89,7 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action

list_run(ChocolateyConfiguration config) { + return new PackageResult[0]; int count = 0; var sources = config.Sources; @@ -129,7 +131,7 @@ public virtual IEnumerable list_run(ChocolateyConfiguration confi config.Prerelease = true; config.ListCommand.IncludeVersionOverrides = true; } - + /* if (config.RegularOutput) this.Log().Debug(() => "Running list with the following filter = '{0}'".format_with(config.Input)); if (config.RegularOutput) this.Log().Debug(ChocolateyLoggers.Verbose, () => "--- Start of List ---"); foreach (var pkg in NugetList.GetPackages(config, _nugetLogger)) @@ -222,7 +224,7 @@ Package url yield return new PackageResult(package, null, config.Sources); } - + */ if (config.RegularOutput) this.Log().Debug(ChocolateyLoggers.Verbose, () => "--- End of List ---"); if (config.RegularOutput && !config.QuietOutput) { @@ -288,7 +290,7 @@ public virtual void pack_run(ChocolateyConfiguration config) properties["version"] = config.Version; } - + // Initialize the property provider based on what was passed in using the properties flag var propertyProvider = new DictionaryPropertyProvider(properties); @@ -324,13 +326,13 @@ public virtual void pack_run(ChocolateyConfiguration config) //{ // AnalyzePackage(package); //} - - this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Important, () => "Successfully created package '{0}'".format_with(outputPath)); + + this.Log().Info(config.QuietOutput ? ChocolateyLoggers.LogFileOnly : ChocolateyLoggers.Important, () => "Successfully created package '{0}'".format_with(outputPath)); } public void push_noop(ChocolateyConfiguration config) { - string nupkgFilePath = validate_and_return_package_file(config, Constants.PackageExtension); + string nupkgFilePath = validate_and_return_package_file(config, NuGetConstants.PackageExtension); this.Log().Info(() => "Would have attempted to push '{0}' to source '{1}'.".format_with(_fileSystem.get_file_name(nupkgFilePath), config.Sources)); } @@ -397,21 +399,21 @@ public virtual ConcurrentDictionary install_run(Chocolate //todo: #23 handle all - SemanticVersion version = !string.IsNullOrWhiteSpace(config.Version) ? new SemanticVersion(config.Version) : null; + SemanticVersion version = !string.IsNullOrWhiteSpace(config.Version) ? new SemanticVersion(SemanticVersion.Parse(config.Version)) : null; if (config.Force) config.AllowDowngrade = true; IList packageNames = config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().ToList(); if (packageNames.Count == 1) { var packageName = packageNames.DefaultIfEmpty(string.Empty).FirstOrDefault(); - if (packageName.EndsWith(Constants.PackageExtension) || packageName.EndsWith(Constants.ManifestExtension)) + if (packageName.EndsWith(NuGetConstants.PackageExtension) || packageName.EndsWith(PackagingConstants.ManifestExtension)) { this.Log().Debug("Updating source and package name to handle *.nupkg or *.nuspec file."); packageNames.Clear(); config.Sources = _fileSystem.get_directory_name(_fileSystem.get_full_path(packageName)); - if (packageName.EndsWith(Constants.ManifestExtension)) + if (packageName.EndsWith(PackagingConstants.ManifestExtension)) { packageNames.Add(_fileSystem.get_file_name_without_extension(packageName)); @@ -422,20 +424,21 @@ public virtual ConcurrentDictionary install_run(Chocolate } else { + /* var packageFile = new OptimizedZipPackage(_fileSystem.get_full_path(packageName)); version = packageFile.Version; - packageNames.Add(packageFile.Id); + packageNames.Add(packageFile.Id); */ } } } // this is when someone points the source directly at a nupkg // e.g. -source c:\somelocation\somewhere\packagename.nupkg - if (config.Sources.to_string().EndsWith(Constants.PackageExtension)) + if (config.Sources.to_string().EndsWith(NuGetConstants.PackageExtension)) { config.Sources = _fileSystem.get_directory_name(_fileSystem.get_full_path(config.Sources)); } - + /* var packageManager = NugetCommon.GetPackageManager( config, _nugetLogger, _packageDownloader, installSuccessAction: (e) => @@ -449,7 +452,7 @@ public virtual ConcurrentDictionary install_run(Chocolate }, uninstallSuccessAction: null, addUninstallHandler: true); - + var originalConfig = config.deep_copy(); foreach (string packageName in packageNames.or_empty_list_if_null()) @@ -491,7 +494,7 @@ public virtual ConcurrentDictionary install_run(Chocolate this.Log().Error(ChocolateyLoggers.Important, logMessage); continue; } - + /* IPackage availablePackage = NugetList.find_package(packageName, version, config, packageManager.SourceRepository); if (availablePackage == null) @@ -568,7 +571,7 @@ Version was specified as '{0}'. It is possible that version if (continueAction != null) continueAction.Invoke(errorResult); } } - + */ return packageInstalls; } @@ -609,10 +612,11 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu public virtual ConcurrentDictionary upgrade_run(ChocolateyConfiguration config, Action continueAction, bool performAction, Action beforeUpgradeAction = null) { + _fileSystem.create_directory_if_not_exists(ApplicationParameters.PackagesLocation); var packageInstalls = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); - - SemanticVersion version = !string.IsNullOrWhiteSpace(config.Version) ? new SemanticVersion(config.Version) : null; + /* + SemanticVersion version = !string.IsNullOrWhiteSpace(config.Version) ? new SemanticVersion(SemanticVersion.Parse(config.Version)) : null; if (config.Force) config.AllowDowngrade = true; var packageManager = NugetCommon.GetPackageManager( @@ -713,7 +717,7 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate // this is a prerelease - opt in for newer prereleases. config.Prerelease = true; } - + /* IPackage availablePackage = NugetList.find_package(packageName, version, config, packageManager.SourceRepository); config.Prerelease = originalPrerelease; @@ -747,7 +751,7 @@ 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 @@ -774,7 +778,7 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate continue; } - + if (installedPackage.Version == availablePackage.Version) { string logMessage = "{0} v{1} is the latest version available based on your source(s).".format_with(installedPackage.Id, installedPackage.Version); @@ -891,12 +895,13 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate } } } - +*/ return packageInstalls; } public virtual ConcurrentDictionary get_outdated(ChocolateyConfiguration config) { + /* var packageManager = NugetCommon.GetPackageManager( config, _nugetLogger, @@ -906,13 +911,15 @@ public virtual ConcurrentDictionary get_outdated(Chocolat addUninstallHandler: false); var repository = packageManager.SourceRepository; - var outdatedPackages = new ConcurrentDictionary(); + */ + var outdatedPackages = new ConcurrentDictionary(); + /* set_package_names_if_all_is_specified(config, () => { config.IgnoreDependencies = true; }); var packageNames = config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().ToList(); var originalConfig = config.deep_copy(); - + /* foreach (var packageName in packageNames) { // reset config each time through @@ -939,7 +946,7 @@ public virtual ConcurrentDictionary get_outdated(Chocolat // this is a prerelease - opt in for newer prereleases. config.Prerelease = true; } - + SemanticVersion version = null; var latestPackage = NugetList.find_package(packageName, null, config, packageManager.SourceRepository); @@ -963,9 +970,9 @@ public virtual ConcurrentDictionary get_outdated(Chocolat string logMessage = "You have {0} v{1} installed. Version {2} is available based on your source(s).{3} Source(s): \"{4}\"".format_with(installedPackage.Id, installedPackage.Version, latestPackage.Version, Environment.NewLine, config.Sources); 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())); + this.Log().Info("{0}|{1}|{2}|{3}".format_with(installedPackage.Id, installedPackage.Version, latestPackage.Version, isPinned.to_string().to_lower())); } - + */ return outdatedPackages; } @@ -1023,6 +1030,7 @@ protected virtual ChocolateyConfiguration set_package_config_for_upgrade(Chocola private string get_install_directory(ChocolateyConfiguration config, IPackage installedPackage) { + /* var pathResolver = NugetCommon.GetPathResolver(config, NugetCommon.GetNuGetFileSystem(config, _nugetLogger)); var installDirectory = pathResolver.GetInstallPath(installedPackage); if (!_fileSystem.directory_exists(installDirectory)) @@ -1037,7 +1045,8 @@ private string get_install_directory(ChocolateyConfiguration config, IPackage in if (!_fileSystem.directory_exists(installDirectory)) return null; } - return installDirectory; + return installDirectory; */ + return "asdf"; } public virtual void ensure_package_files_have_compatible_attributes(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo) @@ -1051,7 +1060,7 @@ public virtual void ensure_package_files_have_compatible_attributes(ChocolateyCo public virtual void rename_legacy_package_version(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo) { if (pkgInfo != null && pkgInfo.IsSideBySide) return; - + /* var installDirectory = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id); if (!_fileSystem.directory_exists(installDirectory)) { @@ -1065,6 +1074,7 @@ public virtual void rename_legacy_package_version(ChocolateyConfiguration config "Error during old package rename"); } } + */ } public virtual void backup_existing_version(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation packageInfo) @@ -1264,8 +1274,8 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi public virtual ConcurrentDictionary uninstall_run(ChocolateyConfiguration config, Action continueAction, bool performAction, Action beforeUninstallAction = null) { var packageUninstalls = new ConcurrentDictionary(StringComparer.InvariantCultureIgnoreCase); - - SemanticVersion version = config.Version != null ? new SemanticVersion(config.Version) : null; + /* + SemanticVersion version = config.Version != null ? new SemanticVersion(SemanticVersion.Parse(config.Version)) : null; var packageManager = NugetCommon.GetPackageManager(config, _nugetLogger, _packageDownloader, installSuccessAction: null, uninstallSuccessAction: (e) => @@ -1392,7 +1402,7 @@ public virtual ConcurrentDictionary uninstall_run(Chocola } else { - var semanticVersion = new SemanticVersion(config.Version); + var semanticVersion = new SemanticVersion(SemanticVersion.Parse(config.Version)); installedPackageVersions = packageManager.LocalRepository.FindPackagesById(packageName).Where((p) => p.Version.Equals(semanticVersion)).ToList(); } @@ -1510,7 +1520,7 @@ public virtual ConcurrentDictionary uninstall_run(Chocola } } } - + */ return packageUninstalls; } diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs index 25511564e9..d35efd3448 100644 --- a/src/chocolatey/infrastructure.app/services/PowershellService.cs +++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs @@ -34,6 +34,7 @@ namespace chocolatey.infrastructure.app.services using infrastructure.commands; using infrastructure.registration; using logging; + using mockups; using NuGet; using powershell; using results; @@ -196,7 +197,7 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack { var failure = false; var package = packageResult.Package; - prepare_powershell_environment(package, configuration, packageDirectory); + //prepare_powershell_environment(package, configuration, packageDirectory); this.Log().Debug(ChocolateyLoggers.Important, "Contents of '{0}':".format_with(chocoPowerShellScript)); string chocoPowerShellScriptContents = _fileSystem.read_file(chocoPowerShellScript); @@ -379,8 +380,8 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura Environment.SetEnvironmentVariable("packageTitle", package.Title); Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Version.to_string()); Environment.SetEnvironmentVariable("packageVersion", package.Version.to_string()); - Environment.SetEnvironmentVariable("chocolateyPackageVersionPrerelease", package.Version.SpecialVersion.to_string()); - Environment.SetEnvironmentVariable("chocolateyPackageVersionPackageRelease", package.Version.PackageReleaseVersion.to_string()); + //Environment.SetEnvironmentVariable("chocolateyPackageVersionPrerelease", package.Version.SpecialVersion.to_string()); + //Environment.SetEnvironmentVariable("chocolateyPackageVersionPackageRelease", package.Version.PackageReleaseVersion.to_string()); Environment.SetEnvironmentVariable("chocolateyPackageFolder", packageDirectory); Environment.SetEnvironmentVariable("packageFolder", packageDirectory); @@ -464,7 +465,7 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura if (package.IsDownloadCacheAvailable) { Environment.SetEnvironmentVariable("DownloadCacheAvailable", "true"); - + /* foreach (var downloadCache in package.DownloadCache.or_empty_list_if_null()) { var urlKey = CryptoHashProvider.hash_value(downloadCache.OriginalUrl, CryptoHashProviderType.Sha256).Replace("=", string.Empty); @@ -472,6 +473,7 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura Environment.SetEnvironmentVariable("CacheChecksum_{0}".format_with(urlKey), downloadCache.Checksum); Environment.SetEnvironmentVariable("CacheChecksumType_{0}".format_with(urlKey), "sha512"); } + */ } SecurityProtocol.set_protocol(configuration, provideWarning:false); diff --git a/src/chocolatey/infrastructure.app/services/TemplateService.cs b/src/chocolatey/infrastructure.app/services/TemplateService.cs index 5961c88664..93834938e9 100644 --- a/src/chocolatey/infrastructure.app/services/TemplateService.cs +++ b/src/chocolatey/infrastructure.app/services/TemplateService.cs @@ -212,11 +212,13 @@ public void list_noop(ChocolateyConfiguration configuration) public void list(ChocolateyConfiguration configuration) { + + /* var packageManager = NugetCommon.GetPackageManager(configuration, _nugetLogger, new PackageDownloader(), installSuccessAction: null, uninstallSuccessAction: null, - addUninstallHandler: false); + addUninstallHandler: false); */ var templateDirList = _fileSystem.get_directories(ApplicationParameters.TemplatesLocation).ToList(); var isBuiltInTemplateOverriden = templateDirList.Contains(_fileSystem.combine_paths(ApplicationParameters.TemplatesLocation, _builtInTemplateOverrideName)); @@ -229,7 +231,7 @@ public void list(ChocolateyConfiguration configuration) foreach (var templateDir in templateDirList) { configuration.TemplateCommand.Name = _fileSystem.get_file_name(templateDir); - list_custom_template_info(configuration, packageManager); + //list_custom_template_info(configuration, packageManager); } this.Log().Info(configuration.RegularOutput ? "{0} Custom templates found at {1}{2}".format_with(templateDirList.Count(), ApplicationParameters.TemplatesLocation, Environment.NewLine) : string.Empty); @@ -245,7 +247,7 @@ public void list(ChocolateyConfiguration configuration) { if (templateDirList.Contains(_fileSystem.combine_paths(ApplicationParameters.TemplatesLocation, configuration.TemplateCommand.Name))) { - list_custom_template_info(configuration, packageManager); + //list_custom_template_info(configuration, packageManager); if (configuration.TemplateCommand.Name == _builtInTemplateName || configuration.TemplateCommand.Name == _builtInTemplateOverrideName) { list_built_in_template_info(configuration, isBuiltInTemplateOverriden, isBuiltInOrDefaultTemplateDefault); @@ -265,7 +267,7 @@ public void list(ChocolateyConfiguration configuration) } } } - + /* protected void list_custom_template_info(ChocolateyConfiguration configuration, IPackageManager packageManager) { var pkg = packageManager.LocalRepository.FindPackage("{0}.template".format_with(configuration.TemplateCommand.Name)); @@ -311,7 +313,7 @@ protected void list_custom_template_info(ChocolateyConfiguration configuration, { this.Log().Info("{0}|{1}".format_with(configuration.TemplateCommand.Name, pkgVersion)); } - } + } */ protected void list_built_in_template_info(ChocolateyConfiguration configuration, bool isOverridden, bool isDefault) { diff --git a/src/chocolatey/infrastructure/cryptography/DefaultEncryptionUtility.cs b/src/chocolatey/infrastructure/cryptography/DefaultEncryptionUtility.cs index e37c9934ae..71c8286c3e 100644 --- a/src/chocolatey/infrastructure/cryptography/DefaultEncryptionUtility.cs +++ b/src/chocolatey/infrastructure/cryptography/DefaultEncryptionUtility.cs @@ -87,7 +87,7 @@ public string generate_unique_token(string caseInsensitiveKey) { // SHA256 is case sensitive; given that our key is case insensitive, we upper case it var pathBytes = Encoding.UTF8.GetBytes(caseInsensitiveKey.ToUpperInvariant()); - var hashProvider = new NuGet.CryptoHashProvider("SHA256"); + var hashProvider = new NuGet.Common.CryptoHashProvider("SHA256"); return Convert.ToBase64String(hashProvider.CalculateHash(pathBytes)).ToUpperInvariant(); } diff --git a/src/chocolatey/infrastructure/mockups/IPackage.cs b/src/chocolatey/infrastructure/mockups/IPackage.cs new file mode 100644 index 0000000000..8aeba03998 --- /dev/null +++ b/src/chocolatey/infrastructure/mockups/IPackage.cs @@ -0,0 +1,84 @@ +// Copyright © 2017 - 2021 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// 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. + +namespace chocolatey.infrastructure.mockups +{ + using System; + using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; + using System.IO; + using System.Runtime.Versioning; + using filesystem; + using NuGet.Packaging; + using NuGet.Versioning; + + public interface IPackage : IPackageMetadata + { + bool IsAbsoluteLatestVersion { get; } + + bool IsLatestVersion { get; } + + bool Listed { get; } + + DateTimeOffset? Published { get; } + + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This might be expensive")] + IEnumerable GetFiles(); + + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This might be expensive")] + IEnumerable GetSupportedFrameworks(); + + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This might be expensive")] + Stream GetStream(); + + void ExtractContents(IFileSystem fileSystem, string extractPath); + + void OverrideOriginalVersion(SemanticVersion version); + + Uri ProjectSourceUrl { get; } + Uri PackageSourceUrl { get; } + Uri DocsUrl { get; } + Uri WikiUrl { get; } + Uri MailingListUrl { get; } + Uri BugTrackerUrl { get; } + IEnumerable Replaces { get; } + IEnumerable Provides { get; } + IEnumerable Conflicts { get; } + + string SoftwareDisplayName { get; } + string SoftwareDisplayVersion { get; } + + string PackageHash { get; } + string PackageHashAlgorithm { get; } + long PackageSize { get; } + int VersionDownloadCount { get; } + + bool IsApproved { get; } + string PackageStatus { get; } + string PackageSubmittedStatus { get; } + string PackageTestResultStatus { get; } + DateTime? PackageTestResultStatusDate { get; } + string PackageValidationResultStatus { get; } + DateTime? PackageValidationResultDate { get; } + DateTime? PackageCleanupResultDate { get; } + DateTime? PackageReviewedDate { get; } + DateTime? PackageApprovedDate { get; } + string PackageReviewer { get; } + + bool IsDownloadCacheAvailable { get; } + DateTime? DownloadCacheDate { get; } + } +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure/mockups/IPackageManager.cs b/src/chocolatey/infrastructure/mockups/IPackageManager.cs new file mode 100644 index 0000000000..1f5e78b19c --- /dev/null +++ b/src/chocolatey/infrastructure/mockups/IPackageManager.cs @@ -0,0 +1,72 @@ +// Copyright © 2017 - 2021 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// 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. + +namespace chocolatey.infrastructure.mockups +{ + using filesystem; + using NuGet.Common; + using NuGet.Versioning; + + public interface IPackageManager + { + IFileSystem FileSystem { get; set; } + + IPackageRepository LocalRepository { get; } + + ILogger Logger { get; set; } + + bool WhatIf { get; set; } + + IPackageRepository SourceRepository { get; } + + + void InstallPackage(IPackage package, bool ignoreDependencies, bool allowPrereleaseVersions); + + void InstallPackage( + IPackage package, + bool ignoreDependencies, + bool allowPrereleaseVersions, + bool ignoreWalkInfo); + + void InstallPackage( + string packageId, + SemanticVersion version, + bool ignoreDependencies, + bool allowPrereleaseVersions); + + void UpdatePackage(IPackage newPackage, bool updateDependencies, bool allowPrereleaseVersions); + + void UpdatePackage( + string packageId, + SemanticVersion version, + bool updateDependencies, + bool allowPrereleaseVersions); + + void UpdatePackage( + string packageId, + string versionSpec, + bool updateDependencies, + bool allowPrereleaseVersions); + + void UninstallPackage(IPackage package, bool forceRemove, bool removeDependencies); + + void UninstallPackage( + string packageId, + SemanticVersion version, + bool forceRemove, + bool removeDependencies); + } +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure/mockups/IPackageRepository.cs b/src/chocolatey/infrastructure/mockups/IPackageRepository.cs new file mode 100644 index 0000000000..cc223ed7e7 --- /dev/null +++ b/src/chocolatey/infrastructure/mockups/IPackageRepository.cs @@ -0,0 +1,35 @@ +// Copyright © 2017 - 2021 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// 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. + +namespace chocolatey.infrastructure.mockups +{ + using System.Diagnostics.CodeAnalysis; + using System.Linq; + + public interface IPackageRepository + { + string Source { get; } + + bool SupportsPrereleasePackages { get; } + + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This call might be expensive")] + IQueryable GetPackages(); + + void AddPackage(IPackage package); + + void RemovePackage(IPackage package); + } +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure/mockups/PackageOperationEventArgs.cs b/src/chocolatey/infrastructure/mockups/PackageOperationEventArgs.cs new file mode 100644 index 0000000000..125d0bbf34 --- /dev/null +++ b/src/chocolatey/infrastructure/mockups/PackageOperationEventArgs.cs @@ -0,0 +1,37 @@ +// Copyright © 2017 - 2021 Chocolatey Software, Inc +// Copyright © 2011 - 2017 RealDimensions Software, LLC +// +// 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. + +namespace chocolatey.infrastructure.mockups +{ + using System.ComponentModel; + using filesystem; + + public class PackageOperationEventArgs : CancelEventArgs + { + public PackageOperationEventArgs(IPackage package, IFileSystem fileSystem, string installPath) + { + this.Package = package; + this.InstallPath = installPath; + this.FileSystem = fileSystem; + } + + public string InstallPath { get; private set; } + + public IPackage Package { get; private set; } + + public IFileSystem FileSystem { get; private set; } + } +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure.app/nuget/ChocolateyPhysicalFileSystem.cs b/src/chocolatey/infrastructure/mockups/PhysicalFileSystem.cs similarity index 60% rename from src/chocolatey/infrastructure.app/nuget/ChocolateyPhysicalFileSystem.cs rename to src/chocolatey/infrastructure/mockups/PhysicalFileSystem.cs index 908011508c..b9db4515fb 100644 --- a/src/chocolatey/infrastructure.app/nuget/ChocolateyPhysicalFileSystem.cs +++ b/src/chocolatey/infrastructure/mockups/PhysicalFileSystem.cs @@ -14,25 +14,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace chocolatey.infrastructure.app.nuget +namespace chocolatey.infrastructure.mockups { + using System; using System.Collections.Generic; - using NuGet; + using NuGet.Packaging; - // ReSharper disable InconsistentNaming - - public class ChocolateyPhysicalFileSystem : PhysicalFileSystem + public class PhysicalFileSystem { - public ChocolateyPhysicalFileSystem(string root) - : base(root) + private readonly string _root; + + public PhysicalFileSystem(string root) { + if (String.IsNullOrEmpty(root)) + { + throw new ArgumentException("thing"); + } + _root = root; } - - public override void AddFiles(IEnumerable files, string rootDir) + public virtual void AddFiles(IEnumerable files, string rootDir) { - this.AddFiles(files, rootDir, preserveFilePath: true); } } - - // ReSharper restore InconsistentNaming -} +} \ No newline at end of file diff --git a/src/chocolatey/infrastructure/results/PackageResult.cs b/src/chocolatey/infrastructure/results/PackageResult.cs index 5c5a35c2a3..6ece4a2b61 100644 --- a/src/chocolatey/infrastructure/results/PackageResult.cs +++ b/src/chocolatey/infrastructure/results/PackageResult.cs @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.results using System; using System.Collections.Generic; using System.Linq; + using mockups; using NuGet.Packaging; ///

@@ -63,7 +64,8 @@ public PackageResult(IPackage package, string installLocation, string source = n } } - + Source = sources.FirstOrDefault(uri => uri.IsFile || uri.IsUnc).to_string(); + /* TODO, fix this var rp = Package as DataServicePackage; if (rp != null && rp.DownloadUrl != null) { @@ -78,6 +80,7 @@ public PackageResult(IPackage package, string installLocation, string source = n { Source = sources.FirstOrDefault(uri => uri.IsFile || uri.IsUnc).to_string(); } + */ } public PackageResult(string name, string version, string installLocation, string source = null)