Skip to content

Commit 66baa8f

Browse files
authored
Merge branch 'develop' into update-refreshenv
2 parents abd389a + 44c5283 commit 66baa8f

File tree

222 files changed

+5717
-961
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+5717
-961
lines changed

.git-blame-ignore-revs

Lines changed: 480 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
path: tools
4949
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
5050
- name: Test with NUnit on .Net Framework
51-
run: .\build.bat --verbosity=diagnostic --target=test --testExecutionType=all
51+
run: .\build.bat --verbosity=diagnostic --target=test --testExecutionType=all --shouldRunOpenCover=false
5252
- name: Upload Windows build results
5353
uses: actions/upload-artifact@v2
5454
# Always upload build results

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Start with [Prerequisites](#prerequisites) and make sure you can sign the Contri
117117
* `git config merge.ff false`
118118
* `git config merge.log true`
119119
* `git config fetch.prune true`
120+
* `git config blame.ignoreRevsFile .git-blame-ignore-revs --local`
120121
1. From there you create a branch named specific to the feature.
121122
1. In the branch you do work specific to the feature.
122123
1. For committing the code, please see [Prepare Commits](#prepare-commits).

GenerateDocs.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ Chocolatey makes a number of environment variables available (You can access any
489489
* ChocolateyPackageName - The name of the package, equivalent to the `<id />` field in the nuspec (0.9.9+)
490490
* ChocolateyPackageTitle - The title of the package, equivalent to the `<title />` field in the nuspec (0.10.1+)
491491
* ChocolateyPackageVersion - The version of the package, equivalent to the `<version />` field in the nuspec (0.9.9+)
492-
* ChocolateyPackageFolder - The top level location of the package folder - the folder where Chocolatey has downloaded and extracted the NuGet package, typically `C:\ProgramData\chocolatey\lib\packageName`.
493492
494493
#### Advanced Environment Variables
495494
@@ -502,7 +501,7 @@ The following are more advanced settings:
502501
* OS_VERSION - The version of OS, like 6.1 something something for Windows. (0.9.9+)
503502
* OS_NAME - The reported name of the OS. (0.9.9+)
504503
* IS_PROCESSELEVATED = Is the process elevated? (0.9.9+)
505-
* ChocolateyToolsLocation - formerly 'ChocolateyBinRoot' ('ChocolateyBinRoot' will be removed with Chocolatey v2.0.0), this is where tools being installed outside of Chocolatey packaging will go. (0.9.10+)
504+
* ChocolateyPackageInstallLocation - Install location of the software that the package installs. Displayed at the end of the package install. (0.9.10+)
506505
507506
#### Set By Options and Configuration
508507
@@ -533,8 +532,8 @@ The following are experimental or use not recommended:
533532
534533
#### Not Useful Or Anti-Pattern If Used
535534
536-
* ChocolateyInstallOverride = Not for use in package automation scripts. Based on `--override-arguments` being passed. (0.9.9+)
537-
* ChocolateyInstallArguments = The installer arguments meant for the native installer. You should use chocolateyPackageParameters instead. Based on `--install-arguments` being passed. (0.9.9+)
535+
* ChocolateyInstallOverride - Not for use in package automation scripts. Based on `--override-arguments` being passed. (0.9.9+)
536+
* ChocolateyInstallArguments - The installer arguments meant for the native installer. You should use chocolateyPackageParameters instead. Based on `--install-arguments` being passed. (0.9.9+)
538537
* ChocolateyIgnoreChecksums - Was `--ignore-checksums` passed or the feature `checksumFiles` turned off? (0.9.9.9+)
539538
* ChocolateyAllowEmptyChecksums - Was `--allow-empty-checksums` passed or the feature `allowEmptyChecksums` turned on? (0.10.0+)
540539
* ChocolateyAllowEmptyChecksumsSecure - Was `--allow-empty-checksums-secure` passed or the feature `allowEmptyChecksumsSecure` turned on? (0.10.0+)
@@ -551,6 +550,8 @@ The following are experimental or use not recommended:
551550
* http_proxy - Set by original `http_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+)
552551
* https_proxy - Set by original `https_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+)
553552
* no_proxy- Set by original `no_proxy` passthrough, or same as `ChocolateyProxyBypassList` if explicitly set. (0.10.4+)
553+
* ChocolateyPackageFolder - Not for use in package automation scripts. Recommend using `$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"` as per template generated by `choco new`
554+
* ChocolateyToolsLocation - Not for use in package automation scripts. Recommend using Get-ToolsLocation instead
554555
'@
555556

556557
$global:powerShellReferenceTOC | Out-File $fileName -Encoding UTF8 -Force

Invoke-Tests.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ try {
9393
Verbosity = 'Minimal'
9494
}
9595
Filter = @{
96-
ExcludeTag = 'Background', 'Licensed', 'CCM', 'WIP', 'NonAdmin'
96+
ExcludeTag = @(
97+
'Background'
98+
'Licensed'
99+
'CCM'
100+
'WIP'
101+
'NonAdmin'
102+
'Internal'
103+
if (-not $env:VM_RUNNING -and -not $env:TEST_KITCHEN) {
104+
'VMOnly'
105+
}
106+
)
97107
}
98108
}
99109

TESTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ The NUnit tests get run automatically when you run `./build.bat` or `./build.sh`
1414

1515
### NUnit Integration Tests
1616

17-
If you need to run the integration tests, you can do so using: `./build.bat --target=test-nunit --exclusive --testExecutionType=integration`, or `./build.sh --target=test-nunit --exclusive --testExecutionType=integration`.
17+
If you need to run the integration tests, you can do so using: `./build.bat --target=test-nunit --exclusive --testExecutionType=integration --shouldRunOpenCover=false`, or `./build.sh --target=test-nunit --exclusive --testExecutionType=integration --shouldRunOpenCover=false`.
1818

1919
### All NUnit Integration Tests
2020

21-
If you need to run all the tests, you can do so using: `./build.bat --target=test-nunit --exclusive --testExecutionType=all`, or `./build.sh --target=test-nunit --exclusive --testExecutionType=all`.
21+
If you need to run all the tests, you can do so using: `./build.bat --target=test-nunit --exclusive --testExecutionType=all --shouldRunOpenCover=false`, or `./build.sh --target=test-nunit --exclusive --testExecutionType=all --shouldRunOpenCover=false`.
22+
23+
The `shouldRunOpenCover` argument is required when running the integration tests because some of the integration tests rely on the standard output and error output, which is not available when run via OpenCover. This switch changes the NUnit tests to run on NUnit directly, instead of on NUnit via OpenCover.
2224

2325
### Skipping NUnit Tests
2426

nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ param(
288288
$ErrorActionPreference = 'Stop'
289289
try {
290290
# get current acl
291-
$acl = (Get-Item $folder).GetAccessControl('Access,Owner')
291+
$acl = Get-Acl $folder
292292

293293
Write-Debug "Removing existing permissions."
294294
$acl.Access | ForEach-Object { $acl.RemoveAccessRuleAll($_) }
@@ -334,17 +334,17 @@ param(
334334
$acl.SetAccessRuleProtection($true, $false)
335335

336336
# enact the changes against the actual
337-
(Get-Item $folder).SetAccessControl($acl)
337+
Set-Acl -Path $folder -AclObject $acl
338338

339339
# set an explicit append permission on the logs folder
340340
Write-Debug "Allow users to append to log files."
341341
$logsFolder = "$folder\logs"
342342
Create-DirectoryIfNotExists $logsFolder
343-
$logsAcl = (Get-Item $logsFolder).GetAccessControl('Access')
343+
$logsAcl = Get-Acl $logsFolder
344344
$usersAppendAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($builtinUsers, $rightsWrite, [Security.AccessControl.InheritanceFlags]::ObjectInherit, [Security.AccessControl.PropagationFlags]::InheritOnly, "Allow")
345345
$logsAcl.SetAccessRule($usersAppendAccessRule)
346346
$logsAcl.SetAccessRuleProtection($false, $true)
347-
(Get-Item $logsFolder).SetAccessControl($logsAcl)
347+
Set-Acl -Path $logsFolder -AclObject $logsAcl
348348
} catch {
349349
Write-ChocolateyWarning "Not able to set permissions for $folder."
350350
}

recipe.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.13.2
1+
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.16.0
22

33
///////////////////////////////////////////////////////////////////////////////
44
// TOOLS

src/chocolatey.console/Program.cs

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 - 2021 Chocolatey Software, Inc
1+
// Copyright © 2017 - 2022 Chocolatey Software, Inc
22
// Copyright © 2011 - 2017 RealDimensions Software, LLC
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,20 +21,25 @@ namespace chocolatey.console
2121
using System.IO;
2222
using System.Linq;
2323
using System.Reflection;
24+
using chocolatey.infrastructure.information;
2425
using infrastructure.app;
2526
using infrastructure.app.builders;
2627
using infrastructure.app.configuration;
2728
using infrastructure.app.runners;
2829
using infrastructure.commandline;
29-
using infrastructure.configuration;
3030
using infrastructure.extractors;
3131
using infrastructure.licensing;
3232
using infrastructure.logging;
3333
using infrastructure.registration;
3434
using infrastructure.tolerance;
35+
using SimpleInjector;
36+
3537
#if !NoResources
38+
3639
using resources;
40+
3741
#endif
42+
3843
using Assembly = infrastructure.adapters.Assembly;
3944
using Console = System.Console;
4045
using Environment = System.Environment;
@@ -65,11 +70,17 @@ private static void Main(string[] args)
6570

6671
"LogFileOnly".Log().Info(() => "".PadRight(60, '='));
6772

68-
config = Config.get_configuration_settings();
73+
config = container.GetInstance<ChocolateyConfiguration>();
6974
var fileSystem = container.GetInstance<IFileSystem>();
7075

7176
var warnings = new List<string>();
7277

78+
if (license.AssemblyLoaded && !is_licensed_assembly_loaded(container))
79+
{
80+
license.AssemblyLoaded = false;
81+
license.IsCompatible = false;
82+
}
83+
7384
ConfigurationBuilder.set_up_configuration(
7485
args,
7586
config,
@@ -78,7 +89,7 @@ private static void Main(string[] args)
7889
warning => { warnings.Add(warning); }
7990
);
8091

81-
if (license.is_licensed_version() && !license.IsCompatible && !config.DisableCompatibilityChecks)
92+
if (license.AssemblyLoaded && license.is_licensed_version() && !license.IsCompatible && !config.DisableCompatibilityChecks)
8293
{
8394
write_warning_for_incompatible_versions();
8495
}
@@ -91,7 +102,7 @@ private static void Main(string[] args)
91102

92103
if (!string.IsNullOrWhiteSpace(config.AdditionalLogFileLocation))
93104
{
94-
Log4NetAppenderConfiguration.configure_additional_log_file(fileSystem.get_full_path(config.AdditionalLogFileLocation));
105+
Log4NetAppenderConfiguration.configure_additional_log_file(fileSystem.get_full_path(config.AdditionalLogFileLocation));
95106
}
96107

97108
report_version_and_exit_if_requested(args, config);
@@ -137,7 +148,7 @@ private static void Main(string[] args)
137148

138149
remove_old_chocolatey_exe(fileSystem);
139150

140-
AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(Program)), ApplicationParameters.InstallLocation, new List<string>(), "chocolatey.console", throwError:false);
151+
AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(Program)), ApplicationParameters.InstallLocation, new List<string>(), "chocolatey.console", throwError: false);
141152
//refactor - thank goodness this is temporary, cuz manifest resource streams are dumb
142153
IList<string> folders = new List<string>
143154
{
@@ -171,7 +182,7 @@ private static void Main(string[] args)
171182
}
172183
finally
173184
{
174-
if (license != null && license.is_licensed_version() && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks)
185+
if (license != null && license.AssemblyLoaded && license.is_licensed_version() && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks)
175186
{
176187
write_warning_for_incompatible_versions();
177188
}
@@ -186,6 +197,25 @@ private static void Main(string[] args)
186197
}
187198
}
188199

