private HierarchicalProperties boardsProperties;
private Properties platformProperties;
private Map<String, String> menus = new HashMap<>();
+ private Map<String, ArduinoLibrary> libraries;
void setOwner(ArduinoPackage pkg) {
this.pkg = pkg;
return sources;
}
+ private void initLibraries() throws CoreException {
+ libraries = new HashMap<>();
+ File[] libraryDirs = getInstallPath().resolve("libraries").toFile().listFiles(); //$NON-NLS-1$
+ if (libraryDirs != null) {
+ for (File libraryDir : libraryDirs) {
+ Path propsPath = libraryDir.toPath().resolve("library.properties"); //$NON-NLS-1$
+ if (propsPath.toFile().exists()) {
+ try {
+ ArduinoLibrary lib = new ArduinoLibrary(propsPath);
+ libraries.put(lib.getName(), lib);
+ } catch (IOException e) {
+ throw new CoreException(
+ new Status(IStatus.ERROR, Activator.getId(), "Loading " + propsPath, e)); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+
+ public synchronized Collection<ArduinoLibrary> getLibraries() throws CoreException {
+ if (libraries == null && isInstalled()) {
+ initLibraries();
+ }
+ return libraries.values();
+ }
+
+ public synchronized ArduinoLibrary getLibrary(String name) throws CoreException {
+ if (libraries == null && isInstalled()) {
+ initLibraries();
+ }
+ return libraries != null ? libraries.get(name) : null;
+ }
+
public IStatus install(IProgressMonitor monitor) {
// Check if we're installed already
if (isInstalled()) {
return status;
}
- // Reload the library index to pick up platform libraries
- ArduinoManager.instance.loadLibraryIndex(false);
-
return Status.OK_STATUS;
}
package org.eclipse.cdt.arduino.core.internal.board;
-import java.io.File;
import java.io.IOException;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
private Map<String, ArduinoLibrary> latestLibs = new HashMap<>();
public void resolve() throws IOException {
- // Add in platform libraries
- for (PackageIndex index : ArduinoManager.instance.getPackageIndices()) {
- for (ArduinoPackage pkg : index.getPackages()) {
- for (ArduinoPlatform platform : pkg.getPlatforms()) {
- if (platform.isInstalled()) {
- File[] libraryDirs = platform.getInstallPath().resolve("libraries").toFile().listFiles(); //$NON-NLS-1$
- if (libraryDirs != null) {
- for (File libraryDir : libraryDirs) {
- Path propsPath = libraryDir.toPath().resolve("library.properties"); //$NON-NLS-1$
- if (propsPath.toFile().exists()) {
- libraries.add(new ArduinoLibrary(propsPath));
- }
- }
- }
- }
- }
- }
- }
-
for (ArduinoLibrary library : libraries) {
String name = library.getName();
import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
+import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
import org.eclipse.cdt.arduino.core.internal.board.LibraryIndex;
+import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.core.resources.IProject;
public class LibrariesPropertyPage extends PropertyPage {
- private static class ContentProvider implements ITreeContentProvider {
+ private class ContentProvider implements ITreeContentProvider {
private LibraryIndex index;
@Override
return !index.getCategories().isEmpty();
} else if (element instanceof String) { // category
return !index.getLibraries((String) element).isEmpty();
+ } else if (element instanceof ArduinoPlatform) {
+ try {
+ return !((ArduinoPlatform) element).getLibraries().isEmpty();
+ } catch (CoreException e) {
+ Activator.log(e);
+ return false;
+ }
} else if (element instanceof ArduinoLibrary) {
return false;
} else {
@Override
public Object getParent(Object element) {
if (element instanceof ArduinoLibrary) {
- return ((ArduinoLibrary) element).getCategory();
- } else if (element instanceof String) {
+ ArduinoLibrary lib = (ArduinoLibrary) element;
+ String category = lib.getCategory();
+ if (category != null) {
+ return category;
+ }
+
+ try {
+ ArduinoPlatform platform = getPlatform();
+ if (platform.getLibrary(lib.getName()) != null) {
+ return platform;
+ }
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+ return null;
+ } else if (element instanceof String || element instanceof ArduinoPlatform) {
return index;
} else {
return null;
@Override
public Object[] getElements(Object inputElement) {
- return ((LibraryIndex) inputElement).getCategories().toArray(new String[0]);
+ List<Object> categories = new ArrayList<>();
+
+ try {
+ ArduinoPlatform platform = getPlatform();
+ categories.add(platform);
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+
+ categories.addAll(((LibraryIndex) inputElement).getCategories());
+ return categories.toArray();
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof String) {
return index.getLibraries((String) parentElement).toArray(new ArduinoLibrary[0]);
+ } else if (parentElement instanceof ArduinoPlatform) {
+ try {
+ return ((ArduinoPlatform) parentElement).getLibraries().toArray();
+ } catch (CoreException e) {
+ Activator.log(e);
+ return new Object[0];
+ }
} else {
- return null;
+ return new Object[0];
}
}
}
public String getColumnText(Object element, int columnIndex) {
if (element instanceof String) {
return columnIndex == 0 ? (String) element : null;
+ } else if (element instanceof ArduinoPlatform) {
+ return columnIndex == 0 ? ((ArduinoPlatform) element).getName() : null;
} else if (element instanceof ArduinoLibrary) {
switch (columnIndex) {
case 0:
}
}
}, true) {
+
@Override
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
return new ContainerCheckedTreeViewer(parent, style);
} catch (CoreException e) {
Activator.log(e);
}
-
return comp;
+
+ }
+
+ private IProject getProject() {
+ return getElement().getAdapter(IProject.class);
+ }
+
+ private ArduinoPlatform getPlatform() throws CoreException {
+ return getProject().getActiveBuildConfig().getAdapter(ArduinoBuildConfiguration.class).getBoard().getPlatform();
}
@Override
}
}
try {
- ArduinoManager.instance.setLibraries(getElement().getAdapter(IProject.class), libs);
+ ArduinoManager.instance.setLibraries(getProject(), libs);
} catch (CoreException e) {
Activator.log(e);
}