Package org.jacoco.core.analysis
Class Analyzer
- java.lang.Object
-
- org.jacoco.core.analysis.Analyzer
-
public class Analyzer extends java.lang.Object
AnAnalyzer
instance processes a set of Java class files and calculates coverage data for them. For each class file the result is reported to a givenICoverageVisitor
instance. In addition theAnalyzer
requires aExecutionDataStore
instance that holds the execution data for the classes to analyze. TheAnalyzer
offers several methods to analyze classes from a variety of sources.
-
-
Field Summary
Fields Modifier and Type Field Description private ICoverageVisitor
coverageVisitor
private ExecutionDataStore
executionData
private StringPool
stringPool
-
Constructor Summary
Constructors Constructor Description Analyzer(ExecutionDataStore executionData, ICoverageVisitor coverageVisitor)
Creates a new analyzer reporting to the given output.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
analyzeAll(java.io.File file)
Analyzes all class files contained in the given file or folder.int
analyzeAll(java.io.InputStream input, java.lang.String location)
Analyzes all classes found in the given input stream.int
analyzeAll(java.lang.String path, java.io.File basedir)
Analyzes all classes from the given class path.private void
analyzeClass(byte[] source)
void
analyzeClass(byte[] buffer, java.lang.String location)
Analyzes the class definition from a given in-memory buffer.void
analyzeClass(java.io.InputStream input, java.lang.String location)
Analyzes the class definition from a given input stream.void
analyzeClass(org.objectweb.asm.ClassReader reader)
Analyzes the class given as a ASM reader.private int
analyzeGzip(java.io.InputStream input, java.lang.String location)
private int
analyzePack200(java.io.InputStream input, java.lang.String location)
private java.io.IOException
analyzerError(java.lang.String location, java.lang.Exception cause)
private int
analyzeZip(java.io.InputStream input, java.lang.String location)
private org.objectweb.asm.ClassVisitor
createAnalyzingVisitor(long classid, java.lang.String className)
Creates an ASM class visitor for analysis.private java.util.zip.ZipEntry
nextEntry(java.util.zip.ZipInputStream input, java.lang.String location)
-
-
-
Field Detail
-
executionData
private final ExecutionDataStore executionData
-
coverageVisitor
private final ICoverageVisitor coverageVisitor
-
stringPool
private final StringPool stringPool
-
-
Constructor Detail
-
Analyzer
public Analyzer(ExecutionDataStore executionData, ICoverageVisitor coverageVisitor)
Creates a new analyzer reporting to the given output.- Parameters:
executionData
- execution datacoverageVisitor
- the output instance that will coverage data for every analyzed class
-
-
Method Detail
-
createAnalyzingVisitor
private org.objectweb.asm.ClassVisitor createAnalyzingVisitor(long classid, java.lang.String className)
Creates an ASM class visitor for analysis.- Parameters:
classid
- id of the class calculated withCRC64
className
- VM name of the class- Returns:
- ASM visitor to write class definition to
-
analyzeClass
public void analyzeClass(org.objectweb.asm.ClassReader reader)
Analyzes the class given as a ASM reader.- Parameters:
reader
- reader with class definitions
-
analyzeClass
private void analyzeClass(byte[] source)
-
analyzeClass
public void analyzeClass(byte[] buffer, java.lang.String location) throws java.io.IOException
Analyzes the class definition from a given in-memory buffer.- Parameters:
buffer
- class definitionslocation
- a location description used for exception messages- Throws:
java.io.IOException
- if the class can't be analyzed
-
analyzeClass
public void analyzeClass(java.io.InputStream input, java.lang.String location) throws java.io.IOException
Analyzes the class definition from a given input stream. The providedInputStream
is not closed by this method.- Parameters:
input
- stream to read class definition fromlocation
- a location description used for exception messages- Throws:
java.io.IOException
- if the stream can't be read or the class can't be analyzed
-
analyzerError
private java.io.IOException analyzerError(java.lang.String location, java.lang.Exception cause)
-
analyzeAll
public int analyzeAll(java.io.InputStream input, java.lang.String location) throws java.io.IOException
Analyzes all classes found in the given input stream. The input stream may either represent a single class file, a ZIP archive, a Pack200 archive or a gzip stream that is searched recursively for class files. All other content types are ignored. The providedInputStream
is not closed by this method.- Parameters:
input
- input datalocation
- a location description used for exception messages- Returns:
- number of class files found
- Throws:
java.io.IOException
- if the stream can't be read or a class can't be analyzed
-
analyzeAll
public int analyzeAll(java.io.File file) throws java.io.IOException
Analyzes all class files contained in the given file or folder. Class files as well as ZIP files are considered. Folders are searched recursively.- Parameters:
file
- file or folder to look for class files- Returns:
- number of class files found
- Throws:
java.io.IOException
- if the file can't be read or a class can't be analyzed
-
analyzeAll
public int analyzeAll(java.lang.String path, java.io.File basedir) throws java.io.IOException
Analyzes all classes from the given class path. Directories containing class files as well as archive files are considered.- Parameters:
path
- path definitionbasedir
- optional base directory, ifnull
the current working directory is used as the base for relative path entries- Returns:
- number of class files found
- Throws:
java.io.IOException
- if a file can't be read or a class can't be analyzed
-
analyzeZip
private int analyzeZip(java.io.InputStream input, java.lang.String location) throws java.io.IOException
- Throws:
java.io.IOException
-
nextEntry
private java.util.zip.ZipEntry nextEntry(java.util.zip.ZipInputStream input, java.lang.String location) throws java.io.IOException
- Throws:
java.io.IOException
-
analyzeGzip
private int analyzeGzip(java.io.InputStream input, java.lang.String location) throws java.io.IOException
- Throws:
java.io.IOException
-
analyzePack200
private int analyzePack200(java.io.InputStream input, java.lang.String location) throws java.io.IOException
- Throws:
java.io.IOException
-
-