Exemplo n.º 1
0
        public void install_noop(ChocolateyConfiguration config, Action <PackageResult> continueAction)
        {
            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(EXE_PATH.escape_curly_braces(), args.escape_curly_braces()));
        }
Exemplo n.º 2
0
        public string build_args(ChocolateyConfiguration config, IDictionary <string, ExternalCommandArgument> argsDictionary)
        {
            var args = ExternalCommandArgsBuilder.build_arguments(config, argsDictionary);

            args = args.Replace(INSTALL_ROOT_TOKEN, _rootDirectory);

            return(args);
        }
            public void should_add_a_parameter_that_does_not_match_the_case_of_the_property_name_when_dictionary_ignores_case()
            {
                IDictionary <string, ExternalCommandArgument> ignoreCaseDictionary = new Dictionary <string, ExternalCommandArgument>(StringComparer.InvariantCultureIgnoreCase);

                ignoreCaseDictionary.Add("sources", new ExternalCommandArgument {
                    ArgumentOption = "-source "
                });
                ExternalCommandArgsBuilder.build_arguments(configuration, ignoreCaseDictionary).ShouldEqual("-source yo");
            }
Exemplo n.º 4
0
        public IEnumerable <PackageResult> list_run(ChocolateyConfiguration config)
        {
            var packageResults = new List <PackageResult>();
            var args           = ExternalCommandArgsBuilder.build_arguments(config, _listArguments);

            //var whereToStartRecording = "---";
            //var whereToStopRecording = "--";
            //var recordingValues = false;

            Environment.ExitCode = _commandExecutor.execute(
                EXE_PATH,
                args,
                config.CommandExecutionTimeoutSeconds,
                workingDirectory: ApplicationParameters.ShimsLocation,
                stdOutAction: (s, e) =>
            {
                var logMessage = e.Data;
                if (string.IsNullOrWhiteSpace(logMessage))
                {
                    return;
                }
                if (!config.QuietOutput)
                {
                    this.Log().Info(e.Data);
                }
                else
                {
                    this.Log().Debug(() => "[{0}] {1}".format_with(APP_NAME, logMessage));
                }

                //if (recordingValues)
                //{
                //    var lineParts = logMessage.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                //    if (lineParts.Length > 1)
                //    {
                //        var pkgResult = new PackageResult(lineParts[0], null, null);
                //        packageResults.GetOrAdd(lineParts[0], pkgResult);
                //    }
                //}

                //if (logMessage.Contains(whereToStartRecording)) recordingValues = true;
            },
                stdErrAction: (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(e.Data))
                {
                    return;
                }
                this.Log().Error(() => "{0}".format_with(e.Data));
            },
                updateProcessPath: false,
                allowUseWindow: true
                );

            return(packageResults);
        }
Exemplo n.º 5
0
        public void install(ChocolateyConfiguration configuration, PackageResult packageResult)
        {
            _fileSystem.create_directory_if_not_exists(ApplicationParameters.ShimsLocation);

            //gather all .exes in the folder
            var exeFiles = _fileSystem.get_files(packageResult.InstallLocation, pattern: "*.exe", option: SearchOption.AllDirectories);

            foreach (string file in exeFiles)
            {
                if (_fileSystem.file_exists(file + ".ignore"))
                {
                    continue;
                }
                bool isGui = _fileSystem.file_exists(file + ".gui");
                //todo: v2 be able to determine gui automatically

                var args           = ExternalCommandArgsBuilder.build_arguments(configuration, _shimGenArguments);
                var shimLocation   = _fileSystem.combine_paths(ApplicationParameters.ShimsLocation, _fileSystem.get_file_name(file));
                var argsForPackage = args.Replace(PATH_TOKEN, file.Replace(ApplicationParameters.InstallLocation, "..\\")).Replace(OUTPUT_TOKEN, shimLocation).Replace(ICON_PATH_TOKEN, file);
                if (isGui)
                {
                    argsForPackage += " --gui";
                }

                var exitCode = _commandExecutor.execute(
                    _shimGenExePath, argsForPackage, configuration.CommandExecutionTimeoutSeconds,
                    (s, e) =>
                {
                    if (string.IsNullOrWhiteSpace(e.Data))
                    {
                        return;
                    }
                    this.Log().Debug(() => " [ShimGen] {0}".format_with(e.Data));
                },
                    (s, e) =>
                {
                    if (string.IsNullOrWhiteSpace(e.Data))
                    {
                        return;
                    }
                    this.Log().Error(() => " [ShimGen] {0}".format_with(e.Data));
                }
                    );

                if (exitCode != 0)
                {
                    Environment.ExitCode = exitCode;
                }
                else
                {
                    this.Log().Info(() => " ShimGen has successfully created a {0}shim for {1}".format_with(isGui ? "gui " : string.Empty, _fileSystem.get_file_name(file)));
                    this.Log().Debug(() => "  Created: {0}{1}  Targeting: {2}{1}  IsGui:{3}{1}".format_with(shimLocation, Environment.NewLine, file, isGui));
                }
            }
        }
