]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5178 Display allowed characters when validating branches
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 3 Apr 2014 15:18:17 +0000 (17:18 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 3 Apr 2014 16:00:21 +0000 (18:00 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/project-with-invalid-key/sonar-project.properties [deleted file]

index 76630fde56a49e056dad9c1393a378c667a7865b..181e66670d5c9215db24a9c2c7e11ffa74387389 100644 (file)
@@ -33,7 +33,6 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.batch.bootstrap.BootstrapSettings;
-import org.sonar.core.component.ComponentKeys;
 
 import javax.annotation.CheckForNull;
 
@@ -123,7 +122,6 @@ public class ProjectReactorBuilder {
       checkMandatoryProperties(properties, MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT);
     }
     final String projectKey = properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY);
-    checkProjectKeyValid(projectKey);
     File workDir;
     if (parent == null) {
       validateDirectories(properties, baseDir, projectKey);
@@ -139,14 +137,6 @@ public class ProjectReactorBuilder {
     return definition;
   }
 
-  private void checkProjectKeyValid(String projectKey) {
-    if (!ComponentKeys.isValidModuleKey(projectKey)) {
-      throw new IllegalStateException(String.format(
-        "Invalid project key '%s'.\n"
-          + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", projectKey));
-    }
-  }
-
   @VisibleForTesting
   protected File initRootProjectWorkDir(File baseDir) {
     String workDir = settings.property(CoreProperties.WORKING_DIRECTORY);
index 66ffbafe93dce722a1ec1cf59f25e6e16cea44b4..196b76513ec80094b33d73fd6ef31619f8fb181e 100644 (file)
@@ -79,7 +79,8 @@ public class ProjectReactorValidator {
 
   private void validateModule(ProjectDefinition moduleDef, List<String> validationMessages, @Nullable String branch, String rootProjectKey) {
     if (!ComponentKeys.isValidModuleKey(moduleDef.getKey())) {
-      validationMessages.add(String.format("\"%s\" is not a valid project or module key", moduleDef.getKey()));
+      validationMessages.add(String.format("\"%s\" is not a valid project or module key. "
+        + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", moduleDef.getKey()));
     } else if (isSubProject(moduleDef)) {
       // SONAR-4692 Validate root project is the same than previous analysis to avoid module with same key in different projects
       String moduleKey = ComponentKeys.createKey(moduleDef.getKey(), branch);
@@ -108,7 +109,8 @@ public class ProjectReactorValidator {
 
   private void validateBranch(List<String> validationMessages, @Nullable String branch) {
     if (StringUtils.isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) {
-      validationMessages.add(String.format("\"%s\" is not a valid branch name", branch));
+      validationMessages.add(String.format("\"%s\" is not a valid branch name. "
+        + "Allowed characters are alphanumeric, '-', '_' and '.'.", branch));
     }
   }
 
index dfea7822a7ae5e4ac13175e2c1cde4ce31a65f2e..85a83bbfba23c7caf55cea7493fa3b50d9b6c578 100644 (file)
@@ -58,13 +58,6 @@ public class ProjectReactorBuilderTest {
       TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
   }
 
-  @Test
-  public void shouldFailOnInvalidProjectKey() throws IOException {
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("Invalid project key 'A key with spaces'.\nAllowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
-    loadProjectDefinition("project-with-invalid-key");
-  }
-
   @Test
   public void shouldFailIfUnexistingSourceDirectory() throws IOException {
     thrown.expect(IllegalStateException.class);
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/project-with-invalid-key/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/project-with-invalid-key/sonar-project.properties
deleted file mode 100644 (file)
index d13fd3f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-sonar.projectKey=A key with spaces
-sonar.projectName=Foo Project
-sonar.projectVersion=1.0-SNAPSHOT
-sonar.projectDescription=Description of Foo Project
-
-sonar.sources=sources
-sonar.libraries=libs/*.txt