From 8b351a6aa49e7ab626721023b9689d798f450e67 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 29 Aug 2014 09:30:58 +0200 Subject: [PATCH] SONAR-5547 Support branches when disabling automatic project creation --- .../sonar/batch/scan/ProjectReactorValidator.java | 3 +-- .../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; -- 2.39.5