"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GradleBuildService = void 0;
const helpers_1 = require("../../common/helpers");
const constants = require("../../constants");
const events_1 = require("events");
const yok_1 = require("../../common/yok");
class GradleBuildService extends events_1.EventEmitter {
    constructor($childProcess, $gradleBuildArgsService, $gradleCommandService) {
        super();
        this.$childProcess = $childProcess;
        this.$gradleBuildArgsService = $gradleBuildArgsService;
        this.$gradleCommandService = $gradleCommandService;
    }
    async buildProject(projectRoot, buildData) {
        const buildTaskArgs = await this.$gradleBuildArgsService.getBuildTaskArgs(buildData);
        const spawnOptions = {
            emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME },
            throwError: true,
        };
        const gradleCommandOptions = {
            cwd: projectRoot,
            message: "Gradle build...",
            stdio: buildData.buildOutputStdio,
            gradlePath: buildData.gradlePath,
            spawnOptions,
        };
        await (0, helpers_1.attachAwaitDetach)(constants.BUILD_OUTPUT_EVENT_NAME, this.$childProcess, (data) => this.emit(constants.BUILD_OUTPUT_EVENT_NAME, data), this.$gradleCommandService.executeCommand(buildTaskArgs, gradleCommandOptions));
    }
    async cleanProject(projectRoot, buildData) {
        const cleanTaskArgs = this.$gradleBuildArgsService.getCleanTaskArgs(buildData);
        const gradleCommandOptions = {
            cwd: projectRoot,
            message: "Gradle clean...",
            gradlePath: buildData.gradlePath,
        };
        await this.$gradleCommandService.executeCommand(cleanTaskArgs, gradleCommandOptions);
    }
}
exports.GradleBuildService = GradleBuildService;
yok_1.injector.register("gradleBuildService", GradleBuildService);
