mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
Using enumerations for LibraryLocation
This commit is contained in:
parent
decf40813c
commit
60dd0945d6
@ -55,5 +55,6 @@
|
||||
<classpathentry kind="lib" path="lib/commons-lang3-3.8.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino4.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc-core-1.20.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc/protobuf-java-3.11.4.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
BIN
app/lib/grpc/protobuf-java-3.11.4.jar
Normal file
BIN
app/lib/grpc/protobuf-java-3.11.4.jar
Normal file
Binary file not shown.
@ -26,6 +26,7 @@ import cc.arduino.Compiler;
|
||||
import cc.arduino.Constants;
|
||||
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler;
|
||||
import cc.arduino.UploaderUtils;
|
||||
import cc.arduino.cli.commands.Lib.LibraryLocation;
|
||||
import cc.arduino.contributions.*;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
|
||||
@ -76,10 +77,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import static processing.app.I18n.format;
|
||||
import static processing.app.I18n.tr;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_CORE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_IDE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
|
||||
|
||||
|
||||
/**
|
||||
@ -1218,7 +1215,7 @@ public class Base {
|
||||
LibraryList otherLibs = new LibraryList();
|
||||
for (UserLibrary lib : allLibraries) {
|
||||
// Get the library's location - used for sorting into categories
|
||||
String location = lib.getLocation();
|
||||
LibraryLocation location = lib.getLocation();
|
||||
// Is this library compatible?
|
||||
Collection<String> arch = lib.getArchitectures();
|
||||
boolean compatible;
|
||||
@ -1228,7 +1225,7 @@ public class Base {
|
||||
compatible = arch.contains(myArch);
|
||||
}
|
||||
// IDE Libaries (including retired)
|
||||
if (location.equals(LOCATION_IDE)) {
|
||||
if (location.equals(LibraryLocation.ide_builtin)) {
|
||||
if (compatible) {
|
||||
// only compatible IDE libs are shown
|
||||
if (lib.getTypes().contains("Retired")) {
|
||||
@ -1238,15 +1235,15 @@ public class Base {
|
||||
}
|
||||
}
|
||||
// Platform Libraries
|
||||
} else if (location.equals(LOCATION_CORE)) {
|
||||
} else if (location.equals(LibraryLocation.platform_builtin)) {
|
||||
// all platform libs are assumed to be compatible
|
||||
platformLibs.add(lib);
|
||||
// Referenced Platform Libraries
|
||||
} else if (location.equals(LOCATION_REF_CORE)) {
|
||||
} else if (location.equals(LibraryLocation.referenced_platform_builtin)) {
|
||||
// all referenced platform libs are assumed to be compatible
|
||||
referencedPlatformLibs.add(lib);
|
||||
// Sketchbook Libraries (including incompatible)
|
||||
} else if (location.equals(LOCATION_SKETCHBOOK)) {
|
||||
} else if (location.equals(LibraryLocation.user)) {
|
||||
if (compatible) {
|
||||
// libraries promoted from sketchbook (behave as builtin)
|
||||
if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")
|
||||
|
@ -63,7 +63,6 @@
|
||||
<classpathentry kind="lib" path="lib/grpc/opencensus-api-0.19.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc/opencensus-contrib-grpc-metrics-0.19.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc/proto-google-common-protos-1.12.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc/protobuf-javanano-3.0.0-alpha-5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc/protobuf-java-3.9.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/grpc/protobuf-java-3.11.4.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
BIN
arduino-core/lib/grpc/protobuf-java-3.11.4.jar
Normal file
BIN
arduino-core/lib/grpc/protobuf-java-3.11.4.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -34,10 +34,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import cc.arduino.cli.commands.Lib.LibraryLocation;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
|
||||
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
|
||||
|
||||
public class ContributedLibrary {
|
||||
|
||||
private String name;
|
||||
@ -78,12 +77,12 @@ public class ContributedLibrary {
|
||||
return releases.values().stream() //
|
||||
.filter(ContributedLibraryRelease::isLibraryInstalled) //
|
||||
.reduce((x, y) -> {
|
||||
String lx = x.getInstalledLibrary().get().getLocation();
|
||||
String ly = y.getInstalledLibrary().get().getLocation();
|
||||
LibraryLocation lx = x.getInstalledLibrary().get().getLocation();
|
||||
LibraryLocation ly = y.getInstalledLibrary().get().getLocation();
|
||||
if (lx.equals(ly)) {
|
||||
return VersionComparator.max(x, y);
|
||||
}
|
||||
return lx.equals(LOCATION_SKETCHBOOK) ? x : y;
|
||||
return lx.equals(LibraryLocation.user) ? x : y;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,6 @@ package cc.arduino.contributions.libraries;
|
||||
|
||||
import static processing.app.I18n.format;
|
||||
import static processing.app.I18n.tr;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_CORE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -45,6 +42,7 @@ import java.util.Optional;
|
||||
import cc.arduino.cli.ArduinoCoreInstance;
|
||||
import cc.arduino.cli.commands.Lib.InstalledLibrary;
|
||||
import cc.arduino.cli.commands.Lib.Library;
|
||||
import cc.arduino.cli.commands.Lib.LibraryLocation;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import io.grpc.StatusException;
|
||||
import processing.app.BaseNoGui;
|
||||
@ -208,8 +206,8 @@ public class LibrariesIndexer {
|
||||
lib.getSrcFolder()));
|
||||
}
|
||||
|
||||
String loc = lib.getLocation();
|
||||
if (!loc.equals(LOCATION_CORE) && !loc.equals(LOCATION_REF_CORE)) {
|
||||
LibraryLocation loc = lib.getLocation();
|
||||
if (!loc.equals(LibraryLocation.platform_builtin) && !loc.equals(LibraryLocation.referenced_platform_builtin)) {
|
||||
// Check if we can find the same library in the index
|
||||
// and mark it as installed
|
||||
index.find(lib.getName(), lib.getVersion()).ifPresent(foundLib -> {
|
||||
@ -218,7 +216,7 @@ public class LibrariesIndexer {
|
||||
});
|
||||
}
|
||||
|
||||
if (lib.getTypes().isEmpty() && loc.equals(LOCATION_SKETCHBOOK)) {
|
||||
if (lib.getTypes().isEmpty() && loc.equals(LibraryLocation.user)) {
|
||||
lib.setTypes(lib.getDeclaredTypes());
|
||||
}
|
||||
|
||||
@ -235,8 +233,8 @@ public class LibrariesIndexer {
|
||||
// TODO: Should be done on the CLI?
|
||||
installedLibraries.stream() //
|
||||
.filter(l -> l.getTypes().contains("Contributed")) //
|
||||
.filter(l -> l.getLocation().equals(LOCATION_CORE)
|
||||
|| l.getLocation().equals(LOCATION_REF_CORE)) //
|
||||
.filter(l -> l.getLocation().equals(LibraryLocation.platform_builtin)
|
||||
|| l.getLocation().equals(LibraryLocation.referenced_platform_builtin)) //
|
||||
.forEach(l -> {
|
||||
File libFolder = l.getInstalledFolder();
|
||||
Optional<ContributedPlatform> platform = BaseNoGui.indexer
|
||||
|
@ -33,6 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import cc.arduino.cli.commands.Lib.LibraryLocation;
|
||||
import cc.arduino.contributions.libraries.ContributedLibraryDependency;
|
||||
|
||||
public class UserLibrary {
|
||||
@ -53,11 +54,7 @@ public class UserLibrary {
|
||||
private Collection<String> includes;
|
||||
protected File installedFolder;
|
||||
|
||||
public static final String LOCATION_IDE = "ide";
|
||||
public static final String LOCATION_SKETCHBOOK = "user";
|
||||
public static final String LOCATION_CORE = "platform";
|
||||
public static final String LOCATION_REF_CORE = "ref-platform";
|
||||
protected String location;
|
||||
protected LibraryLocation location;
|
||||
|
||||
public UserLibrary(File installedFolder, String name, String version,
|
||||
String author, String maintainer, String sentence,
|
||||
@ -65,7 +62,7 @@ public class UserLibrary {
|
||||
String license, Collection<String> architectures,
|
||||
String layout, Collection<String> declaredTypes,
|
||||
boolean onGoingDevelopment, Collection<String> includes,
|
||||
String location) {
|
||||
LibraryLocation location) {
|
||||
this.installedFolder = installedFolder;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
@ -91,16 +88,6 @@ public class UserLibrary {
|
||||
this.onGoingDevelopment = onGoingDevelopment;
|
||||
this.includes = includes;
|
||||
this.location = location;
|
||||
switch (location) {
|
||||
case LOCATION_IDE:
|
||||
case LOCATION_SKETCHBOOK:
|
||||
case LOCATION_CORE:
|
||||
case LOCATION_REF_CORE:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid library location: " + location);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -192,12 +179,12 @@ public class UserLibrary {
|
||||
return (layout == LibraryLayout.RECURSIVE);
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
public LibraryLocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public boolean isIDEBuiltIn() {
|
||||
return getLocation().equals(LOCATION_IDE);
|
||||
return getLocation().equals(LibraryLocation.ide_builtin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,19 +32,16 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static processing.app.packages.UserLibrary.LOCATION_CORE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_IDE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
|
||||
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
|
||||
import cc.arduino.cli.commands.Lib.LibraryLocation;
|
||||
|
||||
public class UserLibraryPriorityComparator implements Comparator<UserLibrary> {
|
||||
|
||||
private final static Map<String, Integer> priorities = new HashMap<>();
|
||||
private final static Map<LibraryLocation, Integer> priorities = new HashMap<>();
|
||||
static {
|
||||
priorities.put(LOCATION_SKETCHBOOK, 4);
|
||||
priorities.put(LOCATION_CORE, 3);
|
||||
priorities.put(LOCATION_REF_CORE, 2);
|
||||
priorities.put(LOCATION_IDE, 1);
|
||||
priorities.put(LibraryLocation.user, 4);
|
||||
priorities.put(LibraryLocation.platform_builtin, 3);
|
||||
priorities.put(LibraryLocation.referenced_platform_builtin, 2);
|
||||
priorities.put(LibraryLocation.ide_builtin, 1);
|
||||
}
|
||||
|
||||
private String arch;
|
||||
|
Loading…
x
Reference in New Issue
Block a user