diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-03-26 14:24:02 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2015-03-26 14:51:08 +0100 |
commit | 6eb670a7d276a1a0f046a5f1925f29e1727eec23 (patch) | |
tree | ce4d43c6a71963eafdb8f68bf4d057be6f36d0dc /server | |
parent | c361f824ba490fe69138205c56e2679800497405 (diff) | |
download | sonarqube-6eb670a7d276a1a0f046a5f1925f29e1727eec23.tar.gz sonarqube-6eb670a7d276a1a0f046a5f1925f29e1727eec23.zip |
SONAR-6325 Apply feedback from PR
Diffstat (limited to 'server')
7 files changed, 18 insertions, 22 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociation.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociation.java index 00bf3394e1b..8fa506e48e7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociation.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociation.java @@ -54,14 +54,14 @@ public class MoveProjectProfileAssociation extends BaseDataChange { Long id = row.getLong(1); String profileLanguage = extractLanguage(row.getString(2)); String profileName = row.getString(3); - Long projectId = row.getLong(4); + Long projectId = row.getNullableLong(4); String projectUuid = row.getString(5); if (profileKeysByLanguageThenName.contains(profileLanguage, profileName)) { String profileKey = profileKeysByLanguageThenName.get(profileLanguage, profileName); if (projectUuid == null) { - if (projectId == null || projectId == 0L) { + if (projectId == null) { setDefaultProfile.setBoolean(1, true).setString(2, profileKey).execute(); } else { LOGGER.warn(String.format("Profile with language '%s' and name '%s' is associated with unknown project '%d', ignored", profileLanguage, profileName, projectId)); @@ -98,7 +98,7 @@ public class MoveProjectProfileAssociation extends BaseDataChange { massUpdate.update("DELETE FROM properties WHERE id = ?"); final Upsert setDefaultProfile = context.prepareUpsert("UPDATE rules_profiles SET is_default = ? WHERE kee = ?"); - final Upsert associateProjectToProfile = context.prepareUpsert("INSERT INTO project_profiles (project_uuid, profile_key) VALUES (?, ?)"); + final Upsert associateProjectToProfile = context.prepareUpsert("INSERT INTO project_qprofiles (project_uuid, profile_key) VALUES (?, ?)"); try { massUpdate.execute(new ProjectProfileAssociationHandler(setDefaultProfile, associateProjectToProfile, profileKeysByLanguageThenName)); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java index 1eb5b2b5e5b..b34ff6244de 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java @@ -53,7 +53,6 @@ public class RegisterQualityProfiles implements ServerComponent { private static final Logger LOGGER = Loggers.get(RegisterQualityProfiles.class); private static final String DEFAULT_PROFILE_NAME = "Sonar way"; - private final PersistentSettings settings; private final List<ProfileDefinition> definitions; private final BuiltInProfiles builtInProfiles; private final DbClient dbClient; @@ -72,7 +71,6 @@ public class RegisterQualityProfiles implements ServerComponent { public RegisterQualityProfiles(PersistentSettings settings, BuiltInProfiles builtInProfiles, DbClient dbClient, QProfileFactory profileFactory, RuleActivator ruleActivator, List<ProfileDefinition> definitions, Languages languages) { - this.settings = settings; this.builtInProfiles = builtInProfiles; this.dbClient = dbClient; this.profileFactory = profileFactory; @@ -151,13 +149,9 @@ public class RegisterQualityProfiles implements ServerComponent { } private void setDefault(String language, List<RulesProfile> profileDefs, DbSession session) { - boolean upToDate = false; QualityProfileDto currentDefault = dbClient.qualityProfileDao().getDefaultProfile(language, session); - if (currentDefault != null) { - upToDate = true; - } - if (!upToDate) { + if (currentDefault == null) { String defaultProfileName = nameOfDefaultProfile(profileDefs); LOGGER.info("Set default " + language + " profile: " + defaultProfileName); QualityProfileDto newDefaultProfile = dbClient.qualityProfileDao().getByNameAndLanguage(defaultProfileName, language, session); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectAssociationActions.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectAssociationActions.java index 2760559bd38..8678d5a785c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectAssociationActions.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectAssociationActions.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile.ws; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import org.sonar.api.ServerComponent; @@ -27,6 +26,7 @@ import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.server.ws.*; import org.sonar.api.server.ws.WebService.NewAction; +import org.sonar.core.util.NonNullInputFunction; import org.sonar.server.component.ComponentService; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.qualityprofile.QProfile; @@ -36,6 +36,8 @@ import org.sonar.server.user.UserSession; import java.util.Arrays; +import static org.apache.commons.lang.StringUtils.isEmpty; + public class ProjectAssociationActions implements ServerComponent { private static final String PARAM_LANGUAGE = "language"; @@ -92,9 +94,9 @@ public class ProjectAssociationActions implements ServerComponent { .setDescription("A quality profile name. If this parameter is set, profileKey must not be set and language must be set to disambiguate"); action.createParam(PARAM_LANGUAGE) .setDescription("A quality profile language. If this parameter is set, profileKey must not be set and language must be set to disambiguate") - .setPossibleValues(Collections2.transform(Arrays.asList(languages.all()), new Function<Language, String>() { + .setPossibleValues(Collections2.transform(Arrays.asList(languages.all()), new NonNullInputFunction<Language, String>() { @Override - public String apply(Language input) { + public String doApply(Language input) { return input.getKey(); } })); @@ -121,8 +123,8 @@ public class ProjectAssociationActions implements ServerComponent { String projectUuid = request.param(PARAM_PROJECT_UUID); Preconditions.checkArgument( - (language != null && profileName != null) ^ profileKey != null, "Either profileKey or profileName + language must be set"); - Preconditions.checkArgument(projectKey != null ^ projectUuid != null, "Either projectKey or projectUuid must be set"); + (!isEmpty(language) && !isEmpty(profileName)) ^ !isEmpty(profileKey), "Either profileKey or profileName + language must be set"); + Preconditions.checkArgument(!isEmpty(projectKey) ^ !isEmpty(projectUuid), "Either projectKey or projectUuid must be set"); if(profileKey == null) { profileKey = getProfileKeyFromLanguageAndName(language, profileName); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java index 8857902e2bc..a571bd04123 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest.java @@ -36,7 +36,7 @@ public class MoveProjectProfileAssociationTest { @Before public void setUp() throws Exception { db.executeUpdateSql("truncate table projects"); - db.executeUpdateSql("truncate table project_profiles"); + db.executeUpdateSql("truncate table project_qprofiles"); db.executeUpdateSql("truncate table properties"); db.executeUpdateSql("truncate table rules_profiles"); @@ -52,14 +52,14 @@ public class MoveProjectProfileAssociationTest { public void migrate() throws Exception { db.prepareDbUnit(this.getClass(), "migrate.xml"); migration.execute(); - db.assertDbUnit(this.getClass(), "migrate-result.xml", "rules_profiles", "project_profiles"); + db.assertDbUnit(this.getClass(), "migrate-result.xml", "rules_profiles", "project_qprofiles"); } @Test public void not_migrate_already_migrated_data() throws Exception { db.prepareDbUnit(this.getClass(), "migrate-result.xml"); migration.execute(); - db.assertDbUnit(this.getClass(), "migrate-result.xml", "rules_profiles", "project_profiles"); + db.assertDbUnit(this.getClass(), "migrate-result.xml", "rules_profiles", "project_qprofiles"); } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/migrate-result.xml index c92078c64de..7c930e3c197 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/migrate-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/migrate-result.xml @@ -23,6 +23,6 @@ <properties id="1" prop_key="polop.palap" text_value="Untouched" resource_id="[null]" user_id="[null]"/> <!-- Project 'Struts' uses profile 'Java Two', moved to association table --> - <project_profiles id="1" project_uuid="ABCD" profile_key="java-two"/> + <project_qprofiles id="1" project_uuid="ABCD" profile_key="java-two"/> </dataset>
\ No newline at end of file diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/schema.sql index f0e98d0690e..004569aacfe 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/schema.sql +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/MoveProjectProfileAssociationTest/schema.sql @@ -41,7 +41,7 @@ CREATE TABLE "PROPERTIES" ( "USER_ID" INTEGER ); -CREATE TABLE "PROJECT_PROFILES" ( +CREATE TABLE "PROJECT_QPROFILES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROJECT_UUID" VARCHAR(50) NOT NULL, "PROFILE_KEY" VARCHAR(255) NOT NULL diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/906_create_project_profiles.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/906_create_project_profiles.rb index ec2766c2307..6dbec9f9a3c 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/906_create_project_profiles.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/906_create_project_profiles.rb @@ -24,12 +24,12 @@ class CreateProjectProfiles < ActiveRecord::Migration def self.up - create_table :project_profiles do |t| + create_table :project_qprofiles do |t| t.column :project_uuid, :string, :limit => 50, :null => false t.column :profile_key, :string, :limit => 255, :null => false end - add_index 'project_profiles', ['project_uuid', 'profile_key'], :unique => true, :name => 'uniq_project_profiles' + add_index 'project_qprofiles', ['project_uuid', 'profile_key'], :unique => true, :name => 'uniq_project_qprofiles' end end |