Skip to content

Commit 3316bab

Browse files
committed
Removed the now useless UserLibraryFolder
1 parent 21e7329 commit 3316bab

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
/**
@@ -1212,7 +1215,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12121215
LibraryList otherLibs = new LibraryList();
12131216
for (UserLibrary lib : allLibraries) {
12141217
// Get the library's location - used for sorting into categories
1215-
Location location = lib.getLocation();
1218+
String location = lib.getLocation();
12161219
// Is this library compatible?
12171220
Collection<String> arch = lib.getArchitectures();
12181221
boolean compatible;
@@ -1222,7 +1225,7 @@ public void rebuildExamplesMenu(JMenu menu) {
12221225
compatible = arch.contains(myArch);
12231226
}
12241227
// IDE Libaries (including retired)
1225-
if (location == Location.IDE_BUILTIN) {
1228+
if (location.equals(LOCATION_IDE)) {
12261229
if (compatible) {
12271230
// only compatible IDE libs are shown
12281231
if (lib.getTypes().contains("Retired")) {
@@ -1232,15 +1235,15 @@ public void rebuildExamplesMenu(JMenu menu) {
12321235
}
12331236
}
12341237
// Platform Libraries
1235-
} else if (location == Location.CORE) {
1238+
} else if (location.equals(LOCATION_CORE)) {
12361239
// all platform libs are assumed to be compatible
12371240
platformLibs.add(lib);
12381241
// Referenced Platform Libraries
1239-
} else if (location == Location.REFERENCED_CORE) {
1242+
} else if (location.equals(LOCATION_REF_CORE)) {
12401243
// all referenced platform libs are assumed to be compatible
12411244
referencedPlatformLibs.add(lib);
12421245
// Sketchbook Libraries (including incompatible)
1243-
} else if (location == Location.SKETCHBOOK) {
1246+
} else if (location.equals(LOCATION_SKETCHBOOK)) {
12441247
if (compatible) {
12451248
// libraries promoted from sketchbook (behave as builtin)
12461249
if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino")
@@ -2415,7 +2418,7 @@ public void handleAddLibrary() {
24152418
}
24162419

24172420
// copy folder
2418-
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder().folder, sourceFile.getName());
2421+
File destinationFolder = new File(BaseNoGui.getSketchbookLibrariesFolder(), sourceFile.getName());
24192422
if (!destinationFolder.mkdir()) {
24202423
activeEditor.statusError(format(tr("A library named {0} already exists"), sourceFile.getName()));
24212424
return;

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

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

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

252252
String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":"));
253253
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

@@ -337,7 +335,7 @@ static public File getSketchbookHardwareFolder() {
337335
return new File(getSketchbookFolder(), "hardware");
338336
}
339337

340-
static public UserLibraryFolder getSketchbookLibrariesFolder() {
338+
static public File getSketchbookLibrariesFolder() {
341339
File libdir = new File(getSketchbookFolder(), "libraries");
342340
if (!libdir.exists()) {
343341
FileWriter freadme = null;
@@ -351,7 +349,7 @@ static public UserLibraryFolder getSketchbookLibrariesFolder() {
351349
IOUtils.closeQuietly(freadme);
352350
}
353351
}
354-
return new UserLibraryFolder(libdir, Location.SKETCHBOOK);
352+
return libdir;
355353
}
356354

357355
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)