diff --git a/CHANGELOG.md b/CHANGELOG.md index 27465f59..9ea2c9ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change context menu now lists IPM packages from all Git-enabled namespaces, prefixed with the namespace name (#952) - Pull event handler option in settings page now displays user-friendly names for options (#908) - Validation that SSH key file path is not a directory when configuring Embedded Git (#943) +- Customization of IPM load flags using `##class(SourceControl.Git.PullEventHandler.PackageManager).ConfigureLoadFlags(.flags)` (#974) ### Fixed - Changes to % routines mapped to the current namespace may now be added to source control and committed (#944) diff --git a/cls/SourceControl/Git/PullEventHandler/PackageManager.cls b/cls/SourceControl/Git/PullEventHandler/PackageManager.cls index 42c39f87..77a4a6f3 100644 --- a/cls/SourceControl/Git/PullEventHandler/PackageManager.cls +++ b/cls/SourceControl/Git/PullEventHandler/PackageManager.cls @@ -9,10 +9,27 @@ Parameter DESCRIPTION = "Does zpm ""load """; Method OnPull() As %Status { set command = "load "_..LocalRoot + set additionalFlags = ..GetLoadFlags() + if (additionalFlags'="") set command = command _ " " _ additionalFlags quit $select( $$$comClassDefined("%IPM.Main"): ##class(%IPM.Main).Shell(command), 1: ##class(%ZPM.PackageManager).Shell(command) ) } +/// Configures additional flags to be used with zpm "load" by Package Manager pull event handlers +/// Example: to use `zpm "load -DNoMapping=1"` run the following: +/// ``` +/// do ##class(SourceControl.Git.PullEventHandler.PackageManager).ConfigureLoadFlags("-DNoMapping=1") +/// ``` +ClassMethod ConfigureLoadFlags(flags = "") +{ + set @##class(SourceControl.Git.Utils).#Storage@("settings","IPM","loadFlags") = flags +} + +ClassMethod GetLoadFlags() As %String +{ + return $get(@##class(SourceControl.Git.Utils).#Storage@("settings","IPM","loadFlags")) +} + } diff --git a/cls/SourceControl/Git/PullEventHandler/PackageManagerReload.cls b/cls/SourceControl/Git/PullEventHandler/PackageManagerReload.cls index 87cb3f5d..29f480be 100644 --- a/cls/SourceControl/Git/PullEventHandler/PackageManagerReload.cls +++ b/cls/SourceControl/Git/PullEventHandler/PackageManagerReload.cls @@ -1,4 +1,4 @@ -Class SourceControl.Git.PullEventHandler.PackageManagerReload Extends SourceControl.Git.PullEventHandler +Class SourceControl.Git.PullEventHandler.PackageManagerReload Extends SourceControl.Git.PullEventHandler.PackageManager { Parameter NAME = "Package Manager Reload"; @@ -20,11 +20,8 @@ Method OnPull() As %Status ) $$$QuitOnError(sc) } - set command = "load "_..LocalRoot - quit $select( - $$$comClassDefined("%IPM.Main"): ##class(%IPM.Main).Shell(command), - 1: ##class(%ZPM.PackageManager).Shell(command) - ) + /// super class loads the IPM package + return ##super() } } diff --git a/test/UnitTest/SourceControl/Git/PullEventHandler/PackageManagerReload.cls b/test/UnitTest/SourceControl/Git/PullEventHandler/PackageManagerReload.cls new file mode 100644 index 00000000..e063e98b --- /dev/null +++ b/test/UnitTest/SourceControl/Git/PullEventHandler/PackageManagerReload.cls @@ -0,0 +1,40 @@ +/// integration tests for the Package Manager Reload pull event handler +Class UnitTest.SourceControl.Git.PullEventHandler.PackageManagerReload Extends UnitTest.SourceControl.Git.AbstractTest +{ + +Method TestLoadUninstallsThenInstalls() +{ + set testModulePath = ##class(SourceControl.Git.PackageManagerContext).ForInternalName("git-source-control.zpm").Package.Root_"test/_resources/simplest-module" + set pullEventHandler = ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).%New() + set pullEventHandler.LocalRoot = testModulePath + // pull once to install simplest-module + do $$$AssertStatusOK(pullEventHandler.OnPull()) + // pull again to verify uninstall + install + do $$$AssertStatusOK(pullEventHandler.OnPull()) + set history = ##class(%IPM.General.History).GetHistory(,,2) + do $$$AssertTrue(history.%Next()) + do $$$AssertEquals(history.Action,"load") + do $$$AssertTrue(history.%Next()) + do $$$AssertEquals(history.Action,"uninstall") + do $$$AssertEquals(history.CommandString,"uninstall simplest-module") + zpm "uninstall simplest-module" +} + +Method TestLoadUsesConfiguredFlags() +{ + set testModulePath = ##class(SourceControl.Git.PackageManagerContext).ForInternalName("git-source-control.zpm").Package.Root_"test/_resources/simplest-module" + set initFlags = $get(@##class(SourceControl.Git.Utils).#Storage@("settings","IPM","loadFlags")) + set flags = "-DNoMapping=1 -extra-pip-flags ""--timeout 30""" + do ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).ConfigureLoadFlags(flags) + set pullEventHandler = ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).%New() + set pullEventHandler.LocalRoot = testModulePath + do $$$AssertStatusOK(pullEventHandler.OnPull()) + set history = ##class(%IPM.General.History).GetHistory(,,2) + do $$$AssertTrue(history.%Next()) + do $$$AssertEquals(history.Action,"load") + do $$$AssertEquals(history.CommandString, "load "_testModulePath_" -DNoMapping=1 -extra-pip-flags ""--timeout 30""") + zpm "uninstall simplest-module" + do ##class(SourceControl.Git.PullEventHandler.PackageManagerReload).ConfigureLoadFlags(initFlags) +} + +} diff --git a/test/_resources/simplest-module/module.xml b/test/_resources/simplest-module/module.xml new file mode 100644 index 00000000..6fbd0e42 --- /dev/null +++ b/test/_resources/simplest-module/module.xml @@ -0,0 +1,10 @@ + + + + + simplest-module + 1.0.0 + module + + +