aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-05-13 10:35:18 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-05-13 15:03:56 +0200
commit35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9 (patch)
tree36655ed02200f6a120b2c3d2ddf435315efcf110 /sonar-scanner-engine/src
parent1d0523368d43ccf4bef67ee9918a84419b4073b7 (diff)
downloadsonarqube-35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9.tar.gz
sonarqube-35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9.zip
SONAR-7367 Remove code previously used by SonarLint
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java49
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java15
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java21
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java28
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java80
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java55
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java96
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java30
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java185
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java36
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java67
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java93
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java41
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoader.java240
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java41
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java23
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java43
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java30
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java23
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java28
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java18
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java20
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java37
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java6
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java14
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java22
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java23
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesLoader.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProvider.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java15
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java3
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/task/ScanTask.java23
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java96
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java62
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java33
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java91
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java83
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java93
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java197
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java80
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java52
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java59
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java264
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java44
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java36
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java155
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java89
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java51
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java58
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java39
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java14
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java34
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java39
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java41
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java12
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java29
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java36
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java31
-rw-r--r--sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo16
-rw-r--r--sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo12
-rw-r--r--sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo12
-rw-r--r--sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo12
-rw-r--r--sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties31
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobufbin27390 -> 0 bytes
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobufbin788 -> 0 bytes
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json164
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf0
82 files changed, 408 insertions, 3152 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java
deleted file mode 100644
index 54ce6e112a3..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.analysis;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.AnalysisMode;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-
-public class AnalysisWSLoaderProvider extends ProviderAdapter {
- static final String SONAR_USE_WS_CACHE = "sonar.useWsCache";
- private WSLoader wsLoader;
-
- public WSLoader provide(AnalysisMode mode, PersistentCache cache, BatchWsClient client, AnalysisProperties props) {
- if (wsLoader == null) {
- // recreate cache directory if needed for this analysis
- cache.reconfigure();
- wsLoader = new WSLoader(getStrategy(mode, props), cache, client);
- }
- return wsLoader;
- }
-
- private static LoadStrategy getStrategy(AnalysisMode mode, AnalysisProperties props) {
- if (mode.isIssues() && "true".equals(props.property(SONAR_USE_WS_CACHE))) {
- return LoadStrategy.CACHE_ONLY;
- }
-
- return LoadStrategy.SERVER_ONLY;
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
index 32a872ed16f..7bd08e9e16d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
@@ -37,7 +37,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
private static final String KEY_SCAN_ALL = "sonar.scanAllFiles";
private boolean mediumTestMode;
- private boolean notAssociated;
private boolean scanAllFiles;
public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props) {
@@ -48,10 +47,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
return mediumTestMode;
}
- public boolean isNotAssociated() {
- return notAssociated;
- }
-
public boolean scanAllFiles() {
return scanAllFiles;
}
@@ -73,7 +68,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
validate(mode);
issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED));
- notAssociated = issues && rootProjectKeyMissing(analysisProps);
String scanAllStr = getPropertyWithFallback(analysisProps, globalProps, KEY_SCAN_ALL);
scanAllFiles = !issues || "true".equals(scanAllStr);
}
@@ -89,9 +83,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
if (mediumTestMode) {
LOG.info("Medium test mode");
}
- if (notAssociated) {
- LOG.info("Local analysis");
- }
if (!scanAllFiles) {
LOG.info("Scanning only changed files");
}
@@ -111,10 +102,4 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
return CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
}
-
- private static boolean rootProjectKeyMissing(Map<String, String> props) {
- // ProjectReactorBuilder depends on this class, so it will only create this property later
- return !props.containsKey(CoreProperties.PROJECT_KEY_PROPERTY);
- }
-
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
index b1dd6aa5843..2a6b64de50d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
@@ -24,19 +24,19 @@ import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Reader;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.RemotePlugin;
import org.sonar.core.platform.RemotePluginFile;
@@ -55,13 +55,11 @@ public class BatchPluginInstaller implements PluginInstaller {
private static final Logger LOG = Loggers.get(BatchPluginInstaller.class);
private static final String PLUGINS_INDEX_URL = "/deploy/plugins/index.txt";
- private final WSLoader wsLoader;
private final FileCache fileCache;
private final BatchPluginPredicate pluginPredicate;
private final BatchWsClient wsClient;
- public BatchPluginInstaller(WSLoader wsLoader, BatchWsClient wsClient, FileCache fileCache, BatchPluginPredicate pluginPredicate) {
- this.wsLoader = wsLoader;
+ public BatchPluginInstaller(BatchWsClient wsClient, FileCache fileCache, BatchPluginPredicate pluginPredicate) {
this.fileCache = fileCache;
this.pluginPredicate = pluginPredicate;
this.wsClient = wsClient;
@@ -129,9 +127,16 @@ public class BatchPluginInstaller implements PluginInstaller {
private String loadPluginIndex() {
Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
- WSLoaderResult<String> wsResult = wsLoader.loadString(PLUGINS_INDEX_URL);
- profiler.stopInfo(wsResult.isFromCache());
- return wsResult.get();
+ GetRequest getRequest = new GetRequest(PLUGINS_INDEX_URL);
+ String str;
+ try (Reader reader = wsClient.call(getRequest).contentReader()) {
+ str = IOUtils.toString(reader);
+ } catch(IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ profiler.stopInfo();
+ return str;
}
private class FileDownloader implements FileCache.Downloader {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index dcc80d2fff5..0578a3b144d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -25,10 +25,6 @@ import org.sonar.api.Plugin;
import org.sonar.api.internal.SonarQubeVersionFactory;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
-import org.sonar.batch.cache.GlobalPersistentCacheProvider;
-import org.sonar.batch.cache.ProjectSyncContainer;
-import org.sonar.batch.cache.StrategyWSLoaderProvider;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
import org.sonar.batch.index.CachesManager;
import org.sonar.batch.platform.DefaultServer;
import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader;
@@ -46,16 +42,14 @@ import org.sonar.core.util.UuidFactoryImpl;
public class GlobalContainer extends ComponentContainer {
private final Map<String, String> bootstrapProperties;
- private boolean preferCache;
- private GlobalContainer(Map<String, String> bootstrapProperties, boolean preferCache) {
+ private GlobalContainer(Map<String, String> bootstrapProperties) {
super();
this.bootstrapProperties = bootstrapProperties;
- this.preferCache = preferCache;
}
- public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions, boolean preferCache) {
- GlobalContainer container = new GlobalContainer(bootstrapProperties, preferCache);
+ public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions) {
+ GlobalContainer container = new GlobalContainer(bootstrapProperties);
container.add(extensions);
return container;
}
@@ -64,22 +58,11 @@ public class GlobalContainer extends ComponentContainer {
protected void doBeforeStart() {
GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties);
GlobalMode globalMode = new GlobalMode(bootstrapProps);
- LoadStrategy strategy = getDataLoadingStrategy(globalMode, preferCache);
- StrategyWSLoaderProvider wsLoaderProvider = new StrategyWSLoaderProvider(strategy);
- add(wsLoaderProvider);
add(bootstrapProps);
add(globalMode);
addBootstrapComponents();
}
- private static LoadStrategy getDataLoadingStrategy(GlobalMode mode, boolean preferCache) {
- if (!mode.isIssues()) {
- return LoadStrategy.SERVER_ONLY;
- }
-
- return preferCache ? LoadStrategy.CACHE_FIRST : LoadStrategy.SERVER_FIRST;
- }
-
private void addBootstrapComponents() {
add(
// plugins
@@ -99,7 +82,6 @@ public class GlobalContainer extends ComponentContainer {
DefaultHttpDownloader.class,
UriReader.class,
new FileCacheProvider(),
- new GlobalPersistentCacheProvider(),
System2.INSTANCE,
new GlobalRepositoriesProvider(),
UuidFactoryImpl.INSTANCE);
@@ -124,8 +106,4 @@ public class GlobalContainer extends ComponentContainer {
new TaskContainer(this, taskProperties, components).execute();
}
- public void syncProject(String projectKey, boolean force) {
- new ProjectSyncContainer(this, projectKey, force).execute();
- }
-
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
index d5d3da13087..5f9ddbfc56f 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
@@ -99,7 +99,7 @@ public final class Batch {
configureLogging();
try {
- bootstrapContainer = GlobalContainer.create(bootstrapProperties, components, preferCache);
+ bootstrapContainer = GlobalContainer.create(bootstrapProperties, components);
bootstrapContainer.startComponents();
} catch (RuntimeException e) {
throw handleException(e);
@@ -159,10 +159,10 @@ public final class Batch {
/**
* @since 5.2
+ * @deprecated since 5.6
*/
public Batch syncProject(String projectKey) {
checkStarted();
- bootstrapContainer.syncProject(projectKey, true);
return this;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
deleted file mode 100644
index 45baaecacc8..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Date;
-import org.sonar.home.cache.PersistentCache;
-
-import static org.sonar.core.util.FileUtils.deleteQuietly;
-
-public class DefaultProjectCacheStatus implements ProjectCacheStatus {
- private static final String STATUS_FILENAME = "cache-sync-status";
- private PersistentCache cache;
-
- public DefaultProjectCacheStatus(PersistentCache cache) {
- this.cache = cache;
- }
-
- @Override
- public void save() {
- Date now = new Date();
-
- try {
- try (ObjectOutputStream objOutput = new ObjectOutputStream(new FileOutputStream(getStatusFilePath().toFile()))) {
- objOutput.writeObject(now);
- }
- } catch (IOException e) {
- throw new IllegalStateException("Failed to write cache sync status", e);
- }
- }
-
- @Override
- public void delete() {
- cache.clear();
- deleteQuietly(getStatusFilePath().toFile());
- }
-
- @Override
- public Date getSyncStatus() {
- Path p = getStatusFilePath();
- try {
- if (!Files.isRegularFile(p)) {
- return null;
- }
- try (ObjectInputStream objInput = new ObjectInputStream(new FileInputStream(p.toFile()))) {
- return (Date) objInput.readObject();
- }
- } catch (IOException | ClassNotFoundException e) {
- deleteQuietly(p.toFile());
- throw new IllegalStateException("Failed to read cache sync status", e);
- }
- }
-
- private Path getStatusFilePath() {
- return cache.getDirectory().resolve(STATUS_FILENAME);
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java
deleted file mode 100644
index 6b8677e2ada..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.apache.commons.lang.StringUtils;
-import org.sonar.batch.bootstrap.Slf4jLogger;
-import org.sonar.home.cache.PersistentCacheBuilder;
-
-import java.nio.file.Paths;
-
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.home.cache.PersistentCache;
-import org.picocontainer.injectors.ProviderAdapter;
-
-public class GlobalPersistentCacheProvider extends ProviderAdapter {
- private PersistentCache cache;
-
- public PersistentCache provide(GlobalProperties props) {
- if (cache == null) {
- PersistentCacheBuilder builder = new PersistentCacheBuilder(new Slf4jLogger());
- String home = props.property("sonar.userHome");
- String serverUrl = getServerUrl(props);
-
- if (home != null) {
- builder.setSonarHome(Paths.get(home));
- }
-
- builder.setAreaForGlobal(serverUrl);
- cache = builder.build();
- }
-
- return cache;
- }
-
- private static String getServerUrl(GlobalProperties props) {
- return StringUtils.removeEnd(StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/");
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java
deleted file mode 100644
index 9287c268634..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-public class NonAssociatedCacheSynchronizer {
- private static final Logger LOG = LoggerFactory.getLogger(NonAssociatedCacheSynchronizer.class);
-
- private final ProjectCacheStatus cacheStatus;
- private final QualityProfileLoader qualityProfileLoader;
- private final ActiveRulesLoader activeRulesLoader;
- private final RulesLoader rulesLoader;
-
- public NonAssociatedCacheSynchronizer(RulesLoader rulesLoader, QualityProfileLoader qualityProfileLoader, ActiveRulesLoader activeRulesLoader, ProjectCacheStatus cacheStatus) {
- this.rulesLoader = rulesLoader;
- this.qualityProfileLoader = qualityProfileLoader;
- this.activeRulesLoader = activeRulesLoader;
- this.cacheStatus = cacheStatus;
- }
-
- public void execute(boolean force) {
- Date lastSync = cacheStatus.getSyncStatus();
-
- if (lastSync != null) {
- if (!force) {
- LOG.info("Found cache [{}]", lastSync);
- return;
- } else {
- LOG.info("-- Found cache [{}], synchronizing data..", lastSync);
- }
- } else {
- LOG.info("-- Cache not found, synchronizing data..");
- }
-
- loadData();
- cacheStatus.save();
- LOG.info("-- Succesfully synchronized cache");
- }
-
- private static Collection<String> getKeys(Collection<QualityProfile> qProfiles) {
- List<String> list = new ArrayList<>(qProfiles.size());
- for (QualityProfile qp : qProfiles) {
- list.add(qp.getKey());
- }
-
- return list;
- }
-
- private void loadData() {
- Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class));
-
- profiler.startInfo("Load rules");
- rulesLoader.load(null);
- profiler.stopInfo();
-
- profiler.startInfo("Load default quality profiles");
- Collection<QualityProfile> qProfiles = qualityProfileLoader.loadDefault(null, null);
- profiler.stopInfo();
-
- profiler.startInfo("Load default active rules");
- Collection<String> keys = getKeys(qProfiles);
- for (String k : keys) {
- activeRulesLoader.load(k, null);
- }
- profiler.stopInfo();
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java
deleted file mode 100644
index ef5fd9754a1..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.util.Date;
-
-public interface ProjectCacheStatus {
- void save();
-
- void delete();
-
- Date getSyncStatus();
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java
deleted file mode 100644
index 64010b34c41..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import com.google.common.base.Function;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.batch.repository.ProjectRepositories;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.repository.user.UserRepositoryLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-public class ProjectCacheSynchronizer {
- private static final Logger LOG = LoggerFactory.getLogger(ProjectCacheSynchronizer.class);
-
- private final ServerIssuesLoader issuesLoader;
- private final UserRepositoryLoader userRepository;
- private final ProjectCacheStatus cacheStatus;
- private final QualityProfileLoader qualityProfileLoader;
- private final ProjectRepositoriesLoader projectRepositoriesLoader;
- private final ActiveRulesLoader activeRulesLoader;
- private final RulesLoader rulesLoader;
-
- public ProjectCacheSynchronizer(RulesLoader rulesLoader, QualityProfileLoader qualityProfileLoader, ProjectRepositoriesLoader projectSettingsLoader,
- ActiveRulesLoader activeRulesLoader, ServerIssuesLoader issuesLoader,
- UserRepositoryLoader userRepository, ProjectCacheStatus cacheStatus) {
- this.rulesLoader = rulesLoader;
- this.qualityProfileLoader = qualityProfileLoader;
- this.projectRepositoriesLoader = projectSettingsLoader;
- this.activeRulesLoader = activeRulesLoader;
- this.issuesLoader = issuesLoader;
- this.userRepository = userRepository;
- this.cacheStatus = cacheStatus;
- }
-
- private static boolean isToday(Date d) {
- Calendar c1 = Calendar.getInstance();
- Calendar c2 = Calendar.getInstance();
- c2.setTime(d);
-
- return c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) &&
- c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR);
- }
-
- private static boolean shouldUpdate(Date lastUpdate) {
- return !isToday(lastUpdate);
- }
-
- public void load(String projectKey, boolean force) {
- Date lastSync = cacheStatus.getSyncStatus();
- boolean failOnError = true;
-
- if (lastSync != null) {
- if (force) {
- LOG.info("-- Found project [{}] cache [{}], synchronizing data (forced)..", projectKey, lastSync);
- } else if (shouldUpdate(lastSync)) {
- LOG.info("-- Found project [{}] cache [{}], synchronizing data..", projectKey, lastSync);
- failOnError = false;
- } else {
- LOG.info("Found project [{}] cache [{}]", projectKey, lastSync);
- return;
- }
- } else {
- LOG.info("-- Cache for project [{}] not found, synchronizing data..", projectKey);
- }
-
- try {
- loadData(projectKey);
- } catch (Exception e) {
- if (failOnError) {
- throw e;
- }
-
- LOG.warn("-- Cache update for project [{}] failed, continuing from cache..", projectKey, e);
- return;
- }
-
- saveStatus();
- }
-
- private void saveStatus() {
- cacheStatus.save();
- LOG.info("-- Successfully synchronized project cache");
- }
-
- private void loadData(String projectKey) {
- Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class));
-
- profiler.startInfo("Load rules");
- rulesLoader.load(null);
- profiler.stopInfo();
-
- profiler.startInfo("Load project settings");
- ProjectRepositories projectRepo = projectRepositoriesLoader.load(projectKey, true, null);
-
- if (!projectRepo.exists()) {
- LOG.debug("Project doesn't exist in the server");
- } else if (projectRepo.lastAnalysisDate() == null) {
- LOG.debug("No previous analysis found");
- }
- profiler.stopInfo();
-
- profiler.startInfo("Load project quality profiles");
- Collection<QualityProfile> qProfiles;
- if (projectRepo.exists()) {
- qProfiles = qualityProfileLoader.load(projectKey, null, null);
- } else {
- qProfiles = qualityProfileLoader.loadDefault(null, null);
- }
- profiler.stopInfo();
-
- profiler.startInfo("Load project active rules");
- Collection<String> keys = getKeys(qProfiles);
- for (String k : keys) {
- activeRulesLoader.load(k, null);
- }
- profiler.stopInfo();
-
- if (projectRepo.lastAnalysisDate() != null) {
- profiler.startInfo("Load server issues");
- UserLoginAccumulator consumer = new UserLoginAccumulator();
- issuesLoader.load(projectKey, consumer);
- profiler.stopInfo();
-
- profiler.startInfo("Load user information");
- for (String login : consumer.loginSet) {
- userRepository.load(login, null);
- }
- profiler.stopInfo("Load user information");
- }
- }
-
- private static Collection<String> getKeys(Collection<QualityProfile> qProfiles) {
- List<String> list = new ArrayList<>(qProfiles.size());
- for (QualityProfile qp : qProfiles) {
- list.add(qp.getKey());
- }
-
- return list;
- }
-
- private static class UserLoginAccumulator implements Function<ServerIssue, Void> {
- Set<String> loginSet = new HashSet<>();
-
- @Override
- public Void apply(ServerIssue input) {
- if (!StringUtils.isEmpty(input.getAssigneeLogin())) {
- loginSet.add(input.getAssigneeLogin());
- }
- return null;
- }
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java
deleted file mode 100644
index abbd8a69485..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.sonar.api.batch.bootstrap.ProjectKey;
-
-public class ProjectKeySupplier implements ProjectKey {
- private final String key;
-
- ProjectKeySupplier(String key) {
- this.key = key;
- }
-
- @Override
- public String get() {
- return key;
- }
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java
deleted file mode 100644
index 2594a006543..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.sonar.api.batch.bootstrap.ProjectKey;
-
-import org.sonar.batch.util.BatchUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import com.google.common.base.Preconditions;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.sonar.batch.bootstrap.Slf4jLogger;
-
-import java.nio.file.Paths;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.home.cache.PersistentCache;
-import org.sonar.home.cache.PersistentCacheBuilder;
-
-public class ProjectPersistentCacheProvider extends ProviderAdapter {
- private PersistentCache cache;
-
- public PersistentCache provide(GlobalProperties props, DefaultAnalysisMode mode, ProjectKey key) {
- if (cache == null) {
- PersistentCacheBuilder builder = new PersistentCacheBuilder(new Slf4jLogger());
- String projectKey = key.get();
- String home = props.property("sonar.userHome");
- String serverUrl = getServerUrl(props);
-
- if (home != null) {
- builder.setSonarHome(Paths.get(home));
- }
-
- if (mode.isNotAssociated()) {
- builder.setAreaForLocalProject(serverUrl, BatchUtils.getServerVersion());
- } else {
- Preconditions.checkNotNull(projectKey);
- builder.setAreaForProject(serverUrl, BatchUtils.getServerVersion(), projectKey);
- }
-
- cache = builder.build();
- }
-
- return cache;
- }
-
- private static String getServerUrl(GlobalProperties props) {
- return StringUtils.removeEnd(StringUtils.defaultIfBlank(props.property("sonar.host.url"), "http://localhost:9000"), "/");
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
deleted file mode 100644
index 816091786b3..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.api.CoreProperties;
-import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.batch.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.batch.repository.DefaultQualityProfileLoader;
-import org.sonar.batch.repository.DefaultServerIssuesLoader;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.repository.user.UserRepositoryLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.DefaultActiveRulesLoader;
-import org.sonar.batch.rule.DefaultRulesLoader;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonar.core.platform.ComponentContainer;
-
-public class ProjectSyncContainer extends ComponentContainer {
- private final boolean force;
- private final String projectKey;
-
- public ProjectSyncContainer(ComponentContainer globalContainer, @Nullable String projectKey, boolean force) {
- super(globalContainer);
- this.projectKey = projectKey;
- this.force = force;
- }
-
- @Override
- public void doBeforeStart() {
- addComponents();
- }
-
- @Override
- public void doAfterStart() {
- if (projectKey != null) {
- getComponentByType(ProjectCacheSynchronizer.class).load(projectKey, force);
- } else {
- getComponentByType(NonAssociatedCacheSynchronizer.class).execute(force);
- }
- }
-
- private static DefaultAnalysisMode createIssuesAnalysisMode(@Nullable String projectKey) {
- Map<String, String> props = new HashMap<>();
- props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
- if (projectKey != null) {
- props.put(CoreProperties.PROJECT_KEY_PROPERTY, projectKey);
- }
- GlobalProperties globalProps = new GlobalProperties(props);
- AnalysisProperties analysisProps = new AnalysisProperties(props);
- return new DefaultAnalysisMode(globalProps, analysisProps);
- }
-
- private void addComponents() {
- add(new StrategyWSLoaderProvider(LoadStrategy.SERVER_ONLY),
- new ProjectKeySupplier(projectKey),
- projectKey != null ? ProjectCacheSynchronizer.class : NonAssociatedCacheSynchronizer.class,
- UserRepositoryLoader.class,
- new ProjectPersistentCacheProvider(),
- createIssuesAnalysisMode(projectKey));
-
- addIfMissing(DefaultProjectCacheStatus.class, ProjectCacheStatus.class);
- addIfMissing(DefaultProjectRepositoriesLoader.class, ProjectRepositoriesLoader.class);
- addIfMissing(DefaultServerIssuesLoader.class, ServerIssuesLoader.class);
- addIfMissing(DefaultQualityProfileLoader.class, QualityProfileLoader.class);
- addIfMissing(DefaultRulesLoader.class, RulesLoader.class);
- addIfMissing(DefaultActiveRulesLoader.class, ActiveRulesLoader.class);
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java
deleted file mode 100644
index d89de5ba448..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-
-public class StrategyWSLoaderProvider extends ProviderAdapter {
- private final LoadStrategy strategy;
- private WSLoader wsLoader;
-
- public StrategyWSLoaderProvider(LoadStrategy strategy) {
- this.strategy = strategy;
- }
-
- public WSLoader provide(PersistentCache cache, BatchWsClient client) {
- if (wsLoader == null) {
- wsLoader = new WSLoader(strategy, cache, client);
- }
- return wsLoader;
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoader.java
deleted file mode 100644
index 328480e68bf..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoader.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.charset.StandardCharsets;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.home.cache.PersistentCache;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.HttpException;
-
-import static org.sonar.batch.cache.WSLoader.ServerStatus.ACCESSIBLE;
-import static org.sonar.batch.cache.WSLoader.ServerStatus.NOT_ACCESSIBLE;
-import static org.sonar.batch.cache.WSLoader.ServerStatus.UNKNOWN;
-
-public class WSLoader {
- private static final Logger LOG = Loggers.get(WSLoader.class);
- private static final String FAIL_MSG = "Server is not accessible and data is not cached";
-
- public enum ServerStatus {
- UNKNOWN, ACCESSIBLE, NOT_ACCESSIBLE
- }
-
- public enum LoadStrategy {
- SERVER_FIRST, CACHE_FIRST, SERVER_ONLY, CACHE_ONLY
- }
-
- private final LoadStrategy defautLoadStrategy;
- private final BatchWsClient wsClient;
- private final PersistentCache cache;
- private ServerStatus serverStatus;
-
- private DataLoader<String> stringServerLoader = new DataLoader<String>() {
- @Override
- public String load(String id) throws IOException {
- GetRequest getRequest = new GetRequest(id);
- try (Reader reader = wsClient.call(getRequest).contentReader()) {
- String str = IOUtils.toString(reader);
- try {
- cache.put(id, str.getBytes(StandardCharsets.UTF_8));
- } catch (IOException e) {
- throw new IllegalStateException("Error saving to WS cache", e);
- }
- return str;
- }
- }
- };
-
- private DataLoader<String> stringCacheLoader = new DataLoader<String>() {
- @Override
- public String load(String id) throws IOException {
- return cache.getString(id);
- }
- };
-
- private DataLoader<InputStream> streamServerLoader = new DataLoader<InputStream>() {
- @Override
- public InputStream load(String id) throws IOException {
- GetRequest getRequest = new GetRequest(id);
- try (InputStream is = wsClient.call(getRequest).contentStream()) {
- try {
- cache.put(id, is);
- } catch (IOException e) {
- throw new IllegalStateException("Error saving to WS cache", e);
- }
- }
- return cache.getStream(id);
- }
- };
-
- private DataLoader<InputStream> streamCacheLoader = new DataLoader<InputStream>() {
- @Override
- public InputStream load(String id) throws IOException {
- return cache.getStream(id);
- }
- };
-
- private static class NotAvailableException extends Exception {
- private static final long serialVersionUID = 1L;
-
- public NotAvailableException(String message) {
- super(message);
- }
-
- public NotAvailableException(Throwable cause) {
- super(cause);
- }
- }
-
- public WSLoader(LoadStrategy strategy, PersistentCache cache, BatchWsClient wsClient) {
- this.defautLoadStrategy = strategy;
- this.serverStatus = UNKNOWN;
- this.cache = cache;
- this.wsClient = wsClient;
- }
-
- @Nonnull
- public WSLoaderResult<InputStream> loadStream(String id) {
- return load(id, defautLoadStrategy, streamServerLoader, streamCacheLoader);
- }
-
- @Nonnull
- public WSLoaderResult<String> loadString(String id) {
- return loadString(id, defautLoadStrategy);
- }
-
- @Nonnull
- public WSLoaderResult<String> loadString(String id, WSLoader.LoadStrategy strategy) {
- return load(id, strategy, stringServerLoader, stringCacheLoader);
- }
-
- @Nonnull
- private <T> WSLoaderResult<T> load(String id, WSLoader.LoadStrategy strategy, DataLoader<T> serverLoader, DataLoader<T> cacheLoader) {
- switch (strategy) {
- case CACHE_FIRST:
- return loadFromCacheFirst(id, cacheLoader, serverLoader);
- case CACHE_ONLY:
- return loadFromCacheFirst(id, cacheLoader, null);
- case SERVER_FIRST:
- return loadFromServerFirst(id, serverLoader, cacheLoader);
- case SERVER_ONLY:
- default:
- return loadFromServerFirst(id, serverLoader, null);
- }
- }
-
- public LoadStrategy getDefaultStrategy() {
- return this.defautLoadStrategy;
- }
-
- private void switchToOffline() {
- LOG.debug("server not available - switching to offline mode");
- serverStatus = NOT_ACCESSIBLE;
- }
-
- private void switchToOnline() {
- serverStatus = ACCESSIBLE;
- }
-
- private boolean isOffline() {
- return serverStatus == NOT_ACCESSIBLE;
- }
-
- @Nonnull
- private <T> WSLoaderResult<T> loadFromCacheFirst(String id, DataLoader<T> cacheLoader, @Nullable DataLoader<T> serverLoader) {
- try {
- return loadFromCache(id, cacheLoader);
- } catch (NotAvailableException cacheNotAvailable) {
- if (serverLoader != null) {
- try {
- return loadFromServer(id, serverLoader);
- } catch (NotAvailableException serverNotAvailable) {
- throw new IllegalStateException(FAIL_MSG, serverNotAvailable.getCause());
- }
- }
- throw new IllegalStateException("Data is not cached", cacheNotAvailable.getCause());
- }
- }
-
- @Nonnull
- private <T> WSLoaderResult<T> loadFromServerFirst(String id, DataLoader<T> serverLoader, @Nullable DataLoader<T> cacheLoader) {
- try {
- return loadFromServer(id, serverLoader);
- } catch (NotAvailableException serverNotAvailable) {
- if (cacheLoader != null) {
- try {
- return loadFromCache(id, cacheLoader);
- } catch (NotAvailableException cacheNotAvailable) {
- throw new IllegalStateException(FAIL_MSG, serverNotAvailable.getCause());
- }
- }
- throw new IllegalStateException("Server is not available: " + wsClient.baseUrl(), serverNotAvailable.getCause());
- }
- }
-
- interface DataLoader<T> {
- T load(String id) throws IOException;
- }
-
- private <T> WSLoaderResult<T> loadFromCache(String id, DataLoader<T> loader) throws NotAvailableException {
- T result;
-
- try {
- result = loader.load(id);
- } catch (IOException e) {
- // any exception on the cache should fail fast
- throw new IllegalStateException(e);
- }
- if (result == null) {
- throw new NotAvailableException("resource not cached");
- }
- return new WSLoaderResult<>(result, true);
- }
-
- private <T> WSLoaderResult<T> loadFromServer(String id, DataLoader<T> loader) throws NotAvailableException {
- if (isOffline()) {
- throw new NotAvailableException("Server not available");
- }
- try {
- T t = loader.load(id);
- switchToOnline();
- return new WSLoaderResult<>(t, false);
- } catch (HttpException | MessageException e) {
- // fail fast if it could connect but there was a application-level error
- throw e;
- } catch (IllegalStateException e) {
- switchToOffline();
- throw new NotAvailableException(e);
- } catch (Exception e) {
- // fail fast
- throw new IllegalStateException(e);
- }
- }
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java
deleted file mode 100644
index 29db0bcb3a7..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import javax.annotation.Nonnull;
-
-public class WSLoaderResult<T> {
- private T result;
- private boolean fromCache;
-
- public WSLoaderResult(T result, boolean fromCache) {
- this.result = result;
- this.fromCache = fromCache;
- }
-
- @Nonnull
- public T get() {
- return result;
- }
-
- public boolean isFromCache() {
- return fromCache;
- }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java
deleted file mode 100644
index 3f72a2d38b6..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java
index 954997466fe..ff28b9e8da3 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java
@@ -19,50 +19,45 @@
*/
package org.sonar.batch.issue.tracking;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.sonar.batch.bootstrap.BatchWsClient;
+import org.sonar.batch.util.BatchUtils;
+import org.sonarqube.ws.client.GetRequest;
-import javax.annotation.Nullable;
+import java.io.IOException;
+import java.io.Reader;
-import org.sonar.batch.util.BatchUtils;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterators;
+import org.apache.commons.io.IOUtils;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
public class DefaultServerLineHashesLoader implements ServerLineHashesLoader {
+ private BatchWsClient wsClient;
- private final WSLoader wsLoader;
-
- public DefaultServerLineHashesLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public DefaultServerLineHashesLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) {
- String hashesFromWs = loadHashesFromWs(fileKey, fromCache);
+ public String[] getLineHashes(String fileKey) {
+ String hashesFromWs = loadHashesFromWs(fileKey);
return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class);
}
- private String loadHashesFromWs(String fileKey, @Nullable MutableBoolean fromCache) {
+ private String loadHashesFromWs(String fileKey) {
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), LoadStrategy.CACHE_FIRST);
+
+ GetRequest getRequest = new GetRequest("/api/sources/hash?key=" + BatchUtils.encodeForUrl(fileKey));
+ Reader reader = wsClient.call(getRequest).contentReader();
try {
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
- }
- return result.get();
+ return IOUtils.toString(reader);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
} finally {
- if (result.isFromCache()) {
- profiler.stopDebug("Load line hashes (done from cache)");
- } else {
- profiler.stopDebug();
- }
+ profiler.stopDebug();
}
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
index 16f104583fd..040ce776b9f 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
@@ -59,8 +59,8 @@ public class ServerIssueRepository {
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
this.issuesCache = caches.createCache("previousIssues");
caches.registerValueCoder(ServerIssue.class, new ServerIssueValueCoder());
- boolean fromCache = previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), new SaveIssueConsumer());
- profiler.stopInfo(fromCache);
+ previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), new SaveIssueConsumer());
+ profiler.stopInfo();
}
public Iterable<ServerIssue> byComponent(BatchComponent component) {
@@ -85,7 +85,7 @@ public class ServerIssueRepository {
return null;
}
}
-
+
public Iterable<ServerIssue> issuesOnMissingComponents() {
return issuesCache.values(0);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java
index fb0b32d0d2b..23edcc430d4 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java
@@ -19,14 +19,10 @@
*/
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, @Nullable MutableBoolean fromCache);
+ String[] getLineHashes(String fileKey);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
index 583a92f0b9d..dac686f27ea 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
+++ b/sonar-scanner-engine/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(), null);
+ String[] lineHashes = lastSnapshots.getLineHashes(inputFile.key());
hashedReference = lineHashes != null ? FileHashes.create(lineHashes) : null;
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java
index 55508b0e8bf..6ccce5e2c25 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java
@@ -19,30 +19,34 @@
*/
package org.sonar.batch.repository;
-import org.sonar.batch.cache.WSLoaderResult;
import org.sonar.scanner.protocol.input.GlobalRepositories;
-import org.sonar.batch.cache.WSLoader;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonar.batch.bootstrap.BatchWsClient;
-import javax.annotation.Nullable;
+import java.io.IOException;
+import java.io.Reader;
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.apache.commons.io.IOUtils;
public class DefaultGlobalRepositoriesLoader implements GlobalRepositoriesLoader {
private static final String BATCH_GLOBAL_URL = "/batch/global";
+ private BatchWsClient wsClient;
- private final WSLoader wsLoader;
-
- public DefaultGlobalRepositoriesLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public DefaultGlobalRepositoriesLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public GlobalRepositories load(@Nullable MutableBoolean fromCache) {
- WSLoaderResult<String> result = wsLoader.loadString(BATCH_GLOBAL_URL);
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
+ public GlobalRepositories load() {
+ GetRequest getRequest = new GetRequest(BATCH_GLOBAL_URL);
+ Reader reader = wsClient.call(getRequest).contentReader();
+ String str;
+ try {
+ str = IOUtils.toString(reader);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
}
- return GlobalRepositories.fromJson(result.get());
+ return GlobalRepositories.fromJson(str);
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
index 0e8a0904b57..878d11ee04f 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
@@ -30,38 +30,33 @@ import java.net.HttpURLConnection;
import java.util.Date;
import java.util.Map;
-import javax.annotation.Nullable;
-
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonar.batch.util.BatchUtils;
import org.sonarqube.ws.WsBatch.WsProjectResponse;
import org.sonarqube.ws.WsBatch.WsProjectResponse.FileDataByPath;
import org.sonarqube.ws.WsBatch.WsProjectResponse.Settings;
+import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.HttpException;
public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoader {
private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectRepositoriesLoader.class);
private static final String BATCH_PROJECT_URL = "/batch/project.protobuf";
- private final WSLoader loader;
+ private BatchWsClient wsClient;
- public DefaultProjectRepositoriesLoader(WSLoader loader) {
- this.loader = loader;
+ public DefaultProjectRepositoriesLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public ProjectRepositories load(String projectKey, boolean issuesMode, @Nullable MutableBoolean fromCache) {
+ public ProjectRepositories load(String projectKey, boolean issuesMode) {
try {
- WSLoaderResult<InputStream> result = loader.loadStream(getUrl(projectKey, issuesMode));
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
- }
- return processStream(result.get(), projectKey);
+ GetRequest request = new GetRequest(getUrl(projectKey, issuesMode));
+ InputStream is = wsClient.call(request).contentStream();
+ return processStream(is, projectKey);
} catch (RuntimeException e) {
if (shouldThrow(e)) {
throw e;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
index 524e6f6856d..6d3766b1c3b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
@@ -25,9 +25,8 @@ import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.sonar.batch.util.BatchUtils;
import org.apache.commons.io.IOUtils;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.apache.commons.lang.mutable.MutableBoolean;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonar.batch.bootstrap.BatchWsClient;
import javax.annotation.Nullable;
@@ -38,36 +37,33 @@ import java.util.List;
public class DefaultQualityProfileLoader implements QualityProfileLoader {
private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
- private WSLoader wsLoader;
+ private BatchWsClient wsClient;
- public DefaultQualityProfileLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public DefaultQualityProfileLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) {
+ public List<QualityProfile> loadDefault(@Nullable String profileName) {
String url = WS_URL + "?defaults=true";
if (profileName != null) {
url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
}
- return loadResource(url, fromCache);
+ return loadResource(url);
}
@Override
- public List<QualityProfile> load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache) {
+ public List<QualityProfile> load(String projectKey, @Nullable String profileName) {
String url = WS_URL + "?projectKey=" + BatchUtils.encodeForUrl(projectKey);
if (profileName != null) {
url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
}
- return loadResource(url, fromCache);
+ return loadResource(url);
}
- private List<QualityProfile> loadResource(String url, @Nullable MutableBoolean fromCache) {
- WSLoaderResult<InputStream> result = wsLoader.loadStream(url);
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
- }
- InputStream is = result.get();
+ private List<QualityProfile> loadResource(String url) {
+ GetRequest getRequest = new GetRequest(url);
+ InputStream is = wsClient.call(getRequest).contentStream();
SearchWsResponse profiles = null;
try {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java
index 394ce0eea92..f5f4406fab5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java
@@ -23,24 +23,24 @@ import com.google.common.base.Function;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonar.batch.util.BatchUtils;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
+import org.sonarqube.ws.client.GetRequest;
public class DefaultServerIssuesLoader implements ServerIssuesLoader {
- private final WSLoader wsLoader;
+ private final BatchWsClient wsClient;
- public DefaultServerIssuesLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public DefaultServerIssuesLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public boolean load(String componentKey, Function<ServerIssue, Void> consumer) {
- WSLoaderResult<InputStream> result = wsLoader.loadStream("/batch/issues.protobuf?key=" + BatchUtils.encodeForUrl(componentKey));
- parseIssues(result.get(), consumer);
- return result.isFromCache();
+ public void load(String componentKey, Function<ServerIssue, Void> consumer) {
+ GetRequest getRequest = new GetRequest("/batch/issues.protobuf?key=" + BatchUtils.encodeForUrl(componentKey));
+ InputStream is = wsClient.call(getRequest).contentStream();
+ parseIssues(is, consumer);
}
private static void parseIssues(InputStream is, Function<ServerIssue, Void> consumer) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java
index 86359e4b772..cf8b435eee7 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java
@@ -19,12 +19,8 @@
*/
package org.sonar.batch.repository;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonar.scanner.protocol.input.GlobalRepositories;
-import javax.annotation.Nullable;
public interface GlobalRepositoriesLoader {
-
- GlobalRepositories load(@Nullable MutableBoolean fromCache);
-
+ GlobalRepositories load();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java
index 578b5458cd8..e28d952671b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java
@@ -19,8 +19,6 @@
*/
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;
@@ -36,9 +34,8 @@ public class GlobalRepositoriesProvider extends ProviderAdapter {
public GlobalRepositories provide(GlobalRepositoriesLoader loader) {
if (globalReferentials == null) {
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
- MutableBoolean fromCache = new MutableBoolean();
- globalReferentials = loader.load(fromCache);
- profiler.stopInfo(fromCache.booleanValue());
+ globalReferentials = loader.load();
+ profiler.stopInfo();
}
return globalReferentials;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java
index 53de4805324..f689d3664df 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java
@@ -19,10 +19,7 @@
*/
package org.sonar.batch.repository;
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang.mutable.MutableBoolean;
public interface ProjectRepositoriesLoader {
- ProjectRepositories load(String projectKeyWithBranch, boolean issuesMode, @Nullable MutableBoolean fromCache);
+ ProjectRepositories load(String projectKeyWithBranch, boolean issuesMode);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java
index 1e0469651d5..f5b17549f46 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java
@@ -26,7 +26,6 @@ import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.picocontainer.injectors.ProviderAdapter;
public class ProjectRepositoriesProvider extends ProviderAdapter {
@@ -36,17 +35,10 @@ public class ProjectRepositoriesProvider extends ProviderAdapter {
public ProjectRepositories provide(ProjectRepositoriesLoader loader, ProjectKey projectKey, DefaultAnalysisMode mode) {
if (project == null) {
- MutableBoolean fromCache = new MutableBoolean(false);
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
- if (mode.isNotAssociated()) {
- project = createNonAssociatedProjectRepositories();
- profiler.stopInfo();
- } else {
- project = loader.load(projectKey.get(), mode.isIssues(), fromCache);
- checkProject(mode);
- profiler.stopInfo(fromCache.booleanValue());
- }
-
+ project = loader.load(projectKey.get(), mode.isIssues());
+ checkProject(mode);
+ profiler.stopInfo();
}
return project;
@@ -56,13 +48,9 @@ public class ProjectRepositoriesProvider extends ProviderAdapter {
if (mode.isIssues()) {
if (!project.exists()) {
LOG.warn("Project doesn't exist on the server. All issues will be marked as 'new'.");
- } else if (project.lastAnalysisDate() == null && !mode.isNotAssociated()) {
+ } else if (project.lastAnalysisDate() == null) {
LOG.warn("No analysis has been found on the server for this project. All issues will be marked as 'new'.");
}
}
}
-
- private static ProjectRepositories createNonAssociatedProjectRepositories() {
- return new ProjectRepositories();
- }
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java
index a93bea66b11..45d492b1347 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java
@@ -19,7 +19,6 @@
*/
package org.sonar.batch.repository;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import javax.annotation.Nullable;
@@ -27,7 +26,7 @@ import javax.annotation.Nullable;
import java.util.List;
public interface QualityProfileLoader {
- List<QualityProfile> load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache);
-
- List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache);
+ List<QualityProfile> load(String projectKey, @Nullable String profileName);
+
+ List<QualityProfile> loadDefault(@Nullable String profileName);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java
index 6878d21ecfb..0b62b406a41 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java
@@ -21,7 +21,6 @@ package org.sonar.batch.repository;
import java.util.List;
import javax.annotation.CheckForNull;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.batch.bootstrap.ProjectKey;
import org.sonar.api.utils.log.Logger;
@@ -40,15 +39,13 @@ public class QualityProfileProvider extends ProviderAdapter {
public ModuleQProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props, DefaultAnalysisMode mode) {
if (this.profiles == null) {
List<QualityProfile> profileList;
- MutableBoolean fromCache = new MutableBoolean();
-
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
- if (mode.isNotAssociated() || !projectRepositories.exists()) {
- profileList = loader.loadDefault(getSonarProfile(props, mode), fromCache);
+ if (!projectRepositories.exists()) {
+ profileList = loader.loadDefault(getSonarProfile(props, mode));
} else {
- profileList = loader.load(projectKey.get(), getSonarProfile(props, mode), fromCache);
+ profileList = loader.load(projectKey.get(), getSonarProfile(props, mode));
}
- profiler.stopInfo(fromCache.booleanValue());
+ profiler.stopInfo();
profiles = new ModuleQProfiles(profileList);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java
index e0c981a11e0..171323b347d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java
@@ -24,6 +24,6 @@ import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
public interface ServerIssuesLoader {
- boolean load(String componentKey, Function<ServerIssue, Void> consumer);
+ void load(String componentKey, Function<ServerIssue, Void> consumer);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java
index 9b33645cebe..f4aa2072911 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java
@@ -21,16 +21,13 @@ package org.sonar.batch.repository.user;
import org.apache.commons.io.IOUtils;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.bootstrap.BatchWsClient;
-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.util.BatchUtils;
import org.sonar.scanner.protocol.input.ScannerInput;
+import org.sonarqube.ws.client.GetRequest;
import com.google.common.base.Function;
import java.io.IOException;
import java.io.InputStream;
@@ -40,43 +37,29 @@ import java.util.Collections;
import java.util.List;
public class UserRepositoryLoader {
- private final WSLoader wsLoader;
+ private final BatchWsClient wsClient;
- public UserRepositoryLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public UserRepositoryLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
public ScannerInput.User load(String userLogin) {
- return load(userLogin, null);
- }
-
- public ScannerInput.User load(String userLogin, @Nullable MutableBoolean fromCache) {
- InputStream is = loadQuery(new UserEncodingFunction().apply(userLogin), fromCache);
+ InputStream is = loadQuery(new UserEncodingFunction().apply(userLogin));
return parseUser(is);
}
public Collection<ScannerInput.User> load(List<String> userLogins) {
- return load(userLogins, null);
- }
-
- /**
- * Not cache friendly. Should not be used if a cache hit is expected.
- */
- public Collection<ScannerInput.User> load(List<String> userLogins, @Nullable MutableBoolean fromCache) {
if (userLogins.isEmpty()) {
return Collections.emptyList();
}
- InputStream is = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction())), fromCache);
+ InputStream is = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction())));
return parseUsers(is);
}
- private InputStream loadQuery(String loginsQuery, @Nullable MutableBoolean fromCache) {
- WSLoaderResult<InputStream> result = wsLoader.loadStream("/batch/users?logins=" + loginsQuery);
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
- }
- return result.get();
+ private InputStream loadQuery(String loginsQuery) {
+ GetRequest getRequest = new GetRequest("/batch/users?logins=" + loginsQuery);
+ return wsClient.call(getRequest).contentStream();
}
private static class UserEncodingFunction implements Function<String, String> {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java
index 028929bd141..cc7d7e12371 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java
@@ -19,12 +19,8 @@
*/
package org.sonar.batch.rule;
-import org.apache.commons.lang.mutable.MutableBoolean;
-
-import javax.annotation.Nullable;
-
import java.util.List;
public interface ActiveRulesLoader {
- List<LoadedActiveRule> load(String qualityProfileKey, @Nullable MutableBoolean fromCache);
+ List<LoadedActiveRule> load(String qualityProfileKey);
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
index 83034e22132..14814b9de0c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
@@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
@@ -47,14 +46,13 @@ public class ActiveRulesProvider extends ProviderAdapter {
public ActiveRules provide(ActiveRulesLoader loader, ModuleQProfiles qProfiles) {
if (singleton == null) {
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
- MutableBoolean fromCache = new MutableBoolean();
- singleton = load(loader, qProfiles, fromCache);
- profiler.stopInfo(fromCache.booleanValue());
+ singleton = load(loader, qProfiles);
+ profiler.stopInfo();
}
return singleton;
}
- private static ActiveRules load(ActiveRulesLoader loader, ModuleQProfiles qProfiles, MutableBoolean fromCache) {
+ private static ActiveRules load(ActiveRulesLoader loader, ModuleQProfiles qProfiles) {
Collection<String> qProfileKeys = getKeys(qProfiles);
Map<RuleKey, LoadedActiveRule> loadedRulesByKey = new HashMap<>();
@@ -62,7 +60,7 @@ public class ActiveRulesProvider extends ProviderAdapter {
try {
for (String qProfileKey : qProfileKeys) {
Collection<LoadedActiveRule> qProfileRules;
- qProfileRules = load(loader, qProfileKey, fromCache);
+ qProfileRules = load(loader, qProfileKey);
for (LoadedActiveRule r : qProfileRules) {
if (!loadedRulesByKey.containsKey(r.getRuleKey())) {
@@ -100,8 +98,8 @@ public class ActiveRulesProvider extends ProviderAdapter {
return builder.build();
}
- private static List<LoadedActiveRule> load(ActiveRulesLoader loader, String qProfileKey, MutableBoolean fromCache) throws IOException {
- return loader.load(qProfileKey, fromCache);
+ private static List<LoadedActiveRule> load(ActiveRulesLoader loader, String qProfileKey) throws IOException {
+ return loader.load(qProfileKey);
}
private static Collection<String> getKeys(ModuleQProfiles qProfiles) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java
index 9485d99e1cb..0a6e7951782 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java
@@ -28,15 +28,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import javax.annotation.Nullable;
-
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonarqube.ws.Rules.Active;
import org.sonarqube.ws.Rules.Active.Param;
+import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.Rules.ActiveList;
import org.sonarqube.ws.Rules.Rule;
import org.sonarqube.ws.Rules.SearchResponse;
@@ -44,22 +41,22 @@ import org.sonarqube.ws.Rules.SearchResponse;
public class DefaultActiveRulesLoader implements ActiveRulesLoader {
private static final String RULES_SEARCH_URL = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true";
- private final WSLoader wsLoader;
+ private final BatchWsClient wsClient;
- public DefaultActiveRulesLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public DefaultActiveRulesLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public List<LoadedActiveRule> load(String qualityProfileKey, @Nullable MutableBoolean fromCache) {
+ public List<LoadedActiveRule> load(String qualityProfileKey) {
List<LoadedActiveRule> ruleList = new LinkedList<>();
int page = 1;
int pageSize = 500;
int loaded = 0;
while (true) {
- WSLoaderResult<InputStream> result = wsLoader.loadStream(getUrl(qualityProfileKey, page, pageSize));
- SearchResponse response = loadFromStream(result.get());
+ GetRequest getRequest = new GetRequest(getUrl(qualityProfileKey, page, pageSize));
+ SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream());
List<LoadedActiveRule> pageRules = readPage(response);
ruleList.addAll(pageRules);
loaded += response.getPs();
@@ -68,9 +65,6 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
break;
}
page++;
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
- }
}
return ruleList;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
index 62292b4581b..9921af66c8b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
@@ -21,13 +21,9 @@ package org.sonar.batch.rule;
import org.apache.commons.io.IOUtils;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonarqube.ws.Rules.ListResponse.Rule;
+import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.Rules.ListResponse;
import java.io.IOException;
@@ -37,19 +33,16 @@ import java.util.List;
public class DefaultRulesLoader implements RulesLoader {
private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf";
- private final WSLoader wsLoader;
+ private final BatchWsClient wsClient;
- public DefaultRulesLoader(WSLoader wsLoader) {
- this.wsLoader = wsLoader;
+ public DefaultRulesLoader(BatchWsClient wsClient) {
+ this.wsClient = wsClient;
}
@Override
- public List<Rule> load(@Nullable MutableBoolean fromCache) {
- WSLoaderResult<InputStream> result = wsLoader.loadStream(RULES_SEARCH_URL);
- ListResponse list = loadFromStream(result.get());
- if (fromCache != null) {
- fromCache.setValue(result.isFromCache());
- }
+ public List<Rule> load() {
+ GetRequest getRequest = new GetRequest(RULES_SEARCH_URL);
+ ListResponse list = loadFromStream(wsClient.call(getRequest).contentStream());
return list.getRulesList();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesLoader.java
index 9572f628f2d..1c4c8df4db2 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesLoader.java
@@ -20,10 +20,8 @@
package org.sonar.batch.rule;
import java.util.List;
-import javax.annotation.Nullable;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonarqube.ws.Rules.ListResponse.Rule;
public interface RulesLoader {
- List<Rule> load(@Nullable MutableBoolean fromCache);
+ List<Rule> load();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProvider.java
index 7a3e0ea34f0..fcc71194a70 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProvider.java
@@ -19,8 +19,6 @@
*/
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;
@@ -48,8 +46,7 @@ public class RulesProvider extends ProviderAdapter {
private static Rules load(RulesLoader ref) {
Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
- MutableBoolean fromCache = new MutableBoolean();
- List<Rule> loadedRules = ref.load(fromCache);
+ List<Rule> loadedRules = ref.load();
RulesBuilder builder = new RulesBuilder();
for (Rule r : loadedRules) {
@@ -58,7 +55,7 @@ public class RulesProvider extends ProviderAdapter {
newRule.setInternalKey(r.getInternalKey());
}
- profiler.stopInfo(fromCache.booleanValue());
+ profiler.stopInfo();
return builder.build();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
index cd779df9e8e..44bc53afed5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
@@ -38,7 +38,6 @@ import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
@@ -107,15 +106,11 @@ public class ProjectReactorBuilder {
private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, CoreProperties.WORKING_DIRECTORY, PROPERTY_MODULES,
CoreProperties.PROJECT_DESCRIPTION_PROPERTY);
- private static final String NON_ASSOCIATED_PROJECT_KEY = "project";
-
private final AnalysisProperties analysisProps;
- private final AnalysisMode analysisMode;
private File rootProjectWorkDir;
- public ProjectReactorBuilder(AnalysisProperties props, AnalysisMode analysisMode) {
+ public ProjectReactorBuilder(AnalysisProperties props) {
this.analysisProps = props;
- this.analysisMode = analysisMode;
}
public ProjectReactor execute() {
@@ -169,15 +164,7 @@ public class ProjectReactorBuilder {
}
}
- private static void prepareNonAssociatedProject(Map<String, String> props, AnalysisMode mode) {
- if (mode.isIssues() && !props.containsKey(CoreProperties.PROJECT_KEY_PROPERTY)) {
- props.put(CoreProperties.PROJECT_KEY_PROPERTY, NON_ASSOCIATED_PROJECT_KEY);
- }
- }
-
protected ProjectDefinition defineRootProject(Map<String, String> rootProperties, @Nullable ProjectDefinition parent) {
- prepareNonAssociatedProject(rootProperties, analysisMode);
-
if (rootProperties.containsKey(PROPERTY_MODULES)) {
checkMandatoryProperties(rootProperties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT);
} else {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 23c83b36550..91c383d55c6 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -33,13 +33,11 @@ import org.sonar.batch.DefaultProjectTree;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.analysis.AnalysisProperties;
import org.sonar.batch.analysis.AnalysisTempFolderProvider;
-import org.sonar.batch.analysis.AnalysisWSLoaderProvider;
import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.bootstrap.ExtensionMatcher;
import org.sonar.batch.bootstrap.ExtensionUtils;
import org.sonar.batch.bootstrap.MetricProvider;
-import org.sonar.batch.cache.ProjectPersistentCacheProvider;
import org.sonar.batch.cpd.CpdExecutor;
import org.sonar.batch.cpd.index.SonarCpdBlockIndex;
import org.sonar.batch.events.EventBus;
@@ -135,7 +133,6 @@ public class ProjectScanContainer extends ComponentContainer {
ResourceTypes.class,
DefaultProjectTree.class,
ProjectReactorValidator.class,
- new AnalysisWSLoaderProvider(),
CodeColorizers.class,
MetricProvider.class,
ProjectConfigurator.class,
@@ -145,7 +142,6 @@ public class ProjectScanContainer extends ComponentContainer {
DefaultIssueCallback.class,
new RulesProvider(),
new ProjectRepositoriesProvider(),
- new ProjectPersistentCacheProvider(),
// temp
new AnalysisTempFolderProvider(),
@@ -214,10 +210,6 @@ public class ProjectScanContainer extends ComponentContainer {
}
private boolean isTherePreviousAnalysis() {
- if (getComponentByType(DefaultAnalysisMode.class).isNotAssociated()) {
- return false;
- }
-
return getComponentByType(ProjectRepositories.class).lastAnalysisDate() != null;
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
index 2d8ee157b9d..b9d6c47bcf8 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
@@ -32,7 +32,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.util.ProgressReport;
-import org.sonar.home.cache.DirectoryLock;
import java.io.File;
import java.io.IOException;
@@ -217,7 +216,7 @@ public class FileIndexer {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- if (!Files.isHidden(file) && !DirectoryLock.LOCK_FILE_NAME.equals(file.getFileName().toString())) {
+ if (!Files.isHidden(file)) {
indexFile(inputFileBuilder, fileSystem, status, file, type);
}
return FileVisitResult.CONTINUE;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/task/ScanTask.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/task/ScanTask.java
index c5ba59c3d37..80b338e0a6e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/task/ScanTask.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/task/ScanTask.java
@@ -19,14 +19,10 @@
*/
package org.sonar.batch.task;
-import javax.annotation.CheckForNull;
import org.sonar.api.CoreProperties;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.batch.cache.ProjectSyncContainer;
import org.sonar.batch.scan.ProjectScanContainer;
import org.sonar.core.platform.ComponentContainer;
@@ -48,25 +44,6 @@ public class ScanTask implements Task {
@Override
public void execute() {
AnalysisProperties props = new AnalysisProperties(taskProps.properties(), taskProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
- if (isIssuesMode(props)) {
- String projectKey = getProjectKeyWithBranch(props);
- new ProjectSyncContainer(taskContainer, projectKey, false).execute();
- }
new ProjectScanContainer(taskContainer, props).execute();
}
-
- @CheckForNull
- private static String getProjectKeyWithBranch(AnalysisProperties props) {
- String projectKey = props.property(CoreProperties.PROJECT_KEY_PROPERTY);
- if (projectKey != null && props.property(CoreProperties.PROJECT_BRANCH_PROPERTY) != null) {
- projectKey = projectKey + ":" + props.property(CoreProperties.PROJECT_BRANCH_PROPERTY);
- }
- return projectKey;
- }
-
- private boolean isIssuesMode(AnalysisProperties props) {
- DefaultAnalysisMode mode = new DefaultAnalysisMode(taskContainer.getComponentByType(GlobalProperties.class), props);
- return mode.isIssues();
- }
-
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java
new file mode 100644
index 00000000000..ffe7e82fc26
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java
@@ -0,0 +1,96 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.batch;
+
+import org.apache.commons.lang.StringUtils;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.sonar.batch.bootstrap.BatchWsClient;
+import org.sonarqube.ws.client.WsRequest;
+import org.sonarqube.ws.client.WsResponse;
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class WsTestUtil {
+ public static void mockStream(BatchWsClient mock, String path, InputStream is) {
+ WsResponse response = mock(WsResponse.class);
+ when(response.contentStream()).thenReturn(is);
+ when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
+ }
+
+ public static void mockStream(BatchWsClient mock, InputStream is) {
+ WsResponse response = mock(WsResponse.class);
+ when(response.contentStream()).thenReturn(is);
+ when(mock.call(any(WsRequest.class))).thenReturn(response);
+ }
+
+ public static void mockReader(BatchWsClient mock, Reader reader) {
+ WsResponse response = mock(WsResponse.class);
+ when(response.contentReader()).thenReturn(reader);
+ when(mock.call(any(WsRequest.class))).thenReturn(response);
+ }
+
+ public static void mockReader(BatchWsClient mock, String path, Reader reader) {
+ WsResponse response = mock(WsResponse.class);
+ when(response.contentReader()).thenReturn(reader);
+ when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
+ }
+
+ public static void mockException(BatchWsClient mock, Exception e) {
+ when(mock.call(any(WsRequest.class))).thenThrow(e);
+ }
+
+ public static void mockException(BatchWsClient mock, String path, Exception e) {
+ when(mock.call(argThat(new RequestMatcher(path)))).thenThrow(e);
+ }
+
+ public static void verifyCall(BatchWsClient mock, String path) {
+ verify(mock).call(argThat(new RequestMatcher(path)));
+ }
+
+ private static class RequestMatcher extends BaseMatcher<WsRequest> {
+ private String path;
+
+ public RequestMatcher(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public boolean matches(Object item) {
+ if (item == null) {
+ return false;
+ }
+ WsRequest request = (WsRequest) item;
+ return StringUtils.equals(request.getPath(), path);
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("request path (\"" + path + "\")");
+ }
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java
deleted file mode 100644
index 66ab296a063..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.analysis;
-
-import com.google.common.collect.ImmutableMap;
-import org.assertj.core.util.Maps;
-import org.junit.Test;
-import org.sonar.api.batch.AnalysisMode;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class AnalysisWSLoaderProviderTest {
-
- PersistentCache cache = mock(PersistentCache.class);
- BatchWsClient wsClient = mock(BatchWsClient.class);
- AnalysisMode mode = mock(AnalysisMode.class);
-
- AnalysisWSLoaderProvider underTest = new AnalysisWSLoaderProvider();
-
- @Test
- public void testDefault() {
- WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap()));
- assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
- }
-
- @Test
- public void no_cache_by_default_in_issues_mode() {
- when(mode.isIssues()).thenReturn(true);
- WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap()));
- assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
- }
-
- @Test
- public void enable_cache_in_issues_mode() {
- when(mode.isIssues()).thenReturn(true);
- WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(ImmutableMap.of(AnalysisWSLoaderProvider.SONAR_USE_WS_CACHE, "true")));
- assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_ONLY);
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
index 95e17ca849a..4c2deee6ebb 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
@@ -20,20 +20,21 @@
package org.sonar.batch.bootstrap;
import java.io.File;
+import java.io.StringReader;
import java.util.List;
+
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
import org.sonar.core.platform.RemotePlugin;
import org.sonar.home.cache.FileCache;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -45,16 +46,19 @@ public class BatchPluginInstallerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- FileCache fileCache = mock(FileCache.class);
- BatchWsClient wsClient = mock(BatchWsClient.class);
- BatchPluginPredicate pluginPredicate = mock(BatchPluginPredicate.class);
+ private FileCache fileCache = mock(FileCache.class);
+ private BatchWsClient wsClient;
+ private BatchPluginPredicate pluginPredicate = mock(BatchPluginPredicate.class);
+
+ @Before
+ public void setUp() {
+ wsClient = mock(BatchWsClient.class);
+ }
@Test
public void listRemotePlugins() {
-
- WSLoader wsLoader = mock(WSLoader.class);
- when(wsLoader.loadString("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<>("checkstyle\nsqale", true));
- BatchPluginInstaller underTest = new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate);
+ WsTestUtil.mockReader(wsClient, "/deploy/plugins/index.txt", new StringReader("checkstyle\nsqale"));
+ BatchPluginInstaller underTest = new BatchPluginInstaller(wsClient, fileCache, pluginPredicate);
List<RemotePlugin> remotePlugins = underTest.listRemotePlugins();
assertThat(remotePlugins).extracting("key").containsOnly("checkstyle", "sqale");
@@ -65,8 +69,7 @@ public class BatchPluginInstallerTest {
File pluginJar = temp.newFile();
when(fileCache.get(eq("checkstyle-plugin.jar"), eq("fakemd5_1"), any(FileCache.Downloader.class))).thenReturn(pluginJar);
- WSLoader wsLoader = mock(WSLoader.class);
- BatchPluginInstaller underTest = new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate);
+ BatchPluginInstaller underTest = new BatchPluginInstaller(wsClient, fileCache, pluginPredicate);
RemotePlugin remote = new RemotePlugin("checkstyle").setFile("checkstyle-plugin.jar", "fakemd5_1");
File file = underTest.download(remote);
@@ -76,11 +79,9 @@ public class BatchPluginInstallerTest {
@Test
public void should_fail_to_get_plugin_index() {
+ WsTestUtil.mockException(wsClient, "/deploy/plugins/index.txt", new IllegalStateException());
thrown.expect(IllegalStateException.class);
- WSLoader wsLoader = mock(WSLoader.class);
- doThrow(new IllegalStateException()).when(wsLoader).loadString("/deploy/plugins/index.txt");
-
- new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate).installRemotes();
+ new BatchPluginInstaller(wsClient, fileCache, pluginPredicate).installRemotes();
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
index 41152b3ccb5..0019d8adc18 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
@@ -42,7 +42,7 @@ public class GlobalContainerTest {
Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(),
CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath());
- GlobalContainer container = GlobalContainer.create(props, extensions, false);
+ GlobalContainer container = GlobalContainer.create(props, extensions);
container.doBeforeStart();
return container;
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java
deleted file mode 100644
index c8f105de443..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import com.google.common.io.Files;
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.home.cache.PersistentCache;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DefaultProjectCacheStatusTest {
- @Rule
- public TemporaryFolder tmp = new TemporaryFolder();
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- ProjectCacheStatus cacheStatus;
- PersistentCache cache = mock(PersistentCache.class);
-
- @Before
- public void setUp() {
- when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath());
- cacheStatus = new DefaultProjectCacheStatus(cache);
- }
-
- @Test
- public void errorSave() throws IOException {
- when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath().resolve("unexistent_folder"));
- cacheStatus = new DefaultProjectCacheStatus(cache);
-
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Failed to write cache sync status");
- cacheStatus.save();
- }
-
- @Test
- public void errorStatus() throws IOException {
- Files.write("trash".getBytes(StandardCharsets.UTF_8), new File(tmp.getRoot(), "cache-sync-status"));
- cacheStatus = new DefaultProjectCacheStatus(cache);
-
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Failed to read cache sync status");
- cacheStatus.getSyncStatus();
- }
-
- @Test
- public void testSave() {
- cacheStatus.save();
- assertThat(cacheStatus.getSyncStatus()).isNotNull();
- assertThat(age(cacheStatus.getSyncStatus())).isLessThan(2000);
- }
-
- @Test
- public void testDelete() {
- cacheStatus.save();
- cacheStatus.delete();
- assertThat(cacheStatus.getSyncStatus()).isNull();
- }
-
- private long age(Date date) {
- return (new Date().getTime()) - date.getTime();
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java
deleted file mode 100644
index 3f019caae02..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.sonar.home.cache.PersistentCache;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
-
-import static org.junit.Assert.*;
-import static org.assertj.core.api.Assertions.assertThat;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.Rule;
-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<>();
- map.put("sonar.userHome", temp.getRoot().getAbsolutePath());
- 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")
- .resolve("global"));
- }
-
- @Test
- public void test_singleton() {
- assertTrue(provider.provide(globalProperties) == provider.provide(globalProperties));
- }
-
- @Test
- public void test_without_sonar_home() {
- globalProperties = new GlobalProperties(new HashMap<String, String>());
- PersistentCache cache = provider.provide(globalProperties);
- assertThat(cache.getDirectory().toAbsolutePath().toString()).startsWith(findHome().toAbsolutePath().toString());
-
- }
-
- private static Path findHome() {
- String home = System.getenv("SONAR_USER_HOME");
-
- if (home != null) {
- return Paths.get(home);
- }
-
- home = System.getProperty("user.home");
- return Paths.get(home, ".sonar");
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java
deleted file mode 100644
index c06bb94ca08..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import com.google.common.collect.ImmutableList;
-import java.util.Date;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.LoadedActiveRule;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-public class NonAssociatedCacheSynchronizerTest {
- private NonAssociatedCacheSynchronizer synchronizer;
-
- @Mock
- private RulesLoader rulesLoader;
- @Mock
- private QualityProfileLoader qualityProfileLoader;
- @Mock
- private ActiveRulesLoader activeRulesLoader;
- @Mock
- private ProjectCacheStatus cacheStatus;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- QualityProfile pf = QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build();
- LoadedActiveRule ar = new LoadedActiveRule();
-
- when(qualityProfileLoader.loadDefault(null, null)).thenReturn(ImmutableList.of(pf));
- when(activeRulesLoader.load("profile", null)).thenReturn(ImmutableList.of(ar));
-
- synchronizer = new NonAssociatedCacheSynchronizer(rulesLoader, qualityProfileLoader, activeRulesLoader, cacheStatus);
- }
-
- @Test
- public void dont_sync_if_exists() {
- when(cacheStatus.getSyncStatus()).thenReturn(new Date());
- synchronizer.execute(false);
- verifyZeroInteractions(rulesLoader, qualityProfileLoader, activeRulesLoader);
- }
-
- @Test
- public void always_sync_if_force() {
- when(cacheStatus.getSyncStatus()).thenReturn(new Date());
- synchronizer.execute(true);
- checkSync();
- }
-
- @Test
- public void sync_if_doesnt_exist() {
- synchronizer.execute(false);
- checkSync();
- }
-
- private void checkSync() {
- verify(cacheStatus).getSyncStatus();
- verify(cacheStatus).save();
- verify(rulesLoader).load(null);
- verify(qualityProfileLoader).loadDefault(null, null);
- verify(activeRulesLoader).load("profile", null);
-
- verifyNoMoreInteractions(qualityProfileLoader, activeRulesLoader);
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java
deleted file mode 100644
index 52df42e035d..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import org.apache.commons.lang.mutable.MutableBoolean;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.sonar.batch.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.batch.repository.DefaultQualityProfileLoader;
-import org.sonar.batch.repository.DefaultServerIssuesLoader;
-import org.sonar.batch.repository.ProjectRepositories;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.repository.user.UserRepositoryLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.DefaultActiveRulesLoader;
-import org.sonar.batch.rule.LoadedActiveRule;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-public class ProjectCacheSynchronizerTest {
- private static final String PROJECT_KEY = "org.codehaus.sonar-plugins:sonar-scm-git-plugin";
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Mock
- private ProjectDefinition project;
- @Mock
- private ProjectCacheStatus cacheStatus;
- @Mock
- private DefaultAnalysisMode analysisMode;
- @Mock
- private AnalysisProperties properties;
- @Mock
- private RulesLoader rulesLoader;
-
- private ServerIssuesLoader issuesLoader;
- private UserRepositoryLoader userRepositoryLoader;
- private QualityProfileLoader qualityProfileLoader;
- private ActiveRulesLoader activeRulesLoader;
- private ProjectRepositoriesLoader projectRepositoriesLoader;
-
- @Before
- public void setUp() throws IOException {
- MockitoAnnotations.initMocks(this);
-
- when(analysisMode.isIssues()).thenReturn(true);
- when(properties.properties()).thenReturn(new HashMap<String, String>());
- }
-
- private ProjectCacheSynchronizer createMockedLoaders(boolean projectExists, Date lastAnalysisDate) {
- issuesLoader = mock(DefaultServerIssuesLoader.class);
- userRepositoryLoader = mock(UserRepositoryLoader.class);
- qualityProfileLoader = mock(DefaultQualityProfileLoader.class);
- activeRulesLoader = mock(DefaultActiveRulesLoader.class);
- projectRepositoriesLoader = mock(DefaultProjectRepositoriesLoader.class);
-
- QualityProfile pf = QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build();
- LoadedActiveRule ar = new LoadedActiveRule();
- ProjectRepositories repo = mock(ProjectRepositories.class);
-
- when(qualityProfileLoader.load(PROJECT_KEY, null, null)).thenReturn(ImmutableList.of(pf));
- when(qualityProfileLoader.loadDefault(null, null)).thenReturn(ImmutableList.of(pf));
- when(activeRulesLoader.load("profile", null)).thenReturn(ImmutableList.of(ar));
- when(repo.lastAnalysisDate()).thenReturn(lastAnalysisDate);
- when(repo.exists()).thenReturn(projectExists);
- when(projectRepositoriesLoader.load(anyString(), anyBoolean(), any(MutableBoolean.class))).thenReturn(repo);
-
- return new ProjectCacheSynchronizer(rulesLoader, qualityProfileLoader, projectRepositoriesLoader, activeRulesLoader, issuesLoader, userRepositoryLoader, cacheStatus);
- }
-
- @Test
- public void testLoadersUsage() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
- synchronizer.load(PROJECT_KEY, false);
-
- verify(issuesLoader).load(eq(PROJECT_KEY), any(Function.class));
- verify(rulesLoader).load(null);
- verify(qualityProfileLoader).load(PROJECT_KEY, null, null);
- verify(activeRulesLoader).load("profile", null);
- verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class));
-
- verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader);
- }
-
- @Test
- public void testLoadersUsage_NoLastAnalysis() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, null);
- synchronizer.load(PROJECT_KEY, false);
-
- verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class));
- verify(qualityProfileLoader).load(PROJECT_KEY, null, null);
- verify(activeRulesLoader).load("profile", null);
-
- verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader);
- }
-
- @Test
- public void testLoadersUsage_ProjectDoesntExist() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(false, null);
- synchronizer.load(PROJECT_KEY, false);
-
- verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class));
- verify(qualityProfileLoader).loadDefault(null, null);
- verify(activeRulesLoader).load("profile", null);
-
- verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader);
- }
-
- @Test
- public void testLastAnalysisToday() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
- when(cacheStatus.getSyncStatus()).thenReturn(new Date());
- synchronizer.load(PROJECT_KEY, false);
-
- verify(cacheStatus).getSyncStatus();
- verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader, cacheStatus);
- }
-
- @Test
- public void testLastAnalysisYesterday() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
- Date d = new Date(new Date().getTime() - 60 * 60 * 24 * 1000);
- when(cacheStatus.getSyncStatus()).thenReturn(d);
- synchronizer.load(PROJECT_KEY, false);
-
- verify(cacheStatus).save();
- verify(cacheStatus).getSyncStatus();
- }
-
- @Test
- public void testDontFailOnError() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
- Date d = new Date(new Date().getTime() - 60 * 60 * 24 * 1000);
- when(cacheStatus.getSyncStatus()).thenReturn(d);
-
- when(projectRepositoriesLoader.load(anyString(), anyBoolean(), any(MutableBoolean.class))).thenThrow(IllegalStateException.class);
- synchronizer.load(PROJECT_KEY, false);
-
- verify(cacheStatus).getSyncStatus();
- verifyNoMoreInteractions(cacheStatus);
- }
-
- @Test
- public void testForce() {
- ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
- when(cacheStatus.getSyncStatus()).thenReturn(new Date());
- synchronizer.load(PROJECT_KEY, true);
-
- verify(cacheStatus).save();
- verify(cacheStatus).getSyncStatus();
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java
deleted file mode 100644
index 69c142556ae..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.sonar.api.batch.bootstrap.ProjectKey;
-
-import org.sonar.batch.util.BatchUtils;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.batch.cache.ProjectPersistentCacheProvider;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Collections;
-
-import static org.mockito.Mockito.mock;
-import org.junit.Before;
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
-
-public class ProjectPersistentCacheProviderTest {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- private ProjectPersistentCacheProvider provider = null;
- private GlobalProperties props = null;
- private DefaultAnalysisMode mode = null;
- private ProjectKey key = null;
-
- @Before
- public void prepare() {
- key = new ProjectKeySupplier("proj");
- props = new GlobalProperties(Collections.<String, String>emptyMap());
- mode = mock(DefaultAnalysisMode.class);
- provider = new ProjectPersistentCacheProvider();
- }
-
- @Test
- public void test_singleton() {
- assertThat(provider.provide(props, mode, key)).isEqualTo(provider.provide(props, mode, key));
- }
-
- @Test
- public void test_cache_dir() {
- assertThat(provider.provide(props, mode, key).getDirectory().toFile()).exists().isDirectory();
- }
-
- @Test
- public void test_home() {
- File f = temp.getRoot();
- props.properties().put("sonar.userHome", f.getAbsolutePath());
- Path expected = f.toPath()
- .resolve("ws_cache")
- .resolve("http%3A%2F%2Flocalhost%3A9000")
- .resolve( BatchUtils.getServerVersion())
- .resolve("projects")
- .resolve("proj");
-
- assertThat(provider.provide(props, mode, key).getDirectory()).isEqualTo(expected);
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java
deleted file mode 100644
index 948f888cd68..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.util.HashMap;
-import org.junit.Test;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.core.platform.ComponentContainer;
-import org.sonar.home.cache.PersistentCache;
-import org.sonar.scanner.protocol.input.ProjectRepositories;
-import org.sonarqube.ws.client.WsClient;
-
-import static org.mockito.Mockito.mock;
-
-public class ProjectSyncContainerTest {
- private ComponentContainer createParentContainer() {
- PersistentCache cache = mock(PersistentCache.class);
- WsClient server = mock(WsClient.class);
-
- GlobalProperties globalProps = new GlobalProperties(new HashMap<String, String>());
- ComponentContainer parent = new ComponentContainer();
- parent.add(cache);
- parent.add(server);
- parent.add(globalProps);
- return parent;
- }
-
- @Test
- public void testProjectRepository() {
- ProjectSyncContainer container = new ProjectSyncContainer(createParentContainer(), "my:project", true);
- container.doBeforeStart();
- container.getPicoContainer().start();
- container.getComponentByType(ProjectRepositories.class);
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java
deleted file mode 100644
index ce9d88a037c..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class StrategyWSLoaderProviderTest {
- @Mock
- private PersistentCache cache;
-
- @Mock
- private BatchWsClient client;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void testStrategy() {
- StrategyWSLoaderProvider provider = new StrategyWSLoaderProvider(LoadStrategy.CACHE_FIRST);
- WSLoader wsLoader = provider.provide(cache, client);
-
- assertThat(wsLoader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_FIRST);
- }
-
- @Test
- public void testSingleton() {
- StrategyWSLoaderProvider provider = new StrategyWSLoaderProvider(LoadStrategy.CACHE_FIRST);
- WSLoader wsLoader = provider.provide(cache, client);
-
- assertThat(provider.provide(null, null)).isEqualTo(wsLoader);
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java
deleted file mode 100644
index ad7bb763d67..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import org.apache.commons.io.IOUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-import org.sonarqube.ws.client.HttpException;
-import org.sonarqube.ws.client.MockWsResponse;
-import org.sonarqube.ws.client.WsRequest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-public class WSLoaderTest {
- private final static String ID = "dummy";
- private final static String cacheValue = "cache";
- private final static String serverValue = "server";
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- BatchWsClient ws = mock(BatchWsClient.class, Mockito.RETURNS_DEEP_STUBS);
- PersistentCache cache = mock(PersistentCache.class);
-
- @Test
- public void dont_retry_server_offline() throws IOException {
- turnServerOffline();
- when(cache.getString(ID)).thenReturn(cacheValue);
- WSLoader underTest = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
- assertResult(underTest.loadString(ID), cacheValue, true);
- assertResult(underTest.loadString(ID), cacheValue, true);
-
- assertUsedServer(1);
- assertUsedCache(2);
- }
-
- @Test
- public void get_stream_from_cache() throws IOException {
- InputStream is = IOUtils.toInputStream("is");
- when(cache.getStream(ID)).thenReturn(is);
-
- WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws);
- WSLoaderResult<InputStream> result = loader.loadStream(ID);
-
- assertThat(result.get()).isEqualTo(is);
- verify(cache).getStream(ID);
- verifyNoMoreInteractions(cache, ws);
- }
-
- @Test
- public void put_stream_in_cache() throws IOException {
- InputStream input = IOUtils.toInputStream("is");
-
- when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(input));
- when(cache.getStream(ID)).thenReturn(input);
-
- // SERVER_FIRST -> load from server then put to cache
- WSLoader underTest = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
- WSLoaderResult<InputStream> result = underTest.loadStream(ID);
- assertThat(result.get()).isEqualTo(input);
-
- InOrder inOrder = inOrder(ws, cache);
- inOrder.verify(ws).call(any(WsRequest.class));
- inOrder.verify(cache).put(eq(ID), any(InputStream.class));
- inOrder.verify(cache).getStream(ID);
- verifyNoMoreInteractions(cache, ws);
- }
-
- @Test
- public void test_cache_strategy_fallback() throws IOException {
- turnCacheEmpty();
- when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
- WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws);
-
- assertResult(loader.loadString(ID), serverValue, false);
-
- InOrder inOrder = inOrder(ws, cache);
- inOrder.verify(cache).getString(ID);
- inOrder.verify(ws).call(any(WsRequest.class));
- }
-
- @Test
- public void test_server_strategy_fallback() throws IOException {
- turnServerOffline();
- when(cache.getString(ID)).thenReturn(cacheValue);
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
- assertResult(loader.loadString(ID), cacheValue, true);
-
- InOrder inOrder = inOrder(ws, cache);
- inOrder.verify(ws).call(any(WsRequest.class));
- inOrder.verify(cache).getString(ID);
- }
-
- @Test
- public void test_put_cache() throws IOException {
- when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
- loader.loadString(ID);
- verify(cache).put(ID, serverValue.getBytes());
- }
-
- @Test
- public void test_throw_cache_exception_fallback() throws IOException {
- turnServerOffline();
-
- when(cache.getString(ID)).thenThrow(new NullPointerException());
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
- try {
- loader.loadString(ID);
- fail("NPE expected");
- } catch (NullPointerException e) {
- assertUsedServer(1);
- assertUsedCache(1);
- }
- }
-
- @Test
- public void test_throw_cache_exception() throws IOException {
- when(cache.getString(ID)).thenThrow(new IllegalStateException());
-
- WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws);
-
- try {
- loader.loadString(ID);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- assertUsedServer(0);
- assertUsedCache(1);
- }
- }
-
- @Test
- public void test_throw_http_exceptions() {
- when(ws.call(any(WsRequest.class))).thenThrow(new HttpException("url", 500));
-
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
- try {
- loader.loadString(ID);
- fail("IllegalStateException expected");
- } catch (HttpException e) {
- // cache should not be used
- verifyNoMoreInteractions(cache);
- }
- }
-
- @Test
- public void test_server_only_not_available() {
- turnServerOffline();
-
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Server is not available");
-
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws);
- loader.loadString(ID);
- }
-
- @Test
- public void test_server_cache_not_available() throws IOException {
- turnServerOffline();
- turnCacheEmpty();
-
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Server is not accessible and data is not cached");
-
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
- loader.loadString(ID);
- }
-
- @Test
- public void test_cache_only_available() throws IOException {
- turnCacheEmpty();
-
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Data is not cached");
-
- WSLoader loader = new WSLoader(LoadStrategy.CACHE_ONLY, cache, ws);
- loader.loadString(ID);
- }
-
- @Test
- public void test_server_strategy() throws IOException {
- when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
- assertResult(loader.loadString(ID), serverValue, false);
-
- // should not fetch from cache
- verify(cache).put(ID, serverValue.getBytes());
- verifyNoMoreInteractions(cache);
- }
-
- @Test(expected = IllegalStateException.class)
- public void test_server_only() throws IOException {
- turnServerOffline();
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws);
- loader.loadString(ID);
- }
-
- @Test
- public void test_string() {
- when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
- WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
- assertResult(loader.loadString(ID), serverValue, false);
- }
-
- private void assertUsedCache(int times) throws IOException {
- verify(cache, times(times)).getString(ID);
- }
-
- private void assertUsedServer(int times) {
- verify(ws, times(times)).call(any(WsRequest.class));
- }
-
- private void assertResult(WSLoaderResult<String> result, String expected, boolean fromCache) {
- assertThat(result).isNotNull();
- assertThat(result.get()).isEqualTo(expected);
- assertThat(result.isFromCache()).isEqualTo(fromCache);
- }
-
- private void turnServerOffline() {
- when(ws.call(any(WsRequest.class))).thenThrow(new IllegalStateException());
- }
-
- private void turnCacheEmpty() throws IOException {
- when(cache.getString(ID)).thenReturn(null);
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java
index 7d8ab1d2319..38102f6a5dc 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java
@@ -19,71 +19,59 @@
*/
package org.sonar.batch.issue.tracking;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.HttpDownloader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
+import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
-import static org.mockito.Matchers.any;
-
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
public class DefaultServerLineHashesLoaderTest {
+ private BatchWsClient wsClient;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Before
public void before() {
+ wsClient = mock(BatchWsClient.class);
}
@Test
public void should_download_source_from_ws_if_preview_mode() {
- WSLoader wsLoader = mock(WSLoader.class);
- when(wsLoader.loadString(anyString(), any(LoadStrategy.class))).thenReturn(new WSLoaderResult<>("ae12\n\n43fb", true));
-
- ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsLoader);
+ WsTestUtil.mockReader(wsClient, new StringReader("ae12\n\n43fb"));
+ ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsClient);
- String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c", null);
+ String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c");
assertThat(hashes).containsOnly("ae12", "", "43fb");
- verify(wsLoader).loadString("/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FBar.c", LoadStrategy.CACHE_FIRST);
+ WsTestUtil.verifyCall(wsClient, "/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FBar.c");
}
@Test
public void should_download_source_with_space_from_ws_if_preview_mode() {
- WSLoader server = mock(WSLoader.class);
- when(server.loadString(anyString(), any(LoadStrategy.class))).thenReturn(new WSLoaderResult<>("ae12\n\n43fb", true));
+ WsTestUtil.mockReader(wsClient, new StringReader("ae12\n\n43fb"));
+ ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsClient);
- ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server);
-
- MutableBoolean fromCache = new MutableBoolean();
- String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c", fromCache);
- assertThat(fromCache.booleanValue()).isTrue();
+ String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c");
assertThat(hashes).containsOnly("ae12", "", "43fb");
- verify(server).loadString("/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FFoo+Bar.c", LoadStrategy.CACHE_FIRST);
+ WsTestUtil.verifyCall(wsClient, "/api/sources/hash?key=myproject%3Aorg%2Ffoo%2FFoo+Bar.c");
}
@Test
public void should_fail_to_download_source_from_ws() throws URISyntaxException {
- WSLoader server = mock(WSLoader.class);
- when(server.loadString(anyString(), any(LoadStrategy.class))).thenThrow(new HttpDownloader.HttpException(new URI(""), 500));
-
- ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server);
+ WsTestUtil.mockException(wsClient, new HttpDownloader.HttpException(new URI(""), 500));
+ ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(wsClient);
thrown.expect(HttpDownloader.HttpException.class);
- lastSnapshots.getLineHashes("foo", null);
+ lastSnapshots.getLineHashes("foo");
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
index 9acf02b3577..d49cb46c9d7 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
+++ b/sonar-scanner-engine/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, null)).thenReturn(new String[] {md5Hex(source)});
+ when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)});
assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source));
- verify(lastSnapshots).getLineHashes(key, null);
+ verify(lastSnapshots).getLineHashes(key);
assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source));
Mockito.verifyNoMoreInteractions(lastSnapshots);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
index f405eea8785..8055f7baae6 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
@@ -31,7 +31,6 @@ import org.sonar.batch.rule.ActiveRulesLoader;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import org.sonar.batch.repository.QualityProfileLoader;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
import javax.annotation.Nullable;
@@ -43,8 +42,6 @@ import org.sonar.batch.rule.RulesLoader;
import org.sonar.scanner.protocol.input.GlobalRepositories;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
import com.google.common.base.Function;
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.Table;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -59,35 +56,19 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import javax.annotation.Nullable;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonar.api.CoreProperties;
import org.sonar.api.Plugin;
import org.sonar.api.batch.debt.internal.DefaultDebtModel;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.server.rule.RulesDefinition.Repository;
-import org.sonar.api.utils.DateUtils;
import org.sonar.batch.bootstrapper.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.batch.bootstrapper.LogOutput;
import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
import org.sonar.batch.report.ReportPublisher;
-import org.sonar.batch.repository.FileData;
import org.sonar.batch.repository.GlobalRepositoriesLoader;
-import org.sonar.batch.repository.ProjectRepositories;
import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.LoadedActiveRule;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.sonarqube.ws.Rules.ListResponse.Rule;
/**
* Main utility class for writing batch medium tests.
@@ -381,7 +362,7 @@ public class BatchMediumTester {
}
@Override
- public List<Rule> load(@Nullable MutableBoolean fromCache) {
+ public List<Rule> load() {
return rules;
}
}
@@ -394,7 +375,7 @@ public class BatchMediumTester {
}
@Override
- public List<LoadedActiveRule> load(String qualityProfileKey, MutableBoolean fromCache) {
+ public List<LoadedActiveRule> load(String qualityProfileKey) {
return activeRules;
}
}
@@ -406,7 +387,7 @@ public class BatchMediumTester {
private GlobalRepositories ref = new GlobalRepositories();
@Override
- public GlobalRepositories load(@Nullable MutableBoolean fromCache) {
+ public GlobalRepositories load() {
return ref;
}
@@ -439,7 +420,7 @@ public class BatchMediumTester {
private Date lastAnalysisDate;
@Override
- public ProjectRepositories load(String projectKey, boolean isIssuesMode, @Nullable MutableBoolean fromCache) {
+ public ProjectRepositories load(String projectKey, boolean isIssuesMode) {
Table<String, String, String> settings = HashBasedTable.create();
return new ProjectRepositories(settings, fileDataTable, lastAnalysisDate);
}
@@ -470,12 +451,12 @@ public class BatchMediumTester {
}
@Override
- public List<QualityProfile> load(String projectKey, String profileName, MutableBoolean fromCache) {
+ public List<QualityProfile> load(String projectKey, String profileName) {
return qualityProfiles;
}
@Override
- public List<QualityProfile> loadDefault(String profileName, MutableBoolean fromCache) {
+ public List<QualityProfile> loadDefault(String profileName) {
return qualityProfiles;
}
}
@@ -489,11 +470,10 @@ public class BatchMediumTester {
}
@Override
- public boolean load(String componentKey, Function<ServerIssue, Void> consumer) {
+ public void load(String componentKey, Function<ServerIssue, Void> consumer) {
for (ServerIssue serverIssue : serverIssues) {
consumer.apply(serverIssue);
}
- return true;
}
}
@@ -501,7 +481,7 @@ public class BatchMediumTester {
private Map<String, String[]> byKey = new HashMap<>();
@Override
- public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) {
+ public String[] getLineHashes(String fileKey) {
if (byKey.containsKey(fileKey)) {
return byKey.get(fileKey);
} else {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java
deleted file mode 100644
index 4ebf5eb1fa6..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.mediumtest.cache;
-
-import org.junit.rules.TemporaryFolder;
-
-import org.sonar.batch.mediumtest.TaskResult;
-import org.sonar.batch.mediumtest.BatchMediumTester.TaskBuilder;
-import org.sonar.batch.mediumtest.LogOutputRecorder;
-import org.sonar.batch.repository.FileData;
-import com.google.common.collect.ImmutableMap;
-
-import java.util.Date;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.After;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.CoreProperties;
-import org.sonar.batch.mediumtest.BatchMediumTester;
-import org.sonar.xoo.XooPlugin;
-import org.sonar.xoo.rule.XooRulesDefinition;
-
-public class CacheSyncTest {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- private BatchMediumTester tester;
-
- @After
- public void stop() {
- if (tester != null) {
- tester.stop();
- tester = null;
- }
- }
-
- @Test
- public void testExecuteTask() {
- LogOutputRecorder logOutput = new LogOutputRecorder();
-
- tester = BatchMediumTester.builder()
- .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES,
- "sonar.verbose", "true"))
- .registerPlugin("xoo", new XooPlugin())
- .addRules(new XooRulesDefinition())
- .addQProfile("lang", "name")
- .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
- .setPreviousAnalysisDate(new Date())
- .addFileData("test-project", "file1", new FileData("hash", "123456789"))
- .setLogOutput(logOutput)
- .build();
-
- tester.start();
- executeTask(tester.newTask());
- assertThat(logOutput.getAsString()).contains("Cache for project [key] not found, synchronizing");
- }
-
- @Test
- public void testSyncFirstTime() {
- LogOutputRecorder logOutput = new LogOutputRecorder();
-
- tester = BatchMediumTester.builder()
- .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES,
- "sonar.verbose", "true"))
- .registerPlugin("xoo", new XooPlugin())
- .addRules(new XooRulesDefinition())
- .addQProfile("lang", "name")
- .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
- .setPreviousAnalysisDate(new Date())
- .addFileData("test-project", "file1", new FileData("hash", "123456789"))
- .setLogOutput(logOutput)
- .build();
-
- tester.start();
- tester.syncProject("test-project");
- assertThat(logOutput.getAsString()).contains("Cache for project [test-project] not found");
- }
-
- @Test
- public void testSyncTwice() {
- LogOutputRecorder logOutput = new LogOutputRecorder();
-
- tester = BatchMediumTester.builder()
- .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES,
- "sonar.verbose", "true"))
- .registerPlugin("xoo", new XooPlugin())
- .addRules(new XooRulesDefinition())
- .addQProfile("lang", "name")
- .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
- .setPreviousAnalysisDate(new Date())
- .addFileData("test-project", "file1", new FileData("hash", "123456789"))
- .setLogOutput(logOutput)
- .build();
-
- tester.start();
- tester.syncProject("test-project");
- tester.syncProject("test-project");
- assertThat(logOutput.getAsString()).contains("-- Found project [test-project]");
- assertThat(logOutput.getAsString()).contains("not found, synchronizing data");
- assertThat(logOutput.getAsString()).contains("], synchronizing data (forced)..");
- }
-
- @Test
- public void testNonAssociated() {
- LogOutputRecorder logOutput = new LogOutputRecorder();
-
- tester = BatchMediumTester.builder()
- .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES))
- .registerPlugin("xoo", new XooPlugin())
- .addRules(new XooRulesDefinition())
- .addQProfile("lang", "name")
- .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo")
- .setPreviousAnalysisDate(new Date())
- .addFileData("test-project", "file1", new FileData("hash", "123456789"))
- .setLogOutput(logOutput)
- .build();
-
- tester.start();
- tester.syncProject(null);
-
- assertThat(logOutput.getAsString()).contains("Cache not found, synchronizing data");
- }
-
- private TaskResult executeTask(TaskBuilder builder) {
- builder.property("sonar.projectKey", "key");
- builder.property("sonar.projectVersion", "1.0");
- builder.property("sonar.projectName", "key");
- builder.property("sonar.projectBaseDir", temp.getRoot().getAbsolutePath());
- builder.property("sonar.sources", temp.getRoot().getAbsolutePath());
- return builder.start();
- }
-
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java
deleted file mode 100644
index 32c66f2689f..00000000000
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.batch.mediumtest.issuesmode;
-
-import com.google.common.collect.ImmutableMap;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.batch.mediumtest.BatchMediumTester;
-import org.sonar.batch.mediumtest.TaskResult;
-import org.sonar.xoo.XooPlugin;
-import org.sonar.xoo.rule.XooRulesDefinition;
-
-import java.io.File;
-import java.io.IOException;
-
-public class NonAssociatedProject {
- @org.junit.Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @org.junit.Rule
- public LogTester logTester = new LogTester();
-
- public BatchMediumTester tester;
-
- @Before
- public void prepare() throws IOException {
- tester = BatchMediumTester.builder()
- .bootstrapProperties(ImmutableMap.of(
- CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES,
- CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.newFolder().getAbsolutePath()))
- .registerPlugin("xoo", new XooPlugin())
- .addQProfile("xoo", "Sonar Way")
- .addRules(new XooRulesDefinition())
- .addRule("manual:MyManualIssue", "manual", "MyManualIssue", "My manual issue")
- .addRule("manual:MyManualIssueDup", "manual", "MyManualIssue", "My manual issue")
- .addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo")
- .addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo")
- .addActiveRule("xoo", "OneIssuePerModule", null, "OneIssuePerModule", "MAJOR", null, "xoo")
- .addActiveRule("manual", "MyManualIssue", null, "My manual issue", "MAJOR", null, null)
- .setAssociated(false)
- .build();
- tester.start();
- }
-
- @After
- public void stop() {
- tester.stop();
- }
-
- private File copyProject(String path) throws Exception {
- File projectDir = temp.newFolder();
- File originalProjectDir = new File(IssueModeAndReportsMediumTest.class.getResource(path).toURI());
- FileUtils.copyDirectory(originalProjectDir, projectDir, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".sonar")));
- return projectDir;
- }
-
- @Test
- public void testNonAssociated() throws Exception {
- File projectDir = copyProject("/mediumtest/xoo/multi-modules-sample-not-associated");
-
- TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
- .start();
-
- }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java
index db1a2dcd30e..2e2d8ea4c47 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java
@@ -27,7 +27,6 @@ import org.hamcrest.TypeSafeMatcher;
import org.junit.BeforeClass;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.api.utils.MessageException;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonar.batch.repository.GlobalRepositoriesLoader;
import org.sonar.scanner.protocol.input.GlobalRepositories;
import org.sonar.batch.bootstrapper.Batch;
@@ -104,7 +103,7 @@ public class ExceptionHandlingMediumTest {
boolean withCause = false;
@Override
- public GlobalRepositories load(MutableBoolean fromCache) {
+ public GlobalRepositories load() {
if (withCause) {
IllegalStateException cause = new IllegalStateException("Code 401");
throw MessageException.of("Error loading repository", cause);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java
index cb3781e5103..c902ee3658a 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java
@@ -19,60 +19,31 @@
*/
package org.sonar.batch.repository;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.junit.Before;
-import org.junit.Test;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonar.scanner.protocol.input.GlobalRepositories;
-import static org.assertj.core.api.Assertions.assertThat;
+import java.io.StringReader;
+
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
public class DefaultGlobalRepositoriesLoaderTest {
private static final String BATCH_GLOBAL_URL = "/batch/global";
- private WSLoader wsLoader;
- private WSLoaderResult<String> result;
+ private BatchWsClient wsClient;
private DefaultGlobalRepositoriesLoader globalRepositoryLoader;
@Before
public void setUp() {
- wsLoader = mock(WSLoader.class);
- result = new WSLoaderResult<>(new GlobalRepositories().toJson(), true);
- when(wsLoader.loadString(BATCH_GLOBAL_URL)).thenReturn(result);
-
- globalRepositoryLoader = new DefaultGlobalRepositoriesLoader(wsLoader);
+ wsClient = mock(BatchWsClient.class);
+ WsTestUtil.mockReader(wsClient, BATCH_GLOBAL_URL, new StringReader(new GlobalRepositories().toJson()));
+ globalRepositoryLoader = new DefaultGlobalRepositoriesLoader(wsClient);
}
- @Test
public void test() {
- MutableBoolean fromCache = new MutableBoolean();
- globalRepositoryLoader.load(fromCache);
-
- assertThat(fromCache.booleanValue()).isTrue();
- verify(wsLoader).loadString(BATCH_GLOBAL_URL);
- verifyNoMoreInteractions(wsLoader);
- }
-
- @Test
- public void testFromServer() {
- result = new WSLoaderResult<>(new GlobalRepositories().toJson(), false);
- when(wsLoader.loadString(BATCH_GLOBAL_URL)).thenReturn(result);
- MutableBoolean fromCache = new MutableBoolean();
- globalRepositoryLoader.load(fromCache);
-
- assertThat(fromCache.booleanValue()).isFalse();
- verify(wsLoader).loadString(BATCH_GLOBAL_URL);
- verifyNoMoreInteractions(wsLoader);
- }
-
- public void testWithoutArg() {
- globalRepositoryLoader.load(null);
-
- verify(wsLoader).loadString(BATCH_GLOBAL_URL);
- verifyNoMoreInteractions(wsLoader);
+ globalRepositoryLoader.load();
+ WsTestUtil.verifyCall(wsClient, BATCH_GLOBAL_URL);
+ verifyNoMoreInteractions(wsClient);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
index d633820ca83..b92301c2647 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
@@ -24,21 +24,20 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.MessageException;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonarqube.ws.WsBatch.WsProjectResponse;
import org.sonarqube.ws.client.HttpException;
+import org.sonarqube.ws.client.WsRequest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class DefaultProjectRepositoriesLoaderTest {
@@ -47,20 +46,20 @@ public class DefaultProjectRepositoriesLoaderTest {
public ExpectedException thrown = ExpectedException.none();
private DefaultProjectRepositoriesLoader loader;
- private WSLoader wsLoader;
+ private BatchWsClient wsClient;
@Before
public void prepare() throws IOException {
- wsLoader = mock(WSLoader.class);
+ wsClient = mock(BatchWsClient.class);
InputStream is = mockData();
- when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
- loader = new DefaultProjectRepositoriesLoader(wsLoader);
+ WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=foo%3F", is);
+ loader = new DefaultProjectRepositoriesLoader(wsClient);
}
@Test
public void continueOnError() {
- when(wsLoader.loadStream(anyString())).thenThrow(IllegalStateException.class);
- ProjectRepositories proj = loader.load(PROJECT_KEY, false, null);
+ when(wsClient.call(any(WsRequest.class))).thenThrow(IllegalStateException.class);
+ ProjectRepositories proj = loader.load(PROJECT_KEY, false);
assertThat(proj.exists()).isEqualTo(false);
}
@@ -68,50 +67,47 @@ public class DefaultProjectRepositoriesLoaderTest {
public void parsingError() throws IOException {
InputStream is = mock(InputStream.class);
when(is.read()).thenThrow(IOException.class);
-
- when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
- loader.load(PROJECT_KEY, false, null);
+ WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=foo%3F", is);
+ loader.load(PROJECT_KEY, false);
}
@Test(expected = IllegalStateException.class)
public void failFastHttpError() {
HttpException http = new HttpException("url", 403);
IllegalStateException e = new IllegalStateException("http error", http);
- when(wsLoader.loadStream(anyString())).thenThrow(e);
- loader.load(PROJECT_KEY, false, null);
+ WsTestUtil.mockException(wsClient, e);
+ loader.load(PROJECT_KEY, false);
}
-
+
@Test
public void failFastHttpErrorMessageException() {
thrown.expect(MessageException.class);
thrown.expectMessage("http error");
-
+
HttpException http = new HttpException("uri", 403);
MessageException e = MessageException.of("http error", http);
- when(wsLoader.loadStream(anyString())).thenThrow(e);
- loader.load(PROJECT_KEY, false, null);
+ WsTestUtil.mockException(wsClient, e);
+ loader.load(PROJECT_KEY, false);
}
@Test
public void passIssuesModeParameter() {
- loader.load(PROJECT_KEY, false, null);
- verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F");
+ loader.load(PROJECT_KEY, false);
+ WsTestUtil.verifyCall(wsClient, "/batch/project.protobuf?key=foo%3F");
- loader.load(PROJECT_KEY, true, null);
- verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F&issues_mode=true");
+ loader.load(PROJECT_KEY, true);
+ WsTestUtil.verifyCall(wsClient, "/batch/project.protobuf?key=foo%3F&issues_mode=true");
}
@Test
public void deserializeResponse() throws IOException {
- MutableBoolean fromCache = new MutableBoolean();
- loader.load(PROJECT_KEY, false, fromCache);
- assertThat(fromCache.booleanValue()).isTrue();
+ loader.load(PROJECT_KEY, false);
}
@Test
public void passAndEncodeProjectKeyParameter() {
- loader.load(PROJECT_KEY, false, null);
- verify(wsLoader).loadStream("/batch/project.protobuf?key=foo%3F");
+ loader.load(PROJECT_KEY, false);
+ WsTestUtil.verifyCall(wsClient, "/batch/project.protobuf?key=foo%3F");
}
private InputStream mockData() throws IOException {
@@ -126,9 +122,9 @@ public class DefaultProjectRepositoriesLoaderTest {
@Test
public void readRealResponse() throws IOException {
InputStream is = getTestResource("project.protobuf");
- when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
+ WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=org.sonarsource.github%3Asonar-github-plugin&issues_mode=true", is);
- ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true, null);
+ ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true);
FileData fd = proj.fileData("org.sonarsource.github:sonar-github-plugin",
"src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java");
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
index d3b4ce6b87d..8110c2a273f 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
@@ -24,8 +24,8 @@ import org.sonar.api.utils.MessageException;
import org.sonarqube.ws.QualityProfiles;
import com.google.common.io.Resources;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.Before;
@@ -38,9 +38,7 @@ import java.io.InputStream;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -49,50 +47,49 @@ public class DefaultQualityProfileLoaderTest {
public ExpectedException exception = ExpectedException.none();
private DefaultQualityProfileLoader qpLoader;
- private WSLoader ws;
+ private BatchWsClient wsClient;
private InputStream is;
@Before
public void setUp() throws IOException {
- ws = mock(WSLoader.class);
+ wsClient = mock(BatchWsClient.class);
is = mock(InputStream.class);
when(is.read()).thenReturn(-1);
- WSLoaderResult<InputStream> result = new WSLoaderResult<>(is, false);
- when(ws.loadStream(anyString())).thenReturn(result);
- qpLoader = new DefaultQualityProfileLoader(ws);
+ WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is);
+ qpLoader = new DefaultQualityProfileLoader(wsClient);
}
@Test
public void testEncoding() throws IOException {
- WSLoaderResult<InputStream> result = new WSLoaderResult<>(createEncodedQP("qp"), false);
- when(ws.loadStream(anyString())).thenReturn(result);
+ InputStream is = createEncodedQP("qp");
+ WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is);
- List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2", null);
- verify(ws).loadStream("/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232");
- verifyNoMoreInteractions(ws);
+ List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2");
+ WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232");
+ verifyNoMoreInteractions(wsClient);
assertThat(loaded).hasSize(1);
}
@Test
public void testNoProfile() throws IOException {
InputStream is = createEncodedQP();
- when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
+ WsTestUtil.mockStream(wsClient, is);
exception.expect(MessageException.class);
exception.expectMessage("No quality profiles");
- qpLoader.load("project", null, null);
- verifyNoMoreInteractions(ws);
+ qpLoader.load("project", null);
+ verifyNoMoreInteractions(wsClient);
}
@Test
public void use_real_response() throws IOException {
InputStream is = getTestResource("quality_profile_search_default");
- when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
+ WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", is);
- List<QualityProfile> loaded = qpLoader.loadDefault(null, null);
- verify(ws).loadStream("/api/qualityprofiles/search.protobuf?defaults=true");
- verifyNoMoreInteractions(ws);
+ List<QualityProfile> loaded = qpLoader.loadDefault(null);
+ WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true");
+ verifyNoMoreInteractions(wsClient);
assertThat(loaded).hasSize(1);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java
index 22416368f3f..a2e978b3b4d 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java
@@ -19,10 +19,10 @@
*/
package org.sonar.batch.repository;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonar.scanner.protocol.input.ScannerInput;
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
-import org.sonar.batch.cache.WSLoader;
import com.google.common.base.Function;
import org.junit.Before;
import org.junit.Test;
@@ -39,12 +39,12 @@ import static org.mockito.Mockito.when;
public class DefaultServerIssuesLoaderTest {
private DefaultServerIssuesLoader loader;
- private WSLoader wsLoader;
+ private BatchWsClient wsClient;
@Before
public void prepare() {
- wsLoader = mock(WSLoader.class);
- loader = new DefaultServerIssuesLoader(wsLoader);
+ wsClient = mock(BatchWsClient.class);
+ loader = new DefaultServerIssuesLoader(wsClient);
}
@Test
@@ -57,7 +57,7 @@ public class DefaultServerIssuesLoaderTest {
.writeDelimitedTo(bos);
InputStream is = new ByteArrayInputStream(bos.toByteArray());
- when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true));
+ WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is);
final List<ServerIssue> result = new ArrayList<>();
loader.load("foo", new Function<ScannerInput.ServerIssue, Void>() {
@@ -76,7 +76,7 @@ public class DefaultServerIssuesLoaderTest {
public void testError() throws IOException {
InputStream is = mock(InputStream.class);
when(is.read()).thenThrow(IOException.class);
- when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true));
+ WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is);
loader.load("foo", mock(Function.class));
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java
index 781b48a2a59..cb0490f79f5 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java
@@ -24,7 +24,6 @@ import java.util.Date;
import org.sonar.batch.repository.FileData;
import com.google.common.collect.Table;
import com.google.common.collect.HashBasedTable;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -32,7 +31,6 @@ import org.mockito.MockitoAnnotations;
import org.sonar.api.batch.bootstrap.ProjectKey;
import org.sonar.batch.analysis.DefaultAnalysisMode;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -64,52 +62,26 @@ public class ProjectRepositoriesProviderTest {
}
@Test
- public void testNonAssociated() {
- when(mode.isNotAssociated()).thenReturn(true);
- ProjectRepositories repo = provider.provide(loader, projectKey, mode);
-
- assertThat(repo.exists()).isEqualTo(false);
- verify(mode).isNotAssociated();
- verifyNoMoreInteractions(loader, projectKey, mode);
- }
-
- @Test
- public void singleton() {
- when(mode.isNotAssociated()).thenReturn(true);
- ProjectRepositories repo = provider.provide(loader, projectKey, mode);
-
- assertThat(repo.exists()).isEqualTo(false);
- verify(mode).isNotAssociated();
- verifyNoMoreInteractions(loader, projectKey, mode);
-
- repo = provider.provide(loader, projectKey, mode);
- verifyNoMoreInteractions(loader, projectKey, mode);
- }
-
- @Test
public void testValidation() {
- when(mode.isNotAssociated()).thenReturn(false);
when(mode.isIssues()).thenReturn(true);
- when(loader.load(eq("key"), eq(true), any(MutableBoolean.class))).thenReturn(project);
+ when(loader.load(eq("key"), eq(true))).thenReturn(project);
provider.provide(loader, projectKey, mode);
}
@Test
public void testAssociated() {
- when(mode.isNotAssociated()).thenReturn(false);
when(mode.isIssues()).thenReturn(false);
- when(loader.load(eq("key"), eq(false), any(MutableBoolean.class))).thenReturn(project);
+ when(loader.load(eq("key"), eq(false))).thenReturn(project);
ProjectRepositories repo = provider.provide(loader, projectKey, mode);
assertThat(repo.exists()).isEqualTo(true);
assertThat(repo.lastAnalysisDate()).isNotNull();
- verify(mode).isNotAssociated();
verify(mode, times(2)).isIssues();
verify(projectKey).get();
- verify(loader).load(eq("key"), eq(false), any(MutableBoolean.class));
+ verify(loader).load(eq("key"), eq(false));
verifyNoMoreInteractions(loader, projectKey, mode);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java
index 0cd1683b9c9..bdbdb0ea703 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java
@@ -22,7 +22,6 @@ package org.sonar.batch.repository;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.lang.mutable.MutableBoolean;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -37,7 +36,6 @@ import org.sonar.batch.rule.ModuleQProfiles;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
@@ -79,49 +77,35 @@ public class QualityProfileProviderTest {
@Test
public void testProvide() {
- when(mode.isNotAssociated()).thenReturn(false);
- when(loader.load(eq("project"), isNull(String.class), any(MutableBoolean.class))).thenReturn(response);
+ when(loader.load(eq("project"), isNull(String.class))).thenReturn(response);
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
assertResponse(qps);
- verify(loader).load(eq("project"), isNull(String.class), any(MutableBoolean.class));
- verifyNoMoreInteractions(loader);
- }
-
- @Test
- public void testNonAssociated() {
- when(mode.isNotAssociated()).thenReturn(true);
- when(loader.loadDefault(anyString(), any(MutableBoolean.class))).thenReturn(response);
- ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
- assertResponse(qps);
-
- verify(loader).loadDefault(anyString(), any(MutableBoolean.class));
+ verify(loader).load(eq("project"), isNull(String.class));
verifyNoMoreInteractions(loader);
}
@Test
public void testProjectDoesntExist() {
- when(mode.isNotAssociated()).thenReturn(false);
when(projectRepo.exists()).thenReturn(false);
- when(loader.loadDefault(anyString(), any(MutableBoolean.class))).thenReturn(response);
+ when(loader.loadDefault(anyString())).thenReturn(response);
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
assertResponse(qps);
- verify(loader).loadDefault(anyString(), any(MutableBoolean.class));
+ verify(loader).loadDefault(anyString());
verifyNoMoreInteractions(loader);
}
@Test
public void testProfileProp() {
- when(mode.isNotAssociated()).thenReturn(false);
- when(loader.load(eq("project"), eq("custom"), any(MutableBoolean.class))).thenReturn(response);
+ when(loader.load(eq("project"), eq("custom"))).thenReturn(response);
when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
assertResponse(qps);
- verify(loader).load(eq("project"), eq("custom"), any(MutableBoolean.class));
+ verify(loader).load(eq("project"), eq("custom"));
verifyNoMoreInteractions(loader);
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+ "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
@@ -129,29 +113,28 @@ public class QualityProfileProviderTest {
@Test
public void testIgnoreSonarProfileIssuesMode() {
- when(mode.isNotAssociated()).thenReturn(false);
when(mode.isIssues()).thenReturn(true);
- when(loader.load(eq("project"), (String) eq(null), any(MutableBoolean.class))).thenReturn(response);
+ when(loader.load(eq("project"), (String) eq(null))).thenReturn(response);
when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
assertResponse(qps);
- verify(loader).load(eq("project"), (String) eq(null), any(MutableBoolean.class));
+ verify(loader).load(eq("project"), (String) eq(null));
verifyNoMoreInteractions(loader);
}
@Test
public void testProfilePropDefault() {
- when(mode.isNotAssociated()).thenReturn(true);
- when(loader.loadDefault(eq("custom"), any(MutableBoolean.class))).thenReturn(response);
+ when(projectRepo.exists()).thenReturn(false);
+ when(loader.loadDefault(eq("custom"))).thenReturn(response);
when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props, mode);
assertResponse(qps);
- verify(loader).loadDefault(eq("custom"), any(MutableBoolean.class));
+ verify(loader).loadDefault(eq("custom"));
verifyNoMoreInteractions(loader);
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+ "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
index 870afd5737e..4b8982a8e74 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
@@ -21,12 +21,10 @@ package org.sonar.batch.repository.user;
import org.assertj.core.util.Lists;
-import org.sonar.batch.cache.WSLoaderResult;
import org.sonar.scanner.protocol.input.ScannerInput;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
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;
@@ -39,23 +37,21 @@ 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;
-import static org.mockito.Mockito.when;
public class UserRepositoryLoaderTest {
@Rule
public final ExpectedException exception = ExpectedException.none();
- private WSLoader wsLoader;
+ private BatchWsClient wsClient;
private UserRepositoryLoader userRepo;
@Before
public void setUp() {
- wsLoader = mock(WSLoader.class);
- userRepo = new UserRepositoryLoader(wsLoader);
+ wsClient = mock(BatchWsClient.class);
+ userRepo = new UserRepositoryLoader(wsClient);
}
@Test
@@ -66,30 +62,15 @@ public class UserRepositoryLoaderTest {
@Test
public void testLoad() throws IOException {
Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon");
- WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(userMap), true);
- when(wsLoader.loadStream("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res);
-
+ InputStream is = createUsersMock(userMap);
+ WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is);
assertThat(userRepo.load(Arrays.asList("fmallet", "sbrandhof"))).extracting("login", "name").containsOnly(tuple("fmallet", "Freddy Mallet"), tuple("sbrandhof", "Simon"));
}
@Test
- public void testFromCache() throws IOException {
- WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true);
- when(wsLoader.loadStream(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<InputStream> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true);
- when(wsLoader.loadStream("/batch/users?logins=fmallet")).thenReturn(res);
-
+ InputStream is = createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet"));
+ WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet", is);
assertThat(userRepo.load("fmallet").getName()).isEqualTo("Freddy Mallet");
}
@@ -107,9 +88,7 @@ public class UserRepositoryLoaderTest {
public void testInputStreamError() throws IOException {
InputStream is = mock(InputStream.class);
Mockito.doThrow(IOException.class).when(is).read();
- WSLoaderResult<InputStream> res = new WSLoaderResult<>(is, true);
-
- when(wsLoader.loadStream("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res);
+ WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is);
exception.expect(IllegalStateException.class);
exception.expectMessage("Unable to get user details from server");
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java
index 1e1b1f0fc3c..9e1c3b70504 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java
@@ -60,9 +60,9 @@ public class ActiveRulesProviderTest {
List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3);
List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3);
- when(loader.load(eq("qp1"), any(MutableBoolean.class))).thenReturn(qp1Rules);
- when(loader.load(eq("qp2"), any(MutableBoolean.class))).thenReturn(qp2Rules);
- when(loader.load(eq("qp3"), any(MutableBoolean.class))).thenReturn(qp3Rules);
+ when(loader.load(eq("qp1"))).thenReturn(qp1Rules);
+ when(loader.load(eq("qp2"))).thenReturn(qp2Rules);
+ when(loader.load(eq("qp3"))).thenReturn(qp3Rules);
ModuleQProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
ActiveRules activeRules = provider.provide(loader, profiles);
@@ -71,9 +71,9 @@ public class ActiveRulesProviderTest {
assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly(
RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3"));
- verify(loader).load(eq("qp1"), any(MutableBoolean.class));
- verify(loader).load(eq("qp2"), any(MutableBoolean.class));
- verify(loader).load(eq("qp3"), any(MutableBoolean.class));
+ verify(loader).load(eq("qp1"));
+ verify(loader).load(eq("qp2"));
+ verify(loader).load(eq("qp3"));
verifyNoMoreInteractions(loader);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java
index 434c84dda93..40f2c462dd2 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java
@@ -20,8 +20,8 @@
package org.sonar.batch.rule;
import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
import com.google.common.io.Resources;
import org.junit.Test;
@@ -29,21 +29,19 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
-import static org.mockito.Mockito.verify;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
import org.junit.Before;
public class DefaultActiveRulesLoaderTest {
private DefaultActiveRulesLoader loader;
- private WSLoader ws;
+ private BatchWsClient wsClient;
@Before
public void setUp() {
- ws = mock(WSLoader.class);
- loader = new DefaultActiveRulesLoader(ws);
+ wsClient = mock(BatchWsClient.class);
+ loader = new DefaultActiveRulesLoader(wsClient);
}
@Test
@@ -53,18 +51,19 @@ public class DefaultActiveRulesLoaderTest {
String req1 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=1&ps=500";
String req2 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=2&ps=500";
- when(ws.loadStream(req1)).thenReturn(new WSLoaderResult<>(response1, false));
- when(ws.loadStream(req2)).thenReturn(new WSLoaderResult<>(response2, false));
+ WsTestUtil.mockStream(wsClient, req1, response1);
+ WsTestUtil.mockStream(wsClient, req2, response2);
- Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445", null);
+ Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445");
assertThat(activeRules).hasSize(226);
assertActiveRule(activeRules);
-
- verify(ws).loadStream(req1);
- verify(ws).loadStream(req2);
- verifyNoMoreInteractions(ws);
+
+ WsTestUtil.verifyCall(wsClient, req1);
+ WsTestUtil.verifyCall(wsClient, req2);
+
+ verifyNoMoreInteractions(wsClient);
}
-
+
private static void assertActiveRule(Collection<LoadedActiveRule> activeRules) {
RuleKey key = RuleKey.of("squid", "S3008");
for (LoadedActiveRule r : activeRules) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
index a5a461c4e9f..ceaa22a494b 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
@@ -20,11 +20,9 @@
package org.sonar.batch.rule;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import org.junit.rules.ExpectedException;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
import org.sonarqube.ws.Rules.ListResponse.Rule;
import com.google.common.io.ByteSource;
import com.google.common.io.Resources;
@@ -33,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import static org.mockito.Matchers.anyString;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -43,37 +40,24 @@ public class DefaultRulesLoaderTest {
@Test
public void testParseServerResponse() throws IOException {
- WSLoader wsLoader = mock(WSLoader.class);
+ BatchWsClient wsClient = mock(BatchWsClient.class);
InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")).openBufferedStream();
- when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
- DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
- List<Rule> ruleList = loader.load(null);
+ WsTestUtil.mockStream(wsClient, is);
+ DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
+ List<Rule> ruleList = loader.load();
assertThat(ruleList).hasSize(318);
}
@Test
- public void testLoadedFromCache() throws IOException {
- WSLoader wsLoader = mock(WSLoader.class);
- InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")).openBufferedStream();
- when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
- DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
- MutableBoolean fromCache = new MutableBoolean();
- loader.load(fromCache);
-
- assertThat(fromCache.booleanValue()).isTrue();
- }
-
- @Test
public void testError() throws IOException {
- WSLoader wsLoader = mock(WSLoader.class);
+ BatchWsClient wsClient = mock(BatchWsClient.class);
InputStream is = ByteSource.wrap(new String("trash").getBytes()).openBufferedStream();
- when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
- DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
+ WsTestUtil.mockStream(wsClient, is);
+ DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
exception.expect(IllegalStateException.class);
exception.expectMessage("Unable to get rules");
- loader.load(null);
+ loader.load();
}
-
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
index 2df29eaa61a..fcf2133be83 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
@@ -19,10 +19,6 @@
*/
package org.sonar.batch.rule;
-import static org.mockito.Matchers.any;
-
-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;
@@ -35,7 +31,7 @@ public class RulesProviderTest {
@Test
public void testRuleTranslation() {
RulesLoader loader = mock(RulesLoader.class);
- when(loader.load(any(MutableBoolean.class))).thenReturn(Lists.newArrayList(getTestRule()));
+ when(loader.load()).thenReturn(Lists.newArrayList(getTestRule()));
RulesProvider provider = new RulesProvider();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
index c550bb3ba39..c10bb04dd8b 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
@@ -30,11 +30,9 @@ import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
@@ -43,8 +41,6 @@ import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.batch.analysis.AnalysisProperties;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class ProjectReactorBuilderTest {
@@ -54,13 +50,6 @@ public class ProjectReactorBuilderTest {
@Rule
public LogTester logTester = new LogTester();
- private AnalysisMode mode;
-
- @Before
- public void setUp() {
- mode = mock(AnalysisMode.class);
- }
-
@Test
public void shouldDefineSimpleProject() {
ProjectDefinition projectDefinition = loadProjectDefinition("simple-project");
@@ -332,7 +321,7 @@ public class ProjectReactorBuilderTest {
AnalysisProperties taskProperties = new AnalysisProperties(props, null);
assertThat(taskProperties.property("module1.module11.property")).isEqualTo("My module11 property");
- new ProjectReactorBuilder(taskProperties, mode).execute();
+ new ProjectReactorBuilder(taskProperties).execute();
assertThat(taskProperties.property("module1.module11.property")).isNull();
}
@@ -415,7 +404,7 @@ public class ProjectReactorBuilderTest {
@Test
public void shouldInitRootWorkDir() {
- ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null), mode);
+ ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null));
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir, Maps.<String, String>newHashMap());
@@ -424,18 +413,10 @@ public class ProjectReactorBuilderTest {
}
@Test
- public void nonAssociatedMode() {
- when(mode.isIssues()).thenReturn(true);
- ProjectDefinition project = loadProjectDefinition("multi-module-with-basedir-not-associated");
-
- assertThat(project.getKey()).isEqualTo("project");
- }
-
- @Test
public void shouldInitWorkDirWithCustomRelativeFolder() {
Map<String, String> props = Maps.<String, String>newHashMap();
props.put("sonar.working.directory", ".foo");
- ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null), mode);
+ ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null));
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir, props);
@@ -447,7 +428,7 @@ public class ProjectReactorBuilderTest {
public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
Map<String, String> props = Maps.<String, String>newHashMap();
props.put("sonar.working.directory", new File("src").getAbsolutePath());
- ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null), mode);
+ ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null));
File baseDir = new File("target/tmp/baseDir");
File workDir = builder.initRootProjectWorkDir(baseDir, props);
@@ -499,7 +480,7 @@ public class ProjectReactorBuilderTest {
private ProjectDefinition loadProjectDefinition(String projectFolder) {
Map<String, String> props = loadProps(projectFolder);
AnalysisProperties bootstrapProps = new AnalysisProperties(props, null);
- ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps, mode).execute();
+ ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps).execute();
return projectReactor.getRoot();
}
@@ -638,7 +619,7 @@ public class ProjectReactorBuilderTest {
Map<String, String> props = loadProps("simple-project");
props.put("sonar.qualitygate", "somevalue");
AnalysisProperties bootstrapProps = new AnalysisProperties(props, null);
- new ProjectReactorBuilder(bootstrapProps, mode).execute();
+ new ProjectReactorBuilder(bootstrapProps).execute();
assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property 'sonar.qualitygate' is not supported any more. It will be ignored.");
}
diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo
deleted file mode 100644
index 74d29a4fa08..00000000000
--- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.sonar.it.samples.modules.a1;
-
-public class HelloA1 {
- private int i;
- private HelloA1() {
-
- }
-
- public void hello() {
- System.out.println("hello" + " xoo");
- }
-
- protected String getHello() {
- return "hello";
- }
-} \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo
deleted file mode 100644
index 42039538a92..00000000000
--- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a2/src/main/xoo/com/sonar/it/samples/modules/a2/HelloA2.xoo
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.sonar.it.samples.modules.a2;
-
-public class HelloA2 {
- private int i;
- private HelloA2() {
-
- }
-
- public void hello() {
- System.out.println("hello" + " xoo");
- }
-} \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo
deleted file mode 100644
index b83c3af128c..00000000000
--- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b1/src/main/xoo/com/sonar/it/samples/modules/b1/HelloB1.xoo
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.sonar.it.samples.modules.b1;
-
-public class HelloB1 {
- private int i;
- private HelloB1() {
-
- }
-
- public void hello() {
- System.out.println("hello" + " world");
- }
-} \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo
deleted file mode 100644
index 20b8bb3876a..00000000000
--- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_b/module_b2/src/main/xoo/com/sonar/it/samples/modules/b2/HelloB2.xoo
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.sonar.it.samples.modules.b2;
-
-public class HelloB2 {
- private int i;
- private HelloB2() {
-
- }
-
- public void hello() {
- System.out.println("hello" + " world");
- }
-} \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties
deleted file mode 100644
index c2b00ede37c..00000000000
--- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties
+++ /dev/null
@@ -1,31 +0,0 @@
-# Root project information
-#sonar.projectKey=com.sonarsource.it.samples:multi-modules-sample
-sonar.projectName=Sonar :: Integration Tests :: Multi-modules Sample
-sonar.projectVersion=1.0-SNAPSHOT
-
-sonar.language=xoo
-
-# Some properties that will be inherited by the modules
-sonar.sources=src/main/xoo
-
-# List of the module identifiers
-sonar.modules=module_a,module_b
-
-module_a.sonar.projectKey=module_a
-module_a.sonar.projectName=Module A
-
-module_a.sonar.modules=module_a1,module_a2
-
-module_a.module_a1.sonar.projectName=Sub-module A1
-
-module_a.module_a2.sonar.projectName=Sub-module A2
-
-
-module_b.sonar.projectKey=module_b
-module_b.sonar.projectName=Module B
-
-module_b.sonar.modules=module_b1,module_b2
-
-module_b.module_b1.sonar.projectName=Sub-module B1
-
-module_b.module_b2.sonar.projectName=Sub-module B2
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf
deleted file mode 100644
index 1d417ce2880..00000000000
--- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf
+++ /dev/null
Binary files differ
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf
deleted file mode 100644
index 8b610d8f73c..00000000000
--- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf
+++ /dev/null
Binary files differ
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json
deleted file mode 100644
index 2887ce18d10..00000000000
--- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json
+++ /dev/null
@@ -1,164 +0,0 @@
-{
- "timestamp": 0,
- "qprofilesByLanguage": {
- "java": {
- "key": "java-sonar-way-72608",
- "name": "Sonar way",
- "language": "java",
- "rulesUpdatedAt": "2015-08-10T12:06:53+0200"
- }
- },
- "activeRules": [
- {
- "repositoryKey": "common-java",
- "ruleKey": "DuplicatedBlocks",
- "name": "Source files should not have any duplicated blocks",
- "severity": "MAJOR",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "common-java",
- "ruleKey": "InsufficientBranchCoverage",
- "name": "Branches should have sufficient coverage by unit tests",
- "severity": "MAJOR",
- "language": "java",
- "params": {
- "minimumBranchCoverageRatio": "65.0"
- }
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "RightCurlyBraceStartLineCheck",
- "name": "A close curly brace should be located at the beginning of a line",
- "severity": "MINOR",
- "internalKey": "RightCurlyBraceStartLineCheck",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "UselessParenthesesCheck",
- "name": "Useless parentheses around expressions should be removed to prevent any misunderstanding",
- "severity": "MAJOR",
- "internalKey": "UselessParenthesesCheck",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "ObjectFinalizeCheck",
- "name": "The Object.finalize() method should not be called",
- "severity": "CRITICAL",
- "internalKey": "ObjectFinalizeCheck",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "ObjectFinalizeOverridenCheck",
- "name": "The Object.finalize() method should not be overriden",
- "severity": "CRITICAL",
- "internalKey": "ObjectFinalizeOverridenCheck",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "ObjectFinalizeOverridenCallsSuperFinalizeCheck",
- "name": "super.finalize() should be called at the end of Object.finalize() implementations",
- "severity": "BLOCKER",
- "internalKey": "ObjectFinalizeOverridenCallsSuperFinalizeCheck",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "ClassVariableVisibilityCheck",
- "name": "Class variable fields should not have public accessibility",
- "severity": "MAJOR",
- "internalKey": "ClassVariableVisibilityCheck",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S2188",
- "name": "JUnit test cases should call super methods",
- "severity": "CRITICAL",
- "internalKey": "S2188",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S2186",
- "name": "JUnit assertions should not be used in \"run\" methods",
- "severity": "CRITICAL",
- "internalKey": "S2186",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S2187",
- "name": "TestCases should contain tests",
- "severity": "MAJOR",
- "internalKey": "S2187",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S2391",
- "name": "JUnit framework methods should be declared properly",
- "severity": "CRITICAL",
- "internalKey": "S2391",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S2325",
- "name": "\"private\" methods that don\u0027t access instance data should be \"static\"",
- "severity": "MINOR",
- "internalKey": "S2325",
- "language": "java",
- "params": {}
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S1166",
- "name": "Exception handlers should preserve the original exception",
- "severity": "CRITICAL",
- "internalKey": "S1166",
- "language": "java",
- "params": {
- "exceptions": "java.lang.InterruptedException, java.lang.NumberFormatException, java.text.ParseException, java.net.MalformedURLException"
- }
- },
- {
- "repositoryKey": "squid",
- "ruleKey": "S2970",
- "name": "Assertions should be complete",
- "severity": "CRITICAL",
- "internalKey": "S2970",
- "language": "java",
- "params": {}
- }
-
- ],
- "settingsByModule": {},
- "fileDataByModuleAndPath": {
- "org.codehaus.sonar-plugins:sonar-scm-git-plugin": {
- "src/test/java/org/sonar/plugins/scm/git/JGitBlameCommandTest.java": {
- "needBlame": true
- },
- "src/main/java/org/sonar/plugins/scm/git/GitScmProvider.java": {
- "hash": "90082117d0dc0f1189ab7e4990a20667",
- "needBlame": true
- }
- }
- },
- "lastAnalysisDate": "2015-08-10T13:20:09+0200"
-} \ No newline at end of file
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf
+++ /dev/null