diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-07-24 09:21:51 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-07-24 09:21:51 +0200 |
commit | ef9869ca12457efb552c7abd4517c334ed839c66 (patch) | |
tree | 69c929a2e99d64b0db3b0dab64c523f6ce134c38 /sonar-core/src | |
parent | e4fdef49e36d269ef5365a3056af67c8c3d5aceb (diff) | |
download | sonarqube-ef9869ca12457efb552c7abd4517c334ed839c66.tar.gz sonarqube-ef9869ca12457efb552c7abd4517c334ed839c66.zip |
SONAR-5417 Return quality profiles and settings by module
Diffstat (limited to 'sonar-core/src')
7 files changed, 77 insertions, 11 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java index cb8c8dac1a0..9d74af46428 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java @@ -19,8 +19,11 @@ */ package org.sonar.core.component.db; +import org.apache.ibatis.annotations.Param; import org.sonar.core.component.ComponentDto; +import java.util.List; + /** * @since 4.3 */ @@ -30,6 +33,8 @@ public interface ComponentMapper { ComponentDto selectById(long id); + List<ComponentDto> findModulesByProject(@Param("projectKey") String projectKey); + long countById(long id); void insert(ComponentDto rule); diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java index 756ed70d824..4357258a1b4 100644 --- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java +++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java @@ -95,11 +95,14 @@ public class PropertiesDao implements BatchComponent, ServerComponent, DaoCompon } } + public List<PropertyDto> selectProjectProperties(String resourceKey, SqlSession session) { + return session.getMapper(PropertiesMapper.class).selectProjectProperties(resourceKey); + } + public List<PropertyDto> selectProjectProperties(String resourceKey) { SqlSession session = mybatis.openSession(false); - PropertiesMapper mapper = session.getMapper(PropertiesMapper.class); try { - return mapper.selectProjectProperties(resourceKey); + return selectProjectProperties(resourceKey, session); } finally { MyBatis.closeQuietly(session); } diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java index 45189d64df9..01244ef1ae2 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java @@ -187,12 +187,17 @@ public class QualityProfileDao implements ServerComponent, DaoComponent { public QualityProfileDto getByProjectAndLanguage(long projectId, String language, String key) { DbSession session = mybatis.openSession(false); try { - return session.getMapper(QualityProfileMapper.class).selectByProjectAndLanguage(projectId, language, key); + return session.getMapper(QualityProfileMapper.class).selectByProjectIdAndLanguage(projectId, language, key); } finally { MyBatis.closeQuietly(session); } } + @CheckForNull + public QualityProfileDto getByProjectAndLanguage(String projectKey, String language, String propertyKeyPrefix, DbSession session) { + return session.getMapper(QualityProfileMapper.class).selectByProjectAndLanguage(projectKey, language, propertyKeyPrefix); + } + public List<QualityProfileDto> findByLanguage(String language) { DbSession session = mybatis.openSession(false); try { diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java index cef07f9a24a..3ba36880451 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java @@ -67,5 +67,7 @@ public interface QualityProfileMapper { int countProjects(@Param("value") String propertyValue, @Param("key") String propertyKey); - QualityProfileDto selectByProjectAndLanguage(@Param("projectId") Long projectId, @Param("language") String language, @Param("key") String propertyKeyPrefix); + QualityProfileDto selectByProjectIdAndLanguage(@Param("projectId") Long projectId, @Param("language") String language, @Param("key") String propertyKeyPrefix); + + QualityProfileDto selectByProjectAndLanguage(@Param("projectKey") String projectKey, @Param("language") String language, @Param("propertyKey") String propertyKeyPrefix); } diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml index de9ad8a46b5..f0dc353a03a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml @@ -18,21 +18,41 @@ <select id="selectByKey" parameterType="String" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p - INNER JOIN snapshots s on s.project_id=p.id and s.islast=${_true} - WHERE p.enabled=${_true} AND p.kee=#{key} + INNER JOIN snapshots s ON s.project_id=p.id AND s.islast=${_true} + <where> + AND p.enabled=${_true} + AND p.kee=#{key} + </where> </select> <select id="selectById" parameterType="long" resultType="Component"> SELECT <include refid="componentColumns"/> FROM projects p - INNER JOIN snapshots s on s.project_id=p.id and s.islast=${_true} - WHERE p.enabled=${_true} AND p.id=#{id} + INNER JOIN snapshots s ON s.project_id=p.id AND s.islast=${_true} + <where> + AND p.enabled=${_true} + AND p.id=#{id} + </where> </select> <select id="countById" parameterType="long" resultType="long"> SELECT count(p.id) FROM projects p - WHERE p.enabled=${_true} AND p.id=#{id} + <where> + AND p.enabled=${_true} + AND p.id=#{id} + </where> + </select> + + <select id="findModulesByProject" parameterType="String" resultType="Component"> + SELECT <include refid="componentColumns"/> + FROM projects p + INNER JOIN projects root ON root.id=p.root_id AND root.enabled=${_true} AND root.kee=#{projectKey} + INNER JOIN snapshots s ON s.project_id=p.id AND s.islast=${_true} + <where> + AND p.enabled=${_true} + AND p.scope='PRJ' + </where> </select> <sql id="insertColumns"> diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml index 84c2ae5e101..b8a6ea50889 100644 --- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml @@ -114,7 +114,7 @@ </where> </select> - <select id="selectByProjectAndLanguage" parameterType="map" resultType="QualityProfile"> + <select id="selectByProjectIdAndLanguage" parameterType="map" resultType="QualityProfile"> SELECT <include refid="profilesColumns"/> FROM rules_profiles p INNER JOIN properties prop ON prop.resource_id=#{projectId} @@ -123,5 +123,17 @@ WHERE p.language=#{language} </select> + <select id="selectByProjectAndLanguage" parameterType="map" resultType="QualityProfile"> + SELECT <include refid="profilesColumns"/> + FROM rules_profiles p, projects project + INNER JOIN properties prop ON prop.resource_id=project.id + <where> + AND p.language=#{language} + AND prop.prop_key LIKE #{propertyKey} + AND prop.text_value LIKE p.name + AND project.kee=#{projectKey} + </where> + </select> + </mapper> diff --git a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java index 1f1c8554acf..21386e7be70 100644 --- a/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java @@ -20,6 +20,7 @@ package org.sonar.core.qualityprofile.db; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.sonar.api.utils.System2; @@ -36,14 +37,21 @@ import static org.mockito.Mockito.when; public class QualityProfileDaoTest extends AbstractDaoTestCase { QualityProfileDao dao; + DbSession session; System2 system = mock(System2.class); @Before public void createDao() { + this.session = getMyBatis().openSession(false); dao = new QualityProfileDao(getMyBatis(), system); when(system.now()).thenReturn(UtcDateUtils.parseDateTime("2014-01-20T12:00:00+0000").getTime()); } + @After + public void after() { + this.session.close(); + } + @Test public void insert() { setupData("shared"); @@ -217,10 +225,21 @@ public class QualityProfileDaoTest extends AbstractDaoTestCase { } @Test - public void select_by_project_and_language() { + public void select_by_project_id_and_language() { setupData("projects"); QualityProfileDto dto = dao.getByProjectAndLanguage(1L, "java", "sonar.profile.java"); assertThat(dto.getId()).isEqualTo(1); } + + @Test + public void select_by_project_key_and_language() { + setupData("projects"); + + QualityProfileDto dto = dao.getByProjectAndLanguage("org.codehaus.sonar:sonar", "java", "sonar.profile.java", session); + assertThat(dto.getId()).isEqualTo(1); + + assertThat(dao.getByProjectAndLanguage("org.codehaus.sonar:sonar", "unkown", "sonar.profile.java", session)).isNull(); + assertThat(dao.getByProjectAndLanguage("unknown", "java", "sonar.profile.java", session)).isNull(); + } } |