aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-home/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-home/src')
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/FileCache.java31
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java19
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/Logger.java (renamed from sonar-home/src/main/java/org/sonar/home/log/Log.java)15
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java48
-rw-r--r--sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java22
-rw-r--r--sonar-home/src/main/java/org/sonar/home/log/LogListener.java28
-rw-r--r--sonar-home/src/main/java/org/sonar/home/log/Slf4jLog.java62
-rw-r--r--sonar-home/src/main/java/org/sonar/home/log/StandardLog.java38
-rw-r--r--sonar-home/src/main/java/org/sonar/home/log/package-info.java25
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/FileCacheBuilderTest.java10
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java18
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java21
-rw-r--r--sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java29
13 files changed, 96 insertions, 270 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
index 5998b97a2c5..3e83cd9d673 100644
--- a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java
@@ -19,13 +19,10 @@
*/
package org.sonar.home.cache;
-import org.sonar.home.log.Log;
-
-import javax.annotation.CheckForNull;
-
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import javax.annotation.CheckForNull;
/**
* This class is responsible for managing Sonar batch file cache. You can put file into cache and
@@ -39,18 +36,18 @@ public class FileCache {
private final File dir, tmpDir;
private final FileHashes hashes;
- private final Log log;
+ private final Logger logger;
- FileCache(File dir, Log log, FileHashes fileHashes) {
+ FileCache(File dir, FileHashes fileHashes, Logger logger) {
this.hashes = fileHashes;
- this.log = log;
- this.dir = createDir(dir, log, "user cache");
- log.info(String.format("User cache: %s", dir.getAbsolutePath()));
- this.tmpDir = createDir(new File(dir, "_tmp"), log, "temp dir");
+ this.logger = logger;
+ this.dir = createDir(dir, "user cache");
+ logger.info(String.format("User cache: %s", dir.getAbsolutePath()));
+ this.tmpDir = createDir(new File(dir, "_tmp"), "temp dir");
}
- public static FileCache create(File dir, Log log) {
- return new FileCache(dir, log, new FileHashes());
+ public static FileCache create(File dir, Logger logger) {
+ return new FileCache(dir, new FileHashes(), logger);
}
public File getDir() {
@@ -67,7 +64,7 @@ public class FileCache {
if (cachedFile.exists()) {
return cachedFile;
}
- log.debug(String.format("No file found in the cache with name %s and hash %s", filename, hash));
+ logger.debug(String.format("No file found in the cache with name %s and hash %s", filename, hash));
return null;
}
@@ -105,8 +102,8 @@ public class FileCache {
boolean rename = sourceFile.renameTo(targetFile);
// Check if the file was cached by another process during download
if (!rename && !targetFile.exists()) {
- log.warn(String.format("Unable to rename %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath()));
- log.warn("A copy/delete will be tempted but with no guarantee of atomicity");
+ logger.warn(String.format("Unable to rename %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath()));
+ logger.warn("A copy/delete will be tempted but with no guarantee of atomicity");
try {
Files.move(sourceFile.toPath(), targetFile.toPath());
} catch (IOException e) {
@@ -147,9 +144,9 @@ public class FileCache {
throw new IllegalStateException("Failed to create directory in " + tmpDir);
}
- private File createDir(File dir, Log log, String debugTitle) {
+ private File createDir(File dir, String debugTitle) {
if (!dir.isDirectory() || !dir.exists()) {
- log.debug("Create : " + dir.getAbsolutePath());
+ logger.debug("Create : " + dir.getAbsolutePath());
try {
Files.createDirectories(dir.toPath());
} catch (IOException e) {
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java b/sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java
index 6ebb828ca5a..040ea887b8e 100644
--- a/sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java
@@ -19,25 +19,20 @@
*/
package org.sonar.home.cache;
-import org.sonar.home.log.Log;
-import org.sonar.home.log.StandardLog;
-
-import javax.annotation.Nullable;
-
import java.io.File;
+import javax.annotation.Nullable;
public class FileCacheBuilder {
private File userHome;
- private Log log = new StandardLog();
+ private Logger logger;
- public FileCacheBuilder setUserHome(File d) {
- this.userHome = d;
- return this;
+ public FileCacheBuilder(Logger logger) {
+ this.logger = logger;
}
- public FileCacheBuilder setLog(Log log) {
- this.log = log;
+ public FileCacheBuilder setUserHome(File d) {
+ this.userHome = d;
return this;
}
@@ -56,6 +51,6 @@ public class FileCacheBuilder {
userHome = new File(path);
}
File cacheDir = new File(userHome, "cache");
- return FileCache.create(cacheDir, log);
+ return FileCache.create(cacheDir, logger);
}
}
diff --git a/sonar-home/src/main/java/org/sonar/home/log/Log.java b/sonar-home/src/main/java/org/sonar/home/cache/Logger.java
index bb67428ae98..fb4e8ebc2e0 100644
--- a/sonar-home/src/main/java/org/sonar/home/log/Log.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/Logger.java
@@ -17,15 +17,18 @@
* 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.home.log;
+package org.sonar.home.cache;
-public interface Log {
- void debug(String s);
+public interface Logger {
- void info(String s);
+ void debug(String msg);
- void warn(String s);
+ void info(String msg);
- void error(String s, Throwable throwable);
+ void warn(String msg);
+
+ void error(String msg);
+
+ void error(String msg, Throwable t);
}
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
index 6af55ef6271..95b93e6ed27 100644
--- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
+++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
@@ -19,12 +19,6 @@
*/
package org.sonar.home.cache;
-import org.sonar.home.log.Log;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
@@ -39,10 +33,16 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.Callable;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
-import static java.nio.file.StandardOpenOption.*;
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
+import static java.nio.file.StandardOpenOption.WRITE;
public class PersistentCache {
+
private static final Charset ENCODING = StandardCharsets.UTF_8;
private static final String DIGEST_ALGO = "MD5";
private static final String LOCK_FNAME = ".lock";
@@ -51,23 +51,23 @@ public class PersistentCache {
// eviction strategy is to expire entries after modification once a time duration has elapsed
private final long defaultDurationToExpireMs;
- private final Log log;
private boolean forceUpdate;
+ private final Logger logger;
- public PersistentCache(Path baseDir, long defaultDurationToExpireMs, Log log, boolean forceUpdate) {
+ public PersistentCache(Path baseDir, long defaultDurationToExpireMs, boolean forceUpdate, Logger logger) {
this.baseDir = baseDir;
this.defaultDurationToExpireMs = defaultDurationToExpireMs;
- this.log = log;
+ this.logger = logger;
reconfigure(forceUpdate);
- log.debug("cache: " + baseDir + ", default expiration time (ms): " + defaultDurationToExpireMs);
+ logger.debug("cache: " + baseDir + ", default expiration time (ms): " + defaultDurationToExpireMs);
}
public void reconfigure(boolean forceUpdate) {
this.forceUpdate = forceUpdate;
if (forceUpdate) {
- log.debug("cache: forcing update");
+ logger.debug("cache: forcing update");
}
try {
@@ -115,13 +115,13 @@ public class PersistentCache {
byte[] cached = getCache(key);
if (cached != null) {
- log.debug("cache hit for " + obj + " -> " + key);
+ logger.debug("cache hit for " + obj + " -> " + key);
return cached;
}
- log.debug("cache miss for " + obj + " -> " + key);
+ logger.debug("cache miss for " + obj + " -> " + key);
} else {
- log.debug("cache force update for " + obj + " -> " + key);
+ logger.debug("cache force update for " + obj + " -> " + key);
}
if (valueLoader != null) {
@@ -142,12 +142,12 @@ public class PersistentCache {
* Deletes all cache entries
*/
public synchronized void clear() {
- log.info("cache: clearing");
+ logger.info("cache: clearing");
try {
lock();
deleteCacheEntries(createClearFilter());
} catch (IOException e) {
- log.error("Error clearing cache", e);
+ logger.error("Error clearing cache", e);
} finally {
unlock();
}
@@ -157,12 +157,12 @@ public class PersistentCache {
* Deletes cache entries that are no longer valid according to the default expiration time period.
*/
public synchronized void clean() {
- log.info("cache: cleaning");
+ logger.info("cache: cleaning");
try {
lock();
deleteCacheEntries(createCleanFilter());
} catch (IOException e) {
- log.error("Error cleaning cache", e);
+ logger.error("Error cleaning cache", e);
} finally {
unlock();
}
@@ -183,21 +183,21 @@ public class PersistentCache {
try {
lock.release();
} catch (IOException e) {
- log.error("Error releasing lock", e);
+ logger.error("Error releasing lock", e);
}
}
if (lock_fc != null) {
try {
lock_fc.close();
} catch (IOException e) {
- log.error("Error closing file channel", e);
+ logger.error("Error closing file channel", e);
}
}
if (lock_raf != null) {
try {
lock_raf.close();
} catch (IOException e) {
- log.error("Error closing file", e);
+ logger.error("Error closing file", e);
}
}
@@ -222,7 +222,7 @@ public class PersistentCache {
try {
Files.delete(p);
} catch (Exception e) {
- log.error("Error deleting " + p, e);
+ logger.error("Error deleting " + p, e);
}
}
}
@@ -271,7 +271,7 @@ public class PersistentCache {
}
if (isCacheEntryExpired(cacheEntryPath, durationToExpireMs)) {
- log.debug("cache: expiring entry");
+ logger.debug("cache: expiring entry");
Files.delete(cacheEntryPath);
return false;
}
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 c58dc53bbd6..e115f1cab64 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
@@ -19,35 +19,29 @@
*/
package org.sonar.home.cache;
-import org.sonar.home.log.StandardLog;
-
-import org.sonar.home.log.Log;
-
-import javax.annotation.Nullable;
-
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
public class PersistentCacheBuilder {
private static final long DEFAULT_EXPIRE_DURATION = TimeUnit.MILLISECONDS.convert(1L, TimeUnit.DAYS);
private static final String DIR_NAME = "ws_cache";
private boolean forceUpdate = false;
- private Path cachePath = null;
- private Log log = new StandardLog();
+ private Path cachePath;
+ private final Logger logger;
+
+ public PersistentCacheBuilder(Logger logger) {
+ this.logger = logger;
+ }
public PersistentCache build() {
if (cachePath == null) {
setSonarHome(findHome());
}
- return new PersistentCache(cachePath, DEFAULT_EXPIRE_DURATION, log, forceUpdate);
- }
-
- public PersistentCacheBuilder setLog(Log log) {
- this.log = log;
- return this;
+ return new PersistentCache(cachePath, DEFAULT_EXPIRE_DURATION, forceUpdate, logger);
}
public PersistentCacheBuilder setSonarHome(@Nullable Path p) {
diff --git a/sonar-home/src/main/java/org/sonar/home/log/LogListener.java b/sonar-home/src/main/java/org/sonar/home/log/LogListener.java
deleted file mode 100644
index fa11374fdc4..00000000000
--- a/sonar-home/src/main/java/org/sonar/home/log/LogListener.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.home.log;
-
-public interface LogListener {
- void log(String msg, Level level);
-
- enum Level {
- ERROR, WARN, INFO, DEBUG, TRACE;
- }
-}
diff --git a/sonar-home/src/main/java/org/sonar/home/log/Slf4jLog.java b/sonar-home/src/main/java/org/sonar/home/log/Slf4jLog.java
deleted file mode 100644
index 03ff7029ff8..00000000000
--- a/sonar-home/src/main/java/org/sonar/home/log/Slf4jLog.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.home.log;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class Slf4jLog implements Log {
-
- private final Logger logger;
-
- public Slf4jLog(Logger logger) {
- this.logger = logger;
- }
-
- public Slf4jLog(Class loggerClass) {
- this.logger = LoggerFactory.getLogger(loggerClass);
- }
-
- public boolean isDebugEnabled() {
- return logger.isDebugEnabled();
- }
-
- @Override
- public void debug(String s) {
- logger.debug(s);
- }
-
- @Override
- public void info(String s) {
- logger.info(s);
- }
-
- @Override
- public void warn(String s) {
- logger.warn(s);
- }
-
- @Override
- public void error(String s, Throwable throwable) {
- logger.error(s, throwable);
- }
-
-
-}
diff --git a/sonar-home/src/main/java/org/sonar/home/log/StandardLog.java b/sonar-home/src/main/java/org/sonar/home/log/StandardLog.java
deleted file mode 100644
index fa4402d15ca..00000000000
--- a/sonar-home/src/main/java/org/sonar/home/log/StandardLog.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.home.log;
-
-public class StandardLog implements Log {
- @Override
- public void debug(String s) {
- }
-
- @Override
- public void info(String s) {
- }
-
- @Override
- public void warn(String s) {
- }
-
- @Override
- public void error(String s, Throwable throwable) {
- }
-}
diff --git a/sonar-home/src/main/java/org/sonar/home/log/package-info.java b/sonar-home/src/main/java/org/sonar/home/log/package-info.java
deleted file mode 100644
index bbf1fe5f448..00000000000
--- a/sonar-home/src/main/java/org/sonar/home/log/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.home.log;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheBuilderTest.java b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheBuilderTest.java
index 59125570012..ec204cbf781 100644
--- a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheBuilderTest.java
+++ b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheBuilderTest.java
@@ -19,13 +19,13 @@
*/
package org.sonar.home.cache;
+import java.io.File;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import java.io.File;
-
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class FileCacheBuilderTest {
@Rule
@@ -34,7 +34,7 @@ public class FileCacheBuilderTest {
@Test
public void setUserHome() throws Exception {
File userHome = temp.newFolder();
- FileCache cache = new FileCacheBuilder().setUserHome(userHome).build();
+ FileCache cache = new FileCacheBuilder(mock(Logger.class)).setUserHome(userHome).build();
assertThat(cache.getDir()).isDirectory().exists();
assertThat(cache.getDir().getName()).isEqualTo("cache");
@@ -43,7 +43,7 @@ public class FileCacheBuilderTest {
@Test
public void user_home_property_can_be_null() {
- FileCache cache = new FileCacheBuilder().setUserHome((String) null).build();
+ FileCache cache = new FileCacheBuilder(mock(Logger.class)).setUserHome((String) null).build();
// does not fail. It uses default path or env variable
assertThat(cache.getDir()).isDirectory().exists();
@@ -52,7 +52,7 @@ public class FileCacheBuilderTest {
@Test
public void use_default_path_or_env_variable() {
- FileCache cache = new FileCacheBuilder().build();
+ FileCache cache = new FileCacheBuilder(mock(Logger.class)).build();
assertThat(cache.getDir()).isDirectory().exists();
assertThat(cache.getDir().getName()).isEqualTo("cache");
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java
index 1410b63ea50..7d7a3d70449 100644
--- a/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java
+++ b/sonar-home/src/test/java/org/sonar/home/cache/FileCacheTest.java
@@ -19,15 +19,13 @@
*/
package org.sonar.home.cache;
+import java.io.File;
+import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.sonar.home.log.Slf4jLog;
-
-import java.io.File;
-import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -41,17 +39,15 @@ public class FileCacheTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private Slf4jLog log = new Slf4jLog(FileCacheTest.class);
-
@Test
public void not_in_cache() throws IOException {
- FileCache cache = FileCache.create(tempFolder.newFolder(), log);
+ FileCache cache = FileCache.create(tempFolder.newFolder(), mock(Logger.class));
assertThat(cache.get("sonar-foo-plugin-1.5.jar", "ABCDE")).isNull();
}
@Test
public void found_in_cache() throws IOException {
- FileCache cache = FileCache.create(tempFolder.newFolder(), log);
+ FileCache cache = FileCache.create(tempFolder.newFolder(), mock(Logger.class));
// populate the cache. Assume that hash is correct.
File cachedFile = new File(new File(cache.getDir(), "ABCDE"), "sonar-foo-plugin-1.5.jar");
@@ -63,7 +59,7 @@ public class FileCacheTest {
@Test
public void download_and_add_to_cache() throws IOException {
FileHashes hashes = mock(FileHashes.class);
- FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes);
+ FileCache cache = new FileCache(tempFolder.newFolder(), hashes, mock(Logger.class));
when(hashes.of(any(File.class))).thenReturn("ABCDE");
FileCache.Downloader downloader = new FileCache.Downloader() {
@@ -84,7 +80,7 @@ public class FileCacheTest {
thrown.expectMessage("INVALID HASH");
FileHashes hashes = mock(FileHashes.class);
- FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes);
+ FileCache cache = new FileCache(tempFolder.newFolder(), hashes, mock(Logger.class));
when(hashes.of(any(File.class))).thenReturn("VWXYZ");
FileCache.Downloader downloader = new FileCache.Downloader() {
@@ -99,7 +95,7 @@ public class FileCacheTest {
public void concurrent_download() throws IOException {
FileHashes hashes = mock(FileHashes.class);
when(hashes.of(any(File.class))).thenReturn("ABCDE");
- final FileCache cache = new FileCache(tempFolder.newFolder(), log, hashes);
+ final FileCache cache = new FileCache(tempFolder.newFolder(), hashes, mock(Logger.class));
FileCache.Downloader downloader = new FileCache.Downloader() {
public void download(String filename, File toFile) throws IOException {
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 33418cd75ca..78efe696695 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
@@ -19,31 +19,30 @@
*/
package org.sonar.home.cache;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assume.*;
-
import java.nio.file.Files;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+import static org.mockito.Mockito.mock;
+
public class PersistentCacheBuilderTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Test
public void user_home_property_can_be_null() {
- PersistentCache cache = new PersistentCacheBuilder().setSonarHome(null).build();
+ PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(null).build();
assertTrue(Files.isDirectory(cache.getBaseDirectory()));
assertThat(cache.getBaseDirectory().getFileName().toString()).isEqualTo("ws_cache");
}
@Test
public void set_user_home() {
- PersistentCache cache = new PersistentCacheBuilder().setSonarHome(temp.getRoot().toPath()).build();
+ PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(temp.getRoot().toPath()).build();
assertThat(cache.getBaseDirectory().getParent().toString()).isEqualTo(temp.getRoot().toPath().toString());
assertTrue(Files.isDirectory(cache.getBaseDirectory()));
@@ -52,10 +51,10 @@ public class PersistentCacheBuilderTest {
@Test
public void read_system_env() {
assumeTrue(System.getenv("SONAR_USER_HOME") == null);
-
+
System.setProperty("user.home", temp.getRoot().getAbsolutePath());
- PersistentCache cache = new PersistentCacheBuilder().build();
+ PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).build();
assertTrue(Files.isDirectory(cache.getBaseDirectory()));
assertThat(cache.getBaseDirectory().getFileName().toString()).isEqualTo("ws_cache");
diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
index e9abb0bc609..09335dffc3b 100644
--- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
+++ b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java
@@ -19,21 +19,18 @@
*/
package org.sonar.home.cache;
+import java.io.File;
+import java.util.concurrent.Callable;
import org.apache.commons.io.FileUtils;
-
-import org.sonar.home.log.Slf4jLog;
+import org.junit.Before;
import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import java.io.File;
-import java.util.concurrent.Callable;
-
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.mock;
import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Before;
-import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PersistentCacheTest {
private final static String URI = "key1";
@@ -43,11 +40,9 @@ public class PersistentCacheTest {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
- private Slf4jLog log = new Slf4jLog(FileCacheTest.class);
-
@Before
public void setUp() {
- cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, log, false);
+ cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, false, mock(Logger.class));
}
@Test
@@ -85,20 +80,20 @@ public class PersistentCacheTest {
@Test
public void testForceUpdate() throws Exception {
- cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, log, true);
+ cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, true, mock(Logger.class));
assertCacheHit(false);
assertCacheHit(false);
assertCacheHit(false);
// with forceUpdate, it should still have cached the last call
- cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, log, false);
+ cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, false, mock(Logger.class));
assertCacheHit(true);
}
@Test
public void testReconfigure() throws Exception {
- cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, log, true);
+ cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, true, mock(Logger.class));
assertCacheHit(false);
assertCacheHit(false);
@@ -116,7 +111,7 @@ public class PersistentCacheTest {
@Test
public void testExpiration() throws Exception {
// negative time to make sure it is expired on the second call
- cache = new PersistentCache(tmp.getRoot().toPath(), -100, log, false);
+ cache = new PersistentCache(tmp.getRoot().toPath(), -100, false, mock(Logger.class));
assertCacheHit(false);
assertCacheHit(false);
}