Пример #1
0
 /// <inheritdoc />
 public void Install(IRepositoryInstalled repository, IPackage package)
 {
     if (!IsInstalled(repository, package))
     {
         repository.AddPackage((IPackage)package.Clone());
     }
 }
Пример #2
0
        /// <summary>
        /// Executes solver operation.
        /// </summary>
        /// <param name="installedRepository">The repository in which to check.</param>
        /// <param name="operation">The operation instance.</param>
        public virtual void Execute(IRepositoryInstalled installedRepository, IOperation operation)
        {
            void WaitDownload(IPackage package, IPackage previousPackage = null)
            {
                var type = previousPackage != null?previousPackage.GetPackageType() : package.GetPackageType();

                var installer = GetInstaller(type);

                installer.Download(package, previousPackage)?.Wait();
            }

            var method = GetExecuteMethod(operation.JobCommand);

            if (operation.JobCommand == JobCommand.Install)
            {
                if (!(operation is OperationInstall operationInstall))
                {
                    throw new UnexpectedException($"The Install operation must be {nameof(OperationInstall)} instance.");
                }

                WaitDownload(operationInstall.GetPackage());
            }
            else if (operation.JobCommand == JobCommand.Update)
            {
                if (!(operation is OperationUpdate operationUpdate))
                {
                    throw new UnexpectedException($"The update operation must be {nameof(OperationUpdate)} instance.");
                }

                WaitDownload(operationUpdate.GetTargetPackage(), operationUpdate.GetInitialPackage());
            }

            method(installedRepository, operation);
        }
Пример #3
0
        /// <summary>
        /// Executes update operation.
        /// </summary>
        /// <param name="installedRepository">The repository in which to check.</param>
        /// <param name="operation">The operation instance.</param>
        protected virtual void Update(IRepositoryInstalled installedRepository, IOperation operation)
        {
            if (!(operation is OperationUpdate operationUpdate))
            {
                throw new UnexpectedException($"The update operation must be {nameof(OperationUpdate)} instance.");
            }

            var initial = operationUpdate.GetInitialPackage();
            var target  = operationUpdate.GetTargetPackage();

            var initialType = initial.GetPackageType();
            var targetType  = target.GetPackageType();

            if (initialType == targetType)
            {
                var installer = GetInstaller(initialType);
                installer.Update(installedRepository, initial, target);
                MarkForNotification(target);
            }
            else
            {
                var installer = GetInstaller(initialType);
                installer.Uninstall(installedRepository, initial);

                installer = GetInstaller(targetType);
                installer.Install(installedRepository, target);
            }
        }
Пример #4
0
        /// <inheritdoc />
        public void Uninstall(IRepositoryInstalled repository, IPackage package)
        {
            if (!IsInstalled(repository, package))
            {
                throw new InvalidArgumentException($"Package is not installed: {package}");
            }

            repository.RemovePackage(package);
        }
Пример #5
0
        /// <inheritdoc />
        public virtual bool IsInstalled(IRepositoryInstalled repository, IPackage package)
        {
            if (!repository.HasPackage(package))
            {
                return(false);
            }

            return(fileSystem.Exists(GetInstallPath(package), FileSystemOptions.Directory));
        }
Пример #6
0
        /// <summary>
        /// Checks whether provided package is installed in one of the registered installers.
        /// </summary>
        /// <param name="installedRepository">The repository in which to check.</param>
        /// <param name="package">The package instance.</param>
        /// <returns>True if the package is installed.</returns>
        public virtual bool IsPackageInstalled(IRepositoryInstalled installedRepository, IPackage package)
        {
            if (package is PackageAlias packageAlias)
            {
                return(installedRepository.HasPackage(package) && IsPackageInstalled(installedRepository, packageAlias.GetAliasOf()));
            }

            return(GetInstaller(package.GetPackageType()).IsInstalled(installedRepository, package));
        }
