Search in sources :

Example 1 with IoExpanderDefinitionCollection

use of com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection in project tcMenu by davetcc.

the class ChooseIoExpanderController method onClose.

public void onClose(ActionEvent actionEvent) {
    project.setGeneratorOptions(new CodeGeneratorOptionsBuilder().withExisting(project.getGeneratorOptions()).withExpanderDefinitions(new IoExpanderDefinitionCollection(ioItems)).codeOptions());
    ((Stage) mainTable.getScene().getWindow()).close();
}
Also used : Stage(javafx.stage.Stage) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)

Example 2 with IoExpanderDefinitionCollection

use of com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection in project tcMenu by davetcc.

the class FileBasedProjectPersistorTest method testSaveThenLoad.

@Test
public void testSaveThenLoad() throws IOException {
    Path projFile = dir.resolve("projectSave.emf");
    FileBasedProjectPersistor persistor = new FileBasedProjectPersistor();
    MenuTree tree = TestUtils.buildCompleteTree();
    List<String> remoteUuids = List.of("uuid3");
    List<CreatorProperty> propsList = Collections.singletonList(new CreatorProperty("name", "desc", "extra desc", "123", DISPLAY, CreatorProperty.PropType.USE_IN_DEFINE, CannedPropertyValidators.textValidator(), new AlwaysApplicable()));
    var options = new CodeGeneratorOptionsBuilder().withPlatform(ARDUINO_AVR.getBoardId()).withDisplay("uuid1").withInput("uuid2").withTheme("uuid4").withRemotes(remoteUuids).withProperties(propsList).withAppName("app name").withNewId(APPLICATION_UUID).withEepromDefinition(new NoEepromDefinition()).withAuthenticationDefinition(new NoAuthenticatorDefinition()).withExpanderDefinitions(new IoExpanderDefinitionCollection()).codeOptions();
    persistor.save(projFile.toString(), "", tree, options);
    MenuTreeWithCodeOptions openResult = persistor.open(projFile.toString());
    compareTrees(tree, openResult.getMenuTree());
    assertEquals(ARDUINO_AVR.getBoardId(), openResult.getOptions().getEmbeddedPlatform());
    assertEquals("uuid1", openResult.getOptions().getLastDisplayUuid());
    assertEquals("uuid2", openResult.getOptions().getLastInputUuid());
    assertEquals("uuid3", openResult.getOptions().getLastRemoteCapabilitiesUuids().get(0));
    assertEquals("app name", openResult.getOptions().getApplicationName());
    assertEquals("app name", openResult.getOptions().getApplicationName());
    assertEquals(APPLICATION_UUID, openResult.getOptions().getApplicationUUID());
    List<CreatorProperty> returnedProps = openResult.getOptions().getLastProperties();
    assertEquals("123", returnedProps.get(0).getLatestValue());
    assertEquals("name", returnedProps.get(0).getName());
    assertEquals(DISPLAY, returnedProps.get(0).getSubsystem());
}
Also used : Path(java.nio.file.Path) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) NoEepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.NoEepromDefinition) CreatorProperty(com.thecoderscorner.menu.editorui.generator.core.CreatorProperty) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) AlwaysApplicable(com.thecoderscorner.menu.editorui.generator.applicability.AlwaysApplicable) NoAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.NoAuthenticatorDefinition) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) Test(org.junit.jupiter.api.Test)

Example 3 with IoExpanderDefinitionCollection

use of com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection in project tcMenu by davetcc.

the class MbedGeneratorTest method testMbedConversion.

