diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-08-29 09:30:58 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-08-29 09:31:36 +0200 |
commit | 8b351a6aa49e7ab626721023b9689d798f450e67 (patch) | |
tree | 90d1216215cd9cf85e111605dda5e47d17cf646d /sonar-batch | |
parent | 125763f1e69f430c7b52bd946e4a65d7209ad704 (diff) | |
download | sonarqube-8b351a6aa49e7ab626721023b9689d798f450e67.tar.gz sonarqube-8b351a6aa49e7ab626721023b9689d798f450e67.zip |
SONAR-5547 Support branches when disabling automatic project creation
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorValidator.java | 3 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java | 13 |
2 files changed, 13 insertions, 3 deletions
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 7b53b884b94..a5b5c1138ab 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 @@ -73,8 +73,7 @@ public class ProjectReactorValidator { private void preventAutomaticProjectCreationIfNeeded(ProjectReactor reactor) { if (settings.getBoolean(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION)) { - // FIXME should we take branch into account here? - String projectKey = reactor.getRoot().getKey(); + String projectKey = reactor.getRoot().getKeyWithBranch(); if (resourceDao.findByKey(projectKey) == null) { throw new SonarException(String.format("Unable to scan non-existing project \"%s\"", projectKey)); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java index a3b5dc26e67..c32b7b5cf0c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorValidatorTest.java @@ -60,6 +60,15 @@ public class ProjectReactorValidatorTest { validator.validate(reactor); } + @Test + public void not_fail_if_provisioning_enforced_and_project_with_branch_exists() throws Exception { + String key = "project-key"; + settings.setProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, true); + when(resourceDao.findByKey(key + ":branch")).thenReturn(mock(Component.class)); + ProjectReactor reactor = createProjectReactor(key, "branch"); + validator.validate(reactor); + } + @Test(expected = SonarException.class) public void fail_if_provisioning_enforced_and_project_not_provisioned() throws Exception { String key = "project-key"; @@ -246,7 +255,9 @@ public class ProjectReactorValidatorTest { } private ProjectReactor createProjectReactor(String projectKey, String branch) { - ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, projectKey); + ProjectDefinition def = ProjectDefinition.create() + .setProperty(CoreProperties.PROJECT_KEY_PROPERTY, projectKey) + .setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, branch); ProjectReactor reactor = new ProjectReactor(def); settings.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, branch); return reactor; |