Skip to content

Commit ac21833

Browse files
author
Steve Ives
committed
Added repository override feature. Initially restricted to suppressing keys from structures.
1 parent 8651016 commit ac21833

File tree

8 files changed

+215
-10
lines changed

8 files changed

+215
-10
lines changed

CodeGen/CodeGen.dbl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,25 @@ proc
422422
endusing
423423
end
424424

425+
;;-------------------------------------------------------------------------
426+
;;Do we have a repository override file specified on the command line?
427+
428+
if (ok && CommandLineParser.Parse("rpsoverride",ClValues))
429+
begin
430+
using ClValues.Count select
431+
(1),
432+
begin
433+
task.RepositoryOverrideFile = ClValues[0]
434+
end
435+
(),
436+
begin
437+
Console.WriteLine("ERROR: One repository override file spec must follow the -rpsoverride option!")
438+
ok = false
439+
exitCode = 1
440+
end
441+
endusing
442+
end
443+
425444
;;-------------------------------------------------------------------------
426445
;;Do we have a custom data mappings file specified?
427446

CodeGenEngine/CodeGenEngine.synproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
<Compile Include="PrimaryKeyField.dbl" />
172172
<Compile Include="ProcessSelectionWindows.dbl" />
173173
<Compile Include="Properties\AssemblyInfo.dbl" />
174+
<Compile Include="RepositoryOverride.dbl" />
174175
<Compile Include="RepositoryTools.dbl" />
175176
<Compile Include="StringTools.dbl" />
176177
<Compile Include="Token.dbl" />

CodeGenEngine/CodeGenTask.dbl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ namespace CodeGen.Engine
336336
;;; </summary>
337337
public readwrite property RepositoryTextFile, String, String.Empty
338338

339+
;;; <summary>
340+
;;; Repository text file to use.
341+
;;; </summary>
342+
public readwrite property RepositoryOverrideFile, String, String.Empty
343+
339344
;;; <summary>
340345
;;; Window script selection list processing. When this option is used CodeGen will examine
341346
;;; any fields which have selection windows specified and will attempt to populate the field

CodeGenEngine/CodeGenerator.dbl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ namespace CodeGen.Engine
728728
if (tplfiles.Length == 0)
729729
errStatus = context.CurrentTask.ErrorLog(string.Format("No templates found in template folder {0}", context.TemplateFolder))
730730
end
731+
731732
;;-------------------------------------------------------------------------
732733
;;See if we have an output location specified with CODEGEN_OUTDIR
733734
;;If present, this location overrides the default location (current dir)
@@ -1464,6 +1465,19 @@ namespace CodeGen.Engine
14641465
end
14651466
end
14661467

