Removed some printStackTrace in favour of throwing RuntimeExceptions. DefaultUncoughtExceptionHandler will handle them

This commit is contained in:
Federico Fissore 2015-02-23 13:33:17 +01:00
parent fe6718ce4f
commit 6007403834
9 changed files with 70 additions and 85 deletions

View File

@ -166,8 +166,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
return getUpdatedCellComponent(value, true, row); return getUpdatedCellComponent(value, true, row);
} }
private Component getUpdatedCellComponent(Object value, boolean isSelected, private Component getUpdatedCellComponent(Object value, boolean isSelected, int row) {
int row) {
ContributedLibraryReleases releases = (ContributedLibraryReleases) value; ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
ContributedLibrary selectedLib = releases.getSelected(); ContributedLibrary selectedLib = releases.getSelected();
ContributedLibrary installedLib = releases.getInstalled(); ContributedLibrary installedLib = releases.getInstalled();
@ -245,26 +244,25 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
description.setText(desc); description.setText(desc);
description.setBackground(Color.WHITE); 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 { try {
// for modelToView to work, the text area has to be sized. It doesn't Rectangle r = description.modelToView(description.getDocument().getLength());
// 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());
r.height += description.modelToView(0).y; // add margins r.height += description.modelToView(0).y; // add margins
Dimension d = new Dimension(minimalSize.width, r.y + r.height); Dimension d = new Dimension(minimalSize.width, r.y + r.height);
description.setPreferredSize(d); description.setPreferredSize(d);
} catch (BadLocationException e) { } catch (BadLocationException e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
if (isSelected) { if (isSelected) {

View File

@ -137,8 +137,7 @@ public class LibraryManagerUI extends InstallerJDialog {
installer.updateIndex(); installer.updateIndex();
onIndexesUpdated(); onIndexesUpdated();
} catch (Exception e) { } catch (Exception e) {
// TODO Show ERROR throw new RuntimeException(e);
e.printStackTrace();
} finally { } finally {
setProgressVisible(false); setProgressVisible(false);
} }
@ -156,8 +155,7 @@ public class LibraryManagerUI extends InstallerJDialog {
installer.install(lib); installer.install(lib);
getContribModel().updateLibrary(lib); getContribModel().updateLibrary(lib);
} catch (Exception e) { } catch (Exception e) {
// TODO Show ERROR throw new RuntimeException(e);
e.printStackTrace();
} finally { } finally {
setProgressVisible(false); setProgressVisible(false);
} }
@ -175,8 +173,7 @@ public class LibraryManagerUI extends InstallerJDialog {
installer.remove(lib); installer.remove(lib);
getContribModel().updateLibrary(lib); getContribModel().updateLibrary(lib);
} catch (Exception e) { } catch (Exception e) {
// TODO Show ERROR throw new RuntimeException(e);
e.printStackTrace();
} finally { } finally {
setProgressVisible(false); setProgressVisible(false);
} }

View File

@ -136,8 +136,7 @@ public class ContributionManagerUI extends InstallerJDialog {
installer.updateIndex(); installer.updateIndex();
onIndexesUpdated(); onIndexesUpdated();
} catch (Exception e) { } catch (Exception e) {
// TODO Show ERROR throw new RuntimeException(e);
e.printStackTrace();
} finally { } finally {
setProgressVisible(false); setProgressVisible(false);
} }
@ -157,8 +156,7 @@ public class ContributionManagerUI extends InstallerJDialog {
installer.remove(platformToRemove); installer.remove(platformToRemove);
} }
} catch (Exception e) { } catch (Exception e) {
// TODO Show ERROR throw new RuntimeException(e);
e.printStackTrace();
} finally { } finally {
setProgressVisible(false); setProgressVisible(false);
} }
@ -175,8 +173,7 @@ public class ContributionManagerUI extends InstallerJDialog {
setProgressVisible(true); setProgressVisible(true);
installer.remove(platform); installer.remove(platform);
} catch (Exception e) { } catch (Exception e) {
// TODO Show ERROR throw new RuntimeException(e);
e.printStackTrace();
} finally { } finally {
setProgressVisible(false); setProgressVisible(false);
} }

