Skip to content

Commit

Permalink
Merge branch 'develop' into update-refreshenv
Browse files Browse the repository at this point in the history
  • Loading branch information
vexx32 authored Sep 30, 2022
2 parents abd389a + 44c5283 commit 66baa8f
Show file tree
Hide file tree
Showing 222 changed files with 5,717 additions and 961 deletions.
480 changes: 480 additions & 0 deletions .git-blame-ignore-revs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
path: tools
key: ${{ runner.os }}-tools-${{ hashFiles('recipe.cake') }}
- name: Test with NUnit on .Net Framework
run: .\build.bat --verbosity=diagnostic --target=test --testExecutionType=all
run: .\build.bat --verbosity=diagnostic --target=test --testExecutionType=all --shouldRunOpenCover=false
- name: Upload Windows build results
uses: actions/upload-artifact@v2
# Always upload build results
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Start with [Prerequisites](#prerequisites) and make sure you can sign the Contri
* `git config merge.ff false`
* `git config merge.log true`
* `git config fetch.prune true`
* `git config blame.ignoreRevsFile .git-blame-ignore-revs --local`
1. From there you create a branch named specific to the feature.
1. In the branch you do work specific to the feature.
1. For committing the code, please see [Prepare Commits](#prepare-commits).
Expand Down
9 changes: 5 additions & 4 deletions GenerateDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ Chocolatey makes a number of environment variables available (You can access any
* ChocolateyPackageName - The name of the package, equivalent to the `<id />` field in the nuspec (0.9.9+)
* ChocolateyPackageTitle - The title of the package, equivalent to the `<title />` field in the nuspec (0.10.1+)
* ChocolateyPackageVersion - The version of the package, equivalent to the `<version />` field in the nuspec (0.9.9+)
* 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`.
#### Advanced Environment Variables
Expand All @@ -502,7 +501,7 @@ The following are more advanced settings:
* OS_VERSION - The version of OS, like 6.1 something something for Windows. (0.9.9+)
* OS_NAME - The reported name of the OS. (0.9.9+)
* IS_PROCESSELEVATED = Is the process elevated? (0.9.9+)
* 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+)
* ChocolateyPackageInstallLocation - Install location of the software that the package installs. Displayed at the end of the package install. (0.9.10+)
#### Set By Options and Configuration
Expand Down Expand Up @@ -533,8 +532,8 @@ The following are experimental or use not recommended:
#### Not Useful Or Anti-Pattern If Used
* ChocolateyInstallOverride = Not for use in package automation scripts. Based on `--override-arguments` being passed. (0.9.9+)
* ChocolateyInstallArguments = The installer arguments meant for the native installer. You should use chocolateyPackageParameters instead. Based on `--install-arguments` being passed. (0.9.9+)
* ChocolateyInstallOverride - Not for use in package automation scripts. Based on `--override-arguments` being passed. (0.9.9+)
* ChocolateyInstallArguments - The installer arguments meant for the native installer. You should use chocolateyPackageParameters instead. Based on `--install-arguments` being passed. (0.9.9+)
* ChocolateyIgnoreChecksums - Was `--ignore-checksums` passed or the feature `checksumFiles` turned off? (0.9.9.9+)
* ChocolateyAllowEmptyChecksums - Was `--allow-empty-checksums` passed or the feature `allowEmptyChecksums` turned on? (0.10.0+)
* ChocolateyAllowEmptyChecksumsSecure - Was `--allow-empty-checksums-secure` passed or the feature `allowEmptyChecksumsSecure` turned on? (0.10.0+)
Expand All @@ -551,6 +550,8 @@ The following are experimental or use not recommended:
* http_proxy - Set by original `http_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+)
* https_proxy - Set by original `https_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+)
* no_proxy- Set by original `no_proxy` passthrough, or same as `ChocolateyProxyBypassList` if explicitly set. (0.10.4+)
* ChocolateyPackageFolder - Not for use in package automation scripts. Recommend using `$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"` as per template generated by `choco new`
* ChocolateyToolsLocation - Not for use in package automation scripts. Recommend using Get-ToolsLocation instead
'@

$global:powerShellReferenceTOC | Out-File $fileName -Encoding UTF8 -Force
Expand Down
12 changes: 11 additions & 1 deletion Invoke-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,17 @@ try {
Verbosity = 'Minimal'
}
Filter = @{
ExcludeTag = 'Background', 'Licensed', 'CCM', 'WIP', 'NonAdmin'
ExcludeTag = @(
'Background'
'Licensed'
'CCM'
'WIP'
'NonAdmin'
'Internal'
if (-not $env:VM_RUNNING -and -not $env:TEST_KITCHEN) {
'VMOnly'
}
)
}
}

Expand Down
6 changes: 4 additions & 2 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ The NUnit tests get run automatically when you run `./build.bat` or `./build.sh`

### NUnit Integration Tests

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`.
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`.

### All NUnit Integration Tests

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`.
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`.

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.

### Skipping NUnit Tests

Expand Down
8 changes: 4 additions & 4 deletions nuspec/chocolatey/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ param(
$ErrorActionPreference = 'Stop'
try {
# get current acl
$acl = (Get-Item $folder).GetAccessControl('Access,Owner')
$acl = Get-Acl $folder

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

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

# set an explicit append permission on the logs folder
Write-Debug "Allow users to append to log files."
$logsFolder = "$folder\logs"
Create-DirectoryIfNotExists $logsFolder
$logsAcl = (Get-Item $logsFolder).GetAccessControl('Access')
$logsAcl = Get-Acl $logsFolder
$usersAppendAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($builtinUsers, $rightsWrite, [Security.AccessControl.InheritanceFlags]::ObjectInherit, [Security.AccessControl.PropagationFlags]::InheritOnly, "Allow")
$logsAcl.SetAccessRule($usersAppendAccessRule)
$logsAcl.SetAccessRuleProtection($false, $true)
(Get-Item $logsFolder).SetAccessControl($logsAcl)
Set-Acl -Path $logsFolder -AclObject $logsAcl
} catch {
Write-ChocolateyWarning "Not able to set permissions for $folder."
}
Expand Down
2 changes: 1 addition & 1 deletion recipe.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.13.2
#load nuget:?package=Chocolatey.Cake.Recipe&version=0.16.0

///////////////////////////////////////////////////////////////////////////////
// TOOLS
Expand Down
79 changes: 71 additions & 8 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 - 2021 Chocolatey Software, Inc
// Copyright © 2017 - 2022 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,20 +21,25 @@ namespace chocolatey.console
using System.IO;
using System.Linq;
using System.Reflection;
using chocolatey.infrastructure.information;
using infrastructure.app;
using infrastructure.app.builders;
using infrastructure.app.configuration;
using infrastructure.app.runners;
using infrastructure.commandline;
using infrastructure.configuration;
using infrastructure.extractors;
using infrastructure.licensing;
using infrastructure.logging;
using infrastructure.registration;
using infrastructure.tolerance;
using SimpleInjector;

#if !NoResources

using resources;

#endif

using Assembly = infrastructure.adapters.Assembly;
using Console = System.Console;
using Environment = System.Environment;
Expand Down Expand Up @@ -65,11 +70,17 @@ private static void Main(string[] args)

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

config = Config.get_configuration_settings();
config = container.GetInstance<ChocolateyConfiguration>();
var fileSystem = container.GetInstance<IFileSystem>();

var warnings = new List<string>();

if (license.AssemblyLoaded && !is_licensed_assembly_loaded(container))
{
license.AssemblyLoaded = false;
license.IsCompatible = false;
}

ConfigurationBuilder.set_up_configuration(
args,
config,
Expand All @@ -78,7 +89,7 @@ private static void Main(string[] args)
warning => { warnings.Add(warning); }
);

if (license.is_licensed_version() && !license.IsCompatible && !config.DisableCompatibilityChecks)
if (license.AssemblyLoaded && license.is_licensed_version() && !license.IsCompatible && !config.DisableCompatibilityChecks)
{
write_warning_for_incompatible_versions();
}
Expand All @@ -91,7 +102,7 @@ private static void Main(string[] args)

if (!string.IsNullOrWhiteSpace(config.AdditionalLogFileLocation))
{
Log4NetAppenderConfiguration.configure_additional_log_file(fileSystem.get_full_path(config.AdditionalLogFileLocation));
Log4NetAppenderConfiguration.configure_additional_log_file(fileSystem.get_full_path(config.AdditionalLogFileLocation));
}

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

remove_old_chocolatey_exe(fileSystem);

AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(Program)), ApplicationParameters.InstallLocation, new List<string>(), "chocolatey.console", throwError:false);
AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(Program)), ApplicationParameters.InstallLocation, new List<string>(), "chocolatey.console", throwError: false);
//refactor - thank goodness this is temporary, cuz manifest resource streams are dumb
IList<string> folders = new List<string>
{
Expand Down Expand Up @@ -171,7 +182,7 @@ private static void Main(string[] args)
}
finally
{
if (license != null && license.is_licensed_version() && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks)
if (license != null && license.AssemblyLoaded && license.is_licensed_version() && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks)
{
write_warning_for_incompatible_versions();
}
Expand All @@ -186,6 +197,25 @@ private static void Main(string[] args)
}
}