1468+
;;-------------------------------------------------------------------------
1469+
;;Do we have a repoository customization file in the template folder?
1470+
;;If so then apply the overrides to the repository.
1471+
;;Right now this only allows keys to be excluded but in future we plan to support customizing anything in repository.
1472+
1473+
if (!errStatus)
1474+
begin
1475+
if (!String.IsNullOrWhiteSpace(context.CurrentTask.RepositoryOverrideFile))
1476+
begin
1477+
errStatus = RepositoryOverride.ApplyOverrides(context)
1478+
end
1479+
end
1480+
14671481
;;-------------------------------------------------------------------------
14681482
;;Are we being asked to process a user defined token file?
14691483

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
;;*****************************************************************************
2+
;;
3+
;; Title: RepositoryOverride.dbl
4+
;;
5+
;; Description: Classes and tools to apply repository overrides based on a
6+
;; metadata in a JSON file.
7+
;;
8+
;; Date: 15th January 2020
9+
;;
10+
;; Author: Steve Ives, Synergex Professional Services Group
11+
;; http://www.synergex.com
12+
;;
13+
;;*****************************************************************************
14+
;;
15+
;; Copyright (c) 2020, Synergex International, Inc.
16+
;; All rights reserved.
17+
;;
18+
;; Redistribution and use in source and binary forms, with or without
19+
;; modification, are permitted provided that the following conditions are met:
20+
;;
21+
;; * Redistributions of source code must retain the above copyright notice,
22+
;; this list of conditions and the following disclaimer.
23+
;;
24+
;; * Redistributions in binary form must reproduce the above copyright notice,
25+
;; this list of conditions and the following disclaimer in the documentation
26+
;; and/or other materials provided with the distribution.
27+
;;
28+
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29+
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30+
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31+
;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
32+
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33+
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34+
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35+
;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36+
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37+
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38+
;; POSSIBILITY OF SUCH DAMAGE.
39+
;;
40+
;;*****************************************************************************
41+
42+
import System
43+
import System.Collections
44+
import System.Collections.Generic
45+
import System.IO
46+
import System.Linq
47+
import System.Text
48+
import CodeGen.RepositoryAPI
49+
import Newtonsoft.Json
50+
51+
namespace CodeGen.Engine
52+
53+
public static class RepositoryOverride
54+
55+
public static method ApplyOverrides, boolean
56+
required inout context, @CodeGenContext
57+
proc
58+
data errStatus = false
59+
60+
data overrides, @OverrideRepository
61+
62+
;;Override files must be in the templates folder
63+
data overrideFile = Path.Combine(context.TemplateFolder,context.CurrentTask.RepositoryOverrideFile)
64+
65+
;;Does the override file exist?
66+
if (File.Exists(overrideFile)) then
67+
begin
68+
;;Read and de-serialize the override file
69+
70+
data jsonData = File.ReadAllText(overrideFile)
71+
72+
try
73+
begin
74+
overrides = JsonConvert.DeserializeObject<OverrideRepository>(jsonData)
75+
end
76+
catch (e, @Exception)
77+
begin
78+
errStatus = context.CurrentTask.ErrorLog("Failed to read or deserialize repository override file " + overrideFile + "!")
79+
end
80+
endtry
81+
end
82+
else
83+
begin
84+
errStatus = context.CurrentTask.ErrorLog("Repository override file " + overrideFile + " not found!")
85+
end
86+
87+
if (!errStatus)
88+
begin
89+
;;Do we have override structures?
90+
data ostr, @OverrideStructure
91+
if (overrides.Structures == ^null) then
92+
begin
93+
errStatus = context.CurrentTask.ErrorLog("Repository override file contains no structures!")
94+
end
95+
else
96+
begin
97+
;;Iterate through the override structures
98+
foreach ostr in overrides.Structures
99+
begin
100+
;;Find the matching repository structure in the repository
101+
data str, @RpsStructure, context.Repository.Structures.FirstOrDefault(lambda(s) { s.Name == ostr.Name })
102+
if (str == ^null) then
103+
begin
104+
errStatus = context.CurrentTask.ErrorLog("Repository override file structure " + ostr.Name + " not found in repository!")
105+
exitloop
106+
end
107+
else
108+
begin
109+
;;Do we have excluded keys?
110+
if (ostr.ExcludeKeys != ^null)
111+
begin
112+
;;Iterate through the excluded keys
113+
data excludedKeyName, string
114+
foreach excludedKeyName in ostr.ExcludeKeys
115+
begin
116+
;;Find the matching repository key in the repository structure
117+
data key, @RpsKey, str.Keys.FirstOrDefault(lambda(k) { k.Name == excludedKeyName })
118+
if (key == ^null) then
119+
begin
120+
errStatus = context.CurrentTask.ErrorLog("Repository override file key " + ostr.Name + "." + excludedKeyName + " not found in repository structure " + ostr.Name + "!")
121+
exitloop
122+
end
123+
else
124+
begin
125+
;;And remove it
126+
str.Keys.Remove(key)
127+
128+
;;Is the structure selected for processing in this task?
129+
data str2, @RpsStructure, context.Structures.FirstOrDefault(lambda(s) { s.Name == ostr.Name })
130+
if (str2 != ^null)
131+
begin
132+
;;Find the matching repository key in the repository structure
133+
key = str2.Keys.FirstOrDefault(lambda(k) { k.Name == excludedKeyName })
134+
str2.Keys.Remove(key)
135+
end
136+
end
137+
end
138+
end
139+
end
140+
end
141+
end
142+
end
143+
144+
mreturn errStatus
145+
146+
endmethod
147+
148+
;
149+
; {
150+
; "Structures": [
151+
; {
152+
; "Name": "STR1",
153+
; "ExcludeKeys": [ "KEY1", "KEY2" ]
154+
; },
155+
; {
156+
; "Name": "STR2",
157+
; "ExcludeKeys": [ "KEY1", "KEY2" ]
158+
; }
159+
; ]
160+
; }
161+
;
162+
163+
private class OverrideRepository
164+
public readwrite property Structures, @IEnumerable<OverrideStructure>
165+
endclass
166+
167+
private class OverrideStructure
168+
public readwrite property Name, string
169+
public readwrite property ExcludeKeys, [#]string
170+
endclass
171+
172+
endclass
173+
174+
175+
endnamespace

Documentation/CodeGen.chm

2.83 KB
Binary file not shown.

Documentation/CodeGen.hsm

8.19 KB
Binary file not shown.

RepositoryAPI/RpsKey.dbl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace CodeGen.RepositoryAPI
7373
public method RpsKey
7474
endparams
7575
proc
76-
76+
init mk_info, mDescription, mNullValue
7777
endmethod
7878

7979
;;; <summary>
@@ -338,15 +338,6 @@ namespace CodeGen.RepositoryAPI
338338
endmethod
339339
endproperty
340340

341-
;;---------------------------------------------------------------------
342-
;;Non-repository attributes
343-
344-
;;; <summary>
345-
;;; Should CodGen exclude this key when processing key loops?
346-
;;; </summary>
347-
public readwrite property CodegeExclude, boolean
348-
349-
350341
endclass
351342

352343
endnamespace

0 commit comments

Comments
 (0)