Skip to content

Commit 9f58bae

Browse files
committed
Using enumerations for LibraryLocation
1 parent 81cef62 commit 9f58bae

File tree

11 files changed

+29
-51
lines changed

11 files changed

+29
-51
lines changed

app/.classpath

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
<classpathentry kind="lib" path="lib/commons-lang3-3.8.1.jar"/>
5757
<classpathentry kind="lib" path="lib/jssc-2.8.0-arduino4.jar"/>
5858
<classpathentry kind="lib" path="lib/grpc-core-1.20.0.jar"/>
59+
<classpathentry kind="lib" path="lib/grpc/protobuf-java-3.11.4.jar"/>
5960
<classpathentry kind="output" path="bin"/>
6061
</classpath>

app/lib/grpc/protobuf-java-3.11.4.jar

1.58 MB
Binary file not shown.

app/src/processing/app/Base.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import cc.arduino.Constants;
2727
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler;
2828
import cc.arduino.UploaderUtils;
29+
import cc.arduino.cli.commands.Lib.LibraryLocation;
2930
import cc.arduino.contributions.*;
3031
import cc.arduino.contributions.libraries.ContributedLibrary;
3132
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
@@ -76,10 +77,6 @@
7677

7778
import static processing.app.I18n.format;
7879
import static processing.app.I18n.tr;
79-
import static processing.app.packages.UserLibrary.LOCATION_CORE;
80-
import static processing.app.packages.UserLibrary.LOCATION_IDE;
81-
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
82-
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
8380

8481

