From: Duarte Meneses Date: Tue, 29 Sep 2015 12:43:50 +0000 (+0200) Subject: Dont use server version in global cache keys X-Git-Tag: 5.2-RC1~156 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9ee1c1e3ba2be613b41807e119ae9f819aa7952b;p=sonarqube.git Dont use server version in global cache keys --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java b/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java index 29e2f42ea38..26d8a215957 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java @@ -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(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java index fe0513bfc5a..e009ddcc795 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java @@ -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 map = new HashMap(); @@ -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")); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java index 75e5b65e633..e66ee692ad4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java @@ -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"); diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java index 2097832853b..7be8fae66e8 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java @@ -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; } diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java index 7a57e98d68c..4ce016dd633 100644 --- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java +++ b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java @@ -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")); } }