mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
ContributionInstaller.onProgress is now a collaborator: ProgressListener
This commit is contained in:
parent
c61c39f5d9
commit
b3baa27435
@ -118,12 +118,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
}
|
||||
|
||||
// Create ConstributionInstaller tied with the provided index
|
||||
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier()) {
|
||||
@Override
|
||||
public void onProgress(Progress progress) {
|
||||
setProgress(progress);
|
||||
}
|
||||
};
|
||||
installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier(), this::setProgress);
|
||||
}
|
||||
|
||||
public void setProgress(Progress progress) {
|
||||
|
@ -341,17 +341,18 @@ public class Base {
|
||||
|
||||
if (parser.isInstallBoard()) {
|
||||
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
|
||||
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier()) {
|
||||
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier(), new ProgressListener() {
|
||||
private String lastStatus = "";
|
||||
|
||||
@Override
|
||||
protected void onProgress(Progress progress) {
|
||||
public void onProgress(Progress progress) {
|
||||
if (!lastStatus.equals(progress.getStatus())) {
|
||||
System.out.println(progress.getStatus());
|
||||
}
|
||||
lastStatus = progress.getStatus();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
List<String> downloadedPackageIndexFiles = installer.updateIndex();
|
||||
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
|
||||
indexer.parseIndex();
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.Progress;
|
||||
|
||||
public interface ProgressListener {
|
||||
|
||||
void onProgress(Progress progress);
|
||||
|
||||
}
|
@ -32,6 +32,7 @@ package cc.arduino.contributions.packages;
|
||||
import cc.arduino.Constants;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionsDownloader;
|
||||
import cc.arduino.contributions.ProgressListener;
|
||||
import cc.arduino.contributions.SignatureVerifier;
|
||||
import cc.arduino.filters.FileExecutablePredicate;
|
||||
import cc.arduino.utils.ArchiveExtractor;
|
||||
@ -64,16 +65,23 @@ public class ContributionInstaller {
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final Platform platform;
|
||||
private final SignatureVerifier signatureVerifier;
|
||||
private final ProgressListener progressListener;
|
||||
|
||||
public ContributionInstaller(ContributionsIndexer contributionsIndexer, Platform platform, SignatureVerifier signatureVerifier) {
|
||||
this(contributionsIndexer, platform, signatureVerifier, progress -> {
|
||||
});
|
||||
}
|
||||
|
||||
public ContributionInstaller(ContributionsIndexer contributionsIndexer, Platform platform, SignatureVerifier signatureVerifier, ProgressListener progressListener) {
|
||||
this.platform = platform;
|
||||
this.signatureVerifier = signatureVerifier;
|
||||
this.progressListener = progressListener;
|
||||
File stagingFolder = contributionsIndexer.getStagingFolder();
|
||||
indexer = contributionsIndexer;
|
||||
downloader = new DownloadableContributionsDownloader(stagingFolder) {
|
||||
@Override
|
||||
protected void onProgress(Progress progress) {
|
||||
ContributionInstaller.this.onProgress(progress);
|
||||
progressListener.onProgress(progress);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -132,7 +140,7 @@ public class ContributionInstaller {
|
||||
int i = 1;
|
||||
for (ContributedTool tool : tools) {
|
||||
progress.setStatus(format(tr("Installing tools ({0}/{1})..."), i, tools.size()));
|
||||
onProgress(progress);
|
||||
progressListener.onProgress(progress);
|
||||
i++;
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
|
||||
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
|
||||
@ -152,7 +160,7 @@ public class ContributionInstaller {
|
||||
|
||||
// Unpack platform on the correct location
|
||||
progress.setStatus(tr("Installing boards..."));
|
||||
onProgress(progress);
|
||||
progressListener.onProgress(progress);
|
||||
File platformFolder = new File(packageFolder, "hardware" + File.separator + contributedPlatform.getArchitecture());
|
||||
File destFolder = new File(platformFolder, contributedPlatform.getParsedVersion());
|
||||
Files.createDirectories(destFolder.toPath());
|
||||
@ -168,7 +176,7 @@ public class ContributionInstaller {
|
||||
progress.stepDone();
|
||||
|
||||
progress.setStatus(tr("Installation completed!"));
|
||||
onProgress(progress);
|
||||
progressListener.onProgress(progress);
|
||||
|
||||
return errors;
|
||||
}
|
||||
@ -328,10 +336,6 @@ public class ContributionInstaller {
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
protected void onProgress(Progress progress) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public void deleteUnknownFiles(List<String> downloadedPackageIndexFiles) throws IOException {
|
||||
File preferencesFolder = indexer.getIndexFile(".").getParentFile();
|
||||
File[] additionalPackageIndexFiles = preferencesFolder.listFiles(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME));
|
||||
|
Loading…
x
Reference in New Issue
Block a user