import { AnswersQuestions, Question, UsesAbilities } from '@serenity-js/core'; import { Path } from '@serenity-js/core/lib/io'; import * as path from 'path'; import { promisify } from 'util'; const findJavaHome = promisify(require('find-java-home')); // tslint:disable-line:no-var-requires /** * @package */ export class JavaExecutable extends Question> { answeredBy(actor: AnswersQuestions & UsesAbilities): Promise { return findJavaHome({ allowJre: true }) .then(pathToJavaHome => path.join(pathToJavaHome, 'bin', this.javaFileName())) .then(Path.fromJSON); } toString() { return `java executable`; } private javaFileName() { return this.isWindows() ? 'java.exe' : 'java'; } private isWindows() { return process.platform.indexOf('win') === 0; } }