CPDCommandLineInterface { public static void main(String[] args) { CPDConfiguration arguments = new CPDConfiguration(); JCommander jcommander = new JCommander(arguments); jcommander.setProgramName(PROGRAM_NAME); try { jcommander.parse(args); if (arguments.isHelp()) { jcommander.usage(); System.out.println(buildUsageText()); setStatusCodeOrExit(NO_ERRORS_STATUS); return; } } catch (ParameterException e) { jcommander.usage(); System.out.println(buildUsageText()); System.err.println(" " + e.getMessage()); setStatusCodeOrExit(ERROR_STATUS); return; } arguments.postContruct(); CPDConfiguration.setSystemProperties(arguments); CPD cpd = new CPD(arguments); try { addSourceFilesToCPD(cpd, arguments); cpd.go(); if (arguments.getCPDRenderer() == null) { System.out.println(arguments.getRenderer().render(cpd.getMatches())); } else { arguments.getCPDRenderer().render(cpd.getMatches(), new BufferedWriter(new OutputStreamWriter(System.out))); } if (cpd.getMatches().hasNext()) { if (arguments.isFailOnViolation()) { setStatusCodeOrExit(DUPLICATE_CODE_FOUND); } else { setStatusCodeOrExit(NO_ERRORS_STATUS); } } else { setStatusCodeOrExit(NO_ERRORS_STATUS); } } catch (IOException | RuntimeException e) { e.printStackTrace(); setStatusCodeOrExit(ERROR_STATUS); } } private  CPDCommandLineInterface(); static void setStatusCodeOrExit(int status); static void main(String[] args); static void addSourceFilesToCPD(CPD cpd, CPDConfiguration arguments); static String buildUsageText(); static final String NO_EXIT_AFTER_RUN; static final String STATUS_CODE_PROPERTY; }
@Test public void testEmptyResultRendering() { System.setProperty(CPDCommandLineInterface.NO_EXIT_AFTER_RUN, "true"); CPDCommandLineInterface.main(new String[] { "--minimum-tokens", "340", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/files/", "--format", "xml", }); Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<pmd-cpd/>", log.getLog()); }