Search in sources :

Example 1 with ArduinoLibraryVersion

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

the class LibraryManager method getLatestInstallableLibraries.

public static Map<String, ArduinoLibraryVersion> getLatestInstallableLibraries(Set<String> libnames) {
    Set<String> remainingLibNames = new TreeSet<>(libnames);
    Map<String, ArduinoLibraryVersion> ret = new HashMap<>();
    for (ArduinoLibraryIndex libraryIndex : libraryIndices) {
        ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames));
        remainingLibNames.removeAll(ret.keySet());
    }
    return ret;
}
Also used : ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArduinoLibraryIndex(io.sloeber.core.api.Json.ArduinoLibraryIndex)

Example 2 with ArduinoLibraryVersion

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

the class LibraryManager method InstallDefaultLibraries.

public static void InstallDefaultLibraries(IProgressMonitor monitor) {
    for (ArduinoLibraryIndex libindex : libraryIndices) {
        for (String libraryName : Defaults.DEFAULT_INSTALLED_LIBRARIES) {
            ArduinoLibrary toInstalLib = libindex.getLibrary(libraryName);
            if (toInstalLib != null) {
                ArduinoLibraryVersion toInstalLibVersion = toInstalLib.getNewestVersion();
                ArduinoLibraryVersion instaledLibVersion = toInstalLib.getInstalledVersion();
                if (toInstalLibVersion != null) {
                    if (toInstalLibVersion != instaledLibVersion) {
                        if (instaledLibVersion != null) {
                            unInstall(instaledLibVersion, monitor);
                        }
                        install(toInstalLibVersion, monitor);
                    }
                }
            }
        }
    }
}
Also used : ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) ArduinoLibraryIndex(io.sloeber.core.api.Json.ArduinoLibraryIndex) ArduinoLibrary(io.sloeber.core.api.Json.ArduinoLibrary)

Example 3 with ArduinoLibraryVersion

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

the class LibraryManager method installLibrary.

/**
 * install 1 single library based on the library name
 *
 * @param libName
 */
public static void installLibrary(String libName) {
    Set<String> libNamesToInstall = new TreeSet<>();
    libNamesToInstall.add(libName);
    Map<String, ArduinoLibraryVersion> libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall);
    if (!libsToInstall.isEmpty()) {
        for (ArduinoLibraryVersion curLib : libsToInstall.values()) {
            install(curLib, new NullProgressMonitor());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) TreeSet(java.util.TreeSet)

Example 4 with ArduinoLibraryVersion

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

the class Libraries method checkLibraries.

public static void checkLibraries(IProject affectedProject) {
    Map<String, String> includeHeaderReplacement = getIncludeHeaderReplacement();
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    if (mngr != null) {
        ICProjectDescription projectDescription = mngr.getProjectDescription(affectedProject, true);
        if (projectDescription != null) {
            ICConfigurationDescription confDesc = projectDescription.getActiveConfiguration();
            if (confDesc != null) {
                Set<String> UnresolvedIncludedHeaders = getUnresolvedProjectIncludes(affectedProject);
                Set<String> alreadyAddedLibs = getAllLibrariesFromProject(affectedProject);
                // remove pgmspace as it gives a problem
                // $NON-NLS-1$
                UnresolvedIncludedHeaders.remove("pgmspace");
                if (UnresolvedIncludedHeaders.isEmpty()) {
                    return;
                }
                for (Map.Entry<String, String> entry : includeHeaderReplacement.entrySet()) {
                    if (UnresolvedIncludedHeaders.contains(entry.getKey())) {
                        UnresolvedIncludedHeaders.remove(entry.getKey());
                        UnresolvedIncludedHeaders.add(entry.getValue());
                    }
                }
                UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs);
                IInstallLibraryHandler installHandler = LibraryManager.getInstallLibraryHandler();
                if (installHandler.autoInstall()) {
                    // Check if there are libraries that are not found in
                    // the installed libraries
                    Map<String, IPath> installedLibs = getAllInstalledLibraries(confDesc);
                    Set<String> uninstalledIncludedHeaders = new TreeSet<>(UnresolvedIncludedHeaders);
                    uninstalledIncludedHeaders.removeAll(installedLibs.keySet());
                    if (!uninstalledIncludedHeaders.isEmpty()) {
                        // some libraries may need to be installed
                        Map<String, ArduinoLibraryVersion> availableLibs = LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders);
                        if (!availableLibs.isEmpty()) {
                            // Ask the user which libs need installing
                            availableLibs = installHandler.selectLibrariesToInstall(availableLibs);
                            for (Entry<String, ArduinoLibraryVersion> curLib : availableLibs.entrySet()) {
                                LibraryManager.install(curLib.getValue(), new NullProgressMonitor());
                            }
                        }
                    }
                }
                Map<String, IPath> installedLibs = getAllInstalledLibraries(confDesc);
                installedLibs.keySet().retainAll(UnresolvedIncludedHeaders);
                if (!installedLibs.isEmpty()) {
                    // there are possible libraries to add
                    Common.log(new Status(IStatus.INFO, CORE_PLUGIN_ID, // $NON-NLS-1$
                    "list of libraries to add to project " + affectedProject.getName() + // $NON-NLS-1$
                    ": " + installedLibs.keySet().toString()));
                    Map<String, List<IPath>> foldersToChange = addLibrariesToProject(affectedProject, installedLibs);
                    if (adjustProjectDescription(confDesc, foldersToChange)) {
                        try {
                            mngr.setProjectDescription(affectedProject, projectDescription, true, null);
                        } catch (CoreException e) {
                        // this can fail because the project may already
                        // be
                        // deleted
                        }
                    }
                }
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) ArduinoLibraryVersion(io.sloeber.core.api.Json.ArduinoLibraryVersion) CoreException(org.eclipse.core.runtime.CoreException) IInstallLibraryHandler(io.sloeber.core.api.IInstallLibraryHandler) TreeSet(java.util.TreeSet) LinkedList(java.util.LinkedList) List(java.util.List) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 5 with ArduinoLibraryVersion

use of io.sloeber.core.api.Json.ArduinoLibraryVersion 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

ArduinoLibraryVersion (io.sloeber.core.api.Json.ArduinoLibraryVersion)7 ArduinoLibrary (io.sloeber.core.api.Json.ArduinoLibrary)4 ArduinoLibraryIndex (io.sloeber.core.api.Json.ArduinoLibraryIndex)3 TreeSet (java.util.TreeSet)3 Category (io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category)2 Library (io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library)2 HashMap (java.util.HashMap)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IInstallLibraryHandler (io.sloeber.core.api.IInstallLibraryHandler)1 VersionNumber (io.sloeber.core.api.VersionNumber)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)1 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)1 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1