200+
private static bool is_licensed_assembly_loaded(Container container)
201+
{
202+
var allExtensions = container.GetAllInstances<ExtensionInformation>();
203+
204+
foreach (var extension in allExtensions)
205+
{
206+
if (extension.Name.is_equal_to("chocolatey.licensed"))
207+
{
208+
return extension.Status == ExtensionStatus.Enabled || extension.Status == ExtensionStatus.Loaded;
209+
}
210+
}
211+
212+
// We will be going by an assumption that it has been loaded in this case.
213+
// This is mostly to prevent that the licensed extension won't be disabled
214+
// if it has been loaded using old method.
215+
216+
return true;
217+
}
218+
189219
private static void warn_on_nuspec_or_nupkg_usage(string[] args, ChocolateyConfiguration config)
190220
{
191221
var commandLine = Environment.CommandLine;
@@ -196,6 +226,7 @@ private static void warn_on_nuspec_or_nupkg_usage(string[] args, ChocolateyConfi
196226
}
197227

198228
private static ResolveEventHandler _handler = null;
229+
199230
private static void add_assembly_resolver()
200231
{
201232
_handler = (sender, args) =>
@@ -208,8 +239,40 @@ private static void add_assembly_resolver()
208239
var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey;
209240
#endif
210241

242+
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey))
243+
{
244+
// Check if it is already loaded
245+
var resolvedAssembly = AssemblyResolution.resolve_existing_assembly(requestedAssembly.Name, chocolateyPublicKey);
246+
247+
if (resolvedAssembly != null)
248+
{
249+
return resolvedAssembly.UnderlyingType;
250+
}
251+
252+
if (Directory.Exists(ApplicationParameters.ExtensionsLocation))
253+
{
254+
foreach (var extensionDll in Directory.EnumerateFiles(ApplicationParameters.ExtensionsLocation, requestedAssembly.Name + ".dll", SearchOption.AllDirectories))
255+
{
256+
try
257+
{
258+
resolvedAssembly = AssemblyResolution.load_assembly(requestedAssembly.Name, extensionDll, chocolateyPublicKey);
259+
260+
if (resolvedAssembly != null)
261+
{
262+
return resolvedAssembly.UnderlyingType;
263+
}
264+
}
265+
catch (Exception ex)
266+
{
267+
// This catch statement is empty on purpose, we do
268+
// not want to do anything if it fails to load.
269+
}
270+
}
271+
}
272+
}
273+
211274
// There are things that are ILMerged into Chocolatey. Anything with
212-
// the right public key except licensed should use the choco/chocolatey assembly
275+
// the right public key except extensions should use the choco/chocolatey assembly
213276
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey)
214277
&& !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)
215278
&& !requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))

