Skip to content

Commit 4266b3a

Browse files
cmagliefacchinm
authored andcommitted
Lib installer: factored out method to perform lib installation
The new method will be used in next commits to handle installations of multiple libraries. This commit fix also minor bug in progress bar.
1 parent d6f561b commit 4266b3a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,31 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E
8787
}
8888

8989
public synchronized void install(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, ProgressListener progressListener) throws Exception {
90+
final MultiStepProgress progress = new MultiStepProgress(4);
91+
92+
// Do install library (3 steps)
93+
performInstall(lib, mayReplacedLib, progressListener, progress);
94+
95+
// Rescan index (1 step)
96+
rescanLibraryIndex(progress, progressListener);
97+
}
98+
99+
private void performInstall(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
90100
if (lib.isLibraryInstalled()) {
91101
System.out.println(I18n.format(tr("Library is already installed: {0}:{1}"), lib.getName(), lib.getParsedVersion()));
92102
return;
93103
}
94104

95105
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());
96106

97-
final MultiStepProgress progress = new MultiStepProgress(3);
98-
99107
// Step 1: Download library
100108
try {
101109
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener);
102110
} catch (InterruptedException e) {
103111
// Download interrupted... just exit
104112
return;
105113
}
114+
progress.stepDone();
106115

107116
// TODO: Extract to temporary folders and move to the final destination only
108117
// once everything is successfully unpacked. If the operation fails remove
@@ -129,9 +138,6 @@ public synchronized void install(ContributedLibrary lib, Optional<ContributedLib
129138
File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_"));
130139
tmpFolder.renameTo(destFolder);
131140
progress.stepDone();
132-
133-
// Step 4: Rescan index
134-
rescanLibraryIndex(progress, progressListener);
135141
}
136142

137143
public synchronized void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException {

0 commit comments

Comments
 (0)