]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5417 Load project referentials using WS
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 28 Jul 2014 13:33:43 +0000 (15:33 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 25 Aug 2014 14:54:31 +0000 (16:54 +0200)
19 files changed:
server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java
sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsLoader.java
sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsProvider.java
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java
sonar-batch/src/main/java/org/sonar/batch/settings/DefaultSettingsReferential.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/settings/SettingsReferential.java [deleted file]
sonar-batch/src/main/java/org/sonar/batch/settings/package-info.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java
sonar-batch/src/test/java/org/sonar/batch/settings/DefaultSettingsReferentialTest.java [deleted file]
sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java

index 981bfb8d60696bf6d7fbc6b6ae3c029292590991..21aabdb972941ce7c0c5c7602c7aea5ea8ff7d09 100644 (file)
@@ -30,14 +30,19 @@ import java.io.IOException;
 
 public class TempFolderProvider extends ProviderAdapter {
 
+  private TempFolder tempFolder;
+
   public TempFolder provide(ServerFileSystem fs) {
-    File tempDir = new File(fs.getTempDir(), "tmp");
-    try {
-      FileUtils.forceMkdir(tempDir);
-    } catch (IOException e) {
-      throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
+    if (tempFolder == null) {
+      File tempDir = new File(fs.getTempDir(), "tmp");
+      try {
+        FileUtils.forceMkdir(tempDir);
+      } catch (IOException e) {
+        throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
+      }
+      tempFolder = new DefaultTempFolder(tempDir);
     }
-    return new DefaultTempFolder(tempDir);
+    return tempFolder;
   }
 
 }
index 570fb3630e57e7162d7fbaff2d1ef7ba6a700118..06109d82b112b2a19d243ef0ae8aa5cfbe860a5e 100644 (file)
@@ -24,6 +24,7 @@ import com.google.gson.Gson;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -39,7 +40,7 @@ public class ProjectReferentials {
   private Map<String, Map<String, String>> settingsByModule = new HashMap<String, Map<String, String>>();
 
   public Map<String, String> settings(String projectKey) {
-    return settingsByModule.get(projectKey);
+    return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.<String, String>emptyMap();
   }
 
   public ProjectReferentials addSettings(String projectKey, Map<String, String> settings) {
index d7d866f3d79ee95a3033e0da682414a14acb57a9..d08d78beafbfc6928987513d22b6594ab3fd961b 100644 (file)
@@ -41,8 +41,6 @@ import org.sonar.batch.referential.DefaultProjectReferentialsLoader;
 import org.sonar.batch.referential.GlobalReferentialsLoader;
 import org.sonar.batch.referential.GlobalReferentialsProvider;
 import org.sonar.batch.referential.ProjectReferentialsLoader;
-import org.sonar.batch.settings.DefaultSettingsReferential;
-import org.sonar.batch.settings.SettingsReferential;
 import org.sonar.core.cluster.NullQueue;
 import org.sonar.core.config.Logback;
 import org.sonar.core.i18n.DefaultI18n;
@@ -108,9 +106,6 @@ public class BootstrapContainer extends ComponentContainer {
       new FileCacheProvider(),
       System2.INSTANCE,
       new GlobalReferentialsProvider());
-    if (getComponentByType(SettingsReferential.class) == null) {
-      add(DefaultSettingsReferential.class);
-    }
     if (getComponentByType(PluginsReferential.class) == null) {
       add(DefaultPluginsReferential.class);
     }
index 50a736b5e4cdf1684286ac6ee1648ff7f35daeb6..fbf973640ed2ab31ab6c6fcfefc6e56fea52d0d2 100644 (file)
@@ -31,16 +31,21 @@ import java.io.IOException;
 
 public class TempFolderProvider extends ProviderAdapter {
 
+  private TempFolder tempFolder;
+
   public TempFolder provide(BootstrapProperties bootstrapProps) {
-    String workingDirPath = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
-    File workingDir = new File(workingDirPath);
-    File tempDir = new File(workingDir, ".sonartmp");
-    try {
-      FileUtils.forceMkdir(tempDir);
-    } catch (IOException e) {
-      throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
+    if (tempFolder == null) {
+      String workingDirPath = StringUtils.defaultIfBlank(bootstrapProps.property(CoreProperties.WORKING_DIRECTORY), CoreProperties.WORKING_DIRECTORY_DEFAULT_VALUE);
+      File workingDir = new File(workingDirPath);
+      File tempDir = new File(workingDir, ".sonartmp");
+      try {
+        FileUtils.forceMkdir(tempDir);
+      } catch (IOException e) {
+        throw new IllegalStateException("Unable to create root temp directory " + tempDir, e);
+      }
+      tempFolder = new DefaultTempFolder(tempDir);
     }
-    return new DefaultTempFolder(tempDir);
+    return tempFolder;
   }
 
 }
index a42ca1ae1b073e6e9a1141b29e571eba72183b19..92cb3a3ffbbda091963d56a8d270b1dd552ccb32 100644 (file)
@@ -34,12 +34,11 @@ import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.batch.sensor.measure.Measure;
 import org.sonar.api.batch.sensor.symbol.Symbol;
-import org.sonar.api.config.Settings;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Metric;
 import org.sonar.api.platform.PluginMetadata;
-import org.sonar.api.resources.Languages;
 import org.sonar.batch.bootstrap.PluginsReferential;
+import org.sonar.batch.bootstrap.TaskProperties;
 import org.sonar.batch.bootstrapper.Batch;
 import org.sonar.batch.bootstrapper.EnvironmentInformation;
 import org.sonar.batch.duplication.DuplicationCache;
@@ -57,7 +56,6 @@ import org.sonar.batch.scan2.AnalyzerIssueCache;
 import org.sonar.batch.scan2.AnalyzerMeasureCache;
 import org.sonar.batch.scan2.ProjectScanContainer;
 import org.sonar.batch.scan2.ScanTaskObserver;
-import org.sonar.batch.settings.SettingsReferential;
 import org.sonar.batch.symbol.SymbolData;
 import org.sonar.core.plugins.DefaultPluginMetadata;
 import org.sonar.core.plugins.RemotePlugin;
@@ -68,7 +66,6 @@ import javax.annotation.CheckForNull;
 import java.io.File;
 import java.io.FileReader;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -91,7 +88,6 @@ public class BatchMediumTester {
   public static class BatchMediumTesterBuilder {
     private final FakeGlobalReferentialsLoader globalRefProvider = new FakeGlobalReferentialsLoader();
     private final FakeProjectReferentialsLoader projectRefProvider = new FakeProjectReferentialsLoader();
-    private final FakeSettingsReferential settingsReferential = new FakeSettingsReferential();
     private final FackPluginsReferential pluginsReferential = new FackPluginsReferential();
     private final Map<String, String> bootstrapProperties = new HashMap<String, String>();
 
@@ -157,7 +153,6 @@ public class BatchMediumTester {
       .setEnableLoggingConfiguration(true)
       .addComponents(
         new EnvironmentInformation("mediumTest", "1.0"),
-        builder.settingsReferential,
         builder.pluginsReferential,
         builder.globalRefProvider,
         builder.projectRefProvider,
@@ -366,7 +361,7 @@ public class BatchMediumTester {
     private ProjectReferentials ref = new ProjectReferentials();
 
     @Override
-    public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
+    public ProjectReferentials load(ProjectReactor reactor, TaskProperties taskProperties) {
       return ref;
     }
 
@@ -381,17 +376,6 @@ public class BatchMediumTester {
     }
   }
 
-  private static class FakeSettingsReferential implements SettingsReferential {
-
-    private Map<String, Map<String, String>> projectSettings = new HashMap<String, Map<String, String>>();
-
-    @Override
-    public Map<String, String> projectSettings(String projectKey) {
-      return projectSettings.containsKey(projectKey) ? projectSettings.get(projectKey) : Collections.<String, String>emptyMap();
-    }
-
-  }
-
   private static class FackPluginsReferential implements PluginsReferential {
 
     private List<RemotePlugin> pluginList = new ArrayList<RemotePlugin>();
index 4405eb259e8245523cbc2af8bf64513a84278bc7..700b477d1d623dc292fbca85d6dca5690b32d9e9 100644 (file)
  */
 package org.sonar.batch.referential;
 
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import org.apache.commons.lang.StringUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.InputSupplier;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.RuleParam;
-import org.sonar.api.utils.MessageException;
-import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.batch.bootstrap.ServerClient;
+import org.sonar.batch.bootstrap.TaskProperties;
 import org.sonar.batch.protocol.input.ProjectReferentials;
-import org.sonar.batch.protocol.input.QProfile;
 import org.sonar.batch.rule.ModuleQProfiles;
-import org.sonar.core.UtcDateUtils;
-import org.sonar.core.qualityprofile.db.ActiveRuleDao;
-import org.sonar.core.qualityprofile.db.ActiveRuleDto;
-import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
-import org.sonar.core.qualityprofile.db.QualityProfileDao;
-import org.sonar.core.qualityprofile.db.QualityProfileDto;
 
-import javax.annotation.CheckForNull;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 
-/**
- * TODO This is currently implemented by accessing DB but should be replaced by WS call
- */
 public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoader {
 
-  private static final String ENABLED = "enabled";
+  private static final String BATCH_PROJECT_URL = "/batch/project";
 
-  private final QualityProfileDao qualityProfileDao;
-  private final ActiveRuleDao activeRuleDao;
-  private final RuleFinder ruleFinder;
+  private final ServerClient serverClient;
 
-  public DefaultProjectReferentialsLoader(QualityProfileDao qualityProfileDao,
-    ActiveRuleDao activeRuleDao, RuleFinder ruleFinder) {
-    this.qualityProfileDao = qualityProfileDao;
-    this.activeRuleDao = activeRuleDao;
-    this.ruleFinder = ruleFinder;
+  public DefaultProjectReferentialsLoader(ServerClient serverClient) {
+    this.serverClient = serverClient;
   }
 
   @Override
-  public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
-    ProjectReferentials ref = new ProjectReferentials();
-
-    String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP);
-
-    for (Language language : languages.all()) {
-      org.sonar.batch.protocol.input.QProfile profile = null;
-      if (StringUtils.isNotBlank(defaultName)) {
-        profile = loadDefaultQProfile(defaultName, language.getKey());
-      }
-      if (profile == null) {
-        profile = loadQProfile(settings, language.getKey());
-      }
-      if (profile != null) {
-        ref.addQProfile(profile);
-      }
-    }
-
-    for (QProfile qProfile : ref.qProfiles()) {
-      ListMultimap<Integer, ActiveRuleParamDto> paramDtosByActiveRuleId = ArrayListMultimap.create();
-      for (ActiveRuleParamDto dto : activeRuleDao.selectParamsByProfileKey(qProfile.key())) {
-        paramDtosByActiveRuleId.put(dto.getActiveRuleId(), dto);
-      }
-
-      for (ActiveRuleDto activeDto : activeRuleDao.selectByProfileKey(qProfile.key())) {
-        Rule rule = ruleFinder.findById(activeDto.getRuleId());
-        if (rule != null) {
-          String internalKey;
-          Rule template = rule.getTemplate();
-          if (template != null) {
-            internalKey = template.getConfigKey();
-          } else {
-            internalKey = rule.getConfigKey();
-          }
-          ActiveRule activeRule = new ActiveRule(rule.ruleKey().repository(), rule.ruleKey().rule(), rule.getName(), activeDto.getSeverityString(), internalKey, rule.getLanguage());
-
-          // load parameter values
-          for (ActiveRuleParamDto paramDto : paramDtosByActiveRuleId.get(activeDto.getId())) {
-            activeRule.params().put(paramDto.getKey(), paramDto.getValue());
-          }
-
-          // load default values
-          for (RuleParam param : rule.getParams()) {
-            if (!activeRule.params().containsKey(param.getKey())) {
-              activeRule.params().put(param.getKey(), param.getDefaultValue());
-            }
-          }
-
-          ref.addActiveRule(activeRule);
-        }
-      }
+  public ProjectReferentials load(ProjectReactor reactor, TaskProperties taskProperties) {
+    String url = BATCH_PROJECT_URL + "?key=" + reactor.getRoot().getKeyWithBranch();
+    if (taskProperties.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
+      url += "&profile=" + taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP);
     }
-
-    return ref;
-  }
-
-  @CheckForNull
-  private QProfile loadQProfile(Settings settings, String language) {
-    String profileName = settings.getString("sonar.profile." + language);
-    if (profileName != null) {
-      QProfile dto = get(language, profileName);
-      if (dto == null) {
-        throw MessageException.of(String.format("Quality profile not found : '%s' on language '%s'", profileName, language));
-      }
-      return dto;
-    }
-    return null;
-  }
-
-  @CheckForNull
-  private QProfile loadDefaultQProfile(String profileName, String language) {
-    return get(language, profileName);
-  }
-
-  public QProfile get(String language, String name) {
-    QualityProfileDto dto = qualityProfileDao.getByNameAndLanguage(name, language);
-    if (dto == null) {
-      return null;
+    InputSupplier<InputStream> jsonStream = serverClient.doRequest(url, null);
+    try {
+      return ProjectReferentials.fromJson(new InputStreamReader(jsonStream.getInput(), Charsets.UTF_8));
+    } catch (IOException e) {
+      throw new IllegalStateException("Unable to load project referentials", e);
     }
-    return new org.sonar.batch.protocol.input.QProfile(dto.getKey(), dto.getName(), dto.getLanguage(), UtcDateUtils.parseDateTime(dto.getRulesUpdatedAt()));
   }
 }
index f34e358ceecdde639e86630811c54a1dc927b744..e4bad9f1e13021f7cf8c63d2e32685bf8af39419 100644 (file)
 package org.sonar.batch.referential;
 
 import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Languages;
+import org.sonar.batch.bootstrap.TaskProperties;
 import org.sonar.batch.protocol.input.ProjectReferentials;
 
 public interface ProjectReferentialsLoader {
 
-  ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages);
+  ProjectReferentials load(ProjectReactor reactor, TaskProperties taskProperties);
 
 }
index eab96e511da1d9dcb9e1afde5d9b98f1258e27e7..03486bfdceeec7c431eb2dee9ba7dfd8d034a42f 100644 (file)
@@ -23,9 +23,8 @@ import org.picocontainer.injectors.ProviderAdapter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Languages;
 import org.sonar.api.utils.TimeProfiler;
+import org.sonar.batch.bootstrap.TaskProperties;
 import org.sonar.batch.protocol.input.ProjectReferentials;
 
 public class ProjectReferentialsProvider extends ProviderAdapter {
@@ -34,11 +33,11 @@ public class ProjectReferentialsProvider extends ProviderAdapter {
 
   private ProjectReferentials projectReferentials;
 
-  public ProjectReferentials provide(ProjectReferentialsLoader loader, ProjectReactor reactor, Settings settings, Languages languages) {
+  public ProjectReferentials provide(ProjectReferentialsLoader loader, ProjectReactor reactor, TaskProperties taskProps) {
     if (projectReferentials == null) {
       TimeProfiler profiler = new TimeProfiler(LOG).start("Load project referentials");
       try {
-        projectReferentials = loader.load(reactor, settings, languages);
+        projectReferentials = loader.load(reactor, taskProps);
       } finally {
         profiler.stop();
       }
index 31201d4de9d189766b89e5798ca0cdd2f0e6dfa6..72063cc1541011f75f11d863b60bdebbc59772ae 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
 import org.sonar.batch.bootstrap.AnalysisMode;
 import org.sonar.batch.bootstrap.GlobalSettings;
-import org.sonar.batch.settings.SettingsReferential;
+import org.sonar.batch.protocol.input.ProjectReferentials;
 
 import javax.annotation.Nullable;
 
@@ -40,13 +40,13 @@ import java.util.List;
 public class ModuleSettings extends Settings {
 
   private final Configuration deprecatedCommonsConf;
-  private final SettingsReferential settingsReferential;
+  private final ProjectReferentials projectReferentials;
   private AnalysisMode analysisMode;
 
-  public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, SettingsReferential settingsReferential,
+  public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, ProjectReferentials projectReferentials,
     AnalysisMode analysisMode) {
     super(batchSettings.getDefinitions());
-    this.settingsReferential = settingsReferential;
+    this.projectReferentials = projectReferentials;
     this.analysisMode = analysisMode;
     getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
 
@@ -63,7 +63,7 @@ public class ModuleSettings extends Settings {
 
   private void addProjectProperties(ProjectDefinition project, GlobalSettings batchSettings) {
     addProperties(batchSettings.getProperties());
-    addProperties(settingsReferential.projectSettings(project.getKeyWithBranch()));
+    addProperties(projectReferentials.settings(project.getKeyWithBranch()));
   }
 
   private void addBuildProperties(ProjectDefinition project) {
index bfff4d73aabebdb849cd6b98f953b7d2abe49159..e404ad075270c6597ad7dc844d8583e6c3a91b4c 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
 import org.sonar.batch.bootstrap.AnalysisMode;
 import org.sonar.batch.bootstrap.GlobalSettings;
-import org.sonar.batch.settings.SettingsReferential;
+import org.sonar.batch.protocol.input.ProjectReferentials;
 
 import javax.annotation.Nullable;
 
@@ -40,16 +40,16 @@ public class ProjectSettings extends Settings {
   private Configuration deprecatedConfiguration;
 
   private final GlobalSettings globalSettings;
-  private final SettingsReferential settingsReferential;
+  private final ProjectReferentials projectReferentials;
   private final AnalysisMode mode;
 
   public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, PropertyDefinitions propertyDefinitions,
-    SettingsReferential settingsReferential, Configuration deprecatedConfiguration, AnalysisMode mode) {
+    ProjectReferentials projectReferentials, Configuration deprecatedConfiguration, AnalysisMode mode) {
     super(propertyDefinitions);
     this.mode = mode;
     getEncryption().setPathToSecretKey(globalSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
     this.globalSettings = globalSettings;
-    this.settingsReferential = settingsReferential;
+    this.projectReferentials = projectReferentials;
     this.deprecatedConfiguration = deprecatedConfiguration;
     init(reactor);
   }
@@ -59,7 +59,7 @@ public class ProjectSettings extends Settings {
 
     addProperties(globalSettings.getProperties());
 
-    addProperties(settingsReferential.projectSettings(reactor.getRoot().getKeyWithBranch()));
+    addProperties(projectReferentials.settings(reactor.getRoot().getKeyWithBranch()));
 
     addProperties(reactor.getRoot().getProperties());
   }
diff --git a/sonar-batch/src/main/java/org/sonar/batch/settings/DefaultSettingsReferential.java b/sonar-batch/src/main/java/org/sonar/batch/settings/DefaultSettingsReferential.java
deleted file mode 100644 (file)
index f9d7d49..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.settings;
-
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import org.sonar.batch.bootstrap.AnalysisMode;
-import org.sonar.batch.bootstrap.ServerClient;
-
-import javax.annotation.Nullable;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Default implementation of {@link SettingsReferential} that fetch settings from remote SQ server using WS.
- * @since 4.4
- */
-public class DefaultSettingsReferential implements SettingsReferential {
-
-  private static final String BATCH_BOOTSTRAP_PROPERTIES_URL = "/batch_bootstrap/properties";
-
-  private final ServerClient serverClient;
-  private final AnalysisMode analysisMode;
-
-  public DefaultSettingsReferential(ServerClient serverClient, AnalysisMode analysisMode) {
-    this.serverClient = serverClient;
-    this.analysisMode = analysisMode;
-  }
-
-  @Override
-  public Map<String, String> projectSettings(String moduleKey) {
-    return downloadSettings(moduleKey);
-  }
-
-  private Map<String, String> downloadSettings(@Nullable String moduleKey) {
-    Map<String, String> result = Maps.newHashMap();
-    String url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?dryRun=" + analysisMode.isPreview();
-    if (moduleKey != null) {
-      url += "&project=" + moduleKey;
-    }
-    String jsonText = serverClient.request(url);
-
-    List<Map<String, String>> json = new Gson().fromJson(jsonText, new TypeToken<List<Map<String, String>>>() {
-    }.getType());
-
-    for (Map<String, String> jsonProperty : json) {
-      String key = jsonProperty.get("k");
-      String value = jsonProperty.get("v");
-      result.put(key, value);
-    }
-
-    return result;
-  }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/settings/SettingsReferential.java b/sonar-batch/src/main/java/org/sonar/batch/settings/SettingsReferential.java
deleted file mode 100644 (file)
index d8e4603..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.settings;
-
-import org.sonar.api.BatchComponent;
-
-import java.util.Map;
-
-/**
- * Settings referential
- * @since 4.4
- */
-public interface SettingsReferential extends BatchComponent {
-
-  /**
-   * Provide settings for a given project or sub-project (includes global settings)
-   * @param projectKey
-   */
-  Map<String, String> projectSettings(String projectKey);
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/settings/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/settings/package-info.java
deleted file mode 100644 (file)
index 7e52b5b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package org.sonar.batch.settings;
index 20e593585ab8fb190940218f9d8eea24cf983430..3bbed76aa17721397eaf3b098703c68f31475d6f 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.utils.MessageException;
 import org.sonar.batch.bootstrap.AnalysisMode;
 import org.sonar.batch.bootstrap.GlobalSettings;
-import org.sonar.batch.settings.SettingsReferential;
+import org.sonar.batch.protocol.input.ProjectReferentials;
 
 import java.util.List;
 
@@ -44,11 +44,12 @@ public class ModuleSettingsTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  SettingsReferential settingsRef = mock(SettingsReferential.class);
+  ProjectReferentials projectRef;
   private AnalysisMode mode;
 
   @Before
   public void before() {
+    projectRef = new ProjectReferentials();
     mode = mock(AnalysisMode.class);
   }
 
@@ -74,12 +75,12 @@ public class ModuleSettingsTest {
       "overridding", "batch",
       "on-batch", "true"
       ));
-    when(settingsRef.projectSettings("struts-core")).thenReturn(ImmutableMap.of("on-module", "true", "overridding", "module"));
+    projectRef.addSettings("struts-core", ImmutableMap.of("on-module", "true", "overridding", "module"));
 
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
     Configuration deprecatedConf = new PropertiesConfiguration();
 
-    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, settingsRef, mode);
+    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, projectRef, mode);
 
     assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
     assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
@@ -97,12 +98,12 @@ public class ModuleSettingsTest {
     when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
       "sonar.foo.secured", "bar"
       ));
-    when(settingsRef.projectSettings("struts-core")).thenReturn(ImmutableMap.of("sonar.foo.license.secured", "bar2"));
+    projectRef.addSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
 
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
     Configuration deprecatedConf = new PropertiesConfiguration();
 
-    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, settingsRef, mode);
+    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, projectRef, mode);
 
     assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
@@ -115,14 +116,14 @@ public class ModuleSettingsTest {
     when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
       "sonar.foo.secured", "bar"
       ));
-    when(settingsRef.projectSettings("struts-core")).thenReturn(ImmutableMap.of("sonar.foo.license.secured", "bar2"));
+    projectRef.addSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));
 
     when(mode.isPreview()).thenReturn(true);
 
     ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
     Configuration deprecatedConf = new PropertiesConfiguration();
 
-    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, settingsRef, mode);
+    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, projectRef, mode);
 
     assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
 
index ce7466ecc232977600a91bffea9c666a89f447a0..c40d9456ce3e555494edaceccf402a698f6c8eaa 100644 (file)
@@ -32,19 +32,18 @@ import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.ComponentContainer;
-import org.sonar.api.resources.Languages;
 import org.sonar.api.task.TaskExtension;
 import org.sonar.api.utils.System2;
 import org.sonar.batch.bootstrap.AnalysisMode;
 import org.sonar.batch.bootstrap.BootstrapProperties;
 import org.sonar.batch.bootstrap.ExtensionInstaller;
 import org.sonar.batch.bootstrap.GlobalSettings;
+import org.sonar.batch.bootstrap.TaskProperties;
 import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
 import org.sonar.batch.protocol.input.GlobalReferentials;
 import org.sonar.batch.protocol.input.ProjectReferentials;
 import org.sonar.batch.referential.ProjectReferentialsLoader;
 import org.sonar.batch.scan.maven.MavenPluginExecutor;
-import org.sonar.batch.settings.SettingsReferential;
 
 import java.util.Collections;
 
@@ -74,14 +73,14 @@ public class ProjectScanContainerTest {
     GlobalReferentials globalRef = new GlobalReferentials();
     settings = new GlobalSettings(bootstrapProperties, new PropertyDefinitions(), globalRef, new PropertiesConfiguration(), analysisMode);
     parentContainer.add(settings);
-    parentContainer.add(mock(SettingsReferential.class));
     ProjectReferentialsLoader projectReferentialsLoader = new ProjectReferentialsLoader() {
       @Override
-      public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
+      public ProjectReferentials load(ProjectReactor reactor, TaskProperties taskProperties) {
         return new ProjectReferentials();
       }
     };
     parentContainer.add(projectReferentialsLoader);
+    parentContainer.add(mock(TaskProperties.class));
     container = new ProjectScanContainer(parentContainer);
   }
 
index 1c6dd28f3b1f1b1a07d2f16b88ebc9513918fd27..4f7726f6695a87f433f7b9e05da2d24d1d1130a6 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.batch.bootstrap.AnalysisMode;
 import org.sonar.batch.bootstrap.BootstrapProperties;
 import org.sonar.batch.bootstrap.GlobalSettings;
 import org.sonar.batch.protocol.input.GlobalReferentials;
-import org.sonar.batch.settings.SettingsReferential;
+import org.sonar.batch.protocol.input.ProjectReferentials;
 
 import java.util.Collections;
 
@@ -48,7 +48,7 @@ public class ProjectSettingsTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  SettingsReferential settingsRef = mock(SettingsReferential.class);
+  ProjectReferentials projectRef;
   ProjectDefinition project = ProjectDefinition.create().setKey("struts");
   Configuration deprecatedConf = new BaseConfiguration();
   GlobalSettings bootstrapProps;
@@ -57,6 +57,7 @@ public class ProjectSettingsTest {
 
   @Before
   public void prepare() {
+    projectRef = new ProjectReferentials();
     mode = mock(AnalysisMode.class);
     bootstrapProps = new GlobalSettings(new BootstrapProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), new GlobalReferentials(), deprecatedConf, mode);
   }
@@ -65,16 +66,16 @@ public class ProjectSettingsTest {
   public void should_load_project_props() {
     project.setProperty("project.prop", "project");
 
-    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
 
     assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
   }
 
   @Test
   public void should_load_project_root_settings() {
-    when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
+    projectRef.addSettings("struts", ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
 
-    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
 
     assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
   }
@@ -83,18 +84,18 @@ public class ProjectSettingsTest {
   public void should_load_project_root_settings_on_branch() {
     project.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "mybranch");
 
-    when(settingsRef.projectSettings("struts:mybranch")).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
+    projectRef.addSettings("struts:mybranch", ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
 
-    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
 
     assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
   }
 
   @Test
   public void should_not_fail_when_accessing_secured_properties() {
-    when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
+    projectRef.addSettings("struts", ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
 
-    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
 
     assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
@@ -102,11 +103,11 @@ public class ProjectSettingsTest {
 
   @Test
   public void should_fail_when_accessing_secured_properties_in_dryrun() {
-    when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
+    projectRef.addSettings("struts", ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
 
     when(mode.isPreview()).thenReturn(true);
 
-    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
 
     assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
     thrown.expect(MessageException.class);
@@ -117,9 +118,9 @@ public class ProjectSettingsTest {
 
   @Test
   public void should_forward_to_deprecated_commons_configuration() {
-    when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
+    projectRef.addSettings("struts", ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
 
-    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+    ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), projectRef, deprecatedConf, mode);
 
     assertThat(deprecatedConf.getString("sonar.cpd.cross")).isEqualTo("true");
     assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/settings/DefaultSettingsReferentialTest.java b/sonar-batch/src/test/java/org/sonar/batch/settings/DefaultSettingsReferentialTest.java
deleted file mode 100644 (file)
index 8687bf8..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.settings;
-
-import org.fest.assertions.MapAssert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.batch.bootstrap.AnalysisMode;
-import org.sonar.batch.bootstrap.ServerClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class DefaultSettingsReferentialTest {
-
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-
-  private static final String REACTOR_JSON_RESPONSE = "[{\"k\":\"sonar.cpd.cross\",\"v\":\"true\"}," +
-    "{\"k\":\"sonar.java.coveragePlugin\",\"v\":\"jacoco\"}]";
-
-  ServerClient client = mock(ServerClient.class);
-
-  private AnalysisMode mode;
-
-  private DefaultSettingsReferential ref;
-
-  @Before
-  public void prepare() {
-    mode = mock(AnalysisMode.class);
-    ref = new DefaultSettingsReferential(client, mode);
-  }
-
-  @Test
-  public void should_load_project_props() {
-    when(client.request("/batch_bootstrap/properties?dryRun=false&project=struts")).thenReturn(REACTOR_JSON_RESPONSE);
-
-    assertThat(ref.projectSettings("struts")).hasSize(2).includes(MapAssert.entry("sonar.cpd.cross", "true"));
-  }
-
-}
index 9e597b79d5999eafd725a9a472ae1ddbc6834e1f..a61f4d8f0811e9dbbf45fd2674ea601a0cd65d75 100644 (file)
@@ -85,15 +85,12 @@ public class PreviewDatabaseFactory implements ServerComponent {
   private void copy(DataSource source, DataSource dest, @Nullable Long projectId) {
     DbTemplate template = new DbTemplate(profiling);
     template
-      .copyTable(source, dest, "active_rules")
-      .copyTable(source, dest, "active_rule_parameters")
       .copyTable(source, dest, "characteristics")
       .copyTable(source, dest, "permission_templates")
       .copyTable(source, dest, "perm_templates_users")
       .copyTable(source, dest, "perm_templates_groups")
       .copyTable(source, dest, "rules")
       .copyTable(source, dest, "rules_parameters")
-      .copyTable(source, dest, "rules_profiles")
       .copyTableColumns(source, dest, "users", new String[] {"id", "login", "name", "active"});
     if (projectId != null) {
       template.copyTable(source, dest, "projects", projectQuery(projectId, false));
index c9e14d6f8363b5071ea158a136adb83fdb323260..42da994a9561c48dd27b8c22849caa91379a49a6 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.sonar.api.profiles.RulesProfile;
 
 import javax.annotation.CheckForNull;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;