aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-12-09 16:20:47 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-12-10 17:59:17 +0100
commit56a4685a6061731fe701ea3ec8afbf9a8a1015f0 (patch)
tree6d6619f27809db90b381c8bfb10415daa27fbc85
parent1be1ef656f02315135f1197f8dfa0128de3ab763 (diff)
downloadsonarqube-56a4685a6061731fe701ea3ec8afbf9a8a1015f0.tar.gz
sonarqube-56a4685a6061731fe701ea3ec8afbf9a8a1015f0.zip
SONAR-6968 Bad error message when analyzer detects that no language plugins are installed
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java16
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java2
8 files changed, 35 insertions, 21 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
index 8f6e0dd5e07..8b26d4bc1d0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.repository;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
+import org.sonar.api.utils.MessageException;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.sonar.batch.util.BatchUtils;
import org.apache.commons.io.IOUtils;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
@@ -34,8 +35,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import static com.google.common.base.Preconditions.checkState;
-
public class DefaultQualityProfileLoader implements QualityProfileLoader {
private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
@@ -48,7 +47,7 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader {
@Override
public List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) {
String url = WS_URL + "?defaults=true";
- if(profileName != null) {
+ if (profileName != null) {
url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
}
return loadResource(url, fromCache);
@@ -80,8 +79,9 @@ public class DefaultQualityProfileLoader implements QualityProfileLoader {
}
List<QualityProfile> profilesList = profiles.getProfilesList();
- checkState(profilesList != null && !profilesList.isEmpty(),
- "No quality profiles has been found this project, you probably don't have any language plugin suitable for this analysis.");
+ if (profilesList == null || profilesList.isEmpty()) {
+ throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed.");
+ }
return profilesList;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java b/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
index e1f0c915cfb..b42d9584226 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/language/DefaultLanguagesRepository.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.repository.language;
+import org.picocontainer.Startable;
+
import org.sonar.api.resources.Languages;
import javax.annotation.CheckForNull;
@@ -30,7 +32,7 @@ import java.util.Collection;
* Languages repository using {@link Languages}
* @since 4.4
*/
-public class DefaultLanguagesRepository implements LanguagesRepository {
+public class DefaultLanguagesRepository implements LanguagesRepository, Startable {
private Languages languages;
@@ -38,6 +40,7 @@ public class DefaultLanguagesRepository implements LanguagesRepository {
this.languages = languages;
}
+ @Override
public void start() {
if (languages.all().length == 0) {
throw new IllegalStateException("No language plugins are installed.");
@@ -67,4 +70,9 @@ public class DefaultLanguagesRepository implements LanguagesRepository {
return result;
}
+ @Override
+ public void stop() {
+ // nothing to do
+ }
+
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java
index 6aa753723b8..97a36e5541d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.scan;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
+import org.sonar.api.utils.MessageException;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import com.google.common.base.Joiner;
import java.util.ArrayList;
@@ -66,7 +67,7 @@ public class ProjectReactorValidator {
validateBranch(validationMessages, branch);
if (!validationMessages.isEmpty()) {
- throw new IllegalStateException("Validation of project reactor failed:\n o " + Joiner.on("\n o ").join(validationMessages));
+ throw MessageException.of("Validation of project reactor failed:\n o " + Joiner.on("\n o ").join(validationMessages));
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
index ed7a35a4836..a8979340a61 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.mediumtest.fs;
+import org.sonar.api.utils.MessageException;
+
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
@@ -102,7 +104,7 @@ public class ProjectBuilderMediumTest {
public void testProjectBuilderWithNewLine() throws IOException {
File baseDir = prepareProject();
- exception.expect(IllegalStateException.class);
+ exception.expect(MessageException.class);
exception.expectMessage("is not a valid branch name");
tester.newTask()
.properties(ImmutableMap.<String, String>builder()
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java
index ec151f29874..f81789b937f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tasks/TasksMediumTest.java
@@ -87,7 +87,7 @@ public class TasksMediumTest {
thrown.expect(IllegalStateException.class);
thrown.expectMessage(
- "Unable to load component class org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask: org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask has unsatisfied dependency 'class org.sonar.api.issue.action.Actions'");
+ "Unable to load component class org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask");
tester.newTask()
.properties(ImmutableMap.<String, String>builder()
diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
index b3c2b79dcb3..4caba83ec70 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.repository;
-import org.sonarqube.ws.QualityProfiles;
+import org.sonar.api.utils.MessageException;
+import org.sonarqube.ws.QualityProfiles;
import com.google.common.io.Resources;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import org.sonar.batch.cache.WSLoaderResult;
@@ -77,7 +78,7 @@ public class DefaultQualityProfileLoaderTest {
InputStream is = createEncodedQP();
when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<InputStream>(is, false));
- exception.expect(IllegalStateException.class);
+ exception.expect(MessageException.class);
exception.expectMessage("No quality profiles");
qpLoader.load("project", null, null);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java
index 761c608c8cd..40b68bf21cb 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java
@@ -21,6 +21,8 @@ package org.sonar.batch.scan;
import static org.mockito.Mockito.when;
+import org.sonar.api.utils.MessageException;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -67,7 +69,7 @@ public class ProjectReactorValidatorTest {
validator.validate(createProjectReactor("project/key"));
when(mode.isIssues()).thenReturn(false);
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("is not a valid project or module key");
validator.validate(createProjectReactor("project/key"));
}
@@ -106,7 +108,7 @@ public class ProjectReactorValidatorTest {
public void fail_with_invalid_key() {
ProjectReactor reactor = createProjectReactor("foo$bar");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"foo$bar\" is not a valid project or module key");
validator.validate(reactor);
}
@@ -115,7 +117,7 @@ public class ProjectReactorValidatorTest {
public void fail_with_backslash_in_key() {
ProjectReactor reactor = createProjectReactor("foo\\bar");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"foo\\bar\" is not a valid project or module key");
validator.validate(reactor);
}
@@ -133,7 +135,7 @@ public class ProjectReactorValidatorTest {
@Test
public void fail_with_invalid_branch() {
ProjectReactor reactor = createProjectReactor("foo", "bran#ch");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"bran#ch\" is not a valid branch name");
validator.validate(reactor);
}
@@ -141,7 +143,7 @@ public class ProjectReactorValidatorTest {
@Test
public void fail_with_colon_in_branch() {
ProjectReactor reactor = createProjectReactor("foo", "bran:ch");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"bran:ch\" is not a valid branch name");
validator.validate(reactor);
}
@@ -150,7 +152,7 @@ public class ProjectReactorValidatorTest {
public void fail_with_only_digits() {
ProjectReactor reactor = createProjectReactor("12345");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"12345\" is not a valid project or module key");
validator.validate(reactor);
}
@@ -160,7 +162,7 @@ public class ProjectReactorValidatorTest {
ProjectReactor reactor = createProjectReactor("foo");
settings.setProperty("sonar.phase", "phase");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"sonar.phase\" is deprecated");
validator.validate(reactor);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java
index 6789d45e61b..ff4dceaef4c 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java
@@ -59,7 +59,7 @@ public class ComponentContainer implements ContainerPopulator.Container {
try {
return super.getComponent(componentKeyOrType, annotation);
} catch (Throwable t) {
- throw new IllegalStateException("Unable to load component " + componentKeyOrType + ": " + t.getMessage(), t);
+ throw new IllegalStateException("Unable to load component " + componentKeyOrType, t);
}
}