processbuilder.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. const AdmZip = require('adm-zip')
  2. const child_process = require('child_process')
  3. const crypto = require('crypto')
  4. const fs = require('fs-extra')
  5. const os = require('os')
  6. const path = require('path')
  7. const { URL } = require('url')
  8. const { AssetGuard, Library } = require('./assetguard')
  9. const ConfigManager = require('./configmanager')
  10. const DistroManager = require('./distromanager')
  11. const LoggerUtil = require('./loggerutil')
  12. const logger = LoggerUtil('%c[ProcessBuilder]', 'color: #003996; font-weight: bold')
  13. class ProcessBuilder {
  14. constructor(distroServer, versionData, forgeData, authUser, launcherVersion){
  15. this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.getID())
  16. this.commonDir = ConfigManager.getCommonDirectory()
  17. this.server = distroServer
  18. this.versionData = versionData
  19. this.forgeData = forgeData
  20. this.authUser = authUser
  21. this.launcherVersion = launcherVersion
  22. this.fmlDir = path.join(this.gameDir, 'forgeModList.json')
  23. this.llDir = path.join(this.gameDir, 'liteloaderModList.json')
  24. this.libPath = path.join(this.commonDir, 'libraries')
  25. this.usingLiteLoader = false
  26. this.llPath = null
  27. }
  28. /**
  29. * Convienence method to run the functions typically used to build a process.
  30. */
  31. build(){
  32. fs.ensureDirSync(this.gameDir)
  33. const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
  34. process.throwDeprecation = true
  35. this.setupLiteLoader()
  36. logger.log('Using liteloader:', this.usingLiteLoader)
  37. const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.getID()).mods, this.server.getModules())
  38. this.constructModList('forge', modObj.fMods, true)
  39. if(this.usingLiteLoader){
  40. this.constructModList('liteloader', modObj.lMods, true)
  41. }
  42. const uberModArr = modObj.fMods.concat(modObj.lMods)
  43. const args = this.constructJVMArguments(uberModArr, tempNativePath)
  44. logger.log('Launch Arguments:', args)
  45. const child = child_process.spawn(ConfigManager.getJavaExecutable(), args, {
  46. cwd: this.gameDir,
  47. detached: ConfigManager.getLaunchDetached()
  48. })
  49. if(ConfigManager.getLaunchDetached()){
  50. child.unref()
  51. }
  52. child.stdout.setEncoding('utf8')
  53. child.stderr.setEncoding('utf8')
  54. const loggerMCstdout = LoggerUtil('%c[Minecraft]', 'color: #36b030; font-weight: bold')
  55. const loggerMCstderr = LoggerUtil('%c[Minecraft]', 'color: #b03030; font-weight: bold')
  56. child.stdout.on('data', (data) => {
  57. loggerMCstdout.log(data)
  58. })
  59. child.stderr.on('data', (data) => {
  60. loggerMCstderr.log(data)
  61. })
  62. child.on('close', (code, signal) => {
  63. logger.log('Exited with code', code)
  64. fs.remove(tempNativePath, (err) => {
  65. if(err){
  66. logger.warn('Error while deleting temp dir', err)
  67. } else {
  68. logger.log('Temp dir deleted successfully.')
  69. }
  70. })
  71. })
  72. return child
  73. }
  74. /**
  75. * Determine if an optional mod is enabled from its configuration value. If the
  76. * configuration value is null, the required object will be used to
  77. * determine if it is enabled.
  78. *
  79. * A mod is enabled if:
  80. * * The configuration is not null and one of the following:
  81. * * The configuration is a boolean and true.
  82. * * The configuration is an object and its 'value' property is true.
  83. * * The configuration is null and one of the following:
  84. * * The required object is null.
  85. * * The required object's 'def' property is null or true.
  86. *
  87. * @param {Object | boolean} modCfg The mod configuration object.
  88. * @param {Object} required Optional. The required object from the mod's distro declaration.
  89. * @returns {boolean} True if the mod is enabled, false otherwise.
  90. */
  91. static isModEnabled(modCfg, required = null){
  92. return modCfg != null ? ((typeof modCfg === 'boolean' && modCfg) || (typeof modCfg === 'object' && (typeof modCfg.value !== 'undefined' ? modCfg.value : true))) : required != null ? required.isDefault() : true
  93. }
  94. /**
  95. * Function which performs a preliminary scan of the top level
  96. * mods. If liteloader is present here, we setup the special liteloader
  97. * launch options. Note that liteloader is only allowed as a top level
  98. * mod. It must not be declared as a submodule.
  99. */
  100. setupLiteLoader(){
  101. for(let ll of this.server.getModules()){
  102. if(ll.getType() === DistroManager.Types.LiteLoader){
  103. if(!ll.getRequired().isRequired()){
  104. const modCfg = ConfigManager.getModConfiguration(this.server.getID()).mods
  105. if(ProcessBuilder.isModEnabled(modCfg[ll.getVersionlessID()], ll.getRequired())){
  106. if(fs.existsSync(ll.getArtifact().getPath())){
  107. this.usingLiteLoader = true
  108. this.llPath = ll.getArtifact().getPath()
  109. }
  110. }
  111. } else {
  112. if(fs.existsSync(ll.getArtifact().getPath())){
  113. this.usingLiteLoader = true
  114. this.llPath = ll.getArtifact().getPath()
  115. }
  116. }
  117. }
  118. }
  119. }
  120. /**
  121. * Resolve an array of all enabled mods. These mods will be constructed into
  122. * a mod list format and enabled at launch.
  123. *
  124. * @param {Object} modCfg The mod configuration object.
  125. * @param {Array.<Object>} mdls An array of modules to parse.
  126. * @returns {{fMods: Array.<Object>, lMods: Array.<Object>}} An object which contains
  127. * a list of enabled forge mods and litemods.
  128. */
  129. resolveModConfiguration(modCfg, mdls){
  130. let fMods = []
  131. let lMods = []
  132. for(let mdl of mdls){
  133. const type = mdl.getType()
  134. if(type === DistroManager.Types.ForgeMod || type === DistroManager.Types.LiteMod || type === DistroManager.Types.LiteLoader){
  135. const o = !mdl.getRequired().isRequired()
  136. const e = ProcessBuilder.isModEnabled(modCfg[mdl.getVersionlessID()], mdl.getRequired())
  137. if(!o || (o && e)){
  138. if(mdl.hasSubModules()){
  139. const v = this.resolveModConfiguration(modCfg[mdl.getVersionlessID()].mods, mdl.getSubModules())
  140. fMods = fMods.concat(v.fMods)
  141. lMods = lMods.concat(v.lMods)
  142. if(mdl.type === DistroManager.Types.LiteLoader){
  143. continue
  144. }
  145. }
  146. if(mdl.type === DistroManager.Types.ForgeMod){
  147. fMods.push(mdl)
  148. } else {
  149. lMods.push(mdl)
  150. }
  151. }
  152. }
  153. }
  154. return {
  155. fMods,
  156. lMods
  157. }
  158. }
  159. /**
  160. * Test to see if this version of forge requires the absolute: prefix
  161. * on the modListFile repository field.
  162. */
  163. _requiresAbsolute(){
  164. try {
  165. const ver = this.forgeData.id.split('-')[2]
  166. const pts = ver.split('.')
  167. const min = [14, 23, 3, 2655]
  168. for(let i=0; i<pts.length; i++){
  169. const parsed = Number.parseInt(pts[i])
  170. if(parsed < min[i]){
  171. return false
  172. } else if(parsed > min[i]){
  173. return true
  174. }
  175. }
  176. } catch (err) {
  177. // We know old forge versions follow this format.
  178. // Error must be caused by newer version.
  179. }
  180. // Equal or errored
  181. return true
  182. }
  183. /**
  184. * Construct a mod list json object.
  185. *
  186. * @param {'forge' | 'liteloader'} type The mod list type to construct.
  187. * @param {Array.<Object>} mods An array of mods to add to the mod list.
  188. * @param {boolean} save Optional. Whether or not we should save the mod list file.
  189. */
  190. constructModList(type, mods, save = false){
  191. const modList = {
  192. repositoryRoot: ((type === 'forge' && this._requiresAbsolute()) ? 'absolute:' : '') + path.join(this.commonDir, 'modstore')
  193. }
  194. const ids = []
  195. if(type === 'forge'){
  196. for(let mod of mods){
  197. ids.push(mod.getExtensionlessID())
  198. }
  199. } else {
  200. for(let mod of mods){
  201. ids.push(mod.getExtensionlessID() + '@' + mod.getExtension())
  202. }
  203. }
  204. modList.modRef = ids
  205. if(save){
  206. const json = JSON.stringify(modList, null, 4)
  207. fs.writeFileSync(type === 'forge' ? this.fmlDir : this.llDir, json, 'UTF-8')
  208. }
  209. return modList
  210. }
  211. /**
  212. * Construct the argument array that will be passed to the JVM process.
  213. *
  214. * @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
  215. * @param {string} tempNativePath The path to store the native libraries.
  216. * @returns {Array.<string>} An array containing the full JVM arguments for this process.
  217. */
  218. constructJVMArguments(mods, tempNativePath){
  219. if(AssetGuard.mcVersionAtLeast('1.13', this.server.getMinecraftVersion())){
  220. return this._constructJVMArguments113(mods, tempNativePath)
  221. } else {
  222. return this._constructJVMArguments112(mods, tempNativePath)
  223. }
  224. }
  225. /**
  226. * Construct the argument array that will be passed to the JVM process.
  227. * This function is for 1.12 and below.
  228. *
  229. * @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
  230. * @param {string} tempNativePath The path to store the native libraries.
  231. * @returns {Array.<string>} An array containing the full JVM arguments for this process.
  232. */
  233. _constructJVMArguments112(mods, tempNativePath){
  234. let args = []
  235. // Classpath Argument
  236. args.push('-cp')
  237. args.push(this.classpathArg(mods, tempNativePath).join(process.platform === 'win32' ? ';' : ':'))
  238. // Java Arguments
  239. if(process.platform === 'darwin'){
  240. args.push('-Xdock:name=WesterosCraft')
  241. args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
  242. }
  243. args.push('-Xmx' + ConfigManager.getMaxRAM())
  244. args.push('-Xms' + ConfigManager.getMinRAM())
  245. args = args.concat(ConfigManager.getJVMOptions())
  246. args.push('-Djava.library.path=' + tempNativePath)
  247. // Main Java Class
  248. args.push(this.forgeData.mainClass)
  249. // Forge Arguments
  250. args = args.concat(this._resolveForgeArgs())
  251. return args
  252. }
  253. /**
  254. * Construct the argument array that will be passed to the JVM process.
  255. * This function is for 1.13+
  256. *
  257. * Note: Required Libs https://github.com/MinecraftForge/MinecraftForge/blob/af98088d04186452cb364280340124dfd4766a5c/src/fmllauncher/java/net/minecraftforge/fml/loading/LibraryFinder.java#L82
  258. *
  259. * @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
  260. * @param {string} tempNativePath The path to store the native libraries.
  261. * @returns {Array.<string>} An array containing the full JVM arguments for this process.
  262. */
  263. _constructJVMArguments113(mods, tempNativePath){
  264. const argDiscovery = /\${*(.*)}/
  265. // JVM Arguments First
  266. let args = this.versionData.arguments.jvm
  267. // Java Arguments
  268. if(process.platform === 'darwin'){
  269. args.push('-Xdock:name=WesterosCraft')
  270. args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
  271. }
  272. args.push('-Xmx' + ConfigManager.getMaxRAM())
  273. args.push('-Xms' + ConfigManager.getMinRAM())
  274. args = args.concat(ConfigManager.getJVMOptions())
  275. // Main Java Class
  276. args.push(this.forgeData.mainClass)
  277. // Vanilla Arguments
  278. args = args.concat(this.versionData.arguments.game)
  279. for(let i=0; i<args.length; i++){
  280. if(typeof args[i] === 'object' && args[i].rules != null){
  281. let checksum = 0
  282. for(let rule of args[i].rules){
  283. if(rule.os != null){
  284. if(rule.os.name === Library.mojangFriendlyOS()
  285. && (rule.os.version == null || new RegExp(rule.os.version).test(os.release))){
  286. if(rule.action === 'allow'){
  287. checksum++
  288. }
  289. } else {
  290. if(rule.action === 'disallow'){
  291. checksum++
  292. }
  293. }
  294. } else if(rule.features != null){
  295. // We don't have many 'features' in the index at the moment.
  296. // This should be fine for a while.
  297. if(rule.features.has_custom_resolution != null && rule.features.has_custom_resolution === true){
  298. if(ConfigManager.getFullscreen()){
  299. rule.values = [
  300. '--fullscreen',
  301. 'true'
  302. ]
  303. }
  304. checksum++
  305. }
  306. }
  307. }
  308. // TODO splice not push
  309. if(checksum === args[i].rules.length){
  310. if(typeof args[i].value === 'string'){
  311. args[i] = args[i].value
  312. } else if(typeof args[i].value === 'object'){
  313. //args = args.concat(args[i].value)
  314. args.splice(i, 1, ...args[i].value)
  315. }
  316. // Decrement i to reprocess the resolved value
  317. i--
  318. } else {
  319. args[i] = null
  320. }
  321. } else if(typeof args[i] === 'string'){
  322. if(argDiscovery.test(args[i])){
  323. const identifier = args[i].match(argDiscovery)[1]
  324. let val = null
  325. switch(identifier){
  326. case 'auth_player_name':
  327. val = this.authUser.displayName.trim()
  328. break
  329. case 'version_name':
  330. //val = versionData.id
  331. val = this.server.getID()
  332. break
  333. case 'game_directory':
  334. val = this.gameDir
  335. break
  336. case 'assets_root':
  337. val = path.join(this.commonDir, 'assets')
  338. break
  339. case 'assets_index_name':
  340. val = this.versionData.assets
  341. break
  342. case 'auth_uuid':
  343. val = this.authUser.uuid.trim()
  344. break
  345. case 'auth_access_token':
  346. val = this.authUser.accessToken
  347. break
  348. case 'user_type':
  349. val = 'mojang'
  350. break
  351. case 'version_type':
  352. val = this.versionData.type
  353. break
  354. case 'resolution_width':
  355. val = ConfigManager.getGameWidth()
  356. break
  357. case 'resolution_height':
  358. val = ConfigManager.getGameHeight()
  359. break
  360. case 'natives_directory':
  361. val = args[i].replace(argDiscovery, tempNativePath)
  362. break
  363. case 'launcher_name':
  364. val = args[i].replace(argDiscovery, 'WesterosCraft-Launcher')
  365. break
  366. case 'launcher_version':
  367. val = args[i].replace(argDiscovery, this.launcherVersion)
  368. break
  369. case 'classpath':
  370. val = this.classpathArg(mods, tempNativePath).join(process.platform === 'win32' ? ';' : ':')
  371. break
  372. }
  373. if(val != null){
  374. args[i] = val
  375. }
  376. }
  377. }
  378. }
  379. // Forge Specific Arguments
  380. args = args.concat(this.forgeData.arguments.game)
  381. // Filter null values
  382. args = args.filter(arg => {
  383. return arg != null
  384. })
  385. return args
  386. }
  387. /**
  388. * Resolve the arguments required by forge.
  389. *
  390. * @returns {Array.<string>} An array containing the arguments required by forge.
  391. */
  392. _resolveForgeArgs(){
  393. const mcArgs = this.forgeData.minecraftArguments.split(' ')
  394. const argDiscovery = /\${*(.*)}/
  395. // Replace the declared variables with their proper values.
  396. for(let i=0; i<mcArgs.length; ++i){
  397. if(argDiscovery.test(mcArgs[i])){
  398. const identifier = mcArgs[i].match(argDiscovery)[1]
  399. let val = null
  400. switch(identifier){
  401. case 'auth_player_name':
  402. val = this.authUser.displayName.trim()
  403. break
  404. case 'version_name':
  405. //val = versionData.id
  406. val = this.server.getID()
  407. break
  408. case 'game_directory':
  409. val = this.gameDir
  410. break
  411. case 'assets_root':
  412. val = path.join(this.commonDir, 'assets')
  413. break
  414. case 'assets_index_name':
  415. val = this.versionData.assets
  416. break
  417. case 'auth_uuid':
  418. val = this.authUser.uuid.trim()
  419. break
  420. case 'auth_access_token':
  421. val = this.authUser.accessToken
  422. break
  423. case 'user_type':
  424. val = 'mojang'
  425. break
  426. case 'version_type':
  427. val = this.versionData.type
  428. break
  429. }
  430. if(val != null){
  431. mcArgs[i] = val
  432. }
  433. }
  434. }
  435. // Autoconnect to the selected server.
  436. if(ConfigManager.getAutoConnect() && this.server.isAutoConnect()){
  437. const serverURL = new URL('my://' + this.server.getAddress())
  438. mcArgs.push('--server')
  439. mcArgs.push(serverURL.hostname)
  440. if(serverURL.port){
  441. mcArgs.push('--port')
  442. mcArgs.push(serverURL.port)
  443. }
  444. }
  445. // Prepare game resolution
  446. if(ConfigManager.getFullscreen()){
  447. mcArgs.push('--fullscreen')
  448. mcArgs.push(true)
  449. } else {
  450. mcArgs.push('--width')
  451. mcArgs.push(ConfigManager.getGameWidth())
  452. mcArgs.push('--height')
  453. mcArgs.push(ConfigManager.getGameHeight())
  454. }
  455. // Mod List File Argument
  456. mcArgs.push('--modListFile')
  457. mcArgs.push('absolute:' + this.fmlDir)
  458. // LiteLoader
  459. if(this.usingLiteLoader){
  460. mcArgs.push('--modRepo')
  461. mcArgs.push(this.llDir)
  462. // Set first arg to liteloader tweak class
  463. mcArgs.unshift('com.mumfrey.liteloader.launch.LiteLoaderTweaker')
  464. mcArgs.unshift('--tweakClass')
  465. }
  466. return mcArgs
  467. }
  468. /**
  469. * Resolve the full classpath argument list for this process. This method will resolve all Mojang-declared
  470. * libraries as well as the libraries declared by the server. Since mods are permitted to declare libraries,
  471. * this method requires all enabled mods as an input
  472. *
  473. * @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
  474. * @param {string} tempNativePath The path to store the native libraries.
  475. * @returns {Array.<string>} An array containing the paths of each library required by this process.
  476. */
  477. classpathArg(mods, tempNativePath){
  478. let cpArgs = []
  479. // Add the version.jar to the classpath.
  480. const version = this.versionData.id
  481. cpArgs.push(path.join(this.commonDir, 'versions', version, version + '.jar'))
  482. if(this.usingLiteLoader){
  483. cpArgs.push(this.llPath)
  484. }
  485. // Resolve the Mojang declared libraries.
  486. const mojangLibs = this._resolveMojangLibraries(tempNativePath)
  487. cpArgs = cpArgs.concat(mojangLibs)
  488. // Resolve the server declared libraries.
  489. const servLibs = this._resolveServerLibraries(mods)
  490. cpArgs = cpArgs.concat(servLibs)
  491. return cpArgs
  492. }
  493. /**
  494. * Resolve the libraries defined by Mojang's version data. This method will also extract
  495. * native libraries and point to the correct location for its classpath.
  496. *
  497. * TODO - clean up function
  498. *
  499. * @param {string} tempNativePath The path to store the native libraries.
  500. * @returns {Array.<string>} An array containing the paths of each library mojang declares.
  501. */
  502. _resolveMojangLibraries(tempNativePath){
  503. const libs = []
  504. const libArr = this.versionData.libraries
  505. fs.ensureDirSync(tempNativePath)
  506. for(let i=0; i<libArr.length; i++){
  507. const lib = libArr[i]
  508. if(Library.validateRules(lib.rules, lib.natives)){
  509. if(lib.natives == null){
  510. const dlInfo = lib.downloads
  511. const artifact = dlInfo.artifact
  512. const to = path.join(this.libPath, artifact.path)
  513. libs.push(to)
  514. } else {
  515. // Extract the native library.
  516. const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/']
  517. const artifact = lib.downloads.classifiers[lib.natives[Library.mojangFriendlyOS()].replace('${arch}', process.arch.replace('x', ''))]
  518. // Location of native zip.
  519. const to = path.join(this.libPath, artifact.path)
  520. let zip = new AdmZip(to)
  521. let zipEntries = zip.getEntries()
  522. // Unzip the native zip.
  523. for(let i=0; i<zipEntries.length; i++){
  524. const fileName = zipEntries[i].entryName
  525. let shouldExclude = false
  526. // Exclude noted files.
  527. exclusionArr.forEach(function(exclusion){
  528. if(fileName.indexOf(exclusion) > -1){
  529. shouldExclude = true
  530. }
  531. })
  532. // Extract the file.
  533. if(!shouldExclude){
  534. fs.writeFile(path.join(tempNativePath, fileName), zipEntries[i].getData(), (err) => {
  535. if(err){
  536. logger.error('Error while extracting native library:', err)
  537. }
  538. })
  539. }
  540. }
  541. }
  542. }
  543. }
  544. return libs
  545. }
  546. /**
  547. * Resolve the libraries declared by this server in order to add them to the classpath.
  548. * This method will also check each enabled mod for libraries, as mods are permitted to
  549. * declare libraries.
  550. *
  551. * @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
  552. * @returns {Array.<string>} An array containing the paths of each library this server requires.
  553. */
  554. _resolveServerLibraries(mods){
  555. const mdls = this.server.getModules()
  556. let libs = []
  557. // Locate Forge/Libraries
  558. for(let mdl of mdls){
  559. const type = mdl.getType()
  560. if(type === DistroManager.Types.ForgeHosted || type === DistroManager.Types.Library){
  561. libs.push(mdl.getArtifact().getPath())
  562. if(mdl.hasSubModules()){
  563. const res = this._resolveModuleLibraries(mdl)
  564. if(res.length > 0){
  565. libs = libs.concat(res)
  566. }
  567. }
  568. }
  569. }
  570. //Check for any libraries in our mod list.
  571. for(let i=0; i<mods.length; i++){
  572. if(mods.sub_modules != null){
  573. const res = this._resolveModuleLibraries(mods[i])
  574. if(res.length > 0){
  575. libs = libs.concat(res)
  576. }
  577. }
  578. }
  579. return libs
  580. }
  581. /**
  582. * Recursively resolve the path of each library required by this module.
  583. *
  584. * @param {Object} mdl A module object from the server distro index.
  585. * @returns {Array.<string>} An array containing the paths of each library this module requires.
  586. */
  587. _resolveModuleLibraries(mdl){
  588. if(!mdl.hasSubModules()){
  589. return []
  590. }
  591. let libs = []
  592. for(let sm of mdl.getSubModules()){
  593. if(sm.getType() === DistroManager.Types.Library){
  594. libs.push(sm.getArtifact().getPath())
  595. }
  596. // If this module has submodules, we need to resolve the libraries for those.
  597. // To avoid unnecessary recursive calls, base case is checked here.
  598. if(mdl.hasSubModules()){
  599. const res = this._resolveModuleLibraries(sm)
  600. if(res.length > 0){
  601. libs = libs.concat(res)
  602. }
  603. }
  604. }
  605. return libs
  606. }
  607. }
  608. module.exports = ProcessBuilder