]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Mar 2015 13:28:51 +0000 (15:28 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Mar 2015 13:29:01 +0000 (15:29 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationThreadLauncher.java
server/sonar-server/src/main/java/org/sonar/server/es/BulkIndexer.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
sonar-core/src/main/java/org/sonar/core/component/ScanPerspectives.java

index 18bf2a35633f6a2d20620db87dc3c962ad10b027..c91d3c88fef2fa942f2bf6c165851d7ed9f3a8ba 100644 (file)
@@ -23,7 +23,6 @@ package org.sonar.server.computation;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import org.picocontainer.Startable;
-import org.sonar.api.ServerComponent;
 import org.sonar.api.platform.Server;
 import org.sonar.api.platform.ServerStartHandler;
 
@@ -32,7 +31,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
-public class ComputationThreadLauncher implements Startable, ServerComponent, ServerStartHandler {
+public class ComputationThreadLauncher implements Startable, ServerStartHandler {
 
   public static final String THREAD_NAME_PREFIX = "computation-";
 
index c10ad36fe33269fa89a6f21600ede7032623c670..aaf7c746f405eb3f0213b34016fe69e10f6923c0 100644 (file)
@@ -218,28 +218,36 @@ public class BulkIndexer implements Startable {
     final BulkRequestBuilder req = this.bulkRequest;
     this.bulkRequest = client.prepareBulk().setRefresh(false);
     semaphore.acquireUninterruptibly();
-    req.execute(new ActionListener<BulkResponse>() {
-      @Override
-      public void onResponse(BulkResponse response) {
-        semaphore.release();
-        counter.addAndGet(response.getItems().length);
-
-        for (BulkItemResponse item : response.getItems()) {
-          if (item.isFailed()) {
-            StringBuilder sb = new StringBuilder();
-            String msg = sb
-              .append("index [").append(item.getIndex()).append("], type [").append(item.getType()).append("], id [").append(item.getId())
-              .append("], message [").append(item.getFailureMessage()).append("]").toString();
-            LOGGER.error(msg);
-          }
+    req.execute(new BulkResponseActionListener(req));
+  }
+
+  private class BulkResponseActionListener implements ActionListener<BulkResponse> {
+    private final BulkRequestBuilder req;
+
+    public BulkResponseActionListener(BulkRequestBuilder req) {
+      this.req = req;
+    }
+
+    @Override
+    public void onResponse(BulkResponse response) {
+      semaphore.release();
+      counter.addAndGet(response.getItems().length);
+
+      for (BulkItemResponse item : response.getItems()) {
+        if (item.isFailed()) {
+          StringBuilder sb = new StringBuilder();
+          String msg = sb
+            .append("index [").append(item.getIndex()).append("], type [").append(item.getType()).append("], id [").append(item.getId())
+            .append("], message [").append(item.getFailureMessage()).append("]").toString();
+          LOGGER.error(msg);
         }
       }
+    }
 
-      @Override
-      public void onFailure(Throwable e) {
-        semaphore.release();
-        LOGGER.error("Fail to execute bulk index request: " + req, e);
-      }
-    });
+    @Override
+    public void onFailure(Throwable e) {
+      semaphore.release();
+      LOGGER.error("Fail to execute bulk index request: " + req, e);
+    }
   }
 }
index f4ccf0a162d011e908258cc6c9dd4480356aa692..ccc8f8f2d52c18ecbd0472fb3a5ba15f3fa12db0 100644 (file)
@@ -208,7 +208,6 @@ public class QProfileFactory implements ServerComponent {
         if (db.qualityProfileDao().getByNameAndLanguage(newName, profile.getLanguage(), dbSession) != null) {
           throw new BadRequestException("Quality profile already exists: " + newName);
         }
-        String previousName = profile.getName();
         profile.setName(newName);
         db.qualityProfileDao().update(dbSession, profile);
         dbSession.commit();
index 757334f710028da9c0ce4e16965cea5d5ac75b58..030d81cd45fbf2875a4eadfb54cfbc87f1e98763 100644 (file)
@@ -269,31 +269,33 @@ public class RuleActivator implements ServerComponent {
   private ActiveRuleDto doUpdate(ActiveRuleChange change, RuleActivatorContext context, DbSession dbSession) {
     ActiveRuleDao dao = db.activeRuleDao();
     ActiveRuleDto activeRule = context.activeRule();
-    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);
-
-    for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
-      ActiveRuleParamDto activeRuleParamDto = context.activeRuleParamsAsMap().get(param.getKey());
-      if (activeRuleParamDto == null) {
-        // did not exist
-        if (param.getValue() != null) {
-          activeRuleParamDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey()));
-          activeRuleParamDto.setValue(param.getValue());
-          dao.addParam(dbSession, activeRule, activeRuleParamDto);
-        }
-      } else {
-        if (param.getValue() != null) {
-          activeRuleParamDto.setValue(param.getValue());
-          dao.updateParam(dbSession, activeRule, activeRuleParamDto);
+    if (activeRule != null) {
+      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);
+
+      for (Map.Entry<String, String> param : change.getParameters().entrySet()) {
+        ActiveRuleParamDto activeRuleParamDto = context.activeRuleParamsAsMap().get(param.getKey());
+        if (activeRuleParamDto == null) {
+          // did not exist
+          if (param.getValue() != null) {
+            activeRuleParamDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey()));
+            activeRuleParamDto.setValue(param.getValue());
+            dao.addParam(dbSession, activeRule, activeRuleParamDto);
+          }
         } else {
-          dao.deleteParam(dbSession, activeRule, activeRuleParamDto);
+          if (param.getValue() != null) {
+            activeRuleParamDto.setValue(param.getValue());
+            dao.updateParam(dbSession, activeRule, activeRuleParamDto);
+          } else {
+            dao.deleteParam(dbSession, activeRule, activeRuleParamDto);
+          }
         }
       }
     }
index 778a9c0d7e799eff351f9f1d67cd4cb4af4d6098..09cf4c72b5414c2271d66aef1a7af394c8f3a5b7 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.core.component;
 
 import com.google.common.collect.Maps;
-import org.sonar.api.BatchComponent;
 import org.sonar.api.batch.SonarIndex;
 import org.sonar.api.batch.fs.InputDir;
 import org.sonar.api.batch.fs.InputFile;
@@ -33,10 +32,9 @@ import org.sonar.api.resources.File;
 import org.sonar.api.resources.Resource;
 
 import javax.annotation.CheckForNull;
-
 import java.util.Map;
 
-public class ScanPerspectives implements ResourcePerspectives, BatchComponent {
+public class ScanPerspectives implements ResourcePerspectives {
 
   private final Map<Class<?>, PerspectiveBuilder<?>> builders = Maps.newHashMap();
   private final SonarIndex resourceIndex;