aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-10 10:26:33 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-12 16:12:50 +0200
commit3dfd88128803a86d614d4085a19c004e230f73ef (patch)
tree85dd85f8a99aa19da5c491a01b70290da2b816f7 /sonar-batch
parentda0e7d2eb596eeed136301cdaa38523ff8c86d54 (diff)
downloadsonarqube-3dfd88128803a86d614d4085a19c004e230f73ef.tar.gz
sonarqube-3dfd88128803a86d614d4085a19c004e230f73ef.zip
SONAR-6776 Global cache sync
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java15
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/WSLoader.java1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java12
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalWSLoaderProvider.java)17
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalWSLoaderProviderTest.java)35
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java14
9 files changed, 45 insertions, 63 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index feab390e969..aa9faaf72e6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -19,8 +19,10 @@
*/
package org.sonar.batch.bootstrap;
-import org.sonar.batch.scan.ProjectAnalysisMode;
+import org.sonar.batch.bootstrap.WSLoader.LoadStrategy;
+import org.sonar.batch.cache.StrategyWSLoaderProvider;
+import org.sonar.batch.scan.ProjectAnalysisMode;
import org.sonar.batch.cache.ProjectSyncContainer;
import org.sonar.batch.rule.RulesLoader;
import org.sonar.batch.rule.DefaultRulesLoader;
@@ -53,14 +55,16 @@ import org.sonar.core.util.DefaultHttpDownloader;
public class GlobalContainer extends ComponentContainer {
private final Map<String, String> bootstrapProperties;
+ private boolean forceSync;
- private GlobalContainer(Map<String, String> bootstrapProperties) {
+ private GlobalContainer(Map<String, String> bootstrapProperties, boolean forceSync) {
super();
this.bootstrapProperties = bootstrapProperties;
+ this.forceSync = forceSync;
}
- public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions) {
- GlobalContainer container = new GlobalContainer(bootstrapProperties);
+ public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions, boolean forceSync) {
+ GlobalContainer container = new GlobalContainer(bootstrapProperties, forceSync);
container.add(extensions);
return container;
}
@@ -68,6 +72,8 @@ public class GlobalContainer extends ComponentContainer {
@Override
protected void doBeforeStart() {
BootstrapProperties bootstrapProps = new BootstrapProperties(bootstrapProperties);
+ StrategyWSLoaderProvider wsLoaderProvider = forceSync ? new StrategyWSLoaderProvider(LoadStrategy.SERVER_ONLY) : new StrategyWSLoaderProvider(LoadStrategy.SERVER_FIRST);
+ add(wsLoaderProvider);
add(bootstrapProps);
addBootstrapComponents();
}
@@ -94,7 +100,6 @@ public class GlobalContainer extends ComponentContainer {
UriReader.class,
new FileCacheProvider(),
new PersistentCacheProvider(),
- new GlobalWSLoaderProvider(),
System2.INSTANCE,
DefaultI18n.class,
Durations.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WSLoader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WSLoader.java
index f231b473a1d..5d9930630bd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WSLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WSLoader.java
@@ -33,7 +33,6 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.sonar.batch.bootstrap.WSLoader.ServerStatus.*;
-import static org.sonar.batch.bootstrap.WSLoader.LoadStrategy.*;
import org.sonar.home.cache.PersistentCache;
public class WSLoader {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
index 12e564c5fcd..14070c17d21 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/Batch.java
@@ -89,12 +89,16 @@ public final class Batch {
* @since 4.4
*/
public synchronized Batch start() {
+ return start(false);
+ }
+
+ public synchronized Batch start(boolean forceSync) {
if (started) {
throw new IllegalStateException("Batch is already started");
}
configureLogging();
- bootstrapContainer = GlobalContainer.create(bootstrapProperties, components);
+ bootstrapContainer = GlobalContainer.create(bootstrapProperties, components, forceSync);
bootstrapContainer.startComponents();
this.started = true;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java
index 9ebfd52034a..c8b96b2e599 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java
@@ -21,8 +21,6 @@ package org.sonar.batch.cache;
import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.batch.bootstrap.BootstrapProperties;
-import org.sonar.batch.bootstrap.GlobalMode;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.bootstrap.WSLoader;
import org.sonar.batch.bootstrap.WSLoader.LoadStrategy;
@@ -36,7 +34,7 @@ public class StrategyWSLoaderProvider extends ProviderAdapter {
this.strategy = strategy;
}
- public WSLoader provide(BootstrapProperties props, GlobalMode mode, PersistentCache cache, ServerClient client) {
+ public WSLoader provide(PersistentCache cache, ServerClient client) {
if (wsLoader == null) {
wsLoader = new WSLoader(strategy, cache, client);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
index d358861b21d..45b85452929 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
@@ -19,15 +19,15 @@
*/
package org.sonar.batch.repository;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.batch.scan.ProjectAnalysisMode;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.batch.bootstrap.AbstractServerLoader;
import org.sonar.batch.bootstrap.WSLoaderResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.bootstrap.AnalysisProperties;
-import org.sonar.batch.bootstrap.GlobalMode;
import org.sonar.batch.bootstrap.WSLoader;
import org.sonar.batch.protocol.input.ProjectRepositories;
import org.sonar.batch.rule.ModuleQProfiles;
@@ -39,11 +39,11 @@ public class DefaultProjectRepositoriesLoader extends AbstractServerLoader imple
private static final String BATCH_PROJECT_URL = "/batch/project";
private final WSLoader wsLoader;
- private final GlobalMode globalMode;
+ private final ProjectAnalysisMode analysisMode;
- public DefaultProjectRepositoriesLoader(WSLoader wsLoader, GlobalMode globalMode) {
+ public DefaultProjectRepositoriesLoader(WSLoader wsLoader, ProjectAnalysisMode analysisMode) {
this.wsLoader = wsLoader;
- this.globalMode = globalMode;
+ this.analysisMode = analysisMode;
}
@Override
@@ -55,7 +55,7 @@ public class DefaultProjectRepositoriesLoader extends AbstractServerLoader imple
+ "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
url += "&profile=" + BatchUtils.encodeForUrl(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP));
}
- url += "&preview=" + globalMode.isIssues();
+ url += "&preview=" + analysisMode.isIssues();
ProjectRepositories projectRepositories = ProjectRepositories.fromJson(load(url));
validateProjectRepositories(projectRepositories);
return projectRepositories;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
index ac87c52fa51..d701489cca4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class GlobalContainerTest {
@Test
public void should_add_components() {
- GlobalContainer container = GlobalContainer.create(Collections.<String, String>emptyMap(), Collections.emptyList());
+ GlobalContainer container = GlobalContainer.create(Collections.<String, String>emptyMap(), Collections.emptyList(), false);
container.doBeforeStart();
assertThat(container.getComponentByType(Logback.class)).isNotNull();
@@ -41,7 +41,7 @@ public class GlobalContainerTest {
@Test
public void should_add_bootstrap_extensions() {
- GlobalContainer container = GlobalContainer.create(Collections.<String, String>emptyMap(), Lists.newArrayList(Foo.class, new Bar()));
+ GlobalContainer container = GlobalContainer.create(Collections.<String, String>emptyMap(), Lists.newArrayList(Foo.class, new Bar()), false);
container.doBeforeStart();
assertThat(container.getComponentByType(Foo.class)).isNotNull();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalWSLoaderProvider.java b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java
index f89c4a3afed..7e4ce898915 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalWSLoaderProvider.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java
@@ -17,21 +17,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.batch.bootstrap;
+package org.sonar.batch.cache;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.batch.bootstrap.WSLoader.LoadStrategy;
+public class ProjectCacheSynchronizerTest {
-import org.sonar.home.cache.PersistentCache;
-
-public class GlobalWSLoaderProvider extends ProviderAdapter {
- private static final LoadStrategy DEFAULT_STRATEGY = LoadStrategy.SERVER_ONLY;
- private WSLoader wsLoader;
-
- public WSLoader provide(BootstrapProperties props, GlobalMode mode, PersistentCache cache, ServerClient client) {
- if (wsLoader == null) {
- wsLoader = new WSLoader(DEFAULT_STRATEGY, cache, client);
- }
- return wsLoader;
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalWSLoaderProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java
index 1ae0c36ab2f..d55fe8bcbee 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalWSLoaderProviderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java
@@ -17,47 +17,36 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.batch.bootstrap;
+package org.sonar.batch.cache;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.sonar.batch.bootstrap.WSLoader.LoadStrategy;
-import org.junit.Test;
+import org.sonar.batch.bootstrap.WSLoader;
import org.junit.Before;
-import org.sonar.home.cache.PersistentCache;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.sonar.batch.bootstrap.ServerClient;
+import org.mockito.Mock;
+import org.sonar.home.cache.PersistentCache;
+import org.junit.Test;
+import org.sonar.batch.bootstrap.WSLoader.LoadStrategy;
-public class GlobalWSLoaderProviderTest {
+public class StrategyWSLoaderProviderTest {
@Mock
private PersistentCache cache;
@Mock
private ServerClient client;
- @Mock
- private GlobalMode mode;
-
- private GlobalWSLoaderProvider loaderProvider;
- private Map<String, String> propMap;
- private BootstrapProperties props;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- loaderProvider = new GlobalWSLoaderProvider();
}
@Test
- public void testDefault() {
- propMap = new HashMap<>();
- props = new BootstrapProperties(propMap);
+ public void testStrategy() {
+ StrategyWSLoaderProvider provider = new StrategyWSLoaderProvider(LoadStrategy.CACHE_FIRST);
+ WSLoader wsLoader = provider.provide(cache, client);
- WSLoader wsLoader = loaderProvider.provide(props, mode, cache, client);
- assertThat(wsLoader.getStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
+ assertThat(wsLoader.getStrategy()).isEqualTo(LoadStrategy.CACHE_FIRST);
}
-
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
index 32f5fe36f59..5e846897aa4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.repository;
+import org.sonar.batch.scan.ProjectAnalysisMode;
+
import org.apache.commons.io.IOUtils;
import org.sonar.batch.bootstrap.WSLoaderResult;
import com.google.common.collect.Maps;
@@ -27,7 +29,6 @@ import java.io.IOException;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -35,7 +36,6 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.bootstrap.AnalysisProperties;
-import org.sonar.batch.bootstrap.GlobalMode;
import org.sonar.batch.bootstrap.WSLoader;
import org.sonar.batch.protocol.input.ProjectRepositories;
import org.sonar.batch.protocol.input.QProfile;
@@ -53,15 +53,15 @@ public class DefaultProjectRepositoriesLoaderTest {
private DefaultProjectRepositoriesLoader loader;
private WSLoader wsLoader;
- private GlobalMode globalMode;
+ private ProjectAnalysisMode analysisMode;
private ProjectDefinition project;
private AnalysisProperties taskProperties;
@Before
public void prepare() {
wsLoader = mock(WSLoader.class);
- globalMode = mock(GlobalMode.class);
- loader = new DefaultProjectRepositoriesLoader(wsLoader, globalMode);
+ analysisMode = mock(ProjectAnalysisMode.class);
+ loader = new DefaultProjectRepositoriesLoader(wsLoader, analysisMode);
loader = spy(loader);
when(wsLoader.loadString(anyString())).thenReturn(new WSLoaderResult<>("{}", true));
taskProperties = new AnalysisProperties(Maps.<String, String>newHashMap(), "");
@@ -71,11 +71,11 @@ public class DefaultProjectRepositoriesLoaderTest {
public void passPreviewParameter() {
addQualityProfile();
project = ProjectDefinition.create().setKey("foo");
- when(globalMode.isIssues()).thenReturn(false);
+ when(analysisMode.isIssues()).thenReturn(false);
loader.load(project, taskProperties);
verify(wsLoader).loadString("/batch/project?key=foo&preview=false");
- when(globalMode.isIssues()).thenReturn(true);
+ when(analysisMode.isIssues()).thenReturn(true);
loader.load(project, taskProperties);
verify(wsLoader).loadString("/batch/project?key=foo&preview=true");
}