Exemplo n.º 1
0
        public ToolInstallLocalInstaller(
            AppliedOption appliedOption,
            IToolPackageInstaller toolPackageInstaller = null)
        {
            if (appliedOption == null)
            {
                throw new ArgumentNullException(nameof(appliedOption));
            }

            _packageId      = new PackageId(appliedOption.Arguments.Single());
            _packageVersion = appliedOption.ValueOrDefault <string>("version");
            _configFilePath = appliedOption.ValueOrDefault <string>("configfile");
            _sources        = appliedOption.ValueOrDefault <string[]>("add-source");
            _verbosity      = appliedOption.SingleArgumentOrDefault("verbosity");

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedOption.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            TargetFrameworkToInstall = BundledTargetFramework.GetTargetFrameworkMoniker();
        }
Exemplo n.º 2
0
        public ToolInstallLocalInstaller(
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller = null)
        {
            _parseResult    = parseResult;
            _packageId      = new PackageId(parseResult.GetValueForArgument(ToolInstallCommandParser.PackageIdArgument));
            _packageVersion = parseResult.GetValueForOption(ToolInstallCommandParser.VersionOption);
            _configFilePath = parseResult.GetValueForOption(ToolInstallCommandParser.ConfigOption);
            _sources        = parseResult.GetValueForOption(ToolInstallCommandParser.AddSourceOption);
            _verbosity      = Enum.GetName(parseResult.GetValueForOption(ToolInstallCommandParser.VerbosityOption));

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: parseResult.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand()));
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            TargetFrameworkToInstall = BundledTargetFramework.GetTargetFrameworkMoniker();
        }
Exemplo n.º 3
0
        public ToolInstallLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault(ToolAppliedOption.ToolManifest);

            _reporter = (reporter ?? Reporter.Output);

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(appliedCommand, toolPackageInstaller);
        }
Exemplo n.º 4
0
        public ToolUpdateLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId            = new PackageId(appliedCommand.Arguments.Single());
            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault(ToolAppliedOption.ToolManifest);

            _reporter = (reporter ?? Reporter.Output);

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedCommand.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(appliedCommand, toolPackageInstaller);
            _toolInstallLocalCommand   = new Lazy <ToolInstallLocalCommand>(
                () => new ToolInstallLocalCommand(
                    appliedCommand,
                    parseResult,
                    _toolPackageInstaller,
                    _toolManifestFinder,
                    _toolManifestEditor,
                    _localToolsResolverCache,
                    _reporter));
        }
Exemplo n.º 5
0
        public ToolInstallLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            DirectoryPath?nugetGlobalPackagesFolder          = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId            = new PackageId(appliedCommand.Arguments.Single());
            _packageVersion       = appliedCommand.ValueOrDefault <string>("version");
            _configFilePath       = appliedCommand.ValueOrDefault <string>("configfile");
            _sources              = appliedCommand.ValueOrDefault <string[]>("add-source");
            _verbosity            = appliedCommand.SingleArgumentOrDefault("verbosity");
            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault("--tool-manifest");

            _reporter = (reporter ?? Reporter.Output);

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedCommand.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _nugetGlobalPackagesFolder =
                nugetGlobalPackagesFolder ?? new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
        }
Exemplo n.º 6
0
        public void WhenRunWithPrereleaseAndPackageVersionItShouldThrow()
        {
            IToolPackageInstaller toolToolPackageInstaller = GetToolToolPackageInstallerWithPreviewInFeed();

            ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --version 2.0 --prerelease");

            var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand(
                result,
                (location, forwardArguments) => (_toolPackageStore, _toolPackageStoreQuery, toolToolPackageInstaller),
                _createShellShimRepository,
                _environmentPathInstructionMock,
                _reporter);

            Action a = () => toolInstallGlobalOrToolPathCommand.Execute();

            a.ShouldThrow <GracefulException>();
        }
