From 4e52a9654b28a7646597ce0e0f010589ff7905d5 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Tue, 17 Jul 2018 10:12:49 +0200 Subject: [PATCH] [FIX] generateLibraryManifest: i18n/css handling --- lib/processors/manifestCreator.js | 6 +- lib/tasks/generateLibraryManifest.js | 3 +- test/lib/tasks/generateLibraryManifest.js | 484 ++++++++++++++++++++++ 3 files changed, 489 insertions(+), 4 deletions(-) create mode 100644 test/lib/tasks/generateLibraryManifest.js diff --git a/lib/processors/manifestCreator.js b/lib/processors/manifestCreator.js index 7262cb0ba..bf743aae5 100644 --- a/lib/processors/manifestCreator.js +++ b/lib/processors/manifestCreator.js @@ -399,9 +399,9 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in let i18nElement = findChild(libraryAppData, "i18n"); if ( i18nElement ) { let i18n = i18nElement._; - if ( "false".equals(i18n) ) { + if ( i18n === "false" ) { return false; - } else if ( "true".equals(i18n) ) { + } else if ( i18n === "true" ) { return "messagebundle.properties"; } else { return i18n; @@ -424,7 +424,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in let cssElement = findChild(libraryAppData, "css"); if ( cssElement != null ) { let css = cssElement._; - if ( "false".equals(css) ) { + if ( css === "false" ) { log.verbose(" sap.ui5/library/css property taken from .library appData: '%s'", false); return false; } diff --git a/lib/tasks/generateLibraryManifest.js b/lib/tasks/generateLibraryManifest.js index 3d41520d7..38fb4c094 100644 --- a/lib/tasks/generateLibraryManifest.js +++ b/lib/tasks/generateLibraryManifest.js @@ -26,7 +26,8 @@ module.exports = function({workspace, dependencies, options}) { // *.json files are needed to avoid overwriting them // *.js files are needed to identify nested components // *.less, *.css, *.theming and *.theme files are needed to identify supported themes - return combo.byGlob("/**/*.{js,json,library,less,css,theming,theme}").then((resources) => { + // *.properties to identify existence of i18n bundles (e.g. messagebundle.properties) + return combo.byGlob("/**/*.{js,json,library,less,css,theming,theme,properties}").then((resources) => { // Find all libraries and create a manifest.json file return workspace.byGlob("/resources/**/.library").then((libraryIndicatorResources) => { if (libraryIndicatorResources.length < 1) { diff --git a/test/lib/tasks/generateLibraryManifest.js b/test/lib/tasks/generateLibraryManifest.js new file mode 100644 index 000000000..4562aaf25 --- /dev/null +++ b/test/lib/tasks/generateLibraryManifest.js @@ -0,0 +1,484 @@ +const {test} = require("ava"); + +const ui5Builder = require("../../../"); +const tasks = ui5Builder.builder.tasks; +const path = require("path"); +const ui5Fs = require("@ui5/fs"); +const resourceFactory = ui5Fs.resourceFactory; + +function createWorkspace() { + return resourceFactory.createAdapter({ + virBasePath: "/", + project: { + metadata: { + name: "test.lib" + }, + version: "2.0.0", + dependencies: [ + { + metadata: { + name: "sap.ui.core" + }, + version: "1.0.0" + } + ] + } + }); +} + +function createDependencies() { + return resourceFactory.createAdapter({ + fsBasePath: path.join(__dirname, "..", "..", "fixtures", "sap.ui.core-evo", "main", "src"), + virBasePath: "/resources" + }); +} + +async function assertCreatedManifest(t, oExpectedManifest) { + const {workspace, dependencies, resources} = t.context; + + await Promise.all(resources.map((resource) => workspace.write(resource))); + + await tasks.generateLibraryManifest({ + workspace: workspace, + dependencies: dependencies, + options: { + projectName: "Test Lib" + } + }); + + const resource = await workspace.byPath("/resources/test/lib/manifest.json"); + if (!resource) { + t.fail("Could not find /resources/test/lib/manifest.json in target"); + return; + } + + const buffer = await resource.getBuffer(); + t.deepEqual(JSON.parse(buffer), oExpectedManifest, "Correct content"); +} + +test("Library without i18n bundle file", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: false, + } + }, + }); +}); + +test("Library with i18n bundle file (messagebundle.properties)", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/messagebundle.properties", + string: "KEY=VALUE", + project: t.context.workspace._project + })); + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: "messagebundle.properties", + } + }, + }); +}); + +test("Library with i18n=true declared in .library", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + + + + true + + + + + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: "messagebundle.properties", + } + }, + }); +}); + +test("Library with i18n=false declared in .library", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + + + + false + + + + + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: false + } + }, + }); +}); + +test("Library with i18n=foo.properties declared in .library", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + + + + foo.properties + + + + + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: "foo.properties" + } + }, + }); +}); + +test("Library with css=true declared in .library", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + + + + true + + + + + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: false + } + }, + }); +}); + +test("Library with css=false declared in .library", async (t) => { + t.context.workspace = createWorkspace(); + t.context.dependencies = createDependencies(); + + t.context.resources = []; + t.context.resources.push(resourceFactory.createResource({ + path: "/resources/test/lib/.library", + string: ` + + + + test.lib + SAP SE + + 2.0.0 + + Test Lib + + + + + + false + + + + + + + `, + project: t.context.workspace._project + })); + + await assertCreatedManifest(t, { + "_version": "1.9.0", + "sap.app": { + applicationVersion: { + version: "2.0.0", + }, + description: "Test Lib", + embeds: [], + id: "test.lib", + offline: true, + resources: "resources.json", + title: "Test Lib", + type: "library", + }, + "sap.ui": { + supportedThemes: [], + technology: "UI5", + }, + "sap.ui5": { + dependencies: { + libs: {}, + minUI5Version: "1.0", + }, + library: { + i18n: false, + css: false + } + }, + }); +});