From b914070c9018198605cf3274ac66e95d71c266b8 Mon Sep 17 00:00:00 2001 From: Ricardo JL Rufino Date: Sun, 17 May 2020 17:03:47 -0300 Subject: [PATCH] Avoid usueless double calls to rescanLibraries() Previously rescanLibraries() was automatically called internally in setLibrariesFolder(). This lead to double calls to rescanLibraries() when setLibrariesFolder() was used in combination with an explicit call to rescanLibraries(). This commit adds a new method setLibrariesFoldersAndRescan(..) and removes the internal call to rescanLibraries() from setLibrariesFolder(). The existing setLibrariesFolder()+rescanLibraries() combos have been replaced with setLibrariesFoldersAndRescan(). Fix #10228 --- .../cc/arduino/contributions/UpdatableLibraryTest.java | 10 ++++------ .../contributions/libraries/LibrariesIndexer.java | 6 +++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/test/cc/arduino/contributions/UpdatableLibraryTest.java b/app/test/cc/arduino/contributions/UpdatableLibraryTest.java index e06c12710..0dab3531c 100644 --- a/app/test/cc/arduino/contributions/UpdatableLibraryTest.java +++ b/app/test/cc/arduino/contributions/UpdatableLibraryTest.java @@ -36,8 +36,7 @@ public class UpdatableLibraryTest { LibrariesIndexer indexer = new LibrariesIndexer(index_SD_only); BaseNoGui.librariesIndexer = indexer; indexer.parseIndex(); - indexer.setLibrariesFolders(folders); - indexer.rescanLibraries(); + indexer.setLibrariesFoldersAndRescan(folders); ContributedLibrary sdLib = indexer.getIndex().getInstalled("SD").get(); assertTrue("SD lib is installed", sdLib.isLibraryInstalled()); @@ -46,7 +45,7 @@ public class UpdatableLibraryTest { assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries()); folders.add(new UserLibraryFolder(SD121, Location.SKETCHBOOK)); - indexer.setLibrariesFolders(folders); + indexer.setLibrariesFoldersAndRescan(folders); sdLib = indexer.getIndex().getInstalled("SD").get(); assertTrue("SD lib is installed", sdLib.isLibraryInstalled()); @@ -63,8 +62,7 @@ public class UpdatableLibraryTest { LibrariesIndexer indexer = new LibrariesIndexer(index_Bridge_only); BaseNoGui.librariesIndexer = indexer; indexer.parseIndex(); - indexer.setLibrariesFolders(folders); - indexer.rescanLibraries(); + indexer.setLibrariesFoldersAndRescan(folders); ContributedLibrary l = indexer.getIndex().getInstalled("Bridge").get(); assertTrue("Bridge lib is installed", l.isLibraryInstalled()); @@ -73,7 +71,7 @@ public class UpdatableLibraryTest { assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries()); folders.add(new UserLibraryFolder(Bridge170, Location.SKETCHBOOK)); - indexer.setLibrariesFolders(folders); + indexer.setLibrariesFoldersAndRescan(folders); l = indexer.getIndex().getInstalled("Bridge").get(); assertTrue("Bridge lib is installed", l.isLibraryInstalled()); diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java index fb0b0c76a..57460fc19 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java @@ -114,7 +114,11 @@ public class LibrariesIndexer { } public void setLibrariesFolders(List folders) { - librariesFolders = folders; + this.librariesFolders = folders; + } + + public void setLibrariesFoldersAndRescan(List folders) { + setLibrariesFolders(folders); rescanLibraries(); }