Exemplo n.º 6
0
        public string build_args(ChocolateyConfiguration config, IDictionary <string, ExternalCommandArgument> argsDictionary)
        {
            var args = ExternalCommandArgsBuilder.build_arguments(config, argsDictionary);

            args = args.Replace(LOG_LEVEL_TOKEN, config.Debug ? "-vvv" : "");

            if (config.CommandName.is_equal_to("intall"))
            {
                args = args.Replace(FORCE_TOKEN, config.Force ? "--ignore-installed" : "");
            }
            else if (config.CommandName.is_equal_to("upgrade"))
            {
                args = args.Replace(FORCE_TOKEN, config.Force ? "--force-reinstall" : "");
            }
            else
            {
                args = args.Replace(FORCE_TOKEN, "");
            }

            return(args);
        }
Exemplo n.º 7
0
        public IEnumerable <PackageResult> list_run(ChocolateyConfiguration config)
        {
            var packageResults = new List <PackageResult>();
            var args           = ExternalCommandArgsBuilder.build_arguments(config, _listArguments);

            Environment.ExitCode = _commandExecutor.execute(
                EXE_PATH,
                args,
                config.CommandExecutionTimeoutSeconds,
                stdOutAction: (s, e) =>
            {
                var logMessage = e.Data;
                if (string.IsNullOrWhiteSpace(logMessage))
                {
                    return;
                }
                if (!config.QuietOutput)
                {
                    this.Log().Info(logMessage.escape_curly_braces());
                }
                else
                {
                    this.Log().Debug(() => "[{0}] {1}".format_with(APP_NAME, logMessage.escape_curly_braces()));
                }
            },
                stdErrAction: (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(e.Data))
                {
                    return;
                }
                this.Log().Error(() => "{0}".format_with(e.Data.escape_curly_braces()));
            },
                updateProcessPath: false
                );

            return(packageResults);
        }
Exemplo n.º 8
0
        public ConcurrentDictionary <string, PackageResult> list_run(ChocolateyConfiguration config, bool logResults)
        {
            var packageResults = new ConcurrentDictionary <string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
            var args           = ExternalCommandArgsBuilder.build_arguments(config, _listArguments);

            Environment.ExitCode = _commandExecutor.execute(
                EXE_PATH,
                args,
                config.CommandExecutionTimeoutSeconds,
                stdOutAction: (s, e) =>
            {
                var logMessage = e.Data;
                if (string.IsNullOrWhiteSpace(logMessage))
                {
                    return;
                }
                if (logResults)
                {
                    this.Log().Info(e.Data);
                }
                else
                {
                    this.Log().Debug(() => "[{0}] {1}".format_with(APP_NAME, logMessage));
                }
            },
                stdErrAction: (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(e.Data))
                {
                    return;
                }
                this.Log().Error(() => "{0}".format_with(e.Data));
            },
                updateProcessPath: false
                );

            return(packageResults);
        }
Exemplo n.º 9
0
        public string build_args(ChocolateyConfiguration config, IDictionary <string, ExternalCommandArgument> argsDictionary)
        {
            var args = ExternalCommandArgsBuilder.build_arguments(config, argsDictionary);

            // at least Windows 8/2012
            if (config.Information.PlatformVersion.Major >= 6 && config.Information.PlatformVersion.Minor >= 2)
            {
                args = args.Replace(ALL_TOKEN, "/All");
            }
            else
            {
                args = args.Replace(ALL_TOKEN, string.Empty);
            }

            if (!string.IsNullOrWhiteSpace(config.Input))
            {
                args = args.Replace(FEATURES_VALUE, "/Get-FeatureInfo").Replace(FORMAT_VALUE, "/FeatureName:{0}".format_with(config.Input));
            }

            args = args.Replace(LOG_LEVEL_TOKEN, config.Debug ? LOG_LEVEL_DEBUG : LOG_LEVEL_INFO);

            return(args);
        }
