@Test(expected = IllegalArgumentException.class) public void should_fail_if_message_not_provided_for_xPath_rule() { PmdRule rule = new PmdRule(PmdConstants.XPATH_CLASS); rule.addProperty(new PmdProperty(PmdConstants.XPATH_EXPRESSION_PARAM, "xpathExpression")); rule.setName("MyOwnRule"); exporter.processXPathRule("xpathKey", rule); }
@VisibleForTesting void processXPathRule(String sonarRuleKey, PmdRule rule) { if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) { rule.setRef(null); PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM); if (xpathMessage == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey); } rule.setMessage(xpathMessage.getValue()); rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM); PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM); if (xpathExp == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey); } xpathExp.setCdataValue(xpathExp.getValue()); rule.setClazz(PmdConstants.XPATH_CLASS); rule.setLanguage(JavaLanguageModule.TERSE_NAME); rule.setName(sonarRuleKey); } }
PmdProfileExporter extends ProfileExporter { @VisibleForTesting void processXPathRule(String sonarRuleKey, PmdRule rule) { if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) { rule.setRef(null); PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM); if (xpathMessage == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey); } rule.setMessage(xpathMessage.getValue()); rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM); PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM); if (xpathExp == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey); } xpathExp.setCdataValue(xpathExp.getValue()); rule.setClazz(PmdConstants.XPATH_CLASS); rule.setLanguage(JavaLanguageModule.TERSE_NAME); rule.setName(sonarRuleKey); } } }
PmdProfileExporter extends ProfileExporter { @VisibleForTesting void processXPathRule(String sonarRuleKey, PmdRule rule) { if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) { rule.setRef(null); PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM); if (xpathMessage == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey); } rule.setMessage(xpathMessage.getValue()); rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM); PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM); if (xpathExp == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey); } xpathExp.setCdataValue(xpathExp.getValue()); rule.setClazz(PmdConstants.XPATH_CLASS); rule.setLanguage(JavaLanguageModule.TERSE_NAME); rule.setName(sonarRuleKey); } } PmdProfileExporter(); }
PmdProfileExporter extends ProfileExporter { @VisibleForTesting void processXPathRule(String sonarRuleKey, PmdRule rule) { if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) { rule.setRef(null); PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM); if (xpathMessage == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey); } rule.setMessage(xpathMessage.getValue()); rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM); PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM); if (xpathExp == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey); } xpathExp.setCdataValue(xpathExp.getValue()); rule.setClazz(PmdConstants.XPATH_CLASS); rule.setLanguage(JavaLanguageModule.TERSE_NAME); rule.setName(sonarRuleKey); } } PmdProfileExporter(); @Override void exportProfile(RulesProfile profile, Writer writer); String exportProfile(String repositoryKey, RulesProfile profile); }
PmdProfileExporter extends ProfileExporter { @VisibleForTesting void processXPathRule(String sonarRuleKey, PmdRule rule) { if (PmdConstants.XPATH_CLASS.equals(rule.getRef())) { rule.setRef(null); PmdProperty xpathMessage = rule.getProperty(PmdConstants.XPATH_MESSAGE_PARAM); if (xpathMessage == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_MESSAGE_PARAM + "' should be set for PMD rule " + sonarRuleKey); } rule.setMessage(xpathMessage.getValue()); rule.removeProperty(PmdConstants.XPATH_MESSAGE_PARAM); PmdProperty xpathExp = rule.getProperty(PmdConstants.XPATH_EXPRESSION_PARAM); if (xpathExp == null) { throw new IllegalArgumentException("Property '" + PmdConstants.XPATH_EXPRESSION_PARAM + "' should be set for PMD rule " + sonarRuleKey); } xpathExp.setCdataValue(xpathExp.getValue()); rule.setClazz(PmdConstants.XPATH_CLASS); rule.setLanguage(JavaLanguageModule.TERSE_NAME); rule.setName(sonarRuleKey); } } PmdProfileExporter(); @Override void exportProfile(RulesProfile profile, Writer writer); String exportProfile(String repositoryKey, RulesProfile profile);  }