PMDCommandLineInterface { public static PMDParameters extractParameters(PMDParameters arguments, String[] args, String progName) { JCommander jcommander = new JCommander(arguments); jcommander.setProgramName(progName); try { jcommander.parse(args); if (arguments.isHelp()) { jcommander.usage(); System.out.println(buildUsageText()); setStatusCodeOrExit(NO_ERRORS_STATUS); } } catch (ParameterException e) { jcommander.usage(); System.out.println(buildUsageText()); System.err.println(e.getMessage()); setStatusCodeOrExit(ERROR_STATUS); } return arguments; } private  PMDCommandLineInterface(); static PMDParameters extractParameters(PMDParameters arguments, String[] args, String progName); static String buildUsageText(); @Deprecated static String buildUsageText(JCommander jcommander); static void main(String[] args); static String jarName(); static void run(String[] args); static void setStatusCodeOrExit(int status); static final String PROG_NAME; static final String NO_EXIT_AFTER_RUN; static final String STATUS_CODE_PROPERTY; static final int NO_ERRORS_STATUS; static final int ERROR_STATUS; static final int VIOLATIONS_FOUND; }
@Test public void testProperties() { PMDParameters params = new PMDParameters(); String[] args = { "-d", "source_folder", "-f", "yahtml", "-P", "outputDir=output_folder", "-R", "java-empty", }; PMDCommandLineInterface.extractParameters(params, args, "PMD"); Assert.assertEquals("output_folder", params.getProperties().getProperty("outputDir")); }
@Test public void testMultipleProperties() { PMDParameters params = new PMDParameters(); String[] args = { "-d", "source_folder", "-f", "ideaj", "-P", "sourcePath=/home/user/source/", "-P", "fileName=Foo.java", "-P", "classAndMethodName=Foo.method", "-R", "java-empty", }; PMDCommandLineInterface.extractParameters(params, args, "PMD"); Assert.assertEquals("/home/user/source/", params.getProperties().getProperty("sourcePath")); Assert.assertEquals("Foo.java", params.getProperties().getProperty("fileName")); Assert.assertEquals("Foo.method", params.getProperties().getProperty("classAndMethodName")); }
@Test public void testNoCacheSwitch() { PMDParameters params = new PMDParameters(); String[] args = {"-d", "source_folder", "-f", "ideaj", "-R", "java-empty", "-cache", "/home/user/.pmd/cache", "-no-cache", }; PMDCommandLineInterface.extractParameters(params, args, "PMD"); assertTrue(params.isIgnoreIncrementalAnalysis()); PMDConfiguration config = params.toConfiguration(); assertTrue(config.isIgnoreIncrementalAnalysis()); assertTrue(config.getAnalysisCache() instanceof NoopAnalysisCache); }