diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-12 14:05:13 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-12 16:12:50 +0200 |
commit | 91c3bee035b2fe4249dca9f953f1a4b0e1b5474a (patch) | |
tree | 9ecd829abd598fc58f8a8507e24126964b479249 /sonar-batch | |
parent | dd2c4c54c3d18939cdf92d86ce6a1576768bd567 (diff) | |
download | sonarqube-91c3bee035b2fe4249dca9f953f1a4b0e1b5474a.tar.gz sonarqube-91c3bee035b2fe4249dca9f953f1a4b0e1b5474a.zip |
SONAR-6777 Project cache sync
Diffstat (limited to 'sonar-batch')
26 files changed, 218 insertions, 148 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java index ee0c94cefd9..a4341c96fe2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java @@ -49,11 +49,11 @@ public class GlobalMode { issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode); if (preview) { - LOG.info("Preview global mode"); + LOG.debug("Preview global mode"); } else if (issues) { - LOG.info("Issues global mode"); + LOG.debug("Issues global mode"); } else { - LOG.info("Publish global mode"); + LOG.debug("Publish global mode"); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java index 9f0c0f4250a..47b0d2dfd32 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.cache; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.mutable.MutableBoolean; +import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.log.Loggers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +67,6 @@ public class ProjectCacheSynchronizer { } public void load(boolean force) { - Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class)); Date lastSync = cacheStatus.getSyncStatus(project.getKeyWithBranch()); if (lastSync != null) { @@ -74,43 +74,50 @@ public class ProjectCacheSynchronizer { LOG.info("Found project [{}] cache [{}]", project.getKeyWithBranch(), lastSync); return; } else { - LOG.info("Found project [{}] cache [{}], refreshing data..", project.getKeyWithBranch(), lastSync); + LOG.info("-- Found project [{}] cache [{}], synchronizing data..", project.getKeyWithBranch(), lastSync); } cacheStatus.delete(project.getKeyWithBranch()); } else { - LOG.info("Cache for project [{}] not found, fetching data..", project.getKeyWithBranch()); + LOG.info("-- Cache for project [{}] not found, synchronizing data..", project.getKeyWithBranch()); } + loadData(); + saveStatus(); + } + + private void saveStatus() { + cacheStatus.save(project.getKeyWithBranch()); + LOG.info("-- Succesfully synchronized project cache"); + } + + private static String getComponentKey(String moduleKey, String filePath) { + return moduleKey + ":" + filePath; + } + + private void loadData() { + Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class)); profiler.startInfo("Load project repository"); - ProjectRepositories projectRepo = projectRepositoryLoader.load(project, properties); - profiler.stopInfo(projectRepositoryLoader.loadedFromCache()); + MutableBoolean fromCache = new MutableBoolean(); + ProjectRepositories projectRepo = projectRepositoryLoader.load(project, properties, fromCache); + profiler.stopInfo(fromCache.booleanValue()); if (projectRepo.lastAnalysisDate() == null) { LOG.debug("No previous analysis found"); - LOG.info("Succesfully synchronized project cache"); return; } profiler.startInfo("Load server issues"); UserLoginAccumulator consumer = new UserLoginAccumulator(); - boolean fromCache = issuesLoader.load(project.getKeyWithBranch(), consumer); - profiler.stopInfo(fromCache); + boolean isFromCache = issuesLoader.load(project.getKeyWithBranch(), consumer); + profiler.stopInfo(isFromCache); profiler.startInfo("Load user information (" + consumer.loginSet.size() + " users)"); for (String login : consumer.loginSet) { - userRepository.load(login); + userRepository.load(login, null); } - stopInfo(profiler, "Load user information", fromCache); + stopInfo(profiler, "Load user information", isFromCache); loadLineHashes(projectRepo.fileDataByModuleAndPath(), profiler); - - cacheStatus.save(project.getKeyWithBranch()); - - LOG.info("Succesfully synchronized project cache"); - } - - private String getComponentKey(String moduleKey, String filePath) { - return moduleKey + ":" + filePath; } private void loadLineHashes(Map<String, Map<String, FileData>> fileDataByModuleAndPath, Profiler profiler) { @@ -127,7 +134,7 @@ public class ProjectCacheSynchronizer { for (Entry<String, FileData> e2 : e1.getValue().entrySet()) { String filePath = e2.getKey(); - lineHashesLoader.getLineHashes(getComponentKey(moduleKey, filePath)); + lineHashesLoader.getLineHashes(getComponentKey(moduleKey, filePath), null); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractServerLoader.java b/sonar-batch/src/main/java/org/sonar/batch/cache/package-info.java index d7883e74b9a..1efcd136516 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractServerLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cache/package-info.java @@ -17,15 +17,7 @@ * 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.bootstrap; +@ParametersAreNonnullByDefault +package org.sonar.batch.cache; -public class AbstractServerLoader { - protected Boolean loadedFromCache = null; - - public boolean loadedFromCache() { - if (loadedFromCache == null) { - throw new IllegalStateException("Didn't load"); - } - return loadedFromCache; - } -} +import javax.annotation.ParametersAreNonnullByDefault;
\ No newline at end of file diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java index c6a405d0d36..411651dc990 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java @@ -19,8 +19,11 @@ */ package org.sonar.batch.issue.tracking; -import org.sonar.batch.bootstrap.WSLoaderResult; +import org.apache.commons.lang.mutable.MutableBoolean; + +import javax.annotation.Nullable; +import org.sonar.batch.bootstrap.WSLoaderResult; import org.sonar.batch.util.BatchUtils; import org.sonar.batch.bootstrap.WSLoader; import com.google.common.base.Splitter; @@ -37,17 +40,20 @@ public class DefaultServerLineHashesLoader implements ServerLineHashesLoader { } @Override - public String[] getLineHashes(String fileKey) { - String hashesFromWs = loadHashesFromWs(fileKey); + public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) { + String hashesFromWs = loadHashesFromWs(fileKey, fromCache); return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class); } - private String loadHashesFromWs(String fileKey) { + private String loadHashesFromWs(String fileKey, @Nullable MutableBoolean fromCache) { Profiler profiler = Profiler.createIfDebug(Loggers.get(getClass())) .addContext("file", fileKey) .startDebug("Load line hashes"); WSLoaderResult<String> result = wsLoader.loadString("/api/sources/hash?key=" + BatchUtils.encodeForUrl(fileKey)); try { + if (fromCache != null) { + fromCache.setValue(result.isFromCache()); + } return result.get(); } finally { if (result.isFromCache()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java index f3a69222c79..0928755d76d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java @@ -19,10 +19,14 @@ */ package org.sonar.batch.issue.tracking; +import org.apache.commons.lang.mutable.MutableBoolean; + +import javax.annotation.Nullable; + import org.sonar.api.batch.BatchSide; @BatchSide public interface ServerLineHashesLoader { - String[] getLineHashes(String fileKey); + String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java index 28ed758d9d9..724dd0dde91 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java @@ -49,7 +49,7 @@ public class SourceHashHolder { } else if (status == Status.SAME) { hashedReference = hashedSource; } else { - String[] lineHashes = lastSnapshots.getLineHashes(inputFile.key()); + String[] lineHashes = lastSnapshots.getLineHashes(inputFile.key(), null); hashedReference = lineHashes != null ? FileHashes.create(lineHashes) : null; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java index 4d0a24c772f..a26d110646f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java @@ -19,13 +19,14 @@ */ package org.sonar.batch.repository; -import org.sonar.batch.bootstrap.AbstractServerLoader; +import javax.annotation.Nullable; +import org.apache.commons.lang.mutable.MutableBoolean; import org.sonar.batch.bootstrap.WSLoaderResult; import org.sonar.batch.bootstrap.WSLoader; import org.sonar.batch.protocol.input.GlobalRepositories; -public class DefaultGlobalRepositoriesLoader extends AbstractServerLoader implements GlobalRepositoriesLoader { +public class DefaultGlobalRepositoriesLoader implements GlobalRepositoriesLoader { private static final String BATCH_GLOBAL_URL = "/batch/global"; @@ -36,10 +37,11 @@ public class DefaultGlobalRepositoriesLoader extends AbstractServerLoader implem } @Override - public GlobalRepositories load() { + public GlobalRepositories load(@Nullable MutableBoolean fromCache) { WSLoaderResult<String> result = wsLoader.loadString(BATCH_GLOBAL_URL); - super.loadedFromCache = result.isFromCache(); + if (fromCache != null) { + fromCache.setValue(result.isFromCache()); + } return GlobalRepositories.fromJson(result.get()); } - } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java index 45b85452929..4481de42aec 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java @@ -19,10 +19,11 @@ */ package org.sonar.batch.repository; -import org.sonar.batch.scan.ProjectAnalysisMode; +import javax.annotation.Nullable; +import org.apache.commons.lang.mutable.MutableBoolean; +import org.sonar.batch.scan.ProjectAnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.batch.bootstrap.AbstractServerLoader; import org.sonar.batch.bootstrap.WSLoaderResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +34,7 @@ import org.sonar.batch.protocol.input.ProjectRepositories; import org.sonar.batch.rule.ModuleQProfiles; import org.sonar.batch.util.BatchUtils; -public class DefaultProjectRepositoriesLoader extends AbstractServerLoader implements ProjectRepositoriesLoader { +public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoader { private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectRepositoriesLoader.class); private static final String BATCH_PROJECT_URL = "/batch/project"; @@ -47,7 +48,7 @@ public class DefaultProjectRepositoriesLoader extends AbstractServerLoader imple } @Override - public ProjectRepositories load(ProjectDefinition projectDefinition, AnalysisProperties taskProperties) { + public ProjectRepositories load(ProjectDefinition projectDefinition, AnalysisProperties taskProperties, @Nullable MutableBoolean fromCache) { String projectKey = projectDefinition.getKeyWithBranch(); String url = BATCH_PROJECT_URL + "?key=" + BatchUtils.encodeForUrl(projectKey); if (taskProperties.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) { @@ -56,15 +57,18 @@ public class DefaultProjectRepositoriesLoader extends AbstractServerLoader imple url += "&profile=" + BatchUtils.encodeForUrl(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP)); } url += "&preview=" + analysisMode.isIssues(); - ProjectRepositories projectRepositories = ProjectRepositories.fromJson(load(url)); + + ProjectRepositories projectRepositories = load(url, fromCache); validateProjectRepositories(projectRepositories); return projectRepositories; } - private String load(String resource) { + private ProjectRepositories load(String resource, @Nullable MutableBoolean fromCache) { WSLoaderResult<String> result = wsLoader.loadString(resource); - super.loadedFromCache = result.isFromCache(); - return result.get(); + if(fromCache != null) { + fromCache.setValue(result.isFromCache()); + } + return ProjectRepositories.fromJson(result.get()); } private static void validateProjectRepositories(ProjectRepositories projectRepositories) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java index d0d88161c45..98ec5bbc18c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java @@ -19,12 +19,14 @@ */ package org.sonar.batch.repository; +import org.apache.commons.lang.mutable.MutableBoolean; + +import javax.annotation.Nullable; + import org.sonar.batch.protocol.input.GlobalRepositories; public interface GlobalRepositoriesLoader { - GlobalRepositories load(); - - boolean loadedFromCache(); + GlobalRepositories load(@Nullable MutableBoolean fromCache); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java index bad8be3dcde..a8ba268f98c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.repository; +import org.apache.commons.lang.mutable.MutableBoolean; + import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -34,8 +36,9 @@ public class GlobalRepositoriesProvider extends ProviderAdapter { public GlobalRepositories provide(GlobalRepositoriesLoader loader) { if (globalReferentials == null) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - globalReferentials = loader.load(); - profiler.stopInfo(loader.loadedFromCache()); + MutableBoolean fromCache = new MutableBoolean(); + globalReferentials = loader.load(fromCache); + profiler.stopInfo(fromCache.booleanValue()); } return globalReferentials; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java index dfb3b741202..e0f120f503c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java @@ -19,15 +19,15 @@ */ package org.sonar.batch.repository; -import org.sonar.api.batch.bootstrap.ProjectDefinition; +import javax.annotation.Nullable; +import org.apache.commons.lang.mutable.MutableBoolean; +import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.batch.bootstrap.AnalysisProperties; import org.sonar.batch.protocol.input.ProjectRepositories; public interface ProjectRepositoriesLoader { - ProjectRepositories load(ProjectDefinition projectDefinition, AnalysisProperties taskProperties); - - boolean loadedFromCache(); + ProjectRepositories load(ProjectDefinition projectDefinition, AnalysisProperties taskProperties, @Nullable MutableBoolean fromCache); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java index adf4e8b1d30..34c4f14f0e0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.repository; +import org.apache.commons.lang.mutable.MutableBoolean; + import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectReactor; @@ -38,8 +40,9 @@ public class ProjectRepositoriesProvider extends ProviderAdapter { public ProjectRepositories provide(ProjectRepositoriesLoader loader, ProjectReactor reactor, AnalysisProperties taskProps, AnalysisMode analysisMode) { if (projectReferentials == null) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - projectReferentials = loader.load(reactor.getRoot(), taskProps); - profiler.stopInfo(loader.loadedFromCache()); + MutableBoolean fromCache = new MutableBoolean(); + projectReferentials = loader.load(reactor.getRoot(), taskProps, fromCache); + profiler.stopInfo(fromCache.booleanValue()); if (analysisMode.isIssues() && projectReferentials.lastAnalysisDate() == null) { LOG.warn("No analysis has been found on the server for this project. All issues will be marked as 'new'."); diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java index a6193dc278a..82e8ec1b991 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java @@ -19,10 +19,11 @@ */ package org.sonar.batch.repository.user; -import com.google.common.collect.Lists; +import javax.annotation.Nullable; +import org.apache.commons.lang.mutable.MutableBoolean; +import com.google.common.collect.Lists; import com.google.common.base.Joiner; -import org.sonar.batch.bootstrap.AbstractServerLoader; import org.sonar.batch.bootstrap.WSLoaderResult; import org.sonar.batch.util.BatchUtils; import org.sonar.batch.bootstrap.WSLoader; @@ -37,7 +38,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -public class UserRepositoryLoader extends AbstractServerLoader { +public class UserRepositoryLoader { private final WSLoader wsLoader; public UserRepositoryLoader(WSLoader wsLoader) { @@ -45,25 +46,35 @@ public class UserRepositoryLoader extends AbstractServerLoader { } public BatchInput.User load(String userLogin) { - ByteSource byteSource = loadQuery(new UserEncodingFunction().apply(userLogin)); + return load(userLogin, null); + } + + public BatchInput.User load(String userLogin, @Nullable MutableBoolean fromCache) { + ByteSource byteSource = loadQuery(new UserEncodingFunction().apply(userLogin), fromCache); return parseUser(byteSource); } + public Collection<BatchInput.User> load(List<String> userLogins) { + return load(userLogins, null); + } + /** * Not cache friendly. Should not be used if a cache hit is expected. */ - public Collection<BatchInput.User> load(List<String> userLogins) { + public Collection<BatchInput.User> load(List<String> userLogins, @Nullable MutableBoolean fromCache) { if (userLogins.isEmpty()) { return Collections.emptyList(); } - ByteSource byteSource = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction()))); + ByteSource byteSource = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction())), fromCache); return parseUsers(byteSource); } - private ByteSource loadQuery(String loginsQuery) { + private ByteSource loadQuery(String loginsQuery, @Nullable MutableBoolean fromCache) { WSLoaderResult<ByteSource> result = wsLoader.loadSource("/batch/users?logins=" + loginsQuery); - super.loadedFromCache = result.isFromCache(); + if (fromCache != null) { + fromCache.setValue(result.isFromCache()); + } return result.get(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java index ae4492bed7b..8837e326946 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.rule; -import org.sonar.batch.bootstrap.AbstractServerLoader; +import javax.annotation.Nullable; +import org.apache.commons.lang.mutable.MutableBoolean; import org.sonar.batch.bootstrap.WSLoaderResult; import org.sonarqube.ws.Rules.ListResponse.Rule; import com.google.common.io.ByteSource; @@ -32,7 +33,7 @@ import java.util.List; import org.sonar.batch.bootstrap.WSLoader; -public class DefaultRulesLoader extends AbstractServerLoader implements RulesLoader { +public class DefaultRulesLoader implements RulesLoader { private static final String RULES_SEARCH_URL = "/api/rules/list"; private final WSLoader wsLoader; @@ -42,10 +43,12 @@ public class DefaultRulesLoader extends AbstractServerLoader implements RulesLoa } @Override - public List<Rule> load() { + public List<Rule> load(@Nullable MutableBoolean fromCache) { WSLoaderResult<ByteSource> result = wsLoader.loadSource(RULES_SEARCH_URL); ListResponse list = loadFromSource(result.get()); - super.loadedFromCache = result.isFromCache(); + if (fromCache != null) { + fromCache.setValue(result.isFromCache()); + } return list.getRulesList(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java index 1e0c5df7cff..e470ce72b8e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesLoader.java @@ -19,12 +19,12 @@ */ package org.sonar.batch.rule; +import org.apache.commons.lang.mutable.MutableBoolean; + import java.util.List; import org.sonarqube.ws.Rules.ListResponse.Rule; public interface RulesLoader { - List<Rule> load(); - - boolean loadedFromCache(); + List<Rule> load(MutableBoolean fromCache); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java index 866bcdcb73b..068eb06c416 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java @@ -19,9 +19,10 @@ */ package org.sonar.batch.rule; +import org.apache.commons.lang.mutable.MutableBoolean; + import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; - import org.sonar.api.utils.log.Profiler; import java.util.List; @@ -47,7 +48,8 @@ public class RulesProvider extends ProviderAdapter { private static Rules load(RulesLoader ref) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); - List<Rule> loadedRules = ref.load(); + MutableBoolean fromCache = new MutableBoolean(); + List<Rule> loadedRules = ref.load(fromCache); RulesBuilder builder = new RulesBuilder(); for (Rule r : loadedRules) { @@ -56,7 +58,7 @@ public class RulesProvider extends ProviderAdapter { newRule.setInternalKey(r.getInternalKey()); } - profiler.stopInfo(ref.loadedFromCache()); + profiler.stopInfo(fromCache.booleanValue()); return builder.build(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java index 4c66441218b..58f9b1ccc1d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectAnalysisMode.java @@ -83,7 +83,9 @@ public class ProjectAnalysisMode implements AnalysisMode { preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode); issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode); mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED)); - + } + + public void printMode() { if (preview) { LOG.info("Preview mode"); } else if (issues) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index 6ab4474292a..508af5d6b52 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -19,8 +19,6 @@ */ package org.sonar.batch.scan; -import org.sonar.batch.cache.ProjectSyncContainer; - import org.sonar.batch.repository.user.UserRepositoryLoader; import org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader; import org.sonar.batch.issue.tracking.ServerLineHashesLoader; @@ -126,13 +124,6 @@ public class ProjectScanContainer extends ComponentContainer { return env != null && "SonarRunner".equals(env.getKey()); } - private void doProjectSync() { - ProjectAnalysisMode mode = getComponentByType(ProjectAnalysisMode.class); - if (mode.isIssues()) { - new ProjectSyncContainer(getParent(), props, false).execute(); - } - } - private void addBatchComponents() { add( props, @@ -223,10 +214,12 @@ public class ProjectScanContainer extends ComponentContainer { @Override protected void doAfterStart() { + ProjectAnalysisMode analysisMode = getComponentByType(ProjectAnalysisMode.class); + analysisMode.printMode(); LOG.debug("Start recursive analysis of project modules"); DefaultProjectTree tree = getComponentByType(DefaultProjectTree.class); scanRecursively(tree.getRootProject()); - if (getComponentByType(ProjectAnalysisMode.class).isMediumTest()) { + if (analysisMode.isMediumTest()) { getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask(); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java index 3cf688897f0..e6bf23eb04e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java @@ -20,6 +20,10 @@ package org.sonar.batch.cache; import static org.mockito.Mockito.when; + +import org.sonar.batch.protocol.input.ProjectRepositories; + +import org.apache.commons.lang.mutable.MutableBoolean; import org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader; import org.sonar.batch.repository.DefaultServerIssuesLoader; import org.sonar.batch.scan.ProjectAnalysisMode; @@ -35,8 +39,9 @@ import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.HashMap; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Matchers.anyString; - import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import com.google.common.io.Resources; @@ -75,6 +80,8 @@ public class ProjectCacheSynchronizerTest { private ServerLineHashesLoader lineHashesLoader; private UserRepositoryLoader userRepositoryLoader; + private ProjectCacheSynchronizer sync; + @Before public void setUp() throws IOException { MockitoAnnotations.initMocks(this); @@ -98,12 +105,13 @@ public class ProjectCacheSynchronizerTest { issuesLoader = new DefaultServerIssuesLoader(ws); lineHashesLoader = new DefaultServerLineHashesLoader(ws); userRepositoryLoader = new UserRepositoryLoader(ws); + + sync = new ProjectCacheSynchronizer(projectReactor, projectRepositoryLoader, properties, issuesLoader, lineHashesLoader, userRepositoryLoader, + cacheStatus); } @Test public void testSync() { - ProjectCacheSynchronizer sync = new ProjectCacheSynchronizer(projectReactor, projectRepositoryLoader, properties, issuesLoader, lineHashesLoader, userRepositoryLoader, - cacheStatus); sync.load(false); verify(ws).loadString(BATCH_PROJECT); @@ -116,6 +124,20 @@ public class ProjectCacheSynchronizerTest { } @Test + public void testSyncNoLastAnalysis() { + projectRepositoryLoader = mock(DefaultProjectRepositoriesLoader.class); + ProjectRepositories mockedProjectRepositories = mock(ProjectRepositories.class); + when(mockedProjectRepositories.lastAnalysisDate()).thenReturn(null); + when(projectRepositoryLoader.load(any(ProjectDefinition.class), any(AnalysisProperties.class), any(MutableBoolean.class))).thenReturn(mockedProjectRepositories); + + sync = new ProjectCacheSynchronizer(projectReactor, projectRepositoryLoader, properties, issuesLoader, lineHashesLoader, userRepositoryLoader, + cacheStatus); + sync.load(true); + + verify(cacheStatus).save("org.codehaus.sonar-plugins:sonar-scm-git-plugin"); + } + + @Test public void testDontSyncIfNotForce() { when(cacheStatus.getSyncStatus("org.codehaus.sonar-plugins:sonar-scm-git-plugin")).thenReturn(new Date()); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java index c7e2a40c04e..f788788fef1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.issue.tracking; -import org.sonar.batch.bootstrap.WSLoaderResult; +import org.apache.commons.lang.mutable.MutableBoolean; +import org.sonar.batch.bootstrap.WSLoaderResult; import org.sonar.batch.bootstrap.WSLoader; import org.junit.Before; import org.junit.Rule; @@ -53,7 +54,7 @@ public class DefaultServerLineHashesLoaderTest { ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsLoader); - String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c"); + String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c", null); assertThat(hashes).containsOnly("ae12", "", "43fb"); verify(wsLoader).loadString("/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FBar.c"); } @@ -65,7 +66,9 @@ public class DefaultServerLineHashesLoaderTest { ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server); - String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c"); + MutableBoolean fromCache = new MutableBoolean(); + String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c", fromCache); + assertThat(fromCache.booleanValue()).isTrue(); assertThat(hashes).containsOnly("ae12", "", "43fb"); verify(server).loadString("/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FFoo+Bar.c"); } @@ -78,7 +81,7 @@ public class DefaultServerLineHashesLoaderTest { ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server); thrown.expect(HttpDownloader.HttpException.class); - lastSnapshots.getLineHashes("foo"); + lastSnapshots.getLineHashes("foo", null); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java index cdb7324ae2a..ed62cd0ee95 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java @@ -83,10 +83,10 @@ public class SourceHashHolderTest { FileUtils.write(ioFile, source, StandardCharsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.CHANGED); - when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)}); + when(lastSnapshots.getLineHashes(key, null)).thenReturn(new String[] {md5Hex(source)}); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); - verify(lastSnapshots).getLineHashes(key); + verify(lastSnapshots).getLineHashes(key, null); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); Mockito.verifyNoMoreInteractions(lastSnapshots); diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java index b4a80af70db..9ff6e0a55d7 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -19,6 +19,10 @@ */ package org.sonar.batch.mediumtest; +import org.apache.commons.lang.mutable.MutableBoolean; + +import javax.annotation.Nullable; + import org.sonar.batch.cache.ProjectCacheStatus; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonarqube.ws.Rules.ListResponse.Rule; @@ -294,14 +298,9 @@ public class BatchMediumTester { } @Override - public List<Rule> load() { + public List<Rule> load(@Nullable MutableBoolean fromCache) { return rules; } - - @Override - public boolean loadedFromCache() { - return false; - } } private static class FakeGlobalRepositoriesLoader implements GlobalRepositoriesLoader { @@ -311,7 +310,7 @@ public class BatchMediumTester { private GlobalRepositories ref = new GlobalRepositories(); @Override - public GlobalRepositories load() { + public GlobalRepositories load(@Nullable MutableBoolean fromCache) { return ref; } @@ -336,10 +335,6 @@ public class BatchMediumTester { return this; } - @Override - public boolean loadedFromCache() { - return false; - } } private static class FakeProjectRepositoriesLoader implements ProjectRepositoriesLoader { @@ -347,7 +342,7 @@ public class BatchMediumTester { private ProjectRepositories ref = new ProjectRepositories(); @Override - public ProjectRepositories load(ProjectDefinition projDefinition, AnalysisProperties taskProperties) { + public ProjectRepositories load(ProjectDefinition projDefinition, AnalysisProperties taskProperties, @Nullable MutableBoolean fromCache) { return ref; } @@ -372,10 +367,6 @@ public class BatchMediumTester { return this; } - @Override - public boolean loadedFromCache() { - return true; - } } private static class FakeServerIssuesLoader implements ServerIssuesLoader { @@ -417,7 +408,7 @@ public class BatchMediumTester { private Map<String, String[]> byKey = new HashMap<>(); @Override - public String[] getLineHashes(String fileKey) { + public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) { if (byKey.containsKey(fileKey)) { return byKey.get(fileKey); } else { diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java index 5e846897aa4..9a1f8abea46 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java @@ -19,8 +19,9 @@ */ package org.sonar.batch.repository; -import org.sonar.batch.scan.ProjectAnalysisMode; +import org.apache.commons.lang.mutable.MutableBoolean; +import org.sonar.batch.scan.ProjectAnalysisMode; import org.apache.commons.io.IOUtils; import org.sonar.batch.bootstrap.WSLoaderResult; import com.google.common.collect.Maps; @@ -72,11 +73,11 @@ public class DefaultProjectRepositoriesLoaderTest { addQualityProfile(); project = ProjectDefinition.create().setKey("foo"); when(analysisMode.isIssues()).thenReturn(false); - loader.load(project, taskProperties); + loader.load(project, taskProperties, null); verify(wsLoader).loadString("/batch/project?key=foo&preview=false"); when(analysisMode.isIssues()).thenReturn(true); - loader.load(project, taskProperties); + loader.load(project, taskProperties, null); verify(wsLoader).loadString("/batch/project?key=foo&preview=true"); } @@ -84,10 +85,12 @@ public class DefaultProjectRepositoriesLoaderTest { public void deserializeResponse() throws IOException { String resourceName = this.getClass().getSimpleName() + "/sample_response.json"; String response = IOUtils.toString(this.getClass().getResourceAsStream(resourceName)); - when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>(response, false)); + when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>(response, true)); project = ProjectDefinition.create().setKey("foo"); - ProjectRepositories projectRepo = loader.load(project, taskProperties); + MutableBoolean fromCache = new MutableBoolean(); + ProjectRepositories projectRepo = loader.load(project, taskProperties, fromCache); + assertThat(fromCache.booleanValue()).isTrue(); assertThat(projectRepo.activeRules().size()).isEqualTo(221); assertThat(projectRepo.fileDataByPath("my:project").size()).isEqualTo(11); @@ -97,7 +100,7 @@ public class DefaultProjectRepositoriesLoaderTest { public void passAndEncodeProjectKeyParameter() { addQualityProfile(); project = ProjectDefinition.create().setKey("foo bàr"); - loader.load(project, taskProperties); + loader.load(project, taskProperties, null); verify(wsLoader).loadString("/batch/project?key=foo+b%C3%A0r&preview=false"); } @@ -106,7 +109,7 @@ public class DefaultProjectRepositoriesLoaderTest { addQualityProfile(); project = ProjectDefinition.create().setKey("foo"); taskProperties.properties().put(ModuleQProfiles.SONAR_PROFILE_PROP, "my-profile#2"); - loader.load(project, taskProperties); + loader.load(project, taskProperties, null); verify(wsLoader).loadString("/batch/project?key=foo&profile=my-profile%232&preview=false"); } @@ -118,7 +121,7 @@ public class DefaultProjectRepositoriesLoaderTest { project = ProjectDefinition.create().setKey("foo"); when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>(new ProjectRepositories().toJson(), true)); - loader.load(project, taskProperties); + loader.load(project, taskProperties, null); } private void addQualityProfile() { diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java index 8f583afba41..1b17e6445c6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java @@ -19,8 +19,11 @@ */ package org.sonar.batch.repository.user; -import com.google.common.collect.ImmutableMap; +import org.junit.Before; +import com.google.common.collect.ImmutableList; +import org.apache.commons.lang.mutable.MutableBoolean; +import com.google.common.collect.ImmutableMap; import org.junit.rules.ExpectedException; import org.junit.Rule; import org.mockito.Mockito; @@ -37,6 +40,7 @@ import java.io.InputStream; import java.util.Arrays; import java.util.Map; +import static org.mockito.Matchers.anyString; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; @@ -46,11 +50,17 @@ public class UserRepositoryLoaderTest { @Rule public final ExpectedException exception = ExpectedException.none(); + private WSLoader wsLoader; + private UserRepositoryLoader userRepo; + + @Before + public void setUp() { + wsLoader = mock(WSLoader.class); + userRepo = new UserRepositoryLoader(wsLoader); + } + @Test public void testLoad() throws IOException { - WSLoader wsLoader = mock(WSLoader.class); - UserRepositoryLoader userRepo = new UserRepositoryLoader(wsLoader); - Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon"); WSLoaderResult<ByteSource> res = new WSLoaderResult<>(createUsersMock(userMap), true); when(wsLoader.loadSource("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res); @@ -59,10 +69,20 @@ public class UserRepositoryLoaderTest { } @Test - public void testLoadSingleUser() throws IOException { - WSLoader wsLoader = mock(WSLoader.class); - UserRepositoryLoader userRepo = new UserRepositoryLoader(wsLoader); + public void testFromCache() throws IOException { + WSLoaderResult<ByteSource> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true); + when(wsLoader.loadSource(anyString())).thenReturn(res); + MutableBoolean fromCache = new MutableBoolean(); + userRepo.load("", fromCache); + assertThat(fromCache.booleanValue()).isTrue(); + + fromCache.setValue(false); + userRepo.load(ImmutableList.of("user"), fromCache); + assertThat(fromCache.booleanValue()).isTrue(); + } + @Test + public void testLoadSingleUser() throws IOException { WSLoaderResult<ByteSource> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true); when(wsLoader.loadSource("/batch/users?logins=fmallet")).thenReturn(res); @@ -83,8 +103,6 @@ public class UserRepositoryLoaderTest { @Test public void testInputStreamError() throws IOException { - WSLoader wsLoader = mock(WSLoader.class); - UserRepositoryLoader userRepo = new UserRepositoryLoader(wsLoader); ByteSource source = mock(ByteSource.class); WSLoaderResult<ByteSource> res = new WSLoaderResult<>(source, true); diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java index bd1a2e65da9..4456d5b3cb0 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java @@ -22,8 +22,9 @@ package org.sonar.batch.rule; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.sonar.batch.bootstrap.WSLoaderResult; +import org.apache.commons.lang.mutable.MutableBoolean; +import org.sonar.batch.bootstrap.WSLoaderResult; import org.sonarqube.ws.Rules.ListResponse.Rule; import com.google.common.io.ByteSource; import com.google.common.io.Resources; @@ -43,7 +44,7 @@ public class DefaultRulesLoaderTest { ByteSource source = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")); when(wsLoader.loadSource(anyString())).thenReturn(new WSLoaderResult<>(source, true)); DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader); - List<Rule> ruleList = loader.load(); + List<Rule> ruleList = loader.load(null); assertThat(ruleList).hasSize(318); } @@ -53,14 +54,10 @@ public class DefaultRulesLoaderTest { ByteSource source = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")); when(wsLoader.loadSource(anyString())).thenReturn(new WSLoaderResult<>(source, true)); DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader); - loader.load(); + MutableBoolean fromCache = new MutableBoolean(); + loader.load(fromCache); - assertThat(loader.loadedFromCache()).isTrue(); + assertThat(fromCache.booleanValue()).isTrue(); } - @Test(expected = IllegalStateException.class) - public void testGetLoadedFromCacheBefore() { - DefaultRulesLoader loader = new DefaultRulesLoader(mock(WSLoader.class)); - loader.loadedFromCache(); - } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java index 3e43363d5f9..cf48e62aafc 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java @@ -19,10 +19,12 @@ */ package org.sonar.batch.rule; -import com.google.common.collect.Lists; +import static org.mockito.Matchers.any; -import org.sonar.api.batch.rule.Rules; +import org.apache.commons.lang.mutable.MutableBoolean; +import com.google.common.collect.Lists; +import org.sonar.api.batch.rule.Rules; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; import static org.mockito.Mockito.mock; @@ -33,7 +35,7 @@ public class RulesProviderTest { @Test public void testRuleTranslation() { RulesLoader loader = mock(RulesLoader.class); - when(loader.load()).thenReturn(Lists.newArrayList(getTestRule())); + when(loader.load(any(MutableBoolean.class))).thenReturn(Lists.newArrayList(getTestRule())); RulesProvider provider = new RulesProvider(); |