Search in sources :

Example 1 with KeyValueTree

use of io.sloeber.core.txt.KeyValueTree in project arduino-eclipse-plugin by Sloeber.

the class BoardDescription method onlyKeepValidOptions.

private Map<String, String> onlyKeepValidOptions(Map<String, String> options) {
    Map<String, String> ret = new HashMap<>();
    KeyValueTree tree = myBoardTxtFile.getData();
    KeyValueTree boardMenuSection = tree.getChild(myBoardID + DOT + MENU);
    if (boardMenuSection != null) {
        for (Entry<String, String> curoption : options.entrySet()) {
            String key = curoption.getKey();
            if (boardMenuSection.getChild(key).getKey() != null) {
                ret.put(key, curoption.getValue());
            }
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) KeyValueTree(io.sloeber.core.txt.KeyValueTree)

Example 2 with KeyValueTree

use of io.sloeber.core.txt.KeyValueTree in project arduino-eclipse-plugin by Sloeber.

the class BoardDescription method ParseSection.

private void ParseSection() {
    KeyValueTree rootData = myBoardTxtFile.getData();
    String boardID = getBoardID();
    KeyValueTree boardData = rootData.getChild(boardID);
    String core = boardData.getValue(BUILD + DOT + CORE);
    String variant = boardData.getValue(BUILD + DOT + VARIANT);
    String upload = boardData.getValue(UPLOAD + DOT + TOOL);
    // also search the options
    for (Entry<String, String> curOption : this.myOptions.entrySet()) {
        KeyValueTree curMenuData = boardData.getChild(MENU + DOT + curOption.getKey() + DOT + curOption.getValue());
        String coreOption = curMenuData.getValue(BUILD + DOT + CORE);
        String variantOption = curMenuData.getValue(BUILD + DOT + VARIANT);
        String uploadOption = curMenuData.getValue(UPLOAD + DOT + TOOL);
        if (!coreOption.isEmpty()) {
            core = coreOption;
        }
        if (!variantOption.isEmpty()) {
            variant = variantOption;
        }
        if (!uploadOption.isEmpty()) {
            upload = uploadOption;
        }
    }
    String architecture = getArchitecture();
    if (core != null) {
        String[] valueSplit = core.split(COLON);
        if (valueSplit.length == 2) {
            String refVendor = valueSplit[0];
            myBoardsCore = valueSplit[1];
            myReferencedPlatformCore = BoardsManager.getNewestInstalledPlatform(refVendor, architecture);
            if (myReferencedPlatformCore == null) {
                Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, core).replace(FILE_TAG, getReferencingBoardsFile().toString()).replace(BOARD_TAG, getBoardID())));
                return;
            }
        } else if (valueSplit.length == 4) {
            String refVendor = valueSplit[0];
            String refArchitecture = valueSplit[1];
            VersionNumber refVersion = new VersionNumber(valueSplit[2]);
            myBoardsCore = valueSplit[3];
            myReferencedPlatformCore = BoardsManager.getPlatform(refVendor, refArchitecture, refVersion);
            if (myReferencedPlatformCore == null) {
                Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, core).replace(FILE_TAG, getReferencingBoardsFile().toString()).replace(BOARD_TAG, getBoardID())));
                return;
            }
        } else {
            this.myBoardsCore = core;
        }
    }
    if (variant != null) {
        String[] valueSplit = variant.split(COLON);
        if (valueSplit.length == 2) {
            String refVendor = valueSplit[0];
            myBoardsVariant = valueSplit[1];
            myReferencedPlatformVariant = BoardsManager.getNewestInstalledPlatform(refVendor, architecture);
            if (myReferencedPlatformVariant == null) {
                Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, variant).replace(FILE_TAG, getReferencingBoardsFile().toString()).replace(BOARD_TAG, getBoardID())));
                return;
            }
        } else if (valueSplit.length == 4) {
            String refVendor = valueSplit[0];
            String refArchitecture = valueSplit[1];
            VersionNumber refVersion = new VersionNumber(valueSplit[2]);
            myBoardsVariant = valueSplit[3];
            if ("*".equals(valueSplit[2])) {
                // $NON-NLS-1$
                myReferencedPlatformVariant = BoardsManager.getNewestInstalledPlatform(refVendor, refArchitecture);
            } else {
                myReferencedPlatformVariant = BoardsManager.getPlatform(refVendor, refArchitecture, refVersion);
            }
            if (myReferencedPlatformVariant == null) {
                Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, variant).replace(FILE_TAG, getReferencingBoardsFile().toString()).replace(BOARD_TAG, getBoardID())));
                return;
            }
        } else {
            myBoardsVariant = variant;
        }
    }
    if (upload != null) {
        String[] valueSplit = upload.split(COLON);
        if (valueSplit.length == 2) {
            String refVendor = valueSplit[0];
            myUploadTool = valueSplit[1];
            myReferencedPlatformUpload = BoardsManager.getNewestInstalledPlatform(refVendor, architecture);
            if (myReferencedPlatformUpload == null) {
                Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, upload).replace(FILE_TAG, getReferencingBoardsFile().toString()).replace(BOARD_TAG, getBoardID())));
                return;
            }
        } else if (valueSplit.length == 4) {
            String refVendor = valueSplit[0];
            String refArchitecture = valueSplit[1];
            VersionNumber refVersion = new VersionNumber(valueSplit[2]);
            myUploadTool = valueSplit[3];
            myReferencedPlatformUpload = BoardsManager.getPlatform(refVendor, refArchitecture, refVersion);
            if (this.myReferencedPlatformUpload == null) {
                Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, upload).replace(FILE_TAG, getReferencingBoardsFile().toString()).replace(BOARD_TAG, getBoardID())));
                return;
            }
        } else {
            myUploadTool = upload;
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) KeyValueTree(io.sloeber.core.txt.KeyValueTree)

