]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4515 Fix IoC dependency on Languages
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 1 Aug 2013 07:16:06 +0000 (09:16 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 1 Aug 2013 07:16:06 +0000 (09:16 +0200)
sonar-batch/src/main/java/org/sonar/batch/DefaultProfileLoader.java
sonar-batch/src/main/java/org/sonar/batch/ProfileLoader.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

index 2e6e064c4be5641828d4a018308b2c228c2b7065..6554b60c0299d641f537548b469364e45482f89f 100644 (file)
@@ -31,14 +31,12 @@ import org.sonar.jpa.dao.ProfilesDao;
 
 public class DefaultProfileLoader implements ProfileLoader {
   private ProfilesDao dao;
-  private Languages languages;
 
-  public DefaultProfileLoader(ProfilesDao dao, Languages languages) {
+  public DefaultProfileLoader(ProfilesDao dao) {
     this.dao = dao;
-    this.languages = languages;
   }
 
-  public RulesProfile load(Project project, Settings settings) {
+  public RulesProfile load(Project project, Settings settings, Languages languages) {
     if (!languages.allKey().contains(project.getLanguageKey())) {
       String languageList = Joiner.on(", ").join(languages.allKey());
       throw new SonarException("You must install a plugin that supports the language '" + project.getLanguageKey() +
index c844cef918f2f8408578b6f5726101f24bd4985b..10479d7d21c09fffd822afb668cba15ba1d2e0cb 100644 (file)
@@ -21,13 +21,15 @@ package org.sonar.batch;
 
 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 interface ProfileLoader {
 
   /**
    * Loads quality profile for specified project.
+   * @param languages remove this parameter when Languages is no more in scope ModuleScanContainer
    */
-  RulesProfile load(Project project, Settings settings);
+  RulesProfile load(Project project, Settings settings, Languages languages);
 
 }
index cc34e85c29967600ee11b1b53ced8550e25385ee..e93a61b100c97c92af918d582babb1bd5b896074 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,9 +33,9 @@ public class ProfileProvider extends ProviderAdapter {
 
   private RulesProfile profile;
 
-  public RulesProfile provide(Project project, ProfileLoader profileLoader, Settings settings) {
+  public RulesProfile provide(Project project, ProfileLoader profileLoader, Settings settings, Languages languages) {
     if (profile == null) {
-      profile = profileLoader.load(project, settings);
+      profile = profileLoader.load(project, settings, languages);
       LOG.info("Quality profile : {}", profile);
     }
     return profile;
index 80e8bb1aff3bfdf52b0ca5e978d70720bec11024..836effb1b038c2642c1a3dbef8e66017c1c0b8e5 100644 (file)
@@ -69,7 +69,7 @@ public class DefaultProfileLoaderTest {
     settings.setProperty("sonar.profile.java", "legacy profile");
     when(dao.getProfile(Java.KEY, "legacy profile")).thenReturn(RulesProfile.create("legacy profile", "java"));
 
-    RulesProfile profile = new DefaultProfileLoader(dao, languages).load(javaProject, settings);
+    RulesProfile profile = new DefaultProfileLoader(dao).load(javaProject, settings, languages);
 
     assertThat(profile.getName()).isEqualTo("legacy profile");
   }
@@ -81,7 +81,7 @@ public class DefaultProfileLoaderTest {
 
     thrown.expect(SonarException.class);
     thrown.expectMessage("Quality profile not found : unknown, language java");
-    new DefaultProfileLoader(dao, languages).load(javaProject, settings);
+    new DefaultProfileLoader(dao).load(javaProject, settings, languages);
   }
 
   /**
@@ -93,7 +93,7 @@ public class DefaultProfileLoaderTest {
 
     thrown.expect(SonarException.class);
     thrown.expectMessage("You must install a plugin that supports the language 'cobol'. Supported language keys are: java, js");
-    new DefaultProfileLoader(dao, languages).load(cobolProject, new Settings());
+    new DefaultProfileLoader(dao).load(cobolProject, new Settings(), languages);
   }
 
   private Project newProject(String language) {
index 0a3f17cc0c89c19fd34e23b211445cab5522dc0d..7cc8ecddf8041e0e85b8cb316e57614051d5daa1 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.batch;
 import org.junit.Test;
 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;
@@ -40,11 +41,12 @@ public class ProfileProviderTest {
     ProfileLoader loader = mock(ProfileLoader.class);
     Project project = new Project("project");
     RulesProfile profile = RulesProfile.create();
-    when(loader.load(eq(project), any(Settings.class))).thenReturn(profile);
+    Languages languages = mock(Languages.class);
+    when(loader.load(eq(project), any(Settings.class), eq(languages))).thenReturn(profile);
 
-    assertThat(provider.provide(project, loader, new Settings()), is(profile));
-    assertThat(provider.provide(project, loader, new Settings()), is(profile));
-    verify(loader).load(eq(project), any(Settings.class));
+    assertThat(provider.provide(project, loader, new Settings(), languages), is(profile));
+    assertThat(provider.provide(project, loader, new Settings(), languages), is(profile));
+    verify(loader).load(eq(project), any(Settings.class), eq(languages));
     verifyNoMoreInteractions(loader);
   }
 }