]> source.dussan.org Git - sonarqube.git/commitdiff
ONAR-4515 Display all allowed values for sonar.languages
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 2 Aug 2013 11:57:34 +0000 (13:57 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 2 Aug 2013 11:57:34 +0000 (13:57 +0200)
sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java
sonar-batch/src/main/java/org/sonar/batch/ProfileProvider.java
sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/ProfileProviderTest.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java

index 035d6209063f142ef14e37757e4d63d30c4e85d5..8e8e02aa5c13cb4160d07dd43c56e1869ac45946 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.batch;
 
 import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.sonar.api.config.Settings;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.resources.Project;
@@ -28,6 +30,9 @@ import org.sonar.api.utils.SonarException;
 import org.sonar.jpa.dao.ProfilesDao;
 
 public class DefaultProfileLoader implements ProfileLoader {
+
+  private static final Logger LOG = LoggerFactory.getLogger(DefaultProfileLoader.class);
+
   private ProfilesDao dao;
 
   public DefaultProfileLoader(ProfilesDao dao) {
@@ -43,7 +48,13 @@ public class DefaultProfileLoader implements ProfileLoader {
     if (StringUtils.isBlank(profileName)) {
       // This means that the current language is not supported by any installed plugin, otherwise at least a
       // "Default <Language Name>" profile would have been created by ActivateDefaultProfiles class.
-      throw new SonarException("You must install a plugin that supports the language '" + project.getLanguageKey() + "'");
+      String msg = "You must install a plugin that supports the language key '" + project.getLanguageKey() + "'.";
+      if (!LOG.isDebugEnabled()) {
+        msg += " Run analysis in verbose mode to see list of available language keys.";
+      } else {
+        msg += " See analysis log for a list of available language keys.";
+      }
+      throw new SonarException(msg);
     }
 
     RulesProfile profile = dao.getProfile(project.getLanguageKey(), profileName);
index cc34e85c29967600ee11b1b53ced8550e25385ee..93012a107d2a3938dc938fccc66b71690341e368 100644 (file)
@@ -24,6 +24,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.config.Settings;
 import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.Project;
 
 public class ProfileProvider extends ProviderAdapter {
@@ -32,7 +33,10 @@ public class ProfileProvider extends ProviderAdapter {
 
   private RulesProfile profile;
 
-  public RulesProfile provide(Project project, ProfileLoader profileLoader, Settings settings) {
+  /**
+   * @param languages This parameter is here to ensure Languages is started before this provider in order to display available languages.
+   */
+  public RulesProfile provide(Project project, ProfileLoader profileLoader, Settings settings, Languages languages) {
     if (profile == null) {
       profile = profileLoader.load(project, settings);
       LOG.info("Quality profile : {}", profile);
index 98004894633f1906624081d43e6cd3badf4e0fba..693d4d67f093c986ee9ea8f6a6a2b10ce7f31a2f 100644 (file)
@@ -92,7 +92,7 @@ public class DefaultProfileLoaderTest {
     Project cobolProject = newProject("cobol");
 
     thrown.expect(SonarException.class);
-    thrown.expectMessage("You must install a plugin that supports the language 'cobol'");
+    thrown.expectMessage("You must install a plugin that supports the language key 'cobol'");
     new DefaultProfileLoader(dao).load(cobolProject, new Settings());
   }
 
index f0bac78d121b37c77937fb55ab7f354a698892ef..12c7cb251b7202e40079f7a4554d7d5fba114278 100644 (file)
@@ -26,6 +26,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.config.Settings;
 import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.Languages;
 import org.sonar.api.resources.Project;
 
 import static org.hamcrest.Matchers.is;
@@ -56,8 +57,8 @@ public class ProfileProviderTest {
     RulesProfile profile = RulesProfile.create();
     when(loader.load(eq(javaProject), any(Settings.class))).thenReturn(profile);
 
-    assertThat(provider.provide(javaProject, loader, new Settings()), is(profile));
-    assertThat(provider.provide(javaProject, loader, new Settings()), is(profile));
+    assertThat(provider.provide(javaProject, loader, new Settings(), mock(Languages.class)), is(profile));
+    assertThat(provider.provide(javaProject, loader, new Settings(), mock(Languages.class)), is(profile));
     verify(loader).load(eq(javaProject), any(Settings.class));
     verifyNoMoreInteractions(loader);
   }
index 96dd37017510869356456b5383bbbedcf1328f13..47d667db4938434936b4a9c9990756c7d921f699 100644 (file)
@@ -21,6 +21,8 @@ package org.sonar.api.resources;
 
 import com.google.common.collect.Maps;
 import org.apache.commons.lang.ArrayUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchComponent;
 import org.sonar.api.ServerComponent;
 
@@ -37,14 +39,18 @@ import java.util.Set;
  */
 public class Languages implements BatchComponent, ServerComponent {
 
+  private static final Logger LOG = LoggerFactory.getLogger(Languages.class);
+
   private final Map<String, Language> map = Maps.newLinkedHashMap();
 
   /**
    * Creates a list of languages
    */
   public Languages(Language... languages) {
+    LOG.debug("Available languages:");
     for (Language language : languages) {
       map.put(language.getKey(), language);
+      LOG.debug("  * " + language.getName() + " => \"" + language.getKey() + "\"");
     }
   }
 
@@ -52,6 +58,7 @@ public class Languages implements BatchComponent, ServerComponent {
    * No languages are installed
    */
   public Languages() {
+    LOG.debug("No language available");
   }
 
   /**