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;
}
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);
}
}
}
}
}
}
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());
}
}
}
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
}
}
}
}
}
}
}
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();
}
});
}
}
});
}
Aggregations