Skip to content

Commit 45f9eea

Browse files
authored
Merge pull request #106 from IBM/feature/obj_refs_override
Allow object references to be overridden by source definition
2 parents 13d383a + 0a66610 commit 45f9eea

File tree

8 files changed

+253
-2
lines changed

8 files changed

+253
-2
lines changed

cli/src/targets.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ export class Targets {
171171
}
172172
}
173173

174+
// This allows us to override the .objrefs if the source actually exists.
175+
if (this.isReferenceObject(theObject, true)) {
176+
this.logger.fileLog(relativePath, {
177+
type: `info`,
178+
message: `The object ${theObject.systemName}.${theObject.type} is defined in the references file even though the source exists for it.`
179+
});
180+
}
181+
174182
this.storeResolved(localPath, theObject);
175183

176184
return theObject;
@@ -188,13 +196,25 @@ export class Targets {
188196

189197
pseudoObjects.forEach(ileObject => {
190198
if (!this.searchForObject(ileObject)) {
191-
const key = `/${ileObject.systemName}.${ileObject.type}`;
199+
const key = `${ileObject.systemName}.${ileObject.type}`;
192200
ileObject.reference = true;
193201
this.resolvedObjects[key] = ileObject;
194202
}
195203
});
196204
}
197205

206+
public isReferenceObject(ileObject: ILEObject, remove?: boolean) {
207+
const key = `${ileObject.systemName}.${ileObject.type}`;
208+
const existing = this.resolvedObjects[key];
209+
const isRef = Boolean(existing && existing.reference);
210+
211+
if (isRef && remove) {
212+
this.resolvedObjects[key] = undefined;
213+
}
214+
215+
return isRef;
216+
}
217+
198218
public removeObjectByPath(localPath: string) {
199219
const resolvedObject = this.resolvedObjects[localPath];
200220

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# cool comment
2+
3+
SAMREF.FILE
4+
5+
# other comment
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
*%METADATA *
2+
* %TEXT Display Article *
3+
*%EMETADATA *
4+
A*%%TS SD 20210414 103200 VTAQUIN REL-V7R3M0 5770-WDS
5+
A*%%EC
6+
A DSPSIZ(24 80 *DS3)
7+
A REF(*LIBL/PROVIDER FPROV)
8+
A PRINT
9+
A INDARA
10+
A ERRSFL
11+
A CA03(03)
12+
A CA12(12)
13+
A R FMT01
14+
A*%%TS SD 20210330 110722 VTAQUIN REL-V7R3M0 5770-WDS
15+
A CF04(04 'Prompt')
16+
A 1 2'PRO250 '
17+
A COLOR(BLU)
18+
A 3 4'Type choices, press Enter.'
19+
A COLOR(BLU)
20+
A 23 3'F3=Exit'
21+
A COLOR(BLU)
22+
A 23 37'F12=Cancel'
23+
A COLOR(BLU)
24+
A 1 34'Provider by Id'
25+
A DSPATR(HI)
26+
A 5 4'Provider Id . . . . . .'
27+
A 23 19'F4=Prompt'
28+
A COLOR(BLU)
29+
A PRID R B 5 29
30+
A 40 ERRMSGID(ERR0103 *LIBL/SAMMSGF 40 &-
31+
A ERRDATA)
32+
A ERRDATA 6A P
33+
A R FMT02
34+
A*%%TS SD 20210414 103200 VTAQUIN REL-V7R3M0 5770-WDS
35+
A CA07(07 'Items')
36+
A 1 2'PRO250 '
37+
A COLOR(BLU)
38+
A 3 4'Press Enter to continue.'
39+
A COLOR(BLU)
40+
A 23 3'F3=Exit'
41+
A COLOR(BLU)
42+
A 23 37'F12=Cancel'
43+
A COLOR(BLU)
44+
A 5 4'Provider Id . . . . . :'
45+
A 6 4'Name . . . . . . . . :'
46+
A 7 4'Phone . . . . . . . . :'
47+
A 8 4'Vat Nr . . . . . . . :'
48+
A 9 4'eMail . . . . . . . . :'
49+
A 10 4'Address . . . . . . . :'
50+
A 13 4'Postal Code & City . :'
51+
A 14 4'Country Code . . . . :'
52+
A 1 34'Provider by Id'
53+
A DSPATR(HI)
54+
A PRID R O 5 29
55+
A PROVNM R O 6 29
56+
A PRPHONE R O 7 29
57+
A PRVAT R O 8 29
58+
A PRMAIL R O 9 29
59+
A PRLINE1 R O 10 29
60+
A PRLINE2 R O 11 29
61+
A PRLINE3 R O 12 29
62+
A PRZIP R O 13 29
63+
A PRCOUN R O 14 29
64+
A PRCITY R O 13 40
65+
A COUNTR R O 14 32REFFLD(FCOUN/COUNTR *LIBL/COUNTRY)
66+
A 23 18'F7=Items'
67+
A COLOR(BLU)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*%METADATA *
2+
* %TEXT Provider file *
3+
*%EMETADATA *
4+
UNIQUE
5+
R FPROV PFILE(PROVIDER)
6+
K PRID
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*%METADATA *
2+
* %TEXT Provider file *
3+
*%EMETADATA *
4+
REF(SAMREF)
5+
R FPROV
6+
PRID R
7+
PROVNM R
8+
PRCONT 30 TEXT('CONTACT PERSON')
9+
PRPHONE R REFFLD(PHONE)
10+
PRVAT R REFFLD(VATNUM)
11+
PRMAIL R REFFLD(EMAIL)
12+
PRLINE1 R REFFLD(ADRLINE)
13+
PRLINE2 R REFFLD(ADRLINE)
14+
PRLINE3 R REFFLD(ADRLINE)
15+
PRZIP R REFFLD(ZIPCOD)
16+
PRCITY R REFFLD(CITY)
17+
PRCOUN R REFFLD(COID)
18+
PRCREA L TEXT('CREATION DATE')
19+
COLHDG('CREAETION' 'DATE')
20+
PRMOD Z TEXT('LAST MODIFICATION')
21+
COLHDG('LAST' 'MODIFICATION')
22+
PRMODID 10 TEXT('LAS MOD BY')
23+
COLHDG('LAST' 'MODIF.' 'BY')
24+
PRDEL R REFFLD(DLCODE)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
R REFER
2+
*
3+
ADID 5P 0 TEXT('ADDRESS ID')
4+
COLHDG('ADRES.' 'ID')
5+
EDTCDE(Z)
6+
ADRLINE 50 TEXT('ADDRESS LINE')
7+
COLHDG('ADDRESS' 'LINE')
8+
ARID 6 TEXT('ARTICLE ID')
9+
COLHDG('ART.' 'ID')
10+
ARDESC 50 TEXT('ARTICLE DESCRPTION')
11+
COLHDG('DESCRIPTION')
12+
CUID 5P 0 TEXT('CUSTOMER ID')
13+
COLHDG('CUST' 'ID')
14+
EDTCDE(Z)
15+
COID 2 TEXT('COUNTRY CODE')
16+
COLHDG('CO' 'ID')
17+
COUNTR 30 TEXT('COUNTRY NAME')
18+
COLHDG('COUNTRY' 'NAME')
19+
CITY 30 TEXT('CITY')
20+
COLHDG('CITY')
21+
CUSTNM 30 TEXT('CUSTOMER NAME')
22+
COLHDG('CUSTOMER' 'NAME')
23+
DLCODE 1 COLHDG('DEL' 'CD')
24+
TEXT('DELETE CODE X=DELETED')
25+
FAID 3 TEXT('FAMILLY ID')
26+
COLHDG('FAM' 'ID')
27+
FADESC 50 TEXT('FAMILLY DESCRIPTION')
28+
COLHDG('FAMILLY')
29+
EMAIL 50 TEXT('ADDRESS MAIL')
30+
COLHDG('ADDRESS' 'MAIL')
31+
ORID 6P 0 TEXT('ORDER NUMBER')
32+
COLHDG('ORD' 'NUM')
33+
EDTCDE(Z)
34+
ODLINE 5P 0 TEXT('ORDER LINE')
35+
COLHDG('ORD' 'LINE')
36+
EDTCDE(Z)
37+
PRID 5P 0 TEXT('PROVIDER ID')
38+
COLHDG('PROVIDER' 'ID')
39+
EDTCDE(Z)
40+
PROVNM 30 TEXT('PROVIDER NAME')
41+
COLHDG('PROVIDER' 'NAME')
42+
PHONE 15 TEXT('PHONE NUMBER')
43+
COLHDG('PHONE' 'NUMBER')
44+
QUANTITY 5 0 TEXT('QUANTITY')
45+
EDTCDE(Z)
46+
COLHDG('QTY')
47+
TOTPRICE 9P 2 TEXT('TOTAL PRICE')
48+
COLHDG('TOTAL' 'PRICE')
49+
EDTCDE(2)
50+
UNITPRICE 7P 2 TEXT('UNIT PRICE')
51+
COLHDG('UNIT' 'PRICE')
52+
EDTCDE(2)
53+
WHID 3 TEXT('WAREHOUSE ID')
54+
COLHDG('WHS' 'ID')
55+
VATCODE 1 TEXT('VAT CODE')
56+
COLHDG('VAT' 'CODE')
57+
DFT('2')
58+
VATRATE 4 2 TEXT('VAT RATE %')
59+
COLHDG('VAT' 'RATE %')
60+
EDTWRD(' , %')
61+
VATNUM 12 TEXT('VAT NUMBER')
62+
COLHDG('VAT' 'NUMBER')
63+
WHNAME 20 TEXT('WAREHOUSE NAME')
64+
COLHDG('WAREHOUSE')
65+
YEAR 4P 0 TEXT('YEAR')
66+
COLHDG('YEAR')
67+
ZIPCOD 10 TEXT('ZIP CODE')
68+
COLHDG('ZIP' 'CODE')

cli/test/overrideObjRef.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { assert, beforeAll, describe, expect, test } from 'vitest';
2+
3+
import { Targets } from '../src/targets'
4+
import path from 'path';
5+
import { MakeProject } from '../src/builders/make';
6+
import { getFiles } from '../src/utils';
7+
import { setupFixture } from './fixtures/projects';
8+
import { referencesFileName, scanGlob } from '../src/extensions';
9+
import { writeFileSync } from 'fs';
10+
import { BobProject } from '../src/builders/bob';
11+
12+
const cwd = setupFixture(`override_objref`);
13+
14+
// This issue was occuring when you had two files with the same name, but different extensions.
15+
16+
let files = getFiles(cwd, scanGlob);
17+
18+
describe(`ensure that objrefs can be overridden`, () => {
19+
const targets = new Targets(cwd);
20+
targets.setSuggestions({renames: true, includes: true})
21+
22+
test(`Ensure objects are defined`, async () => {
23+
await targets.handleRefsFile(path.join(cwd, referencesFileName));
24+
expect(targets.getResolvedObjects().length).toBe(1);
25+
expect(targets.getTargets().length).toBe(0);
26+
27+
targets.loadObjectsFromPaths(files);
28+
const parsePromises = files.map(f => targets.parseFile(f));
29+
await Promise.all(parsePromises);
30+
31+
expect(targets.getTargets().length).toBeGreaterThan(0);
32+
targets.resolveBinder();
33+
34+
expect(targets.getTargets().length).toBe(4);
35+
36+
expect(targets.getResolvedObjects().length).toBe(4);
37+
expect(targets.getResolvedObjects(`FILE`).length).toBe(4);
38+
39+
expect(targets.binderRequired()).toBe(false);
40+
41+
const pro250d = targets.searchForObject({systemName: `PRO250D`, type: `FILE`});
42+
expect(pro250d).toBeDefined();
43+
expect(pro250d.reference).toBeUndefined();
44+
45+
const provider = targets.searchForObject({systemName: `PROVIDER`, type: `FILE`});
46+
expect(provider).toBeDefined();
47+
expect(provider.reference).toBeUndefined();
48+
49+
const provide1 = targets.searchForObject({systemName: `PROVIDE1`, type: `FILE`});
50+
expect(provide1).toBeDefined();
51+
expect(provide1.reference).toBeUndefined();
52+
53+
const samref = targets.searchForObject({systemName: `SAMREF`, type: `FILE`});
54+
expect(samref).toBeDefined();
55+
expect(samref.reference).toBeUndefined();
56+
});
57+
});

docs/pages/general/rules.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ When using Source Orbit, you may find that you want to reference objects that do
7575

7676
> `no object found for reference 'COUNTRY'`
7777
78-
If you know those objects do exist but outside of this project, then you can use the `.objrefs` file in the project root to list those objects and if that object is a service program, you can also list the exports by indenting after the service program reference. Comments can start with `#`
78+
If you know those objects do exist but outside of this project, then you can use the `.objrefs` file (references file) in the project root to list those objects and if that object is a service program, you can also list the exports by indenting after the service program reference. Comments can start with `#`
7979

8080
```
8181
# Files that exist outside this project
@@ -89,6 +89,8 @@ UTILS.SRVPGM
8989
toLower
9090
```
9191

92+
If you use a references file, but you have source that defines the object, the source will take precedence over the reference and a log will be issued on the source.
93+
9294
## Service Programs and Binder Source
9395

9496
For service programs to be created, binder source must exist for it. Source Orbit will read the binder source, find all the referenced export functions/procedures and will find the correct module that exports them to create the service program.
@@ -110,6 +112,8 @@ CREATE OR REPLACE TABLE CUSORD (...)
110112

111113
## Embedded SQL in RPGLE C specs
112114

115+
**This section is not true as of Source Orbit CLI 1.1.0**
116+
113117
Source Orbit does not support embedded SQL (`exec sql`) used in a C spec. - no problem with mixed-format or free-format. We recommend:
114118

115119
1. converting the embedded SQL statements (`exec sql`) to not have C specs, or

0 commit comments

Comments
 (0)