@SuppressWarnings("unchecked")
@Test
public void testMbedConversion() throws IOException {
    ArduinoSketchFileAdjuster adjuster = Mockito.mock(ArduinoSketchFileAdjuster.class);
    MenuTree tree = buildTreeFromJson(LARGE_MENU_STRUCTURE);
    tree.addMenuItem(MenuTree.ROOT, new CustomBuilderMenuItemBuilder().withId(10001).withName("Authenticator").withMenuType(AUTHENTICATION).withEepromAddr(-1).menuItem());
    tree.addMenuItem(MenuTree.ROOT, new CustomBuilderMenuItemBuilder().withId(10002).withName("IoT Monitor").withMenuType(REMOTE_IOT_MONITOR).withEepromAddr(-1).menuItem());
    ArduinoLibraryInstaller installer = Mockito.mock(ArduinoLibraryInstaller.class);
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    when(installer.getVersionOfLibrary("core-remote", InstallationType.CURRENT_PLUGIN)).thenReturn(VersionInfo.fromString("2.2.1"));
    var flashRemotes = List.of(new FlashRemoteId("name1", "first-uuid"), new FlashRemoteId("name2", "second-uuid"));
    var options = new CodeGeneratorOptionsBuilder().withPlatform(MBED_RTOS.getBoardId()).withAppName("tester").withNewId(SERVER_UUID).withEepromDefinition(new BspStm32EepromDefinition(50)).withAuthenticationDefinition(new ReadOnlyAuthenticatorDefinition("1234", flashRemotes)).withExpanderDefinitions(new IoExpanderDefinitionCollection()).withRecursiveNaming(true).withSaveToSrc(true).codeOptions();
    ArduinoGenerator generator = new ArduinoGenerator(adjuster, installer, MBED_RTOS);
    var firstPlugin = pluginConfig.getPlugins().get(0);
    firstPlugin.getProperties().stream().filter(p -> p.getName().equals("SWITCH_IODEVICE")).findFirst().ifPresent(p -> p.setLatestValue("io23017"));
    assertTrue(generator.startConversion(projectDir, pluginConfig.getPlugins(), tree, List.of(), options));
    var sourceDir = projectDir.resolve("src");
    var cppGenerated = new String(Files.readAllBytes(sourceDir.resolve(projectDir.getFileName() + "_menu.cpp")));
    var hGenerated = new String(Files.readAllBytes(sourceDir.resolve(projectDir.getFileName() + "_menu.h")));
    var pluginGeneratedH = new String(Files.readAllBytes(sourceDir.resolve("source.h")));
    var pluginGeneratedCPP = new String(Files.readAllBytes(sourceDir.resolve("source.cpp")));
    var pluginGeneratedTransport = new String(Files.readAllBytes(sourceDir.resolve("MySpecialTransport.h")));
    var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.cpp")).readAllBytes());
    var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.h")).readAllBytes());
    cppGenerated = cppGenerated.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
    cppTemplate = cppTemplate.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
    // these files should line up. IF they do not because of the change in the ArduinoGenerator,
    // then make sure the change is good before adjusting the templates.
    assertEqualsIgnoringCRLF(cppTemplate, cppGenerated);
    assertEqualsIgnoringCRLF(hTemplate, hGenerated);
    assertEqualsIgnoringCRLF("CPP_FILE_CONTENT 10 otherKey", pluginGeneratedCPP);
    assertEqualsIgnoringCRLF("H_FILE_CONTENT 10 otherKey", pluginGeneratedH);
    assertEqualsIgnoringCRLF("My Transport file", pluginGeneratedTransport);
    Mockito.verify(adjuster).makeAdjustments(any(BiConsumer.class), eq(projectDir.resolve(sourceDir.resolve("project_main.cpp")).toString()), eq(projectDir.getFileName().toString()), anyCollection());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) ArduinoGenerator(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoGenerator) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) FlashRemoteId(com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition.FlashRemoteId) ArduinoSketchFileAdjuster(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoSketchFileAdjuster) BspStm32EepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.BspStm32EepromDefinition) ReadOnlyAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) CustomBuilderMenuItemBuilder(com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder) BiConsumer(java.util.function.BiConsumer) DefaultXmlPluginLoaderTest(com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoaderTest) Test(org.junit.jupiter.api.Test)

Example 4 with IoExpanderDefinitionCollection

use of com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection in project tcMenu by davetcc.

the class ArduinoGeneratorTest method runConversionWith.