src/chocolatey.console/chocolatey.console.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
<SpecificVersion>False</SpecificVersion>
134134
<HintPath>..\..\lib\Chocolatey-NuGet.Core.2.11.0.20211014\lib\net4\NuGet.Core.dll</HintPath>
135135
</Reference>
136-
<Reference Include="SimpleInjector">
137-
<HintPath>..\packages\SimpleInjector.2.5.0\lib\net40-client\SimpleInjector.dll</HintPath>
136+
<Reference Include="SimpleInjector, Version=2.8.3.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
137+
<HintPath>..\packages\SimpleInjector.2.8.3\lib\net40-client\SimpleInjector.dll</HintPath>
138138
</Reference>
139139
<Reference Include="System" />
140140
<Reference Include="System.ComponentModel.DataAnnotations" />
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
32
<packages>
43
<package id="AlphaFS" version="2.1.3" targetFramework="net40" />
54
<package id="log4net" version="2.0.12" targetFramework="net40" />
65
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net40" />
7-
<package id="SimpleInjector" version="2.5.0" targetFramework="net40" />
6+
<package id="SimpleInjector" version="2.8.3" targetFramework="net40" />
87
</packages>

src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
[switch] $overrideArgs = $false,
55
[alias("x86")][switch] $forceX86 = $false,
66
[alias("params","parameters","pkgParams")][string]$packageParameters = '',
7-
[string]$packageScript
7+
[string]$packageScript,
8+
[string[]]$preRunHookScripts,
9+
[string[]]$postRunHookScripts
810
)
911

