diff --git a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java index 2eae83e875b..7ff1925878c 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java @@ -200,6 +200,7 @@ protected void onUpdatePressed() { try { setProgressVisible(true, ""); installer.updateIndex(this::setProgress); + ((LibrariesIndexTableModel) contribModel).update(); onIndexesUpdated(); } catch (Exception e) { throw new RuntimeException(e); diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java index 8b7acae748c..c43a4a09423 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java @@ -31,7 +31,10 @@ import cc.arduino.Constants; import cc.arduino.contributions.packages.ContributedPlatform; + +import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.mrbean.MrBeanModule; import org.apache.commons.compress.utils.IOUtils; @@ -73,11 +76,14 @@ public LibrariesIndexer(File preferencesFolder) { } public void parseIndex() throws IOException { + index = new EmptyLibrariesIndex(); // Fallback + if (!indexFile.exists()) { - index = new EmptyLibrariesIndex(); - } else { - parseIndex(indexFile); + return; } + + parseIndex(indexFile); + // TODO: resolve libraries inner references } @@ -98,8 +104,12 @@ private void parseIndex(File file) throws IOException { .forEach(library -> library.setCategory("Uncategorized")); index = newIndex; + } catch (JsonParseException | JsonMappingException e) { + System.err.println( + format(tr("Error parsing libraries index: {0}\nTry to open the Library Manager to update the libraries index."), + e.getMessage())); } catch (Exception e) { - System.err.println("Error parsing library.index:" + e.getMessage()); + System.err.println(format(tr("Error reading libraries index: {0}"), e.getMessage())); } finally { IOUtils.closeQuietly(indexIn); } diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java index f06cc736bbf..4b4fb7f7dbb 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java @@ -56,7 +56,7 @@ public LibraryInstaller(Platform platform) { } public synchronized void updateIndex(ProgressListener progressListener) throws Exception { - final MultiStepProgress progress = new MultiStepProgress(2); + final MultiStepProgress progress = new MultiStepProgress(3); DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder()); // Step 1: Download index @@ -79,7 +79,10 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E if (!tmpFile.renameTo(outputFile)) throw new Exception(tr("An error occurred while updating libraries index!")); - // Step 2: Rescan index + // Step 2: Parse index + BaseNoGui.librariesIndexer.parseIndex(); + + // Step 3: Rescan index rescanLibraryIndex(progress, progressListener); } diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index 1ec4c365faa..a1ca10929d9 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java @@ -39,7 +39,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.mrbean.MrBeanModule; import org.apache.commons.compress.utils.IOUtils; -import processing.app.I18n; import processing.app.Platform; import processing.app.PreferencesData; import processing.app.debug.TargetPackage; @@ -55,6 +54,7 @@ import java.util.*; import java.util.stream.Collectors; +import static processing.app.I18n.format; import static processing.app.I18n.tr; import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS; @@ -100,13 +100,17 @@ public void parseIndex() throws Exception { // Overlay 3rd party indexes File[] indexFiles = preferencesFolder.listFiles(new TestPackageIndexFilenameFilter(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME))); - for (File indexFile : indexFiles) { - try { - mergeContributions(indexFile); - } catch (JsonProcessingException e) { - System.err.println(I18n.format(tr("Skipping contributed index file {0}, parsing error occured:"), indexFile)); - System.err.println(e); + if (indexFiles != null) { + for (File indexFile : indexFiles) { + try { + mergeContributions(indexFile); + } catch (JsonProcessingException e) { + System.err.println(format(tr("Skipping contributed index file {0}, parsing error occured:"), indexFile)); + System.err.println(e); + } } + } else { + System.err.println(format(tr("Error reading package indexes folder: {0}\n(maybe a permission problem?)"), preferencesFolder)); } // Fill tools and toolsDependency cross references @@ -156,7 +160,7 @@ private void mergeContributions(File indexFile) throws IOException { } else { if (contributedPackage.isTrusted() || !isPackageNameProtected(contributedPackage)) { if (isPackageNameProtected(contributedPackage) && trustall) { - System.err.println(I18n.format(tr("Warning: forced trusting untrusted contributions"))); + System.err.println(format(tr("Warning: forced trusting untrusted contributions"))); } List platforms = contributedPackage.getPlatforms(); if (platforms == null) {