@SuppressWarnings("unchecked")
private void runConversionWith(EmbeddedPlatform platform, String templateToUse, boolean recursiveName) throws IOException {
    ArduinoSketchFileAdjuster adjuster = Mockito.mock(ArduinoSketchFileAdjuster.class);
    MenuTree tree = buildSimpleTreeReadOnly();
    ArduinoLibraryInstaller installer = Mockito.mock(ArduinoLibraryInstaller.class);
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    var standardOptions = new CodeGeneratorOptionsBuilder().withPlatform(ARDUINO32.getBoardId()).withEepromDefinition(new AVREepromDefinition()).withAuthenticationDefinition(new EepromAuthenticatorDefinition(100, 3)).withExpanderDefinitions(new IoExpanderDefinitionCollection(List.of(new CustomDeviceExpander("123")))).withAppName("app").withNewId(UUID.fromString("4490f2fb-a48b-4c89-b6e5-7f557e5f6faf")).withRecursiveNaming(recursiveName).codeOptions();
    ArduinoGenerator generator = new ArduinoGenerator(adjuster, installer, platform);
    var firstPlugin = pluginConfig.getPlugins().get(0);
    firstPlugin.getProperties().stream().filter(p -> p.getName().equals("SWITCH_IODEVICE")).findFirst().ifPresent(p -> p.setLatestValue("io23017"));
    assertTrue(generator.startConversion(projectDir, pluginConfig.getPlugins(), tree, List.of(), standardOptions));
    VariableNameGenerator gen = new VariableNameGenerator(tree, false, Set.of());
    assertEquals("GenState", gen.makeNameToVar(generateItemWithName("Gen &^%State")));
    assertEquals("ChannelÖôóò", gen.makeNameToVar(generateItemWithName("ChannelÖôóò")));
    var cppGenerated = new String(Files.readAllBytes(projectDir.resolve(projectDir.getFileName() + "_menu.cpp")));
    var hGenerated = new String(Files.readAllBytes(projectDir.resolve(projectDir.getFileName() + "_menu.h")));
    var pluginGeneratedH = new String(Files.readAllBytes(projectDir.resolve("source.h")));
    var pluginGeneratedCPP = new String(Files.readAllBytes(projectDir.resolve("source.cpp")));
    var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream(templateToUse + ".cpp")).readAllBytes());
    var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream(templateToUse + ".h")).readAllBytes());
    cppGenerated = cppGenerated.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
    cppTemplate = cppTemplate.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
    // these files should line up. IF they do not because of the change in the ArduinoGenerator,
    // then make sure the change is good before adjusting the templates.
    assertEqualsIgnoringCRLF(cppTemplate, cppGenerated);
    assertEqualsIgnoringCRLF(hTemplate, hGenerated);
    assertEqualsIgnoringCRLF("CPP_FILE_CONTENT 10 otherKey", pluginGeneratedCPP);
    assertEqualsIgnoringCRLF("H_FILE_CONTENT 10 otherKey", pluginGeneratedH);
    Mockito.verify(adjuster).makeAdjustments(any(BiConsumer.class), eq(projectDir.resolve(projectDir.resolve(projectDir.getFileName() + ".ino")).toString()), eq(projectDir.getFileName().toString()), anyCollection());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) AVREepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.AVREepromDefinition) EepromAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) CustomDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) BiConsumer(java.util.function.BiConsumer)

Example 5 with IoExpanderDefinitionCollection

use of com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection in project tcMenu by davetcc.

the class GenerateCodeDialog method ensureIoFullyDeclared.