Пример #7
0
        /// <inheritdoc />
        public void Uninstall(IRepositoryInstalled repository, IPackage package)
        {
            if (!repository.HasPackage(package))
            {
                throw new InvalidArgumentException($"Package is not installed: {package}");
            }

            io.WriteError($"  - Removing <info>{package.GetName()}</info> (<comment>{package.GetVersionPrettyFull()}</comment>)");
            repository.RemovePackage(package);
        }
Пример #8
0
 /// <summary>
 /// Purge packages that are not installed.
 /// </summary>
 protected virtual void PurgePackages(IRepositoryInstalled repositoryInstalled, InstallationManager installationManager)
 {
     foreach (var package in repositoryInstalled.GetPackages())
     {
         if (!installationManager.IsPackageInstalled(repositoryInstalled, package))
         {
             repositoryInstalled.RemovePackage(package);
         }
     }
 }
Пример #9
0
        /// <summary>
        /// Executes marke alias uninstall operation.
        /// </summary>
        /// <param name="installedRepository">The repository in which to check.</param>
        /// <param name="operation">The operation instance.</param>
        protected virtual void MarkAliasUninstalled(IRepositoryInstalled installedRepository, IOperation operation)
        {
            if (!(operation is OperationMarkPackageAliasUninstall operationAliasUninstall))
            {
                throw new UnexpectedException($"The mark package aliased uninstalled operation must be {nameof(OperationMarkPackageAliasUninstall)} instance.");
            }

            var package = operationAliasUninstall.GetPackage();

            installedRepository.RemovePackage(package);
        }
Пример #10
0
        /// <summary>
        /// Executes uninstall operation.
        /// </summary>
        /// <param name="installedRepository">The repository in which to check.</param>
        /// <param name="operation">The operation instance.</param>
        protected virtual void Uninstall(IRepositoryInstalled installedRepository, IOperation operation)
        {
            if (!(operation is OperationUninstall operationUninstall))
            {
                throw new UnexpectedException($"The uninstall operation must be {nameof(OperationUninstall)} instance.");
            }

            var package   = operationUninstall.GetPackage();
            var installer = GetInstaller(package.GetPackageType());

            installer.Uninstall(installedRepository, package);
        }
Пример #11
0
        /// <summary>
        /// Executes marke alias installed operation.
        /// </summary>
        /// <param name="installedRepository">The repository in which to check.</param>
        /// <param name="operation">The operation instance.</param>
        protected virtual void MarkAliasInstalled(IRepositoryInstalled installedRepository, IOperation operation)
        {
            if (!(operation is OperationMarkPackageAliasInstalled operationAliasInstall))
            {
                throw new UnexpectedException($"The mark package aliased installed operation must be {nameof(OperationMarkPackageAliasInstalled)} instance.");
            }

            var package = operationAliasInstall.GetPackage();

            if (!installedRepository.HasPackage(package))
            {
                installedRepository.AddPackage((IPackage)package.Clone());
            }
        }
Пример #12
0
        /// <inheritdoc />
        public override void Install(IRepositoryInstalled repository, IPackage package)
        {
            base.Install(repository, package);

            try
            {
                GetBucket().GetPluginManager().ActivatePackages(package, true);
            }
            catch (SException)
            {
                // Rollback installation
                GetIO().WriteError("Plugin installation failed, rolling back.");
                Uninstall(repository, package);
                throw;
            }
        }
Пример #13
0
        /// <inheritdoc />
        public void Update(IRepositoryInstalled repository, IPackage initial, IPackage target)
        {
            if (!repository.HasPackage(initial))
            {
                throw new InvalidArgumentException($"Package is not installed: {initial}");
            }

            var name       = target.GetName();
            var from       = initial.GetVersionPrettyFull();
            var to         = target.GetVersionPrettyFull();
            var actionName = VersionParser.IsUpgrade(initial.GetVersion(), target.GetVersion()) ? "Updating" : "Downgrading";

            io.WriteError($"  - {actionName} <info>{name}</info> (<comment>{from}</comment> => <comment>{to}</comment>)");

            repository.RemovePackage(initial);
            repository.AddPackage((IPackage)target.Clone());
        }