8582
/**
@@ -1214,7 +1211,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12141211
LibraryList otherLibs = new LibraryList();
12151212
for (UserLibrary lib : allLibraries) {
12161213
// Get the library's location - used for sorting into categories
1217-
String location = lib.getLocation();
1214+
LibraryLocation location = lib.getLocation();
12181215
// Is this library compatible?
12191216
Collection<String> arch = lib.getArchitectures();
12201217
boolean compatible;
@@ -1224,7 +1221,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12241221
compatible = arch.contains(myArch);
12251222
}
12261223
// IDE Libaries (including retired)
1227-
if (location.equals(LOCATION_IDE)) {
1224+
if (location.equals(LibraryLocation.ide_builtin)) {
12281225
if (compatible) {
12291226
// only compatible IDE libs are shown
12301227
if (lib.getTypes().contains("Retired")) {
@@ -1234,15 +1231,15 @@ public void rebuildExamplesMenu(JMenu menu) {
12341231
}
12351232
}
12361233
// Platform Libraries
1237-
} else if (location.equals(LOCATION_CORE)) {
1234+
} else if (location.equals(LibraryLocation.platform_builtin)) {
12381235
// all platform libs are assumed to be compatible
12391236
platformLibs.add(lib);
12401237
// Referenced Platform Libraries
1241-
} else if (location.equals(LOCATION_REF_CORE)) {
1238+
} else if (location.equals(LibraryLocation.referenced_platform_builtin)) {
12421239
// all referenced platform libs are assumed to be compatible
12431240
referencedPlatformLibs.add(lib);
12441241
// Sketchbook Libraries (including incompatible)
1245-
} else if (location.equals(LOCATION_SKETCHBOOK)) {
1242+
} else if (location.equals(LibraryLocation.user)) {
12461243
if (compatible) {
12471244
// libraries promoted from sketchbook (behave as builtin)
12481245
if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")

arduino-core/.classpath

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
<classpathentry kind="lib" path="lib/grpc/opencensus-api-0.19.2.jar"/>
6565
<classpathentry kind="lib" path="lib/grpc/opencensus-contrib-grpc-metrics-0.19.2.jar"/>
6666
<classpathentry kind="lib" path="lib/grpc/proto-google-common-protos-1.12.0.jar"/>
67-
<classpathentry kind="lib" path="lib/grpc/protobuf-javanano-3.0.0-alpha-5.jar"/>
68-
<classpathentry kind="lib" path="lib/grpc/protobuf-java-3.9.2.jar"/>
67+
<classpathentry kind="lib" path="lib/grpc/protobuf-java-3.11.4.jar"/>
6968
<classpathentry kind="output" path="bin"/>
7069
</classpath>
1.58 MB
Binary file not shown.
-1.56 MB
Binary file not shown.
Binary file not shown.

arduino-core/src/cc/arduino/contributions/libraries/ContributedLibrary.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
import java.util.Map;
3535
import java.util.Optional;
3636

37+
import cc.arduino.cli.commands.Lib.LibraryLocation;
3738
import cc.arduino.contributions.VersionComparator;
3839

39-
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
40-
4140
public class ContributedLibrary {
4241

4342
private String name;
@@ -78,12 +77,12 @@ public Optional<ContributedLibraryRelease> getInstalled() {
7877
return releases.values().stream() //
7978
.filter(ContributedLibraryRelease::isLibraryInstalled) //
8079
.reduce((x, y) -> {
81-
String lx = x.getInstalledLibrary().get().getLocation();
82-
String ly = y.getInstalledLibrary().get().getLocation();
80+
LibraryLocation lx = x.getInstalledLibrary().get().getLocation();
81+
LibraryLocation ly = y.getInstalledLibrary().get().getLocation();
8382
if (lx.equals(ly)) {
8483
return VersionComparator.max(x, y);
8584
}
86-
return lx.equals(LOCATION_SKETCHBOOK) ? x : y;
85+
return lx.equals(LibraryLocation.user) ? x : y;
8786
});
8887
}
8988

arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131

3232
import static processing.app.I18n.format;
3333
import static processing.app.I18n.tr;
34-
import static processing.app.packages.UserLibrary.LOCATION_CORE;
35-
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
36-
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
3734

3835
import java.io.File;
3936
import java.io.IOException;
@@ -45,6 +42,7 @@
4542
import cc.arduino.cli.ArduinoCoreInstance;
4643
import cc.arduino.cli.commands.Lib.InstalledLibrary;
4744
import cc.arduino.cli.commands.Lib.Library;
45+
import cc.arduino.cli.commands.Lib.LibraryLocation;
4846
import cc.arduino.contributions.packages.ContributedPlatform;
4947
import io.grpc.StatusException;
5048
import processing.app.BaseNoGui;
@@ -208,8 +206,8 @@ public void rescanLibraries() {
208206
lib.getSrcFolder()));
209207
}
210208

211-
String loc = lib.getLocation();
212-
if (!loc.equals(LOCATION_CORE) && !loc.equals(LOCATION_REF_CORE)) {
209+
LibraryLocation loc = lib.getLocation();
210+
if (!loc.equals(LibraryLocation.platform_builtin) && !loc.equals(LibraryLocation.referenced_platform_builtin)) {
213211
// Check if we can find the same library in the index
214212
// and mark it as installed
215213
index.find(lib.getName(), lib.getVersion()).ifPresent(foundLib -> {
@@ -218,7 +216,7 @@ public void rescanLibraries() {
218216
});
219217
}
220218

221-
if (lib.getTypes().isEmpty() && loc.equals(LOCATION_SKETCHBOOK)) {
219+
if (lib.getTypes().isEmpty() && loc.equals(LibraryLocation.user)) {
222220
lib.setTypes(lib.getDeclaredTypes());
223221
}
224222

@@ -235,8 +233,8 @@ public void rescanLibraries() {
235233
// TODO: Should be done on the CLI?
236234
installedLibraries.stream() //
237235
.filter(l -> l.getTypes().contains("Contributed")) //
238-
.filter(l -> l.getLocation().equals(LOCATION_CORE)
239-
|| l.getLocation().equals(LOCATION_REF_CORE)) //
236+
.filter(l -> l.getLocation().equals(LibraryLocation.platform_builtin)
237+
|| l.getLocation().equals(LibraryLocation.referenced_platform_builtin)) //
240238
.forEach(l -> {
241239
File libFolder = l.getInstalledFolder();
242240
Optional<ContributedPlatform> platform = BaseNoGui.indexer

arduino-core/src/processing/app/packages/UserLibrary.java

+5-18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Collection;
3434
import java.util.List;
3535

36+
import cc.arduino.cli.commands.Lib.LibraryLocation;
3637
import cc.arduino.contributions.libraries.ContributedLibraryDependency;
3738

3839
public class UserLibrary {
@@ -53,19 +54,15 @@ public class UserLibrary {
5354
private Collection<String> includes;
5455
protected File installedFolder;
5556

56-
public static final String LOCATION_IDE = "ide";
57-
public static final String LOCATION_SKETCHBOOK = "user";
58-
public static final String LOCATION_CORE = "platform";
59-
public static final String LOCATION_REF_CORE = "ref-platform";
60-
protected String location;
57+
protected LibraryLocation location;
6158

6259
public UserLibrary(File installedFolder, String name, String version,
6360
String author, String maintainer, String sentence,
6461
String paraghraph, String website, String category,
6562
String license, Collection<String> architectures,
6663
String layout, Collection<String> declaredTypes,
6764
boolean onGoingDevelopment, Collection<String> includes,
68-
String location) {
65+
LibraryLocation location) {
6966
this.installedFolder = installedFolder;
7067
this.name = name;
7168
this.version = version;
@@ -91,16 +88,6 @@ public UserLibrary(File installedFolder, String name, String version,
9188
this.onGoingDevelopment = onGoingDevelopment;
9289
this.includes = includes;
9390
this.location = location;
94-
switch (location) {
95-
case LOCATION_IDE:
96-
case LOCATION_SKETCHBOOK:
97-
case LOCATION_CORE:
98-
case LOCATION_REF_CORE:
99-
break;
100-
default:
101-
throw new IllegalArgumentException(
102-
"Invalid library location: " + location);
103-
}
10491
}
10592

10693
public String getName() {
@@ -192,12 +179,12 @@ public boolean useRecursion() {
192179
return (layout == LibraryLayout.RECURSIVE);
193180
}
194181

195-
public String getLocation() {
182+
public LibraryLocation getLocation() {
196183
return location;
197184
}
198185

199186
public boolean isIDEBuiltIn() {
200-
return getLocation().equals(LOCATION_IDE);
187+
return getLocation().equals(LibraryLocation.ide_builtin);
201188
}
202189

203190
@Override

arduino-core/src/processing/app/packages/UserLibraryPriorityComparator.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@
3232
import java.util.HashMap;
3333
import java.util.Map;
3434

35-
import static processing.app.packages.UserLibrary.LOCATION_CORE;
36-
import static processing.app.packages.UserLibrary.LOCATION_IDE;
37-
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
38-
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
35+
import cc.arduino.cli.commands.Lib.LibraryLocation;
3936

4037
public class UserLibraryPriorityComparator implements Comparator<UserLibrary> {
4138

42-
private final static Map<String, Integer> priorities = new HashMap<>();
39+
private final static Map<LibraryLocation, Integer> priorities = new HashMap<>();
4340
static {
44-
priorities.put(LOCATION_SKETCHBOOK, 4);
45-
priorities.put(LOCATION_CORE, 3);
46-
priorities.put(LOCATION_REF_CORE, 2);
47-
priorities.put(LOCATION_IDE, 1);
41+
priorities.put(LibraryLocation.user, 4);
42+
priorities.put(LibraryLocation.platform_builtin, 3);
43+
priorities.put(LibraryLocation.referenced_platform_builtin, 2);
44+
priorities.put(LibraryLocation.ide_builtin, 1);
4845
}
4946

5047
private String arch;

0 commit comments

Comments
 (0)