Skip to content

Commit a57f49c

Browse files
committed
Removed no more needed LibraryInstaller (it's now done via GRPC)
1 parent e5f98cc commit a57f49c

File tree

5 files changed

+66
-202
lines changed

5 files changed

+66
-202
lines changed

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
import javax.swing.table.TableCellRenderer;
5050

5151
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
52+
import cc.arduino.cli.ArduinoCoreInstance;
5253
import cc.arduino.contributions.libraries.ContributedLibrary;
53-
import cc.arduino.contributions.libraries.LibraryInstaller;
5454
import cc.arduino.contributions.libraries.LibraryTypeComparator;
5555
import cc.arduino.contributions.libraries.ui.MultiLibraryInstallDialog.Result;
5656
import cc.arduino.contributions.ui.DropdownItem;
@@ -64,8 +64,8 @@
6464
@SuppressWarnings("serial")
6565
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
6666

67+
private final ArduinoCoreInstance core;
6768
private final JComboBox typeChooser;
68-
private final LibraryInstaller installer;
6969
private Predicate<ContributedLibrary> typeFilter;
7070

7171
@Override
@@ -97,9 +97,9 @@ protected void onRemove(ContributedLibraryRelease library) {
9797
};
9898
}
9999

100-
public LibraryManagerUI(Frame parent, LibraryInstaller installer) {
100+
public LibraryManagerUI(Frame parent, ArduinoCoreInstance core) {
101101
super(parent, tr("Library Manager"), Dialog.ModalityType.APPLICATION_MODAL, tr("Unable to reach Arduino.cc due to possible network issues."));
102-
this.installer = installer;
102+
this.core = core;
103103

104104
filtersContainer.add(new JLabel(tr("Topic")), 1);
105105
filtersContainer.remove(2);
@@ -200,7 +200,7 @@ protected void onUpdatePressed() {
200200
installerThread = new Thread(() -> {
201201
try {
202202
setProgressVisible(true, "");
203-
BaseNoGui.getArduinoCoreService().updateLibrariesIndex(this::setProgress);
203+
core.updateLibrariesIndex(this::setProgress);
204204
((LibrariesIndexTableModel) contribModel).update();
205205
onIndexesUpdated();
206206
} catch (Exception e) {
@@ -215,7 +215,7 @@ protected void onUpdatePressed() {
215215
}
216216

217217
public void onInstallPressed(final ContributedLibraryRelease lib) {
218-
List<ContributedLibraryRelease> deps = BaseNoGui.getArduinoCoreService().libraryResolveDependecies(lib);
218+
List<ContributedLibraryRelease> deps = core.libraryResolveDependecies(lib);
219219
boolean depsInstalled = deps.stream().allMatch(l -> l.getInstalledLibrary().isPresent() || l.getName().equals(lib.getName()));
220220
Result installDeps;
221221
if (!depsInstalled) {
@@ -234,9 +234,11 @@ public void onInstallPressed(final ContributedLibraryRelease lib) {
234234
try {
235235
setProgressVisible(true, tr("Installing..."));
236236
if (installDeps == Result.ALL) {
237-
installer.install(deps, this::setProgress);
237+
deps.forEach(dep -> {
238+
core.libraryInstall(dep, this::setProgress);
239+
});
238240
} else {
239-
installer.install(lib, this::setProgress);
241+
core.libraryInstall(lib, this::setProgress);
240242
}
241243
// TODO: Do a better job in refreshing only the needed element
242244
if (contribTable.getCellEditor() != null) {
@@ -269,7 +271,7 @@ public void onRemovePressed(final ContributedLibraryRelease lib) {
269271
installerThread = new Thread(() -> {
270272
try {
271273
setProgressVisible(true, tr("Removing..."));
272-
installer.remove(lib, this::setProgress);
274+
core.libraryRemove(lib, this::setProgress);
273275
// TODO: Do a better job in refreshing only the needed element
274276
if (contribTable.getCellEditor() != null) {
275277
contribTable.getCellEditor().stopCellEditing();

app/src/processing/app/Base.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import cc.arduino.contributions.libraries.ContributedLibrary;
3131
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
3232
import cc.arduino.contributions.libraries.LibrariesIndexer;
33-
import cc.arduino.contributions.libraries.LibraryInstaller;
3433
import cc.arduino.contributions.libraries.LibraryOfSameTypeComparator;
3534
import cc.arduino.contributions.libraries.ui.LibraryManagerUI;
3635
import cc.arduino.contributions.packages.ContributedPlatform;
@@ -98,7 +97,6 @@ public class Base {
9897

9998
public static Map<String, Object> FIND_DIALOG_STATE = new HashMap<>();
10099
private final ContributionInstaller contributionInstaller;
101-
private final LibraryInstaller libraryInstaller;
102100
private ContributionsSelfCheck contributionsSelfCheck;
103101

104102
// set to true after the first time the menu is built.
@@ -302,7 +300,6 @@ public Base(String[] args) throws Exception {
302300

303301
final GPGDetachedSignatureVerifier gpgDetachedSignatureVerifier = new GPGDetachedSignatureVerifier();
304302
contributionInstaller = new ContributionInstaller(BaseNoGui.getPlatform(), gpgDetachedSignatureVerifier);
305-
libraryInstaller = new LibraryInstaller(BaseNoGui.getPlatform());
306303

307304
parser.parseArgumentsPhase2();
308305

@@ -395,9 +392,9 @@ public Base(String[] args) throws Exception {
395392
System.out.println(tr(I18n
396393
.format("Library {0} is available as built-in in the IDE.\nRemoving the other version {1} installed in the sketchbook...",
397394
libraryArg, mayInstalled.get().getParsedVersion())));
398-
libraryInstaller.remove(mayInstalled.get(), progressListener);
395+
BaseNoGui.getArduinoCoreService().libraryRemove(mayInstalled.get(), progressListener);
399396
} else {
400-
libraryInstaller.install(selected, progressListener);
397+
BaseNoGui.getArduinoCoreService().libraryInstall(selected, progressListener);
401398
}
402399
}
403400

@@ -1368,7 +1365,7 @@ public void openLibraryManager(final String filterText, String dropdownItem) {
13681365
contributionsSelfCheck.cancel();
13691366
}
13701367
@SuppressWarnings("serial")
1371-
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, libraryInstaller) {
1368+
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.getArduinoCoreService()) {
13721369
@Override
13731370
protected void onIndexesUpdated() throws Exception {
13741371
BaseNoGui.initPackages();

arduino-core/src/cc/arduino/cli/ArduinoCoreInstance.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@
4646
import cc.arduino.cli.commands.Commands.UpdateLibrariesIndexResp;
4747
import cc.arduino.cli.commands.Common.DownloadProgress;
4848
import cc.arduino.cli.commands.Common.Instance;
49+
import cc.arduino.cli.commands.Common.TaskProgress;
4950
import cc.arduino.cli.commands.Compile.CompileReq;
5051
import cc.arduino.cli.commands.Compile.CompileResp;
5152
import cc.arduino.cli.commands.Lib.InstalledLibrary;
53+
import cc.arduino.cli.commands.Lib.LibraryInstallReq;
54+
import cc.arduino.cli.commands.Lib.LibraryInstallResp;
5255
import cc.arduino.cli.commands.Lib.LibraryListReq;
5356
import cc.arduino.cli.commands.Lib.LibraryListResp;
5457
import cc.arduino.cli.commands.Lib.LibrarySearchReq;
5558
import cc.arduino.cli.commands.Lib.LibrarySearchResp;
59+
import cc.arduino.cli.commands.Lib.LibraryUninstallReq;
60+
import cc.arduino.cli.commands.Lib.LibraryUninstallResp;
5661
import cc.arduino.cli.commands.Lib.SearchedLibrary;
5762
import cc.arduino.contributions.ProgressListener;
5863
import cc.arduino.contributions.libraries.ContributedLibraryRelease;
@@ -155,7 +160,8 @@ public List<SearchedLibrary> searchLibrary(String query)
155160
}
156161
}
157162

158-
public List<InstalledLibrary> libraryList(boolean listAll) throws StatusException {
163+
public List<InstalledLibrary> libraryList(boolean listAll)
164+
throws StatusException {
159165
try {
160166
LibraryListResp resp = stub.libraryList(LibraryListReq.newBuilder() //
161167
.setInstance(instance) //
@@ -171,4 +177,35 @@ public List<ContributedLibraryRelease> libraryResolveDependecies(ContributedLibr
171177
return new ArrayList<>();
172178
}
173179

180+
public void libraryInstall(ContributedLibraryRelease lib,
181+
ProgressListener progressListener) {
182+
Iterator<LibraryInstallResp> stream = stub
183+
.libraryInstall(LibraryInstallReq.newBuilder() //
184+
.setInstance(instance) //
185+
.setName(lib.getName()) //
186+
.setVersion(lib.getVersion()) //
187+
.build());
188+
ProgressWrapper p = new ProgressWrapper(progressListener);
189+
while (stream.hasNext()) {
190+
LibraryInstallResp resp = stream.next();
191+
DownloadProgress progress = resp.getProgress();
192+
p.update(progress);
193+
}
194+
}
195+
196+
public void libraryRemove(ContributedLibraryRelease lib,
197+
ProgressListener progressListener) {
198+
Iterator<LibraryUninstallResp> stream = stub
199+
.libraryUninstall(LibraryUninstallReq.newBuilder() //
200+
.setInstance(instance) //
201+
.setName(lib.getName()) //
202+
.setVersion(lib.getVersion()) //
203+
.build());
204+
ProgressWrapper p = new ProgressWrapper(progressListener);
205+
while (stream.hasNext()) {
206+
LibraryUninstallResp resp = stream.next();
207+
TaskProgress progress = resp.getTaskProgress();
208+
p.update(progress);
209+
}
210+
}
174211
}

arduino-core/src/cc/arduino/cli/ProgressWrapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static processing.app.I18n.tr;
3434

3535
import cc.arduino.cli.commands.Common.DownloadProgress;
36+
import cc.arduino.cli.commands.Common.TaskProgress;
3637
import cc.arduino.contributions.ProgressListener;
3738
import cc.arduino.utils.MultiStepProgress;
3839
import cc.arduino.utils.Progress;
@@ -78,4 +79,17 @@ public void update(DownloadProgress d) {
7879
}
7980
progressListener.onProgress(progress);
8081
}
82+
83+
String taskName;
84+
85+
public void update(TaskProgress t) {
86+
String name = t.getName();
87+
if (!name.isEmpty()) {
88+
taskName = name;
89+
}
90+
91+
progress.setProgress(t.getCompleted() ? 100 : 0);
92+
progress.setStatus(taskName + " " + t.getMessage());
93+
progressListener.onProgress(progress);
94+
}
8195
}

arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)