From 35997d8bbebb20e87f78ab1d7a7a77ab28cf16a9 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Fri, 13 May 2016 10:35:18 +0200 Subject: [PATCH] SONAR-7367 Remove code previously used by SonarLint --- .../test/java/it/analysis/IssuesModeTest.java | 29 -- .../org/sonar/home/cache/PersistentCache.java | 281 ------------------ .../home/cache/PersistentCacheBuilder.java | 110 ------- .../cache/PersistentCacheInvalidation.java | 27 -- .../home/cache/TTLCacheInvalidation.java | 48 --- .../cache/PersistentCacheBuilderTest.java | 77 ----- .../sonar/home/cache/PersistentCacheTest.java | 145 --------- .../home/cache/TTLCacheInvalidationTest.java | 55 ---- .../analysis/AnalysisWSLoaderProvider.java | 49 --- .../batch/analysis/DefaultAnalysisMode.java | 15 - .../batch/bootstrap/BatchPluginInstaller.java | 21 +- .../batch/bootstrap/GlobalContainer.java | 28 +- .../org/sonar/batch/bootstrapper/Batch.java | 4 +- .../cache/DefaultProjectCacheStatus.java | 80 ----- .../cache/GlobalPersistentCacheProvider.java | 55 ---- .../cache/NonAssociatedCacheSynchronizer.java | 96 ------ .../sonar/batch/cache/ProjectCacheStatus.java | 30 -- .../batch/cache/ProjectCacheSynchronizer.java | 185 ------------ .../sonar/batch/cache/ProjectKeySupplier.java | 36 --- .../cache/ProjectPersistentCacheProvider.java | 67 ----- .../batch/cache/ProjectSyncContainer.java | 93 ------ .../batch/cache/StrategyWSLoaderProvider.java | 41 --- .../java/org/sonar/batch/cache/WSLoader.java | 240 --------------- .../org/sonar/batch/cache/WSLoaderResult.java | 41 --- .../org/sonar/batch/cache/package-info.java | 23 -- .../DefaultServerLineHashesLoader.java | 43 ++- .../issue/tracking/ServerIssueRepository.java | 6 +- .../tracking/ServerLineHashesLoader.java | 6 +- .../issue/tracking/SourceHashHolder.java | 2 +- .../DefaultGlobalRepositoriesLoader.java | 30 +- .../DefaultProjectRepositoriesLoader.java | 23 +- .../DefaultQualityProfileLoader.java | 28 +- .../repository/DefaultServerIssuesLoader.java | 18 +- .../repository/GlobalRepositoriesLoader.java | 6 +- .../GlobalRepositoriesProvider.java | 7 +- .../repository/ProjectRepositoriesLoader.java | 5 +- .../ProjectRepositoriesProvider.java | 20 +- .../repository/QualityProfileLoader.java | 7 +- .../repository/QualityProfileProvider.java | 11 +- .../batch/repository/ServerIssuesLoader.java | 2 +- .../repository/user/UserRepositoryLoader.java | 37 +-- .../sonar/batch/rule/ActiveRulesLoader.java | 6 +- .../sonar/batch/rule/ActiveRulesProvider.java | 14 +- .../batch/rule/DefaultActiveRulesLoader.java | 22 +- .../sonar/batch/rule/DefaultRulesLoader.java | 23 +- .../org/sonar/batch/rule/RulesLoader.java | 4 +- .../org/sonar/batch/rule/RulesProvider.java | 7 +- .../batch/scan/ProjectReactorBuilder.java | 15 +- .../batch/scan/ProjectScanContainer.java | 8 - .../batch/scan/filesystem/FileIndexer.java | 3 +- .../java/org/sonar/batch/task/ScanTask.java | 23 -- .../test/java/org/sonar/batch/WsTestUtil.java | 96 ++++++ .../AnalysisWSLoaderProviderTest.java | 62 ---- .../bootstrap/BatchPluginInstallerTest.java | 33 +- .../batch/bootstrap/GlobalContainerTest.java | 2 +- .../cache/DefaultProjectCacheStatusTest.java | 91 ------ .../GlobalPersistentCacheProviderTest.java | 83 ------ .../NonAssociatedCacheSynchronizerTest.java | 93 ------ .../cache/ProjectCacheSynchronizerTest.java | 197 ------------ .../ProjectPersistentCacheProviderTest.java | 80 ----- .../batch/cache/ProjectSyncContainerTest.java | 52 ---- .../cache/StrategyWSLoaderProviderTest.java | 59 ---- .../org/sonar/batch/cache/WSLoaderTest.java | 264 ---------------- .../DefaultServerLineHashesLoaderTest.java | 44 +-- .../issue/tracking/SourceHashHolderTest.java | 4 +- .../batch/mediumtest/BatchMediumTester.java | 36 +-- .../batch/mediumtest/cache/CacheSyncTest.java | 155 ---------- .../issuesmode/NonAssociatedProject.java | 89 ------ .../log/ExceptionHandlingMediumTest.java | 3 +- .../DefaultGlobalRepositoriesLoaderTest.java | 51 +--- .../DefaultProjectRepositoriesLoaderTest.java | 58 ++-- .../DefaultQualityProfileLoaderTest.java | 39 ++- .../DefaultServerIssuesLoaderTest.java | 14 +- .../ProjectRepositoriesProviderTest.java | 34 +-- .../QualityProfileProviderTest.java | 39 +-- .../user/UserRepositoryLoaderTest.java | 41 +-- .../batch/rule/ActiveRulesProviderTest.java | 12 +- .../rule/DefaultActiveRulesLoaderTest.java | 29 +- .../batch/rule/DefaultRulesLoaderTest.java | 36 +-- .../sonar/batch/rule/RulesProviderTest.java | 6 +- .../batch/scan/ProjectReactorBuilderTest.java | 31 +- .../sonar/it/samples/modules/a1/HelloA1.xoo | 16 - .../sonar/it/samples/modules/a2/HelloA2.xoo | 12 - .../sonar/it/samples/modules/b1/HelloB1.xoo | 12 - .../sonar/it/samples/modules/b2/HelloB2.xoo | 12 - .../sonar-project.properties | 31 -- .../api_rules_list.protobuf | Bin 27390 -> 0 bytes .../batch_issues.protobuf | Bin 788 -> 0 bytes .../batch_project.json | 164 ---------- .../batch_users.protobuf | 0 90 files changed, 408 insertions(+), 3924 deletions(-) delete mode 100644 sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java delete mode 100644 sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java delete mode 100644 sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheInvalidation.java delete mode 100644 sonar-home/src/main/java/org/sonar/home/cache/TTLCacheInvalidation.java delete mode 100644 sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java delete mode 100644 sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java delete mode 100644 sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoader.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java create mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java delete mode 100644 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 delete mode 100644 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 delete mode 100644 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 delete mode 100644 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 delete mode 100644 sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties delete mode 100644 sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf delete mode 100644 sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf delete mode 100644 sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json delete mode 100644 sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf diff --git a/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java b/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java index 8f0a8c826ca..9f6e3c0e2b3 100644 --- a/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java +++ b/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java @@ -209,22 +209,6 @@ public class IssuesModeTest { ItUtils.assertIssuesInJsonReport(result, 3, 0, 17); } - @Test - public void non_associated_mode() throws IOException { - restoreProfile("one-issue-per-line.xml"); - setDefaultQualityProfile("xoo", "one-issue-per-line"); - SonarRunner runner = configureRunnerIssues("shared/xoo-sample-non-associated", null); - BuildResult result = orchestrator.executeBuild(runner); - - assertThat(result.getLogs()).contains("Local analysis"); - assertThat(result.getLogs()).contains("Cache not found, synchronizing data"); - assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); - - result = orchestrator.executeBuild(runner); - assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); - assertThat(result.getLogs()).contains("Found cache"); - } - // SONAR-5715 @Test public void test_issues_mode_on_project_with_space_in_filename() throws IOException { @@ -302,19 +286,6 @@ public class IssuesModeTest { assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(16); } - // SONAR-7100 - @Test - public void enable_issues_cache() throws Exception { - File homeDir = runFirstAnalysisAndFlagIssueAsWontFix(); - - // Second issues mode using same cache dir and enable cache - SonarRunner runner = configureRunnerIssues("shared/xoo-sample", homeDir, "sonar.useWsCache", "true"); - BuildResult result = orchestrator.executeBuild(runner); - - // False positive is still visible since we are using cached issues - assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(17); - } - private File runFirstAnalysisAndFlagIssueAsWontFix() throws IOException { restoreProfile("one-issue-per-line.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample"); 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 deleted file mode 100644 index 6a00267e9d8..00000000000 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java +++ /dev/null @@ -1,281 +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.home.cache; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; -import static java.nio.file.StandardOpenOption.WRITE; - -public class PersistentCache { - private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); - private static final Charset ENCODING = StandardCharsets.UTF_8; - private static final String DIGEST_ALGO = "MD5"; - - private final PersistentCacheInvalidation invalidation; - private final Logger logger; - private final Path dir; - private DirectoryLock lock; - - public PersistentCache(Path dir, PersistentCacheInvalidation invalidation, Logger logger, DirectoryLock lock) { - this.dir = dir; - this.invalidation = invalidation; - this.logger = logger; - this.lock = lock; - - reconfigure(); - logger.debug("cache: " + dir); - } - - public synchronized void reconfigure() { - try { - Files.createDirectories(dir); - } catch (IOException e) { - throw new IllegalStateException("failed to create cache dir", e); - } - } - - public Path getDirectory() { - return dir; - } - - @CheckForNull - public synchronized String getString(@Nonnull String obj) throws IOException { - byte[] cached = get(obj); - - if (cached == null) { - return null; - } - - return new String(cached, ENCODING); - } - - @CheckForNull - public synchronized InputStream getStream(@Nonnull String obj) throws IOException { - String key = getKey(obj); - - try { - lock(); - Path path = getCacheCopy(key); - if (path == null) { - return null; - } - return new DeleteFileOnCloseInputStream(new FileInputStream(path.toFile()), path); - - } finally { - unlock(); - } - } - - @CheckForNull - public synchronized byte[] get(@Nonnull String obj) throws IOException { - String key = getKey(obj); - - try { - lock(); - - byte[] cached = getCache(key); - - if (cached != null) { - logger.debug("cache hit for " + obj + " -> " + key); - return cached; - } - - logger.debug("cache miss for " + obj + " -> " + key); - } finally { - unlock(); - } - - return null; - } - - public synchronized void put(@Nonnull String obj, @Nonnull InputStream stream) throws IOException { - String key = getKey(obj); - try { - lock(); - putCache(key, stream); - } finally { - unlock(); - } - } - - public synchronized void put(@Nonnull String obj, @Nonnull byte[] value) throws IOException { - String key = getKey(obj); - try { - lock(); - putCache(key, value); - } finally { - unlock(); - } - } - - /** - * Deletes all cache entries - */ - public synchronized void clear() { - logger.info("cache: clearing"); - try { - lock(); - deleteCacheEntries(new DirectoryClearFilter()); - } catch (IOException e) { - logger.error("Error clearing cache", e); - } finally { - unlock(); - } - } - - /** - * Deletes cache entries that are no longer valid according to the default expiration time period. - */ - public synchronized void clean() { - logger.info("cache: cleaning"); - try { - lock(); - deleteCacheEntries(new DirectoryCleanFilter()); - } catch (IOException e) { - logger.error("Error cleaning cache", e); - } finally { - unlock(); - } - } - - private void lock() throws IOException { - lock.lock(); - } - - private void unlock() { - lock.unlock(); - } - - private static String getKey(String uri) { - try { - String key = uri; - MessageDigest digest = MessageDigest.getInstance(DIGEST_ALGO); - digest.update(key.getBytes(StandardCharsets.UTF_8)); - return byteArrayToHex(digest.digest()); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("Couldn't create hash", e); - } - } - - private void deleteCacheEntries(DirectoryStream.Filter filter) throws IOException { - try (DirectoryStream stream = Files.newDirectoryStream(dir, filter)) { - for (Path p : stream) { - try { - Files.delete(p); - } catch (Exception e) { - logger.error("Error deleting " + p, e); - } - } - } - } - - private class DirectoryClearFilter implements DirectoryStream.Filter { - @Override - public boolean accept(Path entry) throws IOException { - return !lock.getFileLockName().equals(entry.getFileName().toString()); - } - } - - private class DirectoryCleanFilter implements DirectoryStream.Filter { - @Override - public boolean accept(Path entry) throws IOException { - if (lock.getFileLockName().equals(entry.getFileName().toString())) { - return false; - } - - return invalidation.test(entry); - } - } - - private void putCache(String key, byte[] value) throws IOException { - Path cachePath = getCacheEntryPath(key); - Files.write(cachePath, value, CREATE, WRITE, TRUNCATE_EXISTING); - } - - private void putCache(String key, InputStream stream) throws IOException { - Path cachePath = getCacheEntryPath(key); - Files.copy(stream, cachePath, StandardCopyOption.REPLACE_EXISTING); - } - - private byte[] getCache(String key) throws IOException { - Path cachePath = getCacheEntryPath(key); - - if (!validateCacheEntry(cachePath)) { - return null; - } - - return Files.readAllBytes(cachePath); - } - - private Path getCacheCopy(String key) throws IOException { - Path cachePath = getCacheEntryPath(key); - - if (!validateCacheEntry(cachePath)) { - return null; - } - - Path temp = Files.createTempFile("sonar_cache", null); - Files.copy(cachePath, temp, StandardCopyOption.REPLACE_EXISTING); - return temp; - } - - private boolean validateCacheEntry(Path cacheEntryPath) throws IOException { - if (!Files.exists(cacheEntryPath)) { - return false; - } - - if (invalidation.test(cacheEntryPath)) { - logger.debug("cache: evicting entry"); - Files.delete(cacheEntryPath); - return false; - } - - return true; - } - - private Path getCacheEntryPath(String key) { - return dir.resolve(key); - } - - public static String byteArrayToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - return new String(hexChars); - } -} diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java deleted file mode 100644 index b34ee09277d..00000000000 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java +++ /dev/null @@ -1,110 +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.home.cache; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; - -import javax.annotation.Nullable; - -/** - * Cache files will be placed in 3 areas: - *
- *   <sonar_home>/ws_cache/<server_url>-<version>/projects/<project>/
- *   <sonar_home>/ws_cache/<server_url>-<version>/global/
- *   <sonar_home>/ws_cache/<server_url>-<version>/local/
- * 
- */ -public class PersistentCacheBuilder { - private static final long DEFAULT_EXPIRE_DURATION = TimeUnit.MILLISECONDS.convert(9999L, TimeUnit.DAYS); - private static final String DIR_NAME = "ws_cache"; - - private Path cacheBasePath; - private Path relativePath; - private final Logger logger; - - public PersistentCacheBuilder(Logger logger) { - this.logger = logger; - } - - public PersistentCacheBuilder setAreaForProject(String serverUrl, String serverVersion, String projectKey) { - relativePath = Paths.get(sanitizeFilename(serverUrl)) - .resolve(sanitizeFilename(serverVersion)) - .resolve("projects") - .resolve(sanitizeFilename(projectKey)); - return this; - } - - public PersistentCacheBuilder setAreaForGlobal(String serverUrl) { - relativePath = Paths.get(sanitizeFilename(serverUrl)) - .resolve("global"); - return this; - } - - public PersistentCacheBuilder setAreaForLocalProject(String serverUrl, String serverVersion) { - relativePath = Paths.get(sanitizeFilename(serverUrl)) - .resolve(sanitizeFilename(serverVersion)) - .resolve("local"); - return this; - } - - public PersistentCacheBuilder setSonarHome(@Nullable Path p) { - if (p != null) { - this.cacheBasePath = p.resolve(DIR_NAME); - } - return this; - } - - public PersistentCache build() { - if (relativePath == null) { - throw new IllegalStateException("area must be set before building"); - } - if (cacheBasePath == null) { - setSonarHome(findHome()); - } - Path cachePath = cacheBasePath.resolve(relativePath); - DirectoryLock lock = new DirectoryLock(cacheBasePath, logger); - PersistentCacheInvalidation criteria = new TTLCacheInvalidation(DEFAULT_EXPIRE_DURATION); - return new PersistentCache(cachePath, criteria, logger, lock); - } - - 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"); - } - - private static String sanitizeFilename(String name) { - try { - return URLEncoder.encode(name, StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("Couldn't sanitize filename: " + name, e); - } - } -} diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheInvalidation.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheInvalidation.java deleted file mode 100644 index 184730a4cca..00000000000 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheInvalidation.java +++ /dev/null @@ -1,27 +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.home.cache; - -import java.io.IOException; -import java.nio.file.Path; - -public interface PersistentCacheInvalidation { - boolean test(Path cacheEntryPath) throws IOException; -} diff --git a/sonar-home/src/main/java/org/sonar/home/cache/TTLCacheInvalidation.java b/sonar-home/src/main/java/org/sonar/home/cache/TTLCacheInvalidation.java deleted file mode 100644 index e871e87bb0a..00000000000 --- a/sonar-home/src/main/java/org/sonar/home/cache/TTLCacheInvalidation.java +++ /dev/null @@ -1,48 +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.home.cache; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; - -public class TTLCacheInvalidation implements PersistentCacheInvalidation { - private final long durationToExpireMs; - - public TTLCacheInvalidation(long durationToExpireMs) { - this.durationToExpireMs = durationToExpireMs; - } - - @Override - public boolean test(Path cacheEntryPath) throws IOException { - BasicFileAttributes attr = Files.readAttributes(cacheEntryPath, BasicFileAttributes.class); - long modTime = attr.lastModifiedTime().toMillis(); - - long age = System.currentTimeMillis() - modTime; - - if (age > durationToExpireMs) { - return true; - } - - return false; - } - -} diff --git a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java b/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java deleted file mode 100644 index 56ed229db43..00000000000 --- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java +++ /dev/null @@ -1,77 +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.home.cache; - -import java.nio.file.Files; -import java.nio.file.Paths; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; -import static org.mockito.Mockito.mock; - -public class PersistentCacheBuilderTest { - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void user_home_property_can_be_null() { - PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(null).setAreaForGlobal("url").build(); - assertTrue(Files.isDirectory(cache.getDirectory())); - assertThat(cache.getDirectory()).endsWith(Paths.get("url", "global")); - } - - @Test - public void set_user_home() { - PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setSonarHome(temp.getRoot().toPath()).setAreaForGlobal("url").build(); - - assertThat(cache.getDirectory()).isDirectory(); - assertThat(cache.getDirectory()).startsWith(temp.getRoot().toPath()); - assertTrue(Files.isDirectory(cache.getDirectory())); - } - - @Test - public void read_system_env() { - assumeTrue(System.getenv("SONAR_USER_HOME") == null); - - System.setProperty("user.home", temp.getRoot().getAbsolutePath()); - - PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url").build(); - assertTrue(Files.isDirectory(cache.getDirectory())); - assertThat(cache.getDirectory()).startsWith(temp.getRoot().toPath()); - } - - @Test - public void directories() { - System.setProperty("user.home", temp.getRoot().getAbsolutePath()); - - PersistentCache cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForProject("url", "0", "proj").build(); - assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "0", "projects", "proj")); - - cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForLocalProject("url", "0").build(); - assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "0", "local")); - - cache = new PersistentCacheBuilder(mock(Logger.class)).setAreaForGlobal("url").build(); - assertThat(cache.getDirectory()).endsWith(Paths.get(".sonar", "ws_cache", "url", "global")); - } -} 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 deleted file mode 100644 index 1c149a44b0f..00000000000 --- a/sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java +++ /dev/null @@ -1,145 +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.home.cache; - -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; - -import static org.mockito.Matchers.any; - -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.verify; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -public class PersistentCacheTest { - private final static String URI = "key1"; - private final static String VALUE = "cache content"; - private PersistentCache cache = null; - private DirectoryLock lock = null; - private PersistentCacheInvalidation invalidation = null; - - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); - - @Before - public void setUp() throws IOException { - invalidation = mock(PersistentCacheInvalidation.class); - when(invalidation.test(any(Path.class))).thenReturn(false); - lock = mock(DirectoryLock.class); - when(lock.getFileLockName()).thenReturn("lock"); - cache = new PersistentCache(tmp.getRoot().toPath(), invalidation, mock(Logger.class), lock); - } - - @Test - public void testCacheMiss() throws Exception { - assertCacheHit(false); - } - - @Test - public void testClean() throws Exception { - Path lockFile = cache.getDirectory().resolve("lock"); - // puts entry - cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); - Files.write(lockFile, "test".getBytes(StandardCharsets.UTF_8)); - assertCacheHit(true); - when(invalidation.test(any(Path.class))).thenReturn(true); - cache.clean(); - when(invalidation.test(any(Path.class))).thenReturn(false); - assertCacheHit(false); - // lock file should not get deleted - assertThat(new String(Files.readAllBytes(lockFile), StandardCharsets.UTF_8)).isEqualTo("test"); - } - - @Test - public void testStream() throws IOException { - cache.put("id", "test".getBytes()); - InputStream stream = cache.getStream("id"); - assertThat(IOUtils.toString(stream)).isEqualTo("test"); - - assertThat(cache.getStream("non existing")).isNull(); - } - - @Test - public void testClear() throws Exception { - Path lockFile = cache.getDirectory().resolve("lock"); - cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); - Files.write(lockFile, "test".getBytes(StandardCharsets.UTF_8)); - assertCacheHit(true); - cache.clear(); - assertCacheHit(false); - // lock file should not get deleted - assertThat(new String(Files.readAllBytes(lockFile), StandardCharsets.UTF_8)).isEqualTo("test"); - } - - @Test - public void testCacheHit() throws Exception { - cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); - assertCacheHit(true); - } - - @Test - public void testReconfigure() throws Exception { - assertCacheHit(false); - cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); - assertCacheHit(true); - - File root = tmp.getRoot(); - FileUtils.deleteQuietly(root); - - // should re-create cache directory and start using the cache - cache.reconfigure(); - assertThat(root).exists(); - - assertCacheHit(false); - cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); - assertCacheHit(true); - } - - @Test - public void testExpiration() throws Exception { - when(invalidation.test(any(Path.class))).thenReturn(true); - cache.put(URI, VALUE.getBytes(StandardCharsets.UTF_8)); - assertCacheHit(false); - } - - private void assertCacheHit(boolean hit) throws Exception { - assertCacheHit(cache, hit); - } - - private void assertCacheHit(PersistentCache pCache, boolean hit) throws Exception { - String expected = hit ? VALUE : null; - assertThat(pCache.getString(URI)).isEqualTo(expected); - verify(lock, atLeast(1)).unlock(); - } - -} diff --git a/sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java b/sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java deleted file mode 100644 index 4f60b66d46e..00000000000 --- a/sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.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.home.cache; - -import org.junit.Before; - -import java.io.IOException; -import java.nio.file.Path; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; - -public class TTLCacheInvalidationTest { - private Path testFile; - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Before - public void setUp() throws IOException { - testFile = temp.newFile().toPath(); - } - - @Test - public void testExpired() throws IOException { - TTLCacheInvalidation invalidation = new TTLCacheInvalidation(-100); - assertThat(invalidation.test(testFile)).isEqualTo(true); - } - - @Test - public void testValid() throws IOException { - TTLCacheInvalidation invalidation = new TTLCacheInvalidation(100_000); - assertThat(invalidation.test(testFile)).isEqualTo(false); - } -} 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 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 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 bootstrapProperties; - private boolean preferCache; - private GlobalContainer(Map bootstrapProperties, boolean preferCache) { + private GlobalContainer(Map bootstrapProperties) { super(); this.bootstrapProperties = bootstrapProperties; - this.preferCache = preferCache; } - public static GlobalContainer create(Map bootstrapProperties, List extensions, boolean preferCache) { - GlobalContainer container = new GlobalContainer(bootstrapProperties, preferCache); + public static GlobalContainer create(Map 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 getKeys(Collection qProfiles) { - List 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 qProfiles = qualityProfileLoader.loadDefault(null, null); - profiler.stopInfo(); - - profiler.startInfo("Load default active rules"); - Collection 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 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 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 getKeys(Collection qProfiles) { - List list = new ArrayList<>(qProfiles.size()); - for (QualityProfile qp : qProfiles) { - list.add(qp.getKey()); - } - - return list; - } - - private static class UserLoginAccumulator implements Function { - Set 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 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 stringServerLoader = new DataLoader() { - @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 stringCacheLoader = new DataLoader() { - @Override - public String load(String id) throws IOException { - return cache.getString(id); - } - }; - - private DataLoader streamServerLoader = new DataLoader() { - @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 streamCacheLoader = new DataLoader() { - @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 loadStream(String id) { - return load(id, defautLoadStrategy, streamServerLoader, streamCacheLoader); - } - - @Nonnull - public WSLoaderResult loadString(String id) { - return loadString(id, defautLoadStrategy); - } - - @Nonnull - public WSLoaderResult loadString(String id, WSLoader.LoadStrategy strategy) { - return load(id, strategy, stringServerLoader, stringCacheLoader); - } - - @Nonnull - private WSLoaderResult load(String id, WSLoader.LoadStrategy strategy, DataLoader serverLoader, DataLoader 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 WSLoaderResult loadFromCacheFirst(String id, DataLoader cacheLoader, @Nullable DataLoader 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 WSLoaderResult loadFromServerFirst(String id, DataLoader serverLoader, @Nullable DataLoader 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 load(String id) throws IOException; - } - - private WSLoaderResult loadFromCache(String id, DataLoader 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 WSLoaderResult loadFromServer(String id, DataLoader 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 { - 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 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 byComponent(BatchComponent component) { @@ -85,7 +85,7 @@ public class ServerIssueRepository { return null; } } - + public Iterable 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 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 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 loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) { + public List 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 load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache) { + public List 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 loadResource(String url, @Nullable MutableBoolean fromCache) { - WSLoaderResult result = wsLoader.loadStream(url); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } - InputStream is = result.get(); + private List 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 consumer) { - WSLoaderResult result = wsLoader.loadStream("/batch/issues.protobuf?key=" + BatchUtils.encodeForUrl(componentKey)); - parseIssues(result.get(), consumer); - return result.isFromCache(); + public void load(String componentKey, Function 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 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 load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache); - - List loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache); + List load(String projectKey, @Nullable String profileName); + + List 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 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 consumer); + void load(String componentKey, Function 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 load(List userLogins) { - return load(userLogins, null); - } - - /** - * Not cache friendly. Should not be used if a cache hit is expected. - */ - public Collection load(List 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 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 { 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 load(String qualityProfileKey, @Nullable MutableBoolean fromCache); + List 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 qProfileKeys = getKeys(qProfiles); Map loadedRulesByKey = new HashMap<>(); @@ -62,7 +60,7 @@ public class ActiveRulesProvider extends ProviderAdapter { try { for (String qProfileKey : qProfileKeys) { Collection 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 load(ActiveRulesLoader loader, String qProfileKey, MutableBoolean fromCache) throws IOException { - return loader.load(qProfileKey, fromCache); + private static List load(ActiveRulesLoader loader, String qProfileKey) throws IOException { + return loader.load(qProfileKey); } private static Collection 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 load(String qualityProfileKey, @Nullable MutableBoolean fromCache) { + public List load(String qualityProfileKey) { List ruleList = new LinkedList<>(); int page = 1; int pageSize = 500; int loaded = 0; while (true) { - WSLoaderResult 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 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 load(@Nullable MutableBoolean fromCache) { - WSLoaderResult result = wsLoader.loadStream(RULES_SEARCH_URL); - ListResponse list = loadFromStream(result.get()); - if (fromCache != null) { - fromCache.setValue(result.isFromCache()); - } + public List 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 load(@Nullable MutableBoolean fromCache); + List 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 loadedRules = ref.load(fromCache); + List 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 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 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 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 { + 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.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.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 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 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 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()); - 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()); - } - - 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.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()); - 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 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 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 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 load(@Nullable MutableBoolean fromCache) { + public List load() { return rules; } } @@ -394,7 +375,7 @@ public class BatchMediumTester { } @Override - public List load(String qualityProfileKey, MutableBoolean fromCache) { + public List 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 settings = HashBasedTable.create(); return new ProjectRepositories(settings, fileDataTable, lastAnalysisDate); } @@ -470,12 +451,12 @@ public class BatchMediumTester { } @Override - public List load(String projectKey, String profileName, MutableBoolean fromCache) { + public List load(String projectKey, String profileName) { return qualityProfiles; } @Override - public List loadDefault(String profileName, MutableBoolean fromCache) { + public List loadDefault(String profileName) { return qualityProfiles; } } @@ -489,11 +470,10 @@ public class BatchMediumTester { } @Override - public boolean load(String componentKey, Function consumer) { + public void load(String componentKey, Function consumer) { for (ServerIssue serverIssue : serverIssues) { consumer.apply(serverIssue); } - return true; } } @@ -501,7 +481,7 @@ public class BatchMediumTester { private Map 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 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 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 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 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 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 loaded = qpLoader.loadDefault(null, null); - verify(ws).loadStream("/api/qualityprofiles/search.protobuf?defaults=true"); - verifyNoMoreInteractions(ws); + List 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 result = new ArrayList<>(); loader.load("foo", new Function() { @@ -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; @@ -63,53 +61,27 @@ public class ProjectRepositoriesProviderTest { when(projectKey.get()).thenReturn("key"); } - @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 userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon"); - WSLoaderResult 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 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 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 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 qp2Rules = ImmutableList.of(r2, r3); List 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 activeRules = loader.load("c+-test_c+-values-17445", null); + Collection 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 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 ruleList = loader.load(null); + WsTestUtil.mockStream(wsClient, is); + DefaultRulesLoader loader = new DefaultRulesLoader(wsClient); + List 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.newHashMap(), null), mode); + ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.newHashMap(), null)); File baseDir = new File("target/tmp/baseDir"); File workDir = builder.initRootProjectWorkDir(baseDir, Maps.newHashMap()); @@ -423,19 +412,11 @@ public class ProjectReactorBuilderTest { assertThat(workDir).isEqualTo(new File(baseDir, ".sonar")); } - @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 props = Maps.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 props = Maps.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 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 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 1d417ce28801b53269cfb9b0ddac41442f9e4e68..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 27390 zcmb`QTXS5;wcq2ackkYVAtk0#WwXhd*}eO+F8}pkt6QyS zt$)!UUtW$!_rC2t@BMUXe^kxR&dPpSjHbJMLGz#(Rps=0>7TeyyW`oUUu0+Hu&A=? zVmuoTvWwpHBI{-KW7)tS$i`=x^i3DpupAXt>uK|4KY1{_8kYUuv>4nUj{DClUeR9k ziqUxLUo*PS2JxZnRG(`7Zm!$zv-0Yy7(5-7)03i_O1JC&vuwtP*;GCa<3BC3qMTk7 zlWbC4j-MBUY&>CxFN;Cz@0uOIl`hT!Guq|nliqp33)bY{u}@u-WJUV^huP_MGJ@7_ zv;V(-*kfTE<9^pZN*+pvZG-GLJ8A6T{Yh`szetAJu}|K3r2pebtshtaFe?W?{l(L& zVE3!z-h_?4D5|2`y(s$6mR|LR`@Mf6yQ&|_dXw>NG{}mVR}(rb$D_D*>_^y$={V!- z=OREocK))gc&3ECJgGw-FCjVzGRKt-5vHS#zpVbLVuZwaIXw|qw|%M zi%HQNgjJM%nUsSfVvzf;kh&R;d2mO1lu?$%xPqMY_GvVO1PZT(@76>5xFm3VGr)BV_9+m_B~TxU-t&BPel z%;NiXaE)G7ya&i}kD2Y&V{5N!chb0(!{YK3gY>*NDSM}^(DSk?Ps<@zI82mos;i=3 zo|R1TAawK39*?`@QE##o{^D}?_^5mIc;^WVYW6yj2N5>E3gff0tgNaTR{GP>8^YUO zYm1Q3xZCbYQO$6z1&3q=zGz%&&hr5(_ddYo$}! zo{ocbn;>3_y*e2q8@=JMYCWo7$9jkqO5^g!_|B`@DUK}8s=3nc^ApT))$5C(_J*!C zt$RWgH*MgX?$5hOV#eUqeWHx0fM}aIQHD}hO(S{P!)zhK?CO-Krp4s47|5KmnM_)= zX*hntUl4G5X&pD-x?ykKaNE1%;Si(5*x1&+%d6@2@}02UNSW9TkrVNmY6A*>BEGI_ zRdtUnMaNd88GSo!`5^prXE;oy2wOi%I_qVp zCDsDvLtuIgBNY-HgbF#0+s50A5G{}k^90l28Y(BkauxkaEhK;abTk}VCSk_ zn*YE(IyN<$USAc}-Kb3>E|@vl-Q}I*{Zu&X4pkGfFLCpH*7~I0!1mgj`d=FN+b4y$ zyttu(*v=caLEYpyJpOYu7qdG$_fXi7&caXKhyFKF()`kcQPt33=)}MwA+q#}6AU2_ zirSR@;;{F!yqsO`j{u}4R;ph-KqfAhUiF1*CqG4`i$Xi~0H|q*#Fq_<;;P|Lx7XF7 z(zsjq$KzpvXYLE2o1aH19-pnNy$y!Fv#mam#%=6kpQe*pA32K8Dx?wnnT;@$9&M>h z^B$me64n~{&{mw)-g2LHYu_CEl9dyChy4H#BX$nGF zWUN>jjz{PB%V~8owhtCLGDAFAR@eG{806pVG8Y~yz@@saX6u$-@wt0v=lQrCh!K@- z8N|neaJT*(dj6~K)|O14Ki#7z#ZZw0a|@~&mm%0>ESci#HFcP zJE41B00W}!HTT{(V!~pVwUH2Hk25YuU{cf6R=3fG!hyWqb|1SgVltRvr_DwmBRqRA zi~fxLZ!D+cs8zg}0zX0DRcdGQykn5ABX(w?Bb{DM#xF7y=yHq`8jpa?BB5B?BACq9 ze~%H00KAUjyiV?3y3db1$QRGUR2zUXtR}WmLkz|DnHN;Cc+1#5LSC^f*~T4l6%pLc zf8Du59~fA1zN3P$)Q3!}Cu*-dVE4~=c-1MI0w56BS-U1(D7Db>d$E0NC%b`P4=R&b zH)bk3B8~g4S|=9eRenU5aa051f7)GL%~$g!-@3LUv~1M7tVKhx2LfSwCtt~=8Ic5K zC|@H$>1->iph3|d&xXU}vEq_Ao`zVk@w`Pj=W`n!m z*Z~137_5$a{|61ud)-l^4+U$T?M?T)?!|aAz1J@%{TYnHaC{E_^X4|llsZBSUq`G) zc4f6$9F zl%hd&){tdq&E-)=;zQmhn_dX4J;S^Y(G*X5C2*c~Fq>mAyT7N;>0~_2&IrD04x`Fkc_vYi zcx;*%7chPD7Yo0AOf;Qb&zndBEun@2bQ@mR0O+$T~xx05HT&hX6H{tb* z8bz0bC2EmqI`>lJ|4U$LZ-=wP@Y5S#v z-f1zcx@w0WkEi#Gr)Zlw>(_keereBzweqvjzKcX2)(NQCP#X8x9Q`+*P;JOK@@7&f z5{Y3z)<)un5;Ncd5#ZnB)HsD7ch^=|GBg|{sV7OHg@ z#oMnQ7&&SS^xAI$;K8%pRO~vC&e$yFTLS^!`ae;p?>;GEopxuF;WbGkc!=^$LF@DY z_HU=6?8rSt4mdJij~jp#RXNQJsbV(k8f_l~-tLp@e^>M-$+;jd{_BE|0%Vx{vaKN{S;QmL>id;*ic# z?~vzPW`nkJw|pWojglQAR(q3)@Qe)--p3f*VVFqk_Ntm68VBJX=qmARalWa%_mfBS zEprW9ZFiud9FE$|k`I7`LkXi0OB)@Kt+JQ`;J^$*a7Dcjz_Imh{gQT@fD!jcs``&G^i( zfsoPHDczTEnSZ1qAYMp=#bASEti-yFtk^oaKBh;5Z)5|7typBlWL~%g_hdF2dG}4W zK!Av%pc)*qrCa8gXx!hOAf*UASy_wyM4BoFA;2>7Ss+YkG;ukJxae{fFJTSPnfO=) z3(9J=hKmViy{T?bTKH3Hi^Mb|SbU6E@!mf}_lrq^x`fu~1)`pE-HycS4 zBWEGW7sTPoIQ~O)On-AI0mSIMCSh%YulU@3QU5SwRfN`z6IB6J%1w4Xp$9z>2pNTJ z+BW~Gi1HP%WRAq}tbeg*(~t4DYyG#ltRji3Zqm5P4^Q6B85E`b z8MYXaVE=m%Wc_C(m?=vDfK(`djBg6 zB#%Q3f2b_@(&CR}*jdLWa}tnfZ3JK{UCJl4H#_byk*>sWh@>k=;aNxTfLE#^Su0B< z8=k1;Nu;RNe2Y>dZNj%hDgj2*vwPL_ni>kRyab&1Rwf_UP_`K6P;<63RLI;nIcO|H ziHYS20w|WVXgv$!sdF*6f(oC6D6YRm;R2&8Wy56av4O7Jlkhx~P%*9UK>h6Ak>pu84QBzA{)7M}1rE%FqMFb(>r6 zi^o1m{$Q`0Ek6*dC=nk*9Ew*agF8eylZ>Afyk~ihzoeO2HCm~w+|HG}rEzy%Nt*oS z(HTy)k!j>1sS29*CR50AiVh{ikdlZUrKEBick5NL9G>s&9$6ItD312)dWt+|$x4`; z4-avzB}GDuxnI^QD!qgj0i+2+sdE(QecSTzG;U+3v4gJ>YqnZwK-=g)Bm>Nq$IWTn z{R3D^C`vN+mXlowvc1C8;86f*D5y&XmOc$iL!h2`*p7^Z&XcFYxV`PO5*pD;vKg3a zXv}*o$LO9$XzJmuNbBE+dAzNtJM7Lkv2w`__-nrJJ66C%<2rMB3;zhfT{6LN zL>Mp2U)+BGHVcL*OKP?*kQ2LM%nXg&M_!^B;G>{qahh6&7WP1L20q@z2El-N3=Y$N z0d-bN3@R#;un`Pcc{m!kd)T7}PuWvKW*-Y`l!BKF5Vy8Rlj3SfB<}M`Qe4OL4g6=$ zt}V`PMarJiqM3k?!`P$zlv5U`6;pAV*uxh1*4_D{7*XobuhRy#Z4Tu?o^(kt6k{-o zE6*uRyI%qZ`{MGJ2b$ks2=E&cf#q=v5TT4xl#$`sqiOQA?3TPqO** zd~mL^mglQ(d4GhOlJ9pIO?rBz&ejD5ItJs}^N!nbbHfP9oH&RebOx>jK1n)Hou&}` zRSHhpYuma=G;ZxnDTmI^BsT?l@@zf~Of4Rcok#`Hp4cW<${757-QBNC#_GMokJ87L z6y8Fk5&KQfwblo*qj>D1C`pRHp#0McXw!HArLeF<7bO`@L^60jaV#LF~AO)8fikCmi4QiG%9DK-L~uAZNQ^|B!Lt#Zi*>Z-J6dyZ3mR%{0`Hc51&NdMG!c%F8Db*? z^_hD#onHAg;uH3o!K_eo?f+T~x`fWy)%}6QQ;G8l^GYBI{c3iJ#@!;b#VQiJ)CH~! zo{p1|xIwGdrE$M@5BGn6xJUh5uZE|*(UPu%n&7uJ*zjwx0ngYwomssQc#32SX}CJY z;SGlFM~cVV8)^V)++8Wwt}#ShPFc#y3`nLBSu1b)MQc6mg$~~+CJGvV&LzRGtO|l8At!LUW9gTtO$+!^ht5%i)k0gjaWi8GnyapVFfzPq?Nr(jJJ)_ zm*%u{mjhxntsJSrI9(qFvcV~zUNuPD&ZfE;8rKcr-W`%vTcOg(DUcsgjjG{c4G7fi zu#_MHN$6t5k%Yb;`eBXT;r`>le6w@#bk8+X^&N|1XyL| zA15o@QKFth{srVEX$PUu8B(%6s&I#GUaxw?5B zchxog?1akP@5pD@R^;cq*ZpB}znH!#ijfzaicoC9r|w-V{OikiI7WR$Podxce6*p6fKXqOMx*xDOxd~cORYvjJUw!93^jRuZtbb zY24Ps;g~(gooHoJ+~;Nw;$LL3Q@5CuinQ0Z)UeXH?L#ZwnCAq&4XT&{J<*X#0Dm_O zi{pt&ucZV0a-DVB8>!G(@bH@N+=rCa0b3|uO_EBrEDOOX(?EhHn)6k-Aasf7k|2@k zsMn(*8lg&qDk+Ugd{slbyuLyRJ40;I{8?JyNSCU8G;VueaQqoCJL+#VdCrG5#J^ID zk%eLwUwf3AoHZre>3GY1x<3Lx`?m|Fpnxl3=>y~nBNs&@?QvS3&miI&;dQ=l$*c9; z-8z|E-_z`yFE|R1`@O^{vz#ejK!z>-wBB|b3(yg9k{$qx)db!Q$aIaAtyyt3fBCjq z`J6I^lSXCLo7w6}r3j{3H+E=!!yOz~#cTj=Mp^o$m;LNqf)SxpsWm@-^7xA?avFZ# zY7+^=Dhgf6&&Z_UU8`2AV!6ePG;RwsBgtb-Oq^!AlH)$zNLXiu1(MzL^ zlr1EZ{YOn7?5X1DEqCgDZCm118uy+B`Fd1K(jC#q$n)ezi0Z?xrxkL{ThRy2YwJct zLc*HLaSnM!Hq;WHx~NE^_OIZcn=R;?sLqBHf!H15|YI339f z)$mid{jd?-UR+qdXLm&-`(*GUCk@I=iu^~N9###gtLNuqJL9-W*V z12m;(=|(h62_ffZQP%o+nrwk`iqg109V@8QK{Up9P`@89UH2tUM{a0t#Cw;5v0u;@xK_B4#-lp|9|+i&}L@*dJP zUJ*j^cAXFSSxD?^Ww_acr9~gQ+rF0A7m?3t9LpMTS5gbcST(66Rry_SY@+ycfYYkm zQes~mo$Ppzg4qBy=a-ysL-H;SGxKfp1Dw6trbKTxq@w8iD`d=L)_m@Nj==2KJ5lKN zN8Q=!UQC>sdHSC3i8tf(^E1$s*=iz0NF`X9o!(1QY-u8bHPo1khSEbL$HR7e84-X_ zNz16T$XQ5wplEP0gP%MnMb_$=f{)H|eByv-3cEPym_eLo!7STM*JRD%fF z9Zzp~TiEI(yJ-h>>1^A*Bk(Csld6&7OzI9IG^V9M6^*q+R<` ziId}rNA8$xCoX)W>MN#}k><@Wb$-CHg32C?)Hbats{uwEbIm z2MIYNK8sqO3#wlsT;=GMmQz#uZ2pAoSQM){l`}%9!Ln|dccy`5-R%t_v^b*gCn4F# zhg$A(qjr@=hg?ddp0=I!lEys@+G`eLSUyAJ>uRxJI$%76Kuf=2@#PMvQ`3s{u8h26 zhP$&#rZp*VOn`)Ef}DU|!l;#mS&n%FHjv!5EG!Kd@w^6$2>s9Ts~#aiBT&*4Xgt2b zsR%75hu@7#DO*w%5l@I($)QKrK#1FR1rLq;QnCq$qC|#g zL*)Y-$G!D%F)Jp=z0II4Qj5CEO#HiMmqi(aG|VNX?YK9ca;O)-s{(_(YjT0gv^hZM zgEPd?zrO*V?W_&~^@dy99}$g^x#s2%%pz4E;cP2aMoNn&0*5Z^v8)(?Euk)w1>5CT zDt2*~q}zEsiSp|2u=C8+AHi>KVO(S0#nlN?(E_|pXhKGJ0v>S8~cQ@_;&G#ZsG` zO;}eJ(185{->D9sah`GhTr(gt{;E;XZU-G0Z|*)0z|72I5XG<>QAT~>+Hn1MT311r zb@qnQSkph~p4XOM)>M4VnEUN84;Y}xlv}nxXbPteHO|LXT>)dl#ZXf0*q4&FJ9Wj; zFZCUgpc)grm3?Xn`2pnL_0p@qa_=r4nG8qlHyxyY6-BnFbG7Y`sQe$C0+kXGP)3Yn zj5Pxu)=g$Cc?1NA=vX|H8c_iR+)N`C!)egQd&K-p;~wqAQw4CIA^pKxE_$zRe|YI> z!5oCP(y%zSCR}u*G#HK0l127;m&##cjOus2iAb|Z6Ju868@ltmrYJfU#m=gDJqEk! z{@?B%Oky7frgBZg`R-Sr>$31LBhae}R(^KS`%dbd{OM8K1Po3*htPaEGnh-`#tHzoWy`J$qk-@YHCBnO8HLI-kNB8d zk9@0C4u@j(>!8(dH_5Fdf7Z&o=huGg){f=N*tN=-uCxCQ2! z-Ls?Wc1c^KwrSH?AsTmgr`AXCd@O$13;( z{*`o?h4-2ROVu&ZFG(7Og;iutS#I(0av{c(&5{>zx9GYds7i%!t=)RcYJ@ zTp4(L_<*;2^Cw9VjHUqG#u5c95ogZrML=}@6IUQtO7eCtJtA0;%T5yOQkUX|6%qcJ z;#2+IgjMK@!Cn7m|2P9SikZIQODTpL2xZc&7F;uyl*Sz%j3sXq zXC+o6FklubVU;*LZE=-fUef-;SqfTHh*MvN^FJfIq+>L1LQ>^F{V0L$@nu+8yH=wozc6PDz<}vP_vRU%A2~PZ5sDTtAFJ%P_=?aYjwCYCES67!{P(OxN*744u~?C z0p~%vgRiN)>VA`G0R`3EBn?FcyN~vEzv`a+;b8B>qlXWFxTYq|5FILH-v@ht#uiK2s$zHZlU9usO_<;A)T$eg(yMD0(|Ti)hh{p-lTwTh=*0%Egrn2}$f!(RetrHsm^4P9_ z)FbRmjeohH>CI^9Eg9bIjN1|^i%FwW?n%*v294|Zght9m1i2?Z!QL4UjL{{tVch+A za-ANgZm(__Z@jU=VQO?q648xw2pS%nDHNN z?OOGv*O>DSWo4yt|F-59sug9n#lkM%xoc$xoSN`CefVaiHNxKQZ6^I4}Yy%1wM`Y zVy>TNd?ilcweMkqo?=XrT5Te7L4p#PZ@$sNri7hN{68Fm!Z#ZC8;q%V4XxSovMz4C zG0N8ej-L7U+_e^60)Ht>y>X+(5B;IL*!}-}nFYZWKvPW`KHqW>TF#S#_Eo*&kd*+m z?;_09uvJ0MwT?H0z2W+rXv;1OXwC^F1?Ptp(>37rs@?oWj8s zb0ZI2S)-6}RXN|B#&Ow~#?TTT1YP&eASD!{FMVrIu5{=IGT^CX7R+0}@*C&$nZ=_E zz&YL>4-??|~xz|l1b+4;--x-a2$LCh9R3>!OiZtw8 zX%TNET7jmT7Ac{}yUcU2BOgCBrUI9D!+-P_CNLc(mv&pUORsaHQzcSFUA}7C9Bh2b zOkp{{?^Uu?W;~mq+EU*+jr&wD{l|aWtyB_7x!%~iWlMJu}jF1d!G$nE}M z8h7ilFH_JY~G$<79)ozRW64ezN_vO(-*2AP)1)Q}RkRISa4AQvVDb$fzZbn~` z@Oa$tuAWP%xAo(Nm($ANn6B0~OKGb>hx+te0}5?fl|K!%(>{@&Ufe)pUoKNh=_lz@ zO7`j>`P&`pD?UVrObuwQ$4P;kHl-Op?YuvX3%;oksUZiA!vnK{LzQ4cv6jzay>OEjav<-PAL?wMH;QV=RzUH zys=W*iRWCkBMo7=(#gI5aHjY9%wJuVY=gx5mW4==8KY39gT{Rk6S1n@^RM@5MSp{8 zN;+ZX(n|hxvdECxFWklIH+GMcKf{SnIO;0z1OALJLyM}Okgyz$N$XhX$e<|4e)1a~ zb-zA%eNVCCle;uw;q_0K9rol_-EjOU*dvsKQRr%amTYLQbt^1bn|m3Js+~Ur>Q_5v zt_Jln4S8cn-`hc%{1pe>l0ZpcoO`-ip%hnKCzt;sZwsnUa=Q?j#vOdG;g0G-!I|7M zXEt28ksC;EZs9fSw@TLU=E5I5Ab#M0kRG;~8LbzpfMEalm(U3LT48MaR G(*D03KN#r% 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 8b610d8f73cc488bf0690256a4c584590383b88d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 788 zcmc)IyN=W_6b4{!+fY(cSrHVAXGiv4@3@f{F*> zA*gr>9)vd_!;VBrxuuW(zxjTDyK(!T0Nu5%($qrds8nr7O#_B@+*!*JjjR2gD$eWD zMUNZUrZUA5W;*rTbr{p?@|D~`*CFq(cORzNRRe^v`T!qcSFir&s(q_k^3{^Bo;?Zq zQ4a$?j>7<>FL(LkAf0c6e{k@Y3$ED7s(JxuNQw&x`6SM#kj_ryQkZ(oSP&pZ%8-LA z$bfkheR*{K>9u#aUcEkkX^E&!*D}Ywkj%20G46yC#xvu=T6ELT@4tThKK!~^XfT>9 z%P49zR0`)86-3%KQduLI*PLCk#rxIarG?#w-oL>qrjXpP7 xXEHCl&+&rfO-KYkIh=BcV|jG*-#?JM{gu?t1M}83Y}wa#(sk1K+SYt8@CP@Q1}^{r 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 -- 2.39.5