Exemplo n.º 7
0
        public ToolRestoreCommand(
            AppliedOption appliedCommand,
            ParseResult result,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            DirectoryPath?nugetGlobalPackagesFolder          = null,
            IReporter reporter = null)
            : base(result)
        {
            _options = appliedCommand ?? throw new ArgumentNullException(nameof(appliedCommand));

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedCommand.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder
                = toolManifestFinder
                  ?? new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));

            _localToolsResolverCache = localToolsResolverCache ??
                                       new LocalToolsResolverCache(
                new FileSystemWrapper(),
                new DirectoryPath(
                    Path.Combine(CliFolderPathCalculator.ToolsResolverCachePath)),
                LocalToolResolverCacheVersion);

            _nugetGlobalPackagesFolder =
                nugetGlobalPackagesFolder ?? new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            _reporter      = reporter ?? Reporter.Output;
            _errorReporter = reporter ?? Reporter.Error;

            _configFilePath = appliedCommand.ValueOrDefault <string>("configfile");
            _sources        = appliedCommand.ValueOrDefault <string[]>("add-source");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");
        }
Exemplo n.º 8
0
        public ToolInstallLocalCommand(
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            _explicitManifestFile = parseResult.ValueForOption <string>(ToolAppliedOption.ToolManifestOptionAlias);

            _reporter = (reporter ?? Reporter.Output);

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(parseResult, toolPackageInstaller);
        }
Exemplo n.º 9
0
        public InstallToolCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageStore toolPackageStore                     = null,
            IToolPackageInstaller toolPackageInstaller             = null,
            IShellShimRepository shellShimRepository               = null,
            IEnvironmentPathInstruction environmentPathInstruction = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId      = new PackageId(appliedCommand.Arguments.Single());
            _packageVersion = appliedCommand.ValueOrDefault <string>("version");
            _configFilePath = appliedCommand.ValueOrDefault <string>("configfile");
            _framework      = appliedCommand.ValueOrDefault <string>("framework");
            _source         = appliedCommand.ValueOrDefault <string>("source");
            _global         = appliedCommand.ValueOrDefault <bool>("global");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");

            var cliFolderPathCalculator = new CliFolderPathCalculator();

            _toolPackageStore = toolPackageStore
                                ?? new ToolPackageStore(new DirectoryPath(cliFolderPathCalculator.ToolsPackagePath));

            _toolPackageInstaller = toolPackageInstaller
                                    ?? new ToolPackageInstaller(
                _toolPackageStore,
                new ProjectRestorer(_reporter));

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();

            _shellShimRepository = shellShimRepository
                                   ?? new ShellShimRepository(new DirectoryPath(cliFolderPathCalculator.ToolsShimPath));

            _reporter      = (reporter ?? Reporter.Output);
            _errorReporter = (reporter ?? Reporter.Error);
        }
Exemplo n.º 10
0
        public ToolUpdateLocalCommand(
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            _packageId            = new PackageId(parseResult.GetValueForArgument(ToolUpdateCommandParser.PackageIdArgument));
            _explicitManifestFile = parseResult.GetValueForOption(ToolUpdateCommandParser.ToolManifestOption);

            _reporter = (reporter ?? Reporter.Output);

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: parseResult.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()));
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(parseResult, toolPackageInstaller);
            _toolInstallLocalCommand   = new Lazy <ToolInstallLocalCommand>(
                () => new ToolInstallLocalCommand(
                    parseResult,
                    _toolPackageInstaller,
                    _toolManifestFinder,
                    _toolManifestEditor,
                    _localToolsResolverCache,
                    _reporter));
        }
Exemplo n.º 11
0
        public ToolRestoreCommand(
            ParseResult result,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IFileSystem fileSystem = null,
            IReporter reporter     = null)
            : base(result)
        {
            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()));
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder
                = toolManifestFinder
                  ?? new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));

            _localToolsResolverCache = localToolsResolverCache ?? new LocalToolsResolverCache();
            _fileSystem = fileSystem ?? new FileSystemWrapper();

            _reporter      = reporter ?? Reporter.Output;
            _errorReporter = reporter ?? Reporter.Error;

            _configFilePath = result.ValueForOption <string>(ToolRestoreCommandParser.ConfigOption);
            _sources        = result.ValueForOption <string[]>(ToolRestoreCommandParser.AddSourceOption);
            _verbosity      = Enum.GetName(result.ValueForOption <VerbosityOptions>(ToolRestoreCommandParser.VerbosityOption));
        }
Exemplo n.º 12
0
        public void WhenRunWithPrereleaseItShouldSucceed()
        {
            IToolPackageInstaller toolToolPackageInstaller = GetToolToolPackageInstallerWithPreviewInFeed();

            ParseResult result = Parser.Instance.Parse($"dotnet tool install -g {PackageId} --prerelease");

            var toolInstallGlobalOrToolPathCommand = new ToolInstallGlobalOrToolPathCommand(
                result,
                (location, forwardArguments) => (_toolPackageStore, _toolPackageStoreQuery, toolToolPackageInstaller),
                _createShellShimRepository,
                _environmentPathInstructionMock,
                _reporter);

            toolInstallGlobalOrToolPathCommand.Execute().Should().Be(0);

            _reporter
            .Lines
            .Should()
            .Contain(l => l == string.Format(
                         LocalizableStrings.InstallationSucceeded,
                         ToolCommandName,
                         PackageId,
                         "2.0.1-preview1").Green());
        }
Exemplo n.º 13
0
        public void GivenOfflineFeedInstallWhenCallWithprereleaseItSucceeds(bool testMockBehaviorIsInSync)
        {
            IToolPackageInstaller   installer   = null;
            IToolPackageUninstaller uninstaller = null;

            if (testMockBehaviorIsInSync == false)
            {
                var testFeedWithOnlyPreviewPackages =
                    Path.Combine(Path.GetTempPath(),
                                 Path.GetRandomFileName());

                Directory.CreateDirectory(testFeedWithOnlyPreviewPackages);
                var tempFeed = GetTestLocalFeedPath();
                File.Copy(Path.Combine(GetTestLocalFeedPath(), "global.tool.console.demo.1.0.4.nupkg"),
                          Path.Combine(testFeedWithOnlyPreviewPackages, "global.tool.console.demo.1.0.4.nupkg"));
                File.Copy(Path.Combine(GetTestLocalFeedPath(), "global.tool.console.demo.2.0.1-preview1.nupkg"),
                          Path.Combine(testFeedWithOnlyPreviewPackages, "global.tool.console.demo.2.0.1-preview1.nupkg"));

                var(store, storeQuery, realInstaller, realUninstaller, reporter, fileSystem) = Setup(
                    useMock: testMockBehaviorIsInSync,
                    offlineFeed: new DirectoryPath(testFeedWithOnlyPreviewPackages),
                    feeds: GetOfflineMockFeed());

                installer   = realInstaller;
                uninstaller = realUninstaller;
            }
            else
            {
                var fileSystem = new FileSystemMockBuilder().Build();
                var root       = new DirectoryPath(_testAssetsManager
                                                   .CreateTestDirectory(nameof(GivenOfflineFeedInstallWhenCallWithprereleaseItSucceeds) +
                                                                        testMockBehaviorIsInSync).Path);
                var toolPackageStoreMock = new ToolPackageStoreMock(root, fileSystem);
                var store      = toolPackageStoreMock;
                var storeQuery = toolPackageStoreMock;
                installer = new ToolPackageInstallerMock(
                    fileSystem: fileSystem,
                    store: toolPackageStoreMock,
                    projectRestorer: new ProjectRestorerMock(
                        fileSystem: fileSystem,
                        reporter: new BufferedReporter(),
                        feeds: new List <MockFeed>
                {
                    new MockFeed
                    {
                        Type     = MockFeedType.ImplicitAdditionalFeed,
                        Packages = new List <MockFeedPackage>
                        {
                            new MockFeedPackage
                            {
                                PackageId       = TestPackageId.ToString(),
                                Version         = "1.0.4",
                                ToolCommandName = "SimulatorCommand"
                            },
                            new MockFeedPackage
                            {
                                PackageId       = TestPackageId.ToString(),
                                Version         = "2.0.1-preview1",
                                ToolCommandName = "SimulatorCommand"
                            }
                        }
                    }
                }));
                uninstaller = new ToolPackageUninstallerMock(fileSystem, toolPackageStoreMock);
            }


            var package = installer.InstallPackage(new PackageLocation(), packageId: TestPackageId,
                                                   versionRange: VersionRange.Parse("*-*"), targetFramework: _testTargetframework);

            package.Version.ToNormalizedString().Should().Be("2.0.1-preview1");

            uninstaller.Uninstall(package.PackageDirectory);

            var package2 = installer.InstallPackage(new PackageLocation(), packageId: TestPackageId,
                                                    versionRange: VersionRange.Parse("2.0*-*"), targetFramework: _testTargetframework);

            package2.Version.ToNormalizedString().Should().Be("2.0.1-preview1");

            uninstaller.Uninstall(package.PackageDirectory);
        }