Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (chocolateyGH-1655) make virtual methods for outdated / package service
  (chocolateyGH-1747) Fix: passing timeout switch of 0 is ignored
  (chocolateyGH-1746) Update XML comments / formatting
  (chocolateyGH-1746) update logging for validation
  (chocolateyGH-1038) Stop operation on package reboot request
  (chocolateyGH-1038) Stop execution if pending reboot
  (chocolateyGH-1746) Add concept of global validation
  (maint) Corrected white space
  • Loading branch information
ferventcoder committed Mar 11, 2019
2 parents e0b9a61 + 8822afb commit 2c273d3
Show file tree
Hide file tree
Showing 19 changed files with 883 additions and 145 deletions.
12 changes: 6 additions & 6 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © 2017 - 2018 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
//
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -158,7 +158,7 @@ private static void Main(string[] args)
"chocolatey".Log().Error(ChocolateyLoggers.Important, () => "{0}".format_with(ex.Message));
}

Environment.ExitCode = 1;
if (Environment.ExitCode == 0) Environment.ExitCode = 1;
}
finally
{
Expand Down Expand Up @@ -188,7 +188,7 @@ private static void add_assembly_resolver()
{
var requestedAssembly = new AssemblyName(args.Name);

// There are things that are ILMerged into Chocolatey. Anything with
// There are things that are ILMerged into Chocolatey. Anything with
// the right public key except licensed should use the choco/chocolatey assembly
if (requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
&& !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)
Expand Down
7 changes: 7 additions & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
</Compile>
<Compile Include="AssemblyExtensions.cs" />
<Compile Include="infrastructure.app\commands\ChocolateyInfoCommand.cs" />
<Compile Include="infrastructure.app\validations\GlobalConfigurationValidation.cs" />
<Compile Include="infrastructure.app\configuration\EnvironmentSettings.cs" />
<Compile Include="infrastructure.app\domain\GenericRegistryKey.cs" />
<Compile Include="infrastructure.app\domain\GenericRegistryValue.cs" />
Expand All @@ -120,10 +121,13 @@
<Compile Include="infrastructure.app\domain\RegistryValueExtensions.cs" />
<Compile Include="infrastructure.app\domain\RegistryValueKindType.cs" />
<Compile Include="infrastructure.app\events\HandlePackageResultCompletedMessage.cs" />
<Compile Include="infrastructure.app\services\IPendingRebootService.cs" />
<Compile Include="infrastructure.app\services\PendingRebootService.cs" />
<Compile Include="infrastructure.app\templates\ChocolateyTodoTemplate.cs" />
<Compile Include="infrastructure.app\utility\ArgumentsUtility.cs" />
<Compile Include="infrastructure.app\utility\HashCode.cs" />
<Compile Include="infrastructure.app\utility\PackageUtility.cs" />
<Compile Include="infrastructure.app\validations\SystemStateValidation.cs" />
<Compile Include="infrastructure\filesystem\FileSystem.cs" />
<Compile Include="infrastructure\logging\AggregateLog.cs" />
<Compile Include="infrastructure\logging\LogLevelType.cs" />
Expand Down Expand Up @@ -317,6 +321,9 @@
<Compile Include="infrastructure\tokens\TokenReplacer.cs" />
<Compile Include="ILogExtensions.cs" />
<Compile Include="infrastructure\tolerance\FaultTolerance.cs" />
<Compile Include="infrastructure\validations\IValidation.cs" />
<Compile Include="infrastructure\validations\ValidationResult.cs" />
<Compile Include="infrastructure\validations\ValidationStatus.cs" />
<Compile Include="infrastructure\xml\XmlCData.cs" />
<Compile Include="LogExtensions.cs" />
<Compile Include="ObjectExtensions.cs" />
Expand Down
23 changes: 15 additions & 8 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © 2017 - 2018 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
//
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -33,7 +33,7 @@ public static class ApplicationParameters
#if DEBUG
public static readonly string InstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
public static readonly string LicensedAssemblyLocation = _fileSystem.file_exists(_fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll")) ? _fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll") : _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");

#else
public static readonly string InstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
public static readonly string LicensedAssemblyLocation = _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
Expand Down Expand Up @@ -112,10 +112,10 @@ public static class Environment
public static readonly string[] ConfigFileExtensions = new string[] {".autoconf",".config",".conf",".cfg",".jsc",".json",".jsonp",".ini",".xml",".yaml"};
public static readonly string ConfigFileTransformExtension = ".install.xdt";
public static readonly string[] ShimDirectorFileExtensions = new string[] {".gui",".ignore"};

public static readonly string HashProviderFileTooBig = "UnableToDetectChanges_FileTooBig";
public static readonly string HashProviderFileLocked = "UnableToDetectChanges_FileLocked";

/// <summary>
/// This is a readonly bool set to true. It is only shifted for specs.
/// </summary>
Expand All @@ -127,6 +127,12 @@ public static class Environment
/// </summary>
public static readonly bool AllowPrompts = true;

public static class ExitCodes
{
public static readonly int ErrorFailNoActionReboot = 350;
public static readonly int ErrorInstallSuspend = 1604;
}

public static class Tools
{
//public static readonly string WebPiCmdExe = _fileSystem.combine_paths(InstallLocation, "nuget.exe");
Expand All @@ -145,7 +151,7 @@ public static class ConfigSettings
public static readonly string ProxyBypassOnLocal = "proxyBypassOnLocal";
public static readonly string WebRequestTimeoutSeconds = "webRequestTimeoutSeconds";
}

public static class Features
{
public static readonly string ChecksumFiles = "checksumFiles";
Expand All @@ -171,6 +177,7 @@ public static class Features
public static readonly string SkipPackageUpgradesWhenNotInstalled = "skipPackageUpgradesWhenNotInstalled";
public static readonly string RemovePackageInformationOnUninstall = "removePackageInformationOnUninstall";
public static readonly string LogWithoutColor = "logWithoutColor";
public static readonly string ExitOnRebootDetected = "exitOnRebootDetected";
}

public static class Messages
Expand Down
34 changes: 18 additions & 16 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © 2017 - 2018 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
//
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -210,7 +210,7 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS
config.CacheLocation = Environment.ExpandEnvironmentVariables(set_config_item(ApplicationParameters.ConfigSettings.CacheLocation, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? string.Empty : configFileSettings.CacheLocation, "Cache location if not TEMP folder. Replaces `$env:TEMP` value."));
if (string.IsNullOrWhiteSpace(config.CacheLocation)) {
config.CacheLocation = fileSystem.get_temp_path(); // System.Environment.GetEnvironmentVariable("TEMP");
// TEMP gets set in EnvironmentSettings, so it may already have
// TEMP gets set in EnvironmentSettings, so it may already have
// chocolatey in the path when it installs the next package from
// the API.
if(!String.Equals(fileSystem.get_directory_info_for(config.CacheLocation).Name, "chocolatey", StringComparison.OrdinalIgnoreCase)) {
Expand All @@ -220,7 +220,7 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS

// if it is still empty, use temp in the Chocolatey install directory.
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");

var commandExecutionTimeoutSeconds = 0;
var commandExecutionTimeout = set_config_item(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CommandExecutionTimeoutSeconds.to_string()) ? ApplicationParameters.DefaultWaitForExitInSeconds.to_string() : configFileSettings.CommandExecutionTimeoutSeconds.to_string(), "Default timeout for command execution. '0' for infinite (starting in 0.10.4).");
int.TryParse(commandExecutionTimeout, out commandExecutionTimeoutSeconds);
Expand Down Expand Up @@ -304,6 +304,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile

config.Features.ScriptsCheckLastExitCode = set_feature_flag(ApplicationParameters.Features.ScriptsCheckLastExitCode, configFileSettings, defaultEnabled: false, description: "Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0.");
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
config.Features.ExitOnRebootDetected = set_feature_flag(ApplicationParameters.Features.ExitOnRebootDetected, configFileSettings, defaultEnabled: false, description: "Exit On Reboot Detected - Stop running install, upgrade, or uninstall when a reboot request is detected. Requires '{0}' feature to be turned on. Will exit with either {1} or {2}. When it exits with {1}, it means pending reboot discovered prior to running operation. When it exits with {2}, it means some work completed prior to reboot request being detected. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.12+.".format_with(ApplicationParameters.Features.ExitOnRebootDetected, ApplicationParameters.ExitCodes.ErrorFailNoActionReboot, ApplicationParameters.ExitCodes.ErrorInstallSuspend));
}

private static bool set_feature_flag(string featureName, ConfigFileSettings configFileSettings, bool defaultEnabled, string description)
Expand Down Expand Up @@ -350,7 +351,7 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
option => config.Verbose = option != null)
.Add("trace",
"Trace - Show trace messaging. Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging. Available in 0.10.4+.",
option => config.Trace = option != null)
option => config.Trace = option != null)
.Add("nocolor|no-color",
"No Color - Do not show colorization in logging output. This overrides the feature '{0}', set to '{1}'. Available in 0.10.9+.".format_with(ApplicationParameters.Features.LogWithoutColor, config.Features.LogWithoutColor),
option => config.Features.LogWithoutColor = option != null)
Expand Down Expand Up @@ -378,8 +379,9 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
option =>
{
int timeout = 0;
int.TryParse(option.remove_surrounding_quotes(), out timeout);
if (timeout > 0)
var timeoutString = option.remove_surrounding_quotes();
int.TryParse(timeoutString, out timeout);
if (timeout > 0 || timeoutString.is_equal_to("0"))
{
config.CommandExecutionTimeoutSeconds = timeout;
}
Expand Down Expand Up @@ -413,7 +415,7 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
option => config.Proxy.BypassList = option.remove_surrounding_quotes())
.Add("proxy-bypass-on-local",
"Proxy Bypass On Local - Bypass proxy for local connections. Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy bypass on local setting of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassOnLocal),
option => config.Proxy.BypassOnLocal = option != null)
option => config.Proxy.BypassOnLocal = option != null)
.Add("log-file=",
"Log File to output to in addition to regular loggers. Available in 0.10.8+.",
option => config.AdditionalLogFileLocation= option.remove_surrounding_quotes())
Expand Down Expand Up @@ -472,16 +474,16 @@ the local options are parsed.
(`""value""`) but in powershell.exe you should use backticks
(`` `""value`"" ``) or apostrophes (`'value'`). Using the combination
allows for both shells to work without issue, except for when the next
section applies.
section applies.
* **Pass quotes in arguments**: When you need to pass quoted values to
to something like a native installer, you are in for a world of fun. In
cmd.exe you must pass it like this: `-ia ""/yo=""""Spaces spaces""""""`. In
PowerShell.exe, you must pass it like this: `-ia '/yo=""""Spaces spaces""""'`.
No other combination will work. In PowerShell.exe if you are on version
v3+, you can try `--%` before `-ia` to just pass the args through as is,
which means it should not require any special workarounds.
* **Periods in PowerShell**: If you need to pass a period as part of a
value or a path, PowerShell doesn't always handle it well. Please
* **Periods in PowerShell**: If you need to pass a period as part of a
value or a path, PowerShell doesn't always handle it well. Please
quote those values using ""Quote Values"" section above.
* Options and switches apply to all items passed, so if you are
installing multiple packages, and you use `--version=1.0.0`, choco
Expand Down Expand Up @@ -614,7 +616,7 @@ private static void set_environment_options(ChocolateyConfiguration config)
config.Information.IsUserRemoteDesktop = ProcessInformation.user_is_terminal_services();
config.Information.IsUserRemote = ProcessInformation.user_is_remote();
config.Information.IsProcessElevated = ProcessInformation.process_is_elevated();

if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("https_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location))
{
config.Proxy.Location = Environment.GetEnvironmentVariable("https_proxy");
Expand Down Expand Up @@ -643,7 +645,7 @@ private static void set_licensed_options(ChocolateyConfiguration config, Chocola
if (licensedConfigBuilder == null)
{
if (config.RegularOutput) "chocolatey".Log().Warn(ChocolateyLoggers.Important,
@"Unable to set licensed configuration. Please upgrade to a newer
@"Unable to set licensed configuration. Please upgrade to a newer
licensed version (choco upgrade chocolatey.extension).");
return;
}
Expand Down Expand Up @@ -697,7 +699,7 @@ private static void set_hash_provider(ChocolateyConfiguration config, Container
if (ex.InnerException != null && ex.InnerException.Message.contains("FIPS"))
{
"chocolatey".Log().Warn(ChocolateyLoggers.Important, @"
FIPS Mode detected - run 'choco feature enable -n {0}'
FIPS Mode detected - run 'choco feature enable -n {0}'
to use Chocolatey.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums));

var errorMessage = "When FIPS Mode is enabled, Chocolatey requires {0} feature also be enabled.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums);
Expand Down
Loading

0 comments on commit 2c273d3

Please sign in to comment.