"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.install = void 0;
var tslib_1 = require("tslib");
/**
 * Copyright 2017-2022 Plexus Interop Deutsche Bank AG
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// to execute 'warmp up' of protobufjs cli at this point rather than on first execution
require("protobufjs/cli");
var java_1 = require("./common/java");
var protoc_1 = require("./common/protoc");
function install() {
    return Promise.all([installJre(), installProtoc()]);
}
exports.install = install;
function installProtoc() {
    return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
        var provided, error_1;
        return (0, tslib_1.__generator)(this, function (_a) {
            switch (_a.label) {
                case 0:
                    if (!(process.env.PLEXUS_CLI_SKIP_PROTOC_DOWNLOAD === 'true')) return [3 /*break*/, 1];
                    console.log('protoc download skipped');
                    return [3 /*break*/, 5];
                case 1:
                    _a.trys.push([1, 3, , 5]);
                    return [4 /*yield*/, (0, protoc_1.protocExecProvided)()];
                case 2:
                    provided = _a.sent();
                    console.log("protoc executable already provided: " + provided);
                    return [3 /*break*/, 5];
                case 3:
                    error_1 = _a.sent();
                    console.log('Failed to locate Protoc Executable, going to download', error_1.message);
                    return [4 /*yield*/, (0, protoc_1.downloadProtoc)()];
                case 4:
                    _a.sent();
                    return [3 /*break*/, 5];
                case 5: return [2 /*return*/];
            }
        });
    });
}
function installJre() {
    return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
        var provided, error_2;
        return (0, tslib_1.__generator)(this, function (_a) {
            switch (_a.label) {
                case 0:
                    if (!(process.env.PLEXUS_CLI_SKIP_JRE_DOWNLOAD === 'true')) return [3 /*break*/, 1];
                    console.log('JRE download skipped');
                    return [3 /*break*/, 5];
                case 1:
                    _a.trys.push([1, 3, , 5]);
                    return [4 /*yield*/, (0, java_1.javaExecProvided)()];
                case 2:
                    provided = _a.sent();
                    console.log("Java executable already provided: " + provided);
                    return [3 /*break*/, 5];
                case 3:
                    error_2 = _a.sent();
                    console.log('Failed to locate Java Executable, going to download', error_2.message);
                    return [4 /*yield*/, (0, java_1.downloadJre)()];
                case 4:
                    _a.sent();
                    return [3 /*break*/, 5];
                case 5: return [2 /*return*/];
            }
        });
    });
}
//# sourceMappingURL=install.js.map