View File

@ -64,7 +64,7 @@ public class AStyle implements Tool {
try { try {
formatterConfiguration = FileUtils.readFileToString(formatterConf); formatterConfiguration = FileUtils.readFileToString(formatterConf);
} catch (IOException e) { } catch (IOException e) {
// noop // ignored
} }
this.formatterConfiguration = formatterConfiguration; this.formatterConfiguration = formatterConfiguration;
} }

View File

@ -162,7 +162,7 @@ public class ContributionInstaller {
try { try {
destFolder.getParentFile().delete(); destFolder.getParentFile().delete();
} catch (SecurityException e) { } catch (SecurityException e) {
// Do nothing // ignore
} }
} }
} }

View File

@ -28,7 +28,13 @@
*/ */
package cc.arduino.packages.contributions; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -39,14 +45,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import processing.app.debug.TargetPackage; import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
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;
public class ContributionsIndexer { public class ContributionsIndexer {
@ -58,7 +57,7 @@ public class ContributionsIndexer {
public ContributionsIndexer(File preferencesFolder) { public ContributionsIndexer(File preferencesFolder) {
packagesFolder = new File(preferencesFolder, "packages"); packagesFolder = new File(preferencesFolder, "packages");
stagingFolder = new File(preferencesFolder, "staging" + File.separator + stagingFolder = new File(preferencesFolder, "staging" + File.separator +
"packages"); "packages");
indexFile = new File(preferencesFolder, "package_index.json"); indexFile = new File(preferencesFolder, "package_index.json");
} }
@ -95,7 +94,7 @@ public class ContributionsIndexer {
} }
private void parseIndex(File indexFile) throws JsonParseException, private void parseIndex(File indexFile) throws JsonParseException,
IOException { IOException {
InputStream indexIn = new FileInputStream(indexFile); InputStream indexIn = new FileInputStream(indexFile);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MrBeanModule()); mapper.registerModule(new MrBeanModule());
@ -141,14 +140,14 @@ public class ContributionsIndexer {
private void syncToolWithFilesystem(ContributedPackage pack, File toolFolder, private void syncToolWithFilesystem(ContributedPackage pack, File toolFolder,
File versionFolder) { File versionFolder) {
ContributedTool tool = pack.findTool(toolFolder.getName(), ContributedTool tool = pack.findTool(toolFolder.getName(),
versionFolder.getName()); versionFolder.getName());
if (tool == null) if (tool == null)
return; return;
DownloadableContribution contrib = tool.getDownloadableContribution(); DownloadableContribution contrib = tool.getDownloadableContribution();
if (contrib == null) { if (contrib == null) {
System.err.println(tool + System.err.println(tool +
" seems to have no downloadable contributions for your " + " seems to have no downloadable contributions for your " +
"operating system, but it is installed in\n" + versionFolder); "operating system, but it is installed in\n" + versionFolder);
return; return;
} }
contrib.setInstalled(true); contrib.setInstalled(true);
@ -173,7 +172,7 @@ public class ContributionsIndexer {
return index.toString(); return index.toString();
} }
public List<TargetPackage> createTargetPackages() { public List<TargetPackage> createTargetPackages() throws TargetPlatformException {
List<TargetPackage> res = new ArrayList<TargetPackage>(); List<TargetPackage> res = new ArrayList<TargetPackage>();
for (ContributedPackage pack : index.getPackages()) { for (ContributedPackage pack : index.getPackages()) {
@ -187,14 +186,9 @@ public class ContributionsIndexer {
String arch = platform.getArchitecture(); String arch = platform.getArchitecture();
File folder = platform.getInstalledFolder(); File folder = platform.getInstalledFolder();
try { TargetPlatform targetPlatform;
TargetPlatform targetPlatform; targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage, index);
targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage.addPlatform(targetPlatform);
targetPackage, index);
targetPackage.addPlatform(targetPlatform);
} catch (TargetPlatformException e) {
e.printStackTrace();
}
} }
if (targetPackage.hasPlatforms()) if (targetPackage.hasPlatforms())

View File

@ -29,27 +29,15 @@
package cc.arduino.packages.security; package cc.arduino.packages.security;
import java.io.BufferedReader; import cc.arduino.packages.security.keys.PackagersPublicKeys;
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 org.bouncycastle.bcpg.ArmoredInputStream; import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openpgp.PGPObjectFactory; import org.bouncycastle.openpgp.*;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.openpgp.PGPSignatureList;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider; import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
import processing.app.helpers.StringUtils; import processing.app.helpers.StringUtils;
import cc.arduino.packages.security.keys.PackagersPublicKeys;
import java.io.*;
import java.security.Security;
public class ClearSignedVerifier { public class ClearSignedVerifier {
@ -62,18 +50,16 @@ public class ClearSignedVerifier {
/** /**
* Verify a PGP clearText-signature. * Verify a PGP clearText-signature.
* *
* @param signedTextFile * @param signedTextFile A File containing the clearText signature
* A File containing the clearText signature * @param pubKeyRing A public key-ring containing the public key needed for the
* @param pubKeyRing * signature verification
* A public key-ring containing the public key needed for the
* signature verification
* @return A VerifyResult class with the clearText and the signature * @return A VerifyResult class with the clearText and the signature
* verification status * verification status
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
public static VerifyResult verify(File signedTextFile, public static VerifyResult verify(File signedTextFile,
PGPPublicKeyRingCollection pubKeyRing) PGPPublicKeyRingCollection pubKeyRing)
throws FileNotFoundException { throws FileNotFoundException {
// Create the result object // Create the result object
VerifyResult result = new VerifyResult(); VerifyResult result = new VerifyResult();
result.clearText = null; result.clearText = null;
@ -108,14 +94,14 @@ public class ClearSignedVerifier {
// Verify signature // Verify signature
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"),
publicKey); publicKey);
// RFC 4880, section 7: http://tools.ietf.org/html/rfc4880#section-7 // RFC 4880, section 7: http://tools.ietf.org/html/rfc4880#section-7
// The signature must be validated using clear text: // The signature must be validated using clear text:
// - without trailing white spaces on every line // - without trailing white spaces on every line
// - using CR LF line endings, no matter what the original line ending is // - using CR LF line endings, no matter what the original line ending is
// - without the latest line ending // - without the latest line ending
BufferedReader textIn = new BufferedReader(new InputStreamReader( BufferedReader textIn = new BufferedReader(new InputStreamReader(
new ByteArrayInputStream(clearText))); new ByteArrayInputStream(clearText)));
while (true) { while (true) {
// remove trailing whitespace and line endings // remove trailing whitespace and line endings
String line = StringUtils.rtrim(textIn.readLine()); String line = StringUtils.rtrim(textIn.readLine());
@ -136,7 +122,7 @@ public class ClearSignedVerifier {
try { try {
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); // ignored
} }
} }
return result; return result;
@ -144,7 +130,7 @@ public class ClearSignedVerifier {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
VerifyResult verify = verify(new File( 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); System.out.println(verify.verified);
} }
} }

View File

@ -719,6 +719,8 @@ public class BaseNoGui {
initParameters(args); initParameters(args);
init(args); init(args);
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
} }
static public void onBoardOrPortChange() { static public void onBoardOrPortChange() {
@ -765,7 +767,7 @@ public class BaseNoGui {
populateImportToLibraryTable(); populateImportToLibraryTable();
} }
static protected void loadContributedHardware(ContributionsIndexer indexer) { static protected void loadContributedHardware(ContributionsIndexer indexer) throws TargetPlatformException {
for (TargetPackage pack : indexer.createTargetPackages()) { for (TargetPackage pack : indexer.createTargetPackages()) {
packages.put(pack.getId(), pack); packages.put(pack.getId(), pack);
} }

View File

@ -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);
}
}