Skip to content

Commit e896595

Browse files
committed
UserLibrary doesn't extend ContributedLibrary anymore
ContributedLibrary is used to decode library_index.json and it's intended to keep data coming only from the index. Now, when the library_index is synced with the filesystem, the metadata about installed libraries are kept in a separate list to not mess up with the main index.
1 parent 3ec6748 commit e896595

20 files changed

+83
-94
lines changed

app/src/cc/arduino/contributions/libraries/LibraryByTypeComparator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
import java.util.Comparator;
3333

34-
public class LibraryByTypeComparator implements Comparator<ContributedLibrary> {
34+
import processing.app.packages.UserLibrary;
35+
36+
public class LibraryByTypeComparator implements Comparator<UserLibrary> {
3537

3638
private final LibraryTypeComparator libraryTypeComparator;
3739

@@ -44,7 +46,7 @@ public LibraryByTypeComparator(LibraryTypeComparator libraryTypeComparator) {
4446
}
4547

4648
@Override
47-
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
49+
public int compare(UserLibrary o1, UserLibrary o2) {
4850
if (o1.getTypes() == null) {
4951
return 1;
5052
}

app/src/cc/arduino/contributions/libraries/LibraryOfSameTypeComparator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131

3232
import java.util.Comparator;
3333

34-
public class LibraryOfSameTypeComparator implements Comparator<ContributedLibrary> {
34+
import processing.app.packages.UserLibrary;
35+
36+
public class LibraryOfSameTypeComparator implements Comparator<UserLibrary> {
3537

3638
@Override
37-
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
39+
public int compare(UserLibrary o1, UserLibrary o2) {
3840
if (o1.getTypes() == null) {
3941
return 1;
4042
}

app/src/cc/arduino/contributions/libraries/filters/InstalledLibraryPredicate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
package cc.arduino.contributions.libraries.filters;
3131

32-
import cc.arduino.contributions.filters.InstalledPredicate;
3332
import cc.arduino.contributions.libraries.ContributedLibrary;
3433
import processing.app.BaseNoGui;
3534

@@ -40,14 +39,14 @@ public class InstalledLibraryPredicate implements Predicate<ContributedLibrary>
4039

4140
@Override
4241
public boolean test(ContributedLibrary input) {
43-
if (input.isInstalled()) {
42+
if (input.isLibraryInstalled()) {
4443
return true;
4544
}
4645

4746
List<ContributedLibrary> libraries = BaseNoGui.librariesIndexer.getIndex().find(input.getName());
4847

4948
return libraries.stream()
50-
.filter(new InstalledPredicate())
49+
.filter(l -> l.isLibraryInstalled())
5150
.count() > 0;
5251
}
5352

app/src/cc/arduino/contributions/libraries/filters/OnlyUpstreamReleasePredicate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929

3030
package cc.arduino.contributions.libraries.filters;
3131

32-
import cc.arduino.contributions.libraries.ContributedLibrary;
3332
import processing.app.packages.UserLibrary;
3433

3534
import java.util.function.Predicate;
3635

37-
public class OnlyUpstreamReleasePredicate implements Predicate<ContributedLibrary> {
36+
public class OnlyUpstreamReleasePredicate implements Predicate<Object> {
3837

3938
@Override
40-
public boolean test(ContributedLibrary input) {
39+
public boolean test(Object input) {
4140
return !(input instanceof UserLibrary);
4241
}
4342

app/src/cc/arduino/contributions/libraries/filters/UpdatableLibraryPredicate.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,21 @@
3535
import processing.app.packages.UserLibrary;
3636

3737
import java.util.List;
38+
import java.util.Optional;
3839
import java.util.function.Predicate;
3940

4041
public class UpdatableLibraryPredicate implements Predicate<ContributedLibrary> {
4142

4243
@Override
43-
public boolean test(ContributedLibrary contributedLibrary) {
44-
String libraryName = contributedLibrary.getName();
45-
UserLibrary installed = BaseNoGui.librariesIndexer.getInstalledLibraries().getByName(libraryName);
46-
if (installed == null) {
44+
public boolean test(ContributedLibrary lib) {
45+
Optional<UserLibrary> installed = lib.getInstalledLibrary();
46+
if (!installed.isPresent()) {
4747
return false;
4848
}
49+
String installedVersion = installed.get().getVersion();
50+
String libraryName = lib.getName();
4951
List<ContributedLibrary> libraries = BaseNoGui.librariesIndexer.getIndex().find(libraryName);
5052
return libraries.stream()
51-
.filter(library -> VersionComparator.greaterThan(library.getParsedVersion(), installed.getParsedVersion()))
52-
.count() > 0;
53+
.anyMatch(library -> VersionComparator.greaterThan(library.getParsedVersion(), installedVersion));
5354
}
5455
}

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryReleases.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
package cc.arduino.contributions.libraries.ui;
3131

3232
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
33-
import cc.arduino.contributions.filters.InstalledPredicate;
3433
import cc.arduino.contributions.libraries.ContributedLibrary;
3534
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
3635

@@ -78,13 +77,11 @@ public void add(ContributedLibrary library) {
7877
}
7978

8079
public Optional<ContributedLibrary> getInstalled() {
81-
List<ContributedLibrary> installedReleases = releases.stream().filter(new InstalledPredicate()).collect(Collectors.toList());
82-
Collections.sort(installedReleases, new DownloadableContributionBuiltInAtTheBottomComparator());
83-
80+
List<ContributedLibrary> installedReleases = releases.stream().filter(l -> l.isLibraryInstalled()).collect(Collectors.toList());
8481
if (installedReleases.isEmpty()) {
8582
return Optional.empty();
8683
}
87-
84+
Collections.sort(installedReleases, new DownloadableContributionBuiltInAtTheBottomComparator());
8885
return Optional.of(installedReleases.get(0));
8986
}
9087

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import cc.arduino.contributions.DownloadableContributionVersionComparator;
4646
import cc.arduino.contributions.VersionComparator;
4747
import cc.arduino.contributions.filters.BuiltInPredicate;
48-
import cc.arduino.contributions.filters.InstalledPredicate;
4948
import cc.arduino.contributions.libraries.ContributedLibrary;
5049
import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
5150
import cc.arduino.contributions.ui.InstallerTableCell;
@@ -92,10 +91,10 @@ public Component getTableCellEditorComponent(JTable table, Object value,
9291
.filter(new OnlyUpstreamReleasePredicate())
9392
.collect(Collectors.toList());
9493
List<ContributedLibrary> uninstalledReleases = releases.stream()
95-
.filter(new InstalledPredicate().negate()).collect(Collectors.toList());
94+
.filter(l -> !l.isLibraryInstalled()).collect(Collectors.toList());
9695

9796
List<ContributedLibrary> installedBuiltIn = releases.stream()
98-
.filter(new InstalledPredicate()).filter(new BuiltInPredicate())
97+
.filter(l -> !l.isLibraryInstalled()).filter(new BuiltInPredicate())
9998
.collect(Collectors.toList());
10099

101100
if (mayInstalled.isPresent() && !installedBuiltIn.contains(mayInstalled.get())) {

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Collection;
3939
import java.util.Collections;
4040
import java.util.LinkedList;
41+
import java.util.List;
4142
import java.util.Optional;
4243
import java.util.function.Predicate;
4344

@@ -134,7 +135,6 @@ public void updateUI() {
134135
categoryChooser.removeActionListener(categoryChooserActionListener);
135136
typeChooser.removeActionListener(typeChooserActionListener);
136137

137-
138138
// Load categories
139139
categoryFilter = x -> true;
140140
categoryChooser.removeAllItems();
@@ -158,7 +158,7 @@ public void updateUI() {
158158
typeChooser.addItem(new DropdownAllLibraries());
159159
typeChooser.addItem(new DropdownUpdatableLibrariesItem());
160160
typeChooser.addItem(new DropdownInstalledLibraryItem());
161-
java.util.List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
161+
List<String> types = new LinkedList<>(BaseNoGui.librariesIndexer.getIndex().getTypes());
162162
Collections.sort(types, new LibraryTypeComparator());
163163
for (String type : types) {
164164
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));

app/src/processing/app/Base.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,8 @@ protected void rebuildSketchbookMenu(JMenu menu) {
10591059
}
10601060
}
10611061

1062-
private List<ContributedLibrary> getSortedLibraries() {
1063-
List<ContributedLibrary> installedLibraries = new LinkedList<>(BaseNoGui.librariesIndexer.getInstalledLibraries());
1062+
private LibraryList getSortedLibraries() {
1063+
LibraryList installedLibraries = BaseNoGui.librariesIndexer.getInstalledLibraries();
10641064
Collections.sort(installedLibraries, new LibraryByTypeComparator());
10651065
Collections.sort(installedLibraries, new LibraryOfSameTypeComparator());
10661066
return installedLibraries;
@@ -1097,9 +1097,9 @@ public void actionPerformed(ActionEvent e) {
10971097
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
10981098

10991099
if (targetPlatform != null) {
1100-
List<ContributedLibrary> libs = getSortedLibraries();
1100+
LibraryList libs = getSortedLibraries();
11011101
String lastLibType = null;
1102-
for (ContributedLibrary lib : libs) {
1102+
for (UserLibrary lib : libs) {
11031103
String libType = lib.getTypes().get(0);
11041104
if (!libType.equals(lastLibType)) {
11051105
if (lastLibType != null) {

app/src/processing/app/syntax/PdeKeywords.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
package processing.app.syntax;
2626

27-
import cc.arduino.contributions.libraries.ContributedLibrary;
2827
import org.apache.commons.compress.utils.IOUtils;
2928
import org.fife.ui.rsyntaxtextarea.TokenMap;
3029
import org.fife.ui.rsyntaxtextarea.TokenTypes;
3130
import processing.app.Base;
3231
import processing.app.BaseNoGui;
32+
import processing.app.packages.UserLibrary;
3333
import processing.app.debug.TargetPlatform;
3434

3535
import java.io.BufferedReader;
@@ -89,7 +89,7 @@ public void reload() {
8989
File platformKeywords = new File(tp.getFolder(), "keywords.txt");
9090
if (platformKeywords.exists()) parseKeywordsTxt(platformKeywords);
9191
}
92-
for (ContributedLibrary lib : BaseNoGui.librariesIndexer.getInstalledLibraries()) {
92+
for (UserLibrary lib : BaseNoGui.librariesIndexer.getInstalledLibraries()) {
9393
File keywords = new File(lib.getInstalledFolder(), "keywords.txt");
9494
if (keywords.exists()) {
9595
parseKeywordsTxt(keywords);

0 commit comments

Comments
 (0)