public static PMDConfiguration transformParametersIntoConfiguration( PMDParameters params, String path) { PMDConfiguration configuration = new PMDConfiguration(); configuration.setInputPaths(path); configuration.setReportFormat("text"); configuration.setBenchmark(params.isBenchmark()); configuration.setDebug(params.isDebug()); configuration.setMinimumPriority(params.getMinimumPriority()); configuration.setReportFile(params.getReportfile()); configuration.setReportProperties(params.getProperties()); configuration.setReportShortNames(params.isShortnames()); configuration.setRuleSets("java-stanly,java-basic,java-naming"); configuration.setShowSuppressedViolations(params.isShowsuppressed()); configuration.setSourceEncoding(params.getEncoding()); configuration.setStressTest(params.isStress()); configuration.setSuppressMarker(params.getSuppressmarker()); configuration.setThreads(params.getThreads()); for (LanguageVersion language : LanguageVersion.findVersionsForLanguageTerseName(params.getLanguage())) { configuration .getLanguageVersionDiscoverer() .setDefaultLanguageVersion(language.getLanguage().getVersion(params.getVersion())); } try { configuration.prependClasspath(params.getAuxclasspath()); } catch (IOException e) { throw new IllegalArgumentException("Invalid auxiliary classpath: " + e.getMessage(), e); } return configuration; }
private static Set<Language> getApplicableLanguages( PMDConfiguration configuration, RuleSets ruleSets) { Set<Language> languages = new HashSet<Language>(); LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer(); for (Rule rule : ruleSets.getAllRules()) { Language language = rule.getLanguage(); if (languages.contains(language)) continue; LanguageVersion version = discoverer.getDefaultLanguageVersion(language); if (RuleSet.applies(rule, version)) { languages.add(language); } } return languages; }