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

[FEATURE] Introduce SpecificationVersion class #431

Merged
merged 10 commits into from
Nov 28, 2022
5 changes: 3 additions & 2 deletions lib/build/TaskRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@ class TaskRunner {
params.dependencies = dependencies;
}

if (task.getSpecVersion() === "3.0") {
const specVersion = task.getSpecVersion();
if (specVersion.gte("3.0")) {
params.options.taskName = newTaskName;
params.log = logger.getGroupLogger(`builder:custom-task:${newTaskName}`);
}

const taskUtilInterface = taskUtil.getInterface(task.getSpecVersion());
const taskUtilInterface = taskUtil.getInterface(specVersion);
// Interface is undefined if specVersion does not support taskUtil
if (taskUtilInterface) {
params.taskUtil = taskUtilInterface;
Expand Down
2 changes: 1 addition & 1 deletion lib/build/definitions/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function({project, taskUtil, getTask}) {

// Support rules should not be minified to have readable code in the Support Assistant
const minificationPattern = ["/**/*.js", "!**/*.support.js"];
if (["2.6"].includes(project.getSpecVersion())) {
if (project.getSpecVersion().gte("2.6")) {
const minificationExcludes = project.getMinificationExcludes();
if (minificationExcludes.length) {
enhancePatternWithExcludes(minificationPattern, minificationExcludes, "/resources/");
Expand Down
2 changes: 1 addition & 1 deletion lib/build/definitions/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function({project, taskUtil, getTask}) {

// Support rules should not be minified to have readable code in the Support Assistant
const minificationPattern = ["/resources/**/*.js", "!**/*.support.js"];
if (["2.6"].includes(project.getSpecVersion())) {
if (project.getSpecVersion().gte("2.6")) {
const minificationExcludes = project.getMinificationExcludes();
if (minificationExcludes.length) {
enhancePatternWithExcludes(minificationPattern, minificationExcludes, "/resources/");
Expand Down
29 changes: 9 additions & 20 deletions lib/build/helpers/TaskUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ class TaskUtil {
*
* @public
* @typedef {object} @ui5/project/build/helpers/TaskUtil~ProjectInterface
* @property {Function} getSpecVersion Get the project Specification Version
* @property {Function} getType Get the project type
* @property {Function} getName Get the project name
* @property {Function} getVersion Get the project version
Expand Down Expand Up @@ -269,11 +268,13 @@ class TaskUtil {
* Get an interface to an instance of this class that only provides those functions
* that are supported by the given custom task extension specification version.
*
* @param {string} specVersion Specification version of custom task extension
* @param {@ui5/project/specifications/SpecificationVersion} specVersion
* SpecVersionComparator instance of the custom task
* @returns {object} An object with bound instance methods supported by the given specification version
*/
getInterface(specVersion) {
if (["0.1", "1.0", "1.1", "2.0", "2.1"].includes(specVersion)) {
if (specVersion.lte("2.1")) {
// Tasks defining specVersion <= 2.1 do not have access to any TaskUtil APIs
return undefined;
}

Expand All @@ -283,26 +284,17 @@ class TaskUtil {
bindFunctions(this, baseInterface, [
"setTag", "clearTag", "getTag", "isRootProject", "registerCleanupTask"
]);
switch (specVersion) {
case "2.2":
case "2.3":
case "2.4":
case "2.5":
case "2.6":
return baseInterface;
case "3.0":

if (specVersion.gte("3.0")) {
// getProject function, returning an interfaced project instance
baseInterface.getProject = (projectName) => {
const project = this.getProject(projectName);
const baseProjectInterface = {};
bindFunctions(project, baseProjectInterface, [
"getSpecVersion", "getType", "getName", "getVersion", "getNamespace",
"getType", "getName", "getVersion", "getNamespace",
"getRootReader", "getReader", "getCustomConfiguration", "isFrameworkProject"
]);
switch (specVersion) {
case "3.0":
return baseProjectInterface;
}
return baseProjectInterface;
};
// getDependencies function, returning an array of project names
baseInterface.getDependencies = (projectName) => {
Expand All @@ -318,11 +310,8 @@ class TaskUtil {
].forEach((factoryFunction) => {
baseInterface.resourceFactory[factoryFunction] = this.resourceFactory[factoryFunction];
});

return baseInterface;
default:
throw new Error(`TaskUtil: Unknown or unsupported Specification Version ${specVersion}`);
}
return baseInterface;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/build/helpers/createBuildManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function(project, buildConfig) {

const metadata = {
project: {
specVersion: project.getSpecVersion(),
specVersion: project.getSpecVersion().toString(),
type,
metadata: {
name: projectName,
Expand Down
23 changes: 8 additions & 15 deletions lib/specifications/Specification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logger from "@ui5/logger";
import {createReader} from "@ui5/fs/resourceFactory";
import SpecificationVersion from "./SpecificationVersion.js";

/**
* Abstract superclass for all projects and extensions
Expand Down Expand Up @@ -50,10 +51,9 @@ class Specification {
const config = JSON.parse(JSON.stringify(configuration));
const {validate} = await import("../validation/validator.js");

if (config.specVersion === "0.1" || config.specVersion === "1.0" ||
config.specVersion === "1.1") {
if (SpecificationVersion.major(config.specVersion) <= 1) {
const originalSpecVersion = config.specVersion;
this._log.verbose(`Detected legacy specification version ${config.specVersion}, defined for ` +
this._log.verbose(`Detected legacy Specification Version ${config.specVersion}, defined for ` +
`${config.kind} ${config.metadata.name}. ` +
`Attempting to migrate the project to a supported specification version...`);
this._migrateLegacyProject(config);
Expand All @@ -69,20 +69,12 @@ class Specification {
`Validation error after migration of ${config.kind} ${config.metadata.name}:`);
this._log.verbose(err.message);
throw new Error(
`${config.kind} ${config.metadata.name} defines unsupported specification version ` +
`${config.kind} ${config.metadata.name} defines unsupported Specification Version ` +
`${originalSpecVersion}. Please manually upgrade to 2.0 or higher. ` +
`For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions - ` +
`An attempted migration to a supported specification version failed, ` +
`likely due to unrecognized configuration. Check verbose log for details.`);
}
} else if (config.specVersion !== "2.0" &&
config.specVersion !== "2.1" && config.specVersion !== "2.2" &&
config.specVersion !== "2.3" && config.specVersion !== "2.4" &&
config.specVersion !== "2.5" && config.specVersion !== "2.6") {
throw new Error(
`Unsupported specification version ${config.specVersion} defined in ${config.kind} ` +
`${config.metadata.name}. Your UI5 CLI installation might be outdated. ` +
`For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions`);
} else {
await validate({
config,
Expand All @@ -102,7 +94,8 @@ class Specification {
this._name = config.metadata.name;
this._kind = config.kind;
this._type = config.type;
this._specVersion = config.specVersion;
this._specVersionString = config.specVersion;
this._specVersion = new SpecificationVersion(this._specVersionString);
this._config = config;

return this;
Expand Down Expand Up @@ -142,10 +135,10 @@ class Specification {
}

/**
* Get the Specification Version
* Returns an instance of a helper class representing a Specification Version
*
* @public
* @returns {string} Specification Version
* @returns {@ui5/project/specifications/SpecificationVersion}
*/
getSpecVersion() {
return this._specVersion;
Expand Down
Loading