Browse Source

SONAR-9304 drop use of rules_profiles.is_default

tags/6.5-M1
Simon Brandhof 7 years ago
parent
commit
71987dfa5a
100 changed files with 875 additions and 596 deletions
  1. 1
    0
      server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
  2. 11
    1
      server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
  3. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
  4. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java
  5. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java
  6. 22
    22
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
  7. 14
    14
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java
  8. 15
    25
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java
  9. 22
    23
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
  10. 2
    2
      server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
  11. 3
    3
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
  12. 6
    6
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java
  13. 54
    55
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
  14. 19
    19
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
  15. 2
    2
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java
  16. 0
    1
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml
  17. 0
    6
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml
  18. 0
    3
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml
  19. 0
    2
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml
  20. 0
    3
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml
  21. 0
    3
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml
  22. 8
    2
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml
  23. 0
    2
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml
  24. 87
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java
  25. 3
    1
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
  26. 73
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropIsDefaultColumnFromRulesProfiles.java
  27. 67
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java
  28. 1
    1
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
  29. 43
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropIsDefaultColumnFromRulesProfilesTest.java
  30. 0
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql
  31. 16
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropIsDefaultColumnFromRulesProfilesTest/initial.sql
  32. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
  33. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
  34. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
  35. 5
    6
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
  36. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
  37. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
  38. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
  39. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
  40. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
  41. 8
    9
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
  42. 7
    7
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
  43. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java
  44. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
  45. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java
  46. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
  47. 15
    15
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
  48. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java
  49. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
  50. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java
  51. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java
  52. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java
  53. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
  54. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java
  55. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java
  56. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
  57. 7
    7
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
  58. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
  59. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java
  60. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
  61. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java
  62. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java
  63. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java
  64. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java
  65. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java
  66. 18
    11
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
  67. 15
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java
  68. 18
    18
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
  69. 5
    11
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java
  70. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
  71. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java
  72. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java
  73. 5
    3
      server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
  74. 11
    11
      server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java
  75. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
  76. 8
    8
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
  77. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
  78. 4
    4
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
  79. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
  80. 6
    8
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
  81. 8
    8
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java
  82. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java
  83. 11
    11
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java
  84. 7
    9
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java
  85. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java
  86. 4
    4
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
  87. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
  88. 4
    4
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java
  89. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java
  90. 20
    20
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
  91. 8
    8
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java
  92. 20
    20
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
  93. 7
    7
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java
  94. 12
    12
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java
  95. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java
  96. 15
    17
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java
  97. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
  98. 4
    4
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java
  99. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java
  100. 0
    0
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java

+ 1
- 0
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java View File

