public void Install(PackageReference tool)
        {
            // Get the tool path.
            var root = _environment.WorkingDirectory.Combine("tools").MakeAbsolute(_environment);

            // Get the installer.
            var installer = _installers.FirstOrDefault(i => i.CanInstall(tool, PackageType.Tool));
            if (installer == null)
            {
                const string format = "Could not find an installer for the '{0}' scheme.";
                var message = string.Format(CultureInfo.InvariantCulture, format, tool.Scheme);
                throw new FrostingException(message);
            }

            // Install the tool.
            var result = installer.Install(tool, PackageType.Tool, root);
            if (result.Count == 0)
            {
                const string format = "Failed to install tool '{0}'.";
                var message = string.Format(CultureInfo.InvariantCulture, format, tool.Package);
                throw new FrostingException(message);
            }

            // Register the tools.
            foreach (var item in result)
            {
                _locator.RegisterFile(item.Path);
            }
        }
Esempio n. 2
0
        public void Install(PackageReference tool)
        {
            // Get the tool path.
            var root = _configuration.GetToolPath(".", _environment);

            // Get the installer.
            var installer = _installers.FirstOrDefault(i => i.CanInstall(tool, PackageType.Tool));

            if (installer == null)
            {
                const string format  = "Could not find an installer for the '{0}' scheme.";
                var          message = string.Format(CultureInfo.InvariantCulture, format, tool.Scheme);
                throw new FrostingException(message);
            }

            // Install the tool.
            _log.Debug("Installing tool '{0}'...", tool.Package);
            var result = installer.Install(tool, PackageType.Tool, root);

            if (result.Count == 0)
            {
                const string format  = "Failed to install tool '{0}'.";
                var          message = string.Format(CultureInfo.InvariantCulture, format, tool.Package);
                throw new FrostingException(message);
            }

            // Register the tools.
            foreach (var item in result)
            {
                _locator.RegisterFile(item.Path);
            }
        }
Esempio n. 3
0
        private void InstallPackages(
            IReadOnlyCollection <PackageReference> modules,
            DirectoryPath installPath,
            PackageType packageType)
        {
            if (packageType != PackageType.Tool && packageType != PackageType.Module)
            {
                throw new ArgumentException("Package is not a tool or a module.", nameof(packageType));
            }

            // Make the installation root absolute.
            installPath = installPath.MakeAbsolute(_environment);

            if (modules.Count > 0)
            {
                var packageTypeName = packageType == PackageType.Tool ? "tool" : "module";

                _log.Verbose($"Installing {packageTypeName}s...");
                foreach (var tool in modules)
                {
                    CheckPackageVersion(tool, packageTypeName);

                    // Get the installer.
                    var installer = GetInstaller(tool, packageType);
                    if (installer == null)
                    {
                        const string format  = "Could not find an installer for the '{0}' scheme.";
                        var          message = string.Format(CultureInfo.InvariantCulture, format, tool.Scheme);
                        throw new CakeException(message);
                    }

                    // Install the module.
                    var result = installer.Install(tool, packageType, installPath);
                    if (result.Count == 0)
                    {
                        var format  = $"Failed to install {packageTypeName} '{{0}}'.";
                        var message = string.Format(CultureInfo.InvariantCulture, format, tool.Package);
                        throw new CakeException(message);
                    }

                    if (packageType == PackageType.Tool)
                    {
                        // Register the tools.
                        foreach (var item in result)
                        {
                            _tools.RegisterFile(item.Path);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Installs the tools specified in the build scripts.
        /// </summary>
        /// <param name="analyzerResult">The analyzer result.</param>
        /// <param name="installPath">The install path.</param>
        public void InstallTools(
            ScriptAnalyzerResult analyzerResult,
            DirectoryPath installPath)
        {
            if (analyzerResult == null)
            {
                throw new ArgumentNullException("analyzerResult");
            }
            if (installPath == null)
            {
                throw new ArgumentNullException("installPath");
            }

            // Make the installation root absolute.
            installPath = installPath.MakeAbsolute(_environment);

            if (analyzerResult.Tools.Count > 0)
            {
                _log.Verbose("Installing tools...");
                foreach (var tool in analyzerResult.Tools)
                {
                    // Get the installer.
                    var installer = GetInstaller(tool, PackageType.Tool);
                    if (installer == null)
                    {
                        const string format  = "Could not find an installer for the '{0}' scheme.";
                        var          message = string.Format(CultureInfo.InvariantCulture, format, tool.Scheme);
                        throw new CakeException(message);
                    }

                    // Install the tool.
                    var result = installer.Install(tool, PackageType.Tool, installPath);
                    if (result.Count == 0)
                    {
                        const string format  = "Failed to install tool '{0}'.";
                        var          message = string.Format(CultureInfo.InvariantCulture, format, tool.Package);
                        throw new CakeException(message);
                    }

                    // Register the tools.
                    foreach (var item in result)
                    {
                        _tools.RegisterFile(item.Path);
                    }
                }
            }
        }