Skip to content

Commit

Permalink
Merge pull request #2831 from AdmiringWorm/deprecate-old-run-host
Browse files Browse the repository at this point in the history
(#1185) Add original powershell host run as deprecated method
  • Loading branch information
corbob committed Sep 24, 2022
2 parents 3892cfb + 96b9ebe commit d08d1f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
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 Down Expand Up @@ -68,6 +68,10 @@ public interface IPowershellService
bool before_modify(ChocolateyConfiguration configuration, PackageResult packageResult);

void prepare_powershell_environment(IPackage package, ChocolateyConfiguration configuration, string packageDirectory);

[Obsolete("This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead")]
PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript);

PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript, IEnumerable<string> hookPreScriptPathList, IEnumerable<string> hookPostScriptPathList);
}
}
21 changes: 12 additions & 9 deletions src/chocolatey/infrastructure.app/services/PowershellService.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 @@ -23,10 +23,7 @@ namespace chocolatey.infrastructure.app.services
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using adapters;
using builders;
using commandline;
using configuration;
using cryptography;
Expand All @@ -38,8 +35,6 @@ namespace chocolatey.infrastructure.app.services
using powershell;
using results;
using utility;
using Assembly = adapters.Assembly;
using Console = System.Console;
using CryptoHashProvider = cryptography.CryptoHashProvider;
using Environment = System.Environment;
using IFileSystem = filesystem.IFileSystem;
Expand Down Expand Up @@ -112,12 +107,15 @@ private IEnumerable<string> get_hook_scripts(ChocolateyConfiguration configurati
case CommandNameType.install:
filenameBase += "install-";
break;

case CommandNameType.uninstall:
filenameBase += "uninstall-";
break;

case CommandNameType.upgrade:
filenameBase += "beforemodify-";
break;

default:
throw new ApplicationException("Could not find CommandNameType '{0}' to get hook scripts".format_with(command));
}
Expand Down Expand Up @@ -353,7 +351,6 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
`choco -h` for details.");
}


if (result.ExitCode != 0)
{
Environment.ExitCode = result.ExitCode;
Expand Down Expand Up @@ -534,7 +531,7 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura
}
}

SecurityProtocol.set_protocol(configuration, provideWarning:false);
SecurityProtocol.set_protocol(configuration, provideWarning: false);
}

private ResolveEventHandler _handler = null;
Expand Down Expand Up @@ -593,6 +590,12 @@ private void remove_assembly_resolver()
}
}

[Obsolete("This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead")]
public PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowershellScript, Action<Pipeline> additionalActionsBeforeScript)
{
return run_host(config, chocoPowershellScript, additionalActionsBeforeScript, Enumerable.Empty<string>(), Enumerable.Empty<string>());
}

public PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript, IEnumerable<string> hookPreScriptPathList, IEnumerable<string> hookPostScriptPathList)
{
// since we control output in the host, always set these true
Expand Down Expand Up @@ -732,11 +735,11 @@ public PowerShellExecutionResults run_host(ChocolateyConfiguration config, strin
if (host.ExitCode == 0) host.SetShouldExit(1);
host.HostException = pipeline.PipelineStateInfo.Reason;
break;

case PipelineState.Completed:
if (host.ExitCode == -1) host.SetShouldExit(0);
break;
}

}
}
}
Expand Down

0 comments on commit d08d1f6

Please sign in to comment.