From b7d7a362249629b0326e1ed0062f12078736457c Mon Sep 17 00:00:00 2001 From: Shuheng Liu Date: Mon, 3 Jun 2024 13:14:58 -0400 Subject: [PATCH 1/2] check zpm/ipm compatibility and namespace --- module.xml | 2 +- preload/cls/_ZAPM/compat/Compat.cls | 26 ++++++++++++++++++++++++++ preload/cls/_ZAPM/ext/Lifecycle.cls | 20 -------------------- src/cls/%ZAPM/ext/Lifecycle.cls | 2 +- 4 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 preload/cls/_ZAPM/compat/Compat.cls delete mode 100644 preload/cls/_ZAPM/ext/Lifecycle.cls diff --git a/module.xml b/module.xml index 5a05df0..b145957 100644 --- a/module.xml +++ b/module.xml @@ -18,7 +18,7 @@ - + diff --git a/preload/cls/_ZAPM/compat/Compat.cls b/preload/cls/_ZAPM/compat/Compat.cls new file mode 100644 index 0000000..74e3e5d --- /dev/null +++ b/preload/cls/_ZAPM/compat/Compat.cls @@ -0,0 +1,26 @@ +Class %ZAPM.compat.Compat +{ +/// Will be invoked after Reload and before Compile +ClassMethod CheckCompatibility() +{ + If $Namespace '= "%SYS" { + Throw ##class(%Exception.General).%New("This application must be installed in the ""%SYS"" namespace ") + } + // Some classes have been renamed in IPM (v0.9+). + // The following code will change the class definition to the old class name for backward compatibility + Set oldClass = "%ZPM.PackageManager.Developer.Lifecycle.Module" + Set newClass = "%IPM.Lifecycle.Module" + if ##class(%Dictionary.ClassDefinition).%ExistsId(newClass) { + Return + } ElseIf '##class(%Dictionary.ClassDefinition).%ExistsId(oldClass) { + Throw ##class(%Exception.General).%New("Neither "_oldClass_" nor "_newClass_" exists. Please check your installation of zpm/ipm") + } + set classname = "%zapm.ext.Lifecycle" + set cls = ##class(%Dictionary.ClassDefinition).%OpenId(classname) + if '$IsObject(cls) { + Throw ##class(%Exception.General).%New("Class "_ classname _" does not exist. Please check your src folder") + } + set cls.super = oldClass +} + +} \ No newline at end of file diff --git a/preload/cls/_ZAPM/ext/Lifecycle.cls b/preload/cls/_ZAPM/ext/Lifecycle.cls deleted file mode 100644 index 8197e2b..0000000 --- a/preload/cls/_ZAPM/ext/Lifecycle.cls +++ /dev/null @@ -1,20 +0,0 @@ -Class %ZAPM.ext.Lifecycle Extends %ZPM.PackageManager.Developer.Lifecycle.Module -{ - -ClassMethod RunOnLoad() [ CodeMode = objectgenerator ] -{ - - Set sc = $$$OK - Try { - if $Namespace'="%SYS" { - $$$ThrowOnError($$$ERROR($$$GeneralError,"This application must be installed in the ""%SYS"" namespace ")) - } - ;$$$ThrowOnError($$$ERROR($$$GeneralError,"some error")) - } Catch e { - Set sc = e.AsStatus() - } - Return sc -} - -} - diff --git a/src/cls/%ZAPM/ext/Lifecycle.cls b/src/cls/%ZAPM/ext/Lifecycle.cls index 8197e2b..1d37927 100755 --- a/src/cls/%ZAPM/ext/Lifecycle.cls +++ b/src/cls/%ZAPM/ext/Lifecycle.cls @@ -1,4 +1,4 @@ -Class %ZAPM.ext.Lifecycle Extends %ZPM.PackageManager.Developer.Lifecycle.Module +Class %ZAPM.ext.Lifecycle Extends %IPM.Lifecycle.Module { ClassMethod RunOnLoad() [ CodeMode = objectgenerator ] From 0087e76e52a78a6216e20bd03d58a5b30afae160 Mon Sep 17 00:00:00 2001 From: Shuheng Liu Date: Mon, 3 Jun 2024 16:06:58 -0400 Subject: [PATCH 2/2] fix error in preload script --- preload/cls/_ZAPM/compat/Compat.cls | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/preload/cls/_ZAPM/compat/Compat.cls b/preload/cls/_ZAPM/compat/Compat.cls index 74e3e5d..497bb2d 100644 --- a/preload/cls/_ZAPM/compat/Compat.cls +++ b/preload/cls/_ZAPM/compat/Compat.cls @@ -3,24 +3,35 @@ Class %ZAPM.compat.Compat /// Will be invoked after Reload and before Compile ClassMethod CheckCompatibility() { + Write !, $c(9)_"Checking namespace compatibility..." If $Namespace '= "%SYS" { - Throw ##class(%Exception.General).%New("This application must be installed in the ""%SYS"" namespace ") + Throw ..GetError("This application must be installed in the ""%SYS"" namespace") } + Write " OK!" // Some classes have been renamed in IPM (v0.9+). // The following code will change the class definition to the old class name for backward compatibility + Write !, $c(9)_"Checking package manager version compatibility..." Set oldClass = "%ZPM.PackageManager.Developer.Lifecycle.Module" Set newClass = "%IPM.Lifecycle.Module" - if ##class(%Dictionary.ClassDefinition).%ExistsId(newClass) { + If ##class(%Dictionary.ClassDefinition).%ExistsId(newClass) { Return } ElseIf '##class(%Dictionary.ClassDefinition).%ExistsId(oldClass) { - Throw ##class(%Exception.General).%New("Neither "_oldClass_" nor "_newClass_" exists. Please check your installation of zpm/ipm") + Throw ..GetError("Neither "_oldClass_" nor "_newClass_" exists. Please check your installation of zpm/ipm") } - set classname = "%zapm.ext.Lifecycle" - set cls = ##class(%Dictionary.ClassDefinition).%OpenId(classname) - if '$IsObject(cls) { - Throw ##class(%Exception.General).%New("Class "_ classname _" does not exist. Please check your src folder") + Set classname = "%ZAPM.ext.Lifecycle" + Set cls = ##class(%Dictionary.ClassDefinition).%OpenId(classname) + If '$IsObject(cls) { + Throw ..GetError("Class "_ classname _" does not exist. Please check your src folder") } - set cls.super = oldClass + Set cls.Super = oldClass + $$$ThrowOnError(cls.%Save()) + Write " OK!" +} + +ClassMethod GetError(msg As %String) As %Exception.General [ Internal, Private ] +{ + Write !, "ERROR: ", msg, ! + Return ##class(%Exception.General).%New(msg) } } \ No newline at end of file