From c34a0fbc73d3780b22c9c1aca8dd383419b75305 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 3 Apr 2014 17:18:17 +0200 Subject: [PATCH] SONAR-5178 Display allowed characters when validating branches --- .../org/sonar/batch/scan/ProjectReactorBuilder.java | 10 ---------- .../org/sonar/batch/scan/ProjectReactorValidator.java | 6 ++++-- .../sonar/batch/scan/ProjectReactorBuilderTest.java | 7 ------- .../project-with-invalid-key/sonar-project.properties | 7 ------- 4 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/project-with-invalid-key/sonar-project.properties 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 76630fde56a..181e66670d5 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 @@ -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); 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 66ffbafe93d..196b76513ec 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 @@ -79,7 +79,8 @@ public class ProjectReactorValidator { private void validateModule(ProjectDefinition moduleDef, List 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 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)); } } 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 dfea7822a7a..85a83bbfba2 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 @@ -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 index d13fd3f59d0..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/project-with-invalid-key/sonar-project.properties +++ /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 -- 2.39.5