]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7367 Remove code previously used by SonarLint 972/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 13 May 2016 08:35:18 +0000 (10:35 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 13 May 2016 13:03:56 +0000 (15:03 +0200)
90 files changed:
it/it-tests/src/test/java/it/analysis/IssuesModeTest.java
sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java [deleted file]
sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheBuilder.java [deleted file]
sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheInvalidation.java [deleted file]
sonar-home/src/main/java/org/sonar/home/cache/TTLCacheInvalidation.java [deleted file]
sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheBuilderTest.java [deleted file]
sonar-home/src/test/java/org/sonar/home/cache/PersistentCacheTest.java [deleted file]
sonar-home/src/test/java/org/sonar/home/cache/TTLCacheInvalidationTest.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/AnalysisWSLoaderProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/Batch.java
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/GlobalPersistentCacheProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizer.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheSynchronizer.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectPersistentCacheProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoader.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultQualityProfileLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/DefaultServerIssuesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/GlobalRepositoriesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ProjectRepositoriesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/QualityProfileProvider.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/ServerIssuesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/repository/user/UserRepositoryLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultActiveRulesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/batch/rule/RulesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
sonar-scanner-engine/src/main/java/org/sonar/batch/task/ScanTask.java
sonar-scanner-engine/src/test/java/org/sonar/batch/WsTestUtil.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectCacheSynchronizerTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/cache/WSLoaderTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issuesmode/NonAssociatedProject.java [deleted file]
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/ExceptionHandlingMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultGlobalRepositoriesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultQualityProfileLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/DefaultServerIssuesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/ProjectRepositoriesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/QualityProfileProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/rule/ActiveRulesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultActiveRulesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
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]
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]
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]
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]
sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/sonar-project.properties [deleted file]
sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf [deleted file]
sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf [deleted file]
sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json [deleted file]
sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_users.protobuf [deleted file]

index 8f0a8c826caaa1b6e6e436d522909922411a8481..9f6e3c0e2b3cd14256aed7f2337e4718738ab186 100644 (file)
@@ -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 (file)
index 6a00267..0000000
+++ /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<Path> filter) throws IOException {
-    try (DirectoryStream<Path> 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<Path> {
-    @Override
-    public boolean accept(Path entry) throws IOException {
-      return !lock.getFileLockName().equals(entry.getFileName().toString());
-    }
-  }
-
-  private class DirectoryCleanFilter implements DirectoryStream.Filter<Path> {
-    @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 (file)
index b34ee09..0000000
+++ /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:
- * <pre>
- *   &lt;sonar_home&gt;/ws_cache/&lt;server_url&gt;-&lt;version&gt;/projects/&lt;project&gt;/
- *   &lt;sonar_home&gt;/ws_cache/&lt;server_url&gt;-&lt;version&gt;/global/
- *   &lt;sonar_home&gt;/ws_cache/&lt;server_url&gt;-&lt;version&gt;/local/
- * </pre>
- */
-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 (file)
index 184730a..0000000
+++ /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 (file)
index e871e87..0000000
+++ /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 (file)
index 56ed229..0000000
+++ /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 (file)
index 1c149a4..0000000
+++ /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 (file)
index 4f60b66..0000000
+++ /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 (file)
index 54ce6e1..0000000
+++ /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;
-  }
-}
index 32a872ed16f1faf1239ce33026073698b54e0a72..7bd08e9e16dab04d194003e68b980af84cec1e05 100644 (file)
@@ -37,7 +37,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
   private static final String KEY_SCAN_ALL = "sonar.scanAllFiles";
 
   private boolean mediumTestMode;
-  private boolean notAssociated;
   private boolean scanAllFiles;
 
   public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props) {
@@ -48,10 +47,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
     return mediumTestMode;
   }
 
-  public boolean isNotAssociated() {
-    return notAssociated;
-  }
-
   public boolean scanAllFiles() {
     return scanAllFiles;
   }
@@ -73,7 +68,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
     validate(mode);
     issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
     mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED));
-    notAssociated = issues && rootProjectKeyMissing(analysisProps);
     String scanAllStr = getPropertyWithFallback(analysisProps, globalProps, KEY_SCAN_ALL);
     scanAllFiles = !issues || "true".equals(scanAllStr);
   }
@@ -89,9 +83,6 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
     if (mediumTestMode) {
       LOG.info("Medium test mode");
     }
-    if (notAssociated) {
-      LOG.info("Local analysis");
-    }
     if (!scanAllFiles) {
       LOG.info("Scanning only changed files");
     }
@@ -111,10 +102,4 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode {
 
     return CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
   }
-
-  private static boolean rootProjectKeyMissing(Map<String, String> props) {
-    // ProjectReactorBuilder depends on this class, so it will only create this property later
-    return !props.containsKey(CoreProperties.PROJECT_KEY_PROPERTY);
-  }
-
 }
index b1dd6aa584324ea5ce0a7fd6db9f55745f4b3b9c..2a6b64de50d1c1b800fa5e5ffb28aa7dd312278f 100644 (file)
@@ -24,19 +24,19 @@ import com.google.common.collect.Lists;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.Plugin;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
 import org.sonar.core.platform.PluginInfo;
 import org.sonar.core.platform.RemotePlugin;
 import org.sonar.core.platform.RemotePluginFile;
