JavaScriptProfilesDefinition implements BuiltInQualityProfilesDefinition { @VisibleForTesting static Set<RuleKey> getSecurityRuleKeys(String className, String ruleKeysMethodName, String language) { try { Class<?> rulesClass = Class.forName(className); Method getRuleKeysMethod = rulesClass.getMethod(ruleKeysMethodName, String.class); return (Set<RuleKey>) getRuleKeysMethod.invoke(null, language); } catch (ClassNotFoundException e) { LOG.debug(className + " is not found, " + securityRuleMessage(e)); } catch (NoSuchMethodException e) { LOG.debug("Method not found on " + className +", " + securityRuleMessage(e)); } catch (IllegalAccessException | InvocationTargetException e) { LOG.debug(e.getClass().getSimpleName() + ": " + securityRuleMessage(e)); } return Collections.emptySet(); }  @Override void define(Context context); static final String RESOURCE_PATH; static final String SONAR_WAY_JSON; static final String SONAR_WAY_RECOMMENDED_JSON; static final String SECURITY_RULE_KEYS_METHOD_NAME; }
@Test public void should_contains_security_rules_if_available() { assertThat(getSecurityRuleKeys(SECURITY_RULES_CLASS_NAME, SECURITY_RULE_KEYS_METHOD_NAME, "js")) .isEmpty(); assertThat(getSecurityRuleKeys(SECURITY_RULES_CLASS_NAME, SECURITY_RULE_KEYS_METHOD_NAME, "ts")) .isEmpty(); JsRules.JS_RULES.add(RuleKey.parse("jssecurity:S3649")); assertThat(getSecurityRuleKeys(SECURITY_RULES_CLASS_NAME, SECURITY_RULE_KEYS_METHOD_NAME, "js")) .containsOnly(RuleKey.of("jssecurity", "S3649")); JsRules.TS_RULES.add(RuleKey.parse("tssecurity:S3649")); assertThat(getSecurityRuleKeys(SECURITY_RULES_CLASS_NAME, SECURITY_RULE_KEYS_METHOD_NAME, "ts")) .containsOnly(RuleKey.of("tssecurity", "S3649")); assertThat(getSecurityRuleKeys("xxx", SECURITY_RULE_KEYS_METHOD_NAME, "js")).isEmpty(); assertThat(getSecurityRuleKeys(SECURITY_RULES_CLASS_NAME, "xxx", "js")).isEmpty(); JsRules.clear(); }