From 8fa6f110f19470695ed8edc2388ebc57806676b7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 3 Sep 2018 15:17:47 +0200 Subject: [PATCH 1/6] Do not fail if library_index.json can't be parsed Fix #7937 --- .../contributions/libraries/LibrariesIndexer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java index 8b7acae748c..0d1ec00e39f 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java @@ -73,11 +73,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 } From 53faedaa44af8f1363f1d17f619666589a535f59 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 3 Sep 2018 15:19:13 +0200 Subject: [PATCH 2/6] Get a better error message if the library_index.json can't be parsed See #7937 --- .../contributions/libraries/LibrariesIndexer.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java b/arduino-core/src/cc/arduino/contributions/libraries/LibrariesIndexer.java index 0d1ec00e39f..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; @@ -101,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); } From 97b0911b5496e8fae7be533641b3c7c656adccd7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 3 Sep 2018 15:20:00 +0200 Subject: [PATCH 3/6] Do not fail if the data folder can't be read Fix #7937 --- .../packages/ContributionsIndexer.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index 1ec4c365faa..bdd99c576e6 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java @@ -55,6 +55,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 +101,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 From bab774a9b0b382281ef37e09a7843bedc20a7ea6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 3 Sep 2018 15:20:46 +0200 Subject: [PATCH 4/6] Removed useless I18n reference in call to format --- .../arduino/contributions/packages/ContributionsIndexer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index bdd99c576e6..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; @@ -161,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) { From 8d153e611ccf7c0e79fe67052295c954eab16d62 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 5 Sep 2018 18:12:34 +0200 Subject: [PATCH 5/6] Immediately re-parse library_index.json after updating it --- .../arduino/contributions/libraries/LibraryInstaller.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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); } From c45c1af0a182702b41079f4bf4e565742f16b92d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 5 Sep 2018 18:13:14 +0200 Subject: [PATCH 6/6] Update library list model after a round of library_index.json update --- .../cc/arduino/contributions/libraries/ui/LibraryManagerUI.java | 1 + 1 file changed, 1 insertion(+) 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);