Beispiel #1
0
        public override int Execute()
        {
            FilePath?customManifestFileLocation = GetCustomManifestFileLocation();

            FilePath?configFile = null;

            if (_configFilePath != null)
            {
                configFile = new FilePath(_configFilePath);
            }

            IReadOnlyCollection <ToolManifestPackage> packagesFromManifest;

            try
            {
                packagesFromManifest = _toolManifestFinder.Find(customManifestFileLocation);
            }
            catch (ToolManifestCannotBeFoundException e)
            {
                if (CommandContext.IsVerbose())
                {
                    _reporter.WriteLine(string.Join(Environment.NewLine, e.VerboseMessage).Yellow());
                }

                _reporter.WriteLine(e.Message.Yellow());
                _reporter.WriteLine(LocalizableStrings.NoToolsWereRestored.Yellow());
                return(0);
            }

            ToolRestoreResult[] toolRestoreResults =
                packagesFromManifest
                .AsParallel()
                .Select(package => InstallPackages(package, configFile))
                .ToArray();

            Dictionary <RestoredCommandIdentifier, RestoredCommand> downloaded =
                toolRestoreResults.SelectMany(result => result.SaveToCache)
                .ToDictionary(pair => pair.Item1, pair => pair.Item2);

            EnsureNoCommandNameCollision(downloaded);

            _localToolsResolverCache.Save(downloaded);

            return(PrintConclusionAndReturn(toolRestoreResults));
        }
Beispiel #2
0
        public override int Execute()
        {
            (FilePath manifestFile, string warningMessage) = FindManifestFile();

            var toolDownloadedPackage        = _toolLocalPackageInstaller.Install(manifestFile);
            var existingPackageWithPackageId =
                _toolManifestFinder
                .Find(manifestFile)
                .Where(p => p.PackageId.Equals(_packageId));

            if (!existingPackageWithPackageId.Any())
            {
                return(_toolInstallLocalCommand.Value.Install(manifestFile));
            }

            var existingPackage = existingPackageWithPackageId.Single();

            if (existingPackage.Version > toolDownloadedPackage.Version)
            {
                throw new GracefulException(new[]
                {
                    string.Format(
                        LocalizableStrings.UpdateLocaToolToLowerVersion,
                        toolDownloadedPackage.Version.ToNormalizedString(),
                        existingPackage.Version.ToNormalizedString(),
                        manifestFile.Value)
                },
                                            isUserError: false);
            }

            if (existingPackage.Version != toolDownloadedPackage.Version)
            {
                _toolManifestEditor.Edit(
                    manifestFile,
                    _packageId,
                    toolDownloadedPackage.Version,
                    toolDownloadedPackage.Commands.Select(c => c.Name).ToArray());
            }

            _localToolsResolverCache.SaveToolPackage(
                toolDownloadedPackage,
                _toolLocalPackageInstaller.TargetFrameworkToInstall);

            if (warningMessage != null)
            {
                _reporter.WriteLine(warningMessage.Yellow());
            }

            if (existingPackage.Version == toolDownloadedPackage.Version)
            {
                _reporter.WriteLine(
                    string.Format(
                        LocalizableStrings.UpdateLocaToolSucceededVersionNoChange,
                        toolDownloadedPackage.Id,
                        existingPackage.Version.ToNormalizedString(),
                        manifestFile.Value));
            }
            else
            {
                _reporter.WriteLine(
                    string.Format(
                        LocalizableStrings.UpdateLocalToolSucceeded,
                        toolDownloadedPackage.Id,
                        existingPackage.Version.ToNormalizedString(),
                        toolDownloadedPackage.Version.ToNormalizedString(),
                        manifestFile.Value).Green());
            }

            return(0);
        }
