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;
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) {
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);
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) {
+ /**
+ * @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);
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());
}
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;
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);
}
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;
*/
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() + "\"");
}
}
* No languages are installed
*/
public Languages() {
+ LOG.debug("No language available");
}
/**