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