]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 1 Jul 2014 09:12:34 +0000 (11:12 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 1 Jul 2014 10:10:47 +0000 (12:10 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureValueCoder.java
sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandExecutorTest.java
sonar-server/src/main/java/org/sonar/server/activity/ActivityService.java
sonar-server/src/main/java/org/sonar/server/activity/index/ActivityDoc.java
sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java
sonar-server/src/main/java/org/sonar/server/ws/ListingWs.java

index ccda40c429bb1edb35f8e81627027abb034bbadc..d3e0677e86c7af2c09bc443d8446cedcf9561500 100644 (file)
@@ -26,6 +26,8 @@ import org.sonar.api.measures.Measure;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.measures.MetricFinder;
 import org.sonar.api.measures.PersistenceMode;
+import org.sonar.api.technicaldebt.batch.Characteristic;
+import org.sonar.api.technicaldebt.batch.Requirement;
 import org.sonar.api.technicaldebt.batch.TechnicalDebtModel;
 
 class MeasureValueCoder implements ValueCoder {
@@ -54,10 +56,14 @@ class MeasureValueCoder implements ValueCoder {
     value.put(m.getVariation4());
     value.put(m.getVariation5());
     value.putString(m.getUrl());
-    value.put(m.getCharacteristic() != null ? m.getCharacteristic().id() : null);
-    value.put(m.getRequirement() != null ? m.getRequirement().id() : null);
-    value.put(m.getPersonId() != null ? m.getPersonId().intValue() : null);
-    value.putString(m.getPersistenceMode() != null ? m.getPersistenceMode().name() : null);
+    Characteristic characteristic = m.getCharacteristic();
+    value.put(characteristic != null ? characteristic.id() : null);
+    Requirement requirement = m.getRequirement();
+    value.put(requirement != null ? requirement.id() : null);
+    Integer personId = m.getPersonId();
+    value.put(personId != null ? personId.intValue() : null);
+    PersistenceMode persistenceMode = m.getPersistenceMode();
+    value.putString(persistenceMode != null ? persistenceMode.name() : null);
   }
 
   public Object get(Value value, Class clazz, CoderContext context) {
index eac3e65d45de34c78a1c1088fcfc067c908421ab..2e4ae57f118a9d5841f021baced0f548bd12c1b6 100644 (file)
@@ -73,10 +73,6 @@ public final class ActivityDto extends Dto<String> {
     return this;
   }
 
-  public ActivityDto setExecutionTime(Integer executionTime) {
-    return this;
-  }
-
   public String getData() {
     return data;
   }
index f06adc75dd8b3f598b3d5fca7c024cb74d950cf9..b8d4de678654d69ed84def1560a03cc7316b8022 100644 (file)
@@ -34,7 +34,6 @@ import java.io.IOException;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeFalse;
 
 public class CommandExecutorTest {
 
@@ -57,30 +56,30 @@ public class CommandExecutorTest {
   @Test
   public void should_consume_StdOut_and_StdErr() throws Exception {
     // too many false-positives on MS windows
-    assumeFalse(SystemUtils.IS_OS_WINDOWS);
-
-    final StringBuilder stdOutBuilder = new StringBuilder();
-    StreamConsumer stdOutConsumer = new StreamConsumer() {
-      public void consumeLine(String line) {
-        stdOutBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
-      }
-    };
-    final StringBuilder stdErrBuilder = new StringBuilder();
-    StreamConsumer stdErrConsumer = new StreamConsumer() {
-      public void consumeLine(String line) {
-        stdErrBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
-      }
-    };
-    Command command = Command.create(getScript("output")).setDirectory(workDir);
-    int exitCode = CommandExecutor.create().execute(command, stdOutConsumer, stdErrConsumer, 1000L);
-    assertThat(exitCode).isEqualTo(0);
-
-    String stdOut = stdOutBuilder.toString();
-    String stdErr = stdErrBuilder.toString();
-    assertThat(stdOut).contains("stdOut: first line");
-    assertThat(stdOut).contains("stdOut: second line");
-    assertThat(stdErr).contains("stdErr: first line");
-    assertThat(stdErr).contains("stdErr: second line");
+    if (!SystemUtils.IS_OS_WINDOWS) {
+      final StringBuilder stdOutBuilder = new StringBuilder();
+      StreamConsumer stdOutConsumer = new StreamConsumer() {
+        public void consumeLine(String line) {
+          stdOutBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
+        }
+      };
+      final StringBuilder stdErrBuilder = new StringBuilder();
+      StreamConsumer stdErrConsumer = new StreamConsumer() {
+        public void consumeLine(String line) {
+          stdErrBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
+        }
+      };
+      Command command = Command.create(getScript("output")).setDirectory(workDir);
+      int exitCode = CommandExecutor.create().execute(command, stdOutConsumer, stdErrConsumer, 1000L);
+      assertThat(exitCode).isEqualTo(0);
+
+      String stdOut = stdOutBuilder.toString();
+      String stdErr = stdErrBuilder.toString();
+      assertThat(stdOut).contains("stdOut: first line");
+      assertThat(stdOut).contains("stdOut: second line");
+      assertThat(stdErr).contains("stdErr: first line");
+      assertThat(stdErr).contains("stdErr: second line");
+    }
   }
 
   @Test
index faae800057e09a044b4e01a33a8f8aa3448673a4..b5dd40037d5a957d3a8fe014be9b6ba3d3f5f7a1 100644 (file)
@@ -39,7 +39,6 @@ import java.util.List;
  * Log service is used to log Activity classes which represents an event to DB and Index.
  *
  * @see org.sonar.core.activity.ActivityLog
- * @since 4.4
  */
 public class ActivityService {
 
@@ -62,13 +61,7 @@ public class ActivityService {
   }
 
   public void write(DbSession session, Activity.Type type, String message) {
-    this.write(session, type, message, null);
-  }
-
-  public void write(DbSession session, Activity.Type type, String message, Integer time) {
-    this.save(session, ActivityDto.createFor(message)
-      .setType(type)
-      .setExecutionTime(time));
+    save(session, ActivityDto.createFor(message).setType(type));
   }
 
   public <L extends ActivityLog> void write(DbSession session, Activity.Type type, List<L> logs) {
@@ -88,7 +81,6 @@ public class ActivityService {
 
   public Result<Activity> search(ActivityQuery query, QueryOptions options) {
     ActivityIndex index = indexClient.get(ActivityIndex.class);
-    return
-      new Result<Activity>(index, index.search(query, options));
+    return new Result<Activity>(index, index.search(query, options));
   }
 }
index a2032f4569c37c15b115af2e8707aaa028e8cd4b..a438fa3a61d9d0927175cc399f6dfbd347761682 100644 (file)
@@ -48,7 +48,7 @@ public class ActivityDoc extends BaseDoc implements Activity {
 
   @Override
   public Type type() {
-    return Type.valueOf((String) this.getNullableField(ActivityNormalizer.LogFields.TYPE.field()));
+    return Type.valueOf((String) getField(ActivityNormalizer.LogFields.TYPE.field()));
   }
 
   @Override
index e61ae848b98a8f8af0a7337d337079cdb0627074..92f94cb12301a9142d9791560135e6aee1303705 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.server.search.IndexField;
 import org.sonar.server.search.QueryOptions;
 import org.sonar.server.search.Result;
 
+import javax.annotation.Nullable;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -97,11 +98,11 @@ public class ActivityIndex extends BaseIndex<Activity, ActivityDto, String> {
   }
 
   public SearchResponse search(ActivityQuery query, QueryOptions options) {
-    return this.search(query, options, null);
+    return search(query, options, null);
   }
 
   public SearchResponse search(ActivityQuery query, QueryOptions options,
-                               FilterBuilder domainFilter) {
+                               @Nullable FilterBuilder domainFilter) {
 
     // Prepare query
     SearchRequestBuilder esSearch = getClient()
index 4f85de36a970c847be59e29c70f1b055e9603d80..5329674fb507e5c0ad6e2ac7426c9126a0ac0c9f 100644 (file)
@@ -79,7 +79,11 @@ public class ListingWs implements WebService {
       .setHandler(new RequestHandler() {
         @Override
         public void handle(Request request, Response response) throws Exception {
-          Controller controller = context.controller(request.mandatoryParam("controller"));
+          String controllerKey = request.mandatoryParam("controller");
+          Controller controller = context.controller(controllerKey);
+          if (controller == null) {
+            throw new IllegalArgumentException("Controller does not exist: " + controllerKey);
+          }
           String actionKey = request.mandatoryParam("action");
           Action action = controller.action(actionKey);
           if (action == null) {