private static bool is_licensed_assembly_loaded(Container container)
{
var allExtensions = container.GetAllInstances<ExtensionInformation>();

foreach (var extension in allExtensions)
{
if (extension.Name.is_equal_to("chocolatey.licensed"))
{
return extension.Status == ExtensionStatus.Enabled || extension.Status == ExtensionStatus.Loaded;
}
}

// We will be going by an assumption that it has been loaded in this case.
// This is mostly to prevent that the licensed extension won't be disabled
// if it has been loaded using old method.

return true;
}

private static void warn_on_nuspec_or_nupkg_usage(string[] args, ChocolateyConfiguration config)
{
var commandLine = Environment.CommandLine;
Expand All @@ -196,6 +226,7 @@ private static void warn_on_nuspec_or_nupkg_usage(string[] args, ChocolateyConfi
}

private static ResolveEventHandler _handler = null;

private static void add_assembly_resolver()
{
_handler = (sender, args) =>
Expand All @@ -208,8 +239,40 @@ private static void add_assembly_resolver()
var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey;
#endif

if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey))
{
// Check if it is already loaded
var resolvedAssembly = AssemblyResolution.resolve_existing_assembly(requestedAssembly.Name, chocolateyPublicKey);

if (resolvedAssembly != null)
{
return resolvedAssembly.UnderlyingType;
}

if (Directory.Exists(ApplicationParameters.ExtensionsLocation))
{
foreach (var extensionDll in Directory.EnumerateFiles(ApplicationParameters.ExtensionsLocation, requestedAssembly.Name + ".dll", SearchOption.AllDirectories))
{
try
{
resolvedAssembly = AssemblyResolution.load_assembly(requestedAssembly.Name, extensionDll, chocolateyPublicKey);

if (resolvedAssembly != null)
{
return resolvedAssembly.UnderlyingType;
}
}
catch (Exception ex)
{
// This catch statement is empty on purpose, we do
// not want to do anything if it fails to load.
}
}
}
}

