@Test void should_process_input_file() throws Exception { doAnswer((Answer<Void>) invocation -> { final InputStream inputStreamArg = (InputStream) invocation.getArguments()[0]; final List<String> inputStreamLines = new BufferedReader(new InputStreamReader(inputStreamArg)) .lines() .collect(Collectors.toList()); assertThat(inputStreamLines).containsExactly("Example source"); return null; }).when(processor).processSourceCode(any(InputStream.class), eq(rulesets), eq(ruleContext)); new PmdTemplate(configuration, processor).process(inputFile, rulesets, ruleContext); verify(ruleContext).setSourceCodeFilename(inputFile.uri().toString()); verify(processor).processSourceCode(any(InputStream.class), eq(rulesets), eq(ruleContext)); }
public void process(InputFile file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.uri().toString()); try (InputStream inputStream = file.inputStream()) { processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (RuntimeException | IOException | PMDException e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } }
PmdTemplate { public void process(InputFile file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.uri().toString()); try (InputStream inputStream = file.inputStream()) { processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (RuntimeException | IOException | PMDException e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } } }
PmdTemplate { public void process(InputFile file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.uri().toString()); try (InputStream inputStream = file.inputStream()) { processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (RuntimeException | IOException | PMDException e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } } PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); }
PmdTemplate { public void process(InputFile file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.uri().toString()); try (InputStream inputStream = file.inputStream()) { processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (RuntimeException | IOException | PMDException e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } } PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); static PmdTemplate create(String javaVersion, ClassLoader classloader, Charset charset); void process(InputFile file, RuleSets rulesets, RuleContext ruleContext); }
PmdTemplate { public void process(InputFile file, RuleSets rulesets, RuleContext ruleContext) { ruleContext.setSourceCodeFilename(file.uri().toString()); try (InputStream inputStream = file.inputStream()) { processor.processSourceCode(inputStream, rulesets, ruleContext); } catch (RuntimeException | IOException | PMDException e) { LOG.error("Fail to execute PMD. Following file is ignored: " + file, e); } } PmdTemplate(PMDConfiguration configuration, SourceCodeProcessor processor); static PmdTemplate create(String javaVersion, ClassLoader classloader, Charset charset); void process(InputFile file, RuleSets rulesets, RuleContext ruleContext);  }