Skip to content

Commit

Permalink
Merge pull request #1949 from chrjorgensen/fix/resolve-with-variants
Browse files Browse the repository at this point in the history
Fix member and object resolve with variants
  • Loading branch information
worksofliam authored Apr 3, 2024
2 parents e1763db + 03afbf8 commit 236d0eb
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,22 +778,24 @@ export default class IBMiContent {
}

async memberResolve(member: string, files: QsysPath[]): Promise<IBMiMember | undefined> {
const inAmerican = (s: string) => { return this.ibmi.sysNameInAmerican(s) };
const inLocal = (s: string) => { return this.ibmi.sysNameInLocal(s) };

// Escape names for shell
const pathList = this.ibmi.upperCaseName(
files
.map(file => {
const asp = file.asp || this.config.sourceASP;
if (asp && asp.length > 0) {
return [
Tools.qualifyPath(file.library, file.name, member, asp, true),
Tools.qualifyPath(file.library, file.name, member, undefined, true)
].join(` `);
} else {
return Tools.qualifyPath(file.library, file.name, member, undefined, true);
}
})
.join(` `)
);
const pathList = files
.map(file => {
const asp = file.asp || this.config.sourceASP;
if (asp && asp.length > 0) {
return [
Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), asp, true),
Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), undefined, true)
].join(` `);
} else {
return Tools.qualifyPath(inAmerican(file.library), inAmerican(file.name), inAmerican(member), undefined, true);
}
})
.join(` `)
.toUpperCase();

const command = `for f in ${pathList}; do if [ -f $f ]; then echo $f; break; fi; done`;
const result = await this.ibmi.sendCommand({
Expand All @@ -805,7 +807,7 @@ export default class IBMiContent {

if (firstMost) {
try {
const simplePath = Tools.unqualifyPath(firstMost);
const simplePath = inLocal(Tools.unqualifyPath(firstMost));

// This can error if the path format is wrong for some reason.
// Not that this would ever happen, but better to be safe than sorry
Expand All @@ -820,7 +822,7 @@ export default class IBMiContent {
}

async objectResolve(object: string, libraries: string[]): Promise<string | undefined> {
const command = `for f in ${libraries.map(lib => `/QSYS.LIB/${this.ibmi.upperCaseName(lib)}.LIB/${this.ibmi.upperCaseName(object)}.*`).join(` `)}; do if [ -f $f ] || [ -d $f ]; then echo $f; break; fi; done`;
const command = `for f in ${libraries.map(lib => `/QSYS.LIB/${this.ibmi.sysNameInAmerican(lib)}.LIB/${this.ibmi.sysNameInAmerican(object)}.*`).join(` `)}; do if [ -f $f ] || [ -d $f ]; then echo $f; break; fi; done`;

const result = await this.ibmi.sendCommand({
command,
Expand All @@ -830,7 +832,7 @@ export default class IBMiContent {
const firstMost = result.stdout;

if (firstMost) {
const lib = Tools.unqualifyPath(firstMost);
const lib = this.ibmi.sysNameInLocal(Tools.unqualifyPath(firstMost));

return lib.split('/')[1];
}
Expand Down
66 changes: 66 additions & 0 deletions src/testing/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ export const ContentSuite: TestSuite = {
}
},

{
name: `Test memberResolve with variants`, test: async () => {
const content = instance.getContent();
const config = instance.getConfig();
const connection = instance.getConnection();
const tempLib = config!.tempLibrary,
tempSPF = `O_ABC`.concat(connection!.variantChars.local),
tempMbr = `O_ABC`.concat(connection!.variantChars.local);

const result = await connection!.runCommand({
command: `CRTSRCPF ${tempLib}/${tempSPF} MBR(${tempMbr})`,
environment: `ile`
});

const member = await content?.memberResolve(tempMbr, [
{ library: `QSYSINC`, name: `MIH` }, // Doesn't exist here
{ library: `NOEXIST`, name: `SUP` }, // Doesn't exist here
{ library: tempLib, name: tempSPF } // Doesn't exist here
]);

assert.deepStrictEqual(member, {
asp: undefined,
library: tempLib,
file: tempSPF,
name: tempMbr,
extension: `MBR`,
basename: `${tempMbr}.MBR`
});

// Cleanup...
await connection!.runCommand({
command: `DLTF ${tempLib}/${tempSPF}`,
environment: `ile`
});
}
},

{
name: `Test memberResolve with bad name`, test: async () => {
const content = instance.getContent();
Expand Down Expand Up @@ -92,6 +129,35 @@ export const ContentSuite: TestSuite = {
}
},

{
name: `Test objectResolve .DTAARA with variants`, test: async () => {
const content = instance.getContent();
const config = instance.getConfig();
const connection = instance.getConnection();
const tempLib = config!.tempLibrary,
tempObj = `O_ABC`.concat(connection!.variantChars.local);

await connection!.runCommand({
command: `CRTDTAARA ${tempLib}/${tempObj} TYPE(*CHAR)`,
environment: `ile`
});

const lib = await content?.objectResolve(tempObj, [
"QSYSINC", // Doesn't exist here
"QSYS2", // Doesn't exist here
tempLib // Does exist here
]);

assert.strictEqual(lib, tempLib);

// Cleanup...
await connection!.runCommand({
command: `DLTDTAARA ${tempLib}/${tempObj}`,
environment: `ile`
});
}
},

{
name: `Test objectResolve with bad name`, test: async () => {
const content = instance.getContent();
Expand Down

0 comments on commit 236d0eb

Please sign in to comment.