Skip to content

Commit bdd6217

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

File tree

5 files changed

+65
-201
lines changed

5 files changed

+65
-201
lines changed

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

+10-8
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

7070
@Override
7171
protected FilteredAbstractTableModel createContribModel() {
@@ -100,9 +100,9 @@ protected void onRemove(ContributedLibraryRelease library) {
100100
};
101101
}
102102

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

107107
filtersContainer.add(new JLabel(tr("Topic")), 1);
108108
filtersContainer.remove(2);
@@ -218,7 +218,7 @@ protected void onUpdatePressed() {
218218
}
219219

220220
public void onInstallPressed(final ContributedLibraryRelease lib) {
221-
List<ContributedLibraryRelease> deps = BaseNoGui.getArduinoCoreService().libraryResolveDependecies(lib);
221+
List<ContributedLibraryRelease> deps = core.libraryResolveDependecies(lib);
222222
boolean depsInstalled = deps.stream().allMatch(l -> l.getInstalledLibrary().isPresent() || l.getName().equals(lib.getName()));
223223
Result installDeps;
224224
if (!depsInstalled) {
@@ -237,9 +237,11 @@ public void onInstallPressed(final ContributedLibraryRelease lib) {
237237
try {
238238
setProgressVisible(true, tr("Installing..."));
239239
if (installDeps == Result.ALL) {
240-
installer.install(deps, this::setProgress);
240+
deps.forEach(dep -> {
241+
core.libraryInstall(dep, this::setProgress);
242+
});
241243
} else {
242-
installer.install(lib, this::setProgress);
244+
core.libraryInstall(lib, this::setProgress);
243245
}
244246
onIndexesUpdated();
245247
if (contribTable.getCellEditor() != null) {
@@ -271,7 +273,7 @@ public void onRemovePressed(final ContributedLibraryRelease lib) {
271273
installerThread = new Thread(() -> {
272274
try {
273275
setProgressVisible(true, tr("Removing..."));
274-
installer.remove(lib, this::setProgress);
276+
core.libraryRemove(lib, this::setProgress);
275277
onIndexesUpdated();
276278
if (contribTable.getCellEditor() != null) {
277279
contribTable.getCellEditor().stopCellEditing();

app/src/processing/app/Base.java

+3-6
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

@@ -1374,7 +1371,7 @@ public void openLibraryManager(final String filterText, String dropdownItem) {
13741371
contributionsSelfCheck.cancel();
13751372
}
13761373
@SuppressWarnings("serial")
1377-
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, libraryInstaller) {
1374+
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.getArduinoCoreService()) {
13781375
@Override
13791376
protected void onIndexesUpdated() throws Exception {
13801377
BaseNoGui.initPackages();

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

+38-1
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

+14
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

-186
This file was deleted.

0 commit comments

Comments
 (0)