diff --git a/app/.classpath b/app/.classpath
index bb2bf7417..6f11afa86 100644
--- a/app/.classpath
+++ b/app/.classpath
@@ -54,5 +54,6 @@
+
diff --git a/app/lib/grpc-core-1.20.0.jar b/app/lib/grpc-core-1.20.0.jar
new file mode 100644
index 000000000..a44ec185b
Binary files /dev/null and b/app/lib/grpc-core-1.20.0.jar differ
diff --git a/arduino-core/src/cc/arduino/cli/ArduinoCoreInstance.java b/arduino-core/src/cc/arduino/cli/ArduinoCoreInstance.java
index a00fe5191..3f5722477 100644
--- a/arduino-core/src/cc/arduino/cli/ArduinoCoreInstance.java
+++ b/arduino-core/src/cc/arduino/cli/ArduinoCoreInstance.java
@@ -29,24 +29,32 @@
package cc.arduino.cli;
+import static processing.app.I18n.tr;
+
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.protobuf.ByteString;
+import cc.arduino.cli.commands.ArduinoCoreGrpc.ArduinoCoreBlockingStub;
import cc.arduino.cli.commands.Board.BoardDetailsReq;
import cc.arduino.cli.commands.Board.BoardDetailsResp;
import cc.arduino.cli.commands.Commands.DestroyReq;
import cc.arduino.cli.commands.Commands.RescanReq;
+import cc.arduino.cli.commands.Commands.UpdateLibrariesIndexReq;
+import cc.arduino.cli.commands.Commands.UpdateLibrariesIndexResp;
+import cc.arduino.cli.commands.Common.DownloadProgress;
import cc.arduino.cli.commands.Common.Instance;
import cc.arduino.cli.commands.Compile.CompileReq;
import cc.arduino.cli.commands.Compile.CompileResp;
import cc.arduino.cli.commands.Lib.LibrarySearchReq;
import cc.arduino.cli.commands.Lib.LibrarySearchResp;
import cc.arduino.cli.commands.Lib.SearchedLibrary;
+import cc.arduino.contributions.ProgressListener;
+import cc.arduino.contributions.libraries.ContributedLibraryRelease;
import io.grpc.StatusException;
import io.grpc.StatusRuntimeException;
-import cc.arduino.cli.commands.ArduinoCoreGrpc.ArduinoCoreBlockingStub;
public class ArduinoCoreInstance {
@@ -111,6 +119,24 @@ public class ArduinoCoreInstance {
}
}
+ public void updateLibrariesIndex(ProgressListener progressListener)
+ throws StatusException {
+ try {
+ Iterator stream = stub
+ .updateLibrariesIndex(UpdateLibrariesIndexReq.newBuilder()
+ .setInstance(instance).build());
+ ProgressWrapper p = new ProgressWrapper(progressListener);
+ while (stream.hasNext()) {
+ UpdateLibrariesIndexResp resp = stream.next();
+ DownloadProgress progress = resp.getDownloadProgress().toBuilder()
+ .setFile(tr("Downloading libraries index...")).build();
+ p.update(progress);
+ }
+ } catch (StatusRuntimeException e) {
+ throw e.getStatus().asException();
+ }
+ }
+
// Lib functions
public List searchLibrary(String query)
diff --git a/arduino-core/src/cc/arduino/cli/ProgressWrapper.java b/arduino-core/src/cc/arduino/cli/ProgressWrapper.java
new file mode 100644
index 000000000..892108555
--- /dev/null
+++ b/arduino-core/src/cc/arduino/cli/ProgressWrapper.java
@@ -0,0 +1,81 @@
+/*
+ * This file is part of Arduino.
+ *
+ * Copyright 2019 Arduino LLC (http://www.arduino.cc/)
+ *
+ * Arduino is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ */
+
+package cc.arduino.cli;
+
+import static processing.app.I18n.format;
+import static processing.app.I18n.tr;
+
+import cc.arduino.cli.commands.Common.DownloadProgress;
+import cc.arduino.contributions.ProgressListener;
+import cc.arduino.utils.MultiStepProgress;
+import cc.arduino.utils.Progress;
+
+class ProgressWrapper {
+ final ProgressListener progressListener;
+ String file = "";
+ String url = "";
+ private long downloaded, totalSize;
+ Progress progress = new MultiStepProgress(1);
+
+ public ProgressWrapper(ProgressListener progressListener) {
+ this.progressListener = progressListener;
+ }
+
+ public void update(DownloadProgress d) {
+ if (d == null) {
+ return;
+ }
+ if (!d.getFile().isEmpty()) {
+ file = d.getFile();
+ }
+ if (!d.getUrl().isEmpty()) {
+ url = d.getUrl();
+ }
+ if (d.getTotalSize() > 0) {
+ totalSize = d.getTotalSize();
+ }
+ if (d.getDownloaded() > 0) {
+ downloaded = d.getDownloaded();
+ }
+
+ String msg = format(tr("Downloaded {0}kb of {1}kb."), downloaded, totalSize);
+ if (d.getCompleted()) {
+ file = "";
+ url = "";
+ totalSize = 0;
+ downloaded = 0;
+ } else {
+ progress.setStatus("Downloading " + file + url + " (" + downloaded
+ + " of " + totalSize + ")");
+ progress.setProgress(((float) downloaded / totalSize) * 100);
+ }
+ progressListener.onProgress(progress);
+ }
+}
\ No newline at end of file