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 {
/** * Analyzes the class given as a ASM reader. * * @param reader * reader with class definitions */ public void analyzeClass(final ClassReader reader) { analyzeClass(reader.b); }
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); }
/** * 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); } }
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; }
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; }
/** * 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; }
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;
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; }
/** * 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; }
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); }
/** * 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); }
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) ); }
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; }
/** * 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); } } }
/** * 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); } }
@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; }
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; }
/** * 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); } } }
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); } }