Example 3 with KeyValueTree

use of io.sloeber.core.txt.KeyValueTree in project arduino-eclipse-plugin by Sloeber.

the class TestTxtFile method dumpMatchesExpectationWrongKey.

@Test
public void dumpMatchesExpectationWrongKey() {
    KeyValueTree root = getDataSet1();
    KeyValueTree key1 = root.getChild("NotExistingKey");
    String result = key1.dump();
    String expectedResult = "";
    assertEquals("Wrong Key", expectedResult, result);
}
Also used : KeyValueTree(io.sloeber.core.txt.KeyValueTree) Test(org.junit.Test)

Example 4 with KeyValueTree

use of io.sloeber.core.txt.KeyValueTree in project arduino-eclipse-plugin by Sloeber.

the class TestTxtFile method getDataSet2.

private KeyValueTree getDataSet2() {
    KeyValueTree root = getDataSet1();
    root.addValue("he.I.Can.Do.This", "not once");
    root.addValue("he.I.Can.Hit.This", "not twice");
    root.addValue("he.I.Can.hit.This", "not three times");
    root.addValue("Something.Completely.different", "but always");
    return root;
}
Also used : KeyValueTree(io.sloeber.core.txt.KeyValueTree)

Example 5 with KeyValueTree

use of io.sloeber.core.txt.KeyValueTree in project arduino-eclipse-plugin by Sloeber.

the class TestTxtFile method dumpMatchesExpectationFull.

@Test
public void dumpMatchesExpectationFull() {
    KeyValueTree root = getDataSet1();
    String result = root.dump();
    String expectedResult = "key2=value2\n" + "key2.key2_1=value2_1\n" + "key1.key1_1=value1_1\n" + "key1.key1_2=value1_2\n";
    assertEquals("creation", expectedResult, result);
}
Also used : KeyValueTree(io.sloeber.core.txt.KeyValueTree) Test(org.junit.Test)

Aggregations

KeyValueTree (io.sloeber.core.txt.KeyValueTree)15 Test (org.junit.Test)9 TxtFile (io.sloeber.core.txt.TxtFile)2 BoardTxtFile (io.sloeber.core.txt.BoardTxtFile)1 PlatformTxtFile (io.sloeber.core.txt.PlatformTxtFile)1 Programmers (io.sloeber.core.txt.Programmers)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1