Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Proxy mode: Read ABAP URI configuration from projects #308

Draft
wants to merge 2 commits into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/types/application/ApplicationFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

/**
Expand Down Expand Up @@ -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
*
Expand Down
50 changes: 50 additions & 0 deletions lib/types/library/LibraryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

/**
Expand Down Expand Up @@ -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
*
Expand Down