mirror of https://github.com/noisymime/Arduino.git
ContributedPlatform.getResolvedTools returns a copy of the original list (otherwise violating inner state)
This commit is contained in:
parent
6007403834
commit
589f514a47
|
@ -28,10 +28,6 @@
|
||||||
*/
|
*/
|
||||||
package cc.arduino.packages.contributions.ui;
|
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.ContributedPlatform;
|
||||||
import cc.arduino.packages.contributions.ContributionInstaller;
|
import cc.arduino.packages.contributions.ContributionInstaller;
|
||||||
import cc.arduino.packages.contributions.ContributionsIndexer;
|
import cc.arduino.packages.contributions.ContributionsIndexer;
|
||||||
|
@ -40,6 +36,9 @@ import cc.arduino.ui.InstallerJDialog;
|
||||||
import cc.arduino.ui.InstallerTableCell;
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
import cc.arduino.utils.Progress;
|
import cc.arduino.utils.Progress;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributionManagerUI extends InstallerJDialog {
|
public class ContributionManagerUI extends InstallerJDialog {
|
||||||
|
|
||||||
|
@ -122,8 +121,9 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelPressed() {
|
public void onCancelPressed() {
|
||||||
if (installerThread != null)
|
if (installerThread != null) {
|
||||||
installerThread.interrupt();
|
installerThread.interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,6 +142,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
|
||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +163,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
|
||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,12 +181,13 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
installerThread.setUncaughtExceptionHandler(new ContributionUncaughtExceptionHandler(this));
|
||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback invoked when indexes are updated
|
* Callback invoked when indexes are updated
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected void onIndexesUpdated() throws Exception {
|
protected void onIndexesUpdated() throws Exception {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package processing.app;
|
package cc.arduino;
|
||||||
|
|
||||||
public class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
public class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
System.out.println(t);
|
System.err.println(t);
|
||||||
System.out.println(e);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,6 +30,7 @@ package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ContributedPlatform extends DownloadableContribution {
|
public abstract class ContributedPlatform extends DownloadableContribution {
|
||||||
|
@ -53,7 +54,10 @@ public abstract class ContributedPlatform extends DownloadableContribution {
|
||||||
private ContributedPackage parentPackage;
|
private ContributedPackage parentPackage;
|
||||||
|
|
||||||
public List<ContributedTool> getResolvedTools() {
|
public List<ContributedTool> getResolvedTools() {
|
||||||
return resolvedTools;
|
if (resolvedTools == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new LinkedList<ContributedTool>(resolvedTools);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ContributedTool> resolveToolsDependencies(Collection<ContributedPackage> packages) {
|
public List<ContributedTool> resolveToolsDependencies(Collection<ContributedPackage> packages) {
|
||||||
|
@ -68,8 +72,7 @@ public abstract class ContributedPlatform extends DownloadableContribution {
|
||||||
// Search the referenced tool
|
// Search the referenced tool
|
||||||
ContributedTool tool = dep.resolve(packages);
|
ContributedTool tool = dep.resolve(packages);
|
||||||
if (tool == null) {
|
if (tool == null) {
|
||||||
System.err
|
System.err.println("Index error: could not find referenced tool " + dep);
|
||||||
.println("Index error: could not find referenced tool " + dep);
|
|
||||||
}
|
}
|
||||||
resolvedTools.add(tool);
|
resolvedTools.add(tool);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,10 @@
|
||||||
*/
|
*/
|
||||||
package cc.arduino.packages.contributions;
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import cc.arduino.utils.ArchiveExtractor;
|
||||||
import static processing.app.I18n.format;
|
import cc.arduino.utils.MultiStepProgress;
|
||||||
|
import cc.arduino.utils.Progress;
|
||||||
|
import processing.app.helpers.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -37,10 +39,8 @@ import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import processing.app.helpers.FileUtils;
|
import static processing.app.I18n._;
|
||||||
import cc.arduino.utils.ArchiveExtractor;
|
import static processing.app.I18n.format;
|
||||||
import cc.arduino.utils.MultiStepProgress;
|
|
||||||
import cc.arduino.utils.Progress;
|
|
||||||
|
|
||||||
public class ContributionInstaller {
|
public class ContributionInstaller {
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class ContributionInstaller {
|
||||||
@Override
|
@Override
|
||||||
protected void onProgress(Progress progress) {
|
protected void onProgress(Progress progress) {
|
||||||
ContributionInstaller.this.onProgress(progress);
|
ContributionInstaller.this.onProgress(progress);
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +84,7 @@ public class ContributionInstaller {
|
||||||
// Download all
|
// Download all
|
||||||
try {
|
try {
|
||||||
// Download platform
|
// Download platform
|
||||||
downloader.download(platform, progress,
|
downloader.download(platform, progress, _("Downloading boards definitions."));
|
||||||
_("Downloading boards definitions."));
|
|
||||||
progress.stepDone();
|
progress.stepDone();
|
||||||
|
|
||||||
// Download tools
|
// Download tools
|
||||||
|
@ -111,7 +110,7 @@ public class ContributionInstaller {
|
||||||
// Unzip tools on the correct location
|
// Unzip tools on the correct location
|
||||||
File toolsFolder = new File(packageFolder, "tools");
|
File toolsFolder = new File(packageFolder, "tools");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (ContributedTool tool : platform.getResolvedTools()) {
|
for (ContributedTool tool : tools) {
|
||||||
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size()));
|
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size()));
|
||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
i++;
|
i++;
|
||||||
|
@ -119,6 +118,7 @@ public class ContributionInstaller {
|
||||||
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
|
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
|
||||||
|
|
||||||
destFolder.mkdirs();
|
destFolder.mkdirs();
|
||||||
|
assert toolContrib.getDownloadedFile() != null;
|
||||||
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
||||||
toolContrib.setInstalled(true);
|
toolContrib.setInstalled(true);
|
||||||
toolContrib.setInstalledFolder(destFolder);
|
toolContrib.setInstalledFolder(destFolder);
|
||||||
|
@ -147,8 +147,9 @@ public class ContributionInstaller {
|
||||||
|
|
||||||
// Check if the tools are no longer needed
|
// Check if the tools are no longer needed
|
||||||
for (ContributedTool tool : platform.getResolvedTools()) {
|
for (ContributedTool tool : platform.getResolvedTools()) {
|
||||||
if (indexer.isContributedToolUsed(tool))
|
if (indexer.isContributedToolUsed(tool)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
DownloadableContribution toolContrib = tool.getDownloadableContribution();
|
DownloadableContribution toolContrib = tool.getDownloadableContribution();
|
||||||
File destFolder = toolContrib.getInstalledFolder();
|
File destFolder = toolContrib.getInstalledFolder();
|
||||||
|
|
|
@ -28,17 +28,17 @@
|
||||||
*/
|
*/
|
||||||
package cc.arduino.packages.contributions;
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import cc.arduino.utils.FileHash;
|
||||||
import static processing.app.I18n.format;
|
import cc.arduino.utils.Progress;
|
||||||
|
import cc.arduino.utils.network.FileDownloader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
import cc.arduino.utils.FileHash;
|
import static processing.app.I18n._;
|
||||||
import cc.arduino.utils.Progress;
|
import static processing.app.I18n.format;
|
||||||
import cc.arduino.utils.network.FileDownloader;
|
|
||||||
|
|
||||||
public class DownloadableContributionsDownloader {
|
public class DownloadableContributionsDownloader {
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class DownloadableContributionsDownloader {
|
||||||
|
|
||||||
public File download(DownloadableContribution contribution,
|
public File download(DownloadableContribution contribution,
|
||||||
final Progress progress, final String statusText)
|
final Progress progress, final String statusText)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
URL url = new URL(contribution.getUrl());
|
URL url = new URL(contribution.getUrl());
|
||||||
final File outputFile = new File(stagingFolder, contribution.getArchiveFileName());
|
final File outputFile = new File(stagingFolder, contribution.getArchiveFileName());
|
||||||
|
|
||||||
|
@ -67,8 +67,9 @@ public class DownloadableContributionsDownloader {
|
||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
String checksum = contribution.getChecksum();
|
String checksum = contribution.getChecksum();
|
||||||
String algo = checksum.split(":")[0];
|
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."));
|
throw new Exception(_("CRC doesn't match. File is corrupted."));
|
||||||
|
}
|
||||||
|
|
||||||
contribution.setDownloaded(true);
|
contribution.setDownloaded(true);
|
||||||
contribution.setDownloadedFile(outputFile);
|
contribution.setDownloadedFile(outputFile);
|
||||||
|
@ -94,9 +95,9 @@ public class DownloadableContributionsDownloader {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
downloader.download();
|
downloader.download();
|
||||||
if (!downloader.isCompleted())
|
if (!downloader.isCompleted()) {
|
||||||
throw new Exception(format(_("Error dowloading {0}"), url),
|
throw new Exception(format(_("Error dowloading {0}"), url), downloader.getError());
|
||||||
downloader.getError());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onProgress(Progress progress) {
|
protected void onProgress(Progress progress) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import cc.arduino.DefaultUncaughtExceptionHandler;
|
||||||
import org.apache.commons.logging.impl.LogFactoryImpl;
|
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||||
import org.apache.commons.logging.impl.NoOpLog;
|
import org.apache.commons.logging.impl.NoOpLog;
|
||||||
|
|
||||||
|
@ -712,6 +713,8 @@ public class BaseNoGui {
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||||
|
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
|
||||||
|
|
||||||
initPlatform();
|
initPlatform();
|
||||||
|
|
||||||
initPortableFolder();
|
initPortableFolder();
|
||||||
|
@ -719,8 +722,6 @@ public class BaseNoGui {
|
||||||
initParameters(args);
|
initParameters(args);
|
||||||
|
|
||||||
init(args);
|
init(args);
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void onBoardOrPortChange() {
|
static public void onBoardOrPortChange() {
|
||||||
|
|
Loading…
Reference in New Issue