From 22f39e39acdf84be933aab9d6c1b10455e0e4033 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 27 Aug 2015 16:58:34 +0200 Subject: [PATCH] SONAR-6577 Offline mode in issues mode --- .../org/sonar/batch/bootstrap/ExtensionInstallerTest.java | 8 ++++---- .../main/java/org/sonar/home/cache/PersistentCache.java | 4 +++- .../java/org/sonar/home/cache/PersistentCacheTest.java | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java index aef314012ca..42adfd1d3fc 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java @@ -62,7 +62,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, Bar.class)); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); installer.install(container, new FooMatcher()); assertThat(container.getComponentByType(Foo.class)).isNotNull(); @@ -74,7 +74,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooProvider(), new BarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); installer.install(container, new FooMatcher()); @@ -87,7 +87,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(new FooBarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); installer.install(container, new TrueMatcher()); @@ -100,7 +100,7 @@ public class ExtensionInstallerTest { when(pluginRepository.getPluginInfos()).thenReturn(Arrays.asList(new PluginInfo("foo"))); when(pluginRepository.getPluginInstance("foo")).thenReturn(newPluginInstance(Foo.class, MavenExtension.class, AntExtension.class, new BarProvider())); ComponentContainer container = new ComponentContainer(); - ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode); + ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); installer.install(container, new TrueMatcher()); diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java index 2193f5a1ba4..c5c45090ed4 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java @@ -76,7 +76,9 @@ public class PersistentCache { @CheckForNull public synchronized String getString(@Nonnull String obj, @Nullable final PersistentCacheLoader valueLoader) throws IOException { - byte[] cached = get(obj, new ValueLoaderDecoder(valueLoader)); + ValueLoaderDecoder decoder = valueLoader != null ? new ValueLoaderDecoder(valueLoader) : null; + + byte[] cached = get(obj, decoder); if (cached == null) { return null; diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java index 72f594bf7d1..9760b096676 100644 --- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java +++ b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java @@ -20,7 +20,6 @@ package org.sonar.home.cache; import java.io.File; -import java.io.IOException; import org.apache.commons.io.FileUtils; import org.junit.Before; @@ -55,6 +54,12 @@ public class PersistentCacheTest { assertThat(cache.get(URI, null)).isNull(); assertCacheHit(false); } + + @Test + public void testNullLoaderString() throws Exception { + assertThat(cache.getString(URI, null)).isNull(); + assertCacheHit(false); + } @Test public void testNullValue() throws Exception { -- 2.39.5