Search in sources :

Example 1 with VersionInfo

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

the class MenuEditorTestCases method testAreaInformationPanelNeedingUpdate.

@Test
void testAreaInformationPanelNeedingUpdate(FxRobot robot) throws Exception {
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, false));
    when(installer.getVersionOfLibrary("module.name", AVAILABLE_PLUGIN)).thenReturn(new VersionInfo("1.0.2"));
    openTheCompleteMenuTree(robot);
    SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), MenuTree.ROOT));
    Thread.sleep(500);
    verifyThat("#tcMenuStatusArea", LabeledMatchers.hasText("Libraries need updating, check in General Settings"));
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Test(org.junit.jupiter.api.Test)

Example 2 with VersionInfo

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

the class MenuEditorTestCases method onStart.

@Start
public void onStart(Stage stage) throws Exception {
    dirHelper.initialise();
    dirHelper.createSketch(TCMENU_DIR, "exampleSketch1", true);
    dirHelper.createSketch(TCMENU_DIR, "exampleSketch2", true);
    var sketch1 = dirHelper.createSketch(SKETCHES_DIR, "sketches1", true);
    var sketch2 = dirHelper.createSketch(SKETCHES_DIR, "sketches2", true);
    dirHelper.createSketch(SKETCHES_DIR, "sketchesIgnore", false);
    // load the main window FXML
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/menuEditor.fxml"));
    Pane myPane = loader.load();
    // we need to mock a few things around the edges to make testing easier.
    editorProjectUI = mock(CurrentProjectEditorUI.class);
    when(editorProjectUI.createPanelForMenuItem(any(), any(), any(), any())).thenReturn(Optional.empty());
    persistor = mock(ProjectPersistor.class);
    installer = mock(ArduinoLibraryInstaller.class);
    simulatedCodeManager = mock(CodePluginManager.class);
    when(simulatedCodeManager.getLoadedPlugins()).thenReturn(Collections.singletonList(generateCodePluginConfig()));
    setUpInstallerLibVersions();
    // create a basic project, that has a few menu items in it.
    project = new CurrentEditorProject(editorProjectUI, persistor, mock(ConfigurationStorage.class));
    ConfigurationStorage storage = mock(ConfigurationStorage.class);
    when(storage.loadRecents()).thenReturn(List.of(sketch1.orElseThrow(), sketch2.orElseThrow(), "filesDoesNotExistRemove.emf"));
    when(storage.getRegisteredKey()).thenReturn("UnitTesterII");
    when(storage.isUsingArduinoIDE()).thenReturn(true);
    when(storage.getArduinoOverrideDirectory()).thenReturn(Optional.empty());
    // both versions same, do not invoke splash screen.
    when(storage.getVersion()).thenReturn("1.1.1");
    when(storage.getLastRunVersion()).thenReturn(new VersionInfo("1.1.1"));
    // set up the controller and stage..
    MenuEditorController controller = loader.getController();
    libDetector = mock(LibraryVersionDetector.class);
    when(libDetector.getReleaseType()).thenReturn(ReleaseType.STABLE);
    controller.initialise(project, installer, editorProjectUI, simulatedCodeManager, storage, libDetector);
    this.stage = stage;
    when(libDetector.availableVersionsAreValid(anyBoolean())).thenReturn(true);
    Scene myScene = new Scene(myPane);
    stage.setScene(myScene);
    stage.show();
}
Also used : LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) MenuEditorController(com.thecoderscorner.menu.editorui.controller.MenuEditorController) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) Pane(javafx.scene.layout.Pane) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) Start(org.testfx.framework.junit5.Start)

Example 3 with VersionInfo

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

the class MenuEditorTestCases method setUpInstallerLibVersions.

