diff options
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java | 8 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java | 26 |
2 files changed, 28 insertions, 6 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java index b3779e84b70..35a10a679f7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java @@ -22,6 +22,7 @@ package org.sonar.batch; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; import org.sonar.api.rules.ActiveRule; +import org.sonar.api.utils.SonarException; import org.sonar.jpa.dao.ProfilesDao; public class DefaultProfileLoader implements ProfileLoader { @@ -40,13 +41,16 @@ public class DefaultProfileLoader implements ProfileLoader { Project root = project.getRoot(); profile = dao.getActiveProfile(root.getLanguageKey(), root.getKey()); if (profile == null) { - throw new RuntimeException("Quality profile not found for " + root.getKey() + ", language " + root.getLanguageKey()); + // 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 intall a Sonar plugin that supports language '" + root.getLanguageKey() + + "' in order to analyse the following project: " + root.getKey()); } } else { profile = dao.getProfile(project.getLanguageKey(), profileName); if (profile == null) { - throw new RuntimeException("Quality profile not found : " + profileName + ", language " + project.getLanguageKey()); + throw new SonarException("Quality profile not found : " + profileName + ", language " + project.getLanguageKey()); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java index 5ddfa9f151b..735c21c7130 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/DefaultProfileLoaderTest.java @@ -28,21 +28,24 @@ import static org.mockito.Mockito.when; import java.util.Collections; import java.util.HashMap; -import org.sonar.batch.DefaultProfileLoader; - import org.apache.commons.configuration.MapConfiguration; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.sonar.api.profiles.Alert; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; import org.sonar.api.rules.ActiveRule; -import org.sonar.batch.ProfileLoader; +import org.sonar.api.utils.SonarException; import org.sonar.jpa.dao.ProfilesDao; public class DefaultProfileLoaderTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + private ProfilesDao dao; private ProfileLoader loader; @@ -88,7 +91,7 @@ public class DefaultProfileLoaderTest { verify(dao, never()).getActiveProfile(Java.KEY, "project"); } - @Test(expected = RuntimeException.class) + @Test public void shouldFailIfProfileIsNotFound() { Project project = new Project("project").setLanguageKey(Java.KEY); @@ -98,6 +101,21 @@ public class DefaultProfileLoaderTest { when(dao.getProfile(Java.KEY, "profile1")).thenReturn(null); + thrown.expect(SonarException.class); + thrown.expectMessage("Quality profile not found : unknown, language java"); + loader.load(project); + } + + /** + * SONAR-3125 + */ + @Test + public void shouldGiveExplicitMessageIfNoProfileFound() { + Project project = new Project("foo:project").setLanguageKey("unknown-language"); + when(dao.getProfile(Java.KEY, "profile1")).thenReturn(null); + + thrown.expect(SonarException.class); + thrown.expectMessage("You must intall a Sonar plugin that supports language 'unknown-language' in order to analyse the following project: foo:project"); loader.load(project); } |