Skip to content

Commit caa2b16

Browse files
committed
Merge remote-tracking branch 'mega/libs-cli-inception' into ide-1.9.x-beta
2 parents 39ee234 + 59c9fb9 commit caa2b16

23 files changed

+230
-390
lines changed

app/src/cc/arduino/contributions/ContributionsSelfCheck.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
package cc.arduino.contributions;
3131

3232
import cc.arduino.contributions.libraries.LibraryInstaller;
33-
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
3433
import cc.arduino.contributions.packages.ContributionInstaller;
3534
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
3635
import cc.arduino.view.NotificationPopup;
@@ -130,7 +129,7 @@ static boolean checkForUpdatablePlatforms() {
130129

131130
static boolean checkForUpdatableLibraries() {
132131
return BaseNoGui.librariesIndexer.getIndex().getLibraries().stream()
133-
.anyMatch(new UpdatableLibraryPredicate());
132+
.anyMatch(r -> r.getInstalled().isPresent() && !r.getLatest().isLibraryInstalled());
134133
}
135134

136135
@Override

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

-62
This file was deleted.

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@
3636
import java.util.Collections;
3737
import java.util.LinkedList;
3838
import java.util.List;
39+
import java.util.Map;
3940
import java.util.Optional;
4041

4142
import javax.swing.JComboBox;
4243
import javax.swing.JTable;
4344

44-
import cc.arduino.contributions.DownloadableContributionVersionComparator;
4545
import cc.arduino.contributions.VersionComparator;
4646
import cc.arduino.contributions.libraries.ContributedLibrary;
4747
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
4848
import cc.arduino.contributions.ui.InstallerTableCell;
49-
import cc.arduino.utils.ReverseComparator;
5049

5150
@SuppressWarnings("serial")
5251
public class ContributedLibraryTableCellEditor extends InstallerTableCell {
@@ -67,12 +66,11 @@ public Component getTableCellEditorComponent(JTable table, Object value,
6766

6867
editorCell = new ContributedLibraryTableCellJPanel(table, value, true);
6968
editorCell.installButton
70-
.addActionListener(e -> onInstall(editorValue.getSelected(),
71-
editorValue.getInstalled()));
69+
.addActionListener(e -> onInstall(editorValue.getSelected()));
7270
editorCell.downgradeButton.addActionListener(e -> {
7371
JComboBox chooser = editorCell.downgradeChooser;
7472
ContributedLibrary lib = (ContributedLibrary) chooser.getSelectedItem();
75-
onInstall(lib, editorValue.getInstalled());
73+
onInstall(lib);
7674
});
7775
editorCell.versionToInstallChooser.addActionListener(e -> {
7876
editorValue.select((ContributedLibrary) editorCell.versionToInstallChooser.getSelectedItem());
@@ -83,24 +81,24 @@ public Component getTableCellEditorComponent(JTable table, Object value,
8381

8482
setEnabled(true);
8583

86-
final Optional<ContributedLibrary> mayInstalled = editorValue.getInstalled();
84+
Map<String, ContributedLibrary> releases = editorValue.getReleases();
85+
List<ContributedLibrary> notInstalled = new LinkedList<>(releases.values());
8786

88-
List<ContributedLibrary> releases = editorValue.getReleases();
89-
List<ContributedLibrary> notInstalled = new LinkedList<>(releases);
87+
final Optional<ContributedLibrary> mayInstalled = editorValue.getInstalled();
9088
if (mayInstalled.isPresent()) {
91-
notInstalled.remove(editorValue.getInstalled().get());
89+
notInstalled.remove(mayInstalled.get());
9290
}
9391

94-
Collections.sort(notInstalled, new ReverseComparator<>(
95-
new DownloadableContributionVersionComparator()));
92+
Collections.sort(notInstalled, VersionComparator::compareTo);
93+
Collections.reverse(notInstalled);
9694

9795
editorCell.downgradeChooser.removeAllItems();
9896
editorCell.downgradeChooser.addItem(tr("Select version"));
9997

10098
final List<ContributedLibrary> notInstalledPrevious = new LinkedList<>();
10199
final List<ContributedLibrary> notInstalledNewer = new LinkedList<>();
102100

103-
notInstalled.stream().forEach(input -> {
101+
notInstalled.forEach(input -> {
104102
if (!mayInstalled.isPresent()
105103
|| VersionComparator.greaterThan(mayInstalled.get(), input)) {
106104
notInstalledPrevious.add(input);
@@ -142,8 +140,7 @@ protected void onRemove(ContributedLibrary selected) {
142140
// Empty
143141
}
144142

145-
protected void onInstall(ContributedLibrary selected,
146-
Optional<ContributedLibrary> mayInstalled) {
143+
protected void onInstall(ContributedLibrary selected) {
147144
// Empty
148145
}
149146

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import javax.swing.text.html.HTMLDocument;
2424
import javax.swing.text.html.StyleSheet;
2525

26-
import cc.arduino.contributions.DownloadableContributionVersionComparator;
26+
import cc.arduino.contributions.VersionComparator;
2727
import cc.arduino.contributions.libraries.ContributedLibrary;
2828
import cc.arduino.contributions.libraries.ContributedLibraryReleases;
2929
import cc.arduino.contributions.ui.InstallerTableCell;
@@ -126,8 +126,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
126126
upgradable = false;
127127
} else {
128128
installable = false;
129-
upgradable = new DownloadableContributionVersionComparator()
130-
.compare(selected, mayInstalled.get()) > 0;
129+
upgradable = VersionComparator.greaterThan(selected, mayInstalled.get());
131130
}
132131
if (installable) {
133132
installButton.setText(tr("Install"));
@@ -165,7 +164,7 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
165164

166165
// ...version.
167166
if (mayInstalled.isPresent()) {
168-
String installedVer = mayInstalled.get().getParsedVersion();
167+
String installedVer = mayInstalled.get().getVersion();
169168
if (installedVer == null) {
170169
desc += " " + tr("Version unknown");
171170
} else {

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

+1-44
Original file line numberDiff line numberDiff line change
@@ -158,51 +158,8 @@ private boolean filterCondition(ContributedLibraryReleases lib) {
158158
return true;
159159
}
160160

161-
public void updateLibrary(ContributedLibrary lib) {
162-
// Find the row interested in the change
163-
int row = -1;
164-
for (ContributedLibraryReleases releases : contributions) {
165-
if (releases.shouldContain(lib))
166-
row = contributions.indexOf(releases);
167-
}
168-
169-
updateContributions();
170-
171-
// If the library is found in the list send update event
172-
// or insert event on the specific row...
173-
for (ContributedLibraryReleases releases : contributions) {
174-
if (releases.shouldContain(lib)) {
175-
if (row == -1) {
176-
row = contributions.indexOf(releases);
177-
fireTableRowsInserted(row, row);
178-
} else {
179-
fireTableRowsUpdated(row, row);
180-
}
181-
return;
182-
}
183-
}
184-
// ...otherwise send a row deleted event
185-
fireTableRowsDeleted(row, row);
186-
}
187-
188-
private List<ContributedLibraryReleases> rebuildContributionsFromIndex() {
189-
List<ContributedLibraryReleases> res = new ArrayList<>();
190-
BaseNoGui.librariesIndexer.getIndex().getLibraries(). //
191-
forEach(lib -> {
192-
for (ContributedLibraryReleases contribution : res) {
193-
if (!contribution.shouldContain(lib))
194-
continue;
195-
contribution.add(lib);
196-
return;
197-
}
198-
199-
res.add(new ContributedLibraryReleases(lib));
200-
});
201-
return res;
202-
}
203-
204161
private void updateContributions() {
205-
List<ContributedLibraryReleases> all = rebuildContributionsFromIndex();
162+
List<ContributedLibraryReleases> all = BaseNoGui.librariesIndexer.getIndex().getLibraries();
206163
contributions.clear();
207164
all.stream().filter(this::filterCondition).forEach(contributions::add);
208165
Collections.sort(contributions,

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.Collections;
4040
import java.util.LinkedList;
4141
import java.util.List;
42-
import java.util.Optional;
4342
import java.util.function.Predicate;
4443

4544
import javax.swing.Box;
@@ -81,12 +80,8 @@ protected TableCellRenderer createCellRenderer() {
8180
protected InstallerTableCell createCellEditor() {
8281
return new ContributedLibraryTableCellEditor() {
8382
@Override
84-
protected void onInstall(ContributedLibrary selectedLibrary, Optional<ContributedLibrary> mayInstalledLibrary) {
85-
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
86-
onRemovePressed(mayInstalledLibrary.get());
87-
} else {
88-
onInstallPressed(selectedLibrary, mayInstalledLibrary);
89-
}
83+
protected void onInstall(ContributedLibrary selectedLibrary) {
84+
onInstallPressed(selectedLibrary);
9085
}
9186

9287
@Override
@@ -213,12 +208,12 @@ protected void onUpdatePressed() {
213208
installerThread.start();
214209
}
215210

216-
public void onInstallPressed(final ContributedLibrary lib, final Optional<ContributedLibrary> mayReplaced) {
211+
public void onInstallPressed(final ContributedLibrary lib) {
217212
clearErrorMessage();
218213
installerThread = new Thread(() -> {
219214
try {
220215
setProgressVisible(true, tr("Installing..."));
221-
installer.install(lib, mayReplaced, this::setProgress);
216+
installer.install(lib, this::setProgress);
222217
// TODO: Do a better job in refreshing only the needed element
223218
if (contribTable.getCellEditor() != null) {
224219
contribTable.getCellEditor().stopCellEditing();

app/src/processing/app/Base.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public Base(String[] args) throws Exception {
289289
pdeKeywords.reload();
290290

291291
contributionInstaller = new ContributionInstaller(BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
292-
libraryInstaller = new LibraryInstaller(BaseNoGui.getPlatform());
292+
libraryInstaller = new LibraryInstaller();
293293

294294
parser.parseArgumentsPhase2();
295295

@@ -368,26 +368,17 @@ public Base(String[] args) throws Exception {
368368
}
369369
selected = indexer.getIndex().find(libraryToInstallParts[0], version.get().toString());
370370
} else if (libraryToInstallParts.length == 1) {
371-
List<ContributedLibrary> librariesByName = indexer.getIndex().find(libraryToInstallParts[0]);
372-
Collections.sort(librariesByName, new DownloadableContributionVersionComparator());
373-
if (!librariesByName.isEmpty()) {
374-
selected = librariesByName.get(librariesByName.size() - 1);
371+
ContributedLibraryReleases releases = indexer.getIndex().find(libraryToInstallParts[0]);
372+
if (releases != null) {
373+
selected = releases.getLatest();
375374
}
376375
}
377376
if (selected == null) {
378377
System.out.println(tr("Selected library is not available"));
379378
System.exit(1);
380379
}
381380

382-
Optional<ContributedLibrary> mayInstalled = indexer.getIndex().getInstalled(libraryToInstallParts[0]);
383-
if (mayInstalled.isPresent() && selected.isIDEBuiltIn()) {
384-
System.out.println(tr(I18n
385-
.format("Library {0} is available as built-in in the IDE.\nRemoving the other version {1} installed in the sketchbook...",
386-
library, mayInstalled.get().getParsedVersion())));
387-
libraryInstaller.remove(mayInstalled.get(), progressListener);
388-
} else {
389-
libraryInstaller.install(selected, mayInstalled, progressListener);
390-
}
381+
libraryInstaller.install(selected, progressListener);
391382
}
392383

393384
System.exit(0);

app/test/cc/arduino/contributions/UpdatableLibraryTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void testUpdatableLibrary() throws Exception {
4141

4242
ContributedLibrary sdLib = indexer.getIndex().getInstalled("SD").get();
4343
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
44-
assertEquals("SD installed version", "1.1.1", sdLib.getParsedVersion());
44+
assertEquals("SD installed version", "1.1.1", sdLib.getVersion());
4545

4646
assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());
4747

@@ -50,7 +50,7 @@ public void testUpdatableLibrary() throws Exception {
5050

5151
sdLib = indexer.getIndex().getInstalled("SD").get();
5252
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
53-
assertEquals("SD installed version", "1.2.1", sdLib.getParsedVersion());
53+
assertEquals("SD installed version", "1.2.1", sdLib.getVersion());
5454

5555
assertFalse(ContributionsSelfCheck.checkForUpdatableLibraries());
5656
}
@@ -68,7 +68,7 @@ public void testUpdatableLibraryWithBundled() throws Exception {
6868

6969
ContributedLibrary l = indexer.getIndex().getInstalled("Bridge").get();
7070
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
71-
assertEquals("Bridge installed version", "1.6.3", l.getParsedVersion());
71+
assertEquals("Bridge installed version", "1.6.3", l.getVersion());
7272

7373
assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());
7474

@@ -77,7 +77,7 @@ public void testUpdatableLibraryWithBundled() throws Exception {
7777

7878
l = indexer.getIndex().getInstalled("Bridge").get();
7979
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
80-
assertEquals("Bridge installed version", "1.7.0", l.getParsedVersion());
80+
assertEquals("Bridge installed version", "1.7.0", l.getVersion());
8181

8282
assertFalse(ContributionsSelfCheck.checkForUpdatableLibraries());
8383
}

arduino-core/src/cc/arduino/contributions/VersionComparator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public static ContributedLibrary max(ContributedLibrary a, ContributedLibrary b)
7575
}
7676

7777
public static boolean greaterThan(ContributedLibrary a, ContributedLibrary b) {
78-
return greaterThan(a.getParsedVersion(), b.getParsedVersion());
78+
return greaterThan(a.getVersion(), b.getVersion());
7979
}
8080

8181
public static int compareTo(ContributedLibrary a, ContributedLibrary b) {
82-
return compareTo(a.getParsedVersion(), b.getParsedVersion());
82+
return compareTo(a.getVersion(), b.getVersion());
8383
}
8484
}

0 commit comments

Comments
 (0)