private void setUpInstallerLibVersions() throws IOException {
    // and we are always up to date library wise in unit test land
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    when(installer.findLibraryInstall("tcMenu")).thenReturn(dirHelper.getTcMenuPath());
    when(installer.getArduinoDirectory()).thenReturn(dirHelper.getSketchesDir());
    when(installer.getVersionOfLibrary("java-app", AVAILABLE_APP)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("java-app", CURRENT_APP)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("module.name", AVAILABLE_PLUGIN)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("module.name", CURRENT_PLUGIN)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("tcMenu", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.1"));
    when(installer.getVersionOfLibrary("tcMenu", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("IoAbstraction", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("IoAbstraction", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("LiquidCrystalIO", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("LiquidCrystalIO", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("TaskManagerIO", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("TaskManagerIO", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(false, true, true, true));
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo)

Example 4 with VersionInfo

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

the class ArduinoLibraryInstallerTest method testGetAllLibraryStatus.

@Test
public void testGetAllLibraryStatus() throws IOException {
    // put libs in the embedded source at 1.0.1, newer than arduino copy
    putLibraryInPlace(dirArduinoLibs, "tcMenu", "1.0.1");
    putLibraryInPlace(dirArduinoLibs, "IoAbstraction", "1.2.1");
    putLibraryInPlace(dirArduinoLibs, "LiquidCrystalIO", "1.4.1");
    putLibraryInPlace(dirArduinoLibs, "TaskManagerIO", "1.0.0");
    var versions = Map.of("tcMenu/Library", new VersionInfo("1.0.0"), "IoAbstraction/Library", new VersionInfo("1.2.1"), "LiquidCrystalIO/Library", new VersionInfo("1.5.1"), "TaskManagerIO/Library", new VersionInfo("1.0.1"), "xyz/Plugin", new VersionInfo("7.8.9"));
    when(verDetector.acquireVersions()).thenReturn(versions);
    LibraryStatus libraryStatus = installer.statusOfAllLibraries();
    assertFalse(libraryStatus.isUpToDate());
    assertTrue(libraryStatus.isIoAbstractionUpToDate());
    assertTrue(libraryStatus.isTcMenuUpToDate());
    assertFalse(libraryStatus.isLiquidCrystalIoUpToDate());
    assertEquals("1.0.1", installer.getVersionOfLibrary("tcMenu", CURRENT_LIB).toString());
    assertEquals("1.2.1", installer.getVersionOfLibrary("IoAbstraction", CURRENT_LIB).toString());
    assertEquals("1.4.1", installer.getVersionOfLibrary("LiquidCrystalIO", CURRENT_LIB).toString());
    assertEquals("1.0.0", installer.getVersionOfLibrary("TaskManagerIO", CURRENT_LIB).toString());
    assertEquals("1.0.1", installer.getVersionOfLibrary("TaskManagerIO", AVAILABLE_LIB).toString());
    assertEquals("1.0.0", installer.getVersionOfLibrary("tcMenu", AVAILABLE_LIB).toString());
    assertEquals("1.2.1", installer.getVersionOfLibrary("IoAbstraction", AVAILABLE_LIB).toString());
    assertEquals("1.5.1", installer.getVersionOfLibrary("LiquidCrystalIO", AVAILABLE_LIB).toString());
    assertEquals("7.8.9", installer.getVersionOfLibrary("xyz", AVAILABLE_PLUGIN).toString());
}
Also used : VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) Test(org.junit.jupiter.api.Test)

Example 5 with VersionInfo

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

the class MenuEditorApp method createOrUpdateDirectoriesAsNeeded.

public static void createOrUpdateDirectoriesAsNeeded(ConfigurationStorage storage) {
    var homeDir = Paths.get(System.getProperty("user.home"));
    try {
        Path menuDir = homeDir.resolve(".tcmenu/logs");
        if (!Files.exists(menuDir)) {
            Files.createDirectories(menuDir);
        }
        Path pluginDir = homeDir.resolve(".tcmenu/plugins");
        var current = new VersionInfo(storage.getVersion());
        var noPluginDir = !isDirectoryPresentAndPopulated(pluginDir);
        if (!storage.getLastRunVersion().equals(current) || noPluginDir) {
            try {
                if (noPluginDir)
                    Files.createDirectories(pluginDir);
                if (Files.find(pluginDir, 2, (path, basicFileAttributes) -> path.endsWith(".git") || path.endsWith(".development")).findFirst().isPresent()) {
                    System.getLogger("Main").log(WARNING, "Not upgrading core plugins, this is a development system");
                    return;
                }
                try (var resourceAsStream = MenuEditorApp.class.getResourceAsStream("/plugins/InitialPlugins.zip")) {
                    OnlineLibraryVersionDetector.extractFilesFromZip(pluginDir, resourceAsStream);
                }
            } catch (Exception ex) {
                System.getLogger("Main").log(ERROR, "failed to prepare directory structure", ex);
            }
        }
    } catch (IOException e) {
        Alert alert = new Alert(AlertType.ERROR, "Error creating user directory", ButtonType.CLOSE);
        BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
        alert.setContentText("Couldn't create user directory: " + e.getMessage());
        alert.showAndWait();
    }
}
Also used : Path(java.nio.file.Path) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) 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