Skip to content

Commit

Permalink
Merge pull request #2 from isc-shuliu/master
Browse files Browse the repository at this point in the history
Make zapm compatible with both older and newer version of ZPM
  • Loading branch information
SergeyMi37 authored Jun 10, 2024
2 parents 3b44278 + 0087e76 commit 6bdb3ce
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Resource Name="%ZAPM.ZpmLoad.GBL" />
<UnitTest Name="/unitest/zapm/" Package="ZAPM.unutest.zapm" Phase="verify"/>
<Invokes>
<Invoke Class="%ZAPM.ext.zapp" Method="init"></Invoke>
<Invoke Class="%ZAPM.compat.Compat" Method="CheckCompatibility" Phase="Reload" When="After" />
</Invokes>
</Module>
</Document>
Expand Down
37 changes: 37 additions & 0 deletions preload/cls/_ZAPM/compat/Compat.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Class %ZAPM.compat.Compat
{
/// Will be invoked after Reload and before Compile
ClassMethod CheckCompatibility()
{
Write !, $c(9)_"Checking namespace compatibility..."
If $Namespace '= "%SYS" {
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) {
Return
} ElseIf '##class(%Dictionary.ClassDefinition).%ExistsId(oldClass) {
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 ..GetError("Class "_ classname _" does not exist. Please check your src folder")
}
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)
}

}
20 changes: 0 additions & 20 deletions preload/cls/_ZAPM/ext/Lifecycle.cls

This file was deleted.

2 changes: 1 addition & 1 deletion src/cls/%ZAPM/ext/Lifecycle.cls
Original file line number Diff line number Diff line change
@@ -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 ]
Expand Down

0 comments on commit 6bdb3ce

Please sign in to comment.