Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: CPF Merge #703

Merged
merged 36 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a9938d5
feat: implement an `intialize` lifecycle phase
isc-shuliu Jan 13, 2025
2e53f8f
feat: implement the CPF resource processor
isc-shuliu Jan 13, 2025
d3462df
chore: update changelog
isc-shuliu Jan 13, 2025
c2f9a7e
test: add test case for CPF merge
isc-shuliu Jan 13, 2025
9418f0b
refactor: modernize the code in %Initialize lifecycle
isc-shuliu Jan 14, 2025
56f4b33
refactor: change code based on feedback
isc-shuliu Jan 14, 2025
e580764
refactor: remove preloading in `LoadNewModule` but keep in `%Reload`
isc-shuliu Jan 14, 2025
9e083ea
fix: move preload from %Reload into %Initialize
isc-shuliu Jan 14, 2025
6f7c6cd
refactor: move cpf merge to before preload
isc-shuliu Jan 14, 2025
15bb05a
feat: implement CPF merge
isc-shuliu Jan 15, 2025
a8671c2
test: update cpf test cases
isc-shuliu Jan 15, 2025
a40a7e1
fix: fix incorrect file extension casing in integration test
isc-shuliu Jan 15, 2025
e7c7c12
test: typo fix
isc-shuliu Jan 15, 2025
0f5b5ba
fix: use $zf(-100) instead of Config.CPF:Merge as a workaround
isc-shuliu Jan 15, 2025
2d3eac7
test: re-add the test case for roles creation
isc-shuliu Jan 15, 2025
65bddb7
test: add more test cases for CPF merge
isc-shuliu Jan 15, 2025
b34b001
refactor: create datatypes for `Phase`, `When` and `CustomPhase`
isc-shuliu Jan 16, 2025
a651785
feat: allow running CPF before/after any phase
isc-shuliu Jan 16, 2025
cc34aa0
Merge branch 'v0.10.x' into v0.10.x-feat-init-cpf-merge
isc-shuliu Jan 21, 2025
83898eb
feat: phases with capital letters in the middle aren't all custom phases
isc-shuliu Jan 21, 2025
8ea47d5
feat: support CPF merge in custom phases
isc-shuliu Jan 21, 2025
77face7
test: adjust test cases for cpf merge during different phases
isc-shuliu Jan 21, 2025
37c9641
chore: update changelog about breaking compatibility with preload
isc-shuliu Jan 22, 2025
91baf3c
fix: fix a bug causing unconfigure to contain a trialing space
isc-shuliu Jan 22, 2025
280505e
refactor: unify error reporting for nonexistent CPF resource
isc-shuliu Jan 22, 2025
c6c680c
docs: improve documentation for CPF resource processor
isc-shuliu Jan 22, 2025
1b74d17
fix(ci): fix a bug in CI where $system is expanded in heredoc
isc-shuliu Jan 22, 2025
ddd5d47
refactor: add OnCustomPhase to Abstract ResourceProcessor
isc-shuliu Jan 22, 2025
687f1da
refactor: allow more versatile custom phase handling
isc-shuliu Jan 23, 2025
6818598
refactor: move custom phase props & methods to a mixin class
isc-shuliu Jan 23, 2025
dfe545a
fix(ci): bump version of upload artifact
isc-shuliu Jan 23, 2025
b8fc645
fix: check whether resource processors exists before using it
isc-shuliu Jan 23, 2025
70170b2
Merge branch 'v0.10.x' into v0.10.x-feat-init-cpf-merge
isc-shuliu Jan 23, 2025
51e9a50
fix: catch up fix
isc-shuliu Jan 23, 2025
94be840
feat: omit CustomPhase property in CPF processor which is inherited
isc-shuliu Jan 29, 2025
e2af5aa
Merge branch 'v0.10.x' into v0.10.x-feat-init-cpf-merge
isc-shuliu Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #582 Added functionality to optionally see time of last update and server version of each package
- #609 Added support for `-export-deps` when running the "Package" phase of lifecycle
- #541 Added support for ORAS repository
- #702 Added a new lifecycle phase `Initialize` which supports merging the new `<CPF/>` resource.

### Changed
-
Expand Down
40 changes: 30 additions & 10 deletions src/cls/IPM/Lifecycle/Base.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Property PhaseList As %List;

/// $ListBuild list of phases in this lifecycle. <br />
/// For each phase name, an instance method named "%<phase name>" must be defined in the class with a return type of %Status.
Parameter PHASES = {$ListBuild("Clean","Reload","*","Validate","ExportData","Compile","Activate","Document","MakeDeployed","Test","Package","Verify", "Publish", "Configure","Unconfigure")};
Parameter PHASES = {$ListBuild("Clean","Initialize", "Reload","*","Validate","ExportData","Compile","Activate","Document","MakeDeployed","Test","Package","Verify", "Publish", "Configure","Unconfigure")};

Property Payload As %Stream.Object [ Private ];

Expand Down Expand Up @@ -138,18 +138,19 @@ ClassMethod GetCompletePhasesForOne(pOnePhase As %String) As %List

