]> source.dussan.org Git - sonarqube.git/commitdiff
Dont use server version in global cache keys
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 29 Sep 2015 12:43:50 +0000 (14:43 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 30 Sep 2015 14:28:08 +0000 (16:28 +0200)
sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java
sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java
sonar-batch/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java
sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java
sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java

index 29e2f42ea38d16e1ce9e38509fbc9bd85f3734b8..26d8a21595712cb48c267d1c8008f0eeb580fdbb 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.batch.cache;
 
 import org.apache.commons.lang.StringUtils;
 import org.sonar.batch.bootstrap.Slf4jLogger;
-import org.sonar.batch.util.BatchUtils;
 import org.sonar.home.cache.PersistentCacheBuilder;
 
 import java.nio.file.Paths;
@@ -43,7 +42,7 @@ public class GlobalPersistentCacheProvider extends ProviderAdapter {
         builder.setSonarHome(Paths.get(home));
       }
       
-      builder.setAreaForGlobal(serverUrl, BatchUtils.getServerVersion());
+      builder.setAreaForGlobal(serverUrl);
       cache = builder.build();
     }
 
index fe0513bfc5a31f1eb8f6133a58b6534b26b15a5a..e009ddcc795f85ed66c62633014fd8816902bbad 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.batch.cache;
 
-import org.sonar.batch.util.BatchUtils;
-
 import org.sonar.home.cache.PersistentCache;
 
 import java.util.HashMap;
@@ -35,10 +33,10 @@ import org.junit.rules.TemporaryFolder;
 public class GlobalPersistentCacheProviderTest {
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
-  
+
   private GlobalPersistentCacheProvider provider;
   private GlobalProperties globalProperties;
-  
+
   @Before
   public void setUp() {
     HashMap<String, String> map = new HashMap<String, String>();
@@ -46,13 +44,13 @@ public class GlobalPersistentCacheProviderTest {
     globalProperties = new GlobalProperties(map);
     provider = new GlobalPersistentCacheProvider();
   }
-  
+
   @Test
   public void test_path() {
     PersistentCache cache = provider.provide(globalProperties);
     assertThat(cache.getDirectory()).isEqualTo(temp.getRoot().toPath()
       .resolve("ws_cache")
-      .resolve("http%3A%2F%2Flocalhost%3A9000-" + BatchUtils.getServerVersion())
+      .resolve("http%3A%2F%2Flocalhost%3A9000")
       .resolve("global"));
   }
 }
index 75e5b65e633c69bf169606fb566cadef85c9baed..e66ee692ad4b521d619320ecef509f21c0fff95a 100644 (file)
@@ -22,8 +22,6 @@ package org.sonar.batch.cache;
 import org.sonar.api.batch.bootstrap.ProjectKey;
 
 import org.sonar.batch.util.BatchUtils;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.batch.analysis.DefaultAnalysisMode;
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
@@ -34,7 +32,6 @@ import java.io.File;
 import java.nio.file.Path;
 import java.util.Collections;
 
-import static org.mockito.Mockito.when;
 import static org.mockito.Mockito.mock;
 import org.junit.Before;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -73,7 +70,8 @@ public class ProjectPersistentCacheProviderTest {
     props.properties().put("sonar.userHome", f.getAbsolutePath());
     Path expected = f.toPath()
       .resolve("ws_cache")
-      .resolve("http%3A%2F%2Flocalhost%3A9000-" + BatchUtils.getServerVersion())
+      .resolve("http%3A%2F%2Flocalhost%3A9000")
+      .resolve( BatchUtils.getServerVersion())
       .resolve("projects")
       .resolve("proj");
 
index 2097832853b902872306c97a53f3544f99a6e265..7be8fae66e8ed204c4ba5b3576a1d98094d1b014 100644 (file)
@@ -49,20 +49,22 @@ public class PersistentCacheBuilder {
   }
 
   public PersistentCacheBuilder setAreaForProject(String serverUrl, String serverVersion, String projectKey) {
-    relativePath = Paths.get(sanitizeFilename(serverUrl + "-" + serverVersion))
+    relativePath = Paths.get(sanitizeFilename(serverUrl))
+      .resolve(sanitizeFilename(serverVersion))
       .resolve("projects")
       .resolve(sanitizeFilename(projectKey));
     return this;
   }
   
-  public PersistentCacheBuilder setAreaForGlobal(String serverUrl, String serverVersion) {
-    relativePath = Paths.get(sanitizeFilename(serverUrl + "-" + serverVersion))
+  public PersistentCacheBuilder setAreaForGlobal(String serverUrl) {
+    relativePath = Paths.get(sanitizeFilename(serverUrl))
       .resolve("global");
     return this;
   }
   
   public PersistentCacheBuilder setAreaForLocalProject(String serverUrl, String serverVersion) {
-    relativePath = Paths.get(sanitizeFilename(serverUrl + "-" + serverVersion))
+    relativePath = Paths.get(sanitizeFilename(serverUrl))
+      .resolve(sanitizeFilename(serverVersion))
       .resolve("local");
     return this;
   }
index 7a57e98d68ca5aebfe6c325af4f1c910e47ec061..4ce016dd633f4460dd4cb22deaac16a64261c816 100644 (file)
@@ -36,14 +36,14 @@ public class PersistentCacheBuilderTest {
 
   @Test
   public void user_home_property_can_be_null() {
-    PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(null).setAreaForGlobal("url", "0").build();
+    PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(null).setAreaForGlobal("url").build();
     assertTrue(Files.isDirectory(cache.getDirectory()));
-    assertThat(cache.getDirectory()).endsWith(Paths.get("url-0", "global"));
+    assertThat(cache.getDirectory()).endsWith(Paths.get("url", "global"));
   }
 
   @Test
   public void set_user_home() {
-    PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(temp.getRoot().toPath()).setAreaForGlobal("url", "0").build();
+    PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(temp.getRoot().toPath()).setAreaForGlobal("url").build();
 
     assertThat(cache.getDirectory()).isDirectory();
     assertThat(cache.getDirectory()).startsWith(temp.getRoot().toPath());
@@ -56,7 +56,7 @@ public class PersistentCacheBuilderTest {
 
     System.setProperty("user.home", temp.getRoot().getAbsolutePath());
 
-    PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url", "0").build();
+    PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url").build();
     assertTrue(Files.isDirectory(cache.getDirectory()));
     assertThat(cache.getDirectory()).startsWith(temp.getRoot().toPath());
   }
@@ -66,12 +66,12 @@ public class PersistentCacheBuilderTest {
     System.setProperty("user.home", temp.getRoot().getAbsolutePath());
 
     PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForProject("url", "0", "proj").build();
-    assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url-0", "projects", "proj"));
+    assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "0", "projects", "proj"));
 
     cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForLocalProject("url", "0").build();
-    assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url-0", "local"));
+    assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "0", "local"));
 
-    cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url", "0").build();
-    assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url-0", "global"));
+    cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url").build();
+    assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "global"));
   }
 }