本文整理了Java中org.jacoco.core.analysis.Analyzer
类的一些代码示例,展示了Analyzer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analyzer
类的具体详情如下:
包路径:org.jacoco.core.analysis.Analyzer
类名称:Analyzer
[英]An Analyzer instance processes a set of Java class files and calculates coverage data for them. For each class file the result is reported to a given ICoverageVisitor instance. In addition the Analyzer requires a ExecutionDataStore instance that holds the execution data for the classes to analyze. The Analyzer offers several methods to analyze classes from a variety of sources.
[中]Analyzer实例处理一组Java类文件并计算它们的覆盖率数据。对于每个类文件,结果将报告给给定的ICoverageVisitor实例。此外,分析器还需要一个ExecutionDataStore实例,该实例保存要分析的类的执行数据。分析器提供了几种方法来分析来自各种源的类。
代码示例来源:origin: jenkinsci/jacoco-plugin
private IBundleCoverage analyzeStructure() throws IOException {
File classDirectory = new File(classDir.getRemote());
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionDataStore,
coverageBuilder);
analyzer.analyzeAll(classDirectory);
return coverageBuilder.getBundle(name);
}
public IBundleCoverage loadBundleCoverage() throws IOException {
代码示例来源:origin: org.jacoco/org.jacoco.core
/**
* Analyzes the class given as a ASM reader.
*
* @param reader
* reader with class definitions
*/
public void analyzeClass(final ClassReader reader) {
analyzeClass(reader.b);
}
代码示例来源:origin: org.jacoco/org.jacoco.core
private int analyzeGzip(final InputStream input, final String location)
throws IOException {
GZIPInputStream gzipInputStream;
try {
gzipInputStream = new GZIPInputStream(input);
} catch (final IOException e) {
throw analyzerError(location, e);
}
return analyzeAll(gzipInputStream, location);
}
代码示例来源:origin: org.jacoco/org.jacoco.core
/**
* Analyzes the class definition from a given in-memory buffer.
*
* @param buffer
* class definitions
* @param location
* a location description used for exception messages
* @throws IOException
* if the class can't be analyzed
*/
public void analyzeClass(final byte[] buffer, final String location)
throws IOException {
try {
analyzeClass(buffer);
} catch (final RuntimeException cause) {
throw analyzerError(location, cause);
}
}
代码示例来源:origin: org.jacoco/org.jacoco.core
private int analyzeZip(final InputStream input, final String location)
throws IOException {
final ZipInputStream zip = new ZipInputStream(input);
ZipEntry entry;
int count = 0;
while ((entry = nextEntry(zip, location)) != null) {
count += analyzeAll(zip, location + "@" + entry.getName());
}
return count;
}
代码示例来源:origin: org.codehaus.sonar-plugins.java/java-jacoco
private CoverageBuilder analyze(ExecutionDataStore executionDataStore) {
CoverageBuilder coverageBuilder = new CoverageBuilder();
Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
for (File classFile : classFilesCache.values()) {
analyzeClassFile(analyzer, classFile);
}
return coverageBuilder;
}
代码示例来源:origin: org.jacoco/org.jacoco.core
/**
* Analyzes all class files contained in the given file or folder. Class
* files as well as ZIP files are considered. Folders are searched
* recursively.
*
* @param file
* file or folder to look for class files
* @return number of class files found
* @throws IOException
* if the file can't be read or a class can't be analyzed
*/
public int analyzeAll(final File file) throws IOException {
int count = 0;
if (file.isDirectory()) {
for (final File f : file.listFiles()) {
count += analyzeAll(f);
}
} else {
final InputStream in = new FileInputStream(file);
try {
count += analyzeAll(in, file.getPath());
} finally {
in.close();
}
}
return count;
}
代码示例来源:origin: org.jacoco/org.jacoco.core
detector = new ContentTypeDetector(input);
} catch (final IOException e) {
throw analyzerError(location, e);
analyzeClass(detector.getInputStream(), location);
return 1;
case ContentTypeDetector.ZIPFILE:
return analyzeZip(detector.getInputStream(), location);
case ContentTypeDetector.GZFILE:
return analyzeGzip(detector.getInputStream(), location);
case ContentTypeDetector.PACK200FILE:
return analyzePack200(detector.getInputStream(), location);
default:
return 0;
代码示例来源:origin: Stratio/sonar-scala-plugin
private CoverageBuilder analyze(ExecutionDataStore executionDataStore) {
CoverageBuilder coverageBuilder = new CoverageBuilder();
Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
java.io.File binariesDir = new File(fileSystem.baseDir() + "/target/classes");
if (binariesDir.exists()) {
analyzeAll(analyzer, binariesDir);
}
return coverageBuilder;
}
代码示例来源:origin: org.jacoco/org.jacoco.core
/**
* Analyzes all classes from the given class path. Directories containing
* class files as well as archive files are considered.
*
* @param path
* path definition
* @param basedir
* optional base directory, if <code>null</code> the current
* working directory is used as the base for relative path
* entries
* @return number of class files found
* @throws IOException
* if a file can't be read or a class can't be analyzed
*/
public int analyzeAll(final String path, final File basedir)
throws IOException {
int count = 0;
final StringTokenizer st = new StringTokenizer(path,
File.pathSeparator);
while (st.hasMoreTokens()) {
count += analyzeAll(new File(basedir, st.nextToken()));
}
return count;
}
代码示例来源:origin: org.jacoco/org.jacoco.core
private int analyzePack200(final InputStream input, final String location)
throws IOException {
InputStream unpackedInput;
try {
unpackedInput = Pack200Streams.unpack(input);
} catch (final IOException e) {
throw analyzerError(location, e);
}
return analyzeAll(unpackedInput, location);
}
代码示例来源:origin: org.jacoco/org.jacoco.core
/**
* Analyzes the class definition from a given input stream. The provided
* {@link InputStream} is not closed by this method.
*
* @param input
* stream to read class definition from
* @param location
* a location description used for exception messages
* @throws IOException
* if the stream can't be read or the class can't be analyzed
*/
public void analyzeClass(final InputStream input, final String location)
throws IOException {
final byte[] buffer;
try {
buffer = InputStreams.readFully(input);
} catch (final IOException e) {
throw analyzerError(location, e);
}
analyzeClass(buffer, location);
}
代码示例来源:origin: eu.stamp-project/test-runner
private void collectForParametrizedTest(String testMethodName) {
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(this.internalCoverage.getExecutionData(), coverageBuilder);
try {
analyzer.analyzeAll(new File(this.internalCoverage.getClassesDirectory()));
} catch (IOException e) {
throw new RuntimeException(e);
}
if (!this.coveragesPerMethodName.containsKey(testMethodName)) {
this.coveragesPerMethodName.put(testMethodName, new ArrayList<>());
}
coverageBuilder.getClasses()
.forEach(classCoverage ->
this.coveragesPerMethodName.get(testMethodName)
.add(classCoverage)
);
}
代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-jacoco-plugin
private CoverageBuilder analyze(ExecutionDataStore executionDataStore) {
CoverageBuilder coverageBuilder = new CoverageBuilder();
Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
for (File binaryDir : fileSystem.binaryDirs()) {
analyzeAll(analyzer, binaryDir);
}
return coverageBuilder;
}
代码示例来源:origin: Stratio/sonar-scala-plugin
/**
* Copied from {@link Analyzer#analyzeAll(File)} in order to add logging.
*/
private void analyzeAll(Analyzer analyzer, File file) {
if (file.isDirectory()) {
for (File f : file.listFiles()) {
analyzeAll(analyzer, f);
}
} else if (file.getName().endsWith(".class")) {
try {
analyzer.analyzeAll(file);
} catch (Exception e) {
JaCoCoScalaExtensions.LOG.warn("Exception during analysis of file " + file.getAbsolutePath(), e);
}
}
}
代码示例来源:origin: org.codehaus.sonar-plugins.java/java-jacoco
/**
* Caller must guarantee that {@code classFile} is actually class file.
*/
private void analyzeClassFile(Analyzer analyzer, File classFile) {
InputStream inputStream = null;
try {
inputStream = new FileInputStream(classFile);
analyzer.analyzeClass(inputStream, classFile.getPath());
} catch (IOException e) {
// (Godin): in fact JaCoCo includes name into exception
JaCoCoExtensions.LOG.warn("Exception during analysis of file " + classFile.getAbsolutePath(), e);
} finally {
Closeables.closeQuietly(inputStream);
}
}
代码示例来源:origin: org.jacoco/org.jacoco.cli
@Override
public int execute(final PrintWriter out, final PrintWriter err)
throws IOException {
if (classfiles.isEmpty()) {
out.println("[WARN] No class files provided.");
} else {
final Analyzer analyzer = new Analyzer(new ExecutionDataStore(),
new Printer(out));
for (final File file : classfiles) {
analyzer.analyzeAll(file);
}
}
return 0;
}
代码示例来源:origin: org.codehaus.sonar-plugins.java/java-jacoco
private CoverageBuilder analyze2(ExecutionDataStore executionDataStore) {
CoverageBuilder coverageBuilder = new CoverageBuilder();
Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
for (ExecutionData data : executionDataStore.getContents()) {
String vmClassName = data.getName();
File classFile = classFilesCache.get(vmClassName);
if (classFile != null) {
analyzeClassFile(analyzer, classFile);
}
}
return coverageBuilder;
}
代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-jacoco-plugin
/**
* Copied from {@link Analyzer#analyzeAll(File)} in order to add logging.
*/
private void analyzeAll(Analyzer analyzer, File file) {
if (file.isDirectory()) {
for (File f : file.listFiles()) {
analyzeAll(analyzer, f);
}
} else if (file.getName().endsWith(".class")) {
try {
analyzer.analyzeAll(file);
} catch (Exception e) {
JaCoCoUtils.LOG.warn("Exception during analysis of file " + file.getAbsolutePath(), e);
}
}
}
代码示例来源:origin: SonarSource/sonar-java
private static void analyzeClassFile(Analyzer analyzer, File classFile) {
try (InputStream inputStream = new FileInputStream(classFile)) {
analyzer.analyzeClass(inputStream, classFile.getPath());
} catch (IOException e) {
// (Godin): in fact JaCoCo includes name into exception
LOG.warn("Exception during analysis of file " + classFile.getAbsolutePath(), e);
}
}
内容来源于网络,如有侵权,请联系作者删除!