Search in sources :

Example 1 with DataStore

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;
}
Also used : Interpreter(org.lara.interpreter.Interpreter) MasterWeaver(org.lara.interpreter.weaver.MasterWeaver) FileList(org.lara.interpreter.joptions.keys.FileList) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) LaraIDataStore(org.lara.interpreter.joptions.config.interpreter.LaraIDataStore) File(java.io.File)

Example 2 with DataStore

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;
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) LaraIDataStore(org.lara.interpreter.joptions.config.interpreter.LaraIDataStore) NotImplementedException(pt.up.fe.specs.util.exceptions.NotImplementedException) ExecutionMode(org.lara.interpreter.cli.OptionsParser.ExecutionMode) File(java.io.File) LaraIException(org.lara.interpreter.exception.LaraIException) BaseException(pt.up.fe.specs.tools.lara.exception.BaseException) DOMException(org.w3c.dom.DOMException) NotImplementedException(pt.up.fe.specs.util.exceptions.NotImplementedException)

Example 3 with DataStore

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);
}
Also used : DataStore(org.suikasoft.jOptions.Interfaces.DataStore) LaraIDataStore(org.lara.interpreter.joptions.config.interpreter.LaraIDataStore) File(java.io.File)

Example 4 with DataStore

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;
}
Also used : AppPersistence(org.suikasoft.jOptions.app.AppPersistence) LaraiStoreDefinition(org.lara.interpreter.joptions.config.interpreter.LaraiStoreDefinition) StoreDefinition(org.suikasoft.jOptions.storedefinition.StoreDefinition) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) File(java.io.File)

Example 5 with DataStore

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;
}
Also used : WeaverOption(org.lara.interpreter.weaver.options.WeaverOption) Arrays(java.util.Arrays) LaraIException(org.lara.interpreter.exception.LaraIException) SpecsIo(pt.up.fe.specs.util.SpecsIo) LaraiStoreDefinition(org.lara.interpreter.joptions.config.interpreter.LaraiStoreDefinition) ResourceProvider(pt.up.fe.specs.util.providers.ResourceProvider) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) File(java.io.File) AppPersistence(org.suikasoft.jOptions.app.AppPersistence) WeaverOption(org.lara.interpreter.weaver.options.WeaverOption) List(java.util.List) DataKey(org.suikasoft.jOptions.Datakey.DataKey) WeaverEngine(org.lara.interpreter.weaver.interf.WeaverEngine) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) Map(java.util.Map) CommandLine(org.apache.commons.cli.CommandLine) StoreDefinition(org.suikasoft.jOptions.storedefinition.StoreDefinition) LaraiKeys(org.lara.interpreter.joptions.config.interpreter.LaraiKeys) Replacer(pt.up.fe.specs.util.utilities.Replacer) Option(org.apache.commons.cli.Option) DataStore(org.suikasoft.jOptions.Interfaces.DataStore) DataKey(org.suikasoft.jOptions.Datakey.DataKey) LaraIException(org.lara.interpreter.exception.LaraIException) WeaverOption(org.lara.interpreter.weaver.options.WeaverOption) Option(org.apache.commons.cli.Option) File(java.io.File)

Aggregations

DataStore (org.suikasoft.jOptions.Interfaces.DataStore)30 File (java.io.File)17 StoreDefinition (org.suikasoft.jOptions.storedefinition.StoreDefinition)8 AppPersistence (org.suikasoft.jOptions.app.AppPersistence)7 WeaverEngine (org.lara.interpreter.weaver.interf.WeaverEngine)6 LaraIException (org.lara.interpreter.exception.LaraIException)5 List (java.util.List)4 CommandLine (org.apache.commons.cli.CommandLine)4 LaraiStoreDefinition (org.lara.interpreter.joptions.config.interpreter.LaraiStoreDefinition)4 FileList (org.lara.interpreter.joptions.keys.FileList)4 OptionalFile (org.lara.interpreter.joptions.keys.OptionalFile)4 DefaultWeaver (org.lara.interpreter.weaver.defaultweaver.DefaultWeaver)4 Arrays (java.util.Arrays)3 Collectors (java.util.stream.Collectors)3 LaraI (larai.LaraI)3 Interpreter (org.lara.interpreter.Interpreter)3 LaraIDataStore (org.lara.interpreter.joptions.config.interpreter.LaraIDataStore)3 LaraiKeys (org.lara.interpreter.joptions.config.interpreter.LaraiKeys)3 MasterWeaver (org.lara.interpreter.weaver.MasterWeaver)3 DataKey (org.suikasoft.jOptions.Datakey.DataKey)3