diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-04-03 17:18:17 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-04-03 18:00:21 +0200 |
commit | c34a0fbc73d3780b22c9c1aca8dd383419b75305 (patch) | |
tree | c8f2e7ec2cbb07c494bb5a1f62e3e97ad8b3a365 /sonar-batch | |
parent | 7a0e94ba8a9dbad2747985756411118d8b49bb7f (diff) | |
download | sonarqube-c34a0fbc73d3780b22c9c1aca8dd383419b75305.tar.gz sonarqube-c34a0fbc73d3780b22c9c1aca8dd383419b75305.zip |
SONAR-5178 Display allowed characters when validating branches
Diffstat (limited to 'sonar-batch')
4 files changed, 4 insertions, 26 deletions
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<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)); } } 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 @@ -59,13 +59,6 @@ public class ProjectReactorBuilderTest { } @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); thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = " 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 |