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