Пример #14
0
        /// <inheritdoc />
        public virtual void Update(IRepositoryInstalled repository, IPackage initial, IPackage target)
        {
            if (!repository.HasPackage(initial))
            {
                throw new InvalidArgumentException($"Package is not installed: {initial}");
            }

            installerBinary.Remove(initial);
            UpdateLibrary(initial, target);
            installerBinary.Install(target, GetInstallPath(target));

            repository.RemovePackage(initial);
            if (!repository.HasPackage(target))
            {
                repository.AddPackage((IPackage)target.Clone());
            }
        }
Пример #15
0
        /// <inheritdoc />
        public override void Update(IRepositoryInstalled repository, IPackage initial, IPackage target)
        {
            base.Update(repository, initial, target);

            try
            {
                GetBucket().GetPluginManager().DeactivatePackage(initial);
                GetBucket().GetPluginManager().ActivatePackages(target, true);
            }
            catch (SException)
            {
                // Rollback installation
                GetIO().WriteError("Plugin initialization failed, rolling back.");
                Uninstall(repository, target);
                Install(repository, initial);
                throw;
            }
        }
Пример #16
0
        /// <inheritdoc />
        public virtual void Install(IRepositoryInstalled repository, IPackage package)
        {
            var installPath = GetInstallPath(package);

            // remove the binaries if it appears the package files are missing.
            if (!fileSystem.Exists(installPath, FileSystemOptions.Directory) &&
                repository.HasPackage(package))
            {
                installerBinary.Remove(package);
            }

            InstallLibaray(package);
            installerBinary.Install(package, installPath);

            if (!repository.HasPackage(package))
            {
                repository.AddPackage((IPackage)package.Clone());
            }
        }
Пример #17
0
        /// <inheritdoc />
        public virtual void Uninstall(IRepositoryInstalled repository, IPackage package)
        {
            if (!repository.HasPackage(package))
            {
                throw new InvalidArgumentException($"Package is not installed: {package}");
            }

            RemoveLibrary(package);
            installerBinary.Remove(package);
            repository.RemovePackage(package);

            var installPath = GetInstallPath(package);

            // If the package comes with a vendor, we also need to
            // check if the provider directory is empty.
            if (package.GetName().Contains("/"))
            {
                var venderDir = Path.GetDirectoryName(installPath);
                if (fileSystem.IsEmptyDirectory(venderDir))
                {
                    fileSystem.Delete(venderDir);
                }
            }
        }
Пример #18
0
 /// <inheritdoc />
 public void Update(IRepositoryInstalled repository, IPackage initial, IPackage target)
 {
     Uninstall(repository, initial);
     Install(repository, target);
 }
Пример #19
0
 /// <inheritdoc />
 public override void Uninstall(IRepositoryInstalled repository, IPackage package)
 {
     GetBucket().GetPluginManager().UninstallPackage(package);
     base.Uninstall(repository, package);
 }
Пример #20
0
 protected override void PurgePackages(IRepositoryInstalled repositoryInstalled, InstallationManager installationManager)
 {
     // noop.
 }
Пример #21
0
 /// <inheritdoc />
 public bool IsInstalled(IRepositoryInstalled repository, IPackage package)
 {
     return(repository.HasPackage(package));
 }
Пример #22
0
 /// <summary>
 /// Sets local installed repository for the project.
 /// </summary>
 public virtual void SetLocalInstalledRepository(IRepositoryInstalled repository)
 {
     localRepository = repository;
 }
Пример #23
0
 /// <inheritdoc />
 public void Install(IRepositoryInstalled repository, IPackage package)
 {
     io.WriteError($"  - Installing <info>{package.GetName()}</info> (<comment>{package.GetVersionPrettyFull()}</comment>)");
     repository.AddPackage((IPackage)package.Clone());
 }