Exemplo n.º 10
0
        public ConcurrentDictionary <string, PackageResult> install_run(ChocolateyConfiguration config, Action <PackageResult> continueAction)
        {
            var packageResults = new ConcurrentDictionary <string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
            var args           = ExternalCommandArgsBuilder.build_arguments(config, _installArguments);

            foreach (var packageToInstall in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries))
            {
                var argsForPackage = args.Replace(PACKAGE_NAME_TOKEN, packageToInstall);
                var exitCode       = _commandExecutor.execute(
                    EXE_PATH,
                    argsForPackage,
                    config.CommandExecutionTimeoutSeconds,
                    (s, e) =>
                {
                    var logMessage = e.Data;
                    if (string.IsNullOrWhiteSpace(logMessage))
                    {
                        return;
                    }
                    this.Log().Info(() => " [{0}] {1}".format_with(APP_NAME, logMessage.escape_curly_braces()));

                    if (InstallingRegex.IsMatch(logMessage))
                    {
                        var packageName = get_value_from_output(logMessage, PackageNameFetchingRegex, PACKAGE_NAME_GROUP);
                        var results     = packageResults.GetOrAdd(packageName, new PackageResult(packageName, null, null));
                        this.Log().Info(ChocolateyLoggers.Important, "{0}".format_with(packageName));
                        return;
                    }

                    //if (string.IsNullOrWhiteSpace(packageName)) return;

                    if (InstalledRegex.IsMatch(logMessage))
                    {
                        var packageName = get_value_from_output(logMessage, PackageNameInstalledRegex, PACKAGE_NAME_GROUP);
                        var results     = packageResults.GetOrAdd(packageName, new PackageResult(packageName, null, null));

                        results.Messages.Add(new ResultMessage(ResultType.Note, packageName));
                        this.Log().Info(ChocolateyLoggers.Important, " {0} has been installed successfully.".format_with(string.IsNullOrWhiteSpace(packageName) ? packageToInstall : packageName));
                    }
                },
                    (s, e) =>
                {
                    var logMessage = e.Data;
                    if (string.IsNullOrWhiteSpace(logMessage))
                    {
                        return;
                    }
                    this.Log().Error("[{0}] {1}".format_with(APP_NAME, logMessage.escape_curly_braces()));

                    var packageName = get_value_from_output(logMessage, PackageNameErrorRegex, PACKAGE_NAME_GROUP);

                    if (ErrorNotFoundRegex.IsMatch(logMessage))
                    {
                        var results = packageResults.GetOrAdd(packageName, new PackageResult(packageName, null, null));
                        results.Messages.Add(new ResultMessage(ResultType.Error, packageName));
                    }
                },
                    updateProcessPath: false
                    );

                if (exitCode != 0)
                {
                    Environment.ExitCode = exitCode;
                }
            }

            return(packageResults);
        }
Exemplo n.º 11
0
        public void list_noop(ChocolateyConfiguration config)
        {
            var args = ExternalCommandArgsBuilder.build_arguments(config, _listArguments);

            this.Log().Info("Would have run '{0} {1}'".format_with(EXE_PATH.escape_curly_braces(), args.escape_curly_braces()));
        }
Exemplo n.º 12
0
 public override void Because()
 {
     buildConfigs = () => ExternalCommandArgsBuilder.build_arguments(configuration, argsDictionary);
 }
Exemplo n.º 13
0
        public void install(ChocolateyConfiguration configuration, PackageResult packageResult)
        {
            if (!configuration.Features.UseShimGenService)
            {
                return;
            }

            _fileSystem.create_directory_if_not_exists(ApplicationParameters.ShimsLocation);

            if (packageResult.InstallLocation.is_equal_to(ApplicationParameters.InstallLocation) || packageResult.InstallLocation.is_equal_to(ApplicationParameters.PackagesLocation))
            {
                var logMessage = "Install location is not specific enough, cannot run shimgen:{0} Erroneous install location captured as '{1}'".format_with(Environment.NewLine, packageResult.InstallLocation);
                packageResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage));
                this.Log().Error(logMessage.escape_curly_braces());
                return;
            }

            //gather all .exes in the folder
            var exeFiles = _fileSystem.get_files(packageResult.InstallLocation, pattern: "*.exe", option: SearchOption.AllDirectories);

            foreach (string file in exeFiles.or_empty_list_if_null())
            {
                if (_fileSystem.file_exists(file + ".ignore"))
                {
                    continue;
                }
                bool isGui = _fileSystem.file_exists(file + ".gui");
                //todo: v2 be able to determine gui automatically

                var args           = ExternalCommandArgsBuilder.build_arguments(configuration, _shimGenArguments);
                var shimLocation   = _fileSystem.combine_paths(ApplicationParameters.ShimsLocation, _fileSystem.get_file_name(file));
                var argsForPackage = args.Replace(PATH_TOKEN, file.Replace(ApplicationParameters.InstallLocation, "..\\")).Replace(OUTPUT_TOKEN, shimLocation).Replace(ICON_PATH_TOKEN, file);
                if (isGui)
                {
                    argsForPackage += " --gui";
                }

                var exitCode = _commandExecutor.execute(
                    ApplicationParameters.Tools.ShimGenExe, argsForPackage, configuration.CommandExecutionTimeoutSeconds,
                    (s, e) =>
                {
                    if (string.IsNullOrWhiteSpace(e.Data))
                    {
                        return;
                    }
                    this.Log().Debug(() => " [ShimGen] {0}".format_with(e.Data.escape_curly_braces()));
                },
                    (s, e) =>
                {
                    if (string.IsNullOrWhiteSpace(e.Data))
                    {
                        return;
                    }
                    this.Log().Error(() => " [ShimGen] {0}".format_with(e.Data.escape_curly_braces()));
                },
                    updateProcessPath: true
                    );

                if (exitCode != 0)
                {
                    Environment.ExitCode = exitCode;
                }
                else
                {
                    this.Log().Info(() => " ShimGen has successfully created a {0}shim for {1}".format_with(isGui ? "gui " : string.Empty, _fileSystem.get_file_name(file)));
                    this.Log().Debug(() => "  Created: {0}{1}  Targeting: {2}{1}  IsGui:{3}{1}".format_with(shimLocation, Environment.NewLine, file, isGui));
                }
            }
        }
