]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2922 Do not display stacktrace when validation is faling
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 19 Jun 2015 10:19:48 +0000 (12:19 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 19 Jun 2015 10:19:48 +0000 (12:19 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java

index 7fda85767cd1ac8569cc619e26d6f1ccbf62140c..f3a7aaf6e1174d1958e922b32fbd58f468212de7 100644 (file)
@@ -30,6 +30,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.component.ComponentKeys;
@@ -83,7 +84,7 @@ public class ValidateProjectStep implements ComputationStep {
       visitor.visit(treeRootHolder.getRoot());
 
       if (!visitor.validationMessages.isEmpty()) {
-        throw new IllegalArgumentException("Validation of project failed:\n  o " + MESSAGES_JOINER.join(visitor.validationMessages));
+        throw MessageException.of("Validation of project failed:\n  o " + MESSAGES_JOINER.join(visitor.validationMessages));
       }
     } finally {
       session.close();
index ffd5d8414e2cd821da32f6d38afc3a0a7075196b..cbfab26eab7f2649230d15e4d6efe0096f177a1e 100644 (file)
@@ -28,6 +28,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
 import org.sonar.batch.protocol.Constants;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.core.component.ComponentDto;
@@ -97,7 +98,7 @@ public class ValidateProjectStepTest {
 
   @Test
   public void fail_if_provisioning_enforced_and_project_does_not_exists() throws Exception {
-    thrown.expect(IllegalArgumentException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("Unable to scan non-existing project '" + PROJECT_KEY + "'");
 
     reportReader.setMetadata(BatchReport.Metadata.newBuilder().build());
@@ -145,7 +146,7 @@ public class ValidateProjectStepTest {
 
   @Test
   public void fail_on_invalid_branch() throws Exception {
-    thrown.expect(IllegalArgumentException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("Validation of project failed:\n" +
       "  o \"bran#ch\" is not a valid branch name. Allowed characters are alphanumeric, '-', '_', '.' and '/'.");
 
@@ -166,7 +167,7 @@ public class ValidateProjectStepTest {
   public void fail_on_invalid_key() throws Exception {
     String invalidProjectKey = "Project\\Key";
 
-    thrown.expect(IllegalArgumentException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("Validation of project failed:\n" +
       "  o \"Project\\Key\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.\n" +
       "  o \"Module$Key\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit");
@@ -192,7 +193,7 @@ public class ValidateProjectStepTest {
 
   @Test
   public void fail_if_module_key_is_already_used_as_project_key() throws Exception {
-    thrown.expect(IllegalArgumentException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("Validation of project failed:\n" +
       "  o The project \"" + MODULE_KEY + "\" is already defined in SonarQube but not as a module of project \"" + PROJECT_KEY + "\". " +
       "If you really want to stop directly analysing project \"" + MODULE_KEY + "\", please first delete it from SonarQube and then relaunch the analysis of project \""
@@ -225,7 +226,7 @@ public class ValidateProjectStepTest {
   @Test
   public void fail_if_module_key_already_exists_in_another_project() throws Exception {
     String anotherProjectKey = "ANOTHER_PROJECT_KEY";
-    thrown.expect(IllegalArgumentException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("Validation of project failed:\n" +
       "  o Module \"" + MODULE_KEY + "\" is already part of project \"" + anotherProjectKey + "\"");
 
@@ -259,7 +260,7 @@ public class ValidateProjectStepTest {
   @Test
   public void fail_if_project_key_already_exists_as_module() throws Exception {
     String anotherProjectKey = "ANOTHER_PROJECT_KEY";
-    thrown.expect(IllegalArgumentException.class);
+    thrown.expect(MessageException.class);
     thrown.expectMessage("Validation of project failed:\n" +
       "  o The project \"" + PROJECT_KEY + "\" is already defined in SonarQube but as a module of project \"" + anotherProjectKey + "\". " +
       "If you really want to stop directly analysing project \"" + anotherProjectKey + "\", please first delete it from SonarQube and then relaunch the analysis of project \""