Search in sources :

Example 1 with VersionNumber

use of io.sloeber.core.api.VersionNumber in project arduino-eclipse-plugin by Sloeber.

the class ArduinoLibrary method addVersion.

protected void addVersion(JsonElement json) {
    JsonObject jsonObject = json.getAsJsonObject();
    VersionNumber versionNumber = getSafeVersion(jsonObject, VERSION_KEY);
    versions.put(versionNumber, new ArduinoLibraryVersion(jsonObject, this));
}
Also used : JsonObject(com.google.gson.JsonObject) VersionNumber(io.sloeber.core.api.VersionNumber)

Example 2 with VersionNumber

use of io.sloeber.core.api.VersionNumber in project arduino-eclipse-plugin by Sloeber.

the class WorkAround method applyKnownWorkArounds.

/**
 * workarounds done at installation time. I try to keep those at a minimum but
 * none platform.txt and boards.txt workarounds need to be done during install
 * time
 *
 * @param arduinoPlatformVersion
 */
public static void applyKnownWorkArounds(ArduinoPlatformVersion arduinoPlatformVersion) {
    /*
         * for STM32 V1.8 and later #include "SrcWrapper.h" to Arduino.h remove the
         * prebuild actions remove the build_opt
         * https://github.com/Sloeber/arduino-eclipse-plugin/issues/1143
         */
    if (new VersionNumber("1.8.0").compareTo(arduinoPlatformVersion.getVersion()) != 1) {
        if ("stm32".equals(arduinoPlatformVersion.getArchitecture())) {
            if ("STM32".equals(arduinoPlatformVersion.getParent().getName())) {
                if (arduinoPlatformVersion.getVersion().compareTo("1.8.0") == 0) {
                    File arduino_h = arduinoPlatformVersion.getInstallPath().append("cores").append("arduino").append("Arduino.h").toFile();
                    if (arduino_h.exists()) {
                        FileModifiers.replaceInFile(arduino_h, false, "#include \"pins_arduino.h\"", "#include \"pins_arduino.h\"\n#include \"SrcWrapper.h\"");
                    }
                }
            }
        }
    }
    MakePlatformSloeberTXT(arduinoPlatformVersion.getPlatformFile());
    MakeBoardsSloeberTxt(arduinoPlatformVersion.getBoardsFile());
}
Also used : File(java.io.File) VersionNumber(io.sloeber.core.api.VersionNumber)

Example 3 with VersionNumber

use of io.sloeber.core.api.VersionNumber in project arduino-eclipse-plugin by Sloeber.

the class WorkAround method platformApplyReleaseWorkArounds.

/**
 * This method applies workaround to specific releases of specific platforms
 *
 * @param inPlatformTxt
 *            The content of the platform.txt
 *
 * @param requestedFileToWorkAround
 *            The path of the platform.txt so we can validate for
 *            provider/architecture and versions
 * @return the worked around platform.txt
 */
private static String platformApplyReleaseWorkArounds(String inPlatformTxt, File requestedFileToWorkAround) {
    String platformTXT = inPlatformTxt;
    try {
        // https://github.com/Sloeber/arduino-eclipse-plugin/issues/1182#
        Path platformTXTPath = new Path(requestedFileToWorkAround.toString());
        int totalSegments = platformTXTPath.segmentCount();
        String platformVersion = platformTXTPath.segment(totalSegments - 2);
        String platformArchitecture = platformTXTPath.segment(totalSegments - 3);
        String platformName = platformTXTPath.segment(totalSegments - 5);
        if (new VersionNumber("1.8.0").compareTo(platformVersion) != 1) {
            if ("stm32".equals(platformArchitecture)) {
                if ("STM32".equals(platformName)) {
                    platformTXT = platformTXT.replace("\"@{build.opt.path}\"", "");
                    platformTXT = platformTXT.replaceAll("recipe\\.hooks\\.prebuild\\..*", "");
                }
            }
        }
    } catch (Exception e) {
    // ignore
    }
    return platformTXT;
}
Also used : Path(org.eclipse.core.runtime.Path) VersionNumber(io.sloeber.core.api.VersionNumber) IOException(java.io.IOException)

Example 4 with VersionNumber

use of io.sloeber.core.api.VersionNumber in project arduino-eclipse-plugin by Sloeber.

the class LibrarySelectionPage method createTree.

