diff --git a/lib/types/application/ApplicationFormatter.js b/lib/types/application/ApplicationFormatter.js index 61245b474..8c1ee7beb 100644 --- a/lib/types/application/ApplicationFormatter.js +++ b/lib/types/application/ApplicationFormatter.js @@ -21,6 +21,14 @@ class ApplicationFormatter extends AbstractUi5Formatter { }; project.metadata.namespace = await this.getNamespace(); + + if (project.specVersion === "2.2a") { + try { + project.metadata.abapUri = await this.getAbapUri(); + } catch (err) { + log.warn(err.message); + } + } } /** @@ -71,6 +79,19 @@ class ApplicationFormatter extends AbstractUi5Formatter { return namespace; } + async getAbapUri() { + const {content: manifest} = await this.getManifest(); + + if (manifest["sap.platform.abap"] && manifest["sap.platform.abap"].uri) { + const abapUri = manifest["sap.platform.abap"].uri; + log.verbose(`ABAP URI of project ${this._project.metadata.name} is: ${abapUri}`); + return abapUri; + } else { + throw new Error(`No "sap.platform.abap".uri configuration found in ` + + `manifest.json of project ${this._project.metadata.name}`); + } + } + /** * Reads the projects manifest.json * diff --git a/lib/types/library/LibraryFormatter.js b/lib/types/library/LibraryFormatter.js index 664cb7ce6..9a6dc51c6 100644 --- a/lib/types/library/LibraryFormatter.js +++ b/lib/types/library/LibraryFormatter.js @@ -54,6 +54,14 @@ class LibraryFormatter extends AbstractUi5Formatter { // TODO 2.0: Make copyright mandatory and just let the error throw log.verbose(err.message); } + + if (project.specVersion === "2.2a") { + try { + project.metadata.abapUri = await this.getAbapUri(); + } catch (err) { + log.warn(err.message); + } + } } /** @@ -394,6 +402,48 @@ class LibraryFormatter extends AbstractUi5Formatter { }); } + async getAbapUri() { + let abapUri; + // First try manifest.json + try { + const {content: manifest} = await this.getManifest(); + if (manifest["sap.platform.abap"] && manifest["sap.platform.abap"].uri) { + abapUri = manifest["sap.platform.abap"].uri; + } else { + throw new Error(`No "sap.platform.abap".uri configuration found in ` + + `manifest.json of project ${this._project.metadata.name}`); + } + } catch (err) { + log.verbose(`Failed to read ABAP URI configuration from manifest.json for project ` + + `${this._project.metadata.name}: ${err.message}`); + log.verbose(`Falling back to .library file...`); + } + + + // Fallback to .library + try { + const {content: dotLibrary} = await this.getDotLibrary(); + if (dotLibrary && dotLibrary.library && dotLibrary.library.appData && dotLibrary.library.appData.manifest && + dotLibrary.library.appData.manifest["sap.platform.abap"] && + dotLibrary.library.appData.manifest["sap.platform.abap"].uri) { + abapUri = dotLibrary.library.appData.manifest["sap.platform.abap"].uri; + } else { + throw new Error(`No library.appData.manifest."sap.platform.abap".uri configuration found in ` + + `.library of project ${this._project.metadata.name}`); + } + } catch (err) { + log.verbose(`Failed to read ABAP URI configuration from .library for project ` + + `${this._project.metadata.name}: ${err.message}`); + } + + if (!abapUri) { + throw new Error(`Failed to resolve ABAP URI configuration for ` + + `project ${this._project.metadata.name}. Check verbose log for details.`); + } + log.verbose(`ABAP URI of project ${this._project.metadata.name} is: ${abapUri}`); + return abapUri; + } + /** * Validates the project *