Search in sources :

Example 6 with VersionInfo

use of com.thecoderscorner.menu.persist.VersionInfo in project tcMenu by davetcc.

the class CodeGeneratorCommand method call.

@Override
public Integer call() {
    try {
        var project = projectFileOrNull(projectFile);
        System.out.format("Starting code generator for %s\n", project.getOptions().getApplicationName());
        var prefsStore = new PrefsConfigurationStorage();
        MenuEditorApp.createOrUpdateDirectoriesAsNeeded(prefsStore);
        prefsStore.setLastRunVersion(new VersionInfo(prefsStore.getVersion()));
        var platforms = new PluginEmbeddedPlatformsImpl();
        DefaultXmlPluginLoader loader = new DefaultXmlPluginLoader(platforms, prefsStore, true);
        loader.loadPlugins();
        platforms.setInstallerConfiguration(new ArduinoLibraryInstaller(new OfflineDetector(), loader, prefsStore), prefsStore);
        var embeddedPlatform = platforms.getEmbeddedPlatformFromId(project.getOptions().getEmbeddedPlatform());
        var codeGen = platforms.getCodeGeneratorFor(embeddedPlatform, project.getOptions());
        System.out.println("Preparing to execute generator");
        List<CodePluginItem> allPlugins = loader.getLoadedPlugins().stream().flatMap(pluginLib -> pluginLib.getPlugins().stream()).collect(Collectors.toList());
        List<CodePluginItem> plugins = new ArrayList<>();
        plugins.add(getPluginOrDefault(allPlugins, project.getOptions().getLastInputUuid(), DEFAULT_INPUT_PLUGIN));
        plugins.add(getPluginOrDefault(allPlugins, project.getOptions().getLastDisplayUuid(), DEFAULT_DISPLAY_PLUGIN));
        for (var plugin : project.getOptions().getLastRemoteCapabilitiesUuids()) {
            plugins.add(getPluginOrDefault(allPlugins, plugin, DEFAULT_REMOTE_PLUGIN));
        }
        if (project.getOptions().getLastThemeUuid() != null) {
            plugins.add(getPluginOrDefault(allPlugins, project.getOptions().getLastThemeUuid(), DEFAULT_THEME_PLUGIN));
        }
        System.out.format("Executing code generator");
        var location = Paths.get(loadedProjectFile.getParent());
        codeGen.setLoggerFunction((level, s) -> {
            if (verbose)
                System.out.format("Gen: %s: %s\n", level, s);
        });
        codeGen.startConversion(location, plugins, project.getMenuTree(), Collections.emptyList(), project.getOptions());
        return 0;
    } catch (Exception ex) {
        System.out.println("Error during code generation " + ex.getClass().getSimpleName() + " " + ex.getMessage());
        if (verbose) {
            ex.printStackTrace();
        }
        return -1;
    }
}
Also used : java.util(java.util) ProjectPersistor(com.thecoderscorner.menu.editorui.project.ProjectPersistor) Files(java.nio.file.Files) PluginEmbeddedPlatformsImpl(com.thecoderscorner.menu.editorui.generator.plugin.PluginEmbeddedPlatformsImpl) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) Collectors(java.util.stream.Collectors) File(java.io.File) MenuEditorApp(com.thecoderscorner.menu.editorui.MenuEditorApp) StandardCopyOption(java.nio.file.StandardCopyOption) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) CodePluginItem(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem) Paths(java.nio.file.Paths) CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) FileBasedProjectPersistor(com.thecoderscorner.menu.editorui.project.FileBasedProjectPersistor) PrefsConfigurationStorage(com.thecoderscorner.menu.editorui.storage.PrefsConfigurationStorage) Command(picocli.CommandLine.Command) DefaultXmlPluginLoader(com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) OnlineLibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector) MenuTreeWithCodeOptions(com.thecoderscorner.menu.editorui.project.MenuTreeWithCodeOptions) CommandLine(picocli.CommandLine) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) PluginEmbeddedPlatformsImpl(com.thecoderscorner.menu.editorui.generator.plugin.PluginEmbeddedPlatformsImpl) CodePluginItem(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem) DefaultXmlPluginLoader(com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) PrefsConfigurationStorage(com.thecoderscorner.menu.editorui.storage.PrefsConfigurationStorage) IOException(java.io.IOException)

Aggregations

VersionInfo (com.thecoderscorner.menu.persist.VersionInfo)6 LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)3 LibraryVersionDetector (com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector)2 ArduinoLibraryInstaller (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 MenuItem (com.thecoderscorner.menu.domain.MenuItem)1 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)1 MenuEditorApp (com.thecoderscorner.menu.editorui.MenuEditorApp)1 MenuEditorController (com.thecoderscorner.menu.editorui.controller.MenuEditorController)1 CodeGeneratorOptions (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions)1 OnlineLibraryVersionDetector (com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector)1 CodePluginItem (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem)1 CodePluginManager (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager)1 DefaultXmlPluginLoader (com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader)1 PluginEmbeddedPlatformsImpl (com.thecoderscorner.menu.editorui.generator.plugin.PluginEmbeddedPlatformsImpl)1 FileBasedProjectPersistor (com.thecoderscorner.menu.editorui.project.FileBasedProjectPersistor)1 MenuTreeWithCodeOptions (com.thecoderscorner.menu.editorui.project.MenuTreeWithCodeOptions)1 ProjectPersistor (com.thecoderscorner.menu.editorui.project.ProjectPersistor)1 ConfigurationStorage (com.thecoderscorner.menu.editorui.storage.ConfigurationStorage)1