Quit $Case(pOnePhase,
"clean": $ListBuild("Clean"),
"reload": $ListBuild("Reload","*"),
"validate": $ListBuild("Reload","*","Validate"),
"initialize": $ListBuild("Initialize"),
"reload": $ListBuild("Initialize","Reload","*"),
"validate": $ListBuild("Initialize","Reload","*","Validate"),
"exportdata": $ListBuild("ExportData"),
"compile": $ListBuild("Reload","*","Validate","Compile"),
"activate": $ListBuild("Reload","*","Validate","Compile","Activate"),
"compile": $ListBuild("Initialize","Reload","*","Validate","Compile"),
"activate": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate"),
"document": $ListBuild("Document"),
"makedeployed": $ListBuild("MakeDeployed"),
"test": $ListBuild("Reload","*","Validate","Compile","Activate","Test"),
"package": $ListBuild("Reload","*","Validate","Compile","Activate","Package"),
"verify": $ListBuild("Reload","*","Validate","Compile","Activate","Package","Verify"),
"register": $ListBuild("Reload","*","Validate","Compile","Activate","Package","Register"),
"publish": $ListBuild("Reload","*","Validate","Compile","Activate","Package","Register","Publish"),
"test": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Test"),
"package": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package"),
"verify": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package","Verify"),
"register": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package","Register"),
"publish": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package","Register","Publish"),
"configure": $ListBuild("Configure"),
"unconfigure": $ListBuild("Unconfigure"),
: ""
Expand All @@ -162,6 +163,7 @@ ClassMethod MatchSinglePhase(pOnePhase As %String) As %String
Set phase = $ZCONVERT(pOnePhase, "L")
Quit $Case(phase,
"clean": "Clean",
"initialize": "Initialize",
"reload": "Reload",
"validate": "Validate",
"exportdata": "ExportData",
Expand Down Expand Up @@ -501,6 +503,24 @@ Method %Unconfigure(ByRef pParams) As %Status
Quit tSC
}

Method %Initialize(ByRef pParams) As %Status
{
Set tSC = $$$OK
Try {
Set tKey = ""
For {
Set tResource = ..Module.Resources.GetNext(.tKey)
Quit:tKey=""
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
If $IsObject(tResource.Processor) && ($CLASSNAME(tResource.Processor) = "%IPM.ResourceProcessor.CPF") {
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Set tSC = $$$ADDSC(tSC,tResource.Processor.OnPhase("Initialize",.pParams))
}
}
} Catch ex {
Set tSC = ex.AsStatus()
}
Quit tSC
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
}

Method %Reload(ByRef pParams) As %Status
{
Set tSC = $$$OK
Expand Down
51 changes: 51 additions & 0 deletions src/cls/IPM/ResourceProcessor/CPF.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Class %IPM.ResourceProcessor.CPF Extends %IPM.ResourceProcessor.Abstract
{

/// Comma-separated list of resource attribute names that this processor uses
Parameter ATTRIBUTES As STRING = "Path";

/// Description of resource processor class (shown in UI)
Parameter DESCRIPTION As STRING = "Merges the specified CPF file in the ""Initialize"" lifecycle phase.";
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved

Property Path As %String(MAXLEN = "");
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved

/// Called as phase <var>pPhase</var> is executed for the resource. If <var>pResourceHandled</var> is set to true,
/// then the default behavior for that resource will be bypassed in the current phase.
/// Currently, this is only used in the Verify phase, because of different handling of intermediate error statuses.
/// TODO: Implement for standard database resources (.INC, .CLS, etc.)
Method OnPhase(pPhase As %String, ByRef pParams, Output pResourceHandled As %Boolean = 0) As %Status
{
Set verbose = $Get(pParams("Verbose"))
Set status = $$$OK
Try {
If pPhase '= "Initialize" {
Quit
}

If '$Data(pParams("RootDirectory"), root) {
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
$$$ThrowStatus($$$ERROR($$$GeneralError, "RootDirectory unspecified"))
}
// Use Construct first, rather than NormalizeFilename, so we don't have to deal with leading/trailing slashes
Set filename = ##class(%File).Construct(root, ..Path)
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Set filename = ##class(%File).NormalizeFilename(filename)

Set stream = ##class(%Stream.FileCharacter).%New()
$$$ThrowOnError(stream.LinkToFile(filename))
If verbose {
Write !, "Merging CPF file: ", filename, !
While 'stream.AtEnd {
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Write stream.Read()
}
}
// TODO actually merge the CPF file
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
// ...

Set pResourceHandled = 1
} Catch ex {
Set pResourceHandled = 0
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Set status = ex.AsStatus()
}
Return status
}

}
16 changes: 16 additions & 0 deletions tests/integration_tests/Test/PM/Integration/CPFMerge.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Class Test.PM.Integration.CPFMerge Extends Test.PM.Integration.Base
{

Parameter TargetModuleName As STRING = "cpf-merge";

Method TestCPFMerge()
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
{
Set tModuleDir = ..GetModuleDir(..#TargetModuleName)

Set tSC = ##class(%IPM.Main).Shell("load -v "_tModuleDir)
Do $$$AssertStatusOK(tSC, "Loaded module successfully")

// TODO - Add more tests here
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[config]
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
globals=0,0,150000,0,0,0
gmheap=393,216
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Document name="cpf-merge.ZPM">
<Module>
<Name>cpf-merge</Name>
<Version>0.0.1</Version>
<Packaging>module</Packaging>
<CPF Path="/Merge.CPF"/>
</Module>
</Document>
</Export>
Loading