From dc93bb93d025babbd6774648639edc538b701fa7 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 4 Aug 2015 11:01:00 +0200 Subject: [PATCH] ProgressListener is now a method arg (was an instance arg) --- .../contributions/ContributionsSelfCheck.java | 6 ++- .../libraries/ui/LibraryManagerUI.java | 13 ++----- .../packages/ui/ContributionManagerUI.java | 6 +-- app/src/processing/app/Base.java | 37 +++++------------- .../GzippedJsonDownloaderTest.java | 2 +- .../contributions/JsonDownloaderTest.java | 2 +- .../ConsoleProgressListener.java | 15 +++++++ .../DownloadableContributionsDownloader.java | 14 +++---- .../contributions/GZippedJsonDownloader.java | 6 +-- .../arduino/contributions/JsonDownloader.java | 4 +- .../contributions/NoopProgressListener.java | 12 ++++++ .../libraries/LibraryInstaller.java | 39 +++++++------------ .../packages/ContributionInstaller.java | 37 ++++++------------ 13 files changed, 86 insertions(+), 107 deletions(-) create mode 100644 arduino-core/src/cc/arduino/contributions/ConsoleProgressListener.java create mode 100644 arduino-core/src/cc/arduino/contributions/NoopProgressListener.java diff --git a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java index bb5c13d39..4819b2137 100644 --- a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java +++ b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java @@ -24,6 +24,7 @@ public class ContributionsSelfCheck extends TimerTask { private final ContributionInstaller contributionInstaller; private final LibrariesIndexer librariesIndexer; private final LibraryInstaller libraryInstaller; + private final ProgressListener progressListener; public ContributionsSelfCheck(Base base, HyperlinkListener hyperlinkListener, ContributionsIndexer contributionsIndexer, ContributionInstaller contributionInstaller, LibrariesIndexer librariesIndexer, LibraryInstaller libraryInstaller) { this.base = base; @@ -32,6 +33,7 @@ public class ContributionsSelfCheck extends TimerTask { this.contributionInstaller = contributionInstaller; this.librariesIndexer = librariesIndexer; this.libraryInstaller = libraryInstaller; + this.progressListener = new NoopProgressListener(); } @Override @@ -67,7 +69,7 @@ public class ContributionsSelfCheck extends TimerTask { private void updateLibrariesIndex() { try { - libraryInstaller.updateIndex(); + libraryInstaller.updateIndex(progressListener); } catch (Exception e) { // ignore } @@ -75,7 +77,7 @@ public class ContributionsSelfCheck extends TimerTask { private void updateContributionIndex() { try { - contributionInstaller.updateIndex(); + contributionInstaller.updateIndex(progressListener); } catch (Exception e) { // ignore } diff --git a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java index 921980310..6bb146037 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java @@ -183,12 +183,7 @@ public class LibraryManagerUI extends InstallerJDialog { filterField.setEnabled(contribModel.getRowCount() > 0); // Create LibrariesInstaller tied with the provided index - installer = new LibraryInstaller(indexer, platform) { - @Override - public void onProgress(Progress progress) { - setProgress(progress); - } - }; + installer = new LibraryInstaller(indexer, platform); } public void selectDropdownItemByClassName(String dropdownItem) { @@ -216,7 +211,7 @@ public class LibraryManagerUI extends InstallerJDialog { installerThread = new Thread(() -> { try { setProgressVisible(true, ""); - installer.updateIndex(); + installer.updateIndex(this::setProgress); onIndexesUpdated(); } catch (Exception e) { throw new RuntimeException(e); @@ -233,7 +228,7 @@ public class LibraryManagerUI extends InstallerJDialog { installerThread = new Thread(() -> { try { setProgressVisible(true, tr("Installing...")); - installer.install(lib, replaced); + installer.install(lib, replaced, this::setProgress); onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element //getContribModel().updateLibrary(lib); } catch (Exception e) { @@ -260,7 +255,7 @@ public class LibraryManagerUI extends InstallerJDialog { installerThread = new Thread(() -> { try { setProgressVisible(true, tr("Removing...")); - installer.remove(lib); + installer.remove(lib, this::setProgress); onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element //getContribModel().updateLibrary(lib); } catch (Exception e) { diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java index fcf1bd775..6ec32a406 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java @@ -118,7 +118,7 @@ public class ContributionManagerUI extends InstallerJDialog { } // Create ConstributionInstaller tied with the provided index - installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier(), this::setProgress); + installer = new ContributionInstaller(indexer, platform, new GPGDetachedSignatureVerifier()); } public void setProgress(Progress progress) { @@ -146,7 +146,7 @@ public class ContributionManagerUI extends InstallerJDialog { installerThread = new Thread(() -> { try { setProgressVisible(true, ""); - List downloadedPackageIndexFiles = installer.updateIndex(); + List downloadedPackageIndexFiles = installer.updateIndex(this::setProgress); installer.deleteUnknownFiles(downloadedPackageIndexFiles); onIndexesUpdated(); } catch (Exception e) { @@ -165,7 +165,7 @@ public class ContributionManagerUI extends InstallerJDialog { List errors = new LinkedList<>(); try { setProgressVisible(true, tr("Installing...")); - errors.addAll(installer.install(platformToInstall)); + errors.addAll(installer.install(platformToInstall, this::setProgress)); if (platformToRemove != null && !platformToRemove.isReadOnly()) { errors.addAll(installer.remove(platformToRemove)); } diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index b8d14a849..fa5573b18 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -33,7 +33,6 @@ import cc.arduino.contributions.packages.ContributionsIndexer; import cc.arduino.contributions.packages.ui.ContributionManagerUI; import cc.arduino.files.DeleteFilesOnShutdown; import cc.arduino.packages.DiscoveryManager; -import cc.arduino.utils.Progress; import cc.arduino.view.Event; import cc.arduino.view.JMenuUtils; import cc.arduino.view.SplashScreenHelper; @@ -341,19 +340,10 @@ 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(), new ProgressListener() { - private String lastStatus = ""; + ProgressListener progressListener = new ConsoleProgressListener(); + ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier()); - @Override - public void onProgress(Progress progress) { - if (!lastStatus.equals(progress.getStatus())) { - System.out.println(progress.getStatus()); - } - lastStatus = progress.getStatus(); - } - }); - - List downloadedPackageIndexFiles = installer.updateIndex(); + List downloadedPackageIndexFiles = installer.updateIndex(progressListener); installer.deleteUnknownFiles(downloadedPackageIndexFiles); indexer.parseIndex(); indexer.syncWithFilesystem(BaseNoGui.getHardwareFolder()); @@ -378,7 +368,7 @@ public class Base { ContributedPlatform installed = indexer.getInstalled(boardToInstallParts[0], boardToInstallParts[1]); if (!selected.isReadOnly()) { - installer.install(selected); + installer.install(selected, progressListener); } if (installed != null && !installed.isReadOnly()) { @@ -389,22 +379,13 @@ public class Base { } else if (parser.isInstallLibrary()) { LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier())); - LibraryInstaller installer = new LibraryInstaller(indexer, BaseNoGui.getPlatform()) { - private String lastStatus = ""; - - @Override - protected void onProgress(Progress progress) { - if (!lastStatus.equals(progress.getStatus())) { - System.out.println(progress.getStatus()); - } - lastStatus = progress.getStatus(); - } - }; + ProgressListener progressListener = new ConsoleProgressListener(); + LibraryInstaller installer = new LibraryInstaller(indexer, BaseNoGui.getPlatform()); indexer.parseIndex(); BaseNoGui.onBoardOrPortChange(); indexer.setSketchbookLibrariesFolder(BaseNoGui.getSketchbookLibrariesFolder()); indexer.setLibrariesFolders(BaseNoGui.getLibrariesPath()); - installer.updateIndex(); + installer.updateIndex(progressListener); for (String library : parser.getLibraryToInstall().split(",")) { String[] libraryToInstallParts = library.split(":"); @@ -426,9 +407,9 @@ public class Base { ContributedLibrary installed = indexer.getIndex().getInstalled(libraryToInstallParts[0]); if (selected.isReadOnly()) { - installer.remove(installed); + installer.remove(installed, progressListener); } else { - installer.install(selected, installed); + installer.install(selected, installed, progressListener); } } diff --git a/app/test/cc/arduino/contributions/GzippedJsonDownloaderTest.java b/app/test/cc/arduino/contributions/GzippedJsonDownloaderTest.java index a762b6801..e1e231acd 100644 --- a/app/test/cc/arduino/contributions/GzippedJsonDownloaderTest.java +++ b/app/test/cc/arduino/contributions/GzippedJsonDownloaderTest.java @@ -38,7 +38,7 @@ public class GzippedJsonDownloaderTest { @Test public void testJsonDownload() throws Exception { - new GZippedJsonDownloader(downloader, new URL("http://downloads.arduino.cc/libraries/library_index.json"), new URL("http://downloads.arduino.cc/libraries/library_index.json.gz")).download(tempFile, new MultiStepProgress(1), ""); + new GZippedJsonDownloader(downloader, new URL("http://downloads.arduino.cc/libraries/library_index.json"), new URL("http://downloads.arduino.cc/libraries/library_index.json.gz")).download(tempFile, new MultiStepProgress(1), "", new NoopProgressListener()); InputStream indexIn = new FileInputStream(tempFile); ObjectMapper mapper = new ObjectMapper(); diff --git a/app/test/cc/arduino/contributions/JsonDownloaderTest.java b/app/test/cc/arduino/contributions/JsonDownloaderTest.java index 98cefef49..ebf3c0913 100644 --- a/app/test/cc/arduino/contributions/JsonDownloaderTest.java +++ b/app/test/cc/arduino/contributions/JsonDownloaderTest.java @@ -38,7 +38,7 @@ public class JsonDownloaderTest { @Test public void testJsonDownload() throws Exception { - new JsonDownloader(downloader, new URL("http://downloads.arduino.cc/libraries/library_index.json")).download(tempFile, new MultiStepProgress(1), ""); + new JsonDownloader(downloader, new URL("http://downloads.arduino.cc/libraries/library_index.json")).download(tempFile, new MultiStepProgress(1), "", new NoopProgressListener()); InputStream indexIn = new FileInputStream(tempFile); ObjectMapper mapper = new ObjectMapper(); diff --git a/arduino-core/src/cc/arduino/contributions/ConsoleProgressListener.java b/arduino-core/src/cc/arduino/contributions/ConsoleProgressListener.java new file mode 100644 index 000000000..c45299484 --- /dev/null +++ b/arduino-core/src/cc/arduino/contributions/ConsoleProgressListener.java @@ -0,0 +1,15 @@ +package cc.arduino.contributions; + +import cc.arduino.utils.Progress; + +public class ConsoleProgressListener implements ProgressListener { + private String lastStatus = ""; + + @Override + public void onProgress(Progress progress) { + if (!lastStatus.equals(progress.getStatus())) { + System.out.println(progress.getStatus()); + } + lastStatus = progress.getStatus(); + } +} diff --git a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java index 5b6309285..8bbcbc227 100644 --- a/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/DownloadableContributionsDownloader.java @@ -51,7 +51,7 @@ public class DownloadableContributionsDownloader { stagingFolder = _stagingFolder; } - public File download(DownloadableContribution contribution, Progress progress, final String statusText) throws Exception { + public File download(DownloadableContribution contribution, Progress progress, final String statusText, ProgressListener progressListener) throws Exception { URL url = new URL(contribution.getUrl()); Path outputFile = Paths.get(stagingFolder.getAbsolutePath(), contribution.getArchiveFileName()); @@ -64,12 +64,12 @@ public class DownloadableContributionsDownloader { // Need to download or resume downloading? if (!Files.isRegularFile(outputFile, LinkOption.NOFOLLOW_LINKS) || (Files.size(outputFile) < contribution.getSize())) { - download(url, outputFile.toFile(), progress, statusText); + download(url, outputFile.toFile(), progress, statusText, progressListener); } // Test checksum progress.setStatus(tr("Verifying archive integrity...")); - onProgress(progress); + progressListener.onProgress(progress); String checksum = contribution.getChecksum(); if (hasChecksum(contribution)) { String algo = checksum.split(":")[0]; @@ -94,7 +94,7 @@ public class DownloadableContributionsDownloader { return algo != null && !algo.isEmpty(); } - public void download(URL url, File tmpFile, Progress progress, String statusText) throws Exception { + public void download(URL url, File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception { FileDownloader downloader = new FileDownloader(url, tmpFile); downloader.addObserver((o, arg) -> { FileDownloader me = (FileDownloader) o; @@ -106,7 +106,7 @@ public class DownloadableContributionsDownloader { } progress.setStatus(statusText + " " + msg); progress.setProgress(me.getProgress()); - onProgress(progress); + progressListener.onProgress(progress); }); downloader.download(); if (!downloader.isCompleted()) { @@ -114,8 +114,4 @@ public class DownloadableContributionsDownloader { } } - protected void onProgress(Progress progress) { - // Empty - } - } diff --git a/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java b/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java index b4994d8d7..df7eee420 100644 --- a/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/GZippedJsonDownloader.java @@ -49,14 +49,14 @@ public class GZippedJsonDownloader { this.gzippedUrl = gzippedUrl; } - public void download(File tmpFile, Progress progress, String statusText) throws Exception { + public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception { try { - new JsonDownloader(downloader, gzippedUrl).download(tmpFile, progress, statusText); + new JsonDownloader(downloader, gzippedUrl).download(tmpFile, progress, statusText, progressListener); File gzipTmpFile = new File(tmpFile.getParentFile(), GzipUtils.getCompressedFilename(tmpFile.getName())); tmpFile.renameTo(gzipTmpFile); decompress(gzipTmpFile, tmpFile); } catch (Exception e) { - new JsonDownloader(downloader, url).download(tmpFile, progress, statusText); + new JsonDownloader(downloader, url).download(tmpFile, progress, statusText, progressListener); } } diff --git a/arduino-core/src/cc/arduino/contributions/JsonDownloader.java b/arduino-core/src/cc/arduino/contributions/JsonDownloader.java index da01ff95b..88f9e7783 100644 --- a/arduino-core/src/cc/arduino/contributions/JsonDownloader.java +++ b/arduino-core/src/cc/arduino/contributions/JsonDownloader.java @@ -44,9 +44,9 @@ public class JsonDownloader { this.url = url; } - public void download(File tmpFile, Progress progress, String statusText) throws Exception { + public void download(File tmpFile, Progress progress, String statusText, ProgressListener progressListener) throws Exception { try { - downloader.download(url, tmpFile, progress, statusText); + downloader.download(url, tmpFile, progress, statusText, progressListener); } catch (InterruptedException e) { // Download interrupted... just exit } diff --git a/arduino-core/src/cc/arduino/contributions/NoopProgressListener.java b/arduino-core/src/cc/arduino/contributions/NoopProgressListener.java new file mode 100644 index 000000000..68649ecda --- /dev/null +++ b/arduino-core/src/cc/arduino/contributions/NoopProgressListener.java @@ -0,0 +1,12 @@ +package cc.arduino.contributions; + +import cc.arduino.utils.Progress; + +public class NoopProgressListener implements ProgressListener { + + @Override + public void onProgress(Progress progress) { + + } + +} diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java index c2afad7dc..48c1fc4a2 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java @@ -31,9 +31,9 @@ package cc.arduino.contributions.libraries; import cc.arduino.contributions.DownloadableContributionsDownloader; import cc.arduino.contributions.GZippedJsonDownloader; +import cc.arduino.contributions.ProgressListener; import cc.arduino.utils.ArchiveExtractor; import cc.arduino.utils.MultiStepProgress; -import cc.arduino.utils.Progress; import processing.app.I18n; import processing.app.Platform; import processing.app.helpers.FileUtils; @@ -67,15 +67,10 @@ public class LibraryInstaller { this.indexer = indexer; this.platform = platform; File stagingFolder = indexer.getStagingFolder(); - downloader = new DownloadableContributionsDownloader(stagingFolder) { - @Override - protected void onProgress(Progress progress) { - LibraryInstaller.this.onProgress(progress); - } - }; + downloader = new DownloadableContributionsDownloader(stagingFolder); } - public void updateIndex() throws Exception { + public void updateIndex(ProgressListener progressListener) throws Exception { final MultiStepProgress progress = new MultiStepProgress(2); // Step 1: Download index @@ -83,7 +78,7 @@ public class LibraryInstaller { File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp"); try { GZippedJsonDownloader gZippedJsonDownloader = new GZippedJsonDownloader(downloader, new URL(LIBRARY_INDEX_URL), new URL(LIBRARY_INDEX_URL_GZ)); - gZippedJsonDownloader.download(tmpFile, progress, tr("Downloading libraries index...")); + gZippedJsonDownloader.download(tmpFile, progress, tr("Downloading libraries index..."), progressListener); } catch (InterruptedException e) { // Download interrupted... just exit return; @@ -99,10 +94,10 @@ public class LibraryInstaller { throw new Exception(tr("An error occurred while updating libraries index!")); // Step 2: Rescan index - rescanLibraryIndex(progress); + rescanLibraryIndex(progress, progressListener); } - public void install(ContributedLibrary lib, ContributedLibrary replacedLib) throws Exception { + public void install(ContributedLibrary lib, ContributedLibrary replacedLib, ProgressListener progressListener) throws Exception { if (lib.isInstalled()) { System.out.println(I18n.format(tr("Library is already installed: {0} version {1}"), lib.getName(), lib.getParsedVersion())); return; @@ -112,7 +107,7 @@ public class LibraryInstaller { // Step 1: Download library try { - downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName())); + downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener); } catch (InterruptedException e) { // Download interrupted... just exit return; @@ -124,7 +119,7 @@ public class LibraryInstaller { // Step 2: Unpack library on the correct location progress.setStatus(I18n.format(tr("Installing library: {0}"), lib.getName())); - onProgress(progress); + progressListener.onProgress(progress); File libsFolder = indexer.getSketchbookLibrariesFolder(); File tmpFolder = FileUtils.createTempFolderIn(libsFolder); try { @@ -137,16 +132,16 @@ public class LibraryInstaller { // Step 3: Remove replaced library and move installed one to the correct location // TODO: Fix progress bar... - remove(replacedLib); + remove(replacedLib, progressListener); File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_")); tmpFolder.renameTo(destFolder); progress.stepDone(); // Step 4: Rescan index - rescanLibraryIndex(progress); + rescanLibraryIndex(progress, progressListener); } - public void remove(ContributedLibrary lib) throws IOException { + public void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException { if (lib == null || lib.isReadOnly()) { return; } @@ -155,22 +150,18 @@ public class LibraryInstaller { // Step 1: Remove library progress.setStatus(I18n.format(tr("Removing library: {0}"), lib.getName())); - onProgress(progress); + progressListener.onProgress(progress); FileUtils.recursiveDelete(lib.getInstalledFolder()); progress.stepDone(); // Step 2: Rescan index - rescanLibraryIndex(progress); + rescanLibraryIndex(progress, progressListener); } - private void rescanLibraryIndex(MultiStepProgress progress) { + private void rescanLibraryIndex(MultiStepProgress progress, ProgressListener progressListener) { progress.setStatus(tr("Updating list of installed libraries")); - onProgress(progress); + progressListener.onProgress(progress); indexer.rescanLibraries(); progress.stepDone(); } - - protected void onProgress(Progress progress) { - // Empty - } } diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java index 8a66b1073..72622022b 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java @@ -37,7 +37,6 @@ import cc.arduino.contributions.SignatureVerifier; import cc.arduino.filters.FileExecutablePredicate; import cc.arduino.utils.ArchiveExtractor; import cc.arduino.utils.MultiStepProgress; -import cc.arduino.utils.Progress; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.Executor; @@ -65,28 +64,16 @@ 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) { - progressListener.onProgress(progress); - } - }; + downloader = new DownloadableContributionsDownloader(stagingFolder); } - public List install(ContributedPlatform contributedPlatform) throws Exception { + public List install(ContributedPlatform contributedPlatform, ProgressListener progressListener) throws Exception { List errors = new LinkedList<>(); if (contributedPlatform.isInstalled()) { throw new Exception("Platform is already installed!"); @@ -112,7 +99,7 @@ public class ContributionInstaller { // Download all try { // Download platform - downloader.download(contributedPlatform, progress, tr("Downloading boards definitions.")); + downloader.download(contributedPlatform, progress, tr("Downloading boards definitions."), progressListener); progress.stepDone(); // Download tools @@ -120,7 +107,7 @@ public class ContributionInstaller { for (ContributedTool tool : tools) { String msg = format(tr("Downloading tools ({0}/{1})."), i, tools.size()); i++; - downloader.download(tool.getDownloadableContribution(platform), progress, msg); + downloader.download(tool.getDownloadableContribution(platform), progress, msg, progressListener); progress.stepDone(); } } catch (InterruptedException e) { @@ -282,11 +269,11 @@ public class ContributionInstaller { return errors; } - public List updateIndex() throws Exception { + public List updateIndex(ProgressListener progressListener) throws Exception { MultiStepProgress progress = new MultiStepProgress(1); List downloadedPackageIndexFilesAccumulator = new LinkedList<>(); - downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, Constants.PACKAGE_INDEX_URL); + downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, Constants.PACKAGE_INDEX_URL, progressListener); Set packageIndexURLs = new HashSet<>(); String additionalURLs = PreferencesData.get(Constants.PREF_BOARDS_MANAGER_ADDITIONAL_URLS, ""); @@ -295,7 +282,7 @@ public class ContributionInstaller { } for (String packageIndexURL : packageIndexURLs) { - downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, packageIndexURL); + downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, packageIndexURL, progressListener); } progress.stepDone(); @@ -303,11 +290,11 @@ public class ContributionInstaller { return downloadedPackageIndexFilesAccumulator; } - private void downloadIndexAndSignature(MultiStepProgress progress, List downloadedPackagedIndexFilesAccumulator, String packageIndexUrl) throws Exception { - File packageIndex = download(progress, packageIndexUrl); + private void downloadIndexAndSignature(MultiStepProgress progress, List downloadedPackagedIndexFilesAccumulator, String packageIndexUrl, ProgressListener progressListener) throws Exception { + File packageIndex = download(progress, packageIndexUrl, progressListener); downloadedPackagedIndexFilesAccumulator.add(packageIndex.getName()); try { - File packageIndexSignature = download(progress, packageIndexUrl + ".sig"); + File packageIndexSignature = download(progress, packageIndexUrl + ".sig", progressListener); boolean signatureVerified = signatureVerifier.isSigned(packageIndex); if (signatureVerified) { downloadedPackagedIndexFilesAccumulator.add(packageIndexSignature.getName()); @@ -322,13 +309,13 @@ public class ContributionInstaller { } } - private File download(MultiStepProgress progress, String packageIndexUrl) throws Exception { + private File download(MultiStepProgress progress, String packageIndexUrl, ProgressListener progressListener) throws Exception { String statusText = tr("Downloading platforms index..."); URL url = new URL(packageIndexUrl); String[] urlPathParts = url.getFile().split("/"); File outputFile = indexer.getIndexFile(urlPathParts[urlPathParts.length - 1]); File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp"); - downloader.download(url, tmpFile, progress, statusText); + downloader.download(url, tmpFile, progress, statusText, progressListener); Files.deleteIfExists(outputFile.toPath()); Files.move(tmpFile.toPath(), outputFile.toPath());