Exemplo n.º 14
0
        public ConcurrentDictionary <string, PackageResult> install_run(ChocolateyConfiguration configuration, Action <PackageResult> continueAction)
        {
            var packageInstalls = new ConcurrentDictionary <string, PackageResult>();

            var args = ExternalCommandArgsBuilder.build_arguments(configuration, _webPiInstallArguments);

            foreach (var packageToInstall in configuration.PackageNames.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var argsForPackage = args.Replace(PACKAGE_NAME_TOKEN, packageToInstall);
                var exitCode       = _commandExecutor.execute(
                    _webPiExePath, argsForPackage, configuration.CommandExecutionTimeoutSeconds,
                    (s, e) =>
                {
                    var logMessage = e.Data;
                    if (string.IsNullOrWhiteSpace(logMessage))
                    {
                        return;
                    }
                    this.Log().Debug(() => " [WebPI] {0}".format_with(logMessage));

                    var packageName    = get_value_from_output(logMessage, ApplicationParameters.OutputParser.Nuget.PackageName, ApplicationParameters.OutputParser.Nuget.PACKAGE_NAME_GROUP);
                    var packageVersion = get_value_from_output(logMessage, ApplicationParameters.OutputParser.Nuget.PackageVersion, ApplicationParameters.OutputParser.Nuget.PACKAGE_VERSION_GROUP);

                    if (ApplicationParameters.OutputParser.Nuget.ResolvingDependency.IsMatch(logMessage))
                    {
                        return;
                    }

                    var results = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, packageVersion, _webPiInstallArguments["_output_directory_"].ArgumentValue));

                    if (ApplicationParameters.OutputParser.Nuget.NotInstalled.IsMatch(logMessage))
                    {
                        this.Log().Error("{0} not installed: {1}".format_with(packageName, logMessage));
                        results.Messages.Add(new ResultMessage(ResultType.Error, logMessage));

                        return;
                    }

                    if (ApplicationParameters.OutputParser.Nuget.Installing.IsMatch(logMessage))
                    {
                        return;
                    }

                    if (string.IsNullOrWhiteSpace(packageName))
                    {
                        return;
                    }

                    this.Log().Info(ChocolateyLoggers.Important, "{0} {1}".format_with(packageName, !string.IsNullOrWhiteSpace(packageVersion) ? "v" + packageVersion : string.Empty));

                    if (ApplicationParameters.OutputParser.Nuget.AlreadyInstalled.IsMatch(logMessage) && !configuration.Force)
                    {
                        results.Messages.Add(new ResultMessage(ResultType.Inconclusive, packageName));
                        this.Log().Warn(" Already installed.");
                        this.Log().Warn(ChocolateyLoggers.Important, " Use -force if you want to reinstall.".format_with(Environment.NewLine));
                        return;
                    }

                    results.Messages.Add(new ResultMessage(ResultType.Debug, ApplicationParameters.Messages.ContinueChocolateyAction));
                    if (continueAction != null)
                    {
                        continueAction.Invoke(results);
                    }
                },
                    (s, e) =>
                {
                    if (string.IsNullOrWhiteSpace(e.Data))
                    {
                        return;
                    }
                    this.Log().Error(() => "{0}".format_with(e.Data));
                },
                    updateProcessPath: false
                    );

                if (exitCode != 0)
                {
                    Environment.ExitCode = exitCode;
                }
            }
            return(packageInstalls);
        }