Skip to content

Commit d08d1f6

Browse files
authored
Merge pull request chocolatey#2831 from AdmiringWorm/deprecate-old-run-host
(chocolatey#1185) Add original powershell host run as deprecated method
2 parents 3892cfb + 96b9ebe commit d08d1f6

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/chocolatey/infrastructure.app/services/IPowershellService.cs

Lines changed: 5 additions & 1 deletion
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");
@@ -68,6 +68,10 @@ public interface IPowershellService
6868
bool before_modify(ChocolateyConfiguration configuration, PackageResult packageResult);
6969

7070
void prepare_powershell_environment(IPackage package, ChocolateyConfiguration configuration, string packageDirectory);
71+
72+
[Obsolete("This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead")]
73+
PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript);
74+
7175
PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript, IEnumerable<string> hookPreScriptPathList, IEnumerable<string> hookPostScriptPathList);
7276
}
7377
}

src/chocolatey/infrastructure.app/services/PowershellService.cs

Lines changed: 12 additions & 9 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");
@@ -23,10 +23,7 @@ namespace chocolatey.infrastructure.app.services
2323
using System.Management.Automation;
2424
using System.Management.Automation.Runspaces;
2525
using System.Reflection;
26-
using System.Security.Cryptography;
27-
using System.Text;
2826
using adapters;
29-
using builders;
3027
using commandline;
3128
using configuration;
3229
using cryptography;
@@ -38,8 +35,6 @@ namespace chocolatey.infrastructure.app.services
3835
using powershell;
3936
using results;
4037
using utility;
41-
using Assembly = adapters.Assembly;
42-
using Console = System.Console;
4338
using CryptoHashProvider = cryptography.CryptoHashProvider;
4439
using Environment = System.Environment;
4540
using IFileSystem = filesystem.IFileSystem;
@@ -112,12 +107,15 @@ private IEnumerable<string> get_hook_scripts(ChocolateyConfiguration configurati
112107
case CommandNameType.install:
113108
filenameBase += "install-";
114109
break;
110+
115111
case CommandNameType.uninstall:
116112
filenameBase += "uninstall-";
117113
break;
114+
118115
case CommandNameType.upgrade:
119116
filenameBase += "beforemodify-";
120117
break;
118+
121119
default:
122120
throw new ApplicationException("Could not find CommandNameType '{0}' to get hook scripts".format_with(command));
123121
}
@@ -353,7 +351,6 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
353351
`choco -h` for details.");
354352
}
355353

356-
357354
if (result.ExitCode != 0)
358355
{
359356
Environment.ExitCode = result.ExitCode;
@@ -534,7 +531,7 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura
534531
}
535532
}
536533

537-
SecurityProtocol.set_protocol(configuration, provideWarning:false);
534+
SecurityProtocol.set_protocol(configuration, provideWarning: false);
538535
}
539536

540537
private ResolveEventHandler _handler = null;
@@ -593,6 +590,12 @@ private void remove_assembly_resolver()
593590
}
594591
}
595592

593+
[Obsolete("This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead")]
594+
public PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowershellScript, Action<Pipeline> additionalActionsBeforeScript)
595+
{
596+
return run_host(config, chocoPowershellScript, additionalActionsBeforeScript, Enumerable.Empty<string>(), Enumerable.Empty<string>());
597+
}
598+
596599
public PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript, IEnumerable<string> hookPreScriptPathList, IEnumerable<string> hookPostScriptPathList)
597600
{
598601
// since we control output in the host, always set these true
@@ -732,11 +735,11 @@ public PowerShellExecutionResults run_host(ChocolateyConfiguration config, strin
732735
if (host.ExitCode == 0) host.SetShouldExit(1);
733736
host.HostException = pipeline.PipelineStateInfo.Reason;
734737
break;
738+
735739
case PipelineState.Completed:
736740
if (host.ExitCode == -1) host.SetShouldExit(0);
737741
break;
738742
}
739-
740743
}
741744
}
742745
}

0 commit comments

Comments
 (0)