private ModulesInstallationLocation GetModuleInstallationLocation(PackageReference package) { if (package.GetSwitch("global")) { return(ModulesInstallationLocation.Global); } if (package.GetSwitch("caketools")) { return(ModulesInstallationLocation.Tools); } return(ModulesInstallationLocation.Workdir); }
/// <summary> /// Installs the specified resource. /// </summary> /// <param name="package">The package resource.</param> /// <param name="type">The package type.</param> /// <param name="path">The location where to install the resource.</param> /// <returns>The installed files.</returns> public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path) { if (package == null) { throw new ArgumentNullException(nameof(package)); } // find npm _log.Debug("looking for npm.cmd"); var npmTool = _toolLocator.Resolve("npm.cmd"); if (npmTool == null) { _log.Debug("looking for npm"); npmTool = _toolLocator.Resolve("npm"); } if (npmTool == null) { throw new FileNotFoundException("npm could not be found."); } _log.Debug("Found npm at {0}", npmTool); // Install the package. _log.Debug("Installing package {0} with npm...", package.Package); var process = _processRunner.Start( npmTool.FullPath, new ProcessSettings { Arguments = GetArguments(package, _config), RedirectStandardOutput = true, Silent = _log.Verbosity < Verbosity.Diagnostic }); process.WaitForExit(); var exitCode = process.GetExitCode(); if (exitCode != 0) { _log.Warning("npm exited with {0}", exitCode); var output = string.Join(Environment.NewLine, process.GetStandardOutput()); _log.Verbose(Verbosity.Diagnostic, "Output:\r\n{0}", output); } var result = _contentResolver.GetFiles(package, type, package.GetSwitch("global")); if (result.Count != 0) { return(result); } _log.Warning("Could not determine installed package files! Installation may not be complete."); // TODO: maybe some warnings here return(result); }
/// <summary> /// Gets the arguments to invoke apt-get for the current install. /// </summary> /// <param name="definition">The package definition to install.</param> /// <param name="config">The current configuration.</param> /// <returns>Process arguments for apt-get.</returns> public ProcessArgumentBuilder GetArguments( PackageReference definition, ICakeConfiguration config) { var arguments = new ProcessArgumentBuilder(); arguments.Append("install"); arguments.Append("-y"); var packageString = new StringBuilder(definition.Package); // if an absolute uri is specified for source, use this // otherwise check config for customise package source/s if (definition.Address != null) { _log.Warning("APT does not support installing direct from a source address!"); _log.Warning("Add this source to your `sources.list` and use the `release` parameter."); }/* else { * var aptSource = config.GetValue(Constants.APTSource); * if (!string.IsNullOrWhiteSpace(aptSource)) * { * arguments.Append($"--repofrompath=\"{definition.Package},{aptSource}\""); * arguments.Append($"--repo={definition.Package}"); * } * } */ if (_log.Verbosity == Verbosity.Verbose || _log.Verbosity == Verbosity.Diagnostic) { arguments.Append("--verbose"); } if (definition.GetSwitch("install-suggested")) { arguments.Append("--install-suggests"); } if (definition.Parameters.ContainsKey("release")) { arguments.Append($"-t={definition.Parameters["release"].First()}"); } // Version if (definition.Parameters.ContainsKey("version")) { packageString.Append($"={definition.Parameters["version"].First()}"); } if (definition.Parameters.ContainsKey("dist")) { packageString.Append($"/{definition.Parameters["dist"].First()}"); } arguments.Append(packageString.ToString()); return(arguments); }
private ProcessArgumentBuilder GetArguments( PackageReference definition, ICakeConfiguration config) { var arguments = new ProcessArgumentBuilder(); arguments.Append("install"); arguments.Append("-y"); var packageString = new StringBuilder(definition.Package); // if an absolute uri is specified for source, use this // otherwise check config for customise package source/s if (definition.Address != null) { arguments.Append($"--repofrompath=\"{definition.Package},{definition.Address.AbsoluteUri}\""); arguments.Append($"--repo={definition.Package}"); } else { var dnfSource = config.GetValue("DNF_Source"); if (!string.IsNullOrWhiteSpace(dnfSource)) { arguments.Append($"--repofrompath=\"{definition.Package},{dnfSource}\""); arguments.Append($"--repo={definition.Package}"); } } if (_log.Verbosity == Verbosity.Verbose || _log.Verbosity == Verbosity.Diagnostic) { arguments.Append("--verbose"); } if (definition.GetSwitch("best")) { arguments.Append("--best"); } // Version if (definition.Parameters.ContainsKey("version")) { packageString.Append($"-{definition.Parameters["version"].First()}"); } if (definition.Parameters.ContainsKey("arch")) { packageString.Append($".{definition.Parameters["arch"].First()}"); } arguments.Append(packageString.ToString()); return(arguments); }
private ProcessArgumentBuilder GetArguments( PackageReference definition, ICakeConfiguration config) { var arguments = new ProcessArgumentBuilder(); arguments.Append("install"); if (_log.Verbosity == Verbosity.Verbose || _log.Verbosity == Verbosity.Diagnostic) { arguments.Append("--verbose"); } if (definition.Address != null) { arguments.Append($"--registry \"{definition.Address}\""); } else { var npmSource = config.GetValue(Constants.ConfigKey); if (!string.IsNullOrWhiteSpace(npmSource)) { arguments.Append($"--registry \"{npmSource}\""); } } if (definition.GetSwitch("force")) { arguments.Append("--force"); } if (definition.GetSwitch("global")) { arguments.Append("--global"); } if (definition.GetSwitch("ignore-scripts")) { arguments.Append("--ignore-scripts"); } if (definition.GetSwitch("no-optional")) { arguments.Append("--no-optional"); } if (definition.GetSwitch("save")) { GetSaveArguments(arguments, definition); } var packageString = new StringBuilder(); if (definition.HasValue("source", out string source)) { packageString.Append(source.Trim(':') + ":"); } if (definition.HasValue("scope", out string scope)) { packageString.Append("@" + scope.Trim('@') + "/"); } packageString.Append(definition.Package); if (definition.HasValue("version", out string version)) { packageString.Append(("@" + version.Trim(':', '=', '@')).Quote()); } arguments.Append(packageString.ToString()); return(arguments); }