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 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); }
/** * 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); } } }
/** * 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; }
/** * 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; }
/** * 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); } } }
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); } }
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); }
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); } } } }
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) ); }
final Analyzer analyzer = new Analyzer(executionData, coverageBuilder); try { analyzer.analyzeAll(new File(classesDirectory)); } catch (IOException e) { throw new RuntimeException(e);
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; }
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 {
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); } }
@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; }
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); } }
final List<File> filesToAnalyze = FileUtils.getFiles(classDirectory, fileFilter.getIncludes(), fileFilter.getExcludes()); for (final File file : filesToAnalyze) { analyzer.analyzeAll(file);
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); }
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; } }