ContributedPlatform.getResolvedTools returns a copy of the original list (otherwise violating inner state)

This commit is contained in:
Federico Fissore 2015-02-23 15:57:32 +01:00
parent 6007403834
commit 589f514a47
7 changed files with 66 additions and 35 deletions

View File

@ -28,10 +28,6 @@
*/
package cc.arduino.packages.contributions.ui;
import java.awt.Dialog;
import java.awt.Frame;
import java.util.Collection;
import cc.arduino.packages.contributions.ContributedPlatform;
import cc.arduino.packages.contributions.ContributionInstaller;
import cc.arduino.packages.contributions.ContributionsIndexer;
@ -40,6 +36,9 @@ import cc.arduino.ui.InstallerJDialog;
import cc.arduino.ui.InstallerTableCell;
import cc.arduino.utils.Progress;
import java.awt.*;
import java.util.Collection;
@SuppressWarnings("serial")
public class ContributionManagerUI extends InstallerJDialog {
@ -122,8 +121,9 @@ public class ContributionManagerUI extends InstallerJDialog {
@Override
public void onCancelPressed() {
if (installerThread != null)
if (installerThread != null) {
installerThread.interrupt();
}
}
@Override
@ -142,6 +142,7 @@ public class ContributionManagerUI extends InstallerJDialog {
}
}
});
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
installerThread.start();
}
@ -162,6 +163,7 @@ public class ContributionManagerUI extends InstallerJDialog {
}
}
});
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
installerThread.start();
}
@ -179,12 +181,13 @@ public class ContributionManagerUI extends InstallerJDialog {
}
}
});
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
installerThread.start();
}
/**
* Callback invoked when indexes are updated
*
*
* @throws Exception
*/
protected void onIndexesUpdated() throws Exception {

View File

@ -0,0 +1,22 @@
package cc.arduino.packages.contributions.ui;
import javax.swing.*;
import java.awt.*;
import static processing.app.I18n._;
public class ContributionUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private final Component parent;
public ContributionUncaughtExceptionHandler(Component parent) {
this.parent = parent;
}
@Override
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace();
JOptionPane.showMessageDialog(parent, _(e.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
}
}

View File

@ -1,11 +1,11 @@
package processing.app;
package cc.arduino;
public class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println(t);
System.out.println(e);
System.err.println(t);
e.printStackTrace();
}
}

View File

