Skip to content

Commit 6cd98e8

Browse files
committed
[INTERNAL] Adopt ui5-project changes
1 parent 97cfa6c commit 6cd98e8

File tree

8 files changed

+43
-63
lines changed

8 files changed

+43
-63
lines changed

lib/lbt/resources/LocatorResource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class LocatorResource extends Resource {
1111
}
1212

1313
getProject() {
14-
return this.resource._project;
14+
return this.resource.getProject();
1515
}
1616

1717
getPath() {

lib/lbt/utils/escapePropertiesFile.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ const nonAsciiEscaper = require("../../processors/nonAsciiEscaper");
1212
*/
1313
module.exports = async function(resource) {
1414
const project = resource.getProject();
15-
let propertiesFileSourceEncoding = project &&
16-
project.resources &&
17-
project.resources.configuration &&
18-
project.resources.configuration.propertiesFileSourceEncoding;
15+
let propertiesFileSourceEncoding = project.getPropertiesFileSourceEncoding();
1916

2017
if (!propertiesFileSourceEncoding) {
21-
if (project && ["0.1", "1.0", "1.1"].includes(project.specVersion)) {
18+
if (project && ["0.1", "1.0", "1.1"].includes(project.getSpecVersion())) {
2219
// default encoding to "ISO-8859-1" for old specVersions
2320
propertiesFileSourceEncoding = "ISO-8859-1";
2421
} else {

lib/processors/bundlers/moduleBundler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ module.exports = function({resources, options: {bundleDefinition, bundleOptions,
148148
log.verbose(`bundleDefinition: ${JSON.stringify(bundleDefinition, null, 2)}`);
149149
log.verbose(`bundleOptions: ${JSON.stringify(bundleOptions, null, 2)}`);
150150
}
151-
152151
return pool.prepare( resources, moduleNameMapping ).
153152
then( () => builder.createBundle(bundleDefinition, bundleOptions) ).
154153
then( (results) => {

lib/processors/manifestCreator.js

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ class LibraryBundle {
157157
/*
158158
* Creates the library manifest.json file for a UILibrary.
159159
*/
160-
async function createManifest(libraryResource, libBundle, descriptorVersion, _include3rdParty, omitMinVersions) {
160+
async function createManifest(
161+
libraryResource, libBundle, descriptorVersion, _include3rdParty, omitMinVersions, getProjectVersion
162+
) {
161163
// create a Library wrapper around the .library XML
162164
const library = await Library.from(libraryResource);
163165

@@ -223,13 +225,6 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
223225
return version && version !== "@version@" && version !== "${version}";
224226
}
225227

226-
function getProjectVersion() {
227-
const project = libraryResource._project;
228-
if ( project ) {
229-
return project.version;
230-
}
231-
}
232-
233228
function getLibraryTitle() {
234229
if ( library.getTitle() ) {
235230
return library.getTitle();
@@ -321,7 +316,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
321316
embeds: findEmbeddedComponents(),
322317
i18n,
323318
applicationVersion: {
324-
version: isValid(library.getVersion()) ? library.getVersion() : getProjectVersion()
319+
version: isValid(library.getVersion()) ? library.getVersion() : getProjectVersion(library.getName())
325320
},
326321
title: getLibraryTitle(),
327322
description: library.getDocumentation(),
@@ -398,7 +393,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
398393
_: "sap.ui.core"
399394
}]
400395
});
401-
return normalizeVersion(getVersion(dummy));
396+
return normalizeVersion(getProjectVersion(dummy.getLibraryName()));
402397
}
403398

404399
function dependencies() {
@@ -410,7 +405,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
410405
if ( library.getDependencies() != null ) {
411406
for (const dep of library.getDependencies()) {
412407
dependencies.libs[dep.getLibraryName()] = {
413-
minVersion: omitMinVersions ? "" : getVersion(dep),
408+
minVersion: omitMinVersions ? "" : getProjectVersion(dep.getLibraryName()),
414409
lazy: dep.isLazy() || undefined // suppress default (false)
415410
};
416411
}
@@ -619,33 +614,6 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
619614
return v.major + "." + v.minor;
620615
}
621616

622-
function getVersion(dependency) {
623-
const version = dependency.getVersion();
624-
if ( version != null ) {
625-
return version;
626-
}
627-
628-
function hasName(entity) {
629-
return entity.metadata && entity.metadata.name === dependency.getLibraryName();
630-
}
631-
632-
const project = libraryResource._project;
633-
if ( project ) {
634-
if ( Array.isArray(project.dependencies) ) {
635-
const lib = project.dependencies.find(hasName);
636-
if ( lib ) {
637-
return lib.version;
638-
}
639-
}
640-
if ( hasName(project) ) {
641-
return project.version;
642-
}
643-
}
644-
645-
throw new Error(
646-
`Couldn't find version for library '${dependency.getLibraryName()}', project dependency missing?`);
647-
}
648-
649617
return {
650618
"_version": descriptorVersion.toString(),
651619
"sap.app": createSapApp(),
@@ -657,7 +625,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in
657625
};
658626
}
659627

660-
module.exports = function({libraryResource, resources, options}) {
628+
module.exports = function({libraryResource, resources, getProjectVersion, options}) {
661629
// merge options with defaults
662630
options = Object.assign({
663631
descriptorVersion: APP_DESCRIPTOR_V22, // TODO 3.0: change this to type string instead of a semver object
@@ -677,7 +645,7 @@ module.exports = function({libraryResource, resources, options}) {
677645
}
678646

679647
return createManifest(libraryResource, libBundle, options.descriptorVersion, options.include3rdParty,
680-
options.omitMinVersions)
648+
options.omitMinVersions, getProjectVersion)
681649
.then((manifest) => {
682650
return new EvoResource({
683651
path: resourcePathPrefix + "manifest.json",

lib/tasks/TaskUtil.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ class TaskUtil {
136136
return this._projectBuildContext.registerCleanupTask(callback);
137137
}
138138

139+
/**
140+
* Retrieve a single project from the dependency graph
141+
*
142+
* @param {string} projectName Name of the project to retrieve
143+
* @returns {module:@ui5/project.specifications.Project|undefined}
144+
* project instance or undefined if the project is unknown to the graph
145+
* @public
146+
*/
147+
getProject(projectName) {
148+
return this._projectBuildContext.getProject(projectName);
149+
}
150+
139151
/**
140152
* Get an interface to an instance of this class that only provides those functions
141153
* that are supported by the given custom task extension specification version.

lib/tasks/bundlers/generateLibraryPreload.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,17 @@ function getSapUiCoreBunDef(name, filters, preload) {
266266
* @param {object} parameters Parameters
267267
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
268268
* @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil
269+
* @param {object} parameters.options Options
270+
* @param {module:@ui5/project.specifications.Project} parameters.options.project
269271
* @param {string[]} [parameters.options.excludes=[]] List of modules declared as glob patterns (resource name patterns)
270272
* that should be excluded from the library-preload.js bundle.
271273
* A pattern ending with a slash '/' will, similarly to the use of a single '*' or double '**' asterisk,
272274
* denote an arbitrary number of characters or folder names.
273275
* Re-includes should be marked with a leading exclamation mark '!'. The order of filters is relevant; a later
274276
* inclusion overrides an earlier exclusion, and vice versa.
275-
* @param {object} parameters.options Options
276-
* @param {string} parameters.options.projectName Project name
277277
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
278278
*/
279-
module.exports = function({workspace, taskUtil, options: {projectName, excludes = []}}) {
279+
module.exports = function({workspace, taskUtil, options: {excludes = []}}) {
280280
let nonDbgWorkspace = workspace;
281281
if (taskUtil) {
282282
nonDbgWorkspace = workspace.filter(function(resource) {
@@ -289,18 +289,17 @@ module.exports = function({workspace, taskUtil, options: {projectName, excludes
289289
// Find all libraries and create a library-preload.js bundle
290290

291291
let p = Promise.resolve();
292+
const project = taskUtil.getProject();
292293

293294
// Create core bundles for older versions (<1.97.0) which don't define bundle configuration in the ui5.yaml
294295
// See: https://github.com/SAP/openui5/commit/ff127fd2d009162ea43ad312dec99d759ebc23a0
295-
if (projectName === "sap.ui.core") {
296-
const coreProject = resources[0]._project;
297-
const coreSpecVersion = coreProject && coreProject.specVersion;
296+
if (project.getName() === "sap.ui.core") {
298297
// Instead of checking the sap.ui.core library version, the specVersion is checked against all versions
299298
// that have been defined for sap.ui.core before the bundle configuration has been introduced.
300299
// This is mainly to have an easier check without version parsing or using semver.
301300
// If no project/specVersion is available, the bundles should also be created to not break potential
302301
// existing use cases without a properly formed/formatted project tree.
303-
if (!coreSpecVersion || ["0.1", "1.1", "2.0"].includes(coreSpecVersion)) {
302+
if (["0.1", "1.1", "2.0"].includes(project.getSpecVersion())) {
304303
const isEvo = resources.find((resource) => {
305304
return resource.getPath() === "/resources/ui5loader.js";
306305
});
@@ -378,14 +377,15 @@ module.exports = function({workspace, taskUtil, options: {projectName, excludes
378377
} else {
379378
// Fallback to "library.js" as library indicator
380379
log.verbose(
381-
`Could not find a ".library" file for project ${projectName}, falling back to "library.js".`);
380+
`Could not find a ".library" file for project ${project.getName()}, ` +
381+
`falling back to "library.js".`);
382382
return workspace.byGlob("/resources/**/library.js");
383383
}
384384
}).then((libraryIndicatorResources) => {
385385
if (libraryIndicatorResources.length < 1) {
386386
// No library found - nothing to do
387387
log.verbose(
388-
`Could not find a ".library" or "library.js" file for project ${projectName}. ` +
388+
`Could not find a ".library" or "library.js" file for project ${project.getName()}. ` +
389389
`Skipping library preload bundling.`);
390390
return;
391391
}
@@ -425,7 +425,7 @@ module.exports = function({workspace, taskUtil, options: {projectName, excludes
425425
} else {
426426
log.verbose(
427427
`Could not determine library namespace from file "${libraryIndicatorPath}" ` +
428-
`for project ${projectName}. Skipping library preload bundling.`);
428+
`for project ${project.getName()}. Skipping library preload bundling.`);
429429
return Promise.resolve();
430430
}
431431
}));

lib/tasks/generateLibraryManifest.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ const manifestCreator = require("../processors/manifestCreator");
1111
* @alias module:@ui5/builder.tasks.generateLibraryManifest
1212
* @param {object} parameters Parameters
1313
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
14+
* @param {module:@ui5/builder.tasks.TaskUtil|object} [parameters.taskUtil] TaskUtil
1415
* @param {object} parameters.options Options
1516
* @param {string} parameters.options.projectName Project name
1617
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
1718
*/
18-
module.exports = function({workspace, options: {projectName}}) {
19+
module.exports = function({workspace, taskUtil, options: {projectName}}) {
1920
// Note:
2021
// *.library files are needed to identify libraries
2122
// *.json files are needed to avoid overwriting them
@@ -45,6 +46,9 @@ module.exports = function({workspace, options: {projectName}}) {
4546
libraryResource: libraryIndicatorResource,
4647
namespace: libraryNamespace,
4748
resources,
49+
getProjectVersion: (projectName) => {
50+
return taskUtil.getProject(projectName)?.getVersion();
51+
},
4852
options: {
4953
}
5054
}).then((manifest) => {

lib/tasks/generateVersionInfo.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = async ({workspace, dependencies, options: {rootProject, pattern
1919
const resources = await dependencies.byGlob(pattern);
2020

2121
const libraryInfosPromises = resources.map((dotLibResource) => {
22-
const namespace = dotLibResource._project.metadata.namespace;
22+
const namespace = dotLibResource.getProject().getNamespace();
2323
// pass all required resources to the processor
2424
// the processor will then filter
2525
return dependencies.byGlob(`/resources/${namespace}/**/${MANIFEST_JSON}`).then((manifestResources) => {
@@ -31,17 +31,17 @@ module.exports = async ({workspace, dependencies, options: {rootProject, pattern
3131
return {
3232
libraryManifest,
3333
embeddedManifests,
34-
name: dotLibResource._project.metadata.name,
35-
version: dotLibResource._project.version
34+
name: dotLibResource.getProject().getName(),
35+
version: dotLibResource.getProject().getVersion()
3636
};
3737
});
3838
});
3939
const libraryInfos = await Promise.all(libraryInfosPromises);
4040

4141
const [versionInfoResource] = await versionInfoGenerator({
4242
options: {
43-
rootProjectName: rootProject.metadata.name,
44-
rootProjectVersion: rootProject.version,
43+
rootProjectName: rootProject.getName(),
44+
rootProjectVersion: rootProject.getVersion(),
4545
libraryInfos
4646
}
4747
});

0 commit comments

Comments
 (0)