org.jacoco.core.analysis.Analyzer.analyzeAll()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中org.jacoco.core.analysis.Analyzer.analyzeAll()方法的一些代码示例,展示了Analyzer.analyzeAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Analyzer.analyzeAll()方法的具体详情如下:
包路径:org.jacoco.core.analysis.Analyzer
类名称:Analyzer
方法名:analyzeAll

Analyzer.analyzeAll介绍

[英]Analyzes all class files contained in the given file or folder. Class files as well as ZIP files are considered. Folders are searched recursively.
[中]分析给定文件或文件夹中包含的所有类文件。类文件以及ZIP文件都被考虑在内。递归搜索文件夹。

代码示例

代码示例来源: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.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: 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.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

/**
 * 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.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: eclipse/eclemma

public void walk(IPath path) throws IOException {
 final File file = path.toFile();
 if (file.isFile()) {
  final InputStream in = open(file);
  try {
   analyzer.analyzeAll(in, path.toString());
  } finally {
   in.close();
  }
 } else {
  walkFile(file, true);
 }
}

代码示例来源: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: eclipse/eclemma

private void walkFile(File file, boolean root) throws IOException {
 if (file.isFile()) {
  if (file.getName().endsWith(".class")) { //$NON-NLS-1$
   final InputStream in = open(file);
   try {
    analyzer.analyzeAll(in, file.toString());
   } finally {
    in.close();
   }
  }
 } else {
  // Do not traverse into folders like ".svn"
  if (root || isJavaIdentifier(file.getName())) {
   for (final File child : file.listFiles()) {
    walkFile(child, false);
   }
  }
 }
}

代码示例来源: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: eu.stamp-project/test-runner

final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
try {
  analyzer.analyzeAll(new File(classesDirectory));
} catch (IOException e) {
  throw new RuntimeException(e);

代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-jacoco-plugin

private CoverageBuilder analyze2(ExecutionDataStore executionDataStore) {
 CoverageBuilder coverageBuilder = new CoverageBuilder();
 Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
 for (File binaryDir : fileSystem.binaryDirs()) {
  for (ExecutionData data : executionDataStore.getContents()) {
   String vmClassName = data.getName();
   String classFileName = vmClassName.replace('.', '/') + ".class";
   File classFile = new File(binaryDir, classFileName);
   if (classFile.isFile()) {
    try {
     analyzer.analyzeAll(classFile);
    } catch (Exception e) {
     JaCoCoUtils.LOG.warn("Exception during analysis of file " + classFile.getAbsolutePath(), e);
    }
   }
  }
 }
 return coverageBuilder;
}

代码示例来源: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: eclipse/eclemma

public void walk(IResource resource) throws CoreException, IOException {
 if (resource.getType() == IResource.FILE) {
  final IFile file = (IFile) resource;
  final InputStream in = file.getContents(true);
  try {
   analyzer.analyzeAll(in, resource.getName());
  } finally {
   in.close();
  }
 } else {
  walkResource(resource, true);
 }
}

代码示例来源: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: rohanpadhye/jqf

public void jacocoCheckpoint(File classFile, File csvDir) {
  int idx = nextFileIdx;
  csvDir.mkdirs();
  try {
    // Get exec data by dynamically calling RT.getAgent().getExecutionData()
    Class RT = Class.forName("org.jacoco.agent.rt.RT");
    Method getAgent = RT.getMethod("getAgent");
    Object agent = getAgent.invoke(null);
    Method dump = agent.getClass().getMethod("getExecutionData", boolean.class);
    byte[] execData = (byte[]) dump.invoke(agent, false);
    // Analyze exec data
    ExecFileLoader loader = new ExecFileLoader();
    loader.load(new ByteArrayInputStream(execData));
    final CoverageBuilder builder = new CoverageBuilder();
    Analyzer analyzer = new Analyzer(loader.getExecutionDataStore(), builder);
    analyzer.analyzeAll(classFile);
    // Generate CSV
    File csv = new File(csvDir, String.format("cov-%05d.csv", idx));
    try (FileOutputStream out = new FileOutputStream(csv)) {
      IReportVisitor coverageVisitor = new CSVFormatter().createVisitor(out);
      coverageVisitor.visitBundle(builder.getBundle("JQF"), null);
      coverageVisitor.visitEnd();
      out.flush();
    }
  } catch (Exception e) {
    System.err.println(e);
  }
}

代码示例来源:origin: jenkinsci/jacoco-plugin

final List<File> filesToAnalyze = FileUtils.getFiles(classDirectory, fileFilter.getIncludes(), fileFilter.getExcludes());
for (final File file : filesToAnalyze) {
  analyzer.analyzeAll(file);

代码示例来源:origin: org.jacoco/org.jacoco.cli

private IBundleCoverage analyze(final ExecutionDataStore data,
    final PrintWriter out) throws IOException {
  final CoverageBuilder builder = new CoverageBuilder();
  final Analyzer analyzer = new Analyzer(data, builder);
  for (final File f : classfiles) {
    analyzer.analyzeAll(f);
  }
  printNoMatchWarning(builder.getNoMatchClasses(), out);
  return builder.getBundle(name);
}

代码示例来源:origin: eclipse/eclemma

private void walkResource(IResource resource, boolean root)
  throws CoreException, IOException {
 switch (resource.getType()) {
 case IResource.FILE:
  if (resource.getName().endsWith(".class")) { //$NON-NLS-1$
   final IFile file = (IFile) resource;
   final InputStream in = file.getContents(true);
   try {
    analyzer.analyzeAll(in, resource.getName());
   } finally {
    in.close();
   }
  }
  break;
 case IResource.FOLDER:
 case IResource.PROJECT:
  // Do not traverse into sub-folders like ".svn"
  if (root || isJavaIdentifier(resource.getName())) {
   final IContainer container = (IContainer) resource;
   for (final IResource child : container.members()) {
    walkResource(child, false);
   }
  }
  break;
 }
}

相关文章