"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/**
 * Copyright 2017-2020 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.
 */
var protoc_1 = require("./common/protoc");
var java_1 = require("./common/java");
// to execute 'warmp up' of protobufjs cli at this point rather than on first execution
require("protobufjs/cli");
function install() {
    return Promise.all([installJre(), installProtoc()]);
}
exports.install = install;
function installProtoc() {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var provided, error_1;
        return 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*/, 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*/, protoc_1.downloadProtoc()];
                case 4:
                    _a.sent();
                    return [3 /*break*/, 5];
                case 5: return [2 /*return*/];
            }
        });
    });
}
function installJre() {
    return tslib_1.__awaiter(this, void 0, void 0, function () {
        var provided, error_2;
        return 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*/, 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*/, java_1.downloadJre()];
                case 4:
                    _a.sent();
                    return [3 /*break*/, 5];
                case 5: return [2 /*return*/];
            }
        });
    });
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zdGFsbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9pbnN0YWxsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7Ozs7Ozs7Ozs7Ozs7R0FlRztBQUNILDBDQUFxRTtBQUNyRSxzQ0FBOEQ7QUFDOUQsdUZBQXVGO0FBQ3ZGLDBCQUF3QjtBQUV4QixTQUFnQixPQUFPO0lBQ25CLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLFVBQVUsRUFBRSxFQUFFLGFBQWEsRUFBRSxDQUFDLENBQUMsQ0FBQztBQUN4RCxDQUFDO0FBRkQsMEJBRUM7QUFFRCxTQUFlLGFBQWE7Ozs7Ozt5QkFFcEIsQ0FBQSxPQUFPLENBQUMsR0FBRyxDQUFDLCtCQUErQixLQUFLLE1BQU0sQ0FBQSxFQUF0RCx3QkFBc0Q7b0JBQ3RELE9BQU8sQ0FBQyxHQUFHLENBQUMseUJBQXlCLENBQUMsQ0FBQzs7OztvQkFHbEIscUJBQU0sMkJBQWtCLEVBQUUsRUFBQTs7b0JBQXJDLFFBQVEsR0FBRyxTQUEwQjtvQkFDM0MsT0FBTyxDQUFDLEdBQUcsQ0FBQyx5Q0FBdUMsUUFBVSxDQUFDLENBQUM7Ozs7b0JBRS9ELE9BQU8sQ0FBQyxHQUFHLENBQUMsdURBQ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