diff --git a/libraries/java/Claritas.jar b/libraries/java/Claritas.jar index 619fa03..c390769 100644 Binary files a/libraries/java/Claritas.jar and b/libraries/java/Claritas.jar differ diff --git a/package-lock.json b/package-lock.json index ed3ca54..fcd7b58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1408,9 +1408,9 @@ "dev": true }, "typescript": { - "version": "3.9.6", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.6.tgz", - "integrity": "sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", + "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", "dev": true }, "universalify": { diff --git a/package.json b/package.json index 2927e24..27a06ad 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@typescript-eslint/parser": "^3.6.1", "eslint": "^7.4.0", "rimraf": "^3.0.2", - "typescript": "^3.9.6" + "typescript": "^3.9.7" }, "dependencies": { "axios": "^0.19.2", diff --git a/src/model/struct/model/module/module.struct.ts b/src/model/struct/model/module/module.struct.ts index 548b236..5907d4f 100644 --- a/src/model/struct/model/module/module.struct.ts +++ b/src/model/struct/model/module/module.struct.ts @@ -128,7 +128,7 @@ export abstract class ModuleStructure extends BaseModelStructure { protected async invokeClaritas(moduleCandidates: ModuleCandidate[]): Promise { if(this.getClaritasType() != null) { - const claritasExecutor = new ClaritasWrapper() + const claritasExecutor = new ClaritasWrapper(this.absoluteRoot) let claritasCandidates = moduleCandidates const exceptionCandidates: [ModuleCandidate, ClaritasException][] = [] diff --git a/src/util/java/ClaritasWrapper.ts b/src/util/java/ClaritasWrapper.ts index 6c97e9d..ad5475f 100644 --- a/src/util/java/ClaritasWrapper.ts +++ b/src/util/java/ClaritasWrapper.ts @@ -1,20 +1,36 @@ import { JarExecutor } from './JarExecutor' -import { join } from 'path' +import { join, resolve } from 'path' import { ClaritasResult } from '../../model/claritas/ClaritasResult' import { MinecraftVersion } from '../MinecraftVersion' import { LibraryType } from '../../model/claritas/ClaritasLibraryType' +import { pathExists, remove, readFile } from 'fs-extra' export class ClaritasWrapper extends JarExecutor { - constructor() { + private readonly WORK_DIR: string + private readonly OUTPUT_FILE: string + + constructor(cwd: string) { super('Claritas') - this.stdoutListeners.push((data) => { - const clean = data.toString('utf8').trim() as string - const spike = 'results::' - if(clean.startsWith(spike)) { - this.lastExecutionResult = JSON.parse(clean.substr(spike.length)) as ClaritasResult + + this.WORK_DIR = resolve(cwd, 'claritasWork') + this.OUTPUT_FILE = resolve(this.WORK_DIR, 'claritasOutput.json') + + this.onCloseListeners.push(async (code) => { + if(code !== 0) { + this.logger.error('Claritas finished with non-zero exit code, ', code) + this.lastExecutionResult = undefined! + } else { + if(pathExists(this.OUTPUT_FILE)) { + this.lastExecutionResult = JSON.parse((await readFile(this.OUTPUT_FILE)).toString('utf8')) + } else { + this.logger.error('Claritas output file not found when exit code is 0, is this a bug?') + this.lastExecutionResult = undefined! + } } + await this.cleanOutput() }) + } protected getJarPath(): string { @@ -25,8 +41,16 @@ export class ClaritasWrapper extends JarExecutor { return super.executeJar( '--absoluteJarPaths', absoluteJarPaths.join(','), '--libraryType', libraryType, - '--mcVersion', mcVersion.toString() + '--mcVersion', mcVersion.toString(), + '--outputFile', this.OUTPUT_FILE, + '--previewOutput', 'true' ) } + private async cleanOutput(): Promise { + if(pathExists(this.WORK_DIR)) { + remove(this.WORK_DIR) + } + } + } \ No newline at end of file diff --git a/src/util/java/JarExecutor.ts b/src/util/java/JarExecutor.ts index 24454b5..be30d46 100644 --- a/src/util/java/JarExecutor.ts +++ b/src/util/java/JarExecutor.ts @@ -11,6 +11,7 @@ export abstract class JarExecutor { protected stdoutListeners: ((chunk: any) => void)[] = [] // eslint-disable-next-line @typescript-eslint/no-explicit-any protected stderrListeners: ((chunk: any) => void)[] = [] + protected onCloseListeners: ((code: number) => Promise)[] = [] protected lastExecutionResult!: T @@ -34,10 +35,14 @@ export abstract class JarExecutor { child.stderr.on('data', (data) => this.logger.error(data.toString('utf8').trim())) this.stderrListeners.forEach(l => child.stderr.on('data', l)) - child.on('close', code => { + child.on('close', async code => { this.logger.info('Exited with code', code) + for(const l of this.onCloseListeners) { + await l(code) + } resolve(this.lastExecutionResult) }) + child.on('error', (err) => { this.logger.info('Error during process execution', err) reject(err)