public void createTree(Composite parent) {
    // filtering applied to all columns
    PatternFilter filter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
            int numberOfColumns = ((TreeViewer) viewer1).getTree().getColumnCount();
            boolean isMatch = false;
            for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
                String labelText = LibraryLabelProvider.getColumnText(element, columnIndex);
                isMatch |= wordMatches(labelText);
            }
            return isMatch;
        }
    };
    this.tree = new FilteredTree(parent, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
            CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
            viewer1.setCheckStateProvider(new LibraryCheckProvider());
            viewer1.setLabelProvider(new LibraryLabelProvider());
            viewer1.setContentProvider(new LibraryContentProvider());
            return viewer1;
        }
    };
    this.viewer = this.tree.getViewer();
    this.viewer.setInput(this.libs);
    TreeColumn name = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
    name.setWidth(400);
    TreeColumn version = new TreeColumn(this.viewer.getTree(), SWT.LEFT);
    version.setWidth(100);
    // create the editor and set its attributes
    this.editor = new TreeEditor(this.viewer.getTree());
    this.editor.horizontalAlignment = SWT.LEFT;
    this.editor.grabHorizontal = true;
    this.editor.setColumn(1);
    // this ensures the tree labels are displayed correctly
    this.viewer.refresh(true);
    // enable tooltips
    ColumnViewerToolTipSupport.enableFor(this.viewer);
    // tree interactions listener
    this.viewer.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (LibrarySelectionPage.this.editor.getEditor() != null) {
                LibrarySelectionPage.this.editor.getEditor().dispose();
            }
            final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null;
            if (item != null && event.detail == SWT.CHECK) {
                if (item.getData() instanceof LibraryTree.Category) {
                    Category category = ((LibraryTree.Category) item.getData());
                    item.setGrayed(false);
                    for (LibraryTree.Library child : category.getLibraries()) {
                        if (item.getChecked()) {
                            child.setVersion(child.getLatest());
                        } else {
                            child.setVersion((ArduinoLibraryVersion) null);
                        }
                    }
                    for (TreeItem child : item.getItems()) {
                        child.setChecked(item.getChecked());
                        child.setText(1, ((LibraryTree.Library) child.getData()).getVersionString());
                    }
                } else {
                    if (item.getData() instanceof LibraryTree.Library) {
                        Library lib = ((LibraryTree.Library) item.getData());
                        if (item.getChecked()) {
                            lib.setVersion(lib.getLatest());
                        } else {
                            lib.setVersion((ArduinoLibraryVersion) null);
                        }
                        item.setText(0, lib.getName());
                        item.setText(1, lib.getVersionString());
                        verifySubtreeCheckStatus(item.getParentItem());
                    }
                }
            }
            if (item != null && item.getItemCount() == 0 && item.getChecked()) {
                // Create the dropdown and add data to it
                final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY);
                Library selectedLib = ((LibraryTree.Library) item.getData());
                for (ArduinoLibraryVersion version1 : selectedLib.getVersions()) {
                    combo.add(version1.getVersion().toString());
                }
                ArduinoLibraryVersion displayVersion = selectedLib.getVersion();
                if (displayVersion == null) {
                    displayVersion = selectedLib.getLatest();
                    selectedLib.setVersion(displayVersion);
                    item.setText(0, selectedLib.getName());
                }
                combo.select(combo.indexOf(displayVersion.getVersion().toString()));
                // Compute the width for the editor
                // Also, compute the column width, so that the dropdown fits
                // Set the focus on the dropdown and set into the editor
                combo.setFocus();
                LibrarySelectionPage.this.editor.setEditor(combo, item, 1);
                // Add a listener to set the selected item back into the
                // cell
                combo.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event1) {
                        LibraryTree.Library lib = (LibraryTree.Library) item.getData();
                        lib.setVersion(new VersionNumber(combo.getText()));
                        item.setText(1, lib.getVersionString());
                        item.setText(0, lib.getName());
                        // Item selected: end the editing session
                        combo.dispose();
                    }
                });
            }
        }
    });
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Category(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category) TreeItem(org.eclipse.swt.widgets.TreeItem) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Category(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category) Composite(org.eclipse.swt.widgets.Composite) TreeEditor(org.eclipse.swt.custom.TreeEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Library(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library) Point(org.eclipse.swt.graphics.Point) VersionNumber(io.sloeber.core.api.VersionNumber) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) CCombo(org.eclipse.swt.custom.CCombo) ArduinoLibrary(io.sloeber.core.api.Json.ArduinoLibrary) Library(io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library)

Aggregations

VersionNumber (io.sloeber.core.api.VersionNumber)4 JsonObject (com.google.gson.JsonObject)1 ArduinoLibrary (io.sloeber.core.api.Json.ArduinoLibrary)1 ArduinoLibraryVersion (io.sloeber.core.api.Json.ArduinoLibraryVersion)1 Category (io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category)1 Library (io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (org.eclipse.core.runtime.Path)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 CCombo (org.eclipse.swt.custom.CCombo)1 TreeEditor (org.eclipse.swt.custom.TreeEditor)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Composite (org.eclipse.swt.widgets.Composite)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1