]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 21 Oct 2013 15:07:40 +0000 (17:07 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 21 Oct 2013 15:07:50 +0000 (17:07 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/SquidUtils.java
sonar-server/src/main/java/org/sonar/server/db/migrations/violation/ViolationConverters.java
sonar-server/src/test/java/org/sonar/server/db/migrations/violation/ViolationConvertersTest.java

index ce70ee6d636aa3358777a2e5a0815686495df8f0..e58052abd99bf1d1aee520de2a76465fb40fc24e 100644 (file)
@@ -150,18 +150,18 @@ public class FileIndex implements BatchComponent {
     if (path == null) {
       LoggerFactory.getLogger(getClass()).warn(String.format("File '%s' is not in basedir '%s'", file.getAbsolutePath(), fileSystem.baseDir()));
     } else {
-        InputFile input = newInputFile(fileSystem, sourceDir, type, file, path);
-        if (input != null && accept(input)) {
-          cache.put(fileSystem.moduleKey(), input);
-          status.markAsIndexed(path);
-        }
+      InputFile input = newInputFile(fileSystem, sourceDir, type, file, path);
+      if (input != null && accept(input)) {
+        cache.put(fileSystem.moduleKey(), input);
+        status.markAsIndexed(path);
       }
+    }
   }
 
   @CheckForNull
   private InputFile newInputFile(ModuleFileSystem fileSystem, File sourceDir, String type, File file, String path) {
     String lang = languageRecognizer.of(file);
-    if (lang==null) {
+    if (lang == null) {
       return null;
     }
 
index b9136c0fb690ad87da34c4f60c2e058f847ec82b..dec485a41a70b9b57014bb2e7126b7554193062f 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.api.batch;
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.resources.Java;
 import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.JavaPackage;
 
index 3115472e1b58ba7560b236b0280bb32ea4c668dd..622708d239fe9cdc2b9871198564de0765676cd7 100644 (file)
@@ -26,7 +26,10 @@ import org.sonar.core.persistence.Database;
 import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 
 class ViolationConverters {
 
@@ -38,7 +41,7 @@ class ViolationConverters {
     this.settings = settings;
   }
 
-  void execute(Referentials referentials, Database db) throws ExecutionException, InterruptedException {
+  void execute(Referentials referentials, Database db) {
     Progress progress = new Progress(referentials.totalViolations());
 
     List<Callable<Object>> converters = Lists.newArrayList();
@@ -49,7 +52,7 @@ class ViolationConverters {
     doExecute(progress, converters);
   }
 
-  void doExecute(TimerTask progress, List<Callable<Object>> converters) throws InterruptedException, ExecutionException {
+  void doExecute(TimerTask progress, List<Callable<Object>> converters) {
     Timer timer = new Timer(Progress.THREAD_NAME);
     timer.schedule(progress, Progress.DELAY_MS, Progress.DELAY_MS);
     try {
@@ -59,6 +62,8 @@ class ViolationConverters {
       for (Future result : results) {
         result.get();
       }
+    } catch (Exception e) {
+      throw new IllegalStateException("Fail to start migration threads", e);
     } finally {
       progress.cancel();
       timer.cancel();
index 9b144fe784676cda6a58674971ce5d5375e5a735..6e37ed949e0fcef14cee473f833e1b1250ff95d7 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.db.migrations.violation;
 
 import com.google.common.collect.Lists;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.junit.Test;
 import org.sonar.api.config.Settings;
 
@@ -68,8 +69,8 @@ public class ViolationConvertersTest {
     try {
       new ViolationConverters(new Settings()).doExecute(new FakeTimerTask(), callables);
       fail();
-    } catch (ExecutionException e) {
-      assertThat(e.getCause().getMessage()).isEqualTo("Need to cry");
+    } catch (Exception e) {
+      assertThat(ExceptionUtils.getRootCause(e).getMessage()).isEqualTo("Need to cry");
     }
 
   }