Skip to content

Commit 5d47f93

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 3b32588 commit 5d47f93

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,31 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E
8383
}
8484

8585
public synchronized void install(ContributedLibrary lib, ContributedLibrary replacedLib, ProgressListener progressListener) throws Exception {
86+
final MultiStepProgress progress = new MultiStepProgress(4);
87+
88+
// Do install library (3 steps)
89+
performInstall(lib, replacedLib, progressListener, progress);
90+
91+
// Rescan index (1 step)
92+
rescanLibraryIndex(progress, progressListener);
93+
}
94+
95+
private void performInstall(ContributedLibrary lib, ContributedLibrary replacedLib, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
8696
if (lib.isInstalled()) {
8797
System.out.println(I18n.format(tr("Library is already installed: {0} version {1}"), lib.getName(), lib.getParsedVersion()));
8898
return;
8999
}
90100

91101
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());
92102

93-
final MultiStepProgress progress = new MultiStepProgress(3);
94-
95103
// Step 1: Download library
96104
try {
97105
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener);
98106
} catch (InterruptedException e) {
99107
// Download interrupted... just exit
100108
return;
101109
}
110+
progress.stepDone();
102111

103112
// TODO: Extract to temporary folders and move to the final destination only
104113
// once everything is successfully unpacked. If the operation fails remove
@@ -123,9 +132,6 @@ public synchronized void install(ContributedLibrary lib, ContributedLibrary repl
123132
File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_"));
124133
tmpFolder.renameTo(destFolder);
125134
progress.stepDone();
126-
127-
// Step 4: Rescan index
128-
rescanLibraryIndex(progress, progressListener);
129135
}
130136

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

0 commit comments

Comments
 (0)