mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-16 21:45:22 +02:00
Bug 480169 - Add proper support for platform libraries.
Change-Id: I3016ee6db3cd892f59b44d74d4181c30ca1b5b10
This commit is contained in:
parent
a88d0eb0d9
commit
12acb6f54e
5 changed files with 116 additions and 32 deletions
|
@ -228,4 +228,18 @@ public class ArduinoLibrary {
|
||||||
return sources;
|
return sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof ArduinoLibrary) {
|
||||||
|
return getName().equals(((ArduinoLibrary) obj).getName());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,9 +228,18 @@ public class ArduinoManager {
|
||||||
}.getType();
|
}.getType();
|
||||||
Set<String> libraryNames = new Gson().fromJson(librarySetting, stringSet);
|
Set<String> libraryNames = new Gson().fromJson(librarySetting, stringSet);
|
||||||
LibraryIndex index = ArduinoManager.instance.getLibraryIndex();
|
LibraryIndex index = ArduinoManager.instance.getLibraryIndex();
|
||||||
|
|
||||||
|
ArduinoPlatform platform = project.getActiveBuildConfig().getAdapter(ArduinoBuildConfiguration.class).getBoard()
|
||||||
|
.getPlatform();
|
||||||
List<ArduinoLibrary> libraries = new ArrayList<>(libraryNames.size());
|
List<ArduinoLibrary> libraries = new ArrayList<>(libraryNames.size());
|
||||||
for (String name : libraryNames) {
|
for (String name : libraryNames) {
|
||||||
libraries.add(index.getLibrary(name));
|
ArduinoLibrary lib = index.getLibrary(name);
|
||||||
|
if (lib == null) {
|
||||||
|
lib = platform.getLibrary(name);
|
||||||
|
}
|
||||||
|
if (lib != null) {
|
||||||
|
libraries.add(lib);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return libraries;
|
return libraries;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class ArduinoPlatform {
|
||||||
private HierarchicalProperties boardsProperties;
|
private HierarchicalProperties boardsProperties;
|
||||||
private Properties platformProperties;
|
private Properties platformProperties;
|
||||||
private Map<String, String> menus = new HashMap<>();
|
private Map<String, String> menus = new HashMap<>();
|
||||||
|
private Map<String, ArduinoLibrary> libraries;
|
||||||
|
|
||||||
void setOwner(ArduinoPackage pkg) {
|
void setOwner(ArduinoPackage pkg) {
|
||||||
this.pkg = pkg;
|
this.pkg = pkg;
|
||||||
|
@ -218,6 +219,39 @@ public class ArduinoPlatform {
|
||||||
return sources;
|
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) {
|
public IStatus install(IProgressMonitor monitor) {
|
||||||
// Check if we're installed already
|
// Check if we're installed already
|
||||||
if (isInstalled()) {
|
if (isInstalled()) {
|
||||||
|
@ -253,9 +287,6 @@ public class ArduinoPlatform {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload the library index to pick up platform libraries
|
|
||||||
ArduinoManager.instance.loadLibraryIndex(false);
|
|
||||||
|
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package org.eclipse.cdt.arduino.core.internal.board;
|
package org.eclipse.cdt.arduino.core.internal.board;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -22,25 +20,6 @@ public class LibraryIndex {
|
||||||
private Map<String, ArduinoLibrary> latestLibs = new HashMap<>();
|
private Map<String, ArduinoLibrary> latestLibs = new HashMap<>();
|
||||||
|
|
||||||
public void resolve() throws IOException {
|
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) {
|
for (ArduinoLibrary library : libraries) {
|
||||||
String name = library.getName();
|
String name = library.getName();
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,9 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoLibrary;
|
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.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.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.Activator;
|
||||||
import org.eclipse.cdt.arduino.ui.internal.Messages;
|
import org.eclipse.cdt.arduino.ui.internal.Messages;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -33,7 +35,7 @@ import org.eclipse.ui.dialogs.PropertyPage;
|
||||||
|
|
||||||
public class LibrariesPropertyPage extends PropertyPage {
|
public class LibrariesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
private static class ContentProvider implements ITreeContentProvider {
|
private class ContentProvider implements ITreeContentProvider {
|
||||||
private LibraryIndex index;
|
private LibraryIndex index;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,6 +53,13 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
return !index.getCategories().isEmpty();
|
return !index.getCategories().isEmpty();
|
||||||
} else if (element instanceof String) { // category
|
} else if (element instanceof String) { // category
|
||||||
return !index.getLibraries((String) element).isEmpty();
|
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) {
|
} else if (element instanceof ArduinoLibrary) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,8 +70,22 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
@Override
|
@Override
|
||||||
public Object getParent(Object element) {
|
public Object getParent(Object element) {
|
||||||
if (element instanceof ArduinoLibrary) {
|
if (element instanceof ArduinoLibrary) {
|
||||||
return ((ArduinoLibrary) element).getCategory();
|
ArduinoLibrary lib = (ArduinoLibrary) element;
|
||||||
} else if (element instanceof String) {
|
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;
|
return index;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -71,15 +94,32 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getElements(Object inputElement) {
|
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
|
@Override
|
||||||
public Object[] getChildren(Object parentElement) {
|
public Object[] getChildren(Object parentElement) {
|
||||||
if (parentElement instanceof String) {
|
if (parentElement instanceof String) {
|
||||||
return index.getLibraries((String) parentElement).toArray(new ArduinoLibrary[0]);
|
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 {
|
} else {
|
||||||
return null;
|
return new Object[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +134,8 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
public String getColumnText(Object element, int columnIndex) {
|
public String getColumnText(Object element, int columnIndex) {
|
||||||
if (element instanceof String) {
|
if (element instanceof String) {
|
||||||
return columnIndex == 0 ? (String) element : null;
|
return columnIndex == 0 ? (String) element : null;
|
||||||
|
} else if (element instanceof ArduinoPlatform) {
|
||||||
|
return columnIndex == 0 ? ((ArduinoPlatform) element).getName() : null;
|
||||||
} else if (element instanceof ArduinoLibrary) {
|
} else if (element instanceof ArduinoLibrary) {
|
||||||
switch (columnIndex) {
|
switch (columnIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -139,6 +181,7 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, true) {
|
}, true) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
|
protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
|
||||||
return new ContainerCheckedTreeViewer(parent, style);
|
return new ContainerCheckedTreeViewer(parent, style);
|
||||||
|
@ -171,8 +214,16 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return comp;
|
return comp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private IProject getProject() {
|
||||||
|
return getElement().getAdapter(IProject.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArduinoPlatform getPlatform() throws CoreException {
|
||||||
|
return getProject().getActiveBuildConfig().getAdapter(ArduinoBuildConfiguration.class).getBoard().getPlatform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,7 +238,7 @@ public class LibrariesPropertyPage extends PropertyPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ArduinoManager.instance.setLibraries(getElement().getAdapter(IProject.class), libs);
|
ArduinoManager.instance.setLibraries(getProject(), libs);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue