]> source.dussan.org Git - sonarqube.git/commitdiff
Fix bug creating project keys with branch
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2015 13:07:34 +0000 (15:07 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2015 13:34:18 +0000 (15:34 +0200)
sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
sonar-batch/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java [new file with mode: 0644]

index 191b5872e4813c7ae855166b067d0d0ac8f39d60..3308098c6a06534106b85ddec769b1c1693bcb7a 100644 (file)
@@ -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;
   }
 }
index dc4957bac92400faf8eb41d4bd08eb0846623285..1ebd2dfeee96f099caea050568eada877ad45064 100644 (file)
  */
 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 (file)
index 0000000..b6d132a
--- /dev/null
@@ -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");
+  }
+}