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;
builder.setSonarHome(Paths.get(home));
}
- builder.setAreaForGlobal(serverUrl, BatchUtils.getServerVersion());
+ builder.setAreaForGlobal(serverUrl);
cache = builder.build();
}
*/
package org.sonar.batch.cache;
-import org.sonar.batch.util.BatchUtils;
-
import org.sonar.home.cache.PersistentCache;
import java.util.HashMap;
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>();
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"));
}
}
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;
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;
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");
}
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;
}
@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());
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());
}
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"));
}
}