-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #703 from intersystems/v0.10.x-feat-init-cpf-merge
Feat: CPF Merge
- Loading branch information
Showing
20 changed files
with
352 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Class %IPM.DataType.CustomPhaseName Extends %Library.String [ ClassType = datatype ] | ||
{ | ||
|
||
/// The maximum number of characters the string can contain. | ||
Parameter MAXLEN As INTEGER = 255; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Class %IPM.DataType.PhaseName Extends %Library.String [ ClassType = datatype ] | ||
{ | ||
|
||
/// The maximum number of characters the string can contain. | ||
Parameter MAXLEN As INTEGER = 50; | ||
|
||
/// Used for enumerated (multiple-choice) attributes. | ||
/// <var>VALUELIST</var> is either a null string ("") or a delimiter | ||
/// separated list (where the delimiter is the first character) of logical values. | ||
/// If a non-null value is present, then the attribute is restricted to values | ||
/// in the list, and the validation code simply checks to see if the value is in the list. | ||
Parameter VALUELIST = ",Clean,Initialize,Reload,*,Validate,ExportData,Compile,Activate,Document,MakeDeployed,Test,Package,Verify,Publish,Configure,Unconfigure"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Class %IPM.DataType.PhaseWhen Extends %Library.String [ ClassType = datatype ] | ||
{ | ||
|
||
/// The maximum number of characters the string can contain. | ||
Parameter MAXLEN As INTEGER = 50; | ||
|
||
/// Used for enumerated (multiple-choice) attributes. | ||
/// <var>VALUELIST</var> is either a null string ("") or a delimiter | ||
/// separated list (where the delimiter is the first character) of logical values. | ||
/// If a non-null value is present, then the attribute is restricted to values | ||
/// in the list, and the validation code simply checks to see if the value is in the list. | ||
Parameter VALUELIST = ",Before,After"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Class %IPM.DataType.ResourceDirectory Extends %Library.String [ ClassType = datatype ] | ||
{ | ||
|
||
Parameter MAXLEN = 255; | ||
|
||
/// Tests if the logical value <var>%val</var>, which is a string, is valid. | ||
/// The validation is based on the class parameter settings used for the class attribute this data type is associated with. | ||
/// In this case, <a href="#MINLEN">MINLEN</a>, <a href="#MAXLEN">MAXLEN</a>, <a href="#VALUELIST">VALUELIST</a>, and <a href="#PATTERN">PATTERN</a>. | ||
ClassMethod IsValid(%val As %RawString) As %Status [ ServerOnly = 0 ] | ||
{ | ||
If $Extract(%val) = "/" { | ||
Return $$$ERROR($$$GeneralError, "Resource directory cannot start with a slash.") | ||
} | ||
Set segments = $ListFromString(%val, "/") | ||
Set ptr = 0 | ||
While $ListNext(segments, ptr, seg) { | ||
If seg = ".." { | ||
Return $$$ERROR($$$GeneralError, "For security reasons, resource directory cannot contain '..'.") | ||
} | ||
} | ||
Return $$$OK | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Include %IPM.Formatting | ||
|
||
Class %IPM.ResourceProcessor.CPF Extends (%IPM.ResourceProcessor.Abstract, %IPM.ResourceProcessor.CustomPhaseMixin) | ||
{ | ||
|
||
/// Comma-separated list of resource attribute names that this processor uses | ||
Parameter ATTRIBUTES As STRING = "Name,Directory,Phase,CustomPhase,When"; | ||
|
||
/// Description of resource processor class (shown in UI) | ||
Parameter DESCRIPTION As STRING = "Merges the specified CPF file in the specified lifecycle phase (""Initialize"" by default)."; | ||
|
||
/// Directory containing the CPF file to merge | ||
Property Directory As %IPM.DataType.ResourceDirectory [ InitialExpression = "cpf" ]; | ||
|
||
/// FileN ame of the CPF merge file | ||
Property Name As %IPM.DataType.ResourceName [ Required ]; | ||
|
||
/// The phase before/after which the CPF file should be merged | ||
Property Phase As %IPM.DataType.PhaseName [ InitialExpression = "Initialize" ]; | ||
|
||
/// When to merge the CPF file: Before or After the specified phase. This only applies to the standard phases. | ||
Property When As %IPM.DataType.PhaseWhen [ InitialExpression = "Before" ]; | ||
|
||
Method OnBeforePhase(pPhase As %String, ByRef pParams) As %Status | ||
{ | ||
If (..When = "Before") && (..Phase = pPhase) && (..CustomPhase = "") { | ||
Quit ..DoMerge(.pParams) | ||
} | ||
Quit $$$OK | ||
} | ||
|
||
Method OnAfterPhase(pPhase As %String, ByRef pParams) As %Status | ||
{ | ||
If (..When = "After") && (..Phase = pPhase) && (..CustomPhase = "") { | ||
Quit ..DoMerge(.pParams) | ||
} | ||
Quit $$$OK | ||
} | ||
|
||
Method OnCustomPhase(pCustomPhase As %String, ByRef pParams) As %Status | ||
{ | ||
If (..CustomPhase = pCustomPhase) { | ||
Quit ..DoMerge(.pParams) | ||
} | ||
Quit $$$OK | ||
} | ||
|
||
Method DoMerge(ByRef pParams) As %Status | ||
{ | ||
Try { | ||
Set verbose = $GET(pParams("Verbose")) | ||
Set root = ..ResourceReference.Module.Root | ||
Set sourcesRoot = ..ResourceReference.Module.SourcesRoot | ||
// Use Construct first, rather than NormalizeFilename, so we don't have to deal with leading/trailing slashes | ||
Set dir = $SELECT($$$isWINDOWS: $REPLACE(..Directory, "/", "\"), 1: ..Directory) | ||
Set dir = ##class(%File).Construct(root, sourcesRoot, dir) | ||
Set filename = ##class(%File).NormalizeFilename(..Name, dir) | ||
If (filename = "") || ('##class(%File).Exists(filename)) { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError, $$$FormatText("CPF file '%1' not found in directory '%2'", ..Name, dir))) | ||
} | ||
|
||
Set stream = ##class(%Stream.FileCharacter).%New() | ||
$$$ThrowOnError(stream.LinkToFile(filename)) | ||
If verbose { | ||
Write !, "Merging CPF file: ", filename, ! | ||
Do stream.OutputToDevice() | ||
} | ||
Do ..MergeCPF(filename) | ||
} Catch ex { | ||
Return ex.AsStatus() | ||
} | ||
Return $$$OK | ||
} | ||
|
||
ClassMethod MergeCPF(file As %String) | ||
{ | ||
// TODO The $zf(-100) callout is much slower than ##class(Config.CPF).Merge() | ||
// Figure out why ##class(Config.CPF).Merge() doesn't work | ||
// c.f. https://github.com/intersystems/ipm/pull/703#discussion_r1917290136 | ||
|
||
Set args($INCREMENT(args)) = "merge" | ||
Set args($INCREMENT(args)) = ##class(%SYS.System).GetInstanceName() | ||
Set args($INCREMENT(args)) = file | ||
|
||
// Somehow, if the STDOUT is not set, the merge will silently fail | ||
Set flags = "/SHELL/LOGCMD/STDOUT=""zf100stdout""/STDERR=""zf100stderr""" | ||
Set status = $ZF(-100, flags, "iris", .args) | ||
If status '= 0 { | ||
$$$ThrowStatus($$$ERROR($$$GeneralError, "Error merging CPF file. $zf(-100) exited with "_status)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// Some processors may need to do something custom when a custom phase is executed. | ||
/// Such as the CPF processor, which optionally merges a CPF file during a custom phase. | ||
/// This mixin provides the CustomPhase property and the OnCustomPhase method. | ||
Class %IPM.ResourceProcessor.CustomPhaseMixin | ||
{ | ||
|
||
Property CustomPhase As %IPM.DataType.CustomPhaseName; | ||
|
||
Method OnCustomPhase(pCustomPhase As %String, ByRef pParams) As %Status | ||
{ | ||
Quit $$$OK | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.