]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6968 Bad error message when analyzer detects that no language plugins are installed
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 9 Dec 2015 15:20:47 +0000 (16:20 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 10 Dec 2015 16:59:17 +0000 (17:59 +0100)
sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java
sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java

index 8f6e0dd5e07ca4e810d3416454a4e31c8b93a95f..8b26d4bc1d020a486b89463c6382bb2e1f2c9e38 100644 (file)
@@ -19,8 +19,9 @@
  */
 package org.sonar.batch.repository;
 
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
+import org.sonar.api.utils.MessageException;
 
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
 import org.sonar.batch.util.BatchUtils;
 import org.apache.commons.io.IOUtils;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
@@ -34,8 +35,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
-import static com.google.common.base.Preconditions.checkState;
-
 public class DefaultQualityProfileLoader implements QualityProfileLoader {
   private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
 
@@ -48,7 +47,7 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader {
   @Override
   public List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) {
     String url = WS_URL + "?defaults=true";
-    if(profileName != null) {
+    if (profileName != null) {
       url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
     }
     return loadResource(url, fromCache);
@@ -80,8 +79,9 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader {
     }
 
     List<QualityProfile> profilesList = profiles.getProfilesList();
-    checkState(profilesList != null && !profilesList.isEmpty(),
-      "No quality profiles has been found this project, you probably don't have any language plugin suitable for this analysis.");
+    if (profilesList == null || profilesList.isEmpty()) {
+      throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed.");
+    }
     return profilesList;
   }
 
index e1f0c915cfb1f7b39990127352b2d460fb6b3a4e..b42d958422679952fe8d5d5fffd0937a7238a64b 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.batch.repository.language;
 
+import org.picocontainer.Startable;
+
 import org.sonar.api.resources.Languages;
 
 import javax.annotation.CheckForNull;
@@ -30,7 +32,7 @@ import java.util.Collection;
  * Languages repository using {@link Languages}
  * @since 4.4
  */
-public class DefaultLanguagesRepository implements LanguagesRepository {
+public class DefaultLanguagesRepository implements LanguagesRepository, Startable {
 
   private Languages languages;
 
@@ -38,6 +40,7 @@ public class DefaultLanguagesRepository implements LanguagesRepository {
     this.languages = languages;
   }
 
+  @Override
   public void start() {
     if (languages.all().length == 0) {
       throw new IllegalStateException("No language plugins are installed.");
@@ -67,4 +70,9 @@ public class DefaultLanguagesRepository implements LanguagesRepository {
     return result;
   }
 
+  @Override
+  public void stop() {
+    // nothing to do
+  }
+
 }
index 6aa753723b8c41cfb3c90dd3c15bf76bfb2ce027..97a36e5541d7070998e9a8233151905bec9cec33 100644 (file)
@@ -19,8 +19,9 @@
  */
 package org.sonar.batch.scan;
 
-import org.sonar.batch.analysis.DefaultAnalysisMode;
+import org.sonar.api.utils.MessageException;
 
+import org.sonar.batch.analysis.DefaultAnalysisMode;
 import com.google.common.base.Joiner;
 
 import java.util.ArrayList;
@@ -66,7 +67,7 @@ public class ProjectReactorValidator {
     validateBranch(validationMessages, branch);
 
     if (!validationMessages.isEmpty()) {
-      throw new IllegalStateException("Validation of project reactor failed:\n  o " + Joiner.on("\n  o ").join(validationMessages));
+      throw MessageException.of("Validation of project reactor failed:\n  o " + Joiner.on("\n  o ").join(validationMessages));
     }
   }
 
index ed7a35a4836fad8faed160d4f6a6ad32629b7313..a8979340a6104c59dd0bd5870a9fd4f354c81a02 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.batch.mediumtest.fs;
 
+import org.sonar.api.utils.MessageException;
+
 import com.google.common.collect.ImmutableMap;
 import org.apache.commons.io.FileUtils;
 import org.junit.After;
@@ -102,7 +104,7 @@ public class ProjectBuilderMediumTest {
   public void testProjectBuilderWithNewLine() throws IOException {
     File baseDir = prepareProject();
     
-    exception.expect(IllegalStateException.class);
+    exception.expect(MessageException.class);
     exception.expectMessage("is not a valid branch name");
     tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
index ec151f2987494776a450f7354cc159638da7b583..f81789b937f3c4fbe92997a8b7569ae3c79194ca 100644 (file)
@@ -87,7 +87,7 @@ public class TasksMediumTest {
 
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage(
-      "Unable to load component class org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask: org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask has unsatisfied dependency 'class org.sonar.api.issue.action.Actions'");
+      "Unable to load component class org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask");
 
     tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
index b3c2b79dcb304c3a18658a9c652545fe36edf72f..4caba83ec7075109ce1c60db73d07d392913696e 100644 (file)
@@ -19,8 +19,9 @@
  */
 package org.sonar.batch.repository;
 
-import org.sonarqube.ws.QualityProfiles;
+import org.sonar.api.utils.MessageException;
 
+import org.sonarqube.ws.QualityProfiles;
 import com.google.common.io.Resources;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 import org.sonar.batch.cache.WSLoaderResult;
@@ -77,7 +78,7 @@ public class DefaultQualityProfileLoaderTest {
     InputStream is = createEncodedQP();
     when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<InputStream>(is, false));
 
-    exception.expect(IllegalStateException.class);
+    exception.expect(MessageException.class);
     exception.expectMessage("No quality profiles");
 
     qpLoader.load("project", null, null);
index 761c608c8cd8822c1d8e42f08b482332c54fdea1..40b68bf21cb23fd27e338f3676a46e3e63897218 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.batch.scan;
 
 import static org.mockito.Mockito.when;
 
+import org.sonar.api.utils.MessageException;
+
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -67,7 +69,7 @@ public class ProjectReactorValidatorTest {
     validator.validate(createProjectReactor("project/key"));
     
     when(mode.isIssues()).thenReturn(false);
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("is not a valid project or module key");
     validator.validate(createProjectReactor("project/key"));
   }
@@ -106,7 +108,7 @@ public class ProjectReactorValidatorTest {
   public void fail_with_invalid_key() {
     ProjectReactor reactor = createProjectReactor("foo$bar");
 
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("\"foo$bar\" is not a valid project or module key");
     validator.validate(reactor);
   }
@@ -115,7 +117,7 @@ public class ProjectReactorValidatorTest {
   public void fail_with_backslash_in_key() {
     ProjectReactor reactor = createProjectReactor("foo\\bar");
 
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("\"foo\\bar\" is not a valid project or module key");
     validator.validate(reactor);
   }
@@ -133,7 +135,7 @@ public class ProjectReactorValidatorTest {
   @Test
   public void fail_with_invalid_branch() {
     ProjectReactor reactor = createProjectReactor("foo", "bran#ch");
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("\"bran#ch\" is not a valid branch name");
     validator.validate(reactor);
   }
@@ -141,7 +143,7 @@ public class ProjectReactorValidatorTest {
   @Test
   public void fail_with_colon_in_branch() {
     ProjectReactor reactor = createProjectReactor("foo", "bran:ch");
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("\"bran:ch\" is not a valid branch name");
     validator.validate(reactor);
   }
@@ -150,7 +152,7 @@ public class ProjectReactorValidatorTest {
   public void fail_with_only_digits() {
     ProjectReactor reactor = createProjectReactor("12345");
 
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("\"12345\" is not a valid project or module key");
     validator.validate(reactor);
   }
@@ -160,7 +162,7 @@ public class ProjectReactorValidatorTest {
     ProjectReactor reactor = createProjectReactor("foo");
     settings.setProperty("sonar.phase", "phase");
 
-    thrown.expect(IllegalStateException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("\"sonar.phase\" is deprecated");
     validator.validate(reactor);
   }
index 6789d45e61b4cb25eacc1eb6fd012f3d7e8c3716..ff4dceaef4c309a6ce89bb6016487870de5440d3 100644 (file)
@@ -59,7 +59,7 @@ public class ComponentContainer implements ContainerPopulator.Container {
       try {
         return super.getComponent(componentKeyOrType, annotation);
       } catch (Throwable t) {
-        throw new IllegalStateException("Unable to load component " + componentKeyOrType + ": " + t.getMessage(), t);
+        throw new IllegalStateException("Unable to load component " + componentKeyOrType, t);
       }
     }