// There are things that are ILMerged into Chocolatey. Anything with
// the right public key except licensed should use the choco/chocolatey assembly
// the right public key except extensions should use the choco/chocolatey assembly
if (requestedAssembly.get_public_key_token().is_equal_to(chocolateyPublicKey)
&& !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)
&& !requestedAssembly.Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase))
Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey.console/chocolatey.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Chocolatey-NuGet.Core.2.11.0.20211014\lib\net4\NuGet.Core.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector">
<HintPath>..\packages\SimpleInjector.2.5.0\lib\net40-client\SimpleInjector.dll</HintPath>
<Reference Include="SimpleInjector, Version=2.8.3.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\packages\SimpleInjector.2.8.3\lib\net40-client\SimpleInjector.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down
3 changes: 1 addition & 2 deletions src/chocolatey.console/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<packages>
<package id="AlphaFS" version="2.1.3" targetFramework="net40" />
<package id="log4net" version="2.0.12" targetFramework="net40" />
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net40" />
<package id="SimpleInjector" version="2.5.0" targetFramework="net40" />
<package id="SimpleInjector" version="2.8.3" targetFramework="net40" />
</packages>
26 changes: 22 additions & 4 deletions src/chocolatey.resources/helpers/chocolateyScriptRunner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
[switch] $overrideArgs = $false,
[alias("x86")][switch] $forceX86 = $false,
[alias("params","parameters","pkgParams")][string]$packageParameters = '',
[string]$packageScript
[string]$packageScript,
[string[]]$preRunHookScripts,
[string[]]$postRunHookScripts
)

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

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

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

Write-Debug "Running `'$packageScript`'";
& "$packageScript"
if ($PSBoundParameters.ContainsKey('preRunHookScripts')) {
foreach ($prehookscript in $preRunHookScripts) {
Write-Debug "Running Pre-Run Hook '$prehookscript'";
& "$prehookscript"
}
}

if ($packageScript) {
Write-Debug "Running package script '$packageScript'";
& "$packageScript"
}
$scriptSuccess = $?
$lastExecutableExitCode = $LASTEXITCODE

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

if ($PSBoundParameters.ContainsKey('postRunHookScripts')) {
foreach ($posthookscript in $postRunHookScripts) {
Write-Debug "Running Post-Run Hook '$posthookscript'";
& "$posthookscript"
}
}

Write-Debug '----------------------------------------------------------------------'

Exit $exitCode
Loading

0 comments on commit 66baa8f

Please sign in to comment.