1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

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

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

View File

@ -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
*/

View File

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

View File

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

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