8000 Removed the now useless UserLibraryFolder · arduino-collections/Arduino-1@0056cbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0056cbc

Browse files
committed
Removed the now useless UserLibraryFolder
1 parent 3c46af8 commit 0056cbc

File tree

8 files changed

+49
-93
lines changed

8 files changed

+49
-93
lines changed

app/src/processing/app/Base.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import processing.app.macosx.ThinkDifferent;
5858
import processing.app.packages.LibraryList;
5959
import processing.app.packages.UserLibrary;
60-
import processing.app.packages.UserLibraryFolder.Location;
6160
import processing.app.syntax.PdeKeywords;
6261
import processing.app.syntax.SketchTextAreaDefaultInputMap;
6362
import processing.app.tools.MenuScroller;
@@ -78,6 +77,10 @@
7877

7978
import static processing.app.I18n.format;
8079
import static processing.app.I18n.tr;
80+
import static processing.app.packages.UserLibrary.LOCATION_CORE;
81+
import static processing.app.packages.UserLibrary.LOCATION_IDE;
82+
import static processing.app.packages.UserLibrary.LOCATION_REF_CORE;
83+
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
8184

8285

8386
/**
@@ -1218,7 +1221,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12181221
LibraryList otherLibs = new LibraryList();
12191222
for (UserLibrary lib : allLibraries) {
12201223
// Get the library's location - used for sorting into categories
1221-
Location location = lib.getLocation();
1224+
String location = lib.getLocation();
12221225
// Is this library compatible?
12231226
Collection<String> arch = lib.getArchitectures();
12241227
boolean compatible;
@@ -1228,7 +1231,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12281231
compatible = arch.contains(myArch);
12291232
}
12301233
// IDE Libaries (including retired)
1231-
if (location == Location.IDE_BUILTIN) {
1234+
if (location.equals(LOCATION_IDE)) {
12321235
if (compatible) {
12331236
// only compatible IDE libs are shown
12341237
if (lib.getTypes().contains("Retired")) {
@@ -1238,15 +1241,15 @@ public void rebuildExamplesMenu(JMenu menu) {
12381241
}
12391242
}
12401243
// Platform Libraries
1241-
} else if (location == Location.CORE) {
1244+
} else if (location.equals(LOCATION_CORE)) {
12421245
// all platform libs are assumed to be compatible
12431246
platformLibs.add(lib);
12441247
// Referenced Platform Libraries
1245-
} else if (location == Location.REFERENCED_CORE) {
1248+
} else if (location.equals(LOCATION_REF_CORE)) {
12461249
// all referenced platform libs are assumed to be compatible
12471250
referencedPlatformLibs.add(lib);
12481251
// Sketchbook Libraries (including incompatible)
1249-
} else if (location == Location.SKETCHBOOK) {
1252+
} else if (location.equals(LOCATION_SKETCHBOOK)) {
12501253
if (compatible) {
12511254
// libraries promoted from sketchbook (behave as builtin)
12521255
if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")
@@ -2462,7 +2465,7 @@ public void handleAddLibrary() {
24622465
}
24632466

24642467
// copy folder
2465-
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder, sourceFile.getName());
2468+
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
24662469
if (!destinationFolder.mkdir()) {
24672470
activeEditor.statusError(format(tr("A library named {0} already exists"), sourceFile.getName()));
24682471
return;

arduino-core/src/cc/arduino/Compiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
249249
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
250250

251251
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
252-
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder().folder);
252+
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder());
253253

254254
String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":"));
255255
cmd.add("-fqbn=" + fqbn);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import java.util.Optional;
3636

3737
import cc.arduino.contributions.VersionComparator;
38-
import processing.app.packages.UserLibraryFolder.Location;
38+
39+
import static processing.app.packages.UserLibrary.LOCATION_SKETCHBOOK;
3940

4041
public class ContributedLibrary {
4142

@@ -77,12 +78,12 @@ public Optional<ContributedLibraryRelease> getInstalled() {
7778
return releases.values().stream() //
7879
.filter(ContributedLibraryRelease::isLibraryInstalled) //
7980
.reduce((x, y) -> {
80-
Location lx = x.getInstalledLibrary().get().getLocation();
81-
Location ly = y.getInstalledLibrary().get().getLocation();
82-
if (lx == ly) {
81+
String lx = x.getInstalledLibrary().get().getLocation();
82+
String ly = y.getInstalledLibrary().get().getLocation();
83+
if (lx.equals(ly)) {
8384
return VersionComparator.max(x, y);
8485
}
85-
return lx == Location.SKETCHBOOK ? x : y;
86+
return lx.equals(LOCATION_SKETCHBOOK) ? x : y;
8687
});
8788
}
8889

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
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;
3437

3538
import java.io.File;
3639
import java.io.IOException;
@@ -49,7 +52,6 @@
4952
import processing.app.helpers.FileUtils;
5053
import processing.app.packages.LibraryList;
5154
import processing.app.packages.UserLibrary;
52-
import processing.app.packages.UserLibraryFolder.Location;
5355
import processing.app.packages.UserLibraryPriorityComparator;
5456

5557
public class LibrariesIndexer {
@@ -206,8 +208,8 @@ public void rescanLibraries() {
206208
lib.getSrcFolder()));
207209
}
208210

209-
Location loc = lib.getLocation();
210-
if (loc != Location.CORE && loc != Location.REFERENCED_CORE) {
211+
String loc = lib.getLocation();
212+
if (!loc.equals(LOCATION_CORE) && !loc.equals(LOCATION_REF_CORE)) {
211213
// Check if we can find the same library in the index
212214
// and mark it as installed
213215
index.find(lib.getName(), lib.getVersion()).ifPresent(foundLib -> {
@@ -216,7 +218,7 @@ public void rescanLibraries() {
216218
});
217219
}
218220

219-
if (lib.getTypes().isEmpty() && loc == Location.SKETCHBOOK) {
221+
if (lib.getTypes().isEmpty() && loc.equals(LOCATION_SKETCHBOOK)) {
220222
lib.setTypes(lib.getDeclaredTypes());
221223
}
222224

@@ -233,8 +235,8 @@ public void rescanLibraries() {
233235
// TODO: Should be done on the CLI?
234236
installedLibraries.stream() //
235237
.filter(l -> l.getTypes().contains("Contributed")) //
236-
.filter(l -> l.getLocation() == Location.CORE
237-
|| l.getLocation() == Location.REFERENCED_CORE) //
238+
.filter(l -> l.getLocation().equals(LOCATION_CORE)
239+
|| l.getLocation().equals(LOCATION_REF_CORE)) //
238240
.forEach(l -> {
239241
File libFolder = l.getInstalledFolder();
240242
Optional<ContributedPlatform> platform = BaseNoGui.indexer

arduino-core/src/processing/app/BaseNoGui.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import processing.app.legacy.PApplet;
2222
import processing.app.packages.LibraryList;
2323
import processing.app.packages.UserLibrary;
24-
import processing.app.packages.UserLibraryFolder;
25-
import processing.app.packages.UserLibraryFolder.Location;
2624
import cc.arduino.files.DeleteFilesOnShutdown;
2725
import processing.app.helpers.FileUtils;
2826

@@ -343,7 +341,7 @@ static public File getSketchbookHardwareFolder() {
343341
return new File(getSketchbookFolder(), "hardware");
344342
}
345343

346-
static public UserLibraryFolder getSketchbookLibrariesFolder() {
344+
static public File getSketchbookLibrariesFolder() {
347345
File libdir = new File(getSketchbookFolder(), "libraries");
348346
if (!libdir.exists()) {
349347
FileWriter freadme = null;
@@ -357,7 +355,7 @@ static public UserLibraryFolder getSketchbookLibrariesFolder() {
357355
IOUtils.closeQuietly(freadme);
358356
}
359357
}
360-
return new UserLibraryFolder(libdir, Location.SKETCHBOOK);
358+
return libdir;
361359
}
362360

363361
static public String getSketchbookPath() {

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import cc.arduino.contributions.VersionHelper;
4848
import cc.arduino.contributions.libraries.ContributedLibraryDependency;
4949
import processing.app.helpers.PreferencesMap;
50-
import processing.app.packages.UserLibraryFolder.Location;
5150

5251
public class UserLibrary {
5352

@@ -66,12 +65,14 @@ public class UserLibrary {
6665
private boolean onGoingDevelopment;
6766
private Collection<String> includes;
6867
protected File installedFolder;
69-
protected Location location;
7068

71-
public static UserLibrary create(UserLibraryFolder libFolderDesc) throws IOException {
72-
File libFolder = libFolderDesc.folder;
73-
String location = libFolderDesc.location.toString();
69+
public static final String LOCATION_IDE = "ide";
70+
public static final String LOCATION_SKETCHBOOK = "sketchbook";
71+
public static final String LOCATION_CORE = "platform";
72+
public static final String LOCATION_REF_CORE = "ref-platform";
73+
protected String location;
7474

75+
public static UserLibrary create(File libFolder, String location) throws IOException {
7576
// Parse metadata
7677
File propertiesFile = new File(libFolder, "library.properties");
7778
PreferencesMap properties = new PreferencesMap();
@@ -211,15 +212,12 @@ public UserLibrary(File installedFolder, String name, String version,
211212
this.declaredTypes = declaredTypes;
212213
this.onGoingDevelopment = onGoingDevelopment;
213214
this.includes = includes;
215+
this.location = location;
214216
switch (location) {
215-
case "ide":
216-
this.location = Location.IDE_BUILTIN;
217-
break;
218-
case "sketchbook":
219-
this.location = Location.SKETCHBOOK;
220-
break;
221-
case "platform":
222-
this.location = Location.CORE;
217+
case LOCATION_IDE:
218+
case LOCATION_SKETCHBOOK:
219+
case LOCATION_CORE:
220+
case LOCATION_REF_CORE:
223221
break;
224222
default:
225223
throw new IllegalArgumentException(
@@ -316,12 +314,12 @@ public boolean useRecursion() {
316314
return (layout == LibraryLayout.RECURSIVE);
317315
}
318316

319-
public Location getLocation() {
317+
public String getLocation() {
320318
return location;
321319
}
322320

323321
public boolean isIDEBuiltIn() {
324-
return getLocation() == Location.IDE_BUILTIN;
322+
return getLocation().equals(LOCATION_IDE);
325323
}
326324

327325
@Override

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

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

35-
import processing.app.packages.UserLibraryFolder.Location;
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;
3639

3740
public class UserLibraryPriorityComparator implements Comparator<UserLibrary> {
3841

39-
private final static Map<Location, Integer> priorities = new HashMap<>();
42+
private final static Map<String, Integer> priorities = new HashMap<>();
4043
static {
41-
priorities.put(Location.SKETCHBOOK, 4);
42-
priorities.put(Location.CORE, 3);
43-
priorities.put(Location.REFERENCED_CORE, 2);
44-
priorities.put(Location.IDE_BUILTIN, 1);
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);
4548
}
4649

4750
private String arch;

0 commit comments

Comments
 (0)
0