use of com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader in project tcMenu by davetcc.
the class EmbeddedJavaGeneratorTest method setupGenerator.
@BeforeEach
public void setupGenerator() throws IOException {
storage = mock(ConfigurationStorage.class);
generator = new EmbeddedJavaGenerator(storage, EmbeddedPlatform.RASPBERRY_PIJ);
tempPath = Files.createTempDirectory("gentest");
tree = buildSimpleTreeReadOnly();
tree.addMenuItem(MenuTree.ROOT, new RuntimeListMenuItemBuilder().withId(2039).withName("My List").withFunctionName("listHasChanged").withInitialRows(10).menuItem());
when(storage.getVersion()).thenReturn("1.2.3");
var pluginMgr = new DefaultXmlPluginLoader(new PluginEmbeddedPlatformsImpl(), storage, true);
var data = Objects.requireNonNull(getClass().getResourceAsStream("/plugins/java-test-plugin.xml")).readAllBytes();
plugin = pluginMgr.loadPlugin(new String(data));
}
use of com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader in project tcMenu by davetcc.
the class MenuEditorApp method start.
@Override
public void start(Stage primaryStage) throws Exception {
startUpLogging();
Platform.runLater(() -> {
final String os = System.getProperty("os.name");
if (os != null && os.startsWith("Mac")) {
Desktop desktop = Desktop.getDesktop();
desktop.setAboutHandler(e -> Platform.runLater(() -> controller.aboutMenuPressed(new ActionEvent())));
desktop.setQuitStrategy(QuitStrategy.NORMAL_EXIT);
}
});
ConfigurationStorage prefsStore = new PrefsConfigurationStorage();
createOrUpdateDirectoriesAsNeeded(prefsStore);
primaryStage.setTitle("Embedded Menu Designer");
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/menuEditor.fxml"));
Pane myPane = loader.load();
controller = loader.getController();
var stream = Preferences.userNodeForPackage(MenuEditorApp.class).get("ReleaseStream", ReleaseType.STABLE.toString());
var httpClient = new SimpleHttpClient();
var urlBase = "https://www.thecoderscorner.com";
if (System.getProperty("localTccService") != null) {
urlBase = System.getProperty("localTccService");
System.getLogger("Main").log(WARNING, "Overriding the TCC service to " + urlBase);
}
LibraryVersionDetector libraryVersionDetector = new OnlineLibraryVersionDetector(urlBase, httpClient, ReleaseType.valueOf(stream));
PluginEmbeddedPlatformsImpl platforms = new PluginEmbeddedPlatformsImpl();
DefaultXmlPluginLoader manager = new DefaultXmlPluginLoader(platforms, prefsStore, true);
ArduinoLibraryInstaller installer = new ArduinoLibraryInstaller(libraryVersionDetector, manager, prefsStore);
platforms.setInstallerConfiguration(installer, prefsStore);
manager.loadPlugins();
var homeDirectory = System.getProperty("homeDirectoryOverride", System.getProperty("user.home"));
var editorUI = new CurrentProjectEditorUIImpl(manager, primaryStage, platforms, installer, prefsStore, libraryVersionDetector, homeDirectory);
FileBasedProjectPersistor persistor = new FileBasedProjectPersistor();
CurrentEditorProject project = new CurrentEditorProject(editorUI, persistor, prefsStore);
editorUI.setEditorProject(project);
controller.initialise(project, installer, editorUI, manager, prefsStore, libraryVersionDetector);
Scene myScene = new Scene(myPane);
BaseDialogSupport.getJMetro().setScene(myScene);
primaryStage.setScene(myScene);
primaryStage.show();
primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/img/menu-icon-sm.png"))));
primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/img/menu-icon.png"))));
primaryStage.setOnCloseRequest((evt) -> {
try {
var streamStr = libraryVersionDetector.getReleaseType().toString();
Preferences.userNodeForPackage(MenuEditorApp.class).put("ReleaseStream", streamStr);
controller.persistPreferences();
if (project.isDirty()) {
evt.consume();
Alert alert = new Alert(AlertType.CONFIRMATION, "There are unsaved changes, save first?", ButtonType.YES, ButtonType.NO);
BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
alert.setTitle("Are you sure");
alert.setHeaderText("");
if (alert.showAndWait().orElse(ButtonType.NO) == ButtonType.YES) {
project.saveProject(CurrentEditorProject.EditorSaveMode.SAVE);
}
}
} catch (Exception ex) {
// ignored, we are trying to shutdown so just proceeed anyway.
}
Platform.exit();
System.exit(0);
});
}
use of com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoader 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;
}
}
Aggregations