@sap/cds-dk 7.1.1 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/bin/activate.js +2 -2
  2. package/bin/build.js +5 -2
  3. package/bin/compile/index.js +13 -5
  4. package/bin/env.js +0 -3
  5. package/bin/extend.js +25 -3
  6. package/bin/gen.js +27 -0
  7. package/bin/help.js +2 -1
  8. package/bin/import.js +7 -3
  9. package/bin/push.js +10 -6
  10. package/bin/watch.js +3 -4
  11. package/bin/watched.js +2 -3
  12. package/lib/bind/bindingUtil.js +1 -0
  13. package/lib/build/{buildTaskHandler.js → buildPlugin.js} +25 -30
  14. package/lib/build/buildTaskEngine.js +84 -89
  15. package/lib/build/buildTaskFactory.js +23 -44
  16. package/lib/build/buildTaskProvider.js +24 -19
  17. package/lib/build/buildTaskProviderFactory.js +176 -66
  18. package/lib/build/constants.js +6 -5
  19. package/lib/build/index.js +4 -3
  20. package/lib/build/provider/{buildTaskHandlerEdmx.js → edmxBuildPlugin.js} +6 -6
  21. package/lib/build/provider/{buildTaskHandlerFeatureToggles.js → featureToggleBuildPlugin.js} +3 -3
  22. package/lib/build/provider/fiori/index.js +5 -6
  23. package/lib/build/provider/hana/index.js +67 -36
  24. package/lib/build/provider/{buildTaskHandlerInternal.js → internalBuildPlugin.js} +11 -11
  25. package/lib/build/provider/{buildTaskProviderInternal.js → internalBuildTaskProvider.js} +42 -53
  26. package/lib/build/provider/java/index.js +24 -24
  27. package/lib/build/provider/mtx/index.js +4 -4
  28. package/lib/build/provider/mtx/resourcesTarBuilder.js +8 -8
  29. package/lib/build/provider/mtx-extension/index.js +17 -9
  30. package/lib/build/provider/mtx-sidecar/index.js +17 -11
  31. package/lib/build/provider/nodejs/index.js +63 -29
  32. package/lib/build/util.js +11 -19
  33. package/lib/client/auth_manager.js +6 -12
  34. package/lib/client/base_command.js +1 -1
  35. package/lib/client/download_legacy.js +48 -0
  36. package/lib/client/params.js +5 -0
  37. package/lib/client/push.js +41 -1
  38. package/lib/client/settings_manager.js +12 -3
  39. package/lib/compile/openapi/csdl2openapi.js +30 -21
  40. package/lib/compile/openapi/index.js +7 -3
  41. package/lib/env/schema.js +36 -0
  42. package/lib/env/schemas/cds-rc.json +101 -0
  43. package/lib/import/common.js +24 -11
  44. package/lib/import/importapi.js +2 -2
  45. package/lib/import/message.js +3 -1
  46. package/lib/import/odata/v4parser.js +23 -7
  47. package/lib/index.js +5 -0
  48. package/lib/init/constants.js +9 -12
  49. package/lib/init/index.js +86 -74
  50. package/lib/init/template/_merging/registry-mta.js +21 -12
  51. package/lib/init/template/approuter/files/mta.yaml.hbs +1 -1
  52. package/lib/init/template/approuter/index.js +3 -2
  53. package/lib/init/template/cf-manifest/files/services-manifest.yml.hbs +0 -5
  54. package/lib/init/template/cf-manifest/index.js +2 -2
  55. package/lib/init/template/connectivity/index.js +5 -4
  56. package/lib/init/template/destination/index.js +2 -5
  57. package/lib/init/template/h2/index.js +16 -0
  58. package/lib/init/template/hana/index.js +2 -3
  59. package/lib/init/template/helm/chart/values.root.schema.json +0 -5
  60. package/lib/init/template/helm/chart/values.schema.json +0 -4
  61. package/lib/init/template/helm/index.js +1 -1
  62. package/lib/init/template/html5-repo/index.js +27 -3
  63. package/lib/init/template/lint/index.js +3 -7
  64. package/lib/init/template/mta/index.js +9 -3
  65. package/lib/init/template/multitenancy/files/package.json.hbs +0 -3
  66. package/lib/init/template/multitenancy/index.js +2 -0
  67. package/lib/init/template/nodejs/index.js +3 -3
  68. package/lib/init/template/pipeline/index.js +2 -4
  69. package/lib/init/template/postgres/files/mta.yaml.hbs +27 -0
  70. package/lib/init/template/postgres/files/package.json.hbs +5 -0
  71. package/lib/init/template/postgres/index.js +52 -0
  72. package/lib/init/template/sample/index.js +5 -7
  73. package/lib/init/template/sqlite/index.js +8 -3
  74. package/lib/init/template/tiny-sample/index.js +16 -30
  75. package/lib/init/util/mvn.js +25 -1
  76. package/lib/init/util/projectReader.js +2 -7
  77. package/lib/init/util/template.js +7 -6
  78. package/lib/util/pruneAxiosErrors.js +22 -8
  79. package/lib/watch/node-watch.js +6 -1
  80. package/npm-shrinkwrap.json +2207 -384
  81. package/package.json +3 -3
  82. package/lib/init/template/auditlog/files/mta.yaml.hbs +0 -14
  83. package/lib/init/template/auditlog/files/package.json.hbs +0 -27
  84. package/lib/init/template/auditlog/index.js +0 -74
