Skip to content

Commit 056ee63

Browse files
committed
[POC] Proxy mode: Read ABAP URI configuration from projects
1 parent 9f287ff commit 056ee63

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

lib/types/application/ApplicationFormatter.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class ApplicationFormatter extends AbstractUi5Formatter {
2121
};
2222

2323
project.metadata.namespace = await this.getNamespace();
24+
25+
if (project.specVersion === "1.1a") {
26+
try {
27+
project.metadata.abapUri = await this.getAbapUri();
28+
} catch (err) {
29+
log.warn(err.message);
30+
}
31+
}
2432
}
2533

2634
/**
@@ -71,6 +79,19 @@ class ApplicationFormatter extends AbstractUi5Formatter {
7179
return namespace;
7280
}
7381

82+
async getAbapUri() {
83+
const {content: manifest} = await this.getManifest();
84+
85+
if (manifest["sap.platform.abap"] && manifest["sap.platform.abap"].uri) {
86+
const abapUri = manifest["sap.platform.abap"].uri;
87+
log.verbose(`ABAP URI of project ${this._project.metadata.name} is: ${abapUri}`);
88+
return abapUri;
89+
} else {
90+
throw new Error(`No "sap.platform.abap".uri configuration found in ` +
91+
`manifest.json of project ${this._project.metadata.name}`);
92+
}
93+
}
94+
7495
/**
7596
* Reads the projects manifest.json
7697
*

lib/types/library/LibraryFormatter.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ class LibraryFormatter extends AbstractUi5Formatter {
5454
// TODO 2.0: Make copyright mandatory and just let the error throw
5555
log.verbose(err.message);
5656
}
57+
58+
if (project.specVersion === "1.1a") {
59+
try {
60+
project.metadata.abapUri = await this.getAbapUri();
61+
} catch (err) {
62+
log.warn(err.message);
63+
}
64+
}
5765
}
5866

5967
/**
@@ -394,6 +402,48 @@ class LibraryFormatter extends AbstractUi5Formatter {
394402
});
395403
}
396404

405+
async getAbapUri() {
406+
let abapUri;
407+
// First try manifest.json
408+
try {
409+
const {content: manifest} = await this.getManifest();
410+
if (manifest["sap.platform.abap"] && manifest["sap.platform.abap"].uri) {
411+
abapUri = manifest["sap.platform.abap"].uri;
412+
} else {
413+
throw new Error(`No "sap.platform.abap".uri configuration found in ` +
414+
`manifest.json of project ${this._project.metadata.name}`);
415+
}
416+
} catch (err) {
417+
log.verbose(`Failed to read ABAP URI configuration from manifest.json for project ` +
418+
`${this._project.metadata.name}: ${err.message}`);
419+
log.verbose(`Falling back to .library file...`);
420+
}
421+
422+
423+
// Fallback to .library
424+
try {
425+
const {content: dotLibrary} = await this.getDotLibrary();
426+
if (dotLibrary && dotLibrary.library && dotLibrary.library.appData && dotLibrary.library.appData.manifest &&
427+
dotLibrary.library.appData.manifest["sap.platform.abap"] &&
428+
dotLibrary.library.appData.manifest["sap.platform.abap"].uri) {
429+
abapUri = dotLibrary.library.appData.manifest["sap.platform.abap"].uri;
430+
} else {
431+
throw new Error(`No library.appData.manifest."sap.platform.abap".uri configuration found in ` +
432+
`.library of project ${this._project.metadata.name}`);
433+
}
434+
} catch (err) {
435+
log.verbose(`Failed to read ABAP URI configuration from .library for project ` +
436+
`${this._project.metadata.name}: ${err.message}`);
437+
}
438+
439+
if (!abapUri) {
440+
throw new Error(`Failed to resolve ABAP URI configuration for ` +
441+
`project ${this._project.metadata.name}. Check verbose log for details.`);
442+
}
443+
log.verbose(`ABAP URI of project ${this._project.metadata.name} is: ${abapUri}`);
444+
return abapUri;
445+
}
446+
397447
/**
398448
* Validates the project
399449
*

0 commit comments

Comments
 (0)