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() +
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);
}
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 {
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;
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");
}
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);
}
/**
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) {
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;
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);
}
}