@@ -5,35 +5,33 @@ const { sortMessagesSeverityAware, deduplicateMessages, CompilationError } = cds
5
5
  const { relativePaths, BuildError, resolveRequiredSapModels } = require('./util')
6
6
  const { SEVERITIES, LOG_LEVELS } = require('./constants')
7
7
  const BuildTaskFactory = require('./buildTaskFactory')
8
- const BuildTaskProviderFactory = require('./buildTaskProviderFactory')
9
- const BuildTaskHandlerInternal = require('./provider/buildTaskHandlerInternal')
8
+ const InternalBuildPlugin = require('./provider/internalBuildPlugin')
10
9
 
11
10
  const COMPILATION_ERROR = 'CompilationError'
12
11
  const COMPILE_MESSAGE = 'CompileMessage'
13
12
 
14
13
  class BuildTaskEngine {
15
14
  constructor(options) {
16
- this._providerFactory = new BuildTaskProviderFactory(options)
15
+ this._taskFactory = new BuildTaskFactory(options)
17
16
  }
18
- get providerFactory() {
19
- return this._providerFactory
17
+ get taskFactory() {
18
+ return this._taskFactory
20
19
  }
21
20
  get logger() {
22
- return this.providerFactory.logger
21
+ return this.taskFactory.logger
23
22
  }
24
- get buildOptions() {
25
- return this.providerFactory.buildOptions
23
+ get options() {
24
+ return this.taskFactory.options
26
25
  }
27
26
 
28
27
  async processTasks(tasks) {
29
28
  const startTime = Date.now()
30
29
 
31
- this.logger.log(`building project [${cds.root}], clean [${this.buildOptions.clean}]`)
30
+ this.logger.log(`building project [${cds.root}], clean [${this.options.clean}]`)
32
31
  this.logger.log(`cds-dk [${require('../../package.json').version}], cds [${cds.version}], compiler [${cds.compiler.version()}], home [${cds.home}]\n`)
33
32
 
34
33
  if (!tasks) {
35
- const buildTaskFactory = new BuildTaskFactory(this.buildOptions)
36
- tasks = await buildTaskFactory.getTasks()
34
+ tasks = await this.taskFactory.getTasks()
37
35
  }
38
36
 
39
37
  // validate required @sap namespace models - log only
@@ -42,69 +40,66 @@ class BuildTaskEngine {
42
40
  throw new BuildError(`Required CDS models [${unresolved.join(', ')}] cannot be resolved. Make sure up-to-date versions of the missing modules are installed.`)
43
41
  }
44
42
 
45
- // create build task handlers
46
- const handlers = []
43
+ // create build plugins
44
+ const plugins = []
47
45
  tasks.forEach((task) => {
48
46
  if (task) {
49
- const handler = this._createHandler(task)
50
- handlers.push(handler)
47
+ const plugin = this._createPlugin(task)
48
+ plugins.push(plugin)
51
49
  }
52
50
  })
53
51
 
54
- // use resolved tasks
55
- this.providerFactory.context.tasks = handlers.map(handler => handler.task)
56
-
57
52
  try {
58
- await this._executePrepare(handlers)
59
- await this._executeCleanBuildTasks(handlers)
53
+ await this._executePrepare(plugins)
54
+ await this._executeCleanBuildTasks(plugins)
60
55
 
61
56
  // throwing Exception in case of compilation errors
62
- const buildResult = await this._executeBuildTasks(handlers)
57
+ const buildResult = await this._executeBuildTasks(plugins)
63
58
 
64
- await this._writeGenerationLog(handlers)
65
- this._logBuildOutput(handlers)
66
- this._logMessages(BuildTaskEngine._getHandlerMessages(handlers))
59
+ await this._writeGenerationLog(plugins)
60
+ this._logOutput(plugins)
61
+ this._logMessages(BuildTaskEngine._getMessages(plugins))
67
62
  this._logTimer(startTime, Date.now())
68
63
 
69
64
  return buildResult
70
65
  } catch (error) {
71
- this._logBuildOutput(handlers)
66
+ this._logOutput(plugins)
72
67
  throw error
73
68
  }
74
69
  }
75
70
 
76
71
  /**
77
- * BuildTaskHandler#prepare has been deprecated and was never part of the public API.
78
- * Currently only used by internal FioriBuildTaskHandler.
72
+ * BuildPlugin#prepare has been deprecated and was never part of the public API.
73
+ * Currently only used by internal FioriBuildPlugin.
79
74
  * @deprecated
80
- * @param {*} handlers
75
+ * @param {*} plugins
81
76
  * @returns
82
77
  */
83
- async _executePrepare(handlers) {
84
- const handlerGroups = new Map()
78
+ async _executePrepare(plugins) {
79
+ const pluginGroups = new Map()
85
80
 
86
- // group handlers by type
87
- handlers.forEach(handler => {
88
- handlerGroups.has(handler.task.for) ? handlerGroups.get(handler.task.for).push(handler) : handlerGroups.set(handler.task.for, [handler])
81
+ // group plugins by type
82
+ plugins.forEach(plugin => {
83
+ pluginGroups.has(plugin.task.for) ? pluginGroups.get(plugin.task.for).push(plugin) : pluginGroups.set(plugin.task.for, [plugin])
89
84
  })
90
85
 
91
86
  const promises = []
92
- for (let handlerGroup of handlerGroups.values()) {
93
- promises.push(this._doPrepare(handlerGroup))
87
+ for (let pluginGroup of pluginGroups.values()) {
88
+ promises.push(this._doPrepare(pluginGroup))
94
89
  }
95
90
  return Promise.all(promises)
96
91
  }
97
92
 
98
93
  /**
99
94
  * @deprecated
100
- * @param {*} handlerGroup
95
+ * @param {*} pluginGroup
101
96
  */
102
- async _doPrepare(handlerGroup) {
103
- for (let handler of handlerGroup) {
97
+ async _doPrepare(pluginGroup) {
98
+ for (let plugin of pluginGroup) {
104
99
  // prepare has been deprecated
105
- if (handler instanceof BuildTaskHandlerInternal) {
106
- this.logger._debug && this.logger.debug(`preparing, handler [${handler.constructor.name}], src [${relativePaths(cds.root, handler.task.src)}]`)
107
- const result = await handler.prepare()
100
+ if (plugin instanceof InternalBuildPlugin) {
101
+ this.logger._debug && this.logger.debug(`preparing, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
102
+ const result = await plugin.prepare()
108
103
  if (result === false) {
109
104
  break
110
105
  }
@@ -112,8 +107,8 @@ class BuildTaskEngine {
112
107
  }
113
108
  }
114
109
 
115
- async _executeCleanBuildTasks(handlers) {
116
- if (this.buildOptions.clean) {
110
+ async _executeCleanBuildTasks(plugins) {
111
+ if (this.options.clean) {
117
112
  // clean entire build staging folder once
118
113
  if (cds.env.build.target !== '.') {
119
114
  const target = path.resolve(cds.root, cds.env.build.target)
@@ -121,30 +116,30 @@ class BuildTaskEngine {
121
116
  await fs.promises.rm(target, { force: true, recursive: true })
122
117
  }
123
118
 
124
- const results = await Promise.allSettled(handlers.map((handler) => {
125
- this.logger._debug && this.logger.debug(`cleaning, handler [${handler.constructor.name}], src [${relativePaths(cds.root, handler.task.src)}]`)
126
- return handler.clean()
119
+ const results = await Promise.allSettled(plugins.map((plugin) => {
120
+ this.logger._debug && this.logger.debug(`cleaning, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
121
+ return plugin.clean()
127
122
  }))
128
123
  // check for errors and throw exception
129
124
  this._resolveHandlerResponse(results)
130
125
  }
131
126
  }
132
127
 
133
- async _executeBuildTasks(handlers) {
134
- // sort handlers based on priority in
135
- handlers = handlers.sort((a, b) => {
128
+ async _executeBuildTasks(plugins) {
129
+ // sort plugins based on priority in
130
+ plugins = plugins.sort((a, b) => {
136
131
  return a.priority === b.priority ? 0 : a.priority > b.priority ? -1 : 1
137
132
  })
138
- // group handlers with same priority in order to execute in parallel
139
- const buildPipeline = handlers.reduce((acc, handler) => {
133
+ // group plugins with same priority in order to execute in parallel
134
+ const buildPipeline = plugins.reduce((acc, plugin) => {
140
135
  if (acc.length === 0) {
141
- acc.push([handler])
136
+ acc.push([plugin])
142
137
  } else {
143
138
  const currGroup = acc[acc.length - 1]
144
- if (currGroup[0].priority === handler.priority) {
145
- currGroup.push(handler)
139
+ if (currGroup[0].priority === plugin.priority) {
140
+ currGroup.push(plugin)
146
141
  } else {
147
- acc.push([handler])
142
+ acc.push([plugin])
148
143
  }
149
144
  }
150
145
  return acc
@@ -153,20 +148,20 @@ class BuildTaskEngine {
153
148
  const results = await this._executePipeline(buildPipeline)
154
149
 
155
150
  // check for errors and throw exception - return results otherwise including any compiler and build status messages
156
- return this._resolveHandlerResponse(results, BuildTaskEngine._getHandlerMessages(handlers))
151
+ return this._resolveHandlerResponse(results, BuildTaskEngine._getMessages(plugins))
157
152
  }
158
153
 
159
154
  async _executePipeline(pipeline) {
160
155
  let allResults = []
161
156
  for (const group of pipeline) {
162
- const results = await Promise.allSettled(group.map((handler) => {
163
- this.logger._debug && this.logger.debug(`building, handler [${handler.constructor.name}], src [${relativePaths(cds.root, handler.task.src)}]`)
164
- return handler.build()
165
- .then(handlerResult => {
157
+ const results = await Promise.allSettled(group.map((plugin) => {
158
+ this.logger._debug && this.logger.debug(`building, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
159
+ return plugin.build()
160
+ .then(pluginResult => {
166
161
  return Promise.resolve({
167
- task: handler.task,
168
- result: handlerResult,
169
- messages: this._sortMessagesUnique(handler.messages)
162
+ task: plugin.task,
163
+ result: pluginResult,
164
+ messages: this._sortMessagesUnique(plugin.messages)
170
165
  })
171
166
  })
172
167
  }))
@@ -175,7 +170,7 @@ class BuildTaskEngine {
175
170
  return allResults
176
171
  }
177
172
 
178
- _resolveHandlerResponse(results, handlerMessages = []) {
173
+ _resolveHandlerResponse(results, pluginMessages = []) {
179
174
  const errors = []
180
175
  const resolvedResults = results.reduce((acc, r) => {
181
176
  if (r.status === 'fulfilled') {
@@ -197,9 +192,9 @@ class BuildTaskEngine {
197
192
 
198
193
  // propagate existing CompilationErrors
199
194
  // merge all existing compilation messages into a single CompilationError
200
- // compiler warning and info messages are returned as handler messages
195
+ // compiler warning and info messages are returned as plugin messages
201
196
  const compileErrors = errors.filter(e => e.constructor.name === COMPILATION_ERROR)
202
- const compileMessages = handlerMessages.filter(message => message.constructor.name === COMPILE_MESSAGE)
197
+ const compileMessages = pluginMessages.filter(message => message.constructor.name === COMPILE_MESSAGE)
203
198
  if (compileErrors.length) {
204
199
  throw new CompilationError(this._sortMessagesUnique(BuildTaskEngine._getErrorMessages(compileErrors), compileMessages))
205
200
  }
@@ -207,31 +202,31 @@ class BuildTaskEngine {
207
202
  return resolvedResults
208
203
  }
209
204
 
210
- _createHandler(task) {
211
- const handler = this.providerFactory.createHandler(task)
212
- handler.init()
205
+ _createPlugin(task) {
206
+ const plugin = this.taskFactory.createPlugin(task)
207
+ plugin.init()
213
208
 
214
- if (!(handler instanceof BuildTaskHandlerInternal) && handler.priority !== 1) {
215
- // Custom build handlers are executed before internal handlers to ensure
209
+ if (!(plugin instanceof InternalBuildPlugin) && plugin.priority !== 1) {
210
+ // Custom build plugins are executed before internal plugins to ensure
216
211
  // that generated content cannot be overwritten by mistake
217
- throw new Error(`Illegal priority for ${handler.constructor.name} encountered for custom handler - in this version only priority value '1' is allowed`)
212
+ throw new Error(`Illegal priority for ${plugin.constructor.name} encountered for custom plugin - in this version only priority value '1' is allowed`)
218
213
  }
219
- this._logTaskHandler(handler)
220
- return handler
214
+ this._logTaskHandler(plugin)
215
+ return plugin
221
216
  }
222
217
 
223
- _logBuildOutput(handlers) {
218
+ _logOutput(plugins) {
224
219
  // log all generated files
225
- const files = BuildTaskEngine._getBuildOutput(handlers)
220
+ const files = BuildTaskEngine._getOutput(plugins)
226
221
  if (files.length > 0) {
227
222
  this.logger.log(`done > wrote output to:\n ${files.join("\n ")}\n`)
228
223
  }
229
224
  }
230
225
 
231
- async _writeGenerationLog(handlers) {
226
+ async _writeGenerationLog(plugins) {
232
227
  const outputFile = cds.env.build.outputfile || process.env.GENERATION_LOG
233
228
  if (outputFile) {
234
- const files = BuildTaskEngine._getBuildOutput(handlers)
229
+ const files = BuildTaskEngine._getOutput(plugins)
235
230
  this.logger.log(`writing generation log to [${outputFile}]\n`)
236
231
  try {
237
232
  await fs.promises.mkdir(path.dirname(outputFile), { recursive: true })
@@ -243,8 +238,8 @@ class BuildTaskEngine {
243
238
  }
244
239
  }
245
240
 
246
- static _getBuildOutput(handlers) {
247
- const files = handlers.reduce((acc, handler) => acc.concat(handler.files), []).sort()
241
+ static _getOutput(plugins) {
242
+ const files = plugins.reduce((acc, plugin) => acc.concat(plugin.files), []).sort()
248
243
  return files.map(file => {
249
244
  if (path.isAbsolute(cds.env.build.target)) {
250
245
  return file
@@ -257,9 +252,9 @@ class BuildTaskEngine {
257
252
  this.logger.log(`build completed in ${end - start} ms\n`)
258
253
  }
259
254
 
260
- _logTaskHandler(handler) {
261
- this.logger._debug && this.logger.debug(`handler ${handler.constructor.name}`)
262
- this.logger._debug && this.logger.debug(`details src [${relativePaths(cds.root, handler.task.src)}], dest [${relativePaths(cds.root, handler.task.dest)}], use [${handler.task.use}], options [${JSON.stringify(handler.task.options)}]`) //NOSONAR
255
+ _logTaskHandler(plugin) {
256
+ this.logger._debug && this.logger.debug(`plugin ${plugin.constructor.name}`)
257
+ this.logger._debug && this.logger.debug(`details src [${relativePaths(cds.root, plugin.task.src)}], dest [${relativePaths(cds.root, plugin.task.dest)}], use [${plugin.task.use}], options [${JSON.stringify(plugin.task.options)}]`) //NOSONAR
263
258
  }
264
259
 
265
260
  _logMessages(messages) {
@@ -308,17 +303,17 @@ class BuildTaskEngine {
308
303
  }
309
304
 
310
305
  /**
311
- * Returns compiler messages and validation messages issued by handlers.
312
- * @param {Array<BuildTaskHandler>} handlers
306
+ * Returns compiler messages and validation messages issued by plugins.
307
+ * @param {Array<BuildPlugin>} plugins
313
308
  */
314
- static _getHandlerMessages(handlers) {
315
- return handlers.reduce((acc, handler) => acc.concat(handler.messages), [])
309
+ static _getMessages(plugins) {
310
+ return plugins.reduce((acc, plugin) => acc.concat(plugin.messages), [])
316
311
  }
317
312
 
318
313
  /**
319
314
  * Sort and filter the given errors of type CompileMessage or BuildMessage according to their severity and location,
320
315
  * but leave any other errors untouched as part of the result array.<br>
321
- * The log level passed as 'buildOptions.log-level' or defined in 'cds.env' is used to filter the given messages.
316
+ * The log level ('command line' or 'cds.env' option) is used to filter the given messages.
322
317
  * @param {...Error} messages
323
318
  */
324
319
  _sortMessagesUnique(...messages) {
@@ -337,7 +332,7 @@ class BuildTaskEngine {
337
332
  * Return user defined log level or default value 'warn'
338
333
  */
339
334
  _getLogLevel() {
340
- return this.buildOptions["log-level"] || cds.env["log-level"]
335
+ return this.options["log-level"] || cds.env["log-level"]
341
336
  }
342
337
  }
343
338
  module.exports = BuildTaskEngine
@@ -15,8 +15,8 @@ class BuildTaskFactory {
15
15
  get logger() {
16
16
  return this.providerFactory.logger
17
17
  }
18
- get buildOptions() {
19
- return this.providerFactory.buildOptions
18
+ get options() {
19
+ return this.providerFactory.options
20
20
  }
21
21
 
22
22
  // the following order for determining build tasks is used
@@ -41,12 +41,16 @@ class BuildTaskFactory {
41
41
 
42
42
  // always resolve tasks for input validation
43
43
  const resolvedTasks = this.providerFactory.resolveTasks(tasks)
44
- if (this.buildOptions.resolve) {
44
+ if (this.options.resolve) {
45
45
  return resolvedTasks
46
46
  }
47
47
  return tasks
48
48
  }
49
49
 
50
+ createPlugin(task) {
51
+ return this.providerFactory.createPlugin(task)
52
+ }
53
+
50
54
  async _createTasks() {
51
55
  this.logger.debug(`determining build tasks for project [${cds.root}].`)
52
56
 
@@ -61,7 +65,7 @@ class BuildTaskFactory {
61
65
  // 1. apply default values including task.for and task.use and ensure that for all tasks a provider exists - throwing error otherwise
62
66
  await this.providerFactory.applyTaskDefaults(tasks)
63
67
  // ensure that dependencies get wired up before filtering
64
- await this.providerFactory.lookupTasks(tasks)
68
+ await this.providerFactory.lookupTasks(tasks, true)
65
69
  }
66
70
 
67
71
  // 3. filters the list of build tasks and adapts according to given CLI options
@@ -79,7 +83,7 @@ class BuildTaskFactory {
79
83
 
80
84
  // 2. add dependencies
81
85
  existingTasks = [...tasks]
82
- await this.providerFactory.lookupTasks(tasks)
86
+ await this.providerFactory.lookupTasks(tasks, true)
83
87
  if (tasks.length > existingTasks.length) {
84
88
  const newTasks = tasks.filter(task => !existingTasks.includes(task))
85
89
  // a dependant task was added
@@ -89,9 +93,6 @@ class BuildTaskFactory {
89
93
  // obligatory task defaults shared by all tasks
90
94
  BuildTaskFactory._applyCommonTaskDefaults(tasks)
91
95
 
92
- // ensure correct values for optional build task properties, error for missing mandatory properties
93
- BuildTaskFactory._validateBuildTasks(tasks)
94
-
95
96
  this._setDefaultBuildTargetFolder(tasks)
96
97
  return tasks
97
98
  }
@@ -111,14 +112,6 @@ class BuildTaskFactory {
111
112
  })
112
113
  }
113
114
 
114
- static _validateBuildTasks(tasks) {
115
- tasks.forEach(task => {
116
- if (!task.src) {
117
- throw new Error(`Invalid build task definition - value of property 'src' is missing in [${task.for || task.use}].`)
118
- }
119
- })
120
- }
121
-
122
115
  _setDefaultBuildTargetFolder(tasks) {
123
116
  const task = tasks.find(task => task.for === BUILD_TASK_JAVA_CF || task.for === BUILD_TASK_JAVA)
124
117
  const srv = task ? task.src : BuildTaskFactory._getModuleFolder(flatten([cds.env.folders.srv])) || "srv"
@@ -148,28 +141,22 @@ class BuildTaskFactory {
148
141
  }
149
142
 
150
143
  _applyCliOptionsFilter(tasks) {
151
- const buildOptions = this.buildOptions
144
+ const options = this.options
152
145
  // filter tasks using either option for, use, src
153
146
  let resultTasks = tasks.filter(task => {
154
- return (!buildOptions.use || buildOptions.use === task.use)
155
- && (!buildOptions.for || buildOptions.for === task.for)
156
- && (!buildOptions.src || buildOptions.src === task.src)
147
+ return (!options.use || options.use === task.use)
148
+ && (!options.for || options.for === task.for)
149
+ && (!options.src || options.src === task.src)
157
150
  })
158
151
  if (resultTasks.length === 0) {
159
- if (buildOptions.for || buildOptions.use) {
160
- const task = {}
161
- if ((buildOptions.for)) {
162
- task.for = buildOptions.for
163
- }
164
- if ((buildOptions.use)) {
165
- task.use = buildOptions.use
166
- }
167
- if (buildOptions.src) {
168
- task.src = buildOptions.src
152
+ if (options.for || options.use) {
153
+ const task = this.providerFactory.getTask(options.for ? { for: options.for } : { use: options.use })
154
+ if (options.src) {
155
+ task.src = options.src
169
156
  }
170
157
  resultTasks.push(task)
171
158
  }
172
- } else if (resultTasks.length < tasks.length) {
159
+ } else if (resultTasks.length <= tasks.length) {
173
160
  // return the same array as long as it contains a subset of the given tasks
174
161
  tasks.length = 0
175
162
  resultTasks.forEach(task => tasks.push(task))
@@ -180,14 +167,14 @@ class BuildTaskFactory {
180
167
  }
181
168
 
182
169
  _applyCliOptions(tasks) {
183
- const buildOptions = this.buildOptions
170
+ const options = this.options
184
171
  // apply remaining cli options to filtered tasks
185
172
  tasks.forEach(task => {
186
- if (buildOptions.dest) {
187
- task.dest = buildOptions.dest
173
+ if (options.dest) {
174
+ task.dest = options.dest
188
175
  }
189
- if (buildOptions.opts) {
190
- const opts = BuildTaskFactory._scanTaskOptionParams(buildOptions.opts)
176
+ if (options.opts) {
177
+ const opts = BuildTaskFactory._scanTaskOptionParams(options.opts)
191
178
  task.options = task.options ? Object.assign(task.options, opts) : opts
192
179
  }
193
180
  })
@@ -237,14 +224,6 @@ class BuildTaskFactory {
237
224
  return taskOptions
238
225
  }
239
226
 
240
- /**
241
- * For valid paths remove trailing '/'. Otherwise return as is - important!!
242
- * @param {*} dir
243
- */
244
- static _normalizePath(dir) {
245
- return typeof dir === "string" ? dir.replace(/\/$/, '') : dir
246
- }
247
-
248
227
  /**
249
228
  * Determines the module folder from the past list that may represent files or folders w or w/o .cds file extension.
250
229
  * @param {Array} filesOrFolders
@@ -1,22 +1,27 @@
1
1
  /* eslint-disable no-unused-vars */
2
+ /**
3
+ * @abstract
4
+ */
2
5
  module.exports = class BuildTaskProvider {
3
- constructor() {
4
- //injected by framework
5
- this._plugin = null
6
- }
7
- canHandleTask(task) {
8
- // return this._plugin.provides.includes(task.for || task.use && this._getTaskId(task.use))
9
- }
10
- loadHandler(task) {
11
- // return module.require(`${this._plugin.path}/${task.for || this._getTaskId(task.use)}`)
12
- }
13
- async lookupTasks(tasks) { }
14
- async applyTaskDefaults(task) {
15
- // task.for = task.for || this._getTaskId(task.use)
16
- }
17
- _getTaskId(use) {
18
- if (this._plugin && this._plugin.id) {
19
- return use.substring(this._plugin.id.length + 1)
20
- }
21
- }
6
+ /**
7
+ * @param {object} task
8
+ */
9
+ providesTask(key) { }
10
+ /**
11
+ * @returns {object} task
12
+ */
13
+ getTask(key) { return key }
14
+ /**
15
+ * @param {object} task
16
+ */
17
+ loadPlugin(task) { }
18
+ /**
19
+ * @param {Array} tasks
20
+ * @param {boolean} dependencies
21
+ */
22
+ async lookupTasks(tasks, dependencies) { }
23
+ /**
24
+ * @param {object} task
25
+ */
26
+ async applyTaskDefaults(task) { }
22
27
  }