aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-03-10 14:08:40 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2016-03-15 15:42:51 +0100
commitdf6c0db07a47e156aa5ff1a67788d37d2d6b0555 (patch)
tree5000f93e05df8f2c0f7ab52bc60fdcca21b736af /sonar-batch/src
parentc189245cda6020e46179bb1d0c9f54497440883b (diff)
downloadsonarqube-df6c0db07a47e156aa5ff1a67788d37d2d6b0555.tar.gz
sonarqube-df6c0db07a47e156aa5ff1a67788d37d2d6b0555.zip
Cleanup error reporting on scanner side
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java21
3 files changed, 21 insertions, 20 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java
index 250d5fb9bc3..e3be61067e6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/analysis/AnalysisProperties.java
@@ -19,11 +19,9 @@
*/
package org.sonar.batch.analysis;
-import org.sonar.batch.bootstrap.UserProperties;
-
-import javax.annotation.Nullable;
-
import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.batch.bootstrap.UserProperties;
/**
* Batch properties that are specific to an analysis (for example
@@ -32,8 +30,9 @@ import java.util.Map;
public class AnalysisProperties extends UserProperties {
public AnalysisProperties(Map<String, String> properties) {
this(properties, null);
+
}
-
+
public AnalysisProperties(Map<String, String> properties, @Nullable String pathToSecretKey) {
super(properties, pathToSecretKey);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
index 70eb4fae60c..59ee5a499aa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
@@ -40,6 +40,7 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
@@ -134,7 +135,7 @@ public class ProjectReactorBuilder {
private static void extractPropertiesByModule(Map<String, Map<String, String>> propertiesByModuleIdPath, String currentModuleId, String currentModuleIdPath,
Map<String, String> parentProperties) {
if (propertiesByModuleIdPath.containsKey(currentModuleIdPath)) {
- throw new IllegalStateException(String.format("Two modules have the same id: '%s'. Each module must have a unique id.", currentModuleId));
+ throw MessageException.of(String.format("Two modules have the same id: '%s'. Each module must have a unique id.", currentModuleId));
}
Map<String, String> currentModuleProperties = new HashMap<>();
@@ -295,14 +296,14 @@ public class ProjectReactorBuilder {
protected static void checkUniquenessOfChildKey(ProjectDefinition childProject, ProjectDefinition parentProject) {
for (ProjectDefinition definition : parentProject.getSubProjects()) {
if (definition.getKey().equals(childProject.getKey())) {
- throw new IllegalStateException("Project '" + parentProject.getKey() + "' can't have 2 modules with the following key: " + childProject.getKey());
+ throw MessageException.of("Project '" + parentProject.getKey() + "' can't have 2 modules with the following key: " + childProject.getKey());
}
}
}
protected static void setProjectBaseDir(File baseDir, Map<String, String> childProps, String moduleId) {
if (!baseDir.isDirectory()) {
- throw new IllegalStateException("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath());
+ throw MessageException.of("The base directory of the module '" + moduleId + "' does not exist: " + baseDir.getAbsolutePath());
}
childProps.put(PROPERTY_PROJECT_BASEDIR, baseDir.getAbsolutePath());
}
@@ -320,7 +321,7 @@ public class ProjectReactorBuilder {
}
String moduleKey = StringUtils.defaultIfBlank(props.get(MODULE_KEY_PROPERTY), props.get(CoreProperties.PROJECT_KEY_PROPERTY));
if (missing.length() != 0) {
- throw new IllegalStateException("You must define the following mandatory properties for '" + (moduleKey == null ? "Unknown" : moduleKey) + "': " + missing);
+ throw MessageException.of("You must define the following mandatory properties for '" + (moduleKey == null ? "Unknown" : moduleKey) + "': " + missing);
}
}
@@ -394,7 +395,7 @@ public class ProjectReactorBuilder {
File sourceFolder = resolvePath(baseDir, path);
if (!sourceFolder.exists()) {
LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, propName, moduleRef));
- throw new IllegalStateException("The folder '" + path + "' does not exist for '" + moduleRef +
+ throw MessageException.of("The folder '" + path + "' does not exist for '" + moduleRef +
"' (base directory = " + baseDir.getAbsolutePath() + ")");
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
index 24b6bca3fc9..d1a61853ef2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
@@ -37,6 +37,7 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.batch.analysis.AnalysisProperties;
@@ -73,7 +74,7 @@ public class ProjectReactorBuilderTest {
@Test
public void shouldFailIfUnexistingSourceDirectory() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = "
+ getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")");
@@ -82,7 +83,7 @@ public class ProjectReactorBuilderTest {
@Test
public void fail_if_sources_not_set() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("You must define the following mandatory properties for 'com.foo.project': sonar.sources");
loadProjectDefinition("simple-project-with-missing-source-dir");
}
@@ -94,7 +95,7 @@ public class ProjectReactorBuilderTest {
@Test
public void modulesDuplicateIds() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("Two modules have the same id: 'module1'. Each module must have a unique id.");
loadProjectDefinition("multi-module-duplicate-id");
@@ -242,7 +243,7 @@ public class ProjectReactorBuilderTest {
@Test
public void shouldFailIfUnexistingModuleBaseDir() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("The base directory of the module 'module1' does not exist: "
+ getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1");
@@ -251,7 +252,7 @@ public class ProjectReactorBuilderTest {
@Test
public void shouldFailIfUnexistingSourceFolderInheritedInMultimodule() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project:module1' (base directory = "
+ getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)");
@@ -260,7 +261,7 @@ public class ProjectReactorBuilderTest {
@Test
public void shouldFailIfExplicitUnexistingTestFolder() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("The folder 'tests' does not exist for 'com.foo.project' (base directory = "
+ getResource(this.getClass(), "simple-project-with-unexisting-test-dir").getAbsolutePath());
@@ -269,7 +270,7 @@ public class ProjectReactorBuilderTest {
@Test
public void shouldFailIfExplicitUnexistingTestFolderOnModule() {
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("The folder 'tests' does not exist for 'module1' (base directory = "
+ getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)");
@@ -334,7 +335,7 @@ public class ProjectReactorBuilderTest {
props.put("foo1", "bla");
props.put("foo4", "bla");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3");
ProjectReactorBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
@@ -346,7 +347,7 @@ public class ProjectReactorBuilderTest {
props.put("foo1", "bla");
props.put("sonar.projectKey", "my-project");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("You must define the following mandatory properties for 'my-project': foo2, foo3");
ProjectReactorBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
@@ -465,7 +466,7 @@ public class ProjectReactorBuilderTest {
// Now, add it and check again
root.addSubProject(mod2);
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2");
ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root);