aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core
diff options
context:
space:
mode:
authorEvgeny Mandrikov <Godin@users.noreply.github.com>2016-05-14 09:33:09 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2016-05-14 09:33:09 +0200
commitfde254dd251e6afc1c8f1272efb1be2b6c767387 (patch)
tree047453eeadcb83653f60e651f573faae6974f1b7 /org.jacoco.core
parenta6bcbe3f67cf2d4296562b6bfda227dab4236f75 (diff)
downloadjacoco-fde254dd251e6afc1c8f1272efb1be2b6c767387.tar.gz
Add location to IOException when unable to read input during analysis (#400)
Diffstat (limited to 'org.jacoco.core')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java39
1 files changed, 33 insertions, 6 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
index 5fd859ee..ac86128f 100644
--- a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
+++ b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
@@ -149,7 +149,7 @@ public class Analyzer {
}
private IOException analyzerError(final String location,
- final RuntimeException cause) {
+ final Exception cause) {
final IOException ex = new IOException(String.format(
"Error while analyzing %s.", location));
ex.initCause(cause);
@@ -172,7 +172,12 @@ public class Analyzer {
*/
public int analyzeAll(final InputStream input, final String location)
throws IOException {
- final ContentTypeDetector detector = new ContentTypeDetector(input);
+ final ContentTypeDetector detector;
+ try {
+ detector = new ContentTypeDetector(input);
+ } catch (IOException e) {
+ throw analyzerError(location, e);
+ }
switch (detector.getType()) {
case ContentTypeDetector.CLASSFILE:
analyzeClass(detector.getInputStream(), location);
@@ -233,7 +238,8 @@ public class Analyzer {
public int analyzeAll(final String path, final File basedir)
throws IOException {
int count = 0;
- final StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
+ final StringTokenizer st = new StringTokenizer(path,
+ File.pathSeparator);
while (st.hasMoreTokens()) {
count += analyzeAll(new File(basedir, st.nextToken()));
}
@@ -245,20 +251,41 @@ public class Analyzer {
final ZipInputStream zip = new ZipInputStream(input);
ZipEntry entry;
int count = 0;
- while ((entry = zip.getNextEntry()) != null) {
+ while ((entry = nextEntry(zip, location)) != null) {
count += analyzeAll(zip, location + "@" + entry.getName());
}
return count;
}
+ private ZipEntry nextEntry(ZipInputStream input, String location)
+ throws IOException {
+ try {
+ return input.getNextEntry();
+ } catch (IOException e) {
+ throw analyzerError(location, e);
+ }
+ }
+
private int analyzeGzip(final InputStream input, final String location)
throws IOException {
- return analyzeAll(new GZIPInputStream(input), location);
+ GZIPInputStream gzipInputStream;
+ try {
+ gzipInputStream = new GZIPInputStream(input);
+ } catch (IOException e) {
+ throw analyzerError(location, e);
+ }
+ return analyzeAll(gzipInputStream, location);
}
private int analyzePack200(final InputStream input, final String location)
throws IOException {
- return analyzeAll(Pack200Streams.unpack(input), location);
+ InputStream unpackedInput;
+ try {
+ unpackedInput = Pack200Streams.unpack(input);
+ } catch (IOException e) {
+ throw analyzerError(location, e);
+ }
+ return analyzeAll(unpackedInput, location);
}
}