Skip to content

Commit 0528427

Browse files
committed
added production baseline to be run after enabling or disabling production decomposition
1 parent 4605a98 commit 0528427

File tree

6 files changed

+123
-62
lines changed

6 files changed

+123
-62
lines changed

cls/SourceControl/Git/API.cls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
6464
quit ##class(SourceControl.Git.Utils).BaselineExport(pCommitMessage, pPushToRemote)
6565
}
6666

67+
/// Run to baseline all interoperability productions in the namespace to source control.
68+
/// This should be done after changing the value of the "decompose productions" setting.
69+
ClassMethod BaselineProductions()
70+
{
71+
do ##class(SourceControl.Git.Util.Production).BaselineProductions()
6772
}
6873

74+
}

cls/SourceControl/Git/Production.cls

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Class SourceControl.Git.Production Extends %RegisteredObject
66

77
/// Exports settings for a given Production and each Config Item from
88
/// the ProductionDefinition as separate XMLs. These are exported to
9-
/// the /ptd subdirectory under the client's ^Sources directory.
10-
ClassMethod ExportProductionDefinitionShards(productionClass As %String, nameMethod As %String) As %Status
9+
/// the appropriate file based on nameMethod of the source control class
10+
ClassMethod ExportProductionDefinitionShards(productionClass As %String, nameMethod As %String, Output internalNames) As %Status
1111
{
12-
// First, export Production definition omitting Config Items
13-
Set sc = ..ExportProductionSettings(productionClass, nameMethod)
12+
Set sc = ..ExportProductionSettings(productionClass, nameMethod, .internalName)
1413
If $$$ISERR(sc) {
1514
Return sc
1615
}
16+
Set internalNames(internalName) = 1
1717

1818
// next, export each item to a separate file
1919
Set rs = ##class(%SQL.Statement).%ExecDirect(,
@@ -25,10 +25,11 @@ ClassMethod ExportProductionDefinitionShards(productionClass As %String, nameMet
2525
Set ptdName = ""
2626
Set item = ##class(Ens.Config.Production).OpenItemByConfigName(productionClass _ "||" _ rs.Name _ "|" _ rs.ClassName)
2727
If $isobject(item) {
28-
Set sc = ..ExportConfigItemSettings(productionClass, item, nameMethod)
28+
Set sc = ..ExportConfigItemSettings(productionClass, item, nameMethod, .internalName)
2929
If $$$ISERR(sc) {
3030
Return sc
3131
}
32+
Set internalNames(internalName) = 1
3233
}
3334
}
3435
Return $$$OK
@@ -102,7 +103,7 @@ ClassMethod ExportPTD(internalName As %String, nameMethod) As %Status
102103

103104
/// Export a single Production Config Item. For a given Ens.Config.Item, the
104105
/// exports the PTD for this item to the file system under the directory specified
105-
ClassMethod ExportConfigItemSettings(productionClass As %String, item As %RegisteredObject, nameMethod As %String) As %Status
106+
ClassMethod ExportConfigItemSettings(productionClass As %String, item As %RegisteredObject, nameMethod As %String, Output internalName As %String) As %Status
106107
{
107108
set internalName = ..CreateInternalName(productionClass, item.Name, item.ClassName, 0)
108109
Set externalName = $ClassMethod($$SrcCtrlCls^%buildccr, nameMethod, internalName)
@@ -116,7 +117,7 @@ ClassMethod ExportConfigItemSettings(productionClass As %String, item As %Regist
116117

117118
/// Exports the Production settings from ProductionDefinition given the Production
118119
/// class name
119-
ClassMethod ExportProductionSettings(productionClass As %String, nameMethod As %String) As %Status
120+
ClassMethod ExportProductionSettings(productionClass As %String, nameMethod As %String, Output internalName As %String) As %Status
120121
{
121122
set internalName = ..CreateInternalName(productionClass,,,1)
122123
Set class = ##class(%Dictionary.CompiledClass).%OpenId(productionClass)

cls/SourceControl/Git/PullEventHandler/IncrementalLoad.cls

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Method DeleteFile(item As %String = "", externalName As %String = "") As %Status
4242
{
4343
set sc = $$$OK
4444
set type = $select(
45-
..ItemIsPTD(externalName): "ptd",
45+
##class(SourceControl.Git.Util.Production).ItemIsPTD(externalName): "ptd",
4646
1: ##class(SourceControl.Git.Utils).Type(item)
4747
)
4848
set name = ##class(SourceControl.Git.Utils).NameWithoutExtension(item)
@@ -51,7 +51,11 @@ Method DeleteFile(item As %String = "", externalName As %String = "") As %Status
5151
if type = "prj" {
5252
set sc = $system.OBJ.DeleteProject(name)
5353
}elseif type = "cls" {
54-
set sc = $system.OBJ.Delete(item)
54+
if settings.decomposeProductions && ##class(SourceControl.Git.Production).IsProductionClass(name, "FullExternalName") {
55+
write !, "Production decomposition enabled, skipping delete of production class"
56+
} else {
57+
set sc = $system.OBJ.Delete(item)
58+
}
5559
}elseif $listfind($listbuild("mac","int","inc","bas","mvb","mvi"), type) > 0 {
5660
set sc = ##class(%Routine).Delete(item)
5761
}elseif type = "csp" {
@@ -82,23 +86,4 @@ Method DeleteFile(item As %String = "", externalName As %String = "") As %Status
8286
return sc
8387
}
8488

85-
/// Determines whether an item has type PTD based on the external name, not reliant on the file existing
86-
ClassMethod ItemIsPTD(externalName) As %Boolean
87-
{
88-
if $zconvert($piece(externalName,".",*),"l") '= "xml" {
89-
return 0
90-
}
91-
set settings = ##class(SourceControl.Git.Settings).%New()
92-
set normFilePath = $replace(externalName,"\","/")
93-
set key = $order($$$SourceMapping("PTD",""))
94-
while (key '= "") {
95-
set directory = $replace($$$SourceMapping("PTD",key), "\","/")
96-
if $find(normFilePath, directory) = ($length(directory) + 1) {
97-
return 1
98-
}
99-
set key = $order($$$SourceMapping("PTD",key))
100-
}
101-
return 0
102-
}
103-
10489
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Include SourceControl.Git
2+
3+
/// Contains utilities for production decomposition that are specific to git-source-control
4+
Class SourceControl.Git.Util.Production
5+
{
6+
7+
/// Baselines all productions in this namespace from single-file to decomposed or vice versa.
8+
ClassMethod BaselineProductions()
9+
{
10+
set st = $$$OK
11+
set settings = ##class(SourceControl.Git.Settings).%New()
12+
set rs = ##class(%Dictionary.ClassDefinition).SubclassOfFunc("Ens.Production")
13+
throw:rs.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(rs.%SQLCODE,rs.%Message)
14+
while rs.%Next(.sc) {
15+
$$$ThrowOnError(sc)
16+
set productionName = rs.Name
17+
set productionInternalName = productionName _ ".cls"
18+
if '##class(SourceControl.Git.Utils).FileIsMapped(productionInternalName) {
19+
if settings.decomposeProductions {
20+
write !, "Decomposing production: " _ productionInternalName
21+
if ##class(SourceControl.Git.Utils).IsInSourceControl(productionInternalName) {
22+
set st = ##class(SourceControl.Git.Utils).RemoveFromSourceControl(productionInternalName)
23+
$$$ThrowOnError(st)
24+
}
25+
set st = ##class(SourceControl.Git.Production).ExportProductionDefinitionShards(productionName,"FullExternalName",.itemInternalNames)
26+
$$$ThrowOnError(st)
27+
set key = $order(itemInternalNames(""))
28+
while (key '= "") {
29+
set st = ##class(SourceControl.Git.Utils).AddToSourceControl(key)
30+
$$$ThrowOnError(st)
31+
set key = $order(itemInternalNames(key))
32+
}
33+
} else {
34+
write !, "Recomposing production: " _ productionInternalName
35+
set st = ##class(SourceControl.Git.Utils).AddToSourceControl(productionInternalName)
36+
$$$ThrowOnError(st)
37+
set key = $order(@##class(SourceControl.Git.Utils).#Storage@("items", ""))
38+
while (key '= "") {
39+
if $match(key,"^"_productionName_"\|\|.*\.(?i)ptd$") {
40+
set st = ##class(SourceControl.Git.Utils).RemoveFromSourceControl(key)
41+
$$$ThrowOnError(st)
42+
}
43+
set key = $order(@##class(SourceControl.Git.Utils).#Storage@("items", key))
44+
}
45+
}
46+
}
47+
}
48+
}
49+
50+
/// Determines whether an item has type PTD based on the external name, not reliant on the file existing
51+
ClassMethod ItemIsPTD(externalName) As %Boolean
52+
{
53+
if $zconvert($piece(externalName,".",*),"l") '= "xml" {
54+
return 0
55+
}
56+
set settings = ##class(SourceControl.Git.Settings).%New()
57+
set normFilePath = $replace(externalName,"\","/")
58+
set key = $order($$$SourceMapping("PTD",""))
59+
while (key '= "") {
60+
set directory = $replace($$$SourceMapping("PTD",key), "\","/")
61+
if $find(normFilePath, directory) = ($length(directory) + 1) {
62+
return 1
63+
}
64+
set key = $order($$$SourceMapping("PTD",key))
65+
}
66+
return 0
67+
}
68+
69+
}

test/UnitTest/SourceControl/Git/PullEventHandler/IncrementalLoad.cls

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Include SourceControl.Git
2+
3+
Class UnitTest.SourceControl.Git.Util.Production Extends %UnitTest.TestCase
4+
{
5+
6+
Property Mappings [ MultiDimensional ];
7+
8+
Method TestItemIsPTD()
9+
{
10+
do $$$AssertNotTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD("cls/test.xml"))
11+
do $$$AssertNotTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD("ptd/test.md"))
12+
do $$$AssertNotTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD(""))
13+
do $$$AssertTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD("ptd/test.xml"))
14+
do $$$AssertTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD("ptd2/test.xml"))
15+
do $$$AssertTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD("ptd2\test.xml"))
16+
}
17+
18+
Method OnBeforeAllTests() As %Status
19+
{
20+
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
21+
kill @##class(SourceControl.Git.Utils).MappingsNode()
22+
set $$$SourceMapping("PTD", "*") = "ptd/"
23+
set $$$SourceMapping("PTD", "Some.Production") = "ptd2/"
24+
quit $$$OK
25+
}
26+
27+
Method %OnClose() As %Status
28+
{
29+
kill @##class(SourceControl.Git.Utils).MappingsNode()
30+
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings
31+
quit $$$OK
32+
}
33+
34+
}

0 commit comments

Comments
 (0)