@syntest/core
Version:
The common core of the SynTest Framework
122 lines • 5.91 kB
JavaScript
"use strict";
/*
* Copyright 2020-2023 Delft University of Technology and SynTest contributors
*
* This file is part of SynTest Framework.
*
* 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Launcher = void 0;
const Configuration_1 = require("./Configuration");
const MOSAFamily_1 = require("./search/metaheuristics/evolutionary/MOSAFamily");
const RandomSearch_1 = require("./search/metaheuristics/RandomSearch");
const SignalTerminationTrigger_1 = require("./search/termination/SignalTerminationTrigger");
const NSGAII_1 = require("./search/metaheuristics/evolutionary/NSGAII");
const yargHelper = require("yargs/helpers");
class Launcher {
get eventManager() {
return this._eventManager;
}
get pluginManager() {
return this._pluginManager;
}
get programState() {
return this._eventManager.state;
}
get programName() {
return this._programName;
}
get configuration() {
return this._configuration;
}
constructor(programName, eventManager, pluginManager) {
this._programName = programName;
this._eventManager = eventManager;
this._pluginManager = pluginManager;
this._configuration = new Configuration_1.Configuration();
}
run(args) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Remove binary call from args
args = yargHelper.hideBin(args);
// Configure base options
const yargs1 = this.configuration.configureOptions(this.programName);
// Parse the arguments and config using only the base options
const baseArguments = yield this.configuration.processArguments(yargs1, args);
// Add the language specific tool options
const yargs2 = yield this.addOptions(yargs1);
// Register the plugins and add the plugin options
const yargs3 = yield this.registerPlugins(baseArguments.plugins, yargs2);
// Parse the arguments and config using all options
const argValues = yield this.configuration.processArguments(yargs3, args);
// Initialize the configuration object
this.configuration.initialize(argValues);
// Register all listener plugins
for (const pluginName of this.pluginManager.getListeners()) {
const plugin = this.pluginManager.getListener(pluginName);
this.eventManager.registerListener(plugin.createListener({}));
}
yield this.pluginManager.prepare();
this.eventManager.emitEvent("onInitializeStart");
yield this.initialize();
this.eventManager.emitEvent("onInitializeComplete");
this.eventManager.emitEvent("onPreprocessStart");
yield this.preprocess();
this.eventManager.emitEvent("onPreprocessComplete");
this.eventManager.emitEvent("onProcessStart");
yield this.process();
this.eventManager.emitEvent("onProcessComplete");
this.eventManager.emitEvent("onPostprocessStart");
yield this.postprocess();
this.eventManager.emitEvent("onPostprocessComplete");
yield this.pluginManager.cleanup();
this.eventManager.emitEvent("onExit");
yield this.exit();
}
catch (e) {
console.log(e);
console.trace(e);
}
});
}
registerPlugins(plugins, yargs) {
return __awaiter(this, void 0, void 0, function* () {
// register standard search algorithms
this.pluginManager.registerSearchAlgorithm(new RandomSearch_1.RandomSearchFactory());
this.pluginManager.registerSearchAlgorithm(new NSGAII_1.NSGAIIFactory());
this.pluginManager.registerSearchAlgorithm(new MOSAFamily_1.MOSAFactory());
this.pluginManager.registerSearchAlgorithm(new MOSAFamily_1.DynaMOSAFactory());
// register standard termination triggers
this.pluginManager.registerTermination(new SignalTerminationTrigger_1.SignalTerminationTriggerFactory());
// load external plugins
for (const plugin of plugins) {
yield this.pluginManager.loadPlugin(plugin);
}
// add plugin options
return this.pluginManager.addPluginOptions(yargs);
});
}
}
exports.Launcher = Launcher;
//# sourceMappingURL=Launcher.js.map