1012
$global:DebugPreference = "SilentlyContinue"
@@ -13,7 +15,7 @@ $global:VerbosePreference = "SilentlyContinue"
1315
if ($env:ChocolateyEnvironmentVerbose -eq 'true') { $global:VerbosePreference = "Continue"; $verbosity = $true }
1416

1517
Write-Debug '---------------------------Script Execution---------------------------'
16-
Write-Debug "Running 'ChocolateyScriptRunner' for $($env:packageName) v$($env:packageVersion) with packageScript `'$packageScript`', packageFolder:`'$($env:packageFolder)`', installArguments: `'$installArguments`', packageParameters: `'$packageParameters`',"
18+
Write-Debug "Running 'ChocolateyScriptRunner' for $($env:packageName) v$($env:packageVersion) with packageScript '$packageScript', packageFolder:'$($env:packageFolder)', installArguments: '$installArguments', packageParameters: '$packageParameters', preRunHookScripts: '$preRunHookScripts', postRunHookScripts: '$postRunHookScripts',"
1719

1820
## Set the culture to invariant
1921
$currentThread = [System.Threading.Thread]::CurrentThread;
@@ -45,8 +47,17 @@ $7zip = Join-Path $chocoTools '7z.exe'
4547
$ShimGen = Join-Path $chocoTools 'shimgen.exe'
4648
$checksumExe = Join-Path $chocoTools 'checksum.exe'
4749

48-
Write-Debug "Running `'$packageScript`'";
49-
& "$packageScript"
50+
if ($PSBoundParameters.ContainsKey('preRunHookScripts')) {
51+
foreach ($prehookscript in $preRunHookScripts) {
52+
Write-Debug "Running Pre-Run Hook '$prehookscript'";
53+
& "$prehookscript"
54+
}
55+
}
56+
57+
if ($packageScript) {
58+
Write-Debug "Running package script '$packageScript'";
59+
& "$packageScript"
60+
}
5061
$scriptSuccess = $?
5162
$lastExecutableExitCode = $LASTEXITCODE
5263

@@ -71,6 +82,13 @@ if ($exitCode -ne $null -and $exitCode -ne '' -and $exitCode -ne 0) {
7182
Set-PowerShellExitCode $exitCode
7283
}
7384

85+
if ($PSBoundParameters.ContainsKey('postRunHookScripts')) {
86+
foreach ($posthookscript in $postRunHookScripts) {
87+
Write-Debug "Running Post-Run Hook '$posthookscript'";
88+
& "$posthookscript"
89+
}
90+
}
91+
7492
Write-Debug '----------------------------------------------------------------------'
7593

7694
Exit $exitCode

0 commit comments

Comments
 (0)