Skip to content

Commit b3baa27

Browse files
author
Federico Fissore
committed
ContributionInstaller.onProgress is now a collaborator: ProgressListener
1 parent c61c39f commit b3baa27

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ public void setIndexer(ContributionsIndexer indexer) {
118118
}
119119

120120
// Create ConstributionInstaller tied with the provided index
121-
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier()) {
122-
@Override
123-
public void onProgress(Progress progress) {
124-
setProgress(progress);
125-
}
126-
};
121+
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier(), this::setProgress);
127122
}
128123

129124
public void setProgress(Progress progress) {

app/src/processing/app/Base.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,18 @@ public Base(String[] args) throws Exception {
341341

342342
if (parser.isInstallBoard()) {
343343
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
344-
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier()) {
344+
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier(), new ProgressListener() {
345345
private String lastStatus = "";
346346

347347
@Override
348-
protected void onProgress(Progress progress) {
348+
public void onProgress(Progress progress) {
349349
if (!lastStatus.equals(progress.getStatus())) {
350350
System.out.println(progress.getStatus());
351351
}
352352
lastStatus = progress.getStatus();
353353
}
354-
};
354+
});
355+
355356
List<String> downloadedPackageIndexFiles = installer.updateIndex();
356357
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
357358
indexer.parseIndex();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
30+
package cc.arduino.contributions;
31+
32+
import cc.arduino.utils.Progress;
33+
34+
public interface ProgressListener {
35+
36+
void onProgress(Progress progress);
37+
38+
}

arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import cc.arduino.Constants;
3333
import cc.arduino.contributions.DownloadableContribution;
3434
import cc.arduino.contributions.DownloadableContributionsDownloader;
35+
import cc.arduino.contributions.ProgressListener;
3536
import cc.arduino.contributions.SignatureVerifier;
3637
import cc.arduino.filters.FileExecutablePredicate;
3738
import cc.arduino.utils.ArchiveExtractor;
@@ -64,16 +65,23 @@ public class ContributionInstaller {
6465
private final DownloadableContributionsDownloader downloader;
6566
private final Platform platform;
6667
private final SignatureVerifier signatureVerifier;
68+
private final ProgressListener progressListener;
6769

6870
public ContributionInstaller(ContributionsIndexer contributionsIndexer, Platform platform, SignatureVerifier signatureVerifier) {
71+
this(contributionsIndexer, platform, signatureVerifier, progress -> {
72+
});
73+
}
74+
75+
public ContributionInstaller(ContributionsIndexer contributionsIndexer, Platform platform, SignatureVerifier signatureVerifier, ProgressListener progressListener) {
6976
this.platform = platform;
7077
this.signatureVerifier = signatureVerifier;
78+
this.progressListener = progressListener;
7179
File stagingFolder = contributionsIndexer.getStagingFolder();
7280
indexer = contributionsIndexer;
7381
downloader = new DownloadableContributionsDownloader(stagingFolder) {
7482
@Override
7583
protected void onProgress(Progress progress) {
76-
ContributionInstaller.this.onProgress(progress);
84+
progressListener.onProgress(progress);
7785
}
7886
};
7987
}
@@ -132,7 +140,7 @@ public List<String> install(ContributedPlatform contributedPlatform) throws Exce
132140
int i = 1;
133141
for (ContributedTool tool : tools) {
134142
progress.setStatus(format(tr("Installing tools ({0}/{1})..."), i, tools.size()));
135-
onProgress(progress);
143+
progressListener.onProgress(progress);
136144
i++;
137145
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
138146
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
@@ -152,7 +160,7 @@ public List<String> install(ContributedPlatform contributedPlatform) throws Exce
152160

153161
// Unpack platform on the correct location
154162
progress.setStatus(tr("Installing boards..."));
155-
onProgress(progress);
163+
progressListener.onProgress(progress);
156164
File platformFolder = new File(packageFolder, "hardware" + File.separator + contributedPlatform.getArchitecture());
157165
File destFolder = new File(platformFolder, contributedPlatform.getParsedVersion());
158166
Files.createDirectories(destFolder.toPath());
@@ -168,7 +176,7 @@ public List<String> install(ContributedPlatform contributedPlatform) throws Exce
168176
progress.stepDone();
169177

170178
progress.setStatus(tr("Installation completed!"));
171-
onProgress(progress);
179+
progressListener.onProgress(progress);
172180

173181
return errors;
174182
}
@@ -328,10 +336,6 @@ private File download(MultiStepProgress progress, String packageIndexUrl) throws
328336
return outputFile;
329337
}
330338

331-
protected void onProgress(Progress progress) {
332-
// Empty
333-
}
334-
335339
public void deleteUnknownFiles(List<String> downloadedPackageIndexFiles) throws IOException {
336340
File preferencesFolder = indexer.getIndexFile(".").getParentFile();
337341
File[] additionalPackageIndexFiles = preferencesFolder.listFiles(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME));

0 commit comments

Comments
 (0)