@@ -55,13 +55,11 @@ public class BatchPluginInstaller implements PluginInstaller {
   private static final Logger LOG = Loggers.get(BatchPluginInstaller.class);
   private static final String PLUGINS_INDEX_URL = "/deploy/plugins/index.txt";
 
-  private final WSLoader wsLoader;
   private final FileCache fileCache;
   private final BatchPluginPredicate pluginPredicate;
   private final BatchWsClient wsClient;
 
-  public BatchPluginInstaller(WSLoader wsLoader, BatchWsClient wsClient, FileCache fileCache, BatchPluginPredicate pluginPredicate) {
-    this.wsLoader = wsLoader;
+  public BatchPluginInstaller(BatchWsClient wsClient, FileCache fileCache, BatchPluginPredicate pluginPredicate) {
     this.fileCache = fileCache;
     this.pluginPredicate = pluginPredicate;
     this.wsClient = wsClient;
@@ -129,9 +127,16 @@ public class BatchPluginInstaller implements PluginInstaller {
 
   private String loadPluginIndex() {
     Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
-    WSLoaderResult<String> wsResult = wsLoader.loadString(PLUGINS_INDEX_URL);
-    profiler.stopInfo(wsResult.isFromCache());
-    return wsResult.get();
+    GetRequest getRequest = new GetRequest(PLUGINS_INDEX_URL);
+    String str;
+    try (Reader reader = wsClient.call(getRequest).contentReader()) {
+      str = IOUtils.toString(reader);
+    } catch(IOException e) {
+      throw new IllegalStateException(e);
+    }
+    
+    profiler.stopInfo();
+    return str;
   }
 
   private class FileDownloader implements FileCache.Downloader {
index dcc80d2fff556142e2478d262201f2426cf37513..0578a3b144d24f3dc60e65350e0a8c17a97074be 100644 (file)
@@ -25,10 +25,6 @@ import org.sonar.api.Plugin;
 import org.sonar.api.internal.SonarQubeVersionFactory;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.UriReader;
-import org.sonar.batch.cache.GlobalPersistentCacheProvider;
-import org.sonar.batch.cache.ProjectSyncContainer;
-import org.sonar.batch.cache.StrategyWSLoaderProvider;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
 import org.sonar.batch.index.CachesManager;
 import org.sonar.batch.platform.DefaultServer;
 import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader;
@@ -46,16 +42,14 @@ import org.sonar.core.util.UuidFactoryImpl;
 public class GlobalContainer extends ComponentContainer {
 
   private final Map<String, String> bootstrapProperties;
-  private boolean preferCache;
 
-  private GlobalContainer(Map<String, String> bootstrapProperties, boolean preferCache) {
+  private GlobalContainer(Map<String, String> bootstrapProperties) {
     super();
     this.bootstrapProperties = bootstrapProperties;
-    this.preferCache = preferCache;
   }
 
-  public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions, boolean preferCache) {
-    GlobalContainer container = new GlobalContainer(bootstrapProperties, preferCache);
+  public static GlobalContainer create(Map<String, String> bootstrapProperties, List<?> extensions) {
+    GlobalContainer container = new GlobalContainer(bootstrapProperties);
     container.add(extensions);
     return container;
   }
@@ -64,22 +58,11 @@ public class GlobalContainer extends ComponentContainer {
   protected void doBeforeStart() {
     GlobalProperties bootstrapProps = new GlobalProperties(bootstrapProperties);
     GlobalMode globalMode = new GlobalMode(bootstrapProps);
-    LoadStrategy strategy = getDataLoadingStrategy(globalMode, preferCache);
-    StrategyWSLoaderProvider wsLoaderProvider = new StrategyWSLoaderProvider(strategy);
-    add(wsLoaderProvider);
     add(bootstrapProps);
     add(globalMode);
     addBootstrapComponents();
   }
 
-  private static LoadStrategy getDataLoadingStrategy(GlobalMode mode, boolean preferCache) {
-    if (!mode.isIssues()) {
-      return LoadStrategy.SERVER_ONLY;
-    }
-
-    return preferCache ? LoadStrategy.CACHE_FIRST : LoadStrategy.SERVER_FIRST;
-  }
-
   private void addBootstrapComponents() {
     add(
       // plugins
@@ -99,7 +82,6 @@ public class GlobalContainer extends ComponentContainer {
       DefaultHttpDownloader.class,
       UriReader.class,
       new FileCacheProvider(),
-      new GlobalPersistentCacheProvider(),
       System2.INSTANCE,
       new GlobalRepositoriesProvider(),
       UuidFactoryImpl.INSTANCE);
@@ -124,8 +106,4 @@ public class GlobalContainer extends ComponentContainer {
     new TaskContainer(this, taskProperties, components).execute();
   }
 
-  public void syncProject(String projectKey, boolean force) {
-    new ProjectSyncContainer(this, projectKey, force).execute();
-  }
-
 }
index d5d3da130872715397dc85260187e71f82952e83..5f9ddbfc56fa8c80bbc65e0340e5e1bfafc3a9d5 100644 (file)
@@ -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 (file)
index 45baaec..0000000
+++ /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 (file)
index 6b8677e..0000000
+++ /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 (file)
index 9287c26..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-public class NonAssociatedCacheSynchronizer {
-  private static final Logger LOG = LoggerFactory.getLogger(NonAssociatedCacheSynchronizer.class);
-
-  private final ProjectCacheStatus cacheStatus;
-  private final QualityProfileLoader qualityProfileLoader;
-  private final ActiveRulesLoader activeRulesLoader;
-  private final RulesLoader rulesLoader;
-
-  public NonAssociatedCacheSynchronizer(RulesLoader rulesLoader, QualityProfileLoader qualityProfileLoader, ActiveRulesLoader activeRulesLoader, ProjectCacheStatus cacheStatus) {
-    this.rulesLoader = rulesLoader;
-    this.qualityProfileLoader = qualityProfileLoader;
-    this.activeRulesLoader = activeRulesLoader;
-    this.cacheStatus = cacheStatus;
-  }
-
-  public void execute(boolean force) {
-    Date lastSync = cacheStatus.getSyncStatus();
-
-    if (lastSync != null) {
-      if (!force) {
-        LOG.info("Found cache [{}]", lastSync);
-        return;
-      } else {
-        LOG.info("-- Found cache [{}], synchronizing data..", lastSync);
-      }
-    } else {
-      LOG.info("-- Cache not found, synchronizing data..");
-    }
-
-    loadData();
-    cacheStatus.save();
-    LOG.info("-- Succesfully synchronized cache");
-  }
-
-  private static Collection<String> getKeys(Collection<QualityProfile> qProfiles) {
-    List<String> list = new ArrayList<>(qProfiles.size());
-    for (QualityProfile qp : qProfiles) {
-      list.add(qp.getKey());
-    }
-
-    return list;
-  }
-
-  private void loadData() {
-    Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class));
-
-    profiler.startInfo("Load rules");
-    rulesLoader.load(null);
-    profiler.stopInfo();
-
-    profiler.startInfo("Load default quality profiles");
-    Collection<QualityProfile> qProfiles = qualityProfileLoader.loadDefault(null, null);
-    profiler.stopInfo();
-
-    profiler.startInfo("Load default active rules");
-    Collection<String> keys = getKeys(qProfiles);
-    for (String k : keys) {
-      activeRulesLoader.load(k, null);
-    }
-    profiler.stopInfo();
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java
deleted file mode 100644 (file)
index ef5fd97..0000000
+++ /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 (file)
index 64010b3..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import com.google.common.base.Function;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.log.Profiler;
-import org.sonar.batch.repository.ProjectRepositories;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.repository.user.UserRepositoryLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-public class ProjectCacheSynchronizer {
-  private static final Logger LOG = LoggerFactory.getLogger(ProjectCacheSynchronizer.class);
-
-  private final ServerIssuesLoader issuesLoader;
-  private final UserRepositoryLoader userRepository;
-  private final ProjectCacheStatus cacheStatus;
-  private final QualityProfileLoader qualityProfileLoader;
-  private final ProjectRepositoriesLoader projectRepositoriesLoader;
-  private final ActiveRulesLoader activeRulesLoader;
-  private final RulesLoader rulesLoader;
-
-  public ProjectCacheSynchronizer(RulesLoader rulesLoader, QualityProfileLoader qualityProfileLoader, ProjectRepositoriesLoader projectSettingsLoader,
-    ActiveRulesLoader activeRulesLoader, ServerIssuesLoader issuesLoader,
-    UserRepositoryLoader userRepository, ProjectCacheStatus cacheStatus) {
-    this.rulesLoader = rulesLoader;
-    this.qualityProfileLoader = qualityProfileLoader;
-    this.projectRepositoriesLoader = projectSettingsLoader;
-    this.activeRulesLoader = activeRulesLoader;
-    this.issuesLoader = issuesLoader;
-    this.userRepository = userRepository;
-    this.cacheStatus = cacheStatus;
-  }
-
-  private static boolean isToday(Date d) {
-    Calendar c1 = Calendar.getInstance();
-    Calendar c2 = Calendar.getInstance();
-    c2.setTime(d);
-
-    return c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) &&
-      c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR);
-  }
-
-  private static boolean shouldUpdate(Date lastUpdate) {
-    return !isToday(lastUpdate);
-  }
-
-  public void load(String projectKey, boolean force) {
-    Date lastSync = cacheStatus.getSyncStatus();
-    boolean failOnError = true;
-
-    if (lastSync != null) {
-      if (force) {
-        LOG.info("-- Found project [{}] cache [{}], synchronizing data (forced)..", projectKey, lastSync);
-      } else if (shouldUpdate(lastSync)) {
-        LOG.info("-- Found project [{}] cache [{}], synchronizing data..", projectKey, lastSync);
-        failOnError = false;
-      } else {
-        LOG.info("Found project [{}] cache [{}]", projectKey, lastSync);
-        return;
-      }
-    } else {
-      LOG.info("-- Cache for project [{}] not found, synchronizing data..", projectKey);
-    }
-
-    try {
-      loadData(projectKey);
-    } catch (Exception e) {
-      if (failOnError) {
-        throw e;
-      }
-
-      LOG.warn("-- Cache update for project [{}] failed, continuing from cache..", projectKey, e);
-      return;
-    }
-
-    saveStatus();
-  }
-
-  private void saveStatus() {
-    cacheStatus.save();
-    LOG.info("-- Successfully synchronized project cache");
-  }
-
-  private void loadData(String projectKey) {
-    Profiler profiler = Profiler.create(Loggers.get(ProjectCacheSynchronizer.class));
-
-    profiler.startInfo("Load rules");
-    rulesLoader.load(null);
-    profiler.stopInfo();
-
-    profiler.startInfo("Load project settings");
-    ProjectRepositories projectRepo = projectRepositoriesLoader.load(projectKey, true, null);
-
-    if (!projectRepo.exists()) {
-      LOG.debug("Project doesn't exist in the server");
-    } else if (projectRepo.lastAnalysisDate() == null) {
-      LOG.debug("No previous analysis found");
-    }
-    profiler.stopInfo();
-
-    profiler.startInfo("Load project quality profiles");
-    Collection<QualityProfile> qProfiles;
-    if (projectRepo.exists()) {
-      qProfiles = qualityProfileLoader.load(projectKey, null, null);
-    } else {
-      qProfiles = qualityProfileLoader.loadDefault(null, null);
-    }
-    profiler.stopInfo();
-
-    profiler.startInfo("Load project active rules");
-    Collection<String> keys = getKeys(qProfiles);
-    for (String k : keys) {
-      activeRulesLoader.load(k, null);
-    }
-    profiler.stopInfo();
-
-    if (projectRepo.lastAnalysisDate() != null) {
-      profiler.startInfo("Load server issues");
-      UserLoginAccumulator consumer = new UserLoginAccumulator();
-      issuesLoader.load(projectKey, consumer);
-      profiler.stopInfo();
-
-      profiler.startInfo("Load user information");
-      for (String login : consumer.loginSet) {
-        userRepository.load(login, null);
-      }
-      profiler.stopInfo("Load user information");
-    }
-  }
-
-  private static Collection<String> getKeys(Collection<QualityProfile> qProfiles) {
-    List<String> list = new ArrayList<>(qProfiles.size());
-    for (QualityProfile qp : qProfiles) {
-      list.add(qp.getKey());
-    }
-
-    return list;
-  }
-
-  private static class UserLoginAccumulator implements Function<ServerIssue, Void> {
-    Set<String> loginSet = new HashSet<>();
-
-    @Override
-    public Void apply(ServerIssue input) {
-      if (!StringUtils.isEmpty(input.getAssigneeLogin())) {
-        loginSet.add(input.getAssigneeLogin());
-      }
-      return null;
-    }
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/ProjectKeySupplier.java
deleted file mode 100644 (file)
index abbd8a6..0000000
+++ /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 (file)
index 2594a00..0000000
+++ /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 (file)
index 8160917..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nullable;
-import org.sonar.api.CoreProperties;
-import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.batch.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.batch.repository.DefaultQualityProfileLoader;
-import org.sonar.batch.repository.DefaultServerIssuesLoader;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.repository.user.UserRepositoryLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.DefaultActiveRulesLoader;
-import org.sonar.batch.rule.DefaultRulesLoader;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonar.core.platform.ComponentContainer;
-
-public class ProjectSyncContainer extends ComponentContainer {
-  private final boolean force;
-  private final String projectKey;
-
-  public ProjectSyncContainer(ComponentContainer globalContainer, @Nullable String projectKey, boolean force) {
-    super(globalContainer);
-    this.projectKey = projectKey;
-    this.force = force;
-  }
-
-  @Override
-  public void doBeforeStart() {
-    addComponents();
-  }
-
-  @Override
-  public void doAfterStart() {
-    if (projectKey != null) {
-      getComponentByType(ProjectCacheSynchronizer.class).load(projectKey, force);
-    } else {
-      getComponentByType(NonAssociatedCacheSynchronizer.class).execute(force);
-    }
-  }
-
-  private static DefaultAnalysisMode createIssuesAnalysisMode(@Nullable String projectKey) {
-    Map<String, String> props = new HashMap<>();
-    props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
-    if (projectKey != null) {
-      props.put(CoreProperties.PROJECT_KEY_PROPERTY, projectKey);
-    }
-    GlobalProperties globalProps = new GlobalProperties(props);
-    AnalysisProperties analysisProps = new AnalysisProperties(props);
-    return new DefaultAnalysisMode(globalProps, analysisProps);
-  }
-
-  private void addComponents() {
-    add(new StrategyWSLoaderProvider(LoadStrategy.SERVER_ONLY),
-      new ProjectKeySupplier(projectKey),
-      projectKey != null ? ProjectCacheSynchronizer.class : NonAssociatedCacheSynchronizer.class,
-      UserRepositoryLoader.class,
-      new ProjectPersistentCacheProvider(),
-      createIssuesAnalysisMode(projectKey));
-
-    addIfMissing(DefaultProjectCacheStatus.class, ProjectCacheStatus.class);
-    addIfMissing(DefaultProjectRepositoriesLoader.class, ProjectRepositoriesLoader.class);
-    addIfMissing(DefaultServerIssuesLoader.class, ServerIssuesLoader.class);
-    addIfMissing(DefaultQualityProfileLoader.class, QualityProfileLoader.class);
-    addIfMissing(DefaultRulesLoader.class, RulesLoader.class);
-    addIfMissing(DefaultActiveRulesLoader.class, ActiveRulesLoader.class);
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/StrategyWSLoaderProvider.java
deleted file mode 100644 (file)
index d89de5b..0000000
+++ /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 (file)
index 328480e..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.charset.StandardCharsets;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.home.cache.PersistentCache;
-import org.sonarqube.ws.client.GetRequest;
-import org.sonarqube.ws.client.HttpException;
-
-import static org.sonar.batch.cache.WSLoader.ServerStatus.ACCESSIBLE;
-import static org.sonar.batch.cache.WSLoader.ServerStatus.NOT_ACCESSIBLE;
-import static org.sonar.batch.cache.WSLoader.ServerStatus.UNKNOWN;
-
-public class WSLoader {
-  private static final Logger LOG = Loggers.get(WSLoader.class);
-  private static final String FAIL_MSG = "Server is not accessible and data is not cached";
-
-  public enum ServerStatus {
-    UNKNOWN, ACCESSIBLE, NOT_ACCESSIBLE
-  }
-
-  public enum LoadStrategy {
-    SERVER_FIRST, CACHE_FIRST, SERVER_ONLY, CACHE_ONLY
-  }
-
-  private final LoadStrategy defautLoadStrategy;
-  private final BatchWsClient wsClient;
-  private final PersistentCache cache;
-  private ServerStatus serverStatus;
-
-  private DataLoader<String> stringServerLoader = new DataLoader<String>() {
-    @Override
-    public String load(String id) throws IOException {
-      GetRequest getRequest = new GetRequest(id);
-      try (Reader reader = wsClient.call(getRequest).contentReader()) {
-        String str = IOUtils.toString(reader);
-        try {
-          cache.put(id, str.getBytes(StandardCharsets.UTF_8));
-        } catch (IOException e) {
-          throw new IllegalStateException("Error saving to WS cache", e);
-        }
-        return str;
-      }
-    }
-  };
-
-  private DataLoader<String> stringCacheLoader = new DataLoader<String>() {
-    @Override
-    public String load(String id) throws IOException {
-      return cache.getString(id);
-    }
-  };
-
-  private DataLoader<InputStream> streamServerLoader = new DataLoader<InputStream>() {
-    @Override
-    public InputStream load(String id) throws IOException {
-      GetRequest getRequest = new GetRequest(id);
-      try (InputStream is = wsClient.call(getRequest).contentStream()) {
-        try {
-          cache.put(id, is);
-        } catch (IOException e) {
-          throw new IllegalStateException("Error saving to WS cache", e);
-        }
-      }
-      return cache.getStream(id);
-    }
-  };
-
-  private DataLoader<InputStream> streamCacheLoader = new DataLoader<InputStream>() {
-    @Override
-    public InputStream load(String id) throws IOException {
-      return cache.getStream(id);
-    }
-  };
-
-  private static class NotAvailableException extends Exception {
-    private static final long serialVersionUID = 1L;
-
-    public NotAvailableException(String message) {
-      super(message);
-    }
-
-    public NotAvailableException(Throwable cause) {
-      super(cause);
-    }
-  }
-
-  public WSLoader(LoadStrategy strategy, PersistentCache cache, BatchWsClient wsClient) {
-    this.defautLoadStrategy = strategy;
-    this.serverStatus = UNKNOWN;
-    this.cache = cache;
-    this.wsClient = wsClient;
-  }
-
-  @Nonnull
-  public WSLoaderResult<InputStream> loadStream(String id) {
-    return load(id, defautLoadStrategy, streamServerLoader, streamCacheLoader);
-  }
-
-  @Nonnull
-  public WSLoaderResult<String> loadString(String id) {
-    return loadString(id, defautLoadStrategy);
-  }
-
-  @Nonnull
-  public WSLoaderResult<String> loadString(String id, WSLoader.LoadStrategy strategy) {
-    return load(id, strategy, stringServerLoader, stringCacheLoader);
-  }
-
-  @Nonnull
-  private <T> WSLoaderResult<T> load(String id, WSLoader.LoadStrategy strategy, DataLoader<T> serverLoader, DataLoader<T> cacheLoader) {
-    switch (strategy) {
-      case CACHE_FIRST:
-        return loadFromCacheFirst(id, cacheLoader, serverLoader);
-      case CACHE_ONLY:
-        return loadFromCacheFirst(id, cacheLoader, null);
-      case SERVER_FIRST:
-        return loadFromServerFirst(id, serverLoader, cacheLoader);
-      case SERVER_ONLY:
-      default:
-        return loadFromServerFirst(id, serverLoader, null);
-    }
-  }
-
-  public LoadStrategy getDefaultStrategy() {
-    return this.defautLoadStrategy;
-  }
-
-  private void switchToOffline() {
-    LOG.debug("server not available - switching to offline mode");
-    serverStatus = NOT_ACCESSIBLE;
-  }
-
-  private void switchToOnline() {
-    serverStatus = ACCESSIBLE;
-  }
-
-  private boolean isOffline() {
-    return serverStatus == NOT_ACCESSIBLE;
-  }
-
-  @Nonnull
-  private <T> WSLoaderResult<T> loadFromCacheFirst(String id, DataLoader<T> cacheLoader, @Nullable DataLoader<T> serverLoader) {
-    try {
-      return loadFromCache(id, cacheLoader);
-    } catch (NotAvailableException cacheNotAvailable) {
-      if (serverLoader != null) {
-        try {
-          return loadFromServer(id, serverLoader);
-        } catch (NotAvailableException serverNotAvailable) {
-          throw new IllegalStateException(FAIL_MSG, serverNotAvailable.getCause());
-        }
-      }
-      throw new IllegalStateException("Data is not cached", cacheNotAvailable.getCause());
-    }
-  }
-
-  @Nonnull
-  private <T> WSLoaderResult<T> loadFromServerFirst(String id, DataLoader<T> serverLoader, @Nullable DataLoader<T> cacheLoader) {
-    try {
-      return loadFromServer(id, serverLoader);
-    } catch (NotAvailableException serverNotAvailable) {
-      if (cacheLoader != null) {
-        try {
-          return loadFromCache(id, cacheLoader);
-        } catch (NotAvailableException cacheNotAvailable) {
-          throw new IllegalStateException(FAIL_MSG, serverNotAvailable.getCause());
-        }
-      }
-      throw new IllegalStateException("Server is not available: " + wsClient.baseUrl(), serverNotAvailable.getCause());
-    }
-  }
-
-  interface DataLoader<T> {
-    T load(String id) throws IOException;
-  }
-
-  private <T> WSLoaderResult<T> loadFromCache(String id, DataLoader<T> loader) throws NotAvailableException {
-    T result;
-
-    try {
-      result = loader.load(id);
-    } catch (IOException e) {
-      // any exception on the cache should fail fast
-      throw new IllegalStateException(e);
-    }
-    if (result == null) {
-      throw new NotAvailableException("resource not cached");
-    }
-    return new WSLoaderResult<>(result, true);
-  }
-
-  private <T> WSLoaderResult<T> loadFromServer(String id, DataLoader<T> loader) throws NotAvailableException {
-    if (isOffline()) {
-      throw new NotAvailableException("Server not available");
-    }
-    try {
-      T t = loader.load(id);
-      switchToOnline();
-      return new WSLoaderResult<>(t, false);
-    } catch (HttpException | MessageException e) {
-      // fail fast if it could connect but there was a application-level error
-      throw e;
-    } catch (IllegalStateException e) {
-      switchToOffline();
-      throw new NotAvailableException(e);
-    } catch (Exception e) {
-      // fail fast
-      throw new IllegalStateException(e);
-    }
-  }
-
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/WSLoaderResult.java
deleted file mode 100644 (file)
index 29db0bc..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import javax.annotation.Nonnull;
-
-public class WSLoaderResult<T> {
-  private T result;
-  private boolean fromCache;
-
-  public WSLoaderResult(T result, boolean fromCache) {
-    this.result = result;
-    this.fromCache = fromCache;
-  }
-
-  @Nonnull
-  public T get() {
-    return result;
-  }
-
-  public boolean isFromCache() {
-    return fromCache;
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/cache/package-info.java
deleted file mode 100644 (file)
index 3f72a2d..0000000
+++ /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;
index 954997466fe1a9f5126db361e5d49a2229de0494..ff28b9e8da38868df8edf28ec6d63b973c0c9849 100644 (file)
  */
 package org.sonar.batch.issue.tracking;
 
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.sonar.batch.bootstrap.BatchWsClient;
+import org.sonar.batch.util.BatchUtils;
+import org.sonarqube.ws.client.GetRequest;
 
-import javax.annotation.Nullable;
+import java.io.IOException;
+import java.io.Reader;
 
-import org.sonar.batch.util.BatchUtils;
 import com.google.common.base.Splitter;
 import com.google.common.collect.Iterators;
+import org.apache.commons.io.IOUtils;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
 
 public class DefaultServerLineHashesLoader implements ServerLineHashesLoader {
+  private BatchWsClient wsClient;
 
-  private final WSLoader wsLoader;
-
-  public DefaultServerLineHashesLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public DefaultServerLineHashesLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) {
-    String hashesFromWs = loadHashesFromWs(fileKey, fromCache);
+  public String[] getLineHashes(String fileKey) {
+    String hashesFromWs = loadHashesFromWs(fileKey);
     return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class);
   }
 
-  private String loadHashesFromWs(String fileKey, @Nullable MutableBoolean fromCache) {
+  private String loadHashesFromWs(String fileKey) {
     Profiler profiler = Profiler.createIfDebug(Loggers.get(getClass()))
       .addContext("file", fileKey)
       .startDebug("Load line hashes");
-    WSLoaderResult<String> result = wsLoader.loadString("/api/sources/hash?key=" + BatchUtils.encodeForUrl(fileKey), LoadStrategy.CACHE_FIRST);
+
+    GetRequest getRequest = new GetRequest("/api/sources/hash?key=" + BatchUtils.encodeForUrl(fileKey));
+    Reader reader = wsClient.call(getRequest).contentReader();
     try {
-      if (fromCache != null) {
-        fromCache.setValue(result.isFromCache());
-      }
-      return result.get();
+      return IOUtils.toString(reader);
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
     } finally {
-      if (result.isFromCache()) {
-        profiler.stopDebug("Load line hashes (done from cache)");
-      } else {
-        profiler.stopDebug();
-      }
+      profiler.stopDebug();
     }
   }
 }
index 16f104583fd461d6b03acacac8472606838bb72a..040ce776b9f5440da10cdc505747daee096bcf59 100644 (file)
@@ -59,8 +59,8 @@ public class ServerIssueRepository {
     Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
     this.issuesCache = caches.createCache("previousIssues");
     caches.registerValueCoder(ServerIssue.class, new ServerIssueValueCoder());
-    boolean fromCache = previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), new SaveIssueConsumer());
-    profiler.stopInfo(fromCache);
+    previousIssuesLoader.load(reactor.getRoot().getKeyWithBranch(), new SaveIssueConsumer());
+    profiler.stopInfo();
   }
 
   public Iterable<ServerIssue> byComponent(BatchComponent component) {
@@ -85,7 +85,7 @@ public class ServerIssueRepository {
       return null;
     }
   }
-  
+
   public Iterable<ServerIssue> issuesOnMissingComponents() {
     return issuesCache.values(0);
   }
index fb0b32d0d2bd84bbb1edc5a2937048f4be00971e..23edcc430d451e779c3d5a5a0d72744be7aeca92 100644 (file)
  */
 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);
 }
index 583a92f0b9d6fd3ae22657c7d7c2d94e6ed44f0a..dac686f27ea4e12cbdb9989b1720dbebed075d76 100644 (file)
@@ -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;
       }
     }
index 55508b0e8bf034cc1097867be0410b3db0689ce2..6ccce5e2c25c28f5b2d56a6d89c5985ea8c81185 100644 (file)
  */
 package org.sonar.batch.repository;
 
-import org.sonar.batch.cache.WSLoaderResult;
 import org.sonar.scanner.protocol.input.GlobalRepositories;
-import org.sonar.batch.cache.WSLoader;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonar.batch.bootstrap.BatchWsClient;
 
-import javax.annotation.Nullable;
+import java.io.IOException;
+import java.io.Reader;
 
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.apache.commons.io.IOUtils;
 
 public class DefaultGlobalRepositoriesLoader implements GlobalRepositoriesLoader {
 
   private static final String BATCH_GLOBAL_URL = "/batch/global";
+  private BatchWsClient wsClient;
 
-  private final WSLoader wsLoader;
-
-  public DefaultGlobalRepositoriesLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public DefaultGlobalRepositoriesLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public GlobalRepositories load(@Nullable MutableBoolean fromCache) {
-    WSLoaderResult<String> result = wsLoader.loadString(BATCH_GLOBAL_URL);
-    if (fromCache != null) {
-      fromCache.setValue(result.isFromCache());
+  public GlobalRepositories load() {
+    GetRequest getRequest = new GetRequest(BATCH_GLOBAL_URL);
+    Reader reader = wsClient.call(getRequest).contentReader();
+    String str;
+    try {
+      str = IOUtils.toString(reader);
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
     }
-    return GlobalRepositories.fromJson(result.get());
+    return GlobalRepositories.fromJson(str);
   }
 }
index 0e8a0904b5706df7ccb6431ecd32fe21fe9c83c9..878d11ee04fe66ef60a25be72b3467754435adcb 100644 (file)
@@ -30,38 +30,33 @@ import java.net.HttpURLConnection;
 import java.util.Date;
 import java.util.Map;
 
-import javax.annotation.Nullable;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.utils.MessageException;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonar.batch.util.BatchUtils;
 import org.sonarqube.ws.WsBatch.WsProjectResponse;
 import org.sonarqube.ws.WsBatch.WsProjectResponse.FileDataByPath;
 import org.sonarqube.ws.WsBatch.WsProjectResponse.Settings;
+import org.sonarqube.ws.client.GetRequest;
 import org.sonarqube.ws.client.HttpException;
 
 public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoader {
   private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectRepositoriesLoader.class);
   private static final String BATCH_PROJECT_URL = "/batch/project.protobuf";
-  private final WSLoader loader;
+  private BatchWsClient wsClient;
 
-  public DefaultProjectRepositoriesLoader(WSLoader loader) {
-    this.loader = loader;
+  public DefaultProjectRepositoriesLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public ProjectRepositories load(String projectKey, boolean issuesMode, @Nullable MutableBoolean fromCache) {
+  public ProjectRepositories load(String projectKey, boolean issuesMode) {
     try {
-      WSLoaderResult<InputStream> result = loader.loadStream(getUrl(projectKey, issuesMode));
-      if (fromCache != null) {
-        fromCache.setValue(result.isFromCache());
-      }
-      return processStream(result.get(), projectKey);
+      GetRequest request = new GetRequest(getUrl(projectKey, issuesMode));
+      InputStream is = wsClient.call(request).contentStream();
+      return processStream(is, projectKey);
     } catch (RuntimeException e) {
       if (shouldThrow(e)) {
         throw e;
index 524e6f6856d4c5e2c3bf5301adf2063cd54d5828..6d3766b1c3b0ed87c6e5d026d8d065bdeff9e75f 100644 (file)
@@ -25,9 +25,8 @@ import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
 import org.sonar.batch.util.BatchUtils;
 import org.apache.commons.io.IOUtils;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.apache.commons.lang.mutable.MutableBoolean;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonar.batch.bootstrap.BatchWsClient;
 
 import javax.annotation.Nullable;
 
@@ -38,36 +37,33 @@ import java.util.List;
 public class DefaultQualityProfileLoader implements QualityProfileLoader {
   private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
 
-  private WSLoader wsLoader;
+  private BatchWsClient wsClient;
 
-  public DefaultQualityProfileLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public DefaultQualityProfileLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) {
+  public List<QualityProfile> loadDefault(@Nullable String profileName) {
     String url = WS_URL + "?defaults=true";
     if (profileName != null) {
       url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
     }
-    return loadResource(url, fromCache);
+    return loadResource(url);
   }
 
   @Override
-  public List<QualityProfile> load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache) {
+  public List<QualityProfile> load(String projectKey, @Nullable String profileName) {
     String url = WS_URL + "?projectKey=" + BatchUtils.encodeForUrl(projectKey);
     if (profileName != null) {
       url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
     }
-    return loadResource(url, fromCache);
+    return loadResource(url);
   }
 
-  private List<QualityProfile> loadResource(String url, @Nullable MutableBoolean fromCache) {
-    WSLoaderResult<InputStream> result = wsLoader.loadStream(url);
-    if (fromCache != null) {
-      fromCache.setValue(result.isFromCache());
-    }
-    InputStream is = result.get();
+  private List<QualityProfile> loadResource(String url) {
+    GetRequest getRequest = new GetRequest(url);
+    InputStream is = wsClient.call(getRequest).contentStream();
     SearchWsResponse profiles = null;
 
     try {
index 394ce0eea9208599817a5a268c73b0f97cf9246b..f5f4406fab5af9c5d3169d09bf633f0caadff7b5 100644 (file)
@@ -23,24 +23,24 @@ import com.google.common.base.Function;
 import java.io.IOException;
 import java.io.InputStream;
 import org.apache.commons.io.IOUtils;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonar.batch.util.BatchUtils;
 import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
+import org.sonarqube.ws.client.GetRequest;
 
 public class DefaultServerIssuesLoader implements ServerIssuesLoader {
 
-  private final WSLoader wsLoader;
+  private final BatchWsClient wsClient;
 
-  public DefaultServerIssuesLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public DefaultServerIssuesLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public boolean load(String componentKey, Function<ServerIssue, Void> consumer) {
-    WSLoaderResult<InputStream> result = wsLoader.loadStream("/batch/issues.protobuf?key=" + BatchUtils.encodeForUrl(componentKey));
-    parseIssues(result.get(), consumer);
-    return result.isFromCache();
+  public void load(String componentKey, Function<ServerIssue, Void> consumer) {
+    GetRequest getRequest = new GetRequest("/batch/issues.protobuf?key=" + BatchUtils.encodeForUrl(componentKey));
+    InputStream is = wsClient.call(getRequest).contentStream();
+    parseIssues(is, consumer);
   }
 
   private static void parseIssues(InputStream is, Function<ServerIssue, Void> consumer) {
index 86359e4b772fd3edf001a9397a07bf25b12fb1da..cf8b435eee7b648fbb79289966c008714d71de83 100644 (file)
  */
 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();
 }
index 578b5458cd862c310d5d8edf08a281bb5c484cca..e28d952671bc4135062a43d4f19110a0b48e1711 100644 (file)
@@ -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;
   }
index 53de48053247cc14ab18484d2605f7a50922c8f9..f689d3664df454a2520cbf18530f5a6ddfd43cef 100644 (file)
  */
 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);
 }
index 1e0469651d5ca533bd596fcbd6c6744e1c20d51e..f5b17549f4689adab5d4c6ec5b7121a3dbd3379b 100644 (file)
@@ -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();
-  }
 }
index a93bea66b11a39cbb346abb5c3850d6ee6ebdc1b..45d492b13476c968e711405a742602a98a4eed19 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.repository;
 
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 
 import javax.annotation.Nullable;
@@ -27,7 +26,7 @@ import javax.annotation.Nullable;
 import java.util.List;
 
 public interface QualityProfileLoader {
-  List<QualityProfile> load(String projectKey, @Nullable String profileName, @Nullable MutableBoolean fromCache);
-  
-  List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache);
+  List<QualityProfile> load(String projectKey, @Nullable String profileName);
+
+  List<QualityProfile> loadDefault(@Nullable String profileName);
 }
index 6878d21ecfbe34931b37582420ca9c860b8e87a8..0b62b406a41656b9fc0334e1496ad22391124b8c 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.batch.repository;
 
 import java.util.List;
 import javax.annotation.CheckForNull;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.bootstrap.ProjectKey;
 import org.sonar.api.utils.log.Logger;
@@ -40,15 +39,13 @@ public class QualityProfileProvider extends ProviderAdapter {
   public ModuleQProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props, DefaultAnalysisMode mode) {
     if (this.profiles == null) {
       List<QualityProfile> profileList;
-      MutableBoolean fromCache = new MutableBoolean();
-
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-      if (mode.isNotAssociated() || !projectRepositories.exists()) {
-        profileList = loader.loadDefault(getSonarProfile(props, mode), fromCache);
+      if (!projectRepositories.exists()) {
+        profileList = loader.loadDefault(getSonarProfile(props, mode));
       } else {
-        profileList = loader.load(projectKey.get(), getSonarProfile(props, mode), fromCache);
+        profileList = loader.load(projectKey.get(), getSonarProfile(props, mode));
       }
-      profiler.stopInfo(fromCache.booleanValue());
+      profiler.stopInfo();
       profiles = new ModuleQProfiles(profileList);
     }
 
index e0c981a11e03ca613855aa483c90fd83fa8aa725..171323b347d55bf28c8b612a3128f004fd779ad1 100644 (file)
@@ -24,6 +24,6 @@ import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
 
 public interface ServerIssuesLoader {
 
-  boolean load(String componentKey, Function<ServerIssue, Void> consumer);
+  void load(String componentKey, Function<ServerIssue, Void> consumer);
 
 }
index 9b33645cebefa8f755535d964d841b59d2c30f5f..f4aa20729114ef33ad070ebbb21cc3763cb6ef44 100644 (file)
@@ -21,16 +21,13 @@ package org.sonar.batch.repository.user;
 
 import org.apache.commons.io.IOUtils;
 
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.bootstrap.BatchWsClient;
 
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang.mutable.MutableBoolean;
 import com.google.common.collect.Lists;
 import com.google.common.base.Joiner;
 import org.sonar.batch.util.BatchUtils;
 import org.sonar.scanner.protocol.input.ScannerInput;
+import org.sonarqube.ws.client.GetRequest;
 import com.google.common.base.Function;
 import java.io.IOException;
 import java.io.InputStream;
@@ -40,43 +37,29 @@ import java.util.Collections;
 import java.util.List;
 
 public class UserRepositoryLoader {
-  private final WSLoader wsLoader;
+  private final BatchWsClient wsClient;
 
-  public UserRepositoryLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public UserRepositoryLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   public ScannerInput.User load(String userLogin) {
-    return load(userLogin, null);
-  }
-
-  public ScannerInput.User load(String userLogin, @Nullable MutableBoolean fromCache) {
-    InputStream is = loadQuery(new UserEncodingFunction().apply(userLogin), fromCache);
+    InputStream is = loadQuery(new UserEncodingFunction().apply(userLogin));
     return parseUser(is);
   }
 
   public Collection<ScannerInput.User> load(List<String> userLogins) {
-    return load(userLogins, null);
-  }
-
-  /**
-   * Not cache friendly. Should not be used if a cache hit is expected.
-   */
-  public Collection<ScannerInput.User> load(List<String> userLogins, @Nullable MutableBoolean fromCache) {
     if (userLogins.isEmpty()) {
       return Collections.emptyList();
     }
-    InputStream is = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction())), fromCache);
+    InputStream is = loadQuery(Joiner.on(',').join(Lists.transform(userLogins, new UserEncodingFunction())));
 
     return parseUsers(is);
   }
 
-  private InputStream loadQuery(String loginsQuery, @Nullable MutableBoolean fromCache) {
-    WSLoaderResult<InputStream> result = wsLoader.loadStream("/batch/users?logins=" + loginsQuery);
-    if (fromCache != null) {
-      fromCache.setValue(result.isFromCache());
-    }
-    return result.get();
+  private InputStream loadQuery(String loginsQuery) {
+    GetRequest getRequest = new GetRequest("/batch/users?logins=" + loginsQuery);
+    return wsClient.call(getRequest).contentStream();
   }
 
   private static class UserEncodingFunction implements Function<String, String> {
index 028929bd141bcd6bacd2b5f714b2ba6f77a39505..cc7d7e12371daf0d471ac07d40e2f35cc25b0e96 100644 (file)
  */
 package org.sonar.batch.rule;
 
-import org.apache.commons.lang.mutable.MutableBoolean;
-
-import javax.annotation.Nullable;
-
 import java.util.List;
 
 public interface ActiveRulesLoader {
-  List<LoadedActiveRule> load(String qualityProfileKey, @Nullable MutableBoolean fromCache);
+  List<LoadedActiveRule> load(String qualityProfileKey);
 }
index 83034e2213267593d1c05bb35d1a9d4b280e8113..14814b9de0cd6b6f6f201042ebf92461a3120d1c 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.picocontainer.injectors.ProviderAdapter;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
@@ -47,14 +46,13 @@ public class ActiveRulesProvider extends ProviderAdapter {
   public ActiveRules provide(ActiveRulesLoader loader, ModuleQProfiles qProfiles) {
     if (singleton == null) {
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-      MutableBoolean fromCache = new MutableBoolean();
-      singleton = load(loader, qProfiles, fromCache);
-      profiler.stopInfo(fromCache.booleanValue());
+      singleton = load(loader, qProfiles);
+      profiler.stopInfo();
     }
     return singleton;
   }
 
-  private static ActiveRules load(ActiveRulesLoader loader, ModuleQProfiles qProfiles, MutableBoolean fromCache) {
+  private static ActiveRules load(ActiveRulesLoader loader, ModuleQProfiles qProfiles) {
 
     Collection<String> qProfileKeys = getKeys(qProfiles);
     Map<RuleKey, LoadedActiveRule> loadedRulesByKey = new HashMap<>();
@@ -62,7 +60,7 @@ public class ActiveRulesProvider extends ProviderAdapter {
     try {
       for (String qProfileKey : qProfileKeys) {
         Collection<LoadedActiveRule> qProfileRules;
-        qProfileRules = load(loader, qProfileKey, fromCache);
+        qProfileRules = load(loader, qProfileKey);
 
         for (LoadedActiveRule r : qProfileRules) {
           if (!loadedRulesByKey.containsKey(r.getRuleKey())) {
@@ -100,8 +98,8 @@ public class ActiveRulesProvider extends ProviderAdapter {
     return builder.build();
   }
 
-  private static List<LoadedActiveRule> load(ActiveRulesLoader loader, String qProfileKey, MutableBoolean fromCache) throws IOException {
-    return loader.load(qProfileKey, fromCache);
+  private static List<LoadedActiveRule> load(ActiveRulesLoader loader, String qProfileKey) throws IOException {
+    return loader.load(qProfileKey);
   }
 
   private static Collection<String> getKeys(ModuleQProfiles qProfiles) {
index 9485d99e1cb1f3818c0e704fff0dc562c266e6bb..0a6e7951782fd83199e62e1841583f47c1b00085 100644 (file)
@@ -28,15 +28,12 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
-import javax.annotation.Nullable;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonarqube.ws.Rules.Active;
 import org.sonarqube.ws.Rules.Active.Param;
+import org.sonarqube.ws.client.GetRequest;
 import org.sonarqube.ws.Rules.ActiveList;
 import org.sonarqube.ws.Rules.Rule;
 import org.sonarqube.ws.Rules.SearchResponse;
@@ -44,22 +41,22 @@ import org.sonarqube.ws.Rules.SearchResponse;
 public class DefaultActiveRulesLoader implements ActiveRulesLoader {
   private static final String RULES_SEARCH_URL = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true";
 
-  private final WSLoader wsLoader;
+  private final BatchWsClient wsClient;
 
-  public DefaultActiveRulesLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public DefaultActiveRulesLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public List<LoadedActiveRule> load(String qualityProfileKey, @Nullable MutableBoolean fromCache) {
+  public List<LoadedActiveRule> load(String qualityProfileKey) {
     List<LoadedActiveRule> ruleList = new LinkedList<>();
     int page = 1;
     int pageSize = 500;
     int loaded = 0;
 
     while (true) {
-      WSLoaderResult<InputStream> result = wsLoader.loadStream(getUrl(qualityProfileKey, page, pageSize));
-      SearchResponse response = loadFromStream(result.get());
+      GetRequest getRequest = new GetRequest(getUrl(qualityProfileKey, page, pageSize));
+      SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream());
       List<LoadedActiveRule> pageRules = readPage(response);
       ruleList.addAll(pageRules);
       loaded += response.getPs();
@@ -68,9 +65,6 @@ public class DefaultActiveRulesLoader implements ActiveRulesLoader {
         break;
       }
       page++;
-      if (fromCache != null) {
-        fromCache.setValue(result.isFromCache());
-      }
     }
 
     return ruleList;
index 62292b4581b25695dddfeca5efec9520fd58ea53..9921af66c8ba036abc26700707a55586fc5d93e7 100644 (file)
@@ -21,13 +21,9 @@ package org.sonar.batch.rule;
 
 import org.apache.commons.io.IOUtils;
 
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonarqube.ws.Rules.ListResponse.Rule;
+import org.sonarqube.ws.client.GetRequest;
 import org.sonarqube.ws.Rules.ListResponse;
 
 import java.io.IOException;
@@ -37,19 +33,16 @@ import java.util.List;
 public class DefaultRulesLoader implements RulesLoader {
   private static final String RULES_SEARCH_URL = "/api/rules/list.protobuf";
 
-  private final WSLoader wsLoader;
+  private final BatchWsClient wsClient;
 
-  public DefaultRulesLoader(WSLoader wsLoader) {
-    this.wsLoader = wsLoader;
+  public DefaultRulesLoader(BatchWsClient wsClient) {
+    this.wsClient = wsClient;
   }
 
   @Override
-  public List<Rule> load(@Nullable MutableBoolean fromCache) {
-    WSLoaderResult<InputStream> result = wsLoader.loadStream(RULES_SEARCH_URL);
-    ListResponse list = loadFromStream(result.get());
-    if (fromCache != null) {
-      fromCache.setValue(result.isFromCache());
-    }
+  public List<Rule> load() {
+    GetRequest getRequest = new GetRequest(RULES_SEARCH_URL);
+    ListResponse list = loadFromStream(wsClient.call(getRequest).contentStream());
     return list.getRulesList();
   }
 
index 9572f628f2d2595a84269817915a7ec02d3f6f86..1c4c8df4db2f98c405f30335d5a9980b29f6d090 100644 (file)
 package org.sonar.batch.rule;
 
 import java.util.List;
-import javax.annotation.Nullable;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.sonarqube.ws.Rules.ListResponse.Rule;
 
 public interface RulesLoader {
-  List<Rule> load(@Nullable MutableBoolean fromCache);
+  List<Rule> load();
 }
index 7a3e0ea34f07ed65637fdff32f41150c7bb28ae0..fcc71194a70238182d23a9d9e91ce2b10041830b 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.batch.rule;
 
-import org.apache.commons.lang.mutable.MutableBoolean;
-
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.log.Profiler;
@@ -48,8 +46,7 @@ public class RulesProvider extends ProviderAdapter {
 
   private static Rules load(RulesLoader ref) {
     Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-    MutableBoolean fromCache = new MutableBoolean();
-    List<Rule> loadedRules = ref.load(fromCache);
+    List<Rule> loadedRules = ref.load();
     RulesBuilder builder = new RulesBuilder();
 
     for (Rule r : loadedRules) {
@@ -58,7 +55,7 @@ public class RulesProvider extends ProviderAdapter {
       newRule.setInternalKey(r.getInternalKey());
     }
 
-    profiler.stopInfo(fromCache.booleanValue());
+    profiler.stopInfo();
 
     return builder.build();
   }
index cd779df9e8eef296f072b1d04e08e5cae21ce85d..44bc53afed5130a0142ebf4f9e2196f6ed24ca85 100644 (file)
@@ -38,7 +38,6 @@ import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.utils.MessageException;
@@ -107,15 +106,11 @@ public class ProjectReactorBuilder {
   private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, CoreProperties.WORKING_DIRECTORY, PROPERTY_MODULES,
     CoreProperties.PROJECT_DESCRIPTION_PROPERTY);
 
-  private static final String NON_ASSOCIATED_PROJECT_KEY = "project";
-
   private final AnalysisProperties analysisProps;
-  private final AnalysisMode analysisMode;
   private File rootProjectWorkDir;
 
-  public ProjectReactorBuilder(AnalysisProperties props, AnalysisMode analysisMode) {
+  public ProjectReactorBuilder(AnalysisProperties props) {
     this.analysisProps = props;
-    this.analysisMode = analysisMode;
   }
 
   public ProjectReactor execute() {
@@ -169,15 +164,7 @@ public class ProjectReactorBuilder {
     }
   }
 
-  private static void prepareNonAssociatedProject(Map<String, String> props, AnalysisMode mode) {
-    if (mode.isIssues() && !props.containsKey(CoreProperties.PROJECT_KEY_PROPERTY)) {
-      props.put(CoreProperties.PROJECT_KEY_PROPERTY, NON_ASSOCIATED_PROJECT_KEY);
-    }
-  }
-
   protected ProjectDefinition defineRootProject(Map<String, String> rootProperties, @Nullable ProjectDefinition parent) {
-    prepareNonAssociatedProject(rootProperties, analysisMode);
-
     if (rootProperties.containsKey(PROPERTY_MODULES)) {
       checkMandatoryProperties(rootProperties, MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT);
     } else {
index 23c83b365507c04a8efca3cc0ea790cdde74025f..91c383d55c68bfa307379168de50f7e66f5f3871 100644 (file)
@@ -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;
   }
 
index 2d8ee157b9dec1a81ea34933a308de62b13d0031..b9d6c47bcf80a85cbb5528df2422d7516f2aa141 100644 (file)
@@ -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;
index c5ba59c3d37989a11d6a891e423f2a52b7504461..80b338e0a6e784401bf3b7e2514ef48c571c359a 100644 (file)
  */
 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 (file)
index 0000000..ffe7e82
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch;
+
+import org.apache.commons.lang.StringUtils;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.sonar.batch.bootstrap.BatchWsClient;
+import org.sonarqube.ws.client.WsRequest;
+import org.sonarqube.ws.client.WsResponse;
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class WsTestUtil {
+  public static void mockStream(BatchWsClient mock, String path, InputStream is) {
+    WsResponse response = mock(WsResponse.class);
+    when(response.contentStream()).thenReturn(is);
+    when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
+  }
+
+  public static void mockStream(BatchWsClient mock, InputStream is) {
+    WsResponse response = mock(WsResponse.class);
+    when(response.contentStream()).thenReturn(is);
+    when(mock.call(any(WsRequest.class))).thenReturn(response);
+  }
+
+  public static void mockReader(BatchWsClient mock, Reader reader) {
+    WsResponse response = mock(WsResponse.class);
+    when(response.contentReader()).thenReturn(reader);
+    when(mock.call(any(WsRequest.class))).thenReturn(response);
+  }
+
+  public static void mockReader(BatchWsClient mock, String path, Reader reader) {
+    WsResponse response = mock(WsResponse.class);
+    when(response.contentReader()).thenReturn(reader);
+    when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
+  }
+
+  public static void mockException(BatchWsClient mock, Exception e) {
+    when(mock.call(any(WsRequest.class))).thenThrow(e);
+  }
+
+  public static void mockException(BatchWsClient mock, String path, Exception e) {
+    when(mock.call(argThat(new RequestMatcher(path)))).thenThrow(e);
+  }
+
+  public static void verifyCall(BatchWsClient mock, String path) {
+    verify(mock).call(argThat(new RequestMatcher(path)));
+  }
+
+  private static class RequestMatcher extends BaseMatcher<WsRequest> {
+    private String path;
+
+    public RequestMatcher(String path) {
+      this.path = path;
+    }
+
+    @Override
+    public boolean matches(Object item) {
+      if (item == null) {
+        return false;
+      }
+      WsRequest request = (WsRequest) item;
+      return StringUtils.equals(request.getPath(), path);
+    }
+
+    @Override
+    public void describeTo(Description description) {
+      description.appendText("request path (\"" + path + "\")");
+    }
+  }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/analysis/AnalysisWSLoaderProviderTest.java
deleted file mode 100644 (file)
index 66ab296..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.analysis;
-
-import com.google.common.collect.ImmutableMap;
-import org.assertj.core.util.Maps;
-import org.junit.Test;
-import org.sonar.api.batch.AnalysisMode;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class AnalysisWSLoaderProviderTest {
-
-  PersistentCache cache = mock(PersistentCache.class);
-  BatchWsClient wsClient = mock(BatchWsClient.class);
-  AnalysisMode mode = mock(AnalysisMode.class);
-
-  AnalysisWSLoaderProvider underTest = new AnalysisWSLoaderProvider();
-
-  @Test
-  public void testDefault() {
-    WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap()));
-    assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
-  }
-
-  @Test
-  public void no_cache_by_default_in_issues_mode() {
-    when(mode.isIssues()).thenReturn(true);
-    WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(Maps.<String, String>newHashMap()));
-    assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.SERVER_ONLY);
-  }
-
-  @Test
-  public void enable_cache_in_issues_mode() {
-    when(mode.isIssues()).thenReturn(true);
-    WSLoader loader = underTest.provide(mode, cache, wsClient, new AnalysisProperties(ImmutableMap.of(AnalysisWSLoaderProvider.SONAR_USE_WS_CACHE, "true")));
-    assertThat(loader.getDefaultStrategy()).isEqualTo(LoadStrategy.CACHE_ONLY);
-  }
-}
index 95e17ca849a72a1d0b8be67957740f55a2570881..4c2deee6ebb0ade9eba2b23c1d774e80dc092024 100644 (file)
 package org.sonar.batch.bootstrap;
 
 import java.io.File;
+import java.io.StringReader;
 import java.util.List;
+
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
 import org.sonar.core.platform.RemotePlugin;
 import org.sonar.home.cache.FileCache;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -45,16 +46,19 @@ public class BatchPluginInstallerTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  FileCache fileCache = mock(FileCache.class);
-  BatchWsClient wsClient = mock(BatchWsClient.class);
-  BatchPluginPredicate pluginPredicate = mock(BatchPluginPredicate.class);
+  private FileCache fileCache = mock(FileCache.class);
+  private BatchWsClient wsClient;
+  private BatchPluginPredicate pluginPredicate = mock(BatchPluginPredicate.class);
+
+  @Before
+  public void setUp() {
+    wsClient = mock(BatchWsClient.class);
+  }
 
   @Test
   public void listRemotePlugins() {
-
-    WSLoader wsLoader = mock(WSLoader.class);
-    when(wsLoader.loadString("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<>("checkstyle\nsqale", true));
-    BatchPluginInstaller underTest = new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate);
+    WsTestUtil.mockReader(wsClient, "/deploy/plugins/index.txt", new StringReader("checkstyle\nsqale"));
+    BatchPluginInstaller underTest = new BatchPluginInstaller(wsClient, fileCache, pluginPredicate);
 
     List<RemotePlugin> remotePlugins = underTest.listRemotePlugins();
     assertThat(remotePlugins).extracting("key").containsOnly("checkstyle", "sqale");
@@ -65,8 +69,7 @@ public class BatchPluginInstallerTest {
     File pluginJar = temp.newFile();
     when(fileCache.get(eq("checkstyle-plugin.jar"), eq("fakemd5_1"), any(FileCache.Downloader.class))).thenReturn(pluginJar);
 
-    WSLoader wsLoader = mock(WSLoader.class);
-    BatchPluginInstaller underTest = new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate);
+    BatchPluginInstaller underTest = new BatchPluginInstaller(wsClient, fileCache, pluginPredicate);
 
     RemotePlugin remote = new RemotePlugin("checkstyle").setFile("checkstyle-plugin.jar", "fakemd5_1");
     File file = underTest.download(remote);
@@ -76,11 +79,9 @@ public class BatchPluginInstallerTest {
 
   @Test
   public void should_fail_to_get_plugin_index() {
+    WsTestUtil.mockException(wsClient, "/deploy/plugins/index.txt", new IllegalStateException());
     thrown.expect(IllegalStateException.class);
 
-    WSLoader wsLoader = mock(WSLoader.class);
-    doThrow(new IllegalStateException()).when(wsLoader).loadString("/deploy/plugins/index.txt");
-
-    new BatchPluginInstaller(wsLoader, wsClient, fileCache, pluginPredicate).installRemotes();
+    new BatchPluginInstaller(wsClient, fileCache, pluginPredicate).installRemotes();
   }
 }
index 41152b3ccb56cdd55db793e371cbb5bf86cdc216..0019d8adc18fa17df84dc004d34f5319bdda3ae5 100644 (file)
@@ -42,7 +42,7 @@ public class GlobalContainerTest {
     Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(),
       CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath());
 
-    GlobalContainer container = GlobalContainer.create(props, extensions, false);
+    GlobalContainer container = GlobalContainer.create(props, extensions);
     container.doBeforeStart();
     return container;
   }
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/DefaultProjectCacheStatusTest.java
deleted file mode 100644 (file)
index c8f105d..0000000
+++ /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 (file)
index 3f019ca..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import org.sonar.home.cache.PersistentCache;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
-
-import static org.junit.Assert.*;
-import static org.assertj.core.api.Assertions.assertThat;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-
-public class GlobalPersistentCacheProviderTest {
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  private GlobalPersistentCacheProvider provider;
-  private GlobalProperties globalProperties;
-
-  @Before
-  public void setUp() {
-    HashMap<String, String> map = new HashMap<>();
-    map.put("sonar.userHome", temp.getRoot().getAbsolutePath());
-    globalProperties = new GlobalProperties(map);
-    provider = new GlobalPersistentCacheProvider();
-  }
-
-  @Test
-  public void test_path() {
-    PersistentCache cache = provider.provide(globalProperties);
-    assertThat(cache.getDirectory()).isEqualTo(temp.getRoot().toPath()
-      .resolve("ws_cache")
-      .resolve("http%3A%2F%2Flocalhost%3A9000")
-      .resolve("global"));
-  }
-
-  @Test
-  public void test_singleton() {
-    assertTrue(provider.provide(globalProperties) == provider.provide(globalProperties));
-  }
-
-  @Test
-  public void test_without_sonar_home() {
-    globalProperties = new GlobalProperties(new HashMap<String, String>());
-    PersistentCache cache = provider.provide(globalProperties);
-    assertThat(cache.getDirectory().toAbsolutePath().toString()).startsWith(findHome().toAbsolutePath().toString());
-
-  }
-
-  private static Path findHome() {
-    String home = System.getenv("SONAR_USER_HOME");
-
-    if (home != null) {
-      return Paths.get(home);
-    }
-
-    home = System.getProperty("user.home");
-    return Paths.get(home, ".sonar");
-  }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/NonAssociatedCacheSynchronizerTest.java
deleted file mode 100644 (file)
index c06bb94..0000000
+++ /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 (file)
index 52df42e..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import org.apache.commons.lang.mutable.MutableBoolean;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.sonar.batch.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.batch.repository.DefaultQualityProfileLoader;
-import org.sonar.batch.repository.DefaultServerIssuesLoader;
-import org.sonar.batch.repository.ProjectRepositories;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.repository.user.UserRepositoryLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.DefaultActiveRulesLoader;
-import org.sonar.batch.rule.LoadedActiveRule;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-public class ProjectCacheSynchronizerTest {
-  private static final String PROJECT_KEY = "org.codehaus.sonar-plugins:sonar-scm-git-plugin";
-
-  @Rule
-  public ExpectedException exception = ExpectedException.none();
-
-  @Mock
-  private ProjectDefinition project;
-  @Mock
-  private ProjectCacheStatus cacheStatus;
-  @Mock
-  private DefaultAnalysisMode analysisMode;
-  @Mock
-  private AnalysisProperties properties;
-  @Mock
-  private RulesLoader rulesLoader;
-
-  private ServerIssuesLoader issuesLoader;
-  private UserRepositoryLoader userRepositoryLoader;
-  private QualityProfileLoader qualityProfileLoader;
-  private ActiveRulesLoader activeRulesLoader;
-  private ProjectRepositoriesLoader projectRepositoriesLoader;
-
-  @Before
-  public void setUp() throws IOException {
-    MockitoAnnotations.initMocks(this);
-
-    when(analysisMode.isIssues()).thenReturn(true);
-    when(properties.properties()).thenReturn(new HashMap<String, String>());
-  }
-
-  private ProjectCacheSynchronizer createMockedLoaders(boolean projectExists, Date lastAnalysisDate) {
-    issuesLoader = mock(DefaultServerIssuesLoader.class);
-    userRepositoryLoader = mock(UserRepositoryLoader.class);
-    qualityProfileLoader = mock(DefaultQualityProfileLoader.class);
-    activeRulesLoader = mock(DefaultActiveRulesLoader.class);
-    projectRepositoriesLoader = mock(DefaultProjectRepositoriesLoader.class);
-
-    QualityProfile pf = QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").build();
-    LoadedActiveRule ar = new LoadedActiveRule();
-    ProjectRepositories repo = mock(ProjectRepositories.class);
-
-    when(qualityProfileLoader.load(PROJECT_KEY, null, null)).thenReturn(ImmutableList.of(pf));
-    when(qualityProfileLoader.loadDefault(null, null)).thenReturn(ImmutableList.of(pf));
-    when(activeRulesLoader.load("profile", null)).thenReturn(ImmutableList.of(ar));
-    when(repo.lastAnalysisDate()).thenReturn(lastAnalysisDate);
-    when(repo.exists()).thenReturn(projectExists);
-    when(projectRepositoriesLoader.load(anyString(), anyBoolean(), any(MutableBoolean.class))).thenReturn(repo);
-
-    return new ProjectCacheSynchronizer(rulesLoader, qualityProfileLoader, projectRepositoriesLoader, activeRulesLoader, issuesLoader, userRepositoryLoader, cacheStatus);
-  }
-
-  @Test
-  public void testLoadersUsage() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-    synchronizer.load(PROJECT_KEY, false);
-
-    verify(issuesLoader).load(eq(PROJECT_KEY), any(Function.class));
-    verify(rulesLoader).load(null);
-    verify(qualityProfileLoader).load(PROJECT_KEY, null, null);
-    verify(activeRulesLoader).load("profile", null);
-    verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class));
-
-    verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader);
-  }
-
-  @Test
-  public void testLoadersUsage_NoLastAnalysis() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, null);
-    synchronizer.load(PROJECT_KEY, false);
-
-    verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class));
-    verify(qualityProfileLoader).load(PROJECT_KEY, null, null);
-    verify(activeRulesLoader).load("profile", null);
-
-    verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader);
-  }
-
-  @Test
-  public void testLoadersUsage_ProjectDoesntExist() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(false, null);
-    synchronizer.load(PROJECT_KEY, false);
-
-    verify(projectRepositoriesLoader).load(eq(PROJECT_KEY), eq(true), any(MutableBoolean.class));
-    verify(qualityProfileLoader).loadDefault(null, null);
-    verify(activeRulesLoader).load("profile", null);
-
-    verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader);
-  }
-
-  @Test
-  public void testLastAnalysisToday() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
-    when(cacheStatus.getSyncStatus()).thenReturn(new Date());
-    synchronizer.load(PROJECT_KEY, false);
-
-    verify(cacheStatus).getSyncStatus();
-    verifyNoMoreInteractions(issuesLoader, userRepositoryLoader, qualityProfileLoader, activeRulesLoader, projectRepositoriesLoader, cacheStatus);
-  }
-
-  @Test
-  public void testLastAnalysisYesterday() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
-    Date d = new Date(new Date().getTime() - 60 * 60 * 24 * 1000);
-    when(cacheStatus.getSyncStatus()).thenReturn(d);
-    synchronizer.load(PROJECT_KEY, false);
-
-    verify(cacheStatus).save();
-    verify(cacheStatus).getSyncStatus();
-  }
-
-  @Test
-  public void testDontFailOnError() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
-    Date d = new Date(new Date().getTime() - 60 * 60 * 24 * 1000);
-    when(cacheStatus.getSyncStatus()).thenReturn(d);
-
-    when(projectRepositoriesLoader.load(anyString(), anyBoolean(), any(MutableBoolean.class))).thenThrow(IllegalStateException.class);
-    synchronizer.load(PROJECT_KEY, false);
-
-    verify(cacheStatus).getSyncStatus();
-    verifyNoMoreInteractions(cacheStatus);
-  }
-
-  @Test
-  public void testForce() {
-    ProjectCacheSynchronizer synchronizer = createMockedLoaders(true, new Date());
-
-    when(cacheStatus.getSyncStatus()).thenReturn(new Date());
-    synchronizer.load(PROJECT_KEY, true);
-
-    verify(cacheStatus).save();
-    verify(cacheStatus).getSyncStatus();
-  }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectPersistentCacheProviderTest.java
deleted file mode 100644 (file)
index 69c1425..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import org.sonar.api.batch.bootstrap.ProjectKey;
-
-import org.sonar.batch.util.BatchUtils;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.batch.cache.ProjectPersistentCacheProvider;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Collections;
-
-import static org.mockito.Mockito.mock;
-import org.junit.Before;
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.Test;
-
-public class ProjectPersistentCacheProviderTest {
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
-  private ProjectPersistentCacheProvider provider = null;
-  private GlobalProperties props = null;
-  private DefaultAnalysisMode mode = null;
-  private ProjectKey key = null;
-
-  @Before
-  public void prepare() {
-    key = new ProjectKeySupplier("proj");
-    props = new GlobalProperties(Collections.<String, String>emptyMap());
-    mode = mock(DefaultAnalysisMode.class);
-    provider = new ProjectPersistentCacheProvider();
-  }
-
-  @Test
-  public void test_singleton() {
-    assertThat(provider.provide(props, mode, key)).isEqualTo(provider.provide(props, mode, key));
-  }
-
-  @Test
-  public void test_cache_dir() {
-    assertThat(provider.provide(props, mode, key).getDirectory().toFile()).exists().isDirectory();
-  }
-
-  @Test
-  public void test_home() {
-    File f = temp.getRoot();
-    props.properties().put("sonar.userHome", f.getAbsolutePath());
-    Path expected = f.toPath()
-      .resolve("ws_cache")
-      .resolve("http%3A%2F%2Flocalhost%3A9000")
-      .resolve( BatchUtils.getServerVersion())
-      .resolve("projects")
-      .resolve("proj");
-
-    assertThat(provider.provide(props, mode, key).getDirectory()).isEqualTo(expected);
-  }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/ProjectSyncContainerTest.java
deleted file mode 100644 (file)
index 948f888..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import java.util.HashMap;
-import org.junit.Test;
-import org.sonar.batch.bootstrap.GlobalProperties;
-import org.sonar.core.platform.ComponentContainer;
-import org.sonar.home.cache.PersistentCache;
-import org.sonar.scanner.protocol.input.ProjectRepositories;
-import org.sonarqube.ws.client.WsClient;
-
-import static org.mockito.Mockito.mock;
-
-public class ProjectSyncContainerTest {
-  private ComponentContainer createParentContainer() {
-    PersistentCache cache = mock(PersistentCache.class);
-    WsClient server = mock(WsClient.class);
-
-    GlobalProperties globalProps = new GlobalProperties(new HashMap<String, String>());
-    ComponentContainer parent = new ComponentContainer();
-    parent.add(cache);
-    parent.add(server);
-    parent.add(globalProps);
-    return parent;
-  }
-
-  @Test
-  public void testProjectRepository() {
-    ProjectSyncContainer container = new ProjectSyncContainer(createParentContainer(), "my:project", true);
-    container.doBeforeStart();
-    container.getPicoContainer().start();
-    container.getComponentByType(ProjectRepositories.class);
-  }
-}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/cache/StrategyWSLoaderProviderTest.java
deleted file mode 100644 (file)
index ce9d88a..0000000
+++ /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 (file)
index ad7bb76..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.cache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import org.apache.commons.io.IOUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.InOrder;
-import org.mockito.Mockito;
-import org.sonar.batch.bootstrap.BatchWsClient;
-import org.sonar.batch.cache.WSLoader.LoadStrategy;
-import org.sonar.home.cache.PersistentCache;
-import org.sonarqube.ws.client.HttpException;
-import org.sonarqube.ws.client.MockWsResponse;
-import org.sonarqube.ws.client.WsRequest;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-public class WSLoaderTest {
-  private final static String ID = "dummy";
-  private final static String cacheValue = "cache";
-  private final static String serverValue = "server";
-
-  @Rule
-  public ExpectedException exception = ExpectedException.none();
-
-  BatchWsClient ws = mock(BatchWsClient.class, Mockito.RETURNS_DEEP_STUBS);
-  PersistentCache cache = mock(PersistentCache.class);
-
-  @Test
-  public void dont_retry_server_offline() throws IOException {
-    turnServerOffline();
-    when(cache.getString(ID)).thenReturn(cacheValue);
-    WSLoader underTest = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
-    assertResult(underTest.loadString(ID), cacheValue, true);
-    assertResult(underTest.loadString(ID), cacheValue, true);
-
-    assertUsedServer(1);
-    assertUsedCache(2);
-  }
-
-  @Test
-  public void get_stream_from_cache() throws IOException {
-    InputStream is = IOUtils.toInputStream("is");
-    when(cache.getStream(ID)).thenReturn(is);
-
-    WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws);
-    WSLoaderResult<InputStream> result = loader.loadStream(ID);
-
-    assertThat(result.get()).isEqualTo(is);
-    verify(cache).getStream(ID);
-    verifyNoMoreInteractions(cache, ws);
-  }
-
-  @Test
-  public void put_stream_in_cache() throws IOException {
-    InputStream input = IOUtils.toInputStream("is");
-
-    when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(input));
-    when(cache.getStream(ID)).thenReturn(input);
-
-    // SERVER_FIRST -> load from server then put to cache
-    WSLoader underTest = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-    WSLoaderResult<InputStream> result = underTest.loadStream(ID);
-    assertThat(result.get()).isEqualTo(input);
-
-    InOrder inOrder = inOrder(ws, cache);
-    inOrder.verify(ws).call(any(WsRequest.class));
-    inOrder.verify(cache).put(eq(ID), any(InputStream.class));
-    inOrder.verify(cache).getStream(ID);
-    verifyNoMoreInteractions(cache, ws);
-  }
-
-  @Test
-  public void test_cache_strategy_fallback() throws IOException {
-    turnCacheEmpty();
-    when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
-    WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws);
-
-    assertResult(loader.loadString(ID), serverValue, false);
-
-    InOrder inOrder = inOrder(ws, cache);
-    inOrder.verify(cache).getString(ID);
-    inOrder.verify(ws).call(any(WsRequest.class));
-  }
-
-  @Test
-  public void test_server_strategy_fallback() throws IOException {
-    turnServerOffline();
-    when(cache.getString(ID)).thenReturn(cacheValue);
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
-    assertResult(loader.loadString(ID), cacheValue, true);
-
-    InOrder inOrder = inOrder(ws, cache);
-    inOrder.verify(ws).call(any(WsRequest.class));
-    inOrder.verify(cache).getString(ID);
-  }
-
-  @Test
-  public void test_put_cache() throws IOException {
-    when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-    loader.loadString(ID);
-    verify(cache).put(ID, serverValue.getBytes());
-  }
-
-  @Test
-  public void test_throw_cache_exception_fallback() throws IOException {
-    turnServerOffline();
-
-    when(cache.getString(ID)).thenThrow(new NullPointerException());
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
-    try {
-      loader.loadString(ID);
-      fail("NPE expected");
-    } catch (NullPointerException e) {
-      assertUsedServer(1);
-      assertUsedCache(1);
-    }
-  }
-
-  @Test
-  public void test_throw_cache_exception() throws IOException {
-    when(cache.getString(ID)).thenThrow(new IllegalStateException());
-
-    WSLoader loader = new WSLoader(LoadStrategy.CACHE_FIRST, cache, ws);
-
-    try {
-      loader.loadString(ID);
-      fail("IllegalStateException expected");
-    } catch (IllegalStateException e) {
-      assertUsedServer(0);
-      assertUsedCache(1);
-    }
-  }
-
-  @Test
-  public void test_throw_http_exceptions() {
-    when(ws.call(any(WsRequest.class))).thenThrow(new HttpException("url", 500));
-
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-
-    try {
-      loader.loadString(ID);
-      fail("IllegalStateException expected");
-    } catch (HttpException e) {
-      // cache should not be used
-      verifyNoMoreInteractions(cache);
-    }
-  }
-
-  @Test
-  public void test_server_only_not_available() {
-    turnServerOffline();
-
-    exception.expect(IllegalStateException.class);
-    exception.expectMessage("Server is not available");
-
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws);
-    loader.loadString(ID);
-  }
-
-  @Test
-  public void test_server_cache_not_available() throws IOException {
-    turnServerOffline();
-    turnCacheEmpty();
-
-    exception.expect(IllegalStateException.class);
-    exception.expectMessage("Server is not accessible and data is not cached");
-
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-    loader.loadString(ID);
-  }
-
-  @Test
-  public void test_cache_only_available() throws IOException {
-    turnCacheEmpty();
-
-    exception.expect(IllegalStateException.class);
-    exception.expectMessage("Data is not cached");
-
-    WSLoader loader = new WSLoader(LoadStrategy.CACHE_ONLY, cache, ws);
-    loader.loadString(ID);
-  }
-
-  @Test
-  public void test_server_strategy() throws IOException {
-    when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-    assertResult(loader.loadString(ID), serverValue, false);
-
-    // should not fetch from cache
-    verify(cache).put(ID, serverValue.getBytes());
-    verifyNoMoreInteractions(cache);
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void test_server_only() throws IOException {
-    turnServerOffline();
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws);
-    loader.loadString(ID);
-  }
-
-  @Test
-  public void test_string() {
-    when(ws.call(any(WsRequest.class))).thenReturn(new MockWsResponse().setContent(serverValue));
-    WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
-    assertResult(loader.loadString(ID), serverValue, false);
-  }
-
-  private void assertUsedCache(int times) throws IOException {
-    verify(cache, times(times)).getString(ID);
-  }
-
-  private void assertUsedServer(int times) {
-    verify(ws, times(times)).call(any(WsRequest.class));
-  }
-
-  private void assertResult(WSLoaderResult<String> result, String expected, boolean fromCache) {
-    assertThat(result).isNotNull();
-    assertThat(result.get()).isEqualTo(expected);
-    assertThat(result.isFromCache()).isEqualTo(fromCache);
-  }
-
-  private void turnServerOffline() {
-    when(ws.call(any(WsRequest.class))).thenThrow(new IllegalStateException());
-  }
-
-  private void turnCacheEmpty() throws IOException {
-    when(cache.getString(ID)).thenReturn(null);
-  }
-}
index 7d8ab1d2319e579ac56ab67b6e5e3bb674fe8055..38102f6a5dc61cc0e32f6575e4740836e1864673 100644 (file)
  */
 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");
   }
 
 }
index 9acf02b35779aedd1b3b1ceedc60ffe429a67a66..d49cb46c9d75483a75c8915d2274720c18cc5f5a 100644 (file)
@@ -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);
index f405eea878547c35276296439a4ffd46421dbd4c..8055f7baae67fdc74686eec3dd07fefb18d0297a 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.batch.rule.ActiveRulesLoader;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
 import org.sonar.batch.repository.QualityProfileLoader;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
 
 import javax.annotation.Nullable;
 
@@ -43,8 +42,6 @@ import org.sonar.batch.rule.RulesLoader;
 import org.sonar.scanner.protocol.input.GlobalRepositories;
 import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
 import com.google.common.base.Function;
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.Table;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -59,35 +56,19 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import javax.annotation.Nullable;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.Plugin;
 import org.sonar.api.batch.debt.internal.DefaultDebtModel;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Metric;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.server.rule.RulesDefinition.Repository;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.batch.bootstrapper.Batch;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.bootstrapper.IssueListener;
 import org.sonar.batch.bootstrapper.LogOutput;
 import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
 import org.sonar.batch.report.ReportPublisher;
-import org.sonar.batch.repository.FileData;
 import org.sonar.batch.repository.GlobalRepositoriesLoader;
-import org.sonar.batch.repository.ProjectRepositories;
 import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.QualityProfileLoader;
 import org.sonar.batch.repository.ServerIssuesLoader;
-import org.sonar.batch.rule.ActiveRulesLoader;
-import org.sonar.batch.rule.LoadedActiveRule;
-import org.sonar.batch.rule.RulesLoader;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.sonarqube.ws.Rules.ListResponse.Rule;
 
 /**
  * Main utility class for writing batch medium tests.
@@ -381,7 +362,7 @@ public class BatchMediumTester {
     }
 
     @Override
-    public List<Rule> load(@Nullable MutableBoolean fromCache) {
+    public List<Rule> load() {
       return rules;
     }
   }
@@ -394,7 +375,7 @@ public class BatchMediumTester {
     }
 
     @Override
-    public List<LoadedActiveRule> load(String qualityProfileKey, MutableBoolean fromCache) {
+    public List<LoadedActiveRule> load(String qualityProfileKey) {
       return activeRules;
     }
   }
@@ -406,7 +387,7 @@ public class BatchMediumTester {
     private GlobalRepositories ref = new GlobalRepositories();
 
     @Override
-    public GlobalRepositories load(@Nullable MutableBoolean fromCache) {
+    public GlobalRepositories load() {
       return ref;
     }
 
@@ -439,7 +420,7 @@ public class BatchMediumTester {
     private Date lastAnalysisDate;
 
     @Override
-    public ProjectRepositories load(String projectKey, boolean isIssuesMode, @Nullable MutableBoolean fromCache) {
+    public ProjectRepositories load(String projectKey, boolean isIssuesMode) {
       Table<String, String, String> settings = HashBasedTable.create();
       return new ProjectRepositories(settings, fileDataTable, lastAnalysisDate);
     }
@@ -470,12 +451,12 @@ public class BatchMediumTester {
     }
 
     @Override
-    public List<QualityProfile> load(String projectKey, String profileName, MutableBoolean fromCache) {
+    public List<QualityProfile> load(String projectKey, String profileName) {
       return qualityProfiles;
     }
 
     @Override
-    public List<QualityProfile> loadDefault(String profileName, MutableBoolean fromCache) {
+    public List<QualityProfile> loadDefault(String profileName) {
       return qualityProfiles;
     }
   }
@@ -489,11 +470,10 @@ public class BatchMediumTester {
     }
 
     @Override
-    public boolean load(String componentKey, Function<ServerIssue, Void> consumer) {
+    public void load(String componentKey, Function<ServerIssue, Void> consumer) {
       for (ServerIssue serverIssue : serverIssues) {
         consumer.apply(serverIssue);
       }
-      return true;
     }
   }
 
@@ -501,7 +481,7 @@ public class BatchMediumTester {
     private Map<String, String[]> byKey = new HashMap<>();
 
     @Override
-    public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) {
+    public String[] getLineHashes(String fileKey) {
       if (byKey.containsKey(fileKey)) {
         return byKey.get(fileKey);
       } else {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java
deleted file mode 100644 (file)
index 4ebf5eb..0000000
+++ /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 (file)
index 32c66f2..0000000
+++ /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();
-
-  }
-}
index db1a2dcd30ed18149ddb6bb43b17bf689d91c89d..2e2d8ea4c4753a2f1311cec3043da1509d87c6bf 100644 (file)
@@ -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);
index cb3781e5103d04a9c79b3da6b1d0ae1bfa0140e3..c902ee3658ad5407089ddaf77998ecf2a1905f79 100644 (file)
  */
 package org.sonar.batch.repository;
 
-import org.apache.commons.lang.mutable.MutableBoolean;
 import org.junit.Before;
-import org.junit.Test;
-import org.sonar.batch.cache.WSLoader;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonar.scanner.protocol.input.GlobalRepositories;
 
-import static org.assertj.core.api.Assertions.assertThat;
+import java.io.StringReader;
+
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
 
 public class DefaultGlobalRepositoriesLoaderTest {
   private static final String BATCH_GLOBAL_URL = "/batch/global";
-  private WSLoader wsLoader;
-  private WSLoaderResult<String> result;
+  private BatchWsClient wsClient;
   private DefaultGlobalRepositoriesLoader globalRepositoryLoader;
 
   @Before
   public void setUp() {
-    wsLoader = mock(WSLoader.class);
-    result = new WSLoaderResult<>(new GlobalRepositories().toJson(), true);
-    when(wsLoader.loadString(BATCH_GLOBAL_URL)).thenReturn(result);
-
-    globalRepositoryLoader = new DefaultGlobalRepositoriesLoader(wsLoader);
+    wsClient = mock(BatchWsClient.class);
+    WsTestUtil.mockReader(wsClient, BATCH_GLOBAL_URL, new StringReader(new GlobalRepositories().toJson()));
+    globalRepositoryLoader = new DefaultGlobalRepositoriesLoader(wsClient);
   }
 
-  @Test
   public void test() {
-    MutableBoolean fromCache = new MutableBoolean();
-    globalRepositoryLoader.load(fromCache);
-
-    assertThat(fromCache.booleanValue()).isTrue();
-    verify(wsLoader).loadString(BATCH_GLOBAL_URL);
-    verifyNoMoreInteractions(wsLoader);
-  }
-  
-  @Test
-  public void testFromServer() {
-    result = new WSLoaderResult<>(new GlobalRepositories().toJson(), false);
-    when(wsLoader.loadString(BATCH_GLOBAL_URL)).thenReturn(result);
-    MutableBoolean fromCache = new MutableBoolean();
-    globalRepositoryLoader.load(fromCache);
-
-    assertThat(fromCache.booleanValue()).isFalse();
-    verify(wsLoader).loadString(BATCH_GLOBAL_URL);
-    verifyNoMoreInteractions(wsLoader);
-  }
-
-  public void testWithoutArg() {
-    globalRepositoryLoader.load(null);
-
-    verify(wsLoader).loadString(BATCH_GLOBAL_URL);
-    verifyNoMoreInteractions(wsLoader);
+    globalRepositoryLoader.load();
+    WsTestUtil.verifyCall(wsClient, BATCH_GLOBAL_URL);
+    verifyNoMoreInteractions(wsClient);
   }
 }
index d633820ca836026ca23a09ec25b5948f0f6c433e..b92301c26472567230c9593c67ac391751bd8b02 100644 (file)
@@ -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");
 
index d3b4ce6b87dd88f9b36d6d2f61f671778fdc71cb..8110c2a273f393d2b6eda260be4c53f572de9c78 100644 (file)
@@ -24,8 +24,8 @@ import org.sonar.api.utils.MessageException;
 import org.sonarqube.ws.QualityProfiles;
 import com.google.common.io.Resources;
 import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.junit.Rule;
 import org.junit.rules.ExpectedException;
 import org.junit.Before;
@@ -38,9 +38,7 @@ import java.io.InputStream;
 import java.util.List;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -49,50 +47,49 @@ public class DefaultQualityProfileLoaderTest {
   public ExpectedException exception = ExpectedException.none();
 
   private DefaultQualityProfileLoader qpLoader;
-  private WSLoader ws;
+  private BatchWsClient wsClient;
   private InputStream is;
 
   @Before
   public void setUp() throws IOException {
-    ws = mock(WSLoader.class);
+    wsClient = mock(BatchWsClient.class);
     is = mock(InputStream.class);
     when(is.read()).thenReturn(-1);
-    WSLoaderResult<InputStream> result = new WSLoaderResult<>(is, false);
-    when(ws.loadStream(anyString())).thenReturn(result);
-    qpLoader = new DefaultQualityProfileLoader(ws);
+    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is);
+    qpLoader = new DefaultQualityProfileLoader(wsClient);
   }
 
   @Test
   public void testEncoding() throws IOException {
-    WSLoaderResult<InputStream> result = new WSLoaderResult<>(createEncodedQP("qp"), false);
-    when(ws.loadStream(anyString())).thenReturn(result);
+    InputStream is = createEncodedQP("qp");
+    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232", is);
 
-    List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2", null);
-    verify(ws).loadStream("/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232");
-    verifyNoMoreInteractions(ws);
+    List<QualityProfile> loaded = qpLoader.load("foo#2", "my-profile#2");
+    WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?projectKey=foo%232&profileName=my-profile%232");
+    verifyNoMoreInteractions(wsClient);
     assertThat(loaded).hasSize(1);
   }
 
   @Test
   public void testNoProfile() throws IOException {
     InputStream is = createEncodedQP();
-    when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
+    WsTestUtil.mockStream(wsClient, is);
 
     exception.expect(MessageException.class);
     exception.expectMessage("No quality profiles");
 
-    qpLoader.load("project", null, null);
-    verifyNoMoreInteractions(ws);
+    qpLoader.load("project", null);
+    verifyNoMoreInteractions(wsClient);
   }
 
   @Test
   public void use_real_response() throws IOException {
     InputStream is = getTestResource("quality_profile_search_default");
-    when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, false));
+    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", is);
 
-    List<QualityProfile> loaded = qpLoader.loadDefault(null, null);
-    verify(ws).loadStream("/api/qualityprofiles/search.protobuf?defaults=true");
-    verifyNoMoreInteractions(ws);
+    List<QualityProfile> loaded = qpLoader.loadDefault(null);
+    WsTestUtil.verifyCall(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true");
+    verifyNoMoreInteractions(wsClient);
     assertThat(loaded).hasSize(1);
   }
 
index 22416368f3f33acd710733068456234c22820692..a2e978b3b4d07eaa1fd411f73e916223a34aaead 100644 (file)
  */
 package org.sonar.batch.repository;
 
-import org.sonar.batch.cache.WSLoaderResult;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonar.scanner.protocol.input.ScannerInput;
 import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue;
-import org.sonar.batch.cache.WSLoader;
 import com.google.common.base.Function;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,12 +39,12 @@ import static org.mockito.Mockito.when;
 
 public class DefaultServerIssuesLoaderTest {
   private DefaultServerIssuesLoader loader;
-  private WSLoader wsLoader;
+  private BatchWsClient wsClient;
 
   @Before
   public void prepare() {
-    wsLoader = mock(WSLoader.class);
-    loader = new DefaultServerIssuesLoader(wsLoader);
+    wsClient = mock(BatchWsClient.class);
+    loader = new DefaultServerIssuesLoader(wsClient);
   }
 
   @Test
@@ -57,7 +57,7 @@ public class DefaultServerIssuesLoaderTest {
       .writeDelimitedTo(bos);
 
     InputStream is = new ByteArrayInputStream(bos.toByteArray());
-    when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true));
+    WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is);
 
     final List<ServerIssue> result = new ArrayList<>();
     loader.load("foo", new Function<ScannerInput.ServerIssue, Void>() {
@@ -76,7 +76,7 @@ public class DefaultServerIssuesLoaderTest {
   public void testError() throws IOException {
     InputStream is = mock(InputStream.class);
     when(is.read()).thenThrow(IOException.class);
-    when(wsLoader.loadStream("/batch/issues.protobuf?key=foo")).thenReturn(new WSLoaderResult<>(is, true));
+    WsTestUtil.mockStream(wsClient, "/batch/issues.protobuf?key=foo", is);
     loader.load("foo", mock(Function.class));
   }
 }
index 781b48a2a596ff885f58dc9c192df1802333c784..cb0490f79f53fe72b67a2885224cbe19a3d1c9f0 100644 (file)
@@ -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);
   }
 }
index 0cd1683b9c97d9173d4087116549983cfad01443..bdbdb0ea703aa40145c4cfb26d3a7a2ab9634e5f 100644 (file)
@@ -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.");
index 870afd5737ea447504baa526fa7eb18bd06fc154..4b8982a8e74d48302ebfb4b01f40ef03ee16756a 100644 (file)
@@ -21,12 +21,10 @@ package org.sonar.batch.repository.user;
 
 import org.assertj.core.util.Lists;
 
-import org.sonar.batch.cache.WSLoaderResult;
 import org.sonar.scanner.protocol.input.ScannerInput;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.junit.Before;
-import com.google.common.collect.ImmutableList;
-import org.apache.commons.lang.mutable.MutableBoolean;
 import com.google.common.collect.ImmutableMap;
 import org.junit.rules.ExpectedException;
 import org.junit.Rule;
@@ -39,23 +37,21 @@ import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Map;
 
-import static org.mockito.Matchers.anyString;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class UserRepositoryLoaderTest {
   @Rule
   public final ExpectedException exception = ExpectedException.none();
 
-  private WSLoader wsLoader;
+  private BatchWsClient wsClient;
   private UserRepositoryLoader userRepo;
 
   @Before
   public void setUp() {
-    wsLoader = mock(WSLoader.class);
-    userRepo = new UserRepositoryLoader(wsLoader);
+    wsClient = mock(BatchWsClient.class);
+    userRepo = new UserRepositoryLoader(wsClient);
   }
 
   @Test
@@ -66,30 +62,15 @@ public class UserRepositoryLoaderTest {
   @Test
   public void testLoad() throws IOException {
     Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon");
-    WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(userMap), true);
-    when(wsLoader.loadStream("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res);
-
+    InputStream is = createUsersMock(userMap);
+    WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is);
     assertThat(userRepo.load(Arrays.asList("fmallet", "sbrandhof"))).extracting("login", "name").containsOnly(tuple("fmallet", "Freddy Mallet"), tuple("sbrandhof", "Simon"));
   }
 
-  @Test
-  public void testFromCache() throws IOException {
-    WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true);
-    when(wsLoader.loadStream(anyString())).thenReturn(res);
-    MutableBoolean fromCache = new MutableBoolean();
-    userRepo.load("", fromCache);
-    assertThat(fromCache.booleanValue()).isTrue();
-
-    fromCache.setValue(false);
-    userRepo.load(ImmutableList.of("user"), fromCache);
-    assertThat(fromCache.booleanValue()).isTrue();
-  }
-
   @Test
   public void testLoadSingleUser() throws IOException {
-    WSLoaderResult<InputStream> res = new WSLoaderResult<>(createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")), true);
-    when(wsLoader.loadStream("/batch/users?logins=fmallet")).thenReturn(res);
-
+    InputStream is = createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet"));
+    WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet", is);
     assertThat(userRepo.load("fmallet").getName()).isEqualTo("Freddy Mallet");
   }
 
@@ -107,9 +88,7 @@ public class UserRepositoryLoaderTest {
   public void testInputStreamError() throws IOException {
     InputStream is = mock(InputStream.class);
     Mockito.doThrow(IOException.class).when(is).read();
-    WSLoaderResult<InputStream> res = new WSLoaderResult<>(is, true);
-
-    when(wsLoader.loadStream("/batch/users?logins=fmallet,sbrandhof")).thenReturn(res);
+    WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is);
 
     exception.expect(IllegalStateException.class);
     exception.expectMessage("Unable to get user details from server");
index 1e1b1f0fc3c646c334a3614ef46d43d7075a1704..9e1c3b70504749c212ffd21533bf2c4aec1919cf 100644 (file)
@@ -60,9 +60,9 @@ public class ActiveRulesProviderTest {
     List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3);
     List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3);
 
-    when(loader.load(eq("qp1"), any(MutableBoolean.class))).thenReturn(qp1Rules);
-    when(loader.load(eq("qp2"), any(MutableBoolean.class))).thenReturn(qp2Rules);
-    when(loader.load(eq("qp3"), any(MutableBoolean.class))).thenReturn(qp3Rules);
+    when(loader.load(eq("qp1"))).thenReturn(qp1Rules);
+    when(loader.load(eq("qp2"))).thenReturn(qp2Rules);
+    when(loader.load(eq("qp3"))).thenReturn(qp3Rules);
 
     ModuleQProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
     ActiveRules activeRules = provider.provide(loader, profiles);
@@ -71,9 +71,9 @@ public class ActiveRulesProviderTest {
     assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly(
       RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3"));
 
-    verify(loader).load(eq("qp1"), any(MutableBoolean.class));
-    verify(loader).load(eq("qp2"), any(MutableBoolean.class));
-    verify(loader).load(eq("qp3"), any(MutableBoolean.class));
+    verify(loader).load(eq("qp1"));
+    verify(loader).load(eq("qp2"));
+    verify(loader).load(eq("qp3"));
     verifyNoMoreInteractions(loader);
   }
 
index 434c84dda9389fdb0e84b5b8353e75b033eb9ea6..40f2c462dd28aa9b220a38ace599ebe04217ad1d 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.batch.rule;
 
 import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import com.google.common.io.Resources;
 import org.junit.Test;
 
@@ -29,21 +29,19 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 
-import static org.mockito.Mockito.verify;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
 import org.junit.Before;
 
 public class DefaultActiveRulesLoaderTest {
   private DefaultActiveRulesLoader loader;
-  private WSLoader ws;
+  private BatchWsClient wsClient;
 
   @Before
   public void setUp() {
-    ws = mock(WSLoader.class);
-    loader = new DefaultActiveRulesLoader(ws);
+    wsClient = mock(BatchWsClient.class);
+    loader = new DefaultActiveRulesLoader(wsClient);
   }
 
   @Test
@@ -53,18 +51,19 @@ public class DefaultActiveRulesLoaderTest {
 
     String req1 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=1&ps=500";
     String req2 = "/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives&activation=true&qprofile=c%2B-test_c%2B-values-17445&p=2&ps=500";
-    when(ws.loadStream(req1)).thenReturn(new WSLoaderResult<>(response1, false));
-    when(ws.loadStream(req2)).thenReturn(new WSLoaderResult<>(response2, false));
+    WsTestUtil.mockStream(wsClient, req1, response1);
+    WsTestUtil.mockStream(wsClient, req2, response2);
 
-    Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445", null);
+    Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445");
     assertThat(activeRules).hasSize(226);
     assertActiveRule(activeRules);
-    
-    verify(ws).loadStream(req1);
-    verify(ws).loadStream(req2);
-    verifyNoMoreInteractions(ws);
+
+    WsTestUtil.verifyCall(wsClient, req1);
+    WsTestUtil.verifyCall(wsClient, req2);
+
+    verifyNoMoreInteractions(wsClient);
   }
-  
+
   private static void assertActiveRule(Collection<LoadedActiveRule> activeRules) {
     RuleKey key = RuleKey.of("squid", "S3008");
     for (LoadedActiveRule r : activeRules) {
index a5a461c4e9f5cf288c0b870a432045fb5dcc8ac4..ceaa22a494b6b876327b5d5d24502f5030d25c1f 100644 (file)
 package org.sonar.batch.rule;
 
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 import org.junit.rules.ExpectedException;
-import org.sonar.batch.cache.WSLoaderResult;
-import org.sonar.batch.cache.WSLoader;
-import org.apache.commons.lang.mutable.MutableBoolean;
+import org.sonar.batch.WsTestUtil;
+import org.sonar.batch.bootstrap.BatchWsClient;
 import org.sonarqube.ws.Rules.ListResponse.Rule;
 import com.google.common.io.ByteSource;
 import com.google.common.io.Resources;
@@ -33,7 +31,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
-import static org.mockito.Matchers.anyString;
 import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.Test;
 
@@ -43,37 +40,24 @@ public class DefaultRulesLoaderTest {
 
   @Test
   public void testParseServerResponse() throws IOException {
-    WSLoader wsLoader = mock(WSLoader.class);
+    BatchWsClient wsClient = mock(BatchWsClient.class);
     InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")).openBufferedStream();
-    when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
-    DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
-    List<Rule> ruleList = loader.load(null);
+    WsTestUtil.mockStream(wsClient, is);
+    DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
+    List<Rule> ruleList = loader.load();
     assertThat(ruleList).hasSize(318);
   }
 
-  @Test
-  public void testLoadedFromCache() throws IOException {
-    WSLoader wsLoader = mock(WSLoader.class);
-    InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoader/response.protobuf")).openBufferedStream();
-    when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
-    DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
-    MutableBoolean fromCache = new MutableBoolean();
-    loader.load(fromCache);
-
-    assertThat(fromCache.booleanValue()).isTrue();
-  }
-
   @Test
   public void testError() throws IOException {
-    WSLoader wsLoader = mock(WSLoader.class);
+    BatchWsClient wsClient = mock(BatchWsClient.class);
     InputStream is = ByteSource.wrap(new String("trash").getBytes()).openBufferedStream();
-    when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult<>(is, true));
-    DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
+    WsTestUtil.mockStream(wsClient, is);
+    DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
 
     exception.expect(IllegalStateException.class);
     exception.expectMessage("Unable to get rules");
 
-    loader.load(null);
+    loader.load();
   }
-
 }
index 2df29eaa61af27a64152abd0f47577a4be99822c..fcf2133be83b6d56af09a943c87674a38d5c0757 100644 (file)
  */
 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();
 
index c550bb3ba3916dc663c3a6acae810a84f3f025c6..c10bb04dd8b416fc735415cbade553c38912f641 100644 (file)
@@ -30,11 +30,9 @@ import java.util.Map;
 import java.util.Properties;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.utils.MessageException;
@@ -43,8 +41,6 @@ import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.batch.analysis.AnalysisProperties;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class ProjectReactorBuilderTest {
 
@@ -54,13 +50,6 @@ public class ProjectReactorBuilderTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  private AnalysisMode mode;
-
-  @Before
-  public void setUp() {
-    mode = mock(AnalysisMode.class);
-  }
-
   @Test
   public void shouldDefineSimpleProject() {
     ProjectDefinition projectDefinition = loadProjectDefinition("simple-project");
@@ -332,7 +321,7 @@ public class ProjectReactorBuilderTest {
     AnalysisProperties taskProperties = new AnalysisProperties(props, null);
     assertThat(taskProperties.property("module1.module11.property")).isEqualTo("My module11 property");
 
-    new ProjectReactorBuilder(taskProperties, mode).execute();
+    new ProjectReactorBuilder(taskProperties).execute();
 
     assertThat(taskProperties.property("module1.module11.property")).isNull();
   }
@@ -415,7 +404,7 @@ public class ProjectReactorBuilderTest {
 
   @Test
   public void shouldInitRootWorkDir() {
-    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null), mode);
+    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(Maps.<String, String>newHashMap(), null));
     File baseDir = new File("target/tmp/baseDir");
 
     File workDir = builder.initRootProjectWorkDir(baseDir, Maps.<String, String>newHashMap());
@@ -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<String, String> props = Maps.<String, String>newHashMap();
     props.put("sonar.working.directory", ".foo");
-    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null), mode);
+    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null));
     File baseDir = new File("target/tmp/baseDir");
 
     File workDir = builder.initRootProjectWorkDir(baseDir, props);
@@ -447,7 +428,7 @@ public class ProjectReactorBuilderTest {
   public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
     Map<String, String> props = Maps.<String, String>newHashMap();
     props.put("sonar.working.directory", new File("src").getAbsolutePath());
-    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null), mode);
+    ProjectReactorBuilder builder = new ProjectReactorBuilder(new AnalysisProperties(props, null));
     File baseDir = new File("target/tmp/baseDir");
 
     File workDir = builder.initRootProjectWorkDir(baseDir, props);
@@ -499,7 +480,7 @@ public class ProjectReactorBuilderTest {
   private ProjectDefinition loadProjectDefinition(String projectFolder) {
     Map<String, String> props = loadProps(projectFolder);
     AnalysisProperties bootstrapProps = new AnalysisProperties(props, null);
-    ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps, mode).execute();
+    ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps).execute();
     return projectReactor.getRoot();
   }
 
@@ -638,7 +619,7 @@ public class ProjectReactorBuilderTest {
     Map<String, String> props = loadProps("simple-project");
     props.put("sonar.qualitygate", "somevalue");
     AnalysisProperties bootstrapProps = new AnalysisProperties(props, null);
-    new ProjectReactorBuilder(bootstrapProps, mode).execute();
+    new ProjectReactorBuilder(bootstrapProps).execute();
 
     assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property 'sonar.qualitygate' is not supported any more. It will be ignored.");
   }
diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/multi-modules-sample-not-associated/module_a/module_a1/src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo
deleted file mode 100644 (file)
index 74d29a4..0000000
+++ /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 (file)
index 4203953..0000000
+++ /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 (file)
index b83c3af..0000000
+++ /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 (file)
index 20b8bb3..0000000
+++ /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 (file)
index c2b00ed..0000000
+++ /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 (file)
index 1d417ce..0000000
Binary files a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/api_rules_list.protobuf and /dev/null differ
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf
deleted file mode 100644 (file)
index 8b610d8..0000000
Binary files a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_issues.protobuf and /dev/null differ
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json b/sonar-scanner-engine/src/test/resources/org/sonar/batch/cache/ProjectCacheSynchronizerTest/batch_project.json
deleted file mode 100644 (file)
index 2887ce1..0000000
+++ /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 (file)
index e69de29..0000000