diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-12 11:21:41 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-12-12 11:21:41 +0100 |
commit | 8609582eb85fa4ae31c90dc364fe8671cb9255c4 (patch) | |
tree | cd1b2b3927c76e20fd7c6b32674c1a38a5a44eda /sonar-core/src | |
parent | 3df15859c4f9a48a65ca11d81a34889f7efb6c4f (diff) | |
download | sonarqube-8609582eb85fa4ae31c90dc364fe8671cb9255c4.tar.gz sonarqube-8609582eb85fa4ae31c90dc364fe8671cb9255c4.zip |
SONAR-4535 Add searchProfile action
Diffstat (limited to 'sonar-core/src')
10 files changed, 307 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java index ac31792e5d0..36587a7a6d2 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java @@ -31,6 +31,7 @@ import org.sonar.core.permission.PermissionDao; import org.sonar.core.permission.PermissionTemplateDao; import org.sonar.core.properties.PropertiesDao; import org.sonar.core.purge.PurgeDao; +import org.sonar.core.qualityprofile.db.QualityProfileDao; import org.sonar.core.resource.ResourceDao; import org.sonar.core.resource.ResourceIndexerDao; import org.sonar.core.resource.ResourceKeyUpdaterDao; @@ -70,6 +71,7 @@ public final class DaoUtils { PermissionDao.class, PermissionTemplateDao.class, PropertiesDao.class, + QualityProfileDao.class, PurgeDao.class, CharacteristicDao.class, ResourceIndexerDao.class, diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 9f0576f8b38..1a112a7de87 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -55,6 +55,8 @@ import org.sonar.core.properties.PropertiesMapper; import org.sonar.core.properties.PropertyDto; import org.sonar.core.purge.PurgeMapper; import org.sonar.core.purge.PurgeableSnapshotDto; +import org.sonar.core.qualityprofile.db.QualityProfileDto; +import org.sonar.core.qualityprofile.db.QualityProfileMapper; import org.sonar.core.resource.*; import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleMapper; @@ -136,6 +138,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "Characteristic", CharacteristicDto.class); loadAlias(conf, "UserWithPermission", UserWithPermissionDto.class); loadAlias(conf, "GroupWithPermission", GroupWithPermissionDto.class); + loadAlias(conf, "QualityProfile", QualityProfileDto.class); // AuthorizationMapper has to be loaded before IssueMapper because this last one used it loadMapper(conf, "org.sonar.core.user.AuthorizationMapper"); @@ -151,7 +154,7 @@ public class MyBatis implements BatchComponent, ServerComponent { SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class, NotificationQueueMapper.class, CharacteristicMapper.class, - GroupMembershipMapper.class + GroupMembershipMapper.class, QualityProfileMapper.class }; loadMappers(conf, mappers); configureLogback(mappers); 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 new file mode 100644 index 00000000000..8abf40b311d --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java @@ -0,0 +1,46 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.qualityprofile.db; + +import org.apache.ibatis.session.SqlSession; +import org.sonar.api.ServerComponent; +import org.sonar.core.persistence.MyBatis; + +import java.util.List; + +public class QualityProfileDao implements ServerComponent { + + private final MyBatis mybatis; + + public QualityProfileDao(MyBatis mybatis) { + this.mybatis = mybatis; + } + + public List<QualityProfileDto> selectAll() { + SqlSession session = mybatis.openSession(); + try { + return session.getMapper(QualityProfileMapper.class).selectAll(); + } finally { + MyBatis.closeQuietly(session); + } + } + +} diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDto.java new file mode 100644 index 00000000000..d390016ba89 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDto.java @@ -0,0 +1,85 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.qualityprofile.db; + +public class QualityProfileDto { + + private Integer id; + private String name; + private String language; + private String parent; + private Integer version; + private boolean used; + + public Integer getId() { + return id; + } + + public QualityProfileDto setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public QualityProfileDto setName(String name) { + this.name = name; + return this; + } + + public String getLanguage() { + return language; + } + + public QualityProfileDto setLanguage(String language) { + this.language = language; + return this; + } + + public String getParent() { + return parent; + } + + public QualityProfileDto setParent(String parent) { + this.parent = parent; + return this; + } + + public Integer getVersion() { + return version; + } + + public QualityProfileDto setVersion(Integer version) { + this.version = version; + return this; + } + + public boolean isUsed() { + return used; + } + + public QualityProfileDto setUsed(boolean used) { + this.used = used; + return this; + } +} 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 new file mode 100644 index 00000000000..8e39c65a680 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java @@ -0,0 +1,29 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.qualityprofile.db; + +import java.util.List; + +public interface QualityProfileMapper { + + List<QualityProfileDto> selectAll(); + +} diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/package-info.java new file mode 100644 index 00000000000..40eeac04ff2 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.core.qualityprofile.db; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/package-info.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/package-info.java new file mode 100644 index 00000000000..0965f310037 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +@ParametersAreNonnullByDefault +package org.sonar.core.qualityprofile; + +import javax.annotation.ParametersAreNonnullByDefault; 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 new file mode 100644 index 00000000000..829b765e8e8 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="org.sonar.core.qualityprofile.db.QualityProfileMapper"> + + <sql id="profilesColumns"> + p.id, + p.name as name, + p.language as language, + p.parent_name as parent, + p.version as version, + p.used_profile as used + </sql> + + <select id="selectAll" parameterType="map" resultType="QualityProfile"> + select <include refid="profilesColumns"/> + from rules_profiles p + </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 new file mode 100644 index 00000000000..8718b7843df --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/qualityprofile/db/QualityProfileDaoTest.java @@ -0,0 +1,65 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.qualityprofile.db; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.core.persistence.AbstractDaoTestCase; + +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; + +public class QualityProfileDaoTest extends AbstractDaoTestCase { + + QualityProfileDao dao; + + @Before + public void createDao() { + dao = new QualityProfileDao(getMyBatis()); + } + + @Test + public void select_all() { + setupData("shared"); + + List<QualityProfileDto> dtos = dao.selectAll(); + + assertThat(dtos).hasSize(2); + + QualityProfileDto dto1 = dtos.get(0); + assertThat(dto1.getId()).isEqualTo(1); + assertThat(dto1.getName()).isEqualTo("Sonar way"); + assertThat(dto1.getLanguage()).isEqualTo("java"); + assertThat(dto1.getParent()).isNull(); + assertThat(dto1.getVersion()).isEqualTo(1); + assertThat(dto1.isUsed()).isFalse(); + + QualityProfileDto dto2 = dtos.get(1); + assertThat(dto2.getId()).isEqualTo(2); + assertThat(dto2.getName()).isEqualTo("Sonar way"); + assertThat(dto2.getLanguage()).isEqualTo("js"); + assertThat(dto2.getParent()).isNull(); + assertThat(dto2.getVersion()).isEqualTo(1); + assertThat(dto2.isUsed()).isFalse(); + } + +} diff --git a/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml new file mode 100644 index 00000000000..45e95e254d8 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml @@ -0,0 +1,9 @@ +<dataset> + + <rules_profiles id="1" name="Sonar way" language="java" parent_name="[null]" version="1" + used_profile="[false]"/> + + <rules_profiles id="2" name="Sonar way" language="js" parent_name="[null]" version="1" + used_profile="[false]"/> + +</dataset> |