@ -30,6 +30,7 @@ package cc.arduino.packages.contributions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public abstract class ContributedPlatform extends DownloadableContribution {
@ -53,7 +54,10 @@ public abstract class ContributedPlatform extends DownloadableContribution {
private ContributedPackage parentPackage;
public List<ContributedTool> getResolvedTools() {
return resolvedTools;
if (resolvedTools == null) {
return null;
}
return new LinkedList<ContributedTool>(resolvedTools);
}
public List<ContributedTool> resolveToolsDependencies(Collection<ContributedPackage> packages) {
@ -68,8 +72,7 @@ public abstract class ContributedPlatform extends DownloadableContribution {
// Search the referenced tool
ContributedTool tool = dep.resolve(packages);
if (tool == null) {
System.err
.println("Index error: could not find referenced tool " + dep);
System.err.println("Index error: could not find referenced tool " + dep);
}
resolvedTools.add(tool);
}

View File

@ -28,8 +28,10 @@
*/
package cc.arduino.packages.contributions;
import static processing.app.I18n._;
import static processing.app.I18n.format;
import cc.arduino.utils.ArchiveExtractor;
import cc.arduino.utils.MultiStepProgress;
import cc.arduino.utils.Progress;
import processing.app.helpers.FileUtils;
import java.io.File;
import java.net.URL;
@ -37,10 +39,8 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import processing.app.helpers.FileUtils;
import cc.arduino.utils.ArchiveExtractor;
import cc.arduino.utils.MultiStepProgress;
import cc.arduino.utils.Progress;
import static processing.app.I18n._;
import static processing.app.I18n.format;
public class ContributionInstaller {
@ -55,7 +55,7 @@ public class ContributionInstaller {
@Override
protected void onProgress(Progress progress) {
ContributionInstaller.this.onProgress(progress);
};
}
};
}
@ -84,8 +84,7 @@ public class ContributionInstaller {
// Download all
try {
// Download platform
downloader.download(platform, progress,
_("Downloading boards definitions."));
downloader.download(platform, progress, _("Downloading boards definitions."));
progress.stepDone();
// Download tools
@ -111,7 +110,7 @@ public class ContributionInstaller {
// Unzip tools on the correct location
File toolsFolder = new File(packageFolder, "tools");
int i = 1;
for (ContributedTool tool : platform.getResolvedTools()) {
for (ContributedTool tool : tools) {
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size()));
onProgress(progress);
i++;
@ -119,6 +118,7 @@ public class ContributionInstaller {
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
destFolder.mkdirs();
assert toolContrib.getDownloadedFile() != null;
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
toolContrib.setInstalled(true);
toolContrib.setInstalledFolder(destFolder);
@ -147,8 +147,9 @@ public class ContributionInstaller {
// Check if the tools are no longer needed
for (ContributedTool tool : platform.getResolvedTools()) {
if (indexer.isContributedToolUsed(tool))
if (indexer.isContributedToolUsed(tool)) {
continue;
}
DownloadableContribution toolContrib = tool.getDownloadableContribution();
File destFolder = toolContrib.getInstalledFolder();

View File

@ -28,17 +28,17 @@
*/
package cc.arduino.packages.contributions;
import static processing.app.I18n._;
import static processing.app.I18n.format;
import cc.arduino.utils.FileHash;
import cc.arduino.utils.Progress;
import cc.arduino.utils.network.FileDownloader;
import java.io.File;
import java.net.URL;
import java.util.Observable;
import java.util.Observer;
import cc.arduino.utils.FileHash;
import cc.arduino.utils.Progress;
import cc.arduino.utils.network.FileDownloader;
import static processing.app.I18n._;
import static processing.app.I18n.format;
public class DownloadableContributionsDownloader {
@ -50,7 +50,7 @@ public class DownloadableContributionsDownloader {
public File download(DownloadableContribution contribution,
final Progress progress, final String statusText)
throws Exception {
throws Exception {
URL url = new URL(contribution.getUrl());
final File outputFile = new File(stagingFolder, contribution.getArchiveFileName());
@ -67,8 +67,9 @@ public class DownloadableContributionsDownloader {
onProgress(progress);
String checksum = contribution.getChecksum();
String algo = checksum.split(":")[0];
if (!FileHash.hash(outputFile, algo).equals(checksum))
if (!FileHash.hash(outputFile, algo).equals(checksum)) {
throw new Exception(_("CRC doesn't match. File is corrupted."));
}
contribution.setDownloaded(true);
contribution.setDownloadedFile(outputFile);
@ -94,9 +95,9 @@ public class DownloadableContributionsDownloader {
}
});
downloader.download();
if (!downloader.isCompleted())
throw new Exception(format(_("Error dowloading {0}"), url),
downloader.getError());
if (!downloader.isCompleted()) {
throw new Exception(format(_("Error dowloading {0}"), url), downloader.getError());
}
}
protected void onProgress(Progress progress) {

View File

@ -13,6 +13,7 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import cc.arduino.DefaultUncaughtExceptionHandler;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.commons.logging.impl.NoOpLog;
@ -712,6 +713,8 @@ public class BaseNoGui {
if (args.length == 0)
showError(_("No parameters"), _("No command line parameters found"), null);
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
initPlatform();
initPortableFolder();
@ -719,8 +722,6 @@ public class BaseNoGui {
initParameters(args);
init(args);
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
}
static public void onBoardOrPortChange() {