aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-13 15:07:34 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-13 15:34:18 +0200
commitc5bd94becf874e57b2d624f3d9a2cb3ae546616f (patch)
treeb4c665fa4530048517374ee6b9b858e50cc99538 /sonar-batch
parentfc575b3db63edd279a8b8cdda69331b4382b68d8 (diff)
downloadsonarqube-c5bd94becf874e57b2d624f3d9a2cb3ae546616f.tar.gz
sonarqube-c5bd94becf874e57b2d624f3d9a2cb3ae546616f.zip
Fix bug creating project keys with branch
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java70
3 files changed, 81 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
index 191b5872e48..3308098c6a0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
@@ -80,6 +80,6 @@ public class DefaultProjectCacheStatus implements ProjectCacheStatus {
}
private String getKey(String projectKey) {
- return STATUS_PREFIX + client.getURL() + projectKey;
+ return STATUS_PREFIX + client.getURL() + "-" + projectKey;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
index dc4957bac92..1ebd2dfeee9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
@@ -19,12 +19,13 @@
*/
package org.sonar.batch.cache;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.batch.scan.ProjectReactorBuilder;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.cache.WSLoader.LoadStrategy;
import org.sonar.batch.analysis.AnalysisProperties;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.batch.repository.user.UserRepositoryLoader;
import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
@@ -32,7 +33,6 @@ import org.sonar.batch.repository.DefaultProjectRepositoriesLoader;
import org.sonar.batch.repository.DefaultServerIssuesLoader;
import org.sonar.batch.repository.ProjectRepositoriesLoader;
import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader;
import org.sonar.core.platform.ComponentContainer;
@@ -47,20 +47,16 @@ public class ProjectSyncContainer extends ComponentContainer {
}
@Override
- protected void doBeforeStart() {
- ProjectReactor projectReactor = createSimpleProjectReactor();
+ public void doBeforeStart() {
+ ProjectReactor projectReactor = createProjectReactor();
add(projectReactor);
addComponents();
}
- private ProjectReactor createSimpleProjectReactor() {
- ProjectDefinition rootProjDefinition = ProjectDefinition.create();
- String projectKey = properties.property(CoreProperties.PROJECT_KEY_PROPERTY);
- if (StringUtils.isEmpty(projectKey)) {
- throw new IllegalStateException("Missing mandatory property: " + CoreProperties.PROJECT_KEY_PROPERTY);
- }
- rootProjDefinition.setKey(projectKey);
- return new ProjectReactor(rootProjDefinition);
+ private ProjectReactor createProjectReactor() {
+ ProjectDefinition rootProjectDefinition = ProjectDefinition.create();
+ rootProjectDefinition.setProperties(properties.properties());
+ return new ProjectReactor(rootProjectDefinition);
}
@Override
diff --git a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java
new file mode 100644
index 00000000000..b6d132ae8b2
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java
@@ -0,0 +1,70 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.cache;
+
+import org.sonar.batch.bootstrap.GlobalProperties;
+import org.sonar.batch.bootstrap.ServerClient;
+import org.sonar.home.cache.PersistentCache;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.batch.analysis.AnalysisProperties;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import static org.mockito.Mockito.mock;
+import org.sonar.core.platform.ComponentContainer;
+import org.junit.Test;
+
+public class ProjectSyncContainerTest {
+ private ComponentContainer createParentContainer() {
+ PersistentCache cache = mock(PersistentCache.class);
+ ServerClient server = mock(ServerClient.class);
+
+ GlobalProperties globalProps = new GlobalProperties(new HashMap<String, String>());
+ ComponentContainer parent = new ComponentContainer();
+ parent.add(cache);
+ parent.add(server);
+ parent.add(globalProps);
+ return parent;
+ }
+
+ public AnalysisProperties createProjectProperties() {
+ Map<String, String> properties = new HashMap<>();
+ properties.put("sonar.branch", "branch");
+ properties.put("sonar.projectKey", "my:project");
+ properties.put("sonar.projectName", "My project");
+ properties.put("sonar.projectVersion", "1.0");
+ properties.put("sonar.sources", ".");
+ properties.put("sonar.projectBaseDir", ".");
+ return new AnalysisProperties(properties);
+ }
+
+ @Test
+ public void testProjectKeyWithBranch() {
+ ProjectSyncContainer container = new ProjectSyncContainer(createParentContainer(), createProjectProperties(), true);
+ container.doBeforeStart();
+ container.getPicoContainer().start();
+
+ ProjectReactor projectReactor = container.getComponentByType(ProjectReactor.class);
+ assertThat(projectReactor.getRoot().getKeyWithBranch()).isEqualTo("my:project:branch");
+ }
+}