@Test void cyclomaticComplexityIsCalculatedCorrectly() throws IOException { byte[] fileContent = IOUtils.toByteArray(getClass().getResourceAsStream("/AntPathMatcher.java.txt")); CheckstyleSourceCodeFileAnalyzerPlugin analyzer = new CheckstyleSourceCodeFileAnalyzerPlugin(); FileMetrics metrics = analyzer.analyzeFile("abc.java", fileContent); Assertions.assertEquals( Long.valueOf(78L), metrics.getMetricCount( new Metric( "checkstyle:com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"))); }
@Override public FileMetrics analyzeFile(String filepath, byte[] fileContent) { File fileToAnalyze = null; try { fileToAnalyze = createTempFile(fileContent, filepath); auditListener.reset(); checker.process(Collections.singletonList(fileToAnalyze)); return auditListener.getMetrics(); } catch (CheckstyleException | IOException e) { throw new AnalyzerException(e); } finally { if (fileToAnalyze != null && !fileToAnalyze.delete()) { logger.warn("Could not delete temporary file {}", fileToAnalyze); } } }
CheckstyleSourceCodeFileAnalyzerPlugin implements SourceCodeFileAnalyzerPlugin, ConfigurableAnalyzerPlugin { @Override public FileMetrics analyzeFile(String filepath, byte[] fileContent) { File fileToAnalyze = null; try { fileToAnalyze = createTempFile(fileContent, filepath); auditListener.reset(); checker.process(Collections.singletonList(fileToAnalyze)); return auditListener.getMetrics(); } catch (CheckstyleException | IOException e) { throw new AnalyzerException(e); } finally { if (fileToAnalyze != null && !fileToAnalyze.delete()) { logger.warn("Could not delete temporary file {}", fileToAnalyze); } } } }
CheckstyleSourceCodeFileAnalyzerPlugin implements SourceCodeFileAnalyzerPlugin, ConfigurableAnalyzerPlugin { @Override public FileMetrics analyzeFile(String filepath, byte[] fileContent) { File fileToAnalyze = null; try { fileToAnalyze = createTempFile(fileContent, filepath); auditListener.reset(); checker.process(Collections.singletonList(fileToAnalyze)); return auditListener.getMetrics(); } catch (CheckstyleException | IOException e) { throw new AnalyzerException(e); } finally { if (fileToAnalyze != null && !fileToAnalyze.delete()) { logger.warn("Could not delete temporary file {}", fileToAnalyze); } } } CheckstyleSourceCodeFileAnalyzerPlugin(); }
CheckstyleSourceCodeFileAnalyzerPlugin implements SourceCodeFileAnalyzerPlugin, ConfigurableAnalyzerPlugin { @Override public FileMetrics analyzeFile(String filepath, byte[] fileContent) { File fileToAnalyze = null; try { fileToAnalyze = createTempFile(fileContent, filepath); auditListener.reset(); checker.process(Collections.singletonList(fileToAnalyze)); return auditListener.getMetrics(); } catch (CheckstyleException | IOException e) { throw new AnalyzerException(e); } finally { if (fileToAnalyze != null && !fileToAnalyze.delete()) { logger.warn("Could not delete temporary file {}", fileToAnalyze); } } } CheckstyleSourceCodeFileAnalyzerPlugin(); @Override AnalyzerFileFilter getFilter(); @Override FileMetrics analyzeFile(String filepath, byte[] fileContent); @Override boolean isValidConfigurationFile(byte[] configurationFile); @Override void configure(byte[] configurationFile); }
CheckstyleSourceCodeFileAnalyzerPlugin implements SourceCodeFileAnalyzerPlugin, ConfigurableAnalyzerPlugin { @Override public FileMetrics analyzeFile(String filepath, byte[] fileContent) { File fileToAnalyze = null; try { fileToAnalyze = createTempFile(fileContent, filepath); auditListener.reset(); checker.process(Collections.singletonList(fileToAnalyze)); return auditListener.getMetrics(); } catch (CheckstyleException | IOException e) { throw new AnalyzerException(e); } finally { if (fileToAnalyze != null && !fileToAnalyze.delete()) { logger.warn("Could not delete temporary file {}", fileToAnalyze); } } } CheckstyleSourceCodeFileAnalyzerPlugin(); @Override AnalyzerFileFilter getFilter(); @Override FileMetrics analyzeFile(String filepath, byte[] fileContent); @Override boolean isValidConfigurationFile(byte[] configurationFile); @Override void configure(byte[] configurationFile);  }