From cec4f41dd7c588c5dd6279e82d58d5625a88b380 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 22 Dec 2020 11:56:52 +0100 Subject: [PATCH 1/2] Board Manager: searching returns also near matches The original filter would only populate the contribution list with perfect matches. Previously, if a core was installed but didn't match the search it wouldn't appear in the results (due to a board being added or the description changed); the user could then install (not upgrade) the core, triggering a confusing situation. When moving to arduino-cli backend we should take care of this issue, at least visually (the cli logic would correctly update/downgrade the core) --- .../ui/ContributedPlatformReleases.java | 6 ++++++ .../ui/ContributionIndexTableModel.java | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java index fc516512d4..2cdeb5c274 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java @@ -61,6 +61,12 @@ public boolean shouldContain(ContributedPlatform platform) { return platform.getArchitecture().equals(arch); } + public boolean contains(ContributedPlatform platform) { + return (platform.getParentPackage().equals(packager) + && platform.getArchitecture().equals(arch) + && versions.contains(platform.getParsedVersion())); + } + public void add(ContributedPlatform platform) { releases.add(platform); String version = platform.getParsedVersion(); diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java b/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java index f7dbd95d75..4a9b89bb32 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java @@ -66,11 +66,21 @@ private void updateContributions() { + platform.getBoards().stream() .map(ContributedBoard::getName) .collect(Collectors.joining(" ")); + + // Add all the versions of the same core, even if there's no match + for (ContributedPlatformReleases contribution : contributions) { + if (contribution.shouldContain(platform)) { + addContribution(platform); + continue; + } + } + if (!filter.test(platform)) { continue; } if (!stringContainsAll(compoundTargetSearchText, filters)) continue; + addContribution(platform); } } @@ -110,12 +120,16 @@ private boolean stringContainsAll(String string, String set[]) { private void addContribution(ContributedPlatform platform) { for (ContributedPlatformReleases contribution : contributions) { - if (!contribution.shouldContain(platform)) + if (!contribution.shouldContain(platform)) { continue; + } + if (contribution.contains(platform)) { + // no duplicates + return; + } contribution.add(platform); return; } - contributions.add(new ContributedPlatformReleases(platform)); } From aef6d2ac9877848bfccb8640dabbeea7194fb296 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 11 May 2021 14:31:12 +0200 Subject: [PATCH 2/2] Filter ContributedPlatformReleases after fully building them --- .../ui/ContributedPlatformReleases.java | 6 ---- .../ui/ContributionIndexTableModel.java | 31 +++++++++---------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java index 2cdeb5c274..fc516512d4 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformReleases.java @@ -61,12 +61,6 @@ public boolean shouldContain(ContributedPlatform platform) { return platform.getArchitecture().equals(arch); } - public boolean contains(ContributedPlatform platform) { - return (platform.getParentPackage().equals(packager) - && platform.getArchitecture().equals(arch) - && versions.contains(platform.getParsedVersion())); - } - public void add(ContributedPlatform platform) { releases.add(platform); String version = platform.getParsedVersion(); diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java b/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java index 4a9b89bb32..2c9939849b 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java @@ -60,30 +60,32 @@ public void updateIndexFilter(String[] filters, private void updateContributions() { contributions.clear(); + + // Generate ContributedPlatformReleases from all platform releases for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) { for (ContributedPlatform platform : pack.getPlatforms()) { + addContribution(platform); + } + } + + // Filter ContributedPlatformReleases based on search terms + contributions.removeIf(releases -> { + for (ContributedPlatform platform : releases.releases) { String compoundTargetSearchText = platform.getName() + "\n" + platform.getBoards().stream() .map(ContributedBoard::getName) .collect(Collectors.joining(" ")); - - // Add all the versions of the same core, even if there's no match - for (ContributedPlatformReleases contribution : contributions) { - if (contribution.shouldContain(platform)) { - addContribution(platform); - continue; - } - } - if (!filter.test(platform)) { continue; } if (!stringContainsAll(compoundTargetSearchText, filters)) continue; - - addContribution(platform); + return false; } - } + return true; + }); + + // Sort ContributedPlatformReleases and put deprecated platforms to the bottom Collections.sort(contributions, (x,y)-> { if (x.isDeprecated() != y.isDeprecated()) { return x.isDeprecated() ? 1 : -1; @@ -96,6 +98,7 @@ private void updateContributions() { } return x1.getName().compareToIgnoreCase(y1.getName()); }); + fireTableDataChanged(); } @@ -123,10 +126,6 @@ private void addContribution(ContributedPlatform platform) { if (!contribution.shouldContain(platform)) { continue; } - if (contribution.contains(platform)) { - // no duplicates - return; - } contribution.add(platform); return; }