private void ensureIoFullyDeclared(CodePluginItem pluginItem) {
    logger.log(INFO, "Checking for unmapped IO devices: " + pluginItem.getDescription());
    var codeOptions = project.getGeneratorOptions();
    // find any IO device declarations that do not match to an entry in the expanders
    var anyIoWithoutEntries = pluginItem.getProperties().stream().filter(prop -> prop.getValidationRules() instanceof IoExpanderPropertyValidationRules).filter(prop -> codeOptions.getExpanderDefinitions().getDefinitionById(prop.getLatestValue()).isEmpty()).toList();
    // nothing to do if list is empty
    if (anyIoWithoutEntries.isEmpty()) {
        logger.log(INFO, "All IO devices mapped");
        return;
    }
    var allExpanders = new HashSet<>(codeOptions.getExpanderDefinitions().getAllExpanders());
    // now we iterate through the unmapped expanders, which must be from prior to the automated support.
    for (var customIo : anyIoWithoutEntries) {
        if (StringHelper.isStringEmptyOrNull(customIo.getLatestValue())) {
            // for empty strings, the previous assumption was using device IO. This is now explicitly defined
            // as deviceIO
            customIo.setLatestValue(InternalDeviceExpander.DEVICE_ID);
            logger.log(INFO, "Device being mapped as internal: " + customIo.getLatestValue());
        } else {
            // otherwise, previously the assumption was using a custom defined expander in the sketch, now we'll
            // actually add that to the sketch.
            allExpanders.add(new CustomDeviceExpander(customIo.getLatestValue()));
            logger.log(INFO, "Device being mapped as custom: " + customIo.getLatestValue());
        }
    }
    project.setGeneratorOptions(new CodeGeneratorOptionsBuilder().withExisting(codeOptions).withExpanderDefinitions(new IoExpanderDefinitionCollection(allExpanders)).codeOptions());
    logger.log(INFO, "Done mapping all IO devices");
}
Also used : EmbeddedPlatforms(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatforms) HPos(javafx.geometry.HPos) javafx.scene.layout(javafx.scene.layout) javafx.scene.control(javafx.scene.control) BaseDialogSupport(com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport) CreatorProperty(com.thecoderscorner.menu.editorui.generator.core.CreatorProperty) CHANGE(com.thecoderscorner.menu.editorui.generator.ui.UICodePluginItem.UICodeAction.CHANGE) IoExpanderPropertyValidationRules(com.thecoderscorner.menu.editorui.generator.validation.IoExpanderPropertyValidationRules) FXCollections.observableArrayList(javafx.collections.FXCollections.observableArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Insets(javafx.geometry.Insets) SelectAuthenticatorTypeDialog(com.thecoderscorner.menu.editorui.dialog.SelectAuthenticatorTypeDialog) BiConsumer(java.util.function.BiConsumer) SELECT(com.thecoderscorner.menu.editorui.generator.ui.UICodePluginItem.UICodeAction.SELECT) CustomDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) StringHelper(com.thecoderscorner.menu.editorui.util.StringHelper) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) SelectEepromTypeDialog(com.thecoderscorner.menu.editorui.dialog.SelectEepromTypeDialog) InternalDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.InternalDeviceExpander) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) SubSystem(com.thecoderscorner.menu.editorui.generator.core.SubSystem) INFO(java.lang.System.Logger.Level.INFO) CoreCodeGenerator(com.thecoderscorner.menu.editorui.generator.core.CoreCodeGenerator) EmbeddedPlatform(com.thecoderscorner.menu.editorui.generator.plugin.EmbeddedPlatform) CurrentEditorProject(com.thecoderscorner.menu.editorui.project.CurrentEditorProject) Collectors(java.util.stream.Collectors) BaseDialogSupport.createDialogStateAndShow(com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport.createDialogStateAndShow) Popup(javafx.stage.Popup) ERROR(java.lang.System.Logger.Level.ERROR) ActionEvent(javafx.event.ActionEvent) List(java.util.List) CodePluginItem(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginItem) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) CodeGeneratorOptions(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions) Optional(java.util.Optional) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) CustomDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander) IoExpanderPropertyValidationRules(com.thecoderscorner.menu.editorui.generator.validation.IoExpanderPropertyValidationRules) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) HashSet(java.util.HashSet) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)

Aggregations

CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)6 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)6 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)3 BiConsumer (java.util.function.BiConsumer)3 Stage (javafx.stage.Stage)3 CreatorProperty (com.thecoderscorner.menu.editorui.generator.core.CreatorProperty)2 CustomDeviceExpander (com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander)2 LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)2 Test (org.junit.jupiter.api.Test)2 CustomBuilderMenuItemBuilder (com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder)1 BaseDialogSupport (com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport)1 BaseDialogSupport.createDialogStateAndShow (com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport.createDialogStateAndShow)1 SelectAuthenticatorTypeDialog (com.thecoderscorner.menu.editorui.dialog.SelectAuthenticatorTypeDialog)1 SelectEepromTypeDialog (com.thecoderscorner.menu.editorui.dialog.SelectEepromTypeDialog)1 CodeGeneratorOptions (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptions)1 AlwaysApplicable (com.thecoderscorner.menu.editorui.generator.applicability.AlwaysApplicable)1 ArduinoGenerator (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoGenerator)1 ArduinoLibraryInstaller (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller)1 ArduinoSketchFileAdjuster (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoSketchFileAdjuster)1 CoreCodeGenerator (com.thecoderscorner.menu.editorui.generator.core.CoreCodeGenerator)1