@@ -80,6 +80,7 @@ public final class SqTables {
"project_qprofiles",
"properties",
"qprofile_changes",
"qprofiles",
"rules",
"rules_metadata",
"rules_parameters",

+ 11
- 1
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl View File

@@ -51,7 +51,6 @@ CREATE TABLE "RULES_PROFILES" (
"KEE" VARCHAR(255) NOT NULL,
"PARENT_KEE" VARCHAR(255),
"RULES_UPDATED_AT" VARCHAR(100),
"IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"LAST_USED" BIGINT,
@@ -61,6 +60,17 @@ CREATE TABLE "RULES_PROFILES" (
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");


CREATE TABLE "QPROFILES" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
"PARENT_UUID" VARCHAR(40),
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
CREATE INDEX "QPROFILES_ORG_UUID" ON "QPROFILES" ("ORGANIZATION_UUID");


CREATE TABLE "DEFAULT_QPROFILES" (
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"LANGUAGE" VARCHAR(20) NOT NULL,

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java View File

@@ -97,7 +97,7 @@ import org.sonar.db.qualityprofile.ActiveRuleMapper;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileMapper;
import org.sonar.db.qualityprofile.QProfileChangeMapper;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileMapper;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleMapper;
@@ -166,7 +166,7 @@ public class MyBatis implements Startable {
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class);
confBuilder.loadAlias("QualityGate", QualityGateDto.class);
confBuilder.loadAlias("QualityProfile", QualityProfileDto.class);
confBuilder.loadAlias("RulesProfile", RulesProfileDto.class);
confBuilder.loadAlias("RequirementMigration", RequirementMigrationDto.class);
confBuilder.loadAlias("Resource", ResourceDto.class);
confBuilder.loadAlias("RuleParam", RuleParamDto.class);

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java View File

@@ -142,7 +142,7 @@ public class ActiveRuleDto {
return this;
}

public static ActiveRuleDto createFor(QualityProfileDto profileDto, RuleDefinitionDto ruleDto) {
public static ActiveRuleDto createFor(RulesProfileDto profileDto, RuleDefinitionDto ruleDto) {
requireNonNull(profileDto.getId(), "Profile is not persisted");
requireNonNull(ruleDto.getId(), "Rule is not persisted");
ActiveRuleDto dto = new ActiveRuleDto();

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java View File

@@ -52,7 +52,7 @@ public class DefaultQProfileDto {
return this;
}

public static DefaultQProfileDto from(QualityProfileDto profile) {
public static DefaultQProfileDto from(RulesProfileDto profile) {
return new DefaultQProfileDto()
.setOrganizationUuid(profile.getOrganizationUuid())
.setLanguage(profile.getLanguage())

+ 22
- 22
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java View File

@@ -49,35 +49,35 @@ public class QualityProfileDao implements Dao {
}

@CheckForNull
public QualityProfileDto selectByKey(DbSession session, String key) {
public RulesProfileDto selectByKey(DbSession session, String key) {
return mapper(session).selectByKey(key);
}

public QualityProfileDto selectOrFailByKey(DbSession session, String key) {
QualityProfileDto dto = selectByKey(session, key);
public RulesProfileDto selectOrFailByKey(DbSession session, String key) {
RulesProfileDto dto = selectByKey(session, key);
if (dto == null) {
throw new RowNotFoundException("Quality profile not found: " + key);
}
return dto;
}

public List<QualityProfileDto> selectByKeys(DbSession session, List<String> keys) {
public List<RulesProfileDto> selectByKeys(DbSession session, List<String> keys) {
return executeLargeInputs(keys, mapper(session)::selectByKeys);
}

public List<QualityProfileDto> selectAll(DbSession session, OrganizationDto organization) {
public List<RulesProfileDto> selectAll(DbSession session, OrganizationDto organization) {
return mapper(session).selectAll(organization.getUuid());
}

public void insert(DbSession session, QualityProfileDto profile, QualityProfileDto... otherProfiles) {
public void insert(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(session);
doInsert(mapper, profile);
for (QualityProfileDto other : otherProfiles) {
for (RulesProfileDto other : otherProfiles) {
doInsert(mapper, other);
}
}

private void doInsert(QualityProfileMapper mapper, QualityProfileDto profile) {
private void doInsert(QualityProfileMapper mapper, RulesProfileDto profile) {
Preconditions.checkArgument(profile.getId() == null, "Quality profile is already persisted (got id %d)", profile.getId());
Date now = new Date(system.now());
profile.setCreatedAt(now);
@@ -85,52 +85,52 @@ public class QualityProfileDao implements Dao {
mapper.insert(profile);
}

public void update(DbSession session, QualityProfileDto profile, QualityProfileDto... otherProfiles) {
public void update(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(session);
doUpdate(mapper, profile);
for (QualityProfileDto otherProfile : otherProfiles) {
for (RulesProfileDto otherProfile : otherProfiles) {
doUpdate(mapper, otherProfile);
}
}

private void doUpdate(QualityProfileMapper mapper, QualityProfileDto profile) {
private void doUpdate(QualityProfileMapper mapper, RulesProfileDto profile) {
Preconditions.checkArgument(profile.getId() != null, "Quality profile is not persisted");
profile.setUpdatedAt(new Date(system.now()));
mapper.update(profile);
}

public List<QualityProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languageKeys) {
public List<RulesProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languageKeys) {
return executeLargeInputs(languageKeys, chunk -> mapper(session).selectDefaultProfiles(organization.getUuid(), chunk));
}

@CheckForNull
public QualityProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) {
public RulesProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) {
return mapper(session).selectDefaultProfile(organization.getUuid(), language);
}

@CheckForNull
public QualityProfileDto selectByProjectAndLanguage(DbSession session, String projectKey, String language) {
public RulesProfileDto selectByProjectAndLanguage(DbSession session, String projectKey, String language) {
return mapper(session).selectByProjectAndLanguage(projectKey, language);
}

public List<QualityProfileDto> selectByProjectAndLanguages(DbSession session, OrganizationDto organization, ComponentDto project, Collection<String> languageKeys) {
public List<RulesProfileDto> selectByProjectAndLanguages(DbSession session, OrganizationDto organization, ComponentDto project, Collection<String> languageKeys) {
return executeLargeInputs(languageKeys, input -> mapper(session).selectByProjectAndLanguages(organization.getUuid(), project.getKey(), input));
}

public List<QualityProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
public List<RulesProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
return mapper(dbSession).selectByLanguage(organization.getUuid(), language);
}

public List<QualityProfileDto> selectChildren(DbSession session, String key) {
public List<RulesProfileDto> selectChildren(DbSession session, String key) {
return mapper(session).selectChildren(key);
}

/**
* All descendants, in the top-down order.
*/
public List<QualityProfileDto> selectDescendants(DbSession session, String key) {
List<QualityProfileDto> descendants = Lists.newArrayList();
for (QualityProfileDto child : selectChildren(session, key)) {
public List<RulesProfileDto> selectDescendants(DbSession session, String key) {
List<RulesProfileDto> descendants = Lists.newArrayList();
for (RulesProfileDto child : selectChildren(session, key)) {
descendants.add(child);
descendants.addAll(selectDescendants(session, child.getKey()));
}
@@ -138,11 +138,11 @@ public class QualityProfileDao implements Dao {
}

@CheckForNull
public QualityProfileDto selectByNameAndLanguage(OrganizationDto organization, String name, String language, DbSession session) {
public RulesProfileDto selectByNameAndLanguage(OrganizationDto organization, String name, String language, DbSession session) {
return mapper(session).selectByNameAndLanguage(organization.getUuid(), name, language);
}

public List<QualityProfileDto> selectByNameAndLanguages(OrganizationDto organization, String name, Collection<String> languageKeys, DbSession session) {
public List<RulesProfileDto> selectByNameAndLanguages(OrganizationDto organization, String name, Collection<String> languageKeys, DbSession session) {
return executeLargeInputs(languageKeys, input -> mapper(session).selectByNameAndLanguages(organization.getUuid(), name, input));
}


+ 14
- 14
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java View File

@@ -28,43 +28,43 @@ import org.sonar.db.KeyLongValue;

public interface QualityProfileMapper {

void insert(QualityProfileDto dto);
void insert(RulesProfileDto dto);

void update(QualityProfileDto dto);
void update(RulesProfileDto dto);

void deleteByKeys(@Param("profileKeys") Collection<String> profileKeys);

List<QualityProfileDto> selectAll(@Param("organizationUuid") String organizationUuid);
List<RulesProfileDto> selectAll(@Param("organizationUuid") String organizationUuid);

@CheckForNull
QualityProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
RulesProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language);

List<QualityProfileDto> selectDefaultProfiles(@Param("organizationUuid") String organizationUuid, @Param("languages") List<String> languages);
List<RulesProfileDto> selectDefaultProfiles(@Param("organizationUuid") String organizationUuid, @Param("languages") List<String> languages);

@CheckForNull
QualityProfileDto selectByNameAndLanguage(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("language") String language);
RulesProfileDto selectByNameAndLanguage(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("language") String language);

List<QualityProfileDto> selectByNameAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("languages") List<String> languages);
List<RulesProfileDto> selectByNameAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("languages") List<String> languages);

@CheckForNull
QualityProfileDto selectByKey(String key);
RulesProfileDto selectByKey(String key);

List<QualityProfileDto> selectByLanguage(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
List<RulesProfileDto> selectByLanguage(@Param("organizationUuid") String organizationUuid, @Param("language") String language);

List<QualityProfileDto> selectByKeys(@Param("keys") List<String> keys);
List<RulesProfileDto> selectByKeys(@Param("keys") List<String> keys);

// INHERITANCE

List<QualityProfileDto> selectChildren(String key);
List<RulesProfileDto> selectChildren(String key);

// PROJECTS

List<KeyLongValue> countProjectsByProfileKey(@Param("organizationUuid") String organizationUuid);

QualityProfileDto selectByProjectAndLanguage(@Param("projectKey") String projectKey, @Param("language") String language);
RulesProfileDto selectByProjectAndLanguage(@Param("projectKey") String projectKey, @Param("language") String language);

List<QualityProfileDto> selectByProjectAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("projectKey") String projectKey,
@Param("languages") List<String> input);
List<RulesProfileDto> selectByProjectAndLanguages(@Param("organizationUuid") String organizationUuid, @Param("projectKey") String projectKey,
@Param("languages") List<String> input);

void insertProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileKey") String profileKey);


server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDto.java → server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.organization.OrganizationDto;
/**
* Represents the table "rules_profiles"
*/
public class QualityProfileDto extends Dto<String> {
public class RulesProfileDto extends Dto<String> {

private Integer id;
/**
@@ -45,14 +45,13 @@ public class QualityProfileDto extends Dto<String> {
private String rulesUpdatedAt;
private Long lastUsed;
private Long userUpdatedAt;
private boolean isDefault;
private boolean isBuiltIn;

public String getOrganizationUuid() {
return organizationUuid;
}

public QualityProfileDto setOrganizationUuid(String organizationUuid) {
public RulesProfileDto setOrganizationUuid(String organizationUuid) {
this.organizationUuid = organizationUuid;
return this;
}
@@ -62,7 +61,7 @@ public class QualityProfileDto extends Dto<String> {
return kee;
}

public QualityProfileDto setKey(String s) {
public RulesProfileDto setKey(String s) {
return setKee(s);
}

@@ -70,7 +69,7 @@ public class QualityProfileDto extends Dto<String> {
return kee;
}

public QualityProfileDto setKee(String s) {
public RulesProfileDto setKee(String s) {
this.kee = s;
return this;
}
@@ -79,7 +78,7 @@ public class QualityProfileDto extends Dto<String> {
return id;
}

public QualityProfileDto setId(Integer id) {
public RulesProfileDto setId(Integer id) {
this.id = id;
return this;
}
@@ -88,7 +87,7 @@ public class QualityProfileDto extends Dto<String> {
return name;
}

public QualityProfileDto setName(String name) {
public RulesProfileDto setName(String name) {
this.name = name;
return this;
}
@@ -97,7 +96,7 @@ public class QualityProfileDto extends Dto<String> {
return language;
}

public QualityProfileDto setLanguage(String language) {
public RulesProfileDto setLanguage(String language) {
this.language = language;
return this;
}
@@ -107,7 +106,7 @@ public class QualityProfileDto extends Dto<String> {
return parentKee;
}

public QualityProfileDto setParentKee(@Nullable String s) {
public RulesProfileDto setParentKee(@Nullable String s) {
this.parentKee = s;
return this;
}
@@ -116,12 +115,12 @@ public class QualityProfileDto extends Dto<String> {
return rulesUpdatedAt;
}

public QualityProfileDto setRulesUpdatedAt(String s) {
public RulesProfileDto setRulesUpdatedAt(String s) {
this.rulesUpdatedAt = s;
return this;
}

public QualityProfileDto setRulesUpdatedAtAsDate(Date d) {
public RulesProfileDto setRulesUpdatedAtAsDate(Date d) {
this.rulesUpdatedAt = UtcDateUtils.formatDateTime(d);
return this;
}
@@ -131,7 +130,7 @@ public class QualityProfileDto extends Dto<String> {
return lastUsed;
}

public QualityProfileDto setLastUsed(@Nullable Long lastUsed) {
public RulesProfileDto setLastUsed(@Nullable Long lastUsed) {
this.lastUsed = lastUsed;
return this;
}
@@ -141,30 +140,21 @@ public class QualityProfileDto extends Dto<String> {
return userUpdatedAt;
}

public QualityProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
public RulesProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
this.userUpdatedAt = userUpdatedAt;
return this;
}

public boolean isDefault() {
return isDefault;
}

public QualityProfileDto setDefault(boolean isDefault) {
this.isDefault = isDefault;
return this;
}

public boolean isBuiltIn() {
return isBuiltIn;
}

public QualityProfileDto setIsBuiltIn(boolean b) {
public RulesProfileDto setIsBuiltIn(boolean b) {
this.isBuiltIn = b;
return this;
}

public static QualityProfileDto createFor(String key) {
return new QualityProfileDto().setKee(key);
public static RulesProfileDto createFor(String key) {
return new RulesProfileDto().setKee(key);
}
}

+ 22
- 23
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml View File

@@ -10,7 +10,6 @@
p.name as name,
p.language as language,
p.parent_kee as parentKee,
p.is_default as isDefault,
p.created_at as createdAt,
p.updated_at as updatedAt,
p.rules_updated_at as rulesUpdatedAt,
@@ -19,15 +18,14 @@
p.is_built_in as isBuiltIn
</sql>

<insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO rules_profiles (organization_uuid, kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used, user_updated_at, is_built_in)
<insert id="insert" parameterType="RulesProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO rules_profiles (organization_uuid, kee, parent_kee, name, language, created_at, updated_at, rules_updated_at, last_used, user_updated_at, is_built_in)
VALUES (
#{organizationUuid, jdbcType=VARCHAR},
#{kee, jdbcType=VARCHAR},
#{parentKee, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR},
#{language, jdbcType=VARCHAR},
#{isDefault, jdbcType=BOOLEAN},
#{createdAt, jdbcType=TIMESTAMP},
#{updatedAt, jdbcType=TIMESTAMP},
#{rulesUpdatedAt, jdbcType=VARCHAR},
@@ -37,11 +35,10 @@
)
</insert>

<update id="update" parameterType="QualityProfile">
<update id="update" parameterType="RulesProfile">
UPDATE rules_profiles SET
name=#{name, jdbcType=VARCHAR},
language=#{language, jdbcType=VARCHAR},
is_default=#{isDefault, jdbcType=BOOLEAN},
parent_kee=#{parentKee, jdbcType=VARCHAR},
updated_at=#{updatedAt, jdbcType=TIMESTAMP},
rules_updated_at=#{rulesUpdatedAt, jdbcType=VARCHAR},
@@ -57,7 +54,7 @@
<foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">#{profileKey, jdbcType=VARCHAR}</foreach>
</update>

<select id="selectAll" parameterType="map" resultType="QualityProfile">
<select id="selectAll" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -65,7 +62,7 @@
ORDER BY p.name, p.language
</select>

<select id="selectByNameAndLanguage" parameterType="map" resultType="QualityProfile">
<select id="selectByNameAndLanguage" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -76,7 +73,7 @@
</if>
</select>

<select id="selectByNameAndLanguages" parameterType="map" resultType="QualityProfile">
<select id="selectByNameAndLanguages" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -85,14 +82,14 @@
AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectByKey" parameterType="string" resultType="QualityProfile">
<select id="selectByKey" parameterType="string" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.kee=#{id}
</select>

<select id="selectByKeys" parameterType="string" resultType="QualityProfile">
<select id="selectByKeys" parameterType="string" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -102,7 +99,7 @@
</foreach>
</select>

<select id="selectByLanguage" parameterType="String" resultType="QualityProfile">
<select id="selectByLanguage" parameterType="String" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -111,7 +108,7 @@
ORDER BY p.name
</select>

<select id="selectChildren" parameterType="string" resultType="QualityProfile">
<select id="selectChildren" parameterType="string" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -119,22 +116,24 @@
ORDER BY p.name
</select>

<select id="selectDefaultProfile" parameterType="map" resultType="QualityProfile">
<select id="selectDefaultProfile" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.is_default=${_true}
AND p.language=#{language, jdbcType=VARCHAR}
AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
INNER JOIN default_qprofiles dp on p.kee=dp.qprofile_uuid
WHERE
dp.language=#{language, jdbcType=VARCHAR}
AND dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectDefaultProfiles" parameterType="map" resultType="QualityProfile">
<select id="selectDefaultProfiles" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.is_default=${_true}
AND p.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
INNER JOIN default_qprofiles dp on p.kee=dp.qprofile_uuid
WHERE
dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
AND dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
@@ -181,7 +180,7 @@
group by pp.profile_key
</select>

<select id="selectByProjectAndLanguage" parameterType="map" resultType="QualityProfile">
<select id="selectByProjectAndLanguage" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
@@ -190,7 +189,7 @@
WHERE p.language=#{language}
</select>

<select id="selectByProjectAndLanguages" parameterType="map" resultType="QualityProfile">
<select id="selectByProjectAndLanguages" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p

+ 2
- 2
server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java View File

@@ -41,7 +41,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.Oracle;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupTesting;
import org.sonar.db.user.UserDto;
@@ -877,7 +877,7 @@ public class OrganizationDaoTest {
public void selectWithoutQualityProfile_returns_() {
OrganizationDto orgWithoutAnyProfiles = dbTester.organizations().insert();
OrganizationDto orgWithProfiles = dbTester.organizations().insert();
QualityProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles);
RulesProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles);

assertThat(underTest.selectWithoutQualityProfile(dbSession, "js", "foo"))
.extracting(OrganizationDto::getUuid).containsExactlyInAnyOrder(orgWithoutAnyProfiles.getUuid(), orgWithProfiles.getUuid());

+ 3
- 3
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java View File

@@ -63,8 +63,8 @@ public class ActiveRuleDaoTest {

private OrganizationDto organization = OrganizationTesting.newOrganizationDto();

private QualityProfileDto profile1 = QualityProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
private QualityProfileDto profile2 = QualityProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2");
private RulesProfileDto profile1 = RulesProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
private RulesProfileDto profile2 = RulesProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2");

private RuleDefinitionDto rule1 = RuleTesting.newRule(RuleTesting.XOO_X1);
private RuleDefinitionDto rule2 = RuleTesting.newRule(RuleTesting.XOO_X2);
@@ -334,7 +334,7 @@ public class ActiveRuleDaoTest {
assertThat(dbTester.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1);
}

private static ActiveRuleDto newRow(QualityProfileDto profile, RuleDefinitionDto rule) {
private static ActiveRuleDto newRow(RulesProfileDto profile, RuleDefinitionDto rule) {
return createFor(profile, rule).setSeverity(BLOCKER);
}


+ 6
- 6
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java View File

@@ -42,7 +42,7 @@ public class DefaultQProfileDaoTest {
@Test
public void insertOrUpdate_inserts_row_when_does_not_exist() {
OrganizationDto org = dbTester.organizations().insert();
QualityProfileDto profile = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile = dbTester.qualityProfiles().insert(org);
DefaultQProfileDto dto = DefaultQProfileDto.from(profile);

underTest.insertOrUpdate(dbSession, dto);
@@ -94,8 +94,8 @@ public class DefaultQProfileDaoTest {
@Test
public void selectExistingQProfileUuids_filters_defaults() {
OrganizationDto org = dbTester.organizations().insert();
QualityProfileDto profile1 = dbTester.qualityProfiles().insert(org);
QualityProfileDto profile2 = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org);
dbTester.qualityProfiles().markAsDefault(profile1);

List<String> profileUuids = asList(profile1.getKee(), profile2.getKee(), "other");
@@ -106,8 +106,8 @@ public class DefaultQProfileDaoTest {
@Test
public void isDefault_returns_true_if_profile_is_marked_as_default() {
OrganizationDto org = dbTester.organizations().insert();
QualityProfileDto profile1 = dbTester.qualityProfiles().insert(org);
QualityProfileDto profile2 = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org);
dbTester.qualityProfiles().markAsDefault(profile1);

assertThat(underTest.isDefault(dbSession, org.getUuid(), profile1.getKee())).isTrue();
@@ -115,7 +115,7 @@ public class DefaultQProfileDaoTest {
assertThat(underTest.isDefault(dbSession, org.getUuid(), "does_not_exist")).isFalse();
}

private void assertThatIsDefault(OrganizationDto org, QualityProfileDto profile) {
private void assertThatIsDefault(OrganizationDto org, RulesProfileDto profile) {
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org, profile.getLanguage())).hasValue(profile.getKee());
assertThat(underTest.isDefault(dbSession, org.getUuid(), profile.getKee())).isTrue();
}

+ 54
- 55
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java View File

@@ -75,7 +75,7 @@ public class QualityProfileDaoTest {
public void insert() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

QualityProfileDto dto = QualityProfileDto.createFor("abcde")
RulesProfileDto dto = RulesProfileDto.createFor("abcde")
.setOrganizationUuid(organization.getUuid())
.setName("ABCDE")
.setLanguage("xoo")
@@ -91,13 +91,12 @@ public class QualityProfileDaoTest {
public void update() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

QualityProfileDto dto = QualityProfileDto.createFor("key")
RulesProfileDto dto = RulesProfileDto.createFor("key")
.setId(1)
.setOrganizationUuid(organization.getUuid())
.setName("New Name")
.setLanguage("js")
.setParentKee("fghij")
.setDefault(false)
.setIsBuiltIn(false);

underTest.update(dbSession, dto);
@@ -108,9 +107,9 @@ public class QualityProfileDaoTest {

@Test
public void test_deleteByKeys() {
QualityProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
QualityProfileDto p2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
QualityProfileDto p3 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto p2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto p3 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());

underTest.deleteByKeys(dbSession, asList(p1.getKey(), p3.getKey(), "does_not_exist"));

@@ -121,7 +120,7 @@ public class QualityProfileDaoTest {

@Test
public void deleteByKeys_does_nothing_if_empty_keys() {
QualityProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());

underTest.deleteByKeys(dbSession, Collections.emptyList());

@@ -130,7 +129,7 @@ public class QualityProfileDaoTest {

@Test
public void deleteProjectAssociationsByProfileKeys_does_nothing_if_empty_keys() {
QualityProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
ComponentDto project1 = dbTester.components().insertPrivateProject();
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);

@@ -141,8 +140,8 @@ public class QualityProfileDaoTest {

@Test
public void deleteProjectAssociationsByProfileKeys_deletes_rows_from_table_project_profiles() {
QualityProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
QualityProfileDto profile2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto profile2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
ComponentDto project1 = dbTester.components().insertPrivateProject();
ComponentDto project2 = dbTester.components().insertPrivateProject();
ComponentDto project3 = dbTester.components().insertPrivateProject();
@@ -162,18 +161,18 @@ public class QualityProfileDaoTest {
public void find_all() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

List<QualityProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);
List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);

assertThat(dtos).hasSize(2);

QualityProfileDto dto1 = dtos.get(0);
RulesProfileDto dto1 = dtos.get(0);
assertThat(dto1.getId()).isEqualTo(1);
assertThat(dto1.getName()).isEqualTo("Sonar Way");
assertThat(dto1.getLanguage()).isEqualTo("java");
assertThat(dto1.getParentKee()).isNull();
assertThat(dto1.isBuiltIn()).isTrue();

QualityProfileDto dto2 = dtos.get(1);
RulesProfileDto dto2 = dtos.get(1);
assertThat(dto2.getId()).isEqualTo(2);
assertThat(dto2.getName()).isEqualTo("Sonar Way");
assertThat(dto2.getLanguage()).isEqualTo("js");
@@ -185,7 +184,7 @@ public class QualityProfileDaoTest {
public void find_all_is_sorted_by_profile_name() {
dbTester.prepareDbUnit(getClass(), "select_all_is_sorted_by_profile_name.xml");

List<QualityProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);
List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);

assertThat(dtos).hasSize(3);
assertThat(dtos.get(0).getName()).isEqualTo("First");
@@ -197,7 +196,7 @@ public class QualityProfileDaoTest {
public void get_default_profile() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

QualityProfileDto java = underTest.selectDefaultProfile(dbTester.getSession(), organization, "java");
RulesProfileDto java = underTest.selectDefaultProfile(dbTester.getSession(), organization, "java");
assertThat(java).isNotNull();
assertThat(java.getKey()).isEqualTo("java_sonar_way");

@@ -209,7 +208,7 @@ public class QualityProfileDaoTest {
public void get_default_profiles() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

List<QualityProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("java"));
List<RulesProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("java"));
assertThat(java).extracting("key").containsOnly("java_sonar_way");

assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("js"))).isEmpty();
@@ -221,7 +220,7 @@ public class QualityProfileDaoTest {
public void get_by_name_and_language() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

QualityProfileDto dto = underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession());
RulesProfileDto dto = underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession());
assertThat(dto.getId()).isEqualTo(1);
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
@@ -235,9 +234,9 @@ public class QualityProfileDaoTest {
public void get_by_name_and_languages() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

List<QualityProfileDto> dtos = underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("java"), dbTester.getSession());
List<RulesProfileDto> dtos = underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("java"), dbTester.getSession());
assertThat(dtos).hasSize(1);
QualityProfileDto dto = dtos.iterator().next();
RulesProfileDto dto = dtos.iterator().next();
assertThat(dto.getId()).isEqualTo(1);
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
@@ -249,13 +248,13 @@ public class QualityProfileDaoTest {

@Test
public void should_find_by_language() {
QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto()
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);

List<QualityProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage());
List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage());
assertThat(results).hasSize(1);
QualityProfileDto result = results.get(0);
RulesProfileDto result = results.get(0);

assertThat(result.getId()).isEqualTo(profile.getId());
assertThat(result.getName()).isEqualTo(profile.getName());
@@ -266,21 +265,21 @@ public class QualityProfileDaoTest {

@Test
public void should_not_find_by_language_in_wrong_organization() {
QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto()
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);

List<QualityProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage());
List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage());
assertThat(results).isEmpty();
}

@Test
public void should_not_find_by_language_with_wrong_language() {
QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto()
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);

List<QualityProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language");
List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language");
assertThat(results).isEmpty();
}

@@ -288,17 +287,17 @@ public class QualityProfileDaoTest {
public void find_children() {
dbTester.prepareDbUnit(getClass(), "inheritance.xml");

List<QualityProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent");
List<RulesProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent");

assertThat(dtos).hasSize(2);

QualityProfileDto dto1 = dtos.get(0);
RulesProfileDto dto1 = dtos.get(0);
assertThat(dto1.getId()).isEqualTo(1);
assertThat(dto1.getName()).isEqualTo("Child1");
assertThat(dto1.getLanguage()).isEqualTo("java");
assertThat(dto1.getParentKee()).isEqualTo("java_parent");

QualityProfileDto dto2 = dtos.get(1);
RulesProfileDto dto2 = dtos.get(1);
assertThat(dto2.getId()).isEqualTo(2);
assertThat(dto2.getName()).isEqualTo("Child2");
assertThat(dto2.getLanguage()).isEqualTo("java");
@@ -307,15 +306,15 @@ public class QualityProfileDaoTest {

@Test
public void countProjectsByProfileKey() {
QualityProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
QualityProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization);
RulesProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
RulesProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization);
ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profileWithProjects);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profileWithProjects);

OrganizationDto otherOrg = dbTester.organizations().insert();
QualityProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
RulesProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
ComponentDto projectInOtherOrg = dbTester.components().insertPrivateProject(otherOrg);
dbTester.qualityProfiles().associateProjectWithQualityProfile(projectInOtherOrg, profileInOtherOrg);

@@ -327,7 +326,7 @@ public class QualityProfileDaoTest {
public void select_by_project_key_and_language() {
dbTester.prepareDbUnit(getClass(), "projects.xml");

QualityProfileDto dto = underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "java");
RulesProfileDto dto = underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "java");
assertThat(dto.getId()).isEqualTo(1);

assertThat(underTest.selectByProjectAndLanguage(dbTester.getSession(), "org.codehaus.sonar:sonar", "unkown")).isNull();
@@ -341,7 +340,7 @@ public class QualityProfileDaoTest {
OrganizationDto organization = dbTester.organizations().insert(OrganizationTesting.newOrganizationDto().setUuid("org1"));
ComponentDto project = dbTester.getDbClient().componentDao().selectOrFailByKey(dbTester.getSession(), "org.codehaus.sonar:sonar");
ComponentDto unknownProject = dbTester.components().insertPrivateProject(organization, p -> p.setKey("unknown"));
List<QualityProfileDto> dto = underTest.selectByProjectAndLanguages(dbTester.getSession(), organization, project, singletonList("java"));
List<RulesProfileDto> dto = underTest.selectByProjectAndLanguages(dbTester.getSession(), organization, project, singletonList("java"));
assertThat(dto).extracting("id").containsOnly(1);

assertThat(underTest.selectByProjectAndLanguages(dbTester.getSession(), organization, project, singletonList("unkown"))).isEmpty();
@@ -358,7 +357,7 @@ public class QualityProfileDaoTest {
assertThat(underTest.selectByKey(dbSession, "qp-key-42")).isNull();
assertThat(underTest.selectByKeys(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
.hasSize(2)
.extracting(QualityProfileDto::getKey).containsOnlyOnce("qp-key-1", "qp-key-3");
.extracting(RulesProfileDto::getKey).containsOnlyOnce("qp-key-1", "qp-key-3");
assertThat(underTest.selectByKeys(dbSession, emptyList())).isEmpty();
}

@@ -370,12 +369,12 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));

QualityProfileDto profile1 = newQualityProfileDto();
RulesProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
qualityProfileDb.associateProjectWithQualityProfile(project2, profile1);

QualityProfileDto profile2 = newQualityProfileDto();
RulesProfileDto profile2 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile2);
qualityProfileDb.associateProjectWithQualityProfile(project3, profile2);

@@ -397,11 +396,11 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));

QualityProfileDto profile1 = newQualityProfileDto();
RulesProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);

QualityProfileDto profile2 = newQualityProfileDto();
RulesProfileDto profile2 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile2);
qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);

@@ -423,11 +422,11 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));

QualityProfileDto profile1 = newQualityProfileDto();
RulesProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);

QualityProfileDto profile2 = newQualityProfileDto();
RulesProfileDto profile2 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile2);
qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);

@@ -445,9 +444,9 @@ public class QualityProfileDaoTest {
@Test
public void update_project_profile_association() {
ComponentDto project = dbTester.components().insertPrivateProject();
QualityProfileDto profile1Language1 = insertQualityProfileDto("profile1", "Profile 1", "xoo");
QualityProfileDto profile2Language2 = insertQualityProfileDto("profile2", "Profile 2", "xoo2");
QualityProfileDto profile3Language1 = insertQualityProfileDto("profile3", "Profile 3", "xoo");
RulesProfileDto profile1Language1 = insertQualityProfileDto("profile1", "Profile 1", "xoo");
RulesProfileDto profile2Language2 = insertQualityProfileDto("profile2", "Profile 2", "xoo2");
RulesProfileDto profile3Language1 = insertQualityProfileDto("profile3", "Profile 3", "xoo");
qualityProfileDb.associateProjectWithQualityProfile(project, profile1Language1, profile2Language2);

underTest.updateProjectProfileAssociation(project.uuid(), profile3Language1.getKey(), profile1Language1.getKey(), dbSession);
@@ -461,11 +460,11 @@ public class QualityProfileDaoTest {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
OrganizationDto org3 = dbTester.organizations().insert();
QualityProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
QualityProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
QualityProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo"));
QualityProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
QualityProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));
RulesProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
RulesProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
RulesProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo"));
RulesProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
RulesProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));

Collection<String> keys = underTest.selectOutdatedProfiles(dbSession, "java", "foo");

@@ -481,9 +480,9 @@ public class QualityProfileDaoTest {
public void renameAndCommit_updates_name_of_specified_profiles() {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
QualityProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p->p.setName("foo"));
QualityProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p->p.setName("foo"));
QualityProfileDto bar = dbTester.qualityProfiles().insert(org1, p->p.setName("bar"));
RulesProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p->p.setName("foo"));
RulesProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p->p.setName("foo"));
RulesProfileDto bar = dbTester.qualityProfiles().insert(org1, p->p.setName("bar"));

underTest.renameAndCommit(dbSession, asList(fooInOrg1.getKee(), fooInOrg2.getKee()), "foo (copy)");

@@ -495,15 +494,15 @@ public class QualityProfileDaoTest {
@Test
public void renameAndCommit_does_nothing_if_empty_keys() {
OrganizationDto org = dbTester.organizations().insert();
QualityProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo"));
RulesProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo"));

underTest.renameAndCommit(dbSession, Collections.emptyList(), "foo (copy)");

assertThat(underTest.selectOrFailByKey(dbSession, profile.getKey()).getName()).isEqualTo("foo");
}

private QualityProfileDto insertQualityProfileDto(String key, String name, String language) {
QualityProfileDto dto = QualityProfileDto.createFor(key)
private RulesProfileDto insertQualityProfileDto(String key, String name, String language) {
RulesProfileDto dto = RulesProfileDto.createFor(key)
.setOrganizationUuid(organization.getUuid())
.setName(name)
.setLanguage(language);

+ 19
- 19
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java View File

@@ -22,7 +22,6 @@ package org.sonar.db.qualityprofile;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;
import org.apache.commons.lang.math.RandomUtils;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -44,7 +43,7 @@ public class QualityProfileDbTester {
this.dbSession = dbTester.getSession();
}

public Optional<QualityProfileDto> selectByKey(String key) {
public Optional<RulesProfileDto> selectByKey(String key) {
return Optional.ofNullable(dbClient.qualityProfileDao().selectByKey(dbSession, key));
}

@@ -52,10 +51,8 @@ public class QualityProfileDbTester {
* Create a profile with random field values on the specified organization.
*/
@SafeVarargs
public final QualityProfileDto insert(OrganizationDto organization, Consumer<QualityProfileDto>... consumers) {
QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto()
// default is not randomized yet in QualityProfileTesting
.setDefault(RandomUtils.nextBoolean())
public final RulesProfileDto insert(OrganizationDto organization, Consumer<RulesProfileDto>... consumers) {
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
Arrays.stream(consumers).forEach(c -> c.accept(profile));

@@ -64,34 +61,34 @@ public class QualityProfileDbTester {
return profile;
}

public void insertQualityProfiles(QualityProfileDto qualityProfile, QualityProfileDto... qualityProfiles) {
public void insertQualityProfiles(RulesProfileDto qualityProfile, RulesProfileDto... qualityProfiles) {
dbClient.qualityProfileDao().insert(dbSession, qualityProfile, qualityProfiles);
dbSession.commit();
}

public QualityProfileDto insertQualityProfile(QualityProfileDto qualityProfile) {
public RulesProfileDto insertQualityProfile(RulesProfileDto qualityProfile) {
dbClient.qualityProfileDao().insert(dbSession, qualityProfile);
dbSession.commit();
return qualityProfile;
}

public void insertProjectWithQualityProfileAssociations(ComponentDto project, QualityProfileDto... qualityProfiles) {
public void insertProjectWithQualityProfileAssociations(ComponentDto project, RulesProfileDto... qualityProfiles) {
dbClient.componentDao().insert(dbSession, project);
for (QualityProfileDto qualityProfile : qualityProfiles) {
for (RulesProfileDto qualityProfile : qualityProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession);
}
dbSession.commit();
}

public void associateProjectWithQualityProfile(ComponentDto project, QualityProfileDto... qualityProfiles) {
for (QualityProfileDto qualityProfile : qualityProfiles) {
public void associateProjectWithQualityProfile(ComponentDto project, RulesProfileDto... qualityProfiles) {
for (RulesProfileDto qualityProfile : qualityProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), qualityProfile.getKey(), dbSession);
}
dbSession.commit();
}

@SafeVarargs
public final ActiveRuleDto activateRule(QualityProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto>... consumers) {
public final ActiveRuleDto activateRule(RulesProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto>... consumers) {
ActiveRuleDto activeRule = createFor(profile, rule).setSeverity(MAJOR);
for (Consumer<ActiveRuleDto> consumer : consumers) {
consumer.accept(activeRule);
@@ -101,12 +98,15 @@ public class QualityProfileDbTester {
return activeRule;
}

public void markAsDefault(QualityProfileDto profile) {
DefaultQProfileDto dto = new DefaultQProfileDto()
.setOrganizationUuid(profile.getOrganizationUuid())
.setLanguage(profile.getLanguage())
.setQProfileUuid(profile.getKee());
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, dto);
public void markAsDefault(RulesProfileDto... profiles) {
for (RulesProfileDto profile : profiles) {
DefaultQProfileDto dto = new DefaultQProfileDto()
.setOrganizationUuid(profile.getOrganizationUuid())
.setLanguage(profile.getLanguage())
.setQProfileUuid(profile.getKee());
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, dto);
}
dbSession.commit();
}


+ 2
- 2
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java View File

@@ -30,9 +30,9 @@ import static org.apache.commons.lang.math.RandomUtils.nextLong;

public class QualityProfileTesting {

public static QualityProfileDto newQualityProfileDto() {
public static RulesProfileDto newQualityProfileDto() {
String uuid = Uuids.createFast();
QualityProfileDto dto = QualityProfileDto.createFor(uuid)
RulesProfileDto dto = RulesProfileDto.createFor(uuid)
.setOrganizationUuid(randomAlphanumeric(40))
.setName(uuid)
.setLanguage(randomAlphanumeric(20))

+ 0
- 1
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml View File

@@ -7,7 +7,6 @@
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"

+ 0
- 6
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml View File

@@ -6,7 +6,6 @@
organization_uuid="org-123"
parent_kee="java_parent"
kee="java_child1"
is_default="[false]"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
@@ -18,7 +17,6 @@
organization_uuid="org-123"
parent_kee="java_parent"
kee="java_child2"
is_default="[false]"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
@@ -30,7 +28,6 @@
organization_uuid="org-123"
parent_kee="[null]"
kee="java_parent"
is_default="[false]"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
@@ -45,7 +42,6 @@
parent_kee="js_parent"
kee="js_child1"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -57,7 +53,6 @@
parent_kee="js_parent"
kee="js_child2"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -69,7 +64,6 @@
parent_kee="[null]"
kee="js_parent"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

+ 0
- 3
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml View File

@@ -7,7 +7,6 @@
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[true]"
is_default="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
@@ -21,7 +20,6 @@
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
@@ -35,7 +33,6 @@
parent_kee="[null]"
kee="abcde"
is_built_in="[true]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"

+ 0
- 2
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/projects.xml View File

@@ -7,7 +7,6 @@
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[false]"
is_default="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -18,7 +17,6 @@
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
is_default="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

+ 0
- 3
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml View File

@@ -7,7 +7,6 @@
parent_kee="[null]"
kee="js_third"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -19,7 +18,6 @@
parent_kee="[null]"
kee="js_first"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -31,7 +29,6 @@
parent_kee="[null]"
kee="js_second"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

+ 0
- 3
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml View File

@@ -7,7 +7,6 @@
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -19,7 +18,6 @@
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>
@@ -31,7 +29,6 @@
parent_kee="[null]"
kee="java_sonar_way2"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

+ 8
- 2
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml View File

@@ -7,7 +7,6 @@
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[true]"
is_default="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
@@ -21,11 +20,18 @@
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="123456789"
user_updated_at="987654321"/>

<default_qprofiles
organization_uuid="QualityProfileDaoTest-ORG"
language="java"
qprofile_uuid="java_sonar_way"
created_at="1000"
updated_at="2000"
/>

</dataset>

+ 0
- 2
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml View File

@@ -7,7 +7,6 @@
parent_kee="fghij"
kee="java_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
@@ -21,7 +20,6 @@
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
is_default="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"

+ 87
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java View File

@@ -0,0 +1,87 @@
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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.server.platform.db.migration.version.v65;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableQProfiles extends DdlChange {

private static final String TABLE_NAME = "qprofiles";

public CreateTableQProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
VarcharColumnDef organizationColumn = newVarcharColumnDefBuilder()
.setColumnName("organization_uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
context.execute(
new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newVarcharColumnDefBuilder()
.setColumnName("uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build())
.addColumn(organizationColumn)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("rules_profile_uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build())
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("parent_uuid")
.setLimit(UUID_SIZE)
.setIsNullable(true)
.setIgnoreOracleUnit(true)
.build())
.addColumn(newBigIntegerColumnDefBuilder()
.setColumnName("created_at")
.setIsNullable(false)
.build())
.addColumn(newBigIntegerColumnDefBuilder()
.setColumnName("updated_at")
.setIsNullable(false)
.build())
.build());

context.execute(
new CreateIndexBuilder(getDialect())
.setTable(TABLE_NAME)
.setName("qprofiles_org_uuid")
.addColumn(organizationColumn)
.build());
}
}

+ 3
- 1
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java View File

@@ -46,6 +46,8 @@ public class DbVersion65 implements DbVersion {
.add(1717, "Make rules_profiles.is_built_in not null", MakeRulesProfilesIsBuiltInNotNullable.class)
.add(1718, "Delete unused loaded_templates on quality profiles", DeleteLoadedTemplatesOnQProfiles.class)
.add(1719, "Create table default_qprofiles", CreateTableDefaultQProfiles.class)
.add(1720, "Populate table default_qprofiles", PopulateTableDefaultQProfiles.class);
.add(1720, "Populate table default_qprofiles", PopulateTableDefaultQProfiles.class)
.add(1721, "Drop rules_profiles.is_default", DropIsDefaultColumnFromRulesProfiles.class)
.add(1722, "Create table qprofiles", CreateTableQProfiles.class);
}
}

+ 73
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropIsDefaultColumnFromRulesProfiles.java View File

@@ -0,0 +1,73 @@
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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.server.platform.db.migration.version.v65;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.sonar.db.Database;
import org.sonar.db.dialect.MsSql;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

import static java.lang.String.format;

public class DropIsDefaultColumnFromRulesProfiles extends DdlChange {

private static final String TABLE_NAME = "rules_profiles";
private static final String COLUMN_NAME = "is_default";

public DropIsDefaultColumnFromRulesProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
if (getDialect().getId().equals(MsSql.ID)) {
// this should be handled automatically by DropColumnsBuilder
dropMssqlConstraints();
}

context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, COLUMN_NAME).build());
}

private void dropMssqlConstraints() throws SQLException {
try (Connection connection = getDatabase().getDataSource().getConnection();
PreparedStatement pstmt = connection
.prepareStatement(format("SELECT d.name " +
"FROM sys.default_constraints d " +
"INNER JOIN sys.columns AS c ON d.parent_column_id = c.column_id " +
"WHERE OBJECT_NAME(d.parent_object_id)='%s' AND c.name='%s'", TABLE_NAME, COLUMN_NAME));
ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
String constraintName = rs.getString(1);
dropMssqlConstraint(connection, constraintName);
}
}
}

private void dropMssqlConstraint(Connection connection, String constraintName) throws SQLException {
try (Statement stmt = connection.createStatement()) {
stmt.executeUpdate(format("ALTER TABLE %s DROP CONSTRAINT %s", TABLE_NAME, constraintName));
}
}
}

+ 67
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java View File

@@ -0,0 +1,67 @@
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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.server.platform.db.migration.version.v65;

import java.sql.SQLException;
import java.sql.Types;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.CoreDbTester;

import static org.assertj.core.api.Assertions.assertThat;


public class CreateTableQProfilesTest {

private static final String TABLE = "qprofiles";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableQProfilesTest.class, "empty.sql");
@Rule
public ExpectedException expectedException = ExpectedException.none();

private CreateTableQProfiles underTest = new CreateTableQProfiles(db.database());

@Test
public void creates_table_on_empty_db() throws SQLException {
underTest.execute();

assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0);

db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false);
db.assertPrimaryKey(TABLE, "pk_qprofiles", "uuid");
db.assertColumnDefinition(TABLE, "organization_uuid", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE, "rules_profile_uuid", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false);
db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false);
db.assertIndex(TABLE, "qprofiles_org_uuid", "organization_uuid");
}

@Test
public void migration_is_not_reentrant() throws SQLException {
underTest.execute();

expectedException.expect(IllegalStateException.class);

underTest.execute();
}

}

+ 1
- 1
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java View File

@@ -35,6 +35,6 @@ public class DbVersion65Test {

@Test
public void verify_migration_count() {
verifyMigrationCount(underTest, 21);
verifyMigrationCount(underTest, 23);
}
}

+ 43
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropIsDefaultColumnFromRulesProfilesTest.java View File

@@ -0,0 +1,43 @@
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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.server.platform.db.migration.version.v65;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

public class DropIsDefaultColumnFromRulesProfilesTest {

private static final String TABLE_NAME = "rules_profiles";

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropIsDefaultColumnFromRulesProfilesTest.class, "initial.sql");

private DropIsDefaultColumnFromRulesProfiles underTest = new DropIsDefaultColumnFromRulesProfiles(db.database());

@Test
public void column_is_dropped() throws SQLException {
underTest.execute();

db.assertColumnDoesNotExist(TABLE_NAME, "is_default");
}

}

+ 0
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql View File


+ 16
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropIsDefaultColumnFromRulesProfilesTest/initial.sql View File

@@ -0,0 +1,16 @@
CREATE TABLE "RULES_PROFILES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"KEE" VARCHAR(255) NOT NULL,
"PARENT_KEE" VARCHAR(255),
"RULES_UPDATED_AT" VARCHAR(100),
"IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"LAST_USED" BIGINT,
"USER_UPDATED_AT" BIGINT,
"IS_BUILT_IN" BOOLEAN NOT NULL
);
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java View File

@@ -31,7 +31,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile;
import org.sonar.server.computation.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
@@ -107,10 +107,10 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
.map(QProfile::getKey)
.collect(toList(metadata.getQprofilesPerLanguage().size()));
try (DbSession dbSession = dbClient.openSession(false)) {
List<QualityProfileDto> profiles = dbClient.qualityProfileDao().selectByKeys(dbSession, profileKeys);
List<RulesProfileDto> profiles = dbClient.qualityProfileDao().selectByKeys(dbSession, profileKeys);
String badKeys = profiles.stream()
.filter(p -> !p.getOrganizationUuid().equals(organization.getUuid()))
.map(QualityProfileDto::getKey)
.map(RulesProfileDto::getKey)
.collect(MoreCollectors.join(Joiner.on(", ")));
if (!badKeys.isEmpty()) {
throw MessageException.of(format("Quality profiles with following keys don't exist in organization [%s]: %s", organization.getKey(), badKeys));

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java View File

@@ -26,7 +26,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
@@ -68,7 +68,7 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
return;
}

List<QualityProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
List<RulesProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
dtos.addAll(getAncestors(dbSession, dtos));
long analysisDate = analysisMetadataHolder.getAnalysisDate();
dtos.forEach(dto -> {
@@ -80,16 +80,16 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
}
}

private List<QualityProfileDto> getAncestors(DbSession dbSession, List<QualityProfileDto> dtos) {
List<QualityProfileDto> ancestors = new ArrayList<>();
private List<RulesProfileDto> getAncestors(DbSession dbSession, List<RulesProfileDto> dtos) {
List<RulesProfileDto> ancestors = new ArrayList<>();
dtos.forEach(dto -> incrementAncestors(dbSession, dto, ancestors));
return ancestors;
}

private void incrementAncestors(DbSession session, QualityProfileDto profile, List<QualityProfileDto> ancestors) {
private void incrementAncestors(DbSession session, RulesProfileDto profile, List<RulesProfileDto> ancestors) {
String parentKey = profile.getParentKee();
if (parentKey != null) {
QualityProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByKey(session, parentKey);
RulesProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByKey(session, parentKey);
ancestors.add(parentDto);
incrementAncestors(session, parentDto, ancestors);
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java View File

@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.organization.DefaultOrganization;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -134,9 +134,9 @@ public class DeleteAction implements OrganizationsWsAction {
}

private void deleteQualityProfiles(DbSession dbSession, OrganizationDto organization) {
List<QualityProfileDto> profiles = dbClient.qualityProfileDao().selectAll(dbSession, organization);
List<RulesProfileDto> profiles = dbClient.qualityProfileDao().selectAll(dbSession, organization);
List<String> profileKeys = profiles.stream()
.map(QualityProfileDto::getKey)
.map(RulesProfileDto::getKey)
.collect(MoreCollectors.toArrayList(profiles.size()));
qProfileFactory.deleteByKeys(dbSession, profileKeys);
dbSession.commit();

+ 5
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java View File

@@ -47,7 +47,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.util.TypeValidations;
@@ -75,7 +75,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
initRuleRepository(batchSession);

Date now = new Date(system2.now());
QualityProfileDto profileDto = insertQualityProfile(session, builtInQProfile, organization, now);
RulesProfileDto profileDto = insertQualityProfile(session, builtInQProfile, organization, now);

List<ActiveRuleChange> localChanges = builtInQProfile.getActiveRules()
.stream()
@@ -91,12 +91,11 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
}
}

private QualityProfileDto insertQualityProfile(DbSession dbSession, BuiltInQProfile builtInQProfile, OrganizationDto organization, Date now) {
QualityProfileDto profileDto = QualityProfileDto.createFor(uuidFactory.create())
private RulesProfileDto insertQualityProfile(DbSession dbSession, BuiltInQProfile builtInQProfile, OrganizationDto organization, Date now) {
RulesProfileDto profileDto = RulesProfileDto.createFor(uuidFactory.create())
.setName(builtInQProfile.getName())
.setOrganizationUuid(organization.getUuid())
.setLanguage(builtInQProfile.getLanguage())
.setDefault(builtInQProfile.isDefault())
.setIsBuiltIn(true)
.setRulesUpdatedAtAsDate(now);
dbClient.qualityProfileDao().insert(dbSession, profileDto);
@@ -106,7 +105,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
return profileDto;
}

private ActiveRuleChange insertActiveRule(DbSession session, QualityProfileDto profileDto, org.sonar.api.rules.ActiveRule activeRule, long now) {
private ActiveRuleChange insertActiveRule(DbSession session, RulesProfileDto profileDto, org.sonar.api.rules.ActiveRule activeRule, long now) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
RuleDefinitionDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey)
.orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey));

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java View File

@@ -24,14 +24,14 @@ import java.io.Writer;
import javax.annotation.Nullable;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

/**
* Backup and restore a Quality profile.
*/
public interface QProfileBackuper {

void backup(DbSession dbSession, QualityProfileDto profile, Writer backupWriter);
void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter);

/**
* Restore backup on a profile in the specified organization. The parameter {@code overriddenProfileName}
@@ -43,5 +43,5 @@ public interface QProfileBackuper {
/**
* Restore backup on an existing profile.
*/
QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QualityProfileDto profile);
QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile);
}

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java View File

@@ -47,7 +47,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

import static com.google.common.base.Preconditions.checkArgument;

@@ -82,13 +82,13 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}

@Override
public void backup(DbSession dbSession, QualityProfileDto profileDto, Writer writer) {
public void backup(DbSession dbSession, RulesProfileDto profileDto, Writer writer) {
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKey());
activeRules.sort(BackupActiveRuleComparator.INSTANCE);
writeXml(dbSession, writer, profileDto, activeRules.iterator());
}

private void writeXml(DbSession dbSession, Writer writer, QualityProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
private void writeXml(DbSession dbSession, Writer writer, RulesProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
XmlWriter xml = XmlWriter.of(writer).declaration();
xml.begin(ATTRIBUTE_PROFILE);
xml.prop(ATTRIBUTE_NAME, profile.getName());
@@ -126,7 +126,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}

@Override
public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QualityProfileDto profile) {
public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
return restore(dbSession, backup, nameInBackup -> {
checkArgument(profile.getLanguage().equals(nameInBackup.getLanguage()),
"Can't restore %s backup on %s profile with key [%s]. Languages are different.", nameInBackup.getLanguage(), profile.getLanguage(), profile.getKey());
@@ -134,7 +134,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
});
}

private QProfileRestoreSummary restore(DbSession dbSession, Reader backup, Function<QProfileName, QualityProfileDto> profileLoader) {
private QProfileRestoreSummary restore(DbSession dbSession, Reader backup, Function<QProfileName, RulesProfileDto> profileLoader) {
try {
String profileLang = null;
String profileName = null;
@@ -161,7 +161,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}

QProfileName targetName = new QProfileName(profileLang, profileName);
QualityProfileDto targetProfile = profileLoader.apply(targetName);
RulesProfileDto targetProfile = profileLoader.apply(targetName);
BulkChangeResult changes = profileReset.reset(dbSession, targetProfile, ruleActivations);
return new QProfileRestoreSummary(targetProfile, changes);
} catch (XMLStreamException e) {

+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java View File

@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

@ServerSide
@ComputeEngineSide
@@ -48,7 +48,7 @@ public class QProfileComparison {
this.dbClient = dbClient;
}

public QProfileComparisonResult compare(DbSession dbSession, QualityProfileDto left, QualityProfileDto right) {
public QProfileComparisonResult compare(DbSession dbSession, RulesProfileDto left, RulesProfileDto right) {
Map<RuleKey, ActiveRuleDto> leftActiveRulesByRuleKey = loadActiveRules(dbSession, left);
Map<RuleKey, ActiveRuleDto> rightActiveRulesByRuleKey = loadActiveRules(dbSession, right);

@@ -86,29 +86,29 @@ public class QProfileComparison {
}
}

private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, QualityProfileDto profile) {
private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, RulesProfileDto profile) {
return Maps.uniqueIndex(dbClient.activeRuleDao().selectByProfileKey(session, profile.getKey()), ActiveRuleToRuleKey.INSTANCE);
}

public static class QProfileComparisonResult {

private final QualityProfileDto left;
private final QualityProfileDto right;
private final RulesProfileDto left;
private final RulesProfileDto right;
private final Map<RuleKey, ActiveRuleDto> inLeft = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDto> inRight = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDiff> modified = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDto> same = Maps.newHashMap();

public QProfileComparisonResult(QualityProfileDto left, QualityProfileDto right) {
public QProfileComparisonResult(RulesProfileDto left, RulesProfileDto right) {
this.left = left;
this.right = right;
}

public QualityProfileDto left() {
public RulesProfileDto left() {
return left;
}

public QualityProfileDto right() {
public RulesProfileDto right() {
return right;
}


+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java View File

@@ -32,7 +32,7 @@ import org.sonar.api.utils.TempFolder;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

import static java.nio.charset.StandardCharsets.UTF_8;

@@ -51,10 +51,10 @@ public class QProfileCopier {
this.temp = temp;
}

public QualityProfileDto copyToName(DbSession dbSession, QualityProfileDto sourceProfile, String toName) {
public RulesProfileDto copyToName(DbSession dbSession, RulesProfileDto sourceProfile, String toName) {
OrganizationDto organization = db.organizationDao().selectByUuid(dbSession, sourceProfile.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException("Organization with UUID [" + sourceProfile.getOrganizationUuid() + "] does not exist"));
QualityProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName);
RulesProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName);
File backupFile = temp.newFile();
try {
backup(dbSession, sourceProfile, backupFile);
@@ -65,10 +65,10 @@ public class QProfileCopier {
}
}

private QualityProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, QualityProfileDto sourceProfile, String toName) {
private RulesProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, RulesProfileDto sourceProfile, String toName) {
QProfileName toProfileName = new QProfileName(sourceProfile.getLanguage(), toName);
verify(sourceProfile, toProfileName);
QualityProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(organization, toProfileName.getName(), toProfileName.getLanguage(), dbSession);
RulesProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(organization, toProfileName.getName(), toProfileName.getLanguage(), dbSession);
if (toProfile == null) {
toProfile = factory.checkAndCreateCustom(dbSession, organization, toProfileName);
toProfile.setParentKee(sourceProfile.getParentKee());
@@ -78,7 +78,7 @@ public class QProfileCopier {
return toProfile;
}

private void verify(QualityProfileDto fromProfile, QProfileName toProfileName) {
private void verify(RulesProfileDto fromProfile, QProfileName toProfileName) {
if (!StringUtils.equals(fromProfile.getLanguage(), toProfileName.getLanguage())) {
throw new IllegalArgumentException(String.format(
"Source and target profiles do not have the same language: %s and %s",
@@ -90,7 +90,7 @@ public class QProfileCopier {
}
}

private void backup(DbSession dbSession, QualityProfileDto profile, File backupFile) {
private void backup(DbSession dbSession, RulesProfileDto profile, File backupFile) {
try (Writer writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile), UTF_8)) {
backuper.backup(dbSession, profile, writer);
} catch (IOException e) {
@@ -98,7 +98,7 @@ public class QProfileCopier {
}
}

private void restore(DbSession dbSession, File backupFile, QualityProfileDto profile) {
private void restore(DbSession dbSession, File backupFile, RulesProfileDto profile) {
try (Reader reader = new InputStreamReader(FileUtils.openInputStream(backupFile), UTF_8)) {
backuper.restore(dbSession, reader, profile);
} catch (IOException e) {

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java View File

@@ -44,7 +44,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;

@@ -103,12 +103,12 @@ public class QProfileExporters {
return exporter.getMimeType();
}

public void export(QualityProfileDto profile, String exporterKey, Writer writer) {
public void export(RulesProfileDto profile, String exporterKey, Writer writer) {
ProfileExporter exporter = findExporter(exporterKey);
exporter.exportProfile(wrap(profile), writer);
}

private RulesProfile wrap(QualityProfileDto profile) {
private RulesProfile wrap(RulesProfileDto profile) {
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
@@ -137,11 +137,11 @@ public class QProfileExporters {
throw new NotFoundException("Unknown quality profile exporter: " + exporterKey);
}

public QProfileResult importXml(QualityProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) {
public QProfileResult importXml(RulesProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) {
return importXml(profileDto, importerKey, new InputStreamReader(xml, StandardCharsets.UTF_8), dbSession);
}

private QProfileResult importXml(QualityProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
private QProfileResult importXml(RulesProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
QProfileResult result = new QProfileResult();
ValidationMessages messages = ValidationMessages.create();
ProfileImporter importer = getProfileImporter(importerKey);
@@ -152,7 +152,7 @@ public class QProfileExporters {
return result;
}

private List<ActiveRuleChange> importProfile(QualityProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
private List<ActiveRuleChange> importProfile(RulesProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
List<ActiveRuleChange> changes = new ArrayList<>();
for (org.sonar.api.rules.ActiveRule activeRule : rulesProfile.getActiveRules()) {
changes.addAll(ruleActivator.activate(dbSession, toRuleActivation(activeRule), profileDto));

+ 8
- 9
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java View File

@@ -30,7 +30,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;

@@ -55,9 +55,9 @@ public class QProfileFactory {

// ------------- CREATION

QualityProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
RulesProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
requireNonNull(organization);
QualityProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
RulesProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
if (profile == null) {
profile = doCreate(dbSession, organization, name, false, false);
}
@@ -69,9 +69,9 @@ public class QProfileFactory {
*
* @throws BadRequestException if a quality profile with the specified name already exists
*/
public QualityProfileDto checkAndCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
public RulesProfileDto checkAndCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
requireNonNull(organization);
QualityProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
RulesProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
checkRequest(dto == null, "Quality profile already exists: %s", name);
return doCreate(dbSession, organization, name, false, false);
}
@@ -81,7 +81,7 @@ public class QProfileFactory {
*
* A DB error will be thrown if the quality profile already exists.
*/
public QualityProfileDto createBuiltIn(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault) {
public RulesProfileDto createBuiltIn(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault) {
return doCreate(dbSession, requireNonNull(organization), name, isDefault, true);
}

@@ -90,16 +90,15 @@ public class QProfileFactory {
return organization;
}

private QualityProfileDto doCreate(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault, boolean isBuiltIn) {
private RulesProfileDto doCreate(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault, boolean isBuiltIn) {
if (StringUtils.isEmpty(name.getName())) {
throw BadRequestException.create("quality_profiles.profile_name_cant_be_blank");
}
Date now = new Date(system2.now());
QualityProfileDto dto = QualityProfileDto.createFor(uuidFactory.create())
RulesProfileDto dto = RulesProfileDto.createFor(uuidFactory.create())
.setName(name.getName())
.setOrganizationUuid(organization.getUuid())
.setLanguage(name.getLanguage())
.setDefault(isDefault)
.setIsBuiltIn(isBuiltIn)
.setRulesUpdatedAtAsDate(now);
db.qualityProfileDao().insert(dbSession, dto);

+ 7
- 7
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java View File

@@ -24,7 +24,7 @@ import org.sonar.api.server.ServerSide;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

import static com.google.common.collect.Lists.newArrayList;

@@ -37,23 +37,23 @@ public class QProfileLookup {
this.db = db;
}

public List<QualityProfileDto> allProfiles(DbSession dbSession, OrganizationDto organization) {
public List<RulesProfileDto> allProfiles(DbSession dbSession, OrganizationDto organization) {
return db.qualityProfileDao().selectAll(dbSession, organization);
}

public List<QualityProfileDto> profiles(DbSession dbSession, String language, OrganizationDto organization) {
public List<RulesProfileDto> profiles(DbSession dbSession, String language, OrganizationDto organization) {
return db.qualityProfileDao().selectByLanguage(dbSession, organization, language);
}

public List<QualityProfileDto> ancestors(QualityProfileDto profile, DbSession session) {
List<QualityProfileDto> ancestors = newArrayList();
public List<RulesProfileDto> ancestors(RulesProfileDto profile, DbSession session) {
List<RulesProfileDto> ancestors = newArrayList();
incrementAncestors(profile, ancestors, session);
return ancestors;
}

private void incrementAncestors(QualityProfileDto profile, List<QualityProfileDto> ancestors, DbSession session) {
private void incrementAncestors(RulesProfileDto profile, List<RulesProfileDto> ancestors, DbSession session) {
if (profile.getParentKee() != null) {
QualityProfileDto parentDto = db.qualityProfileDao().selectByKey(session, profile.getParentKee());
RulesProfileDto parentDto = db.qualityProfileDao().selectByKey(session, profile.getParentKee());
if (parentDto == null) {
throw new IllegalStateException("Cannot find parent of profile : " + profile.getId());
}

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java View File

@@ -22,7 +22,7 @@ package org.sonar.server.qualityprofile;
import java.util.Collection;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

public interface QProfileReset {
/**
@@ -34,5 +34,5 @@ public interface QProfileReset {
/**
* Reset the rules of the specified profile.
*/
BulkChangeResult reset(DbSession dbSession, QualityProfileDto profile, Collection<RuleActivation> activations);
BulkChangeResult reset(DbSession dbSession, RulesProfileDto profile, Collection<RuleActivation> activations);
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java View File

@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
@@ -72,7 +72,7 @@ public class QProfileResetImpl implements QProfileReset {
}

private void resetProfile(DbSession dbSession, OrganizationDto organization, BuiltInQProfile builtInQProfile) {
QualityProfileDto profile = factory.getOrCreateCustom(dbSession, organization, builtInQProfile.getQProfileName());
RulesProfileDto profile = factory.getOrCreateCustom(dbSession, organization, builtInQProfile.getQProfileName());

List<RuleActivation> activations = Lists.newArrayList();
builtInQProfile.getActiveRules().forEach(activeRule -> activations.add(getRuleActivation(dbSession, activeRule)));
@@ -95,7 +95,7 @@ public class QProfileResetImpl implements QProfileReset {
}

@Override
public BulkChangeResult reset(DbSession dbSession, QualityProfileDto profile, Collection<RuleActivation> activations) {
public BulkChangeResult reset(DbSession dbSession, RulesProfileDto profile, Collection<RuleActivation> activations) {
requireNonNull(profile.getId(), "Quality profile must be persisted");
BulkChangeResult result = new BulkChangeResult();
Set<RuleKey> ruleToBeDeactivated = Sets.newHashSet();

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java View File

@@ -19,20 +19,20 @@
*/
package org.sonar.server.qualityprofile;

import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

import static java.util.Objects.requireNonNull;

public final class QProfileRestoreSummary {
private final QualityProfileDto profile;
private final RulesProfileDto profile;
private final BulkChangeResult ruleChanges;

public QProfileRestoreSummary(QualityProfileDto profile, BulkChangeResult ruleChanges) {
public QProfileRestoreSummary(RulesProfileDto profile, BulkChangeResult ruleChanges) {
this.profile = requireNonNull(profile);
this.ruleChanges = requireNonNull(ruleChanges);
}

public QualityProfileDto getProfile() {
public RulesProfileDto getProfile() {
return profile;
}


+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java View File

@@ -21,14 +21,14 @@ package org.sonar.server.qualityprofile;

import java.util.ArrayList;
import java.util.List;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

public class QProfileResult {

private List<String> warnings;
private List<String> infos;

private QualityProfileDto profile;
private RulesProfileDto profile;

private List<ActiveRuleChange> changes;

@@ -56,11 +56,11 @@ public class QProfileResult {
return this;
}

public QualityProfileDto profile() {
public RulesProfileDto profile() {
return profile;
}

public QProfileResult setProfile(QualityProfileDto profile) {
public QProfileResult setProfile(RulesProfileDto profile) {
this.profile = profile;
return this;
}

+ 15
- 15
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java View File

@@ -38,7 +38,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -82,7 +82,7 @@ public class RuleActivator {
return doActivate(dbSession, activation, context);
}

public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, QualityProfileDto profileDto) {
public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, RulesProfileDto profileDto) {
RuleActivatorContext context = contextFactory.create(profileDto, activation.getRuleKey(), dbSession);
return doActivate(dbSession, activation, context);
}
@@ -146,7 +146,7 @@ public class RuleActivator {
}

private void updateProfileDates(DbSession dbSession, RuleActivatorContext context) {
QualityProfileDto profile = context.profile();
RulesProfileDto profile = context.profile();
profile.setRulesUpdatedAtAsDate(context.getInitDate());
if (userSession.isLoggedIn()) {
profile.setUserUpdatedAt(context.getInitDate().getTime());
@@ -224,20 +224,20 @@ public class RuleActivator {
return null;
}

private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, QualityProfileDto qualityProfileDto) {
private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, RulesProfileDto rulesProfileDto) {
List<ActiveRuleChange> changes = Lists.newArrayList();

// get all inherited profiles
String qualityProfileKey = qualityProfileDto.getKey();
List<QualityProfileDto> children = getChildren(session, qualityProfileKey);
for (QualityProfileDto child : children) {
String qualityProfileKey = rulesProfileDto.getKey();
List<RulesProfileDto> children = getChildren(session, qualityProfileKey);
for (RulesProfileDto child : children) {
RuleActivation childActivation = new RuleActivation(activation).setCascade(true);
changes.addAll(activate(session, childActivation, child));
}
return changes;
}

protected List<QualityProfileDto> getChildren(DbSession session, String qualityProfileKey) {
protected List<RulesProfileDto> getChildren(DbSession session, String qualityProfileKey) {
return db.qualityProfileDao().selectChildren(session, qualityProfileKey);
}

@@ -370,9 +370,9 @@ public class RuleActivator {
persist(change, context, dbSession);

// get all inherited profiles
List<QualityProfileDto> profiles = getChildren(dbSession, key.qProfile());
List<RulesProfileDto> profiles = getChildren(dbSession, key.qProfile());

for (QualityProfileDto profile : profiles) {
for (RulesProfileDto profile : profiles) {
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), key.ruleKey());
changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true, force));
}
@@ -457,14 +457,14 @@ public class RuleActivator {
}

public List<ActiveRuleChange> setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
QualityProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
RulesProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
List<ActiveRuleChange> changes = new ArrayList<>();
if (parentKey == null) {
// unset if parent is defined, else nothing to do
changes.addAll(removeParent(dbSession, profile));

} else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
QualityProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
RulesProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
checkRequest(!isDescendant(dbSession, profile, parentProfile), "Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey);
changes.addAll(removeParent(dbSession, profile));

@@ -489,7 +489,7 @@ public class RuleActivator {
/**
* Does not commit
*/
private List<ActiveRuleChange> removeParent(DbSession dbSession, QualityProfileDto profileDto) {
private List<ActiveRuleChange> removeParent(DbSession dbSession, RulesProfileDto profileDto) {
if (profileDto.getParentKee() != null) {
List<ActiveRuleChange> changes = new ArrayList<>();
profileDto.setParentKee(null);
@@ -509,8 +509,8 @@ public class RuleActivator {
return Collections.emptyList();
}

boolean isDescendant(DbSession dbSession, QualityProfileDto childProfile, @Nullable QualityProfileDto parentProfile) {
QualityProfileDto currentParent = parentProfile;
boolean isDescendant(DbSession dbSession, RulesProfileDto childProfile, @Nullable RulesProfileDto parentProfile) {
RulesProfileDto currentParent = parentProfile;
while (currentParent != null) {
if (childProfile.getName().equals(currentParent.getName())) {
return true;

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java View File

@@ -30,7 +30,7 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;

@@ -41,7 +41,7 @@ class RuleActivatorContext {
private final Date initDate = new Date();
private RuleDefinitionDto rule;
private final Map<String, RuleParamDto> ruleParams = Maps.newHashMap();
private QualityProfileDto profile;
private RulesProfileDto profile;
private ActiveRuleDto activeRule;
private ActiveRuleDto parentActiveRule;
private final Map<String, ActiveRuleParamDto> activeRuleParams = Maps.newHashMap();
@@ -83,11 +83,11 @@ class RuleActivatorContext {
return this;
}

QualityProfileDto profile() {
RulesProfileDto profile() {
return profile;
}

RuleActivatorContext setProfile(QualityProfileDto profile) {
RuleActivatorContext setProfile(RulesProfileDto profile) {
this.profile = profile;
return this;
}

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;

@@ -46,13 +46,13 @@ public class RuleActivatorContextFactory {

RuleActivatorContext create(String profileKey, RuleKey ruleKey, DbSession session) {
RuleActivatorContext context = new RuleActivatorContext();
QualityProfileDto profile = getQualityProfileDto(session, profileKey);
RulesProfileDto profile = getQualityProfileDto(session, profileKey);
checkRequest(profile != null, "Quality profile not found: %s", profileKey);
context.setProfile(profile);
return create(ruleKey, session, context);
}

RuleActivatorContext create(QualityProfileDto profile, RuleKey ruleKey, DbSession session) {
RuleActivatorContext create(RulesProfileDto profile, RuleKey ruleKey, DbSession session) {
return create(ruleKey, session, new RuleActivatorContext().setProfile(profile));
}

@@ -91,7 +91,7 @@ public class RuleActivatorContextFactory {
}
}

QualityProfileDto getQualityProfileDto(DbSession session, String profileKey) {
RulesProfileDto getQualityProfileDto(DbSession session, String profileKey) {
return db.qualityProfileDao().selectByKey(session, profileKey);
}


+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.UserSession;
@@ -81,13 +81,13 @@ public class AddProjectAction implements QProfileWsAction {

try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = loadProject(dbSession, request);
QualityProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));

if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) {
throw new IllegalArgumentException("Project and Quality profile must have same organization");
}

QualityProfileDto currentProfile = dbClient.qualityProfileDao().selectByProjectAndLanguage(dbSession, project.key(), profile.getLanguage());
RulesProfileDto currentProfile = dbClient.qualityProfileDao().selectByProjectAndLanguage(dbSession, project.key(), profile.getLanguage());
if (currentProfile == null) {
// project uses the default profile
dbClient.qualityProfileDao().insertProjectProfileAssociation(project.uuid(), profile.getKey(), dbSession);

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java View File

@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonarqube.ws.MediaTypes;

@@ -69,7 +69,7 @@ public class BackupAction implements QProfileWsAction {
try (OutputStreamWriter writer = new OutputStreamWriter(stream.output(), UTF_8);
DbSession dbSession = dbClient.openSession(false)) {

QualityProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
response.setHeader("Content-Disposition", String.format("attachment; filename=%s.xml", profile.getKee()));
backuper.backup(dbSession, profile, writer);
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java View File

@@ -28,7 +28,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.user.UserSession;

@@ -85,7 +85,7 @@ public class ChangeParentAction implements QProfileWsAction {
QProfileReference reference = QProfileReference.from(request);

try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = wsSupport.getProfile(dbSession, reference);
RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
String organizationUuid = profile.getOrganizationUuid();
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find organization with uuid '%s' of profile '%s'", organizationUuid, profile.getKee())));
@@ -99,7 +99,7 @@ public class ChangeParentAction implements QProfileWsAction {
String parentOrganizationKey = parentKey == null ? organization.getKey() : null;
String parentLanguage = parentKey == null ? request.param(PARAM_LANGUAGE) : null;
QProfileReference parentRef = QProfileReference.from(parentKey, parentOrganizationKey, parentLanguage, parentName);
QualityProfileDto parent = wsSupport.getProfile(dbSession, parentRef);
RulesProfileDto parent = wsSupport.getProfile(dbSession, parentRef);
ruleActivator.setParent(dbSession, profile.getKey(), parent.getKey());
}
response.noContent();

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java View File

@@ -32,7 +32,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QProfileChangeQuery;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
@@ -84,7 +84,7 @@ public class ChangelogAction implements QProfileWsAction {
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = wsSupport.getProfile(dbSession, reference);
RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);

QProfileChangeQuery query = new QProfileChangeQuery(profile.getKey());
Date since = parseStartingDateOrDateTime(request.param(PARAM_SINCE));

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java View File

@@ -39,7 +39,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleRepositoryDto;
import org.sonar.server.qualityprofile.QProfileComparison;
@@ -104,9 +104,9 @@ public class CompareAction implements QProfileWsAction {
String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);

try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto left = dbClient.qualityProfileDao().selectByKey(dbSession, leftKey);
RulesProfileDto left = dbClient.qualityProfileDao().selectByKey(dbSession, leftKey);
checkArgument(left != null, "Could not find left profile '%s'", leftKey);
QualityProfileDto right = dbClient.qualityProfileDao().selectByKey(dbSession, rightKey);
RulesProfileDto right = dbClient.qualityProfileDao().selectByKey(dbSession, rightKey);
checkArgument(right != null, "Could not find right profile '%s'", rightKey);

checkArgument(Objects.equals(left.getOrganizationUuid(), right.getOrganizationUuid()),
@@ -148,7 +148,7 @@ public class CompareAction implements QProfileWsAction {
json.endObject().close();
}

private void writeProfile(JsonWriter json, QualityProfileDto profile) {
private void writeProfile(JsonWriter json, RulesProfileDto profile) {
json.prop(ATTRIBUTE_KEY, profile.getKey())
.prop(ATTRIBUTE_NAME, profile.getName());
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java View File

@@ -29,7 +29,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileCopier;
import org.sonar.server.user.UserSession;

@@ -79,10 +79,10 @@ public class CopyAction implements QProfileWsAction {
String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);

try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto sourceProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
RulesProfileDto sourceProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, sourceProfile.getOrganizationUuid());

QualityProfileDto copiedProfile = profileCopier.copyToName(dbSession, sourceProfile, newName);
RulesProfileDto copiedProfile = profileCopier.copyToName(dbSession, sourceProfile, newName);
boolean isDefault = dbClient.defaultQProfileDao().isDefault(dbSession, copiedProfile.getOrganizationUuid(), copiedProfile.getKee());

String languageKey = copiedProfile.getLanguage();

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java View File

@@ -29,7 +29,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileName;
@@ -123,7 +123,7 @@ public class CreateAction implements QProfileWsAction {

private CreateWsResponse doHandle(DbSession dbSession, CreateRequest createRequest, Request request, OrganizationDto organization) {
QProfileResult result = new QProfileResult();
QualityProfileDto profile = profileFactory.checkAndCreateCustom(dbSession, organization,
RulesProfileDto profile = profileFactory.checkAndCreateCustom(dbSession, organization,
QProfileName.createFor(createRequest.getLanguage(), createRequest.getProfileName()));
result.setProfile(profile);
for (ProfileImporter importer : importers) {

+ 7
- 7
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java View File

@@ -31,7 +31,7 @@ import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.user.UserSession;

@@ -72,10 +72,10 @@ public class DeleteAction implements QProfileWsAction {
userSession.checkLoggedIn();

try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = qProfileWsSupport.getProfile(dbSession, QProfileReference.from(request));
RulesProfileDto profile = qProfileWsSupport.getProfile(dbSession, QProfileReference.from(request));
userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, profile.getOrganizationUuid());

List<QualityProfileDto> descendants = selectDescendants(dbSession, profile);
List<RulesProfileDto> descendants = selectDescendants(dbSession, profile);
ensureNoneIsMarkedAsDefault(dbSession, profile, descendants);

profileFactory.deleteByKeys(dbSession, toKeys(profile, descendants));
@@ -84,11 +84,11 @@ public class DeleteAction implements QProfileWsAction {
response.noContent();
}

private List<QualityProfileDto> selectDescendants(DbSession dbSession, QualityProfileDto profile) {
private List<RulesProfileDto> selectDescendants(DbSession dbSession, RulesProfileDto profile) {
return dbClient.qualityProfileDao().selectDescendants(dbSession, profile.getKey());
}

private void ensureNoneIsMarkedAsDefault(DbSession dbSession, QualityProfileDto profile, List<QualityProfileDto> descendants) {
private void ensureNoneIsMarkedAsDefault(DbSession dbSession, RulesProfileDto profile, List<RulesProfileDto> descendants) {
Set<String> allUuids = new HashSet<>();
allUuids.add(profile.getKee());
descendants.forEach(p -> allUuids.add(p.getKee()));
@@ -104,9 +104,9 @@ public class DeleteAction implements QProfileWsAction {
});
}

private static List<String> toKeys(QualityProfileDto profile, List<QualityProfileDto> descendants) {
private static List<String> toKeys(RulesProfileDto profile, List<RulesProfileDto> descendants) {
return Stream.concat(Stream.of(profile), descendants.stream())
.map(QualityProfileDto::getKee)
.map(RulesProfileDto::getKee)
.collect(MoreCollectors.toList(descendants.size() + 1));
}
}

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java View File

@@ -38,7 +38,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.util.LanguageParamUtils;
@@ -111,12 +111,12 @@ public class ExportAction implements QProfileWsAction {

try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
QualityProfileDto profile = loadProfile(dbSession, organization, language, name);
RulesProfileDto profile = loadProfile(dbSession, organization, language, name);
writeResponse(dbSession, profile, exporterKey, response);
}
}

private void writeResponse(DbSession dbSession, QualityProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
private void writeResponse(DbSession dbSession, RulesProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
Stream stream = response.stream();
try (
OutputStream output = response.stream().output();
@@ -131,8 +131,8 @@ public class ExportAction implements QProfileWsAction {
}
}

private QualityProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) {
QualityProfileDto profile;
private RulesProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) {
RulesProfileDto profile;
if (name == null) {
// return the default profile
profile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, organization, language);

+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java View File

@@ -34,7 +34,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse;
import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse.QualityProfile;
@@ -72,19 +72,19 @@ public class InheritanceAction implements QProfileWsAction {
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto profile = wsSupport.getProfile(dbSession, reference);
RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
String organizationUuid = profile.getOrganizationUuid();
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find organization with uuid '%s' for quality profile '%s'", organizationUuid, profile.getKee())));
List<QualityProfileDto> ancestors = profileLookup.ancestors(profile, dbSession);
List<QualityProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKey());
List<RulesProfileDto> ancestors = profileLookup.ancestors(profile, dbSession);
List<RulesProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKey());
Statistics statistics = new Statistics(dbSession, organization);

writeProtobuf(buildResponse(profile, ancestors, children, statistics), request, response);
}
}

private static InheritanceWsResponse buildResponse(QualityProfileDto profile, List<QualityProfileDto> ancestors, List<QualityProfileDto> children, Statistics statistics) {
private static InheritanceWsResponse buildResponse(RulesProfileDto profile, List<RulesProfileDto> ancestors, List<RulesProfileDto> children, Statistics statistics) {
return InheritanceWsResponse.newBuilder()
.setProfile(buildProfile(profile, statistics))
.addAllAncestors(buildAncestors(ancestors, statistics))
@@ -92,17 +92,17 @@ public class InheritanceAction implements QProfileWsAction {
.build();
}

private static QualityProfile buildProfile(QualityProfileDto profile, Statistics statistics) {
private static QualityProfile buildProfile(RulesProfileDto profile, Statistics statistics) {
return buildProfile(profile.getKey(), profile.getName(), profile.getParentKee(), statistics);
}

private static Iterable<QualityProfile> buildAncestors(List<QualityProfileDto> ancestors, Statistics statistics) {
private static Iterable<QualityProfile> buildAncestors(List<RulesProfileDto> ancestors, Statistics statistics) {
return ancestors.stream()
.map(ancestor -> buildProfile(ancestor.getKey(), ancestor.getName(), ancestor.getParentKee(), statistics))
.collect(Collectors.toList());
}

private static Iterable<QualityProfile> buildChildren(List<QualityProfileDto> children, Statistics statistics) {
private static Iterable<QualityProfile> buildChildren(List<RulesProfileDto> children, Statistics statistics) {
return children.stream()
.map(child -> buildProfile(child.getKey(), child.getName(), null, statistics))
.collect(Collectors.toList());

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java View File

@@ -32,7 +32,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -102,7 +102,7 @@ public class OldRestoreAction implements WsAction {
}

private void writeResponse(JsonWriter json, QProfileRestoreSummary result) {
QualityProfileDto profile = result.getProfile();
RulesProfileDto profile = result.getProfile();
String languageKey = profile.getLanguage();
Language language = languages.get(languageKey);


+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java View File

@@ -40,7 +40,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ProjectQprofileAssociationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;

@@ -135,7 +135,7 @@ public class ProjectsAction implements QProfileWsAction {
}

private List<ProjectQprofileAssociationDto> loadProjects(String profileKey, DbSession session, String selected, String query) {
QualityProfileDto qualityProfile = dbClient.qualityProfileDao().selectByKey(session, profileKey);
RulesProfileDto qualityProfile = dbClient.qualityProfileDao().selectByKey(session, profileKey);
OrganizationDto organization = wsSupport.getOrganization(session, qualityProfile);
List<ProjectQprofileAssociationDto> projects = Lists.newArrayList();
SelectionMode selectionMode = SelectionMode.fromParam(selected);

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java View File

@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.WsUtils;
@@ -50,7 +50,7 @@ public class QProfileWsSupport {
this.defaultOrganizationProvider = defaultOrganizationProvider;
}

public OrganizationDto getOrganization(DbSession dbSession, QualityProfileDto profile) {
public OrganizationDto getOrganization(DbSession dbSession, RulesProfileDto profile) {
requireNonNull(profile);
String organizationUuid = profile.getOrganizationUuid();
return dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
@@ -79,8 +79,8 @@ public class QProfileWsSupport {
*
* @throws org.sonar.server.exceptions.NotFoundException if the specified organization or profile do not exist
*/
public QualityProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
QualityProfileDto profile;
public RulesProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
RulesProfileDto profile;
if (ref.hasKey()) {
profile = dbClient.qualityProfileDao().selectByKey(dbSession, ref.getKey());
checkFound(profile, "Quality Profile with key '%s' does not exist", ref.getKey());
@@ -94,7 +94,7 @@ public class QProfileWsSupport {
}

public void checkPermission(DbSession dbSession, String qualityProfileKey) {
QualityProfileDto qualityProfile = dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey);
RulesProfileDto qualityProfile = dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey);
OrganizationDto organization = getOrganization(dbSession, qualityProfile);
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
}

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.UserSession;
@@ -80,7 +80,7 @@ public class RemoveProjectAction implements QProfileWsAction {

try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = loadProject(dbSession, request);
QualityProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));

if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) {
throw new IllegalArgumentException("Project and Quality profile must have same organization");

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java View File

@@ -30,7 +30,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
@@ -88,7 +88,7 @@ public class RenameAction implements QProfileWsAction {
userSession.checkLoggedIn();

try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto qualityProfile = ofNullable(dbClient.qualityProfileDao().selectByKey(dbSession, profileKey))
RulesProfileDto qualityProfile = ofNullable(dbClient.qualityProfileDao().selectByKey(dbSession, profileKey))
.orElseThrow(() -> new NotFoundException("Quality profile not found: " + profileKey));

String organizationUuid = qualityProfile.getOrganizationUuid();

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java View File

@@ -32,7 +32,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -102,7 +102,7 @@ public class RestoreAction implements QProfileWsAction {
}

private void writeResponse(JsonWriter json, OrganizationDto organization, QProfileRestoreSummary summary) {
QualityProfileDto profile = summary.getProfile();
RulesProfileDto profile = summary.getProfile();
String languageKey = profile.getLanguage();
Language language = languages.get(languageKey);


+ 18
- 11
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java View File

@@ -22,6 +22,7 @@ package org.sonar.server.qualityprofile.ws;
import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.resources.Languages;
@@ -30,11 +31,12 @@ import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.util.LanguageParamUtils;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
@@ -156,12 +158,16 @@ public class SearchAction implements QProfileWsAction {
}
}

List<RulesProfileDto> profiles = dataLoader.findProfiles(dbSession, request, organization, project);
Set<String> defaultProfiles = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, organization.getUuid(), profiles.stream().map(RulesProfileDto::getKey).collect(MoreCollectors.toList()));

return new SearchData()
.setOrganization(organization)
.setProfiles(dataLoader.findProfiles(dbSession, request, organization, project))
.setProfiles(profiles)
.setActiveRuleCountByProfileKey(dbClient.activeRuleDao().countActiveRulesByProfileKey(dbSession, organization))
.setActiveDeprecatedRuleCountByProfileKey(dbClient.activeRuleDao().countActiveRulesForRuleStatusByProfileKey(dbSession, organization, RuleStatus.DEPRECATED))
.setProjectCountByProfileKey(dbClient.qualityProfileDao().countProjectsByProfileKey(dbSession, organization));
.setProjectCountByProfileKey(dbClient.qualityProfileDao().countProjectsByProfileKey(dbSession, organization))
.setDefaultProfileKeys(defaultProfiles);
}
}

@@ -186,12 +192,12 @@ public class SearchAction implements QProfileWsAction {
}

private SearchWsResponse buildResponse(SearchData data) {
List<QualityProfileDto> profiles = data.getProfiles();
Map<String, QualityProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(QualityProfileDto::getKey, identity()));
List<RulesProfileDto> profiles = data.getProfiles();
Map<String, RulesProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(RulesProfileDto::getKey, identity()));

SearchWsResponse.Builder response = SearchWsResponse.newBuilder();

for (QualityProfileDto profile : profiles) {
for (RulesProfileDto profile : profiles) {
QualityProfile.Builder profileBuilder = response.addProfilesBuilder();

String profileKey = profile.getKey();
@@ -203,21 +209,22 @@ public class SearchAction implements QProfileWsAction {
setNullable(profile.getUserUpdatedAt(), userUpdatedAt -> profileBuilder.setUserUpdatedAt(formatDateTime(userUpdatedAt)));
profileBuilder.setActiveRuleCount(data.getActiveRuleCount(profileKey));
profileBuilder.setActiveDeprecatedRuleCount(data.getActiveDeprecatedRuleCount(profileKey));
if (!profile.isDefault()) {
boolean isDefault = data.isDefault(profile);
profileBuilder.setIsDefault(isDefault);
if (!isDefault) {
profileBuilder.setProjectCount(data.getProjectCount(profileKey));
}

writeLanguageFields(profileBuilder, profile);
writeParentFields(profileBuilder, profile, profilesByKey);
profileBuilder.setIsInherited(profile.getParentKee() != null);
profileBuilder.setIsDefault(profile.isDefault());
profileBuilder.setIsBuiltIn(profile.isBuiltIn());
}

return response.build();
}

private void writeLanguageFields(QualityProfile.Builder profileBuilder, QualityProfileDto profile) {
private void writeLanguageFields(QualityProfile.Builder profileBuilder, RulesProfileDto profile) {
String languageKey = profile.getLanguage();
if (languageKey == null) {
return;
@@ -230,14 +237,14 @@ public class SearchAction implements QProfileWsAction {
}
}

private static void writeParentFields(QualityProfile.Builder profileBuilder, QualityProfileDto profile, Map<String, QualityProfileDto> profilesByKey) {
private static void writeParentFields(QualityProfile.Builder profileBuilder, RulesProfileDto profile, Map<String, RulesProfileDto> profilesByKey) {
String parentKey = profile.getParentKee();
if (parentKey == null) {
return;
}

profileBuilder.setParentKey(parentKey);
QualityProfileDto parent = profilesByKey.get(parentKey);
RulesProfileDto parent = profilesByKey.get(parentKey);
if (parent != null && parent.getName() != null) {
profileBuilder.setParentName(parent.getName());
}

+ 15
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java View File

@@ -21,8 +21,9 @@ package org.sonar.server.qualityprofile.ws;

import java.util.List;
import java.util.Map;
import java.util.Set;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.ImmutableList.copyOf;
@@ -30,10 +31,11 @@ import static com.google.common.collect.ImmutableMap.copyOf;

public class SearchData {
private OrganizationDto organization;
private List<QualityProfileDto> profiles;
private List<RulesProfileDto> profiles;
private Map<String, Long> activeRuleCountByProfileKey;
private Map<String, Long> activeDeprecatedRuleCountByProfileKey;
private Map<String, Long> projectCountByProfileKey;
private Set<String> defaultProfileKeys;

public SearchData setOrganization(OrganizationDto organization) {
this.organization = organization;
@@ -44,11 +46,11 @@ public class SearchData {
return organization;
}

public List<QualityProfileDto> getProfiles() {
public List<RulesProfileDto> getProfiles() {
return profiles;
}

public SearchData setProfiles(List<QualityProfileDto> profiles) {
public SearchData setProfiles(List<RulesProfileDto> profiles) {
this.profiles = copyOf(profiles);
return this;
}
@@ -79,4 +81,13 @@ public class SearchData {
public long getActiveDeprecatedRuleCount(String profileKey) {
return firstNonNull(activeDeprecatedRuleCountByProfileKey.get(profileKey), 0L);
}

boolean isDefault(RulesProfileDto profile) {
return defaultProfileKeys.contains(profile.getKey());
}

SearchData setDefaultProfileKeys(Set<String> s) {
this.defaultProfileKeys = s;
return this;
}
}

+ 18
- 18
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java View File

@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.client.qualityprofile.SearchWsRequest;

@@ -44,9 +44,9 @@ import static java.lang.String.format;

public class SearchDataLoader {

private static final Comparator<QualityProfileDto> Q_PROFILE_COMPARATOR = Comparator
.comparing(QualityProfileDto::getLanguage)
.thenComparing(QualityProfileDto::getName);
private static final Comparator<RulesProfileDto> Q_PROFILE_COMPARATOR = Comparator
.comparing(RulesProfileDto::getLanguage)
.thenComparing(RulesProfileDto::getName);

private final Languages languages;
private final QProfileLookup profileLookup;
@@ -59,8 +59,8 @@ public class SearchDataLoader {
}

@VisibleForTesting
List<QualityProfileDto> findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) {
Collection<QualityProfileDto> profiles;
List<RulesProfileDto> findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) {
Collection<RulesProfileDto> profiles;
if (askDefaultProfiles(request)) {
profiles = findDefaultProfiles(dbSession, request, organization);
} else if (project != null) {
@@ -72,11 +72,11 @@ public class SearchDataLoader {
return profiles.stream().sorted(Q_PROFILE_COMPARATOR).collect(Collectors.toList());
}

private Collection<QualityProfileDto> findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
private Collection<RulesProfileDto> findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
String profileName = request.getProfileName();

Set<String> languageKeys = getLanguageKeys();
Map<String, QualityProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
Map<String, RulesProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());

Set<String> missingLanguageKeys = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName);
Set<String> noDefaultProfileLanguageKeys = lookupDefaults(dbSession, organization, qualityProfiles, missingLanguageKeys);
@@ -88,11 +88,11 @@ public class SearchDataLoader {
return qualityProfiles.values();
}

private Collection<QualityProfileDto> findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) {
private Collection<RulesProfileDto> findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) {
String profileName = request.getProfileName();

Set<String> languageKeys = getLanguageKeys();
Map<String, QualityProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
Map<String, RulesProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());

// look up profiles by profileName (if any) for each language
Set<String> unresolvedLanguages = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName);
@@ -108,7 +108,7 @@ public class SearchDataLoader {
return qualityProfiles.values();
}

private List<QualityProfileDto> findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
private List<RulesProfileDto> findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
String language = request.getLanguage();

if (language == null) {
@@ -117,8 +117,8 @@ public class SearchDataLoader {
return profileLookup.profiles(dbSession, language, organization);
}

private Set<String> lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map<String, QualityProfileDto> qualityProfiles, Set<String> languageKeys,
@Nullable String profileName) {
private Set<String> lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys,
@Nullable String profileName) {
if (languageKeys.isEmpty() || profileName == null) {
return languageKeys;
}
@@ -129,8 +129,8 @@ public class SearchDataLoader {
return difference(languageKeys, qualityProfiles.keySet());
}

private Set<String> lookupByModule(DbSession dbSession, OrganizationDto organization, Map<String, QualityProfileDto> qualityProfiles, Set<String> languageKeys,
ComponentDto project) {
private Set<String> lookupByModule(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys,
ComponentDto project) {
if (languageKeys.isEmpty()) {
return languageKeys;
}
@@ -140,7 +140,7 @@ public class SearchDataLoader {
return difference(languageKeys, qualityProfiles.keySet());
}

private Set<String> lookupDefaults(DbSession dbSession, OrganizationDto organization, Map<String, QualityProfileDto> qualityProfiles, Set<String> languageKeys) {
private Set<String> lookupDefaults(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys) {
if (languageKeys.isEmpty()) {
return languageKeys;
}
@@ -153,7 +153,7 @@ public class SearchDataLoader {
return Sets.newHashSet(Sets.difference(languageKeys, set2));
}

private static void addAll(Map<String, QualityProfileDto> qualityProfiles, Collection<QualityProfileDto> list) {
private static void addAll(Map<String, RulesProfileDto> qualityProfiles, Collection<RulesProfileDto> list) {
list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), qualityProfile));
}

@@ -161,7 +161,7 @@ public class SearchDataLoader {
return Arrays.stream(languages.all()).map(Language::getKey).collect(Collectors.toSet());
}

private List<QualityProfileDto> findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set<String> languageKeys) {
private List<RulesProfileDto> findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set<String> languageKeys) {
return dbClient.qualityProfileDao().selectDefaultProfiles(dbSession, organization, languageKeys);
}


+ 5
- 11
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java View File

@@ -26,9 +26,8 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.user.UserSession;

import static java.lang.String.format;
@@ -67,23 +66,18 @@ public class SetDefaultAction implements QProfileWsAction {
userSession.checkLoggedIn();
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
QualityProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference);
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, qualityProfile.getOrganizationUuid())
RulesProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference);
dbClient.organizationDao().selectByUuid(dbSession, qualityProfile.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(
format("Cannot find organization '%s' for quality profile '%s'", qualityProfile.getOrganizationUuid(), qualityProfile.getKee())));
userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, qualityProfile.getOrganizationUuid());
setDefault(dbSession, organization, qualityProfile);
setDefault(dbSession, qualityProfile);
dbSession.commit();
}
response.noContent();
}

public void setDefault(DbSession dbSession, OrganizationDto organization, QualityProfileDto profile) {
QualityProfileDto previousDefault = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, organization, profile.getLanguage());
if (previousDefault != null) {
dbClient.qualityProfileDao().update(dbSession, previousDefault.setDefault(false));
}
dbClient.qualityProfileDao().update(dbSession, profile.setDefault(true));
public void setDefault(DbSession dbSession, RulesProfileDto profile) {
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
}
}

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java View File

@@ -44,7 +44,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.qualityprofile.ActiveRule;
@@ -178,10 +178,10 @@ public class ActiveRuleCompleter {
}

private Rules.QProfiles.Builder buildQProfiles(DbSession dbSession, Collection<String> harvestedProfileKeys) {
Map<String, QualityProfileDto> qProfilesByKey = new HashMap<>();
Map<String, RulesProfileDto> qProfilesByKey = new HashMap<>();
for (String qProfileKey : harvestedProfileKeys) {
if (!qProfilesByKey.containsKey(qProfileKey)) {
QualityProfileDto profile = loadProfile(dbSession, qProfileKey);
RulesProfileDto profile = loadProfile(dbSession, qProfileKey);
if (profile == null) {
LOG.warn("Could not find quality profile with key " + qProfileKey);
continue;
@@ -196,7 +196,7 @@ public class ActiveRuleCompleter {

Rules.QProfiles.Builder qProfilesResponse = Rules.QProfiles.newBuilder();
Map<String, Rules.QProfile> qProfilesMapResponse = qProfilesResponse.getMutableQProfiles();
for (QualityProfileDto profile : qProfilesByKey.values()) {
for (RulesProfileDto profile : qProfilesByKey.values()) {
writeProfile(qProfilesMapResponse, profile);
}

@@ -204,11 +204,11 @@ public class ActiveRuleCompleter {
}

@CheckForNull
private QualityProfileDto loadProfile(DbSession dbSession, String qProfileKey) {
private RulesProfileDto loadProfile(DbSession dbSession, String qProfileKey) {
return dbClient.qualityProfileDao().selectByKey(dbSession, qProfileKey);
}

private void writeProfile(Map<String, Rules.QProfile> profilesResponse, QualityProfileDto profile) {
private void writeProfile(Map<String, Rules.QProfile> profilesResponse, RulesProfileDto profile) {
Rules.QProfile.Builder profileResponse = Rules.QProfile.newBuilder();
setNullable(profile.getName(), profileResponse::setName);


+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.user.UserSession;

import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION;
@@ -87,7 +87,7 @@ public class AppAction implements RulesWsAction {

private void addProfiles(DbSession dbSession, OrganizationDto organization, JsonWriter json) {
json.name("qualityprofiles").beginArray();
for (QualityProfileDto profile : dbClient.qualityProfileDao().selectAll(dbSession, organization)) {
for (RulesProfileDto profile : dbClient.qualityProfileDao().selectAll(dbSession, organization)) {
if (languageIsSupported(profile)) {
json
.beginObject()
@@ -101,7 +101,7 @@ public class AppAction implements RulesWsAction {
json.endArray();
}

private boolean languageIsSupported(QualityProfileDto profile) {
private boolean languageIsSupported(RulesProfileDto profile) {
return languages.get(profile.getLanguage()) != null;
}


+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java View File

@@ -32,7 +32,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.ws.WsUtils;

@@ -88,8 +88,8 @@ public class RuleQueryFactory {
organizationUuid = wsSupport.getOrganizationByKey(dbSession, organizationKey).getUuid();
languages = request.paramAsStrings(PARAM_LANGUAGES);
} else {
QualityProfileDto qualityProfileOptional = dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey);
QualityProfileDto qualityProfile = WsUtils.checkFound(qualityProfileOptional, "The specified qualityProfile '%s' does not exist", qualityProfileKey);
RulesProfileDto qualityProfileOptional = dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey);
RulesProfileDto qualityProfile = WsUtils.checkFound(qualityProfileOptional, "The specified qualityProfile '%s' does not exist", qualityProfileKey);
query.setQProfileKey(qualityProfileKey);
languages = ImmutableList.of(qualityProfile.getLanguage());
organizationUuid = qualityProfile.getOrganizationUuid();
@@ -121,7 +121,7 @@ public class RuleQueryFactory {
}

@CheckForNull
private QualityProfileDto getProfileByKey(DbSession dbSession, String key) {
private RulesProfileDto getProfileByKey(DbSession dbSession, String key) {
return dbClient.qualityProfileDao().selectByKey(dbSession, key);
}


+ 5
- 3
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java View File

@@ -37,7 +37,8 @@ import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.source.FileSourceDto;
import org.sonar.db.source.FileSourceDto.Type;
@@ -604,9 +605,10 @@ public class ProjectDataLoaderMediumTest {
private void addDefaultProfile() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto, false);
QualityProfileDto profileDto = newQProfileDto(organizationDto, QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
formatDateTime(new Date())).setDefault(true);
RulesProfileDto profileDto = newQProfileDto(organizationDto, QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
formatDateTime(new Date()));
dbClient.qualityProfileDao().insert(dbSession, profileDto);
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profileDto));
}

private static FileSourceDto newFileSourceDto(ComponentDto file) {

+ 11
- 11
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java View File

@@ -32,7 +32,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.qualityprofile.QualityProfileDbTester;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
@@ -51,9 +51,9 @@ import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfil
public class UpdateQualityProfilesLastUsedDateStepTest {
static final long ANALYSIS_DATE = 1_123_456_789L;
private static final Component PROJECT = ReportComponent.DUMB_PROJECT;
private QualityProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
private QualityProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
private QualityProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");
private RulesProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
private RulesProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
private RulesProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");

@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -107,12 +107,12 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
@Test
public void ancestor_profiles_are_updated() throws Exception {
// Parent profiles should be updated
QualityProfileDto rootProfile = newQualityProfileDto().setKey("root");
QualityProfileDto parentProfile = newQualityProfileDto().setKey("parent").setParentKee(rootProfile.getKey());
RulesProfileDto rootProfile = newQualityProfileDto().setKey("root");
RulesProfileDto parentProfile = newQualityProfileDto().setKey("parent").setParentKee(rootProfile.getKey());
// Current profile => should be updated
QualityProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee(parentProfile.getKey());
RulesProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee(parentProfile.getKey());
// Child of current profile => should not be updated
QualityProfileDto childProfile = newQualityProfileDto().setKey("child").setParentKee(currentProfile.getKey());
RulesProfileDto childProfile = newQualityProfileDto().setKey("child").setParentKee(currentProfile.getKey());
qualityProfileDb.insertQualityProfiles(rootProfile, parentProfile, currentProfile, childProfile);

measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKey())));
@@ -127,7 +127,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest {

@Test
public void fail_when_profile_is_linked_to_unknown_parent() throws Exception {
QualityProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
RulesProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
qualityProfileDb.insertQualityProfiles(currentProfile);

measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKey())));
@@ -141,11 +141,11 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
assertThat(underTest.getDescription()).isEqualTo("Update last usage date of quality profiles");
}

private void assertQualityProfileIsUpdated(QualityProfileDto qp) {
private void assertQualityProfileIsUpdated(RulesProfileDto qp) {
assertThat(selectLastUser(qp.getKey())).withFailMessage("Quality profile '%s' hasn't been updated. Value: %d", qp.getKey(), qp.getLastUsed()).isEqualTo(ANALYSIS_DATE);
}

private void assertQualityProfileIsTheSame(QualityProfileDto qp) {
private void assertQualityProfileIsTheSame(RulesProfileDto qp) {
assertThat(selectLastUser(qp.getKey())).isEqualTo(qp.getLastUsed());
}


+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java View File

@@ -37,7 +37,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentCleanerService;
@@ -321,8 +321,8 @@ public class DeleteActionTest {
public void request_also_deletes_quality_profiles_of_specified_organization() {
OrganizationDto org = db.organizations().insert();
OrganizationDto otherOrg = db.organizations().insert();
QualityProfileDto profileInOrg = db.qualityProfiles().insert(org);
QualityProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);
RulesProfileDto profileInOrg = db.qualityProfiles().insert(org);
RulesProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);

logInAsAdministrator(org);


+ 8
- 8
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java View File

@@ -44,7 +44,7 @@ import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -126,14 +126,14 @@ public class QProfileBackuperMediumTest {
ruleIndexer.indexRuleDefinition(blahRule.getKey());

// create profile P1 with rules x2 and x1 activated
QualityProfileDto profile = newXooP1(organization);
RulesProfileDto profile = newXooP1(organization);
db.qualityProfileDao().insert(dbSession, profile);
RuleActivation activation1 = new RuleActivation(XOO_X2).setSeverity("MINOR");
RuleActivation activation2 = new RuleActivation(XOO_X1);
RuleActivation activation3 = new RuleActivation(blahRuleKey);
activation2.setSeverity(Severity.BLOCKER);
activation2.setParameter("max", "7");
QualityProfileDto profileDto = get(XOO_P1_NAME);
RulesProfileDto profileDto = get(XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation1, profileDto);
tester.get(RuleActivator.class).activate(dbSession, activation2, profileDto);
tester.get(RuleActivator.class).activate(dbSession, activation3, profileDto);
@@ -156,7 +156,7 @@ public class QProfileBackuperMediumTest {
organization, null);

// Check in db
QualityProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
RulesProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
assertThat(profile).isNotNull();

List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profile.getKey());
@@ -182,7 +182,7 @@ public class QProfileBackuperMediumTest {
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(Severity.INFO);
activation.setParameter("max", "10");
QualityProfileDto profileDto = get(XOO_P1_NAME);
RulesProfileDto profileDto = get(XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation, profileDto);

activation = new RuleActivation(XOO_X2);
@@ -379,7 +379,7 @@ public class QProfileBackuperMediumTest {
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
assertThat(activeRules).hasSize(0);

QualityProfileDto target = db.qualityProfileDao().selectByNameAndLanguage(organization, "P3", "xoo", dbSession);
RulesProfileDto target = db.qualityProfileDao().selectByNameAndLanguage(organization, "P3", "xoo", dbSession);
assertThat(target).isNotNull();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, target.getKey())).hasSize(1);
}
@@ -392,7 +392,7 @@ public class QProfileBackuperMediumTest {

dbSession.clearCache();
assertThat(anyActiveRuleExists()).isFalse();
List<QualityProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
List<RulesProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
assertThat(profiles).hasSize(1);
assertThat(profiles.get(0).getName()).isEqualTo("P1");
}
@@ -404,7 +404,7 @@ public class QProfileBackuperMediumTest {
}
}

private QualityProfileDto get(QProfileName profileName) {
private RulesProfileDto get(QProfileName profileName) {
return db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
}
}

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java View File

@@ -30,7 +30,7 @@ import org.sonar.api.rule.Severity;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
@@ -56,8 +56,8 @@ public class QProfileComparisonMediumTest {

RuleDto xooRule1;
RuleDto xooRule2;
QualityProfileDto left;
QualityProfileDto right;
RulesProfileDto left;
RulesProfileDto right;

@Before
public void before() {

+ 4
- 4
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java View File

@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -65,7 +65,7 @@ public class QProfileCopierMediumTest {
private RuleIndexer ruleIndexer;
private ActiveRuleIndexer activeRuleIndexer;
private OrganizationDto organization;
private QualityProfileDto sourceProfile;
private RulesProfileDto sourceProfile;

@Before
public void before() {
@@ -169,7 +169,7 @@ public class QProfileCopierMediumTest {
copier.copyToName(dbSession, sourceProfile, QProfileTesting.XOO_P2_NAME.getName());

verifyOneActiveRule(QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
QualityProfileDto profile2Dto = db.qualityProfileDao().selectByKey(dbSession, QProfileTesting.XOO_P2_KEY);
RulesProfileDto profile2Dto = db.qualityProfileDao().selectByKey(dbSession, QProfileTesting.XOO_P2_KEY);
assertThat(profile2Dto.getParentKee()).isEqualTo(QProfileTesting.XOO_P1_KEY);
}

@@ -193,7 +193,7 @@ public class QProfileCopierMediumTest {

private void verifyOneActiveRule(QProfileName profileName, String expectedSeverity,
@Nullable String expectedInheritance, Map<String, String> expectedParams) {
QualityProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
RulesProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
verifyOneActiveRule(dto.getKey(), expectedSeverity, expectedInheritance, expectedParams);
}


+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java View File

@@ -41,7 +41,7 @@ import org.sonar.api.utils.ValidationMessages;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.index.RuleIndex;
@@ -102,7 +102,7 @@ public class QProfileExportersTest {

@Test
public void import_xml() {
QualityProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
RulesProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();


+ 6
- 8
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -69,7 +69,7 @@ public class QProfileFactoryMediumTest {
public void checkAndCreate() {
String uuid = organization.getUuid();

QualityProfileDto writtenDto = factory.checkAndCreateCustom(dbSession, organization, new QProfileName("xoo", "P1"));
RulesProfileDto writtenDto = factory.checkAndCreateCustom(dbSession, organization, new QProfileName("xoo", "P1"));
dbSession.commit();
dbSession.clearCache();
assertThat(writtenDto.getOrganizationUuid()).isEqualTo(uuid);
@@ -80,7 +80,7 @@ public class QProfileFactoryMediumTest {
assertThat(writtenDto.isBuiltIn()).isFalse();

// reload the dto
QualityProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
RulesProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
assertEqual(writtenDto, readDto);

assertThat(db.qualityProfileDao().selectAll(dbSession, organization)).hasSize(1);
@@ -90,7 +90,7 @@ public class QProfileFactoryMediumTest {
public void create() {
String uuid = organization.getUuid();

QualityProfileDto writtenDto = factory.createBuiltIn(dbSession, organization, new QProfileName("xoo", "P1"), true);
RulesProfileDto writtenDto = factory.createBuiltIn(dbSession, organization, new QProfileName("xoo", "P1"), true);
dbSession.commit();
dbSession.clearCache();
assertThat(writtenDto.getOrganizationUuid()).isEqualTo(uuid);
@@ -99,10 +99,9 @@ public class QProfileFactoryMediumTest {
assertThat(writtenDto.getLanguage()).isEqualTo("xoo");
assertThat(writtenDto.getId()).isNotNull();
assertThat(writtenDto.getParentKee()).isNull();
assertThat(writtenDto.isDefault()).isTrue();

// reload the dto
QualityProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
RulesProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
assertEqual(writtenDto, readDto);

assertThat(db.qualityProfileDao().selectAll(dbSession, organization)).hasSize(1);
@@ -171,13 +170,12 @@ public class QProfileFactoryMediumTest {
thrown.expectMessage(message);
}

private static void assertEqual(QualityProfileDto writtenDto, QualityProfileDto readDto) {
private static void assertEqual(RulesProfileDto writtenDto, RulesProfileDto readDto) {
assertThat(readDto.getOrganizationUuid()).isEqualTo(writtenDto.getOrganizationUuid());
assertThat(readDto.getName()).isEqualTo(writtenDto.getName());
assertThat(readDto.getKey()).startsWith(writtenDto.getKey());
assertThat(readDto.getLanguage()).isEqualTo(writtenDto.getLanguage());
assertThat(readDto.getId()).isEqualTo(writtenDto.getId());
assertThat(readDto.getParentKee()).isEqualTo(writtenDto.getParentKee());
assertThat(readDto.isDefault()).isEqualTo(writtenDto.isDefault());
}
}

+ 8
- 8
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java View File

@@ -34,7 +34,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
@@ -65,9 +65,9 @@ public class QProfileFactoryTest {
@Test
public void deleteByKeys_deletes_profiles_in_db_and_elasticsearch() {
OrganizationDto org = db.organizations().insert();
QualityProfileDto profile1 = createRandomProfile(org);
QualityProfileDto profile2 = createRandomProfile(org);
QualityProfileDto profile3 = createRandomProfile(org);
RulesProfileDto profile1 = createRandomProfile(org);
RulesProfileDto profile2 = createRandomProfile(org);
RulesProfileDto profile3 = createRandomProfile(org);

List<String> profileKeys = asList(profile1.getKey(), profile2.getKey(), "does_not_exist");
underTest.deleteByKeys(db.getSession(), profileKeys);
@@ -81,7 +81,7 @@ public class QProfileFactoryTest {
@Test
public void deleteByKeys_accepts_empty_list_of_keys() {
OrganizationDto org = db.organizations().insert();
QualityProfileDto profile1 = createRandomProfile(org);
RulesProfileDto profile1 = createRandomProfile(org);

underTest.deleteByKeys(db.getSession(), Collections.emptyList());

@@ -89,8 +89,8 @@ public class QProfileFactoryTest {
assertQualityProfileFromDb(profile1).isNotNull();
}

private QualityProfileDto createRandomProfile(OrganizationDto org) {
QualityProfileDto profile = db.qualityProfiles().insert(org);
private RulesProfileDto createRandomProfile(OrganizationDto org) {
RulesProfileDto profile = db.qualityProfiles().insert(org);
ComponentDto project = db.components().insertPrivateProject(org);
db.qualityProfiles().associateProjectWithQualityProfile(project, profile);
ActiveRuleDto activeRuleDto = new ActiveRuleDto()
@@ -107,7 +107,7 @@ public class QProfileFactoryTest {
return profile;
}

private AbstractObjectAssert<?, QualityProfileDto> assertQualityProfileFromDb(QualityProfileDto profile) {
private AbstractObjectAssert<?, RulesProfileDto> assertQualityProfileFromDb(RulesProfileDto profile) {
return assertThat(db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), profile.getKey()));
}
}

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileResetMediumTest.java View File

@@ -42,7 +42,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.platform.Platform;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -125,7 +125,7 @@ public class QProfileResetMediumTest {
defProfile);

RuleKey ruleKey = RuleKey.of("xoo", "x1");
QualityProfileDto profile = tester.get(QualityProfileDao.class).selectByNameAndLanguage(defaultOrganization, "Basic", ServerTester.Xoo.KEY, dbSession);
RulesProfileDto profile = tester.get(QualityProfileDao.class).selectByNameAndLanguage(defaultOrganization, "Basic", ServerTester.Xoo.KEY, dbSession);
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);

// Change the severity and the value of the parameter in the active rule
@@ -174,7 +174,7 @@ public class QProfileResetMediumTest {
}
}, defProfile);

QualityProfileDto profile = tester.get(QualityProfileDao.class).selectByNameAndLanguage(defaultOrganization, "Basic", ServerTester.Xoo.KEY, dbSession);
RulesProfileDto profile = tester.get(QualityProfileDao.class).selectByNameAndLanguage(defaultOrganization, "Basic", ServerTester.Xoo.KEY, dbSession);
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), RuleKey.of("xoo", "x1"));

// Change param in the rule def

+ 11
- 11
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTesting.java View File

@@ -22,7 +22,7 @@ package org.sonar.server.qualityprofile;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.tester.ServerTester;

@@ -42,15 +42,15 @@ public class QProfileTesting {
* @deprecated provide organization as dto
*/
@Deprecated
public static QualityProfileDto newQProfileDto(String organizationUuid, QProfileName name, String key) {
return QualityProfileDto.createFor(key).setOrganizationUuid(organizationUuid).setName(name.getName()).setLanguage(name.getLanguage());
public static RulesProfileDto newQProfileDto(String organizationUuid, QProfileName name, String key) {
return RulesProfileDto.createFor(key).setOrganizationUuid(organizationUuid).setName(name.getName()).setLanguage(name.getLanguage());
}

/**
* @deprecated provide organization as dto
*/
@Deprecated
public static QualityProfileDto newXooP1(String organizationUuid) {
public static RulesProfileDto newXooP1(String organizationUuid) {
return newQProfileDto(organizationUuid, XOO_P1_NAME, XOO_P1_KEY);
}

@@ -58,7 +58,7 @@ public class QProfileTesting {
* @deprecated provide organization as dto
*/
@Deprecated
public static QualityProfileDto newXooP2(String organizationUuid) {
public static RulesProfileDto newXooP2(String organizationUuid) {
return newQProfileDto(organizationUuid, XOO_P2_NAME, XOO_P2_KEY);
}

@@ -66,23 +66,23 @@ public class QProfileTesting {
* @deprecated provide organization as dto
*/
@Deprecated
public static QualityProfileDto newXooP3(String organizationUuid) {
public static RulesProfileDto newXooP3(String organizationUuid) {
return newQProfileDto(organizationUuid, XOO_P3_NAME, XOO_P3_KEY);
}

public static QualityProfileDto newQProfileDto(OrganizationDto organization, QProfileName name, String key) {
return QualityProfileDto.createFor(key).setOrganizationUuid(organization.getUuid()).setName(name.getName()).setLanguage(name.getLanguage());
public static RulesProfileDto newQProfileDto(OrganizationDto organization, QProfileName name, String key) {
return RulesProfileDto.createFor(key).setOrganizationUuid(organization.getUuid()).setName(name.getName()).setLanguage(name.getLanguage());
}

public static QualityProfileDto newXooP1(OrganizationDto organization) {
public static RulesProfileDto newXooP1(OrganizationDto organization) {
return newQProfileDto(organization, XOO_P1_NAME, XOO_P1_KEY);
}

public static QualityProfileDto newXooP2(OrganizationDto organization) {
public static RulesProfileDto newXooP2(OrganizationDto organization) {
return newQProfileDto(organization, XOO_P2_NAME, XOO_P2_KEY);
}

public static QualityProfileDto newXooP3(OrganizationDto organization) {
public static RulesProfileDto newXooP3(OrganizationDto organization) {
return newQProfileDto(organization, XOO_P3_NAME, XOO_P3_KEY);
}


+ 7
- 9
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesMediumTest.java View File

@@ -39,8 +39,9 @@ import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.platform.Platform;
import org.sonar.server.rule.index.RuleIndex;
@@ -79,7 +80,7 @@ public class RegisterQualityProfilesMediumTest {
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession, organization)).hasSize(1);
QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage(organization, "Basic", "xoo", dbSession);
RulesProfileDto profile = qualityProfileDao.selectByNameAndLanguage(organization, "Basic", "xoo", dbSession);
assertThat(profile).isNotNull();
assertThat(profile.isBuiltIn()).isTrue();

@@ -129,7 +130,7 @@ public class RegisterQualityProfilesMediumTest {
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient.qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession, organization)).hasSize(1);
QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage(organization, "Basic", "xoo", dbSession);
RulesProfileDto profile = qualityProfileDao.selectByNameAndLanguage(organization, "Basic", "xoo", dbSession);
assertThat(profile).isNotNull();
assertThat(profile.isBuiltIn()).isTrue();

@@ -211,11 +212,8 @@ public class RegisterQualityProfilesMediumTest {
dbSession = dbClient().openSession(false);
OrganizationDto organization = getDefaultOrganization(tester, dbClient, dbSession);

QualityProfileDao dao = dbClient().qualityProfileDao();
dao.update(dbSession, dao.selectDefaultProfile(dbSession, organization, "xoo")
.setDefault(false));
dao.update(dbSession, dao.selectByNameAndLanguage(organization, "two", "xoo", dbSession)
.setDefault(true));
RulesProfileDto profile = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "two", "xoo", dbSession);
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
dbSession.commit();

verifyDefaultProfile(organization, "xoo", "two");
@@ -227,7 +225,7 @@ public class RegisterQualityProfilesMediumTest {

private void verifyDefaultProfile(OrganizationDto organization, String language, String name) {
dbSession = dbClient().openSession(false);
QualityProfileDto defaultProfile = dbClient().qualityProfileDao().selectDefaultProfile(dbSession, organization, language);
RulesProfileDto defaultProfile = dbClient().qualityProfileDao().selectDefaultProfile(dbSession, organization, language);
assertThat(defaultProfile).isNotNull();
assertThat(defaultProfile.getName()).isEqualTo(name);
}

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesTest.java View File

@@ -33,7 +33,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.tester.UserSessionRule;
@@ -108,8 +108,8 @@ public class RegisterQualityProfilesTest {
OrganizationDto org1 = dbTester.organizations().insert(org -> org.setKey("org1"));
OrganizationDto org2 = dbTester.organizations().insert(org -> org.setKey("org2"));

QualityProfileDto outdatedProfileInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
QualityProfileDto outdatedProfileInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
RulesProfileDto outdatedProfileInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
RulesProfileDto outdatedProfileInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage(FOO_LANGUAGE.getKey()).setName("Sonar way"));
builtInQProfileRepositoryRule.add(FOO_LANGUAGE, "Sonar way", false);
builtInQProfileRepositoryRule.initialize();


+ 4
- 4
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java View File

@@ -40,7 +40,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -98,7 +98,7 @@ public class RuleActivatorMediumTest {

ActiveRuleIndexer activeRuleIndexer;

QualityProfileDto profileDto;
RulesProfileDto profileDto;
private OrganizationDto organization;

@Before
@@ -1197,13 +1197,13 @@ public class RuleActivatorMediumTest {
}

private void assertProfileHasBeenUpdatedManually(String profileKey) {
QualityProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
RulesProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
assertThat(profile.getRulesUpdatedAt()).isNotEmpty();
assertThat(profile.getUserUpdatedAt()).isNotNull();
}

private void assertProfileHasBeenUpdatedAutomatically(String profileKey) {
QualityProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
RulesProfileDto profile = db.qualityProfileDao().selectByKey(dbSession, profileKey);
assertThat(profile.getRulesUpdatedAt()).isNotEmpty();
assertThat(profile.getUserUpdatedAt()).isNull();
}

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java View File

@@ -31,7 +31,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
@@ -144,7 +144,7 @@ public class ActiveRuleIndexerTest {
// Index one active rule
RuleDefinitionDto rule = RuleTesting.newRule(RULE_KEY_1);
dbTester.rules().insert(rule);
QualityProfileDto profile = QualityProfileDto.createFor("qp")
RulesProfileDto profile = RulesProfileDto.createFor("qp")
.setOrganizationUuid(organization.getUuid())
.setLanguage("xoo")
.setName("profile");

+ 4
- 4
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRuleActionTest.java View File

@@ -34,7 +34,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -101,7 +101,7 @@ public class ActivateRuleActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
@@ -114,7 +114,7 @@ public class ActivateRuleActionTest {
@Test
public void activate_rule_in_default_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -138,7 +138,7 @@ public class ActivateRuleActionTest {
@Test
public void activate_rule_in_specific_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ActivateRulesActionTest.java View File

@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
@@ -109,7 +109,7 @@ public class ActivateRulesActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("profile_key", qualityProfile.getKey());

+ 20
- 20
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java View File

@@ -30,8 +30,8 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -83,7 +83,7 @@ public class AddProjectActionTest {
public void add_project_on_profile_of_default_organization() {
logInAsProfileAdmin(db.getDefaultOrganization());
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());

TestResponse response = call(project, profile);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
@@ -96,7 +96,7 @@ public class AddProjectActionTest {
OrganizationDto org1 = db.organizations().insert();
logInAsProfileAdmin(org1);
ComponentDto project = db.components().insertPrivateProject(org1);
QualityProfileDto profile = db.qualityProfiles().insert(org1, p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profile = db.qualityProfiles().insert(org1, p -> p.setLanguage(LANGUAGE_1));

TestResponse response = call(org1, project, profile);
assertThat(response.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
@@ -110,7 +110,7 @@ public class AddProjectActionTest {
OrganizationDto org2 = db.organizations().insert();
logInAsProfileAdmin(org1);
ComponentDto project = db.components().insertPrivateProject(org1);
QualityProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Project and Quality profile must have same organization");
@@ -126,7 +126,7 @@ public class AddProjectActionTest {
OrganizationDto org2 = db.organizations().insert();
logInAsProfileAdmin(org1);
ComponentDto project = db.components().insertPrivateProject(org1);
QualityProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profileInOrg2 = db.qualityProfiles().insert(org2, p -> p.setLanguage(LANGUAGE_1));

expectedException.expect(NotFoundException.class);
expectedException
@@ -143,8 +143,8 @@ public class AddProjectActionTest {

ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
// two profiles on same language
QualityProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
QualityProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
db.qualityProfiles().associateProjectWithQualityProfile(project, profile1);

call(project, profile2);
@@ -157,9 +157,9 @@ public class AddProjectActionTest {
public void changing_association_does_not_change_other_language_associations() throws Exception {
logInAsProfileAdmin(db.getDefaultOrganization());
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile1Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
QualityProfileDto profile2Language2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
QualityProfileDto profile3Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profile1Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
RulesProfileDto profile2Language2 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_2));
RulesProfileDto profile3Language1 = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(LANGUAGE_1));
db.qualityProfiles().associateProjectWithQualityProfile(project, profile1Language1, profile2Language2);

call(project, profile3Language1);
@@ -171,7 +171,7 @@ public class AddProjectActionTest {
@Test
public void project_administrator_can_change_profile() throws Exception {
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);

call(project, profile);
@@ -183,7 +183,7 @@ public class AddProjectActionTest {
public void throw_ForbiddenException_if_not_project_nor_organization_administrator() {
userSession.logIn();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());

expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@@ -195,7 +195,7 @@ public class AddProjectActionTest {
public void throw_UnauthorizedException_if_not_logged_in() {
userSession.anonymous();
ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());

expectedException.expect(UnauthorizedException.class);
expectedException.expectMessage("Authentication is required");
@@ -206,7 +206,7 @@ public class AddProjectActionTest {
@Test
public void throw_NotFoundException_if_project_does_not_exist() {
logInAsProfileAdmin(db.getDefaultOrganization());
QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
RulesProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());

expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Component id 'unknown' not found");
@@ -231,13 +231,13 @@ public class AddProjectActionTest {
.execute();
}

private void assertProjectIsAssociatedToProfile(ComponentDto project, QualityProfileDto profile) {
QualityProfileDto loaded = dbClient.qualityProfileDao().selectByProjectAndLanguage(db.getSession(), project.getKey(), profile.getLanguage());
private void assertProjectIsAssociatedToProfile(ComponentDto project, RulesProfileDto profile) {
RulesProfileDto loaded = dbClient.qualityProfileDao().selectByProjectAndLanguage(db.getSession(), project.getKey(), profile.getLanguage());
assertThat(loaded.getKey()).isEqualTo(profile.getKey());
}

private void assertProjectIsNotAssociatedToProfile(ComponentDto project, QualityProfileDto profile) {
QualityProfileDto loaded = dbClient.qualityProfileDao().selectByProjectAndLanguage(db.getSession(), project.getKey(), profile.getLanguage());
private void assertProjectIsNotAssociatedToProfile(ComponentDto project, RulesProfileDto profile) {
RulesProfileDto loaded = dbClient.qualityProfileDao().selectByProjectAndLanguage(db.getSession(), project.getKey(), profile.getLanguage());
assertThat(loaded == null || !loaded.getKey().equals(profile.getKey())).isTrue();
}

@@ -245,14 +245,14 @@ public class AddProjectActionTest {
userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES, organization);
}

private TestResponse call(ComponentDto project, QualityProfileDto qualityProfile) {
private TestResponse call(ComponentDto project, RulesProfileDto qualityProfile) {
TestRequest request = tester.newRequest()
.setParam("projectUuid", project.uuid())
.setParam("profileKey", qualityProfile.getKey());
return request.execute();
}

private TestResponse call(OrganizationDto organization, ComponentDto project, QualityProfileDto qualityProfile) {
private TestResponse call(OrganizationDto organization, ComponentDto project, RulesProfileDto qualityProfile) {
TestRequest request = tester.newRequest()
.setParam("organization", organization.getKey())
.setParam("projectUuid", project.uuid())

+ 8
- 8
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/BackupActionTest.java View File

@@ -26,7 +26,7 @@ import org.sonar.api.resources.Languages;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.language.LanguageTesting;
@@ -78,7 +78,7 @@ public class BackupActionTest {

@Test
public void returns_backup_of_profile_with_specified_key() throws Exception {
QualityProfileDto profile = db.qualityProfiles().insertQualityProfile(QualityProfileTesting.newQualityProfileDto());
RulesProfileDto profile = db.qualityProfiles().insertQualityProfile(QualityProfileTesting.newQualityProfileDto());

TestResponse response = tester.newRequest().setParam("profileKey", profile.getKey()).execute();
assertThat(response.getMediaType()).isEqualTo("application/xml");
@@ -88,7 +88,7 @@ public class BackupActionTest {

@Test
public void returns_backup_of_profile_with_specified_name_on_default_organization() throws Exception {
QualityProfileDto profile = newProfile(db.getDefaultOrganization());
RulesProfileDto profile = newProfile(db.getDefaultOrganization());
db.qualityProfiles().insertQualityProfile(profile);

TestResponse response = tester.newRequest()
@@ -101,7 +101,7 @@ public class BackupActionTest {
@Test
public void returns_backup_of_profile_with_specified_name_and_organization() throws Exception {
OrganizationDto org = db.organizations().insert();
QualityProfileDto profile = newProfile(org);
RulesProfileDto profile = newProfile(org);
db.qualityProfiles().insertQualityProfile(profile);

TestResponse response = tester.newRequest()
@@ -135,10 +135,10 @@ public class BackupActionTest {
@Test
public void throws_NotFoundException_if_profile_name_exists_but_in_another_organization() throws Exception {
OrganizationDto org1 = db.organizations().insert();
QualityProfileDto profileInOrg1 = newProfile(org1);
RulesProfileDto profileInOrg1 = newProfile(org1);
db.qualityProfiles().insertQualityProfile(profileInOrg1);
OrganizationDto org2 = db.organizations().insert();
QualityProfileDto profileInOrg2 = newProfile(org2).setLanguage(profileInOrg1.getLanguage());
RulesProfileDto profileInOrg2 = newProfile(org2).setLanguage(profileInOrg1.getLanguage());

expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Quality Profile for language 'xoo' and name '" + profileInOrg1.getName() + "' does not exist in organization '" + org2.getKey() +"'");
@@ -157,7 +157,7 @@ public class BackupActionTest {
tester.newRequest().execute();
}

private static String xmlForProfileWithoutRules(QualityProfileDto profile) {
private static String xmlForProfileWithoutRules(RulesProfileDto profile) {
return "<?xml version='1.0' encoding='UTF-8'?>" +
"<profile>" +
" <name>" + profile.getName() + "</name>" +
@@ -166,7 +166,7 @@ public class BackupActionTest {
"</profile>";
}

private static QualityProfileDto newProfile(OrganizationDto org) {
private static RulesProfileDto newProfile(OrganizationDto org) {
return QualityProfileTesting.newQualityProfileDto()
.setLanguage(A_LANGUAGE)
.setOrganizationUuid(org.getUuid());

+ 20
- 20
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java View File

@@ -40,7 +40,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
@@ -153,8 +153,8 @@ public class ChangeParentActionTest {

@Test
public void change_parent_with_no_parent_before() throws Exception {
QualityProfileDto parent1 = createProfile();
QualityProfileDto child = createProfile();
RulesProfileDto parent1 = createProfile();
RulesProfileDto child = createProfile();

RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent1);
@@ -180,9 +180,9 @@ public class ChangeParentActionTest {

@Test
public void replace_existing_parent() throws Exception {
QualityProfileDto parent1 = createProfile();
QualityProfileDto parent2 = createProfile();
QualityProfileDto child = createProfile();
RulesProfileDto parent1 = createProfile();
RulesProfileDto parent2 = createProfile();
RulesProfileDto child = createProfile();

RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
@@ -211,8 +211,8 @@ public class ChangeParentActionTest {

@Test
public void remove_parent() throws Exception {
QualityProfileDto parent = createProfile();
QualityProfileDto child = createProfile();
RulesProfileDto parent = createProfile();
RulesProfileDto child = createProfile();

RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
@@ -237,9 +237,9 @@ public class ChangeParentActionTest {

@Test
public void change_parent_with_names() throws Exception {
QualityProfileDto parent1 = createProfile();
QualityProfileDto parent2 = createProfile();
QualityProfileDto child = createProfile();
RulesProfileDto parent1 = createProfile();
RulesProfileDto parent2 = createProfile();
RulesProfileDto child = createProfile();

RuleDefinitionDto rule1 = createRule();
RuleDefinitionDto rule2 = createRule();
@@ -299,8 +299,8 @@ public class ChangeParentActionTest {

@Test
public void remove_parent_with_empty_key() throws Exception {
QualityProfileDto parent = createProfile();
QualityProfileDto child = createProfile();
RulesProfileDto parent = createProfile();
RulesProfileDto child = createProfile();

RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
@@ -327,7 +327,7 @@ public class ChangeParentActionTest {

@Test
public void fail_if_parent_key_and_name_both_set() throws Exception {
QualityProfileDto child = createProfile();
RulesProfileDto child = createProfile();

assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, child.getKey())).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
@@ -344,7 +344,7 @@ public class ChangeParentActionTest {

@Test
public void fail_if_profile_key_and_name_both_set() throws Exception {
QualityProfileDto child = createProfile();
RulesProfileDto child = createProfile();

assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, child.getKey())).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
@@ -364,7 +364,7 @@ public class ChangeParentActionTest {
public void fail_if_missing_permission() throws Exception {
userSessionRule.logIn();

QualityProfileDto child = createProfile();
RulesProfileDto child = createProfile();

TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -380,7 +380,7 @@ public class ChangeParentActionTest {
OrganizationDto organization2 = dbTester.organizations().insert();
userSessionRule.logIn().addPermission(ADMINISTER_QUALITY_PROFILES, organization2.getUuid());

QualityProfileDto child = createProfile();
RulesProfileDto child = createProfile();

TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -391,8 +391,8 @@ public class ChangeParentActionTest {
request.execute();
}

private QualityProfileDto createProfile() {
QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto()
private RulesProfileDto createProfile() {
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid())
.setLanguage(language.getKey());
dbClient.qualityProfileDao().insert(dbSession, profile);
@@ -410,7 +410,7 @@ public class ChangeParentActionTest {
return rule;
}

private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QualityProfileDto profile) {
private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, RulesProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
dbClient.activeRuleDao().insert(dbSession, activeRule);

+ 7
- 7
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionDatabaseTest.java View File

@@ -29,7 +29,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileChangeDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -67,7 +67,7 @@ public class ChangelogActionDatabaseTest {

@Test
public void find_changelog_by_profileKey() throws Exception {
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);

String response = wsTester.newRequest()
.setMethod("GET")
@@ -80,7 +80,7 @@ public class ChangelogActionDatabaseTest {

@Test
public void find_changelog_by_language_and_name() throws Exception {
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());

String response = wsTester.newRequest()
.setMethod("GET")
@@ -94,7 +94,7 @@ public class ChangelogActionDatabaseTest {

@Test
public void find_changelog_by_organization_and_language_and_name() throws Exception {
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);

String response = wsTester.newRequest()
.setMethod("GET")
@@ -112,7 +112,7 @@ public class ChangelogActionDatabaseTest {
OrganizationDto organization1 = dbTester.organizations().insert();
OrganizationDto organization2 = dbTester.organizations().insert();

QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);

TestRequest request = wsTester.newRequest()
.setMethod("GET")
@@ -127,7 +127,7 @@ public class ChangelogActionDatabaseTest {

@Test
public void changelog_empty() throws Exception {
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);

String response = wsTester.newRequest()
.setMethod("GET")
@@ -141,7 +141,7 @@ public class ChangelogActionDatabaseTest {

@Test
public void changelog_not_empty() throws Exception {
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
QProfileChangeDto change = QualityProfileTesting.newQProfileChangeDto()
.setKey(null)
.setCreatedAt(0)

+ 12
- 12
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionMediumTest.java View File

@@ -34,7 +34,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -99,7 +99,7 @@ public class CompareActionMediumTest {
* - rule 4 active with different parameters => "modified"
* - rule 5 active with different severity => "modified"
*/
QualityProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
RulesProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
createActiveRule(rule1, profile1);
createActiveRule(rule2, profile1);
createActiveRuleWithParam(rule4, profile1, "polop");
@@ -112,7 +112,7 @@ public class CompareActionMediumTest {
* - rule 3 active (only in this profile) => "inRight"
* - rule 4 active with different parameters => "modified"
*/
QualityProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
RulesProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
createActiveRule(rule1, profile2);
createActiveRule(rule3, profile2);
createActiveRuleWithParam(rule4, profile2, "palap");
@@ -129,9 +129,9 @@ public class CompareActionMediumTest {
public void compare_param_on_left() throws Exception {
RuleDefinitionDto rule1 = createRuleWithParam("xoo", "rule1");
createRepository("blah", "xoo", "Blah");
QualityProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
RulesProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
createActiveRuleWithParam(rule1, profile1, "polop");
QualityProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
RulesProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
createActiveRule(rule1, profile2);
session.commit();

@@ -145,9 +145,9 @@ public class CompareActionMediumTest {
public void compare_param_on_right() throws Exception {
RuleDefinitionDto rule1 = createRuleWithParam("xoo", "rule1");
createRepository("blah", "xoo", "Blah");
QualityProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
RulesProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
createActiveRule(rule1, profile1);
QualityProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
RulesProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
createActiveRuleWithParam(rule1, profile2, "polop");
session.commit();

@@ -189,8 +189,8 @@ public class CompareActionMediumTest {
.execute();
}

private QualityProfileDto createProfile(String lang, String name, String key) {
QualityProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), key);
private RulesProfileDto createProfile(String lang, String name, String key) {
RulesProfileDto profile = QProfileTesting.newQProfileDto("org-123", new QProfileName(lang, name), key);
db.qualityProfileDao().insert(session, profile);
session.commit();
return profile;
@@ -218,14 +218,14 @@ public class CompareActionMediumTest {
return rule;
}

private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QualityProfileDto profile) {
private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, RulesProfileDto profile) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(rule.getSeverityString());
db.activeRuleDao().insert(session, activeRule);
return activeRule;
}

private ActiveRuleDto createActiveRuleWithParam(RuleDefinitionDto rule, QualityProfileDto profile, String value) {
private ActiveRuleDto createActiveRuleWithParam(RuleDefinitionDto rule, RulesProfileDto profile, String value) {
ActiveRuleDto activeRule = createActiveRule(rule, profile);
RuleParamDto paramDto = db.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey()).get(0);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(paramDto).setValue(value);
@@ -233,7 +233,7 @@ public class CompareActionMediumTest {
return activeRule;
}

private ActiveRuleDto createActiveRuleWithSeverity(RuleDefinitionDto rule, QualityProfileDto profile, String severity) {
private ActiveRuleDto createActiveRuleWithSeverity(RuleDefinitionDto rule, RulesProfileDto profile, String severity) {
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
.setSeverity(severity);
db.activeRuleDao().insert(session, activeRule);

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CompareActionTest.java View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.resources.Languages;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileTesting;
import org.sonar.server.qualityprofile.QProfileComparison;
import org.sonar.server.tester.UserSessionRule;
@@ -51,8 +51,8 @@ public class CompareActionTest {

@Test
public void should_not_allow_to_compare_quality_profiles_from_different_organizations() {
QualityProfileDto left = QualityProfileTesting.newQualityProfileDto();
QualityProfileDto right = QualityProfileTesting.newQualityProfileDto();
RulesProfileDto left = QualityProfileTesting.newQualityProfileDto();
RulesProfileDto right = QualityProfileTesting.newQualityProfileDto();
dbTester.qualityProfiles().insertQualityProfiles(left, right);

TestRequest request = wsTester.newRequest().setMethod("POST")

+ 15
- 17
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java View File

@@ -34,7 +34,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.language.LanguageTesting;
@@ -96,7 +96,7 @@ public class CopyActionTest {
OrganizationDto organization = db.organizations().insert();
logInAsQProfileAdministrator(organization);

QualityProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
RulesProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
TestResponse response = tester.newRequest()
.setMethod("POST")
.setParam("fromKey", sourceProfile.getKey())
@@ -112,10 +112,9 @@ public class CopyActionTest {
" \"isDefault\": false," +
" \"isInherited\": false" +
"}");
QualityProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(organization, "target-name", sourceProfile.getLanguage(),
RulesProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(organization, "target-name", sourceProfile.getLanguage(),
db.getSession());
assertThat(loadedProfile.getKey()).isEqualTo(generatedUuid);
assertThat(loadedProfile.isDefault()).isFalse();
assertThat(loadedProfile.getParentKee()).isNull();

assertThat(backuper.backupedProfile.getKey()).isEqualTo(sourceProfile.getKey());
@@ -130,8 +129,8 @@ public class CopyActionTest {
public void copy_rules_on_existing_profile_in_default_organization() throws Exception {
OrganizationDto organization = db.organizations().insert();
logInAsQProfileAdministrator(organization);
QualityProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
QualityProfileDto targetProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
RulesProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
RulesProfileDto targetProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));

TestResponse response = tester.newRequest()
.setMethod("POST")
@@ -147,7 +146,7 @@ public class CopyActionTest {
" \"isDefault\": false," +
" \"isInherited\": false" +
"}");
QualityProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), targetProfile.getKey());
RulesProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByKey(db.getSession(), targetProfile.getKey());
assertThat(loadedProfile).isNotNull();

assertThat(backuper.backupedProfile.getKey()).isEqualTo(sourceProfile.getKey());
@@ -159,8 +158,8 @@ public class CopyActionTest {
OrganizationDto organization = db.organizations().insert();
logInAsQProfileAdministrator(organization);

QualityProfileDto parentProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
QualityProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE), p -> p.setParentKee(parentProfile.getKey()));
RulesProfileDto parentProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
RulesProfileDto sourceProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE), p -> p.setParentKee(parentProfile.getKey()));

TestResponse response = tester.newRequest()
.setMethod("POST")
@@ -177,10 +176,9 @@ public class CopyActionTest {
" \"isDefault\": false," +
" \"isInherited\": true" +
"}");
QualityProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(organization, "target-name", sourceProfile.getLanguage(),
RulesProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(organization, "target-name", sourceProfile.getLanguage(),
db.getSession());
assertThat(loadedProfile.getKey()).isEqualTo(generatedUuid);
assertThat(loadedProfile.isDefault()).isFalse();
assertThat(loadedProfile.getParentKee()).isEqualTo(parentProfile.getKey());

assertThat(backuper.backupedProfile.getKey()).isEqualTo(sourceProfile.getKey());
@@ -208,7 +206,7 @@ public class CopyActionTest {
@Test
public void throw_ForbiddenException_if_not_profile_administrator_of_organization() {
OrganizationDto organization = db.organizations().insert();
QualityProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
RulesProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
userSession.logIn().addPermission(OrganizationPermission.SCAN, organization);

expectedException.expect(ForbiddenException.class);
@@ -224,7 +222,7 @@ public class CopyActionTest {
@Test
public void throw_ForbiddenException_if_not_profile_administrator() {
OrganizationDto organization = db.organizations().insert();
QualityProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
RulesProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setLanguage(A_LANGUAGE));
userSession.logIn().addPermission(OrganizationPermission.SCAN, organization);

expectedException.expect(ForbiddenException.class);
@@ -271,11 +269,11 @@ public class CopyActionTest {

private static class TestBackuper implements QProfileBackuper {

private QualityProfileDto backupedProfile;
private QualityProfileDto restoredProfile;
private RulesProfileDto backupedProfile;
private RulesProfileDto restoredProfile;

@Override
public void backup(DbSession dbSession, QualityProfileDto profile, Writer backupWriter) {
public void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter) {
if (this.backupedProfile != null) {
throw new IllegalStateException("Already backup-ed/backed-up");
}
@@ -288,7 +286,7 @@ public class CopyActionTest {
}

@Override
public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QualityProfileDto profile) {
public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
if (this.restoredProfile != null) {
throw new IllegalStateException("Already restored");
}

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java View File

@@ -38,7 +38,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
@@ -115,7 +115,7 @@ public class CreateActionTest {

CreateWsResponse response = executeRequest("New Profile", XOO_LANGUAGE);

QualityProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "New Profile", XOO_LANGUAGE, dbSession);
RulesProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "New Profile", XOO_LANGUAGE, dbSession);
assertThat(dto.getKey()).isNotNull();
assertThat(dto.getLanguage()).isEqualTo(XOO_LANGUAGE);
assertThat(dto.getName()).isEqualTo("New Profile");
@@ -137,7 +137,7 @@ public class CreateActionTest {

executeRequest("New Profile", XOO_LANGUAGE, ImmutableMap.of("xoo_lint", "<xml/>"));

QualityProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "New Profile", XOO_LANGUAGE, dbSession);
RulesProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, "New Profile", XOO_LANGUAGE, dbSession);
assertThat(dto.getKey()).isNotNull();
assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, dto.getKey())).hasSize(1);
assertThat(ruleIndex.searchAll(new RuleQuery().setQProfileKey(dto.getKey()).setActivation(true))).hasSize(1);

+ 4
- 4
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRuleActionTest.java View File

@@ -34,7 +34,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
@@ -96,7 +96,7 @@ public class DeactivateRuleActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("rule_key", RuleTesting.newRuleDto().getKey().toString())
@@ -109,7 +109,7 @@ public class DeactivateRuleActionTest {
@Test
public void deactivate_rule_in_default_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(defaultOrganization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
@@ -128,7 +128,7 @@ public class DeactivateRuleActionTest {
@Test
public void deactivate_rule_in_specific_organization() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RuleKey ruleKey = RuleTesting.randomRuleKey();
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeactivateRulesActionTest.java View File

@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.QualityProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
@@ -108,7 +108,7 @@ public class DeactivateRulesActionTest {
@Test
public void should_fail_if_not_organization_quality_profile_administrator() {
userSession.logIn().addPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, defaultOrganization);
QualityProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
RulesProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
TestRequest request = wsActionTester.newRequest()
.setMethod("POST")
.setParam("profile_key", qualityProfile.getKey());

+ 0
- 0
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/DeleteActionTest.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save