mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Removed some printStackTrace in favour of throwing RuntimeExceptions. DefaultUncoughtExceptionHandler will handle them
This commit is contained in:
parent
fe6718ce4f
commit
6007403834
@ -166,8 +166,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
return getUpdatedCellComponent(value, true, row);
|
||||
}
|
||||
|
||||
private Component getUpdatedCellComponent(Object value, boolean isSelected,
|
||||
int row) {
|
||||
private Component getUpdatedCellComponent(Object value, boolean isSelected, int row) {
|
||||
ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
|
||||
ContributedLibrary selectedLib = releases.getSelected();
|
||||
ContributedLibrary installedLib = releases.getInstalled();
|
||||
@ -245,26 +244,25 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
description.setText(desc);
|
||||
description.setBackground(Color.WHITE);
|
||||
|
||||
// for modelToView to work, the text area has to be sized. It doesn't
|
||||
// matter if it's visible or not.
|
||||
|
||||
// See:
|
||||
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
|
||||
int width = parentTable.getBounds().width;
|
||||
width -= installButtonPlaceholder.getPreferredSize().width;
|
||||
width -= removeButtonPlaceholder.getPreferredSize().width;
|
||||
Dimension minimalSize = new Dimension(width, 10);
|
||||
description.setPreferredSize(minimalSize);
|
||||
description.setSize(minimalSize);
|
||||
|
||||
try {
|
||||
// for modelToView to work, the text area has to be sized. It doesn't
|
||||
// matter if it's visible or not.
|
||||
|
||||
// See:
|
||||
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
|
||||
int width = parentTable.getBounds().width;
|
||||
width -= installButtonPlaceholder.getPreferredSize().width;
|
||||
width -= removeButtonPlaceholder.getPreferredSize().width;
|
||||
Dimension minimalSize = new Dimension(width, 10);
|
||||
description.setPreferredSize(minimalSize);
|
||||
description.setSize(minimalSize);
|
||||
|
||||
Rectangle r = description.modelToView(description.getDocument()
|
||||
.getLength());
|
||||
Rectangle r = description.modelToView(description.getDocument().getLength());
|
||||
r.height += description.modelToView(0).y; // add margins
|
||||
Dimension d = new Dimension(minimalSize.width, r.y + r.height);
|
||||
description.setPreferredSize(d);
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (isSelected) {
|
||||
|
@ -137,8 +137,7 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
installer.updateIndex();
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false);
|
||||
}
|
||||
@ -156,8 +155,7 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
installer.install(lib);
|
||||
getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false);
|
||||
}
|
||||
@ -175,8 +173,7 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
installer.remove(lib);
|
||||
getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false);
|
||||
}
|
||||
|
@ -136,8 +136,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
installer.updateIndex();
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false);
|
||||
}
|
||||
@ -157,8 +156,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
installer.remove(platformToRemove);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false);
|
||||
}
|
||||
@ -175,8 +173,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
setProgressVisible(true);
|
||||
installer.remove(platform);
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class AStyle implements Tool {
|
||||
try {
|
||||
formatterConfiguration = FileUtils.readFileToString(formatterConf);
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
// ignored
|
||||
}
|
||||
this.formatterConfiguration = formatterConfiguration;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public class ContributionInstaller {
|
||||
try {
|
||||
destFolder.getParentFile().delete();
|
||||
} catch (SecurityException e) {
|
||||
// Do nothing
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,13 @@
|
||||
*/
|
||||
package cc.arduino.packages.contributions;
|
||||
|
||||
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -39,14 +45,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||
|
||||
public class ContributionsIndexer {
|
||||
|
||||
@ -58,7 +57,7 @@ public class ContributionsIndexer {
|
||||
public ContributionsIndexer(File preferencesFolder) {
|
||||
packagesFolder = new File(preferencesFolder, "packages");
|
||||
stagingFolder = new File(preferencesFolder, "staging" + File.separator +
|
||||
"packages");
|
||||
"packages");
|
||||
indexFile = new File(preferencesFolder, "package_index.json");
|
||||
}
|
||||
|
||||
@ -95,7 +94,7 @@ public class ContributionsIndexer {
|
||||
}
|
||||
|
||||
private void parseIndex(File indexFile) throws JsonParseException,
|
||||
IOException {
|
||||
IOException {
|
||||
InputStream indexIn = new FileInputStream(indexFile);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new MrBeanModule());
|
||||
@ -141,14 +140,14 @@ public class ContributionsIndexer {
|
||||
private void syncToolWithFilesystem(ContributedPackage pack, File toolFolder,
|
||||
File versionFolder) {
|
||||
ContributedTool tool = pack.findTool(toolFolder.getName(),
|
||||
versionFolder.getName());
|
||||
versionFolder.getName());
|
||||
if (tool == null)
|
||||
return;
|
||||
DownloadableContribution contrib = tool.getDownloadableContribution();
|
||||
if (contrib == null) {
|
||||
System.err.println(tool +
|
||||
" seems to have no downloadable contributions for your " +
|
||||
"operating system, but it is installed in\n" + versionFolder);
|
||||
" seems to have no downloadable contributions for your " +
|
||||
"operating system, but it is installed in\n" + versionFolder);
|
||||
return;
|
||||
}
|
||||
contrib.setInstalled(true);
|
||||
@ -173,7 +172,7 @@ public class ContributionsIndexer {
|
||||
return index.toString();
|
||||
}
|
||||
|
||||
public List<TargetPackage> createTargetPackages() {
|
||||
public List<TargetPackage> createTargetPackages() throws TargetPlatformException {
|
||||
List<TargetPackage> res = new ArrayList<TargetPackage>();
|
||||
|
||||
for (ContributedPackage pack : index.getPackages()) {
|
||||
@ -187,14 +186,9 @@ public class ContributionsIndexer {
|
||||
String arch = platform.getArchitecture();
|
||||
File folder = platform.getInstalledFolder();
|
||||
|
||||
try {
|
||||
TargetPlatform targetPlatform;
|
||||
targetPlatform = new ContributedTargetPlatform(arch, folder,
|
||||
targetPackage, index);
|
||||
targetPackage.addPlatform(targetPlatform);
|
||||
} catch (TargetPlatformException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
TargetPlatform targetPlatform;
|
||||
targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage, index);
|
||||
targetPackage.addPlatform(targetPlatform);
|
||||
}
|
||||
|
||||
if (targetPackage.hasPlatforms())
|
||||
@ -205,7 +199,7 @@ public class ContributionsIndexer {
|
||||
|
||||
/**
|
||||
* Check if a ContributedTool is currently in use by an installed platform
|
||||
*
|
||||
*
|
||||
* @param tool
|
||||
* @return
|
||||
*/
|
||||
|
@ -29,27 +29,15 @@
|
||||
|
||||
package cc.arduino.packages.security;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.Security;
|
||||
|
||||
import cc.arduino.packages.security.keys.PackagersPublicKeys;
|
||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.openpgp.PGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPSignatureList;
|
||||
import org.bouncycastle.openpgp.*;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
|
||||
|
||||
import processing.app.helpers.StringUtils;
|
||||
import cc.arduino.packages.security.keys.PackagersPublicKeys;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.Security;
|
||||
|
||||
public class ClearSignedVerifier {
|
||||
|
||||
@ -61,19 +49,17 @@ public class ClearSignedVerifier {
|
||||
|
||||
/**
|
||||
* Verify a PGP clearText-signature.
|
||||
*
|
||||
* @param signedTextFile
|
||||
* A File containing the clearText signature
|
||||
* @param pubKeyRing
|
||||
* A public key-ring containing the public key needed for the
|
||||
* signature verification
|
||||
*
|
||||
* @param signedTextFile A File containing the clearText signature
|
||||
* @param pubKeyRing A public key-ring containing the public key needed for the
|
||||
* signature verification
|
||||
* @return A VerifyResult class with the clearText and the signature
|
||||
* verification status
|
||||
* verification status
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public static VerifyResult verify(File signedTextFile,
|
||||
PGPPublicKeyRingCollection pubKeyRing)
|
||||
throws FileNotFoundException {
|
||||
throws FileNotFoundException {
|
||||
// Create the result object
|
||||
VerifyResult result = new VerifyResult();
|
||||
result.clearText = null;
|
||||
@ -108,14 +94,14 @@ public class ClearSignedVerifier {
|
||||
// Verify signature
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"),
|
||||
publicKey);
|
||||
publicKey);
|
||||
// RFC 4880, section 7: http://tools.ietf.org/html/rfc4880#section-7
|
||||
// The signature must be validated using clear text:
|
||||
// - without trailing white spaces on every line
|
||||
// - using CR LF line endings, no matter what the original line ending is
|
||||
// - without the latest line ending
|
||||
BufferedReader textIn = new BufferedReader(new InputStreamReader(
|
||||
new ByteArrayInputStream(clearText)));
|
||||
new ByteArrayInputStream(clearText)));
|
||||
while (true) {
|
||||
// remove trailing whitespace and line endings
|
||||
String line = StringUtils.rtrim(textIn.readLine());
|
||||
@ -136,7 +122,7 @@ public class ClearSignedVerifier {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -144,7 +130,7 @@ public class ClearSignedVerifier {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
VerifyResult verify = verify(new File(
|
||||
"/home/megabug/git/arduino/test.txt.asc"), new PackagersPublicKeys());
|
||||
"/home/megabug/git/arduino/test.txt.asc"), new PackagersPublicKeys());
|
||||
System.out.println(verify.verified);
|
||||
}
|
||||
}
|
||||
|
@ -719,6 +719,8 @@ public class BaseNoGui {
|
||||
initParameters(args);
|
||||
|
||||
init(args);
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
|
||||
}
|
||||
|
||||
static public void onBoardOrPortChange() {
|
||||
@ -765,7 +767,7 @@ public class BaseNoGui {
|
||||
populateImportToLibraryTable();
|
||||
}
|
||||
|
||||
static protected void loadContributedHardware(ContributionsIndexer indexer) {
|
||||
static protected void loadContributedHardware(ContributionsIndexer indexer) throws TargetPlatformException {
|
||||
for (TargetPackage pack : indexer.createTargetPackages()) {
|
||||
packages.put(pack.getId(), pack);
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package processing.app;
|
||||
|
||||
public class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
System.out.println(t);
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user