use of org.suikasoft.jOptions.Interfaces.DataStore in project lara-framework by specs-feup.
the class LaraI method buildAspectProcessor.
public static AspectClassProcessor buildAspectProcessor(WeaverEngine weaver, JsEngine jsEngine) {
// Create LARA Interpreter
DataStore laraiConfig = DataStore.newInstance("LaraCompiler");
laraiConfig.set(LaraiKeys.LARA_FILE, new File(""));
LaraI larai = LaraI.newInstance(laraiConfig, weaver);
// Create MasterWeaver
FileList folderApplication = FileList.newInstance();
MasterWeaver masterWeaver = new MasterWeaver(larai, weaver, folderApplication, jsEngine);
larai.setWeaver(masterWeaver);
// Create interpreter
Interpreter interpreter = new Interpreter(larai, jsEngine, false);
larai.setInterpreter(interpreter);
// larai.getInterpreter().getImportProcessor().importAndInitialize();
masterWeaver.simpleBegin();
var aspectProcessor = AspectClassProcessor.newInstance(interpreter);
return aspectProcessor;
}
use of org.suikasoft.jOptions.Interfaces.DataStore in project lara-framework by specs-feup.
the class LaraI method execPrivate.
public static LaraiResult execPrivate(String[] args, WeaverEngine weaverEngine) {
SpecsLogs.debug("Weaver command-line arguments: " + Arrays.stream(args).collect(Collectors.joining(" ")));
// Set weaver (e.g. for help message to access name and build number)
weaverEngine.setWeaver();
// Reset global state
MessageConstants.order = 1;
if (CLIConfigOption.ALLOW_GUI && OptionsParser.guiMode(args)) {
LaraLauncher.launchGUI(weaverEngine, Optional.empty());
// return true;
return LaraiResult.newInstance(true, true);
}
try {
// Collection<Option> configOptions = OptionsParser.buildConfigOptions();
// Collection<Option> mainOptions = OptionsParser.buildLaraIOptionGroup();
// OptionsParser.addExtraOptions(mainOptions, weaverEngine.getOptions());
//
// Options finalOptions = new Options();
//
// configOptions.forEach(finalOptions::addOption); // So the config options appear on the top
// mainOptions.forEach(finalOptions::addOption);
Options finalOptions = LaraCli.getCliOptions(weaverEngine);
CommandLine cmd = OptionsParser.parse(args, finalOptions);
if (LaraIUtils.printHelp(cmd, finalOptions)) {
// return true;
return LaraiResult.newInstance(true, false);
}
// ExecutionMode mode = OptionsParser.getExecMode(args[0], cmd, mainOptions, finalOptions);
ExecutionMode mode = OptionsParser.getExecMode(args[0], cmd, finalOptions);
DataStore dataStore;
boolean success;
boolean isRunningGui;
switch(mode) {
// return weaverEngine.executeUnitTestMode(Arrays.asList(args));
case // convert configuration file to data store and run
CONFIG:
// System.out.println("CONFIG ARGS:" + Arrays.toString(args));
dataStore = OptionsConverter.configFile2DataStore(weaverEngine, cmd);
success = execPrivate(dataStore, weaverEngine);
isRunningGui = false;
break;
// return execPrivate(dataStore, weaverEngine);
case // get the configuration file and execute GUI
CONFIG_GUI:
File guiFile = OptionsParser.getConfigFile(cmd);
LaraLauncher.launchGUI(weaverEngine, Optional.of(guiFile));
success = true;
isRunningGui = true;
break;
case // convert options to data store and run
OPTIONS:
// SpecsLogs.debug("Received args: " + Arrays.toString(args));
dataStore = OptionsConverter.commandLine2DataStore(args[0], cmd, weaverEngine.getOptions());
// return execPrivate(dataStore, weaverEngine);
success = execPrivate(dataStore, weaverEngine);
isRunningGui = false;
break;
case // convert configuration file to data store, override with extra options and run
CONFIG_OPTIONS:
dataStore = OptionsConverter.configExtraOptions2DataStore(args[0], cmd, weaverEngine);
// return execPrivate(dataStore, weaverEngine);
success = execPrivate(dataStore, weaverEngine);
isRunningGui = false;
break;
case GUI:
LaraLauncher.launchGUI(weaverEngine, Optional.empty());
success = true;
isRunningGui = true;
break;
default:
throw new NotImplementedException(mode);
}
return LaraiResult.newInstance(success, isRunningGui);
} catch (final Exception e) {
// throw new RuntimeException("", e);
throw prettyRuntimeException(e);
} finally {
if (WeaverEngine.isWeaverSet()) {
WeaverEngine.removeWeaver();
}
}
// return true;
}
use of org.suikasoft.jOptions.Interfaces.DataStore in project lara-framework by specs-feup.
the class LaraI method newInstance.
public static LaraI newInstance(WeaverEngine weaverEngine) {
DataStore data = DataStore.newInstance("EmptyLarai");
data.add(LaraiKeys.LARA_FILE, new File(""));
return LaraI.newInstance(data, weaverEngine);
}
use of org.suikasoft.jOptions.Interfaces.DataStore in project lara-framework by specs-feup.
the class OptionsConverter method configFile2DataStore.
public static DataStore configFile2DataStore(WeaverEngine weaverEngine, CommandLine cmd) {
File file = OptionsParser.getConfigFile(cmd);
StoreDefinition laraiDefinition = OptionsParser.getLaraStoreDefinition(weaverEngine);
AppPersistence persistence = OptionsParser.getXmlPersistence(laraiDefinition);
DataStore laraiStore = persistence.loadData(file);
return laraiStore;
}
use of org.suikasoft.jOptions.Interfaces.DataStore in project lara-framework by specs-feup.
the class OptionsConverter method configExtraOptions2DataStore.
/**
* Adds the commandline options into an existing datastore, using the Mapping in {@link JOptionsInterface}
*
* @param laraFileName
* @param cmd
* @return
*/
public static DataStore configExtraOptions2DataStore(String laraFileName, CommandLine cmd, WeaverEngine engine) {
DataStore dataStore = configFile2DataStore(engine, cmd);
if (!laraFileName.startsWith("-")) {
dataStore.set(LaraiKeys.LARA_FILE, new File(laraFileName));
}
Map<WeaverOption, DataKey<?>> conversionMap = JOptionsInterface.getConversionMap();
/**
* Maybe it is better to deal with each option, see if it exists and put it in the datakey, this way we can
* control better the multiple arguments
*/
Map<String, WeaverOption> map = engine.getOptions().stream().collect(Collectors.toMap(WeaverOption::longOption, value -> value));
for (Option opt : Arrays.asList(cmd.getOptions())) {
if (CLIConfigOption.contains(opt.getLongOpt())) {
// Just ignore options for config file (such as -c and -g)
continue;
}
if (CLIOption.contains(opt.getLongOpt())) {
processLaraIOption(dataStore, conversionMap, opt);
} else if (map.containsKey(opt.getLongOpt())) {
DataKey<?> weaverOptionKey = map.get(opt.getLongOpt()).dataKey();
setValue(dataStore, weaverOptionKey, opt);
} else {
throw new LaraIException("LARAI does not have option '" + opt.getLongOpt() + "'.");
}
}
return dataStore;
}
Aggregations