@Test public void should_contains_security_rules_if_present() { PhpRules.getRuleKeys().clear(); assertThat(PHPProfileDefinition.getSecurityRuleKeys()).isEmpty(); PhpRules.getRuleKeys().add("S3649"); assertThat(PHPProfileDefinition.getSecurityRuleKeys()).containsOnly(RuleKey.of("phpsecurity", "S3649")); }
@VisibleForTesting static Set<RuleKey> getSecurityRuleKeys() { try { Class<?> phpRulesClass = Class.forName("com.sonar.plugins.security.api.PhpRules"); Method getRuleKeysMethod = phpRulesClass.getMethod("getRuleKeys"); Set<String> ruleKeys = (Set<String>) getRuleKeysMethod.invoke(null); Method getRepositoryKeyMethod = phpRulesClass.getMethod("getRepositoryKey"); String repositoryKey = (String) getRepositoryKeyMethod.invoke(null); return ruleKeys.stream().map(k -> RuleKey.of(repositoryKey, k)).collect(Collectors.toSet()); } catch (ClassNotFoundException e) { LOG.debug("com.sonar.plugins.security.api.PhpRules is not found, " + securityRuleMessage(e)); } catch (NoSuchMethodException e) { LOG.debug("Method not found on com.sonar.plugins.security.api.PhpRules, " + securityRuleMessage(e)); } catch (IllegalAccessException e) { LOG.debug("[IllegalAccessException] " + securityRuleMessage(e)); } catch (InvocationTargetException e) { LOG.debug("[InvocationTargetException] " + securityRuleMessage(e)); } return new HashSet<>(); }
PHPProfileDefinition implements BuiltInQualityProfilesDefinition { @VisibleForTesting static Set<RuleKey> getSecurityRuleKeys() { try { Class<?> phpRulesClass = Class.forName("com.sonar.plugins.security.api.PhpRules"); Method getRuleKeysMethod = phpRulesClass.getMethod("getRuleKeys"); Set<String> ruleKeys = (Set<String>) getRuleKeysMethod.invoke(null); Method getRepositoryKeyMethod = phpRulesClass.getMethod("getRepositoryKey"); String repositoryKey = (String) getRepositoryKeyMethod.invoke(null); return ruleKeys.stream().map(k -> RuleKey.of(repositoryKey, k)).collect(Collectors.toSet()); } catch (ClassNotFoundException e) { LOG.debug("com.sonar.plugins.security.api.PhpRules is not found, " + securityRuleMessage(e)); } catch (NoSuchMethodException e) { LOG.debug("Method not found on com.sonar.plugins.security.api.PhpRules, " + securityRuleMessage(e)); } catch (IllegalAccessException e) { LOG.debug("[IllegalAccessException] " + securityRuleMessage(e)); } catch (InvocationTargetException e) { LOG.debug("[InvocationTargetException] " + securityRuleMessage(e)); } return new HashSet<>(); } }
PHPProfileDefinition implements BuiltInQualityProfilesDefinition { @VisibleForTesting static Set<RuleKey> getSecurityRuleKeys() { try { Class<?> phpRulesClass = Class.forName("com.sonar.plugins.security.api.PhpRules"); Method getRuleKeysMethod = phpRulesClass.getMethod("getRuleKeys"); Set<String> ruleKeys = (Set<String>) getRuleKeysMethod.invoke(null); Method getRepositoryKeyMethod = phpRulesClass.getMethod("getRepositoryKey"); String repositoryKey = (String) getRepositoryKeyMethod.invoke(null); return ruleKeys.stream().map(k -> RuleKey.of(repositoryKey, k)).collect(Collectors.toSet()); } catch (ClassNotFoundException e) { LOG.debug("com.sonar.plugins.security.api.PhpRules is not found, " + securityRuleMessage(e)); } catch (NoSuchMethodException e) { LOG.debug("Method not found on com.sonar.plugins.security.api.PhpRules, " + securityRuleMessage(e)); } catch (IllegalAccessException e) { LOG.debug("[IllegalAccessException] " + securityRuleMessage(e)); } catch (InvocationTargetException e) { LOG.debug("[InvocationTargetException] " + securityRuleMessage(e)); } return new HashSet<>(); } PHPProfileDefinition(SonarRuntime sonarRuntime); }
PHPProfileDefinition implements BuiltInQualityProfilesDefinition { @VisibleForTesting static Set<RuleKey> getSecurityRuleKeys() { try { Class<?> phpRulesClass = Class.forName("com.sonar.plugins.security.api.PhpRules"); Method getRuleKeysMethod = phpRulesClass.getMethod("getRuleKeys"); Set<String> ruleKeys = (Set<String>) getRuleKeysMethod.invoke(null); Method getRepositoryKeyMethod = phpRulesClass.getMethod("getRepositoryKey"); String repositoryKey = (String) getRepositoryKeyMethod.invoke(null); return ruleKeys.stream().map(k -> RuleKey.of(repositoryKey, k)).collect(Collectors.toSet()); } catch (ClassNotFoundException e) { LOG.debug("com.sonar.plugins.security.api.PhpRules is not found, " + securityRuleMessage(e)); } catch (NoSuchMethodException e) { LOG.debug("Method not found on com.sonar.plugins.security.api.PhpRules, " + securityRuleMessage(e)); } catch (IllegalAccessException e) { LOG.debug("[IllegalAccessException] " + securityRuleMessage(e)); } catch (InvocationTargetException e) { LOG.debug("[InvocationTargetException] " + securityRuleMessage(e)); } return new HashSet<>(); } PHPProfileDefinition(SonarRuntime sonarRuntime); @Override void define(Context context); }
PHPProfileDefinition implements BuiltInQualityProfilesDefinition { @VisibleForTesting static Set<RuleKey> getSecurityRuleKeys() { try { Class<?> phpRulesClass = Class.forName("com.sonar.plugins.security.api.PhpRules"); Method getRuleKeysMethod = phpRulesClass.getMethod("getRuleKeys"); Set<String> ruleKeys = (Set<String>) getRuleKeysMethod.invoke(null); Method getRepositoryKeyMethod = phpRulesClass.getMethod("getRepositoryKey"); String repositoryKey = (String) getRepositoryKeyMethod.invoke(null); return ruleKeys.stream().map(k -> RuleKey.of(repositoryKey, k)).collect(Collectors.toSet()); } catch (ClassNotFoundException e) { LOG.debug("com.sonar.plugins.security.api.PhpRules is not found, " + securityRuleMessage(e)); } catch (NoSuchMethodException e) { LOG.debug("Method not found on com.sonar.plugins.security.api.PhpRules, " + securityRuleMessage(e)); } catch (IllegalAccessException e) { LOG.debug("[IllegalAccessException] " + securityRuleMessage(e)); } catch (InvocationTargetException e) { LOG.debug("[InvocationTargetException] " + securityRuleMessage(e)); } return new HashSet<>(); } PHPProfileDefinition(SonarRuntime sonarRuntime); @Override void define(Context context); static final String SONAR_WAY_PROFILE; static final String SONAR_WAY_PATH; }