diff options
author | Godin <mandrikov@gmail.com> | 2010-11-23 21:48:08 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-23 21:48:08 +0000 |
commit | b603701f4475d1b0b2728dedbe61cb8133eac1cf (patch) | |
tree | 0808df909ddefbe43b4daccd4935619301095ceb | |
parent | 894ce598de301b77a3785a5cf0c58190f9d2d3e1 (diff) | |
download | sonarqube-b603701f4475d1b0b2728dedbe61cb8133eac1cf.tar.gz sonarqube-b603701f4475d1b0b2728dedbe61cb8133eac1cf.zip |
SONAR-1556: When a language is specified with the 'sonar.language' property but not supported, a clear message must be displayed
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java | 26 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java | 13 |
2 files changed, 27 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java index d47ed8d6939..cee58be0c82 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java @@ -19,6 +19,8 @@ */ package org.sonar.batch; +import java.util.List; + import org.picocontainer.Characteristics; import org.picocontainer.MutablePicoContainer; import org.sonar.api.batch.BatchExtensionDictionnary; @@ -30,16 +32,21 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metrics; import org.sonar.api.resources.DefaultProjectFileSystem; +import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.resources.Project; import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.utils.IocContainer; +import org.sonar.api.utils.SonarException; import org.sonar.batch.indexer.DefaultSonarIndex; import org.sonar.core.qualitymodel.DefaultModelFinder; import org.sonar.core.rule.DefaultRuleFinder; -import org.sonar.jpa.dao.*; - -import java.util.List; +import org.sonar.jpa.dao.AsyncMeasuresDao; +import org.sonar.jpa.dao.AsyncMeasuresService; +import org.sonar.jpa.dao.DaoFacade; +import org.sonar.jpa.dao.MeasuresDao; +import org.sonar.jpa.dao.ProfilesDao; +import org.sonar.jpa.dao.RulesDao; public class ProjectBatch { @@ -75,7 +82,7 @@ public class ProjectBatch { batchContainer.as(Characteristics.CACHE).addComponent(index.getBucket(project).getSnapshot()); batchContainer.as(Characteristics.CACHE).addComponent(project.getConfiguration()); - //need to be registered after the Configuration + // need to be registered after the Configuration batchContainer.getComponent(BatchPluginRepository.class).registerPlugins(batchContainer); batchContainer.as(Characteristics.CACHE).addComponent(DaoFacade.class); @@ -107,11 +114,16 @@ public class ProjectBatch { } private void prepareProject(Project project, DefaultSonarIndex index) { - project.setLanguage(getComponent(Languages.class).get(project.getLanguageKey())); - index.selectProject(project, getComponent(ResourceFilters.class), getComponent(ViolationFilters.class), getComponent(MeasuresDao.class), getComponent(ViolationsDao.class)); + Language language = getComponent(Languages.class).get(project.getLanguageKey()); + if (language == null) { + throw new SonarException("Language with key '" + project.getLanguageKey() + "' not found"); + } + project.setLanguage(language); + index.selectProject(project, getComponent(ResourceFilters.class), getComponent(ViolationFilters.class), + getComponent(MeasuresDao.class), getComponent(ViolationsDao.class)); List<FileFilter> fileFilters = batchContainer.getComponents(FileFilter.class); - ((DefaultProjectFileSystem)project.getFileSystem()).addFileFilters(fileFilters); + ((DefaultProjectFileSystem) project.getFileSystem()).addFileFilters(fileFilters); } private void loadCoreComponents(MutablePicoContainer container) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java index 372100fe4ae..9908252d11e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Languages.java @@ -19,15 +19,19 @@ */ package org.sonar.api.resources; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.commons.lang.ArrayUtils; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; -import java.util.*; - /** * A class to store the list of languages - * + * * @since 1.10 */ public class Languages implements BatchComponent, ServerComponent { @@ -47,9 +51,8 @@ public class Languages implements BatchComponent, ServerComponent { /** * @param keys the languages keys - * @return * @return the list of suffix files associates to languages included in the current object + * @return the list of suffix files associates to languages included in the current object */ - public String[] getSuffixes(String... keys) { List<String> suffixes = new ArrayList<String>(); |