From 074f5c655822a466819c899ed9c90aef4ba1d2b4 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 1 Jul 2014 18:55:58 +0200 Subject: [PATCH] Fix some quality flaws --- .../server/db/migrations/MassUpdater.java | 4 +--- .../server/qualityprofile/RuleActivator.java | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java index bff09fd3f9d..621d92fc15b 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java +++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java @@ -82,10 +82,9 @@ public class MassUpdater { public void execute(InputLoader inputLoader, InputConverter converter, @Nullable PeriodicUpdater periodicUpdater) { long count = 0; - Connection readConnection = null; + Connection readConnection = null, writeConnection = null; Statement stmt = null; ResultSet rs = null; - Connection writeConnection = null; PreparedStatement writeStatement = null; try { readConnection = db.getDataSource().getConnection(); @@ -136,7 +135,6 @@ public class MassUpdater { DbUtils.closeQuietly(writeStatement); DbUtils.closeQuietly(writeConnection); DbUtils.closeQuietly(readConnection, stmt, rs); - LOGGER.info("{} rows have been updated", count); } } diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index 6c53e8b856e..394001c452a 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -95,7 +95,8 @@ public class RuleActivator implements ServerComponent { ActiveRuleChange change; boolean stopPropagation = false; - if (context.activeRule() == null) { + ActiveRuleDto activeRule = context.activeRule(); + if (activeRule == null) { if (activation.isReset()) { // ignore reset when rule is not activated return changes; @@ -108,12 +109,12 @@ public class RuleActivator implements ServerComponent { } } else { // already activated - if (activation.isCascade() && context.activeRule().doesOverride()) { + if (activation.isCascade() && activeRule.doesOverride()) { // propagating to descendants, but child profile already overrides rule -> stop propagation return changes; } change = ActiveRuleChange.createFor(ActiveRuleChange.Type.UPDATED, context.activeRuleKey()); - if (activation.isCascade() && context.activeRule().getInheritance() == null) { + if (activation.isCascade() && activeRule.getInheritance() == null) { // activate on child, then on parent -> mark child as overriding parent change.setInheritance(ActiveRule.Inheritance.OVERRIDES); change.setSeverity(context.currentSeverity()); @@ -265,9 +266,13 @@ public class RuleActivator implements ServerComponent { ActiveRuleDto activeRule; ActiveRuleDao dao = db.activeRuleDao(); activeRule = context.activeRule(); - activeRule.setSeverity(change.getSeverity()); - if (change.getInheritance() != null) { - activeRule.setInheritance(change.getInheritance().name()); + String severity = change.getSeverity(); + if (severity != null) { + activeRule.setSeverity(severity); + } + ActiveRule.Inheritance inheritance = change.getInheritance(); + if (inheritance != null) { + activeRule.setInheritance(inheritance.name()); } dao.update(dbSession, activeRule); @@ -456,7 +461,7 @@ public class RuleActivator implements ServerComponent { // unset if parent is defined, else nothing to do removeParent(dbSession, profile); - } else if (profile.getParentKee() == null || !profile.getParentKee().equals(parentKey)) { + } else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) { QualityProfileDto parentProfile = db.qualityProfileDao().getNonNullByKey(dbSession, parentKey); if (isDescendant(dbSession, profile, parentProfile)) { throw new BadRequestException(String.format("Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey)); @@ -502,8 +507,9 @@ public class RuleActivator implements ServerComponent { if (childProfile.getName().equals(currentParent.getName())) { return true; } - if (currentParent.getParentKee() != null) { - currentParent = db.qualityProfileDao().getByKey(dbSession, currentParent.getParentKee()); + String parentKey = currentParent.getParentKee(); + if (parentKey != null) { + currentParent = db.qualityProfileDao().getByKey(dbSession, parentKey); } else { currentParent = null; } -- 2.39.5