Skip to content

Commit 1821a14

Browse files
committed
[POC] Proxy mode: Read ABAP URI configuration from projects
1 parent b7d4aad commit 1821a14

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
@@ -27,6 +27,14 @@ class ApplicationFormatter extends AbstractUi5Formatter {
2727
// TODO 2.0: Make namespace mandatory and just let the error throw
2828
log.warn(err.message);
2929
}
30+
31+
if (project.specVersion === "1.1a") {
32+
try {
33+
project.metadata.abapUri = await this.getAbapUri();
34+
} catch (err) {
35+
log.warn(err.message);
36+
}
37+
}
3038
}
3139

3240
/**
@@ -77,6 +85,19 @@ class ApplicationFormatter extends AbstractUi5Formatter {
7785
return namespace;
7886
}
7987

88+
async getAbapUri() {
89+
const {content: manifest} = await this.getManifest();
90+
91+
if (manifest["sap.platform.abap"] && manifest["sap.platform.abap"].uri) {
92+
const abapUri = manifest["sap.platform.abap"].uri;
93+
log.verbose(`ABAP URI of project ${this._project.metadata.name} is: ${abapUri}`);
94+
return abapUri;
95+
} else {
96+
throw new Error(`No "sap.platform.abap".uri configuration found in ` +
97+
`manifest.json of project ${this._project.metadata.name}`);
98+
}
99+
}
100+
80101
/**
81102
* Reads the projects manifest.json
82103
*

lib/types/library/LibraryFormatter.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ class LibraryFormatter extends AbstractUi5Formatter {
4646
// TODO 2.0: Make copyright mandatory and just let the error throw
4747
log.verbose(err.message);
4848
}
49+
50+
if (project.specVersion === "1.1a") {
51+
try {
52+
project.metadata.abapUri = await this.getAbapUri();
53+
} catch (err) {
54+
log.warn(err.message);
55+
}
56+
}
4957
}
5058

5159
/**
@@ -306,6 +314,48 @@ class LibraryFormatter extends AbstractUi5Formatter {
306314
});
307315
}
308316

317+
async getAbapUri() {
318+
let abapUri;
319+
// First try manifest.json
320+
try {
321+
const {content: manifest} = await this.getManifest();
322+
if (manifest["sap.platform.abap"] && manifest["sap.platform.abap"].uri) {
323+
abapUri = manifest["sap.platform.abap"].uri;
324+
} else {
325+
throw new Error(`No "sap.platform.abap".uri configuration found in ` +
326+
`manifest.json of project ${this._project.metadata.name}`);
327+
}
328+
} catch (err) {
329+
log.verbose(`Failed to read ABAP URI configuration from manifest.json for project ` +
330+
`${this._project.metadata.name}: ${err.message}`);
331+
log.verbose(`Falling back to .library file...`);
332+
}
333+
334+
335+
// Fallback to .library
336+
try {
337+
const {content: dotLibrary} = await this.getDotLibrary();
338+
if (dotLibrary && dotLibrary.library && dotLibrary.library.appData && dotLibrary.library.appData.manifest &&
339+
dotLibrary.library.appData.manifest["sap.platform.abap"] &&
340+
dotLibrary.library.appData.manifest["sap.platform.abap"].uri) {
341+
abapUri = dotLibrary.library.appData.manifest["sap.platform.abap"].uri;
342+
} else {
343+
throw new Error(`No library.appData.manifest."sap.platform.abap".uri configuration found in ` +
344+
`.library of project ${this._project.metadata.name}`);
345+
}
346+
} catch (err) {
347+
log.verbose(`Failed to read ABAP URI configuration from .library for project ` +
348+
`${this._project.metadata.name}: ${err.message}`);
349+
}
350+
351+
if (!abapUri) {
352+
throw new Error(`Failed to resolve ABAP URI configuration for ` +
353+
`project ${this._project.metadata.name}. Check verbose log for details.`);
354+
}
355+
log.verbose(`ABAP URI of project ${this._project.metadata.name} is: ${abapUri}`);
356+
return abapUri;
357+
}
358+
309359
/**
310360
* Validates the project
311361
*

0 commit comments

Comments
 (0)