diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-07 23:23:23 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-07 23:23:23 +0000 |
commit | 3cc63963cfd20176c605c27f023fb6e70db69b80 (patch) | |
tree | eed6fd559c6877052a4ef3ce2c0ebb845c41ea66 /sonar-core | |
parent | 0b9d0acd74b08a9076cd982684f0be8285c94251 (diff) | |
download | sonarqube-3cc63963cfd20176c605c27f023fb6e70db69b80.tar.gz sonarqube-3cc63963cfd20176c605c27f023fb6e70db69b80.zip |
SONAR-1549 The Sonar profile creation form doesn't allow to import checkstyle,pmd and Findbugs conf files when several langages are defined
SONAR-440 add warnings to checkstyle when importing configuration
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java | 18 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java | 8 |
2 files changed, 19 insertions, 7 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java index faac5971355..0512cff60e9 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java @@ -20,6 +20,7 @@ package org.sonar.core.rule; import org.apache.commons.lang.StringUtils; +import org.sonar.api.database.DatabaseSession; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleProvider; import org.sonar.api.rules.RuleQuery; @@ -43,30 +44,33 @@ public class DefaultRuleProvider implements RuleProvider { } public Rule find(RuleQuery query) { - return (Rule) createHqlQuery(query).getSingleResult(); + DatabaseSession session = sessionFactory.getSession(); + return (Rule)session.getSingleResult(createHqlQuery(session, query), null); + } public Collection<Rule> findAll(RuleQuery query) { - return createHqlQuery(query).getResultList(); + DatabaseSession session = sessionFactory.getSession(); + return createHqlQuery(session, query).getResultList(); } - private Query createHqlQuery(RuleQuery query) { + private Query createHqlQuery(DatabaseSession session, RuleQuery query) { StringBuilder hql = new StringBuilder().append("from ").append(Rule.class.getSimpleName()).append(" where enabled=true "); Map<String,Object> params = new HashMap<String,Object>(); if (StringUtils.isNotBlank(query.getRepositoryKey())) { - hql.append("AND pluginName=:repositoryKey"); + hql.append("AND pluginName=:repositoryKey "); params.put("repositoryKey", query.getRepositoryKey()); } if (StringUtils.isNotBlank(query.getKey())) { - hql.append("AND key=:key"); + hql.append("AND key=:key "); params.put("key", query.getKey()); } if (StringUtils.isNotBlank(query.getConfigKey())) { - hql.append("AND configKey=:configKey"); + hql.append("AND configKey=:configKey "); params.put("configKey", query.getConfigKey()); } - Query hqlQuery = sessionFactory.getSession().createQuery(hql.toString()); + Query hqlQuery = session.createQuery(hql.toString()); for (Map.Entry<String, Object> entry : params.entrySet()) { hqlQuery.setParameter(entry.getKey(), entry.getValue()); } diff --git a/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java b/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java index 10830c4256f..69287804e8c 100644 --- a/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java @@ -45,6 +45,14 @@ public class DefaultRuleProviderTest extends AbstractDbUnitTestCase { } @Test + public void findReturnsNullIfNoResults() { + setupData("shared"); + DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory()); + assertNull(provider.findByKey("checkstyle", "unknown")); + assertNull(provider.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown"))); + } + + @Test public void findRepositoryRules() { setupData("shared"); DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory()); |