diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index c6d94a64f8..a546a87287 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -87,26 +87,6 @@ public static class Messages public static readonly string NugetEventActionHeader = "Nuget called an event"; } - public static class SourceRunner - { - public static readonly string WebPiName = "Web Platform Installer"; - public static readonly string WebPiPackage = "webpicmd"; - public static readonly string WebPiExe = "webpicmd.exe"; - } - - public static class OutputParser - { - public static class WebPi - { - public const string PACKAGE_NAME_GROUP = "PkgName"; - public static readonly Regex Installing =new Regex(@"Started installing:", RegexOptions.Compiled); - public static readonly Regex Installed = new Regex(@"Install completed \(Success\):", RegexOptions.Compiled); - public static readonly Regex AlreadyInstalled = new Regex(@"No products to be installed \(either not available or already installed\)", RegexOptions.Compiled); - //public static readonly Regex NotInstalled = new Regex(@"not installed", RegexOptions.Compiled); - public static readonly Regex PackageName = new Regex(@"'(?<{0}>[^']*)'".format_with(PACKAGE_NAME_GROUP), RegexOptions.Compiled); - } - } - private static T try_get_config(Func func, T defaultValue) { try diff --git a/src/chocolatey/infrastructure.app/services/WebPiService.cs b/src/chocolatey/infrastructure.app/services/WebPiService.cs index 9ae01edd40..02fa1cae95 100644 --- a/src/chocolatey/infrastructure.app/services/WebPiService.cs +++ b/src/chocolatey/infrastructure.app/services/WebPiService.cs @@ -30,8 +30,16 @@ public sealed class WebPiService : ISourceRunner private readonly ICommandExecutor _commandExecutor; private readonly INugetService _nugetService; private const string PACKAGE_NAME_TOKEN = "{{packagename}}"; - private readonly string _exePath = ApplicationParameters.SourceRunner.WebPiExe; - private readonly string _appName = ApplicationParameters.SourceRunner.WebPiName; + private const string EXE_PATH = "webpicmd.exe"; + private const string APP_NAME = "Web Platform Installer"; + public const string WEB_PI_PACKAGE = "webpicmd"; + public const string PACKAGE_NAME_GROUP = "PkgName"; + public static readonly Regex InstallingRegex = new Regex(@"Started installing:", RegexOptions.Compiled); + public static readonly Regex InstalledRegex = new Regex(@"Install completed \(Success\):", RegexOptions.Compiled); + public static readonly Regex AlreadyInstalledRegex = new Regex(@"No products to be installed \(either not available or already installed\)", RegexOptions.Compiled); + //public static readonly Regex NotInstalled = new Regex(@"not installed", RegexOptions.Compiled); + public static readonly Regex PackageNameRegex = new Regex(@"'(?<{0}>[^']*)'".format_with(PACKAGE_NAME_GROUP), RegexOptions.Compiled); + private readonly IDictionary _listArguments = new Dictionary(StringComparer.InvariantCultureIgnoreCase); private readonly IDictionary _installArguments = new Dictionary(StringComparer.InvariantCultureIgnoreCase); @@ -86,7 +94,7 @@ public void ensure_source_app_installed(ChocolateyConfiguration config, Action

list_run(ChocolateyConfiguration config, bool logResults) @@ -128,7 +136,7 @@ public ConcurrentDictionary list_run(ChocolateyConfigurat //var recordingValues = false; Environment.ExitCode = _commandExecutor.execute( - _exePath, + EXE_PATH, args, config.CommandExecutionTimeoutSeconds, workingDirectory: ApplicationParameters.ShimsLocation, @@ -142,7 +150,7 @@ public ConcurrentDictionary list_run(ChocolateyConfigurat } else { - this.Log().Debug(() => "[{0}] {1}".format_with(_appName, logMessage)); + this.Log().Debug(() => "[{0}] {1}".format_with(APP_NAME, logMessage)); } //if (recordingValues) @@ -172,7 +180,7 @@ public void install_noop(ChocolateyConfiguration config, Action c { var args = ExternalCommandArgsBuilder.build_arguments(config, _installArguments); args = args.Replace(PACKAGE_NAME_TOKEN, config.PackageNames.Replace(';', ',')); - this.Log().Info("Would have run '{0} {1}'".format_with(_exePath, args)); + this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH, args)); } public ConcurrentDictionary install_run(ChocolateyConfiguration configuration, Action continueAction) @@ -184,7 +192,7 @@ public ConcurrentDictionary install_run(ChocolateyConfigu { var argsForPackage = args.Replace(PACKAGE_NAME_TOKEN, packageToInstall); var exitCode = _commandExecutor.execute( - _exePath, + EXE_PATH, argsForPackage, configuration.CommandExecutionTimeoutSeconds, ApplicationParameters.ShimsLocation, @@ -192,26 +200,24 @@ public ConcurrentDictionary install_run(ChocolateyConfigu { var logMessage = e.Data; if (string.IsNullOrWhiteSpace(logMessage)) return; - this.Log().Info(() => " [{0}] {1}".format_with(_appName, logMessage)); + this.Log().Info(() => " [{0}] {1}".format_with(APP_NAME, logMessage)); - var packageName = get_value_from_output(logMessage, ApplicationParameters.OutputParser.WebPi.PackageName, ApplicationParameters.OutputParser.WebPi.PACKAGE_NAME_GROUP); + var packageName = get_value_from_output(logMessage, PackageNameRegex, PACKAGE_NAME_GROUP); var results = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, null, null)); - if (ApplicationParameters.OutputParser.WebPi.AlreadyInstalled.IsMatch(logMessage)) + if (AlreadyInstalledRegex.IsMatch(logMessage)) { results.Messages.Add(new ResultMessage(ResultType.Inconclusive, packageName)); - this.Log().Warn(ChocolateyLoggers.Important, " [{0}] {1} already installed or doesn't exist. --force has no effect.".format_with(_appName, string.IsNullOrWhiteSpace(packageName) ? packageToInstall : packageName)); + this.Log().Warn(ChocolateyLoggers.Important, " [{0}] {1} already installed or doesn't exist. --force has no effect.".format_with(APP_NAME, string.IsNullOrWhiteSpace(packageName) ? packageToInstall : packageName)); return; } - if (ApplicationParameters.OutputParser.WebPi.Installing.IsMatch(logMessage)) + if (InstallingRegex.IsMatch(logMessage)) { this.Log().Info(ChocolateyLoggers.Important, "{0}".format_with(packageName)); return; } - //if (string.IsNullOrWhiteSpace(packageName)) return; - - if (ApplicationParameters.OutputParser.WebPi.Installed.IsMatch(logMessage)) + if (InstalledRegex.IsMatch(logMessage)) { this.Log().Info(ChocolateyLoggers.Important, " {0} has been installed successfully.".format_with(string.IsNullOrWhiteSpace(packageName) ? packageToInstall : packageName)); } @@ -219,7 +225,7 @@ public ConcurrentDictionary install_run(ChocolateyConfigu (s, e) => { if (string.IsNullOrWhiteSpace(e.Data)) return; - this.Log().Error(() => "[{0}] {1}".format_with(_appName, e.Data)); + this.Log().Error(() => "[{0}] {1}".format_with(APP_NAME, e.Data)); }, updateProcessPath: false ); @@ -234,23 +240,23 @@ public ConcurrentDictionary install_run(ChocolateyConfigu public ConcurrentDictionary upgrade_noop(ChocolateyConfiguration config, Action continueAction) { - this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement upgrade".format_with(_appName)); + this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement upgrade".format_with(APP_NAME)); return new ConcurrentDictionary(); } public ConcurrentDictionary upgrade_run(ChocolateyConfiguration config, Action continueAction) { - throw new NotImplementedException("{0} does not implement upgrade".format_with(_appName)); + throw new NotImplementedException("{0} does not implement upgrade".format_with(APP_NAME)); } public void uninstall_noop(ChocolateyConfiguration config, Action continueAction) { - this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement uninstall".format_with(_appName)); + this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement uninstall".format_with(APP_NAME)); } public ConcurrentDictionary uninstall_run(ChocolateyConfiguration config, Action continueAction) { - throw new NotImplementedException("{0} does not implement uninstall".format_with(_appName)); + throw new NotImplementedException("{0} does not implement uninstall".format_with(APP_NAME)); } ///