Beispiel #3
0
        public override int Execute()
        {
            FilePath?customManifestFileLocation = GetCustomManifestFileLocation();

            FilePath?configFile = null;

            if (_configFilePath != null)
            {
                configFile = new FilePath(_configFilePath);
            }

            IReadOnlyCollection <ToolManifestPackage> packagesFromManifest;

            try
            {
                packagesFromManifest = _toolManifestFinder.Find(customManifestFileLocation);
            }
            catch (ToolManifestCannotFindException e)
            {
                _reporter.WriteLine(e.Message.Yellow());
                return(0);
            }

            Dictionary <RestoredCommandIdentifier, RestoredCommand> dictionary =
                new Dictionary <RestoredCommandIdentifier, RestoredCommand>();

            Dictionary <PackageId, ToolPackageException> toolPackageExceptions =
                new Dictionary <PackageId, ToolPackageException>();
            List <string> errorMessages = new List <string>();

            foreach (var package in packagesFromManifest)
            {
                string targetFramework = BundledTargetFramework.GetTargetFrameworkMoniker();

                try
                {
                    IToolPackage toolPackage =
                        _toolPackageInstaller.InstallPackageToExternalManagedLocation(
                            new PackageLocation(
                                nugetConfig: configFile,
                                additionalFeeds: _sources),
                            package.PackageId, ToVersionRangeWithOnlyOneVersion(package.Version), targetFramework,
                            verbosity: _verbosity);

                    if (!ManifestCommandMatchesActualInPackage(package.CommandNames, toolPackage.Commands))
                    {
                        errorMessages.Add(
                            string.Format(LocalizableStrings.CommandsMismatch,
                                          package.PackageId,
                                          JoinBySpaceWithQuote(toolPackage.Commands.Select(c => c.Name.ToString())),
                                          JoinBySpaceWithQuote(package.CommandNames.Select(c => c.Value.ToString()))));
                    }

                    foreach (RestoredCommand command in toolPackage.Commands)
                    {
                        dictionary.Add(
                            new RestoredCommandIdentifier(
                                toolPackage.Id,
                                toolPackage.Version,
                                NuGetFramework.Parse(targetFramework),
                                "any",
                                command.Name),
                            command);
                    }
                }
                catch (ToolPackageException e)
                {
                    toolPackageExceptions.Add(package.PackageId, e);
                }
            }

            EnsureNoCommandNameCollision(dictionary);

            _localToolsResolverCache.Save(dictionary, _nugetGlobalPackagesFolder);

            if (toolPackageExceptions.Any() || errorMessages.Any())
            {
                var partialOrTotalFailed = dictionary.Count() > 0
                    ? LocalizableStrings.RestorePartiallySuccessful
                    : LocalizableStrings.RestoreFailed;

                _errorReporter.WriteLine(partialOrTotalFailed +
                                         Environment.NewLine +
                                         string.Join(
                                             Environment.NewLine,
                                             CreateErrorMessage(toolPackageExceptions).Concat(errorMessages)));

                return(1);
            }

            return(0);
        }
Beispiel #4
0
        public override int Execute()
        {
            FilePath?customManifestFileLocation = GetCustomManifestFileLocation();

            FilePath?configFile = null;

            if (_configFilePath != null)
            {
                configFile = new FilePath(_configFilePath);
            }

            IReadOnlyCollection <ToolManifestPackage> packagesFromManifest;

            try
            {
                packagesFromManifest = _toolManifestFinder.Find(customManifestFileLocation);
            }
            catch (ToolManifestCannotBeFoundException e)
            {
                _reporter.WriteLine(e.Message.Yellow());
                return(0);
            }

            Dictionary <RestoredCommandIdentifier, RestoredCommand> dictionary =
                new Dictionary <RestoredCommandIdentifier, RestoredCommand>();

            Dictionary <PackageId, ToolPackageException> toolPackageExceptions =
                new Dictionary <PackageId, ToolPackageException>();

            List <string> errorMessages   = new List <string>();
            List <string> successMessages = new List <string>();

            foreach (var package in packagesFromManifest)
            {
                string targetFramework = BundledTargetFramework.GetTargetFrameworkMoniker();

                if (PackageHasBeenRestored(package, targetFramework))
                {
                    successMessages.Add(string.Format(
                                            LocalizableStrings.RestoreSuccessful, package.PackageId,
                                            package.Version.ToNormalizedString(), string.Join(", ", package.CommandNames)));
                    continue;
                }

                try
                {
                    IToolPackage toolPackage =
                        _toolPackageInstaller.InstallPackageToExternalManagedLocation(
                            new PackageLocation(
                                nugetConfig: configFile,
                                additionalFeeds: _sources,
                                rootConfigDirectory: package.FirstEffectDirectory),
                            package.PackageId, ToVersionRangeWithOnlyOneVersion(package.Version), targetFramework,
                            verbosity: _verbosity);

                    if (!ManifestCommandMatchesActualInPackage(package.CommandNames, toolPackage.Commands))
                    {
                        errorMessages.Add(
                            string.Format(LocalizableStrings.CommandsMismatch,
                                          JoinBySpaceWithQuote(package.CommandNames.Select(c => c.Value.ToString())),
                                          package.PackageId,
                                          JoinBySpaceWithQuote(toolPackage.Commands.Select(c => c.Name.ToString()))));
                    }

                    foreach (RestoredCommand command in toolPackage.Commands)
                    {
                        dictionary.Add(
                            new RestoredCommandIdentifier(
                                toolPackage.Id,
                                toolPackage.Version,
                                NuGetFramework.Parse(targetFramework),
                                Constants.AnyRid,
                                command.Name),
                            command);
                    }

                    successMessages.Add(string.Format(
                                            LocalizableStrings.RestoreSuccessful, package.PackageId,
                                            package.Version.ToNormalizedString(), string.Join(" ", package.CommandNames)));
                }
                catch (ToolPackageException e)
                {
                    toolPackageExceptions.Add(package.PackageId, e);
                }
            }

            EnsureNoCommandNameCollision(dictionary);

            _localToolsResolverCache.Save(dictionary, _nugetGlobalPackagesFolder);

            return(PrintConclusionAndReturn(dictionary.Count() > 0, toolPackageExceptions, errorMessages, successMessages));
        }