From: Julien HENRY Date: Mon, 28 Jul 2014 13:33:43 +0000 (+0200) Subject: SONAR-5417 Load project referentials using WS X-Git-Tag: 4.5-RC1~102 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8eceec4c11715b83faf6a7bff745b3f5e383fd11;p=sonarqube.git SONAR-5417 Load project referentials using WS --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java b/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java index 981bfb8d606..21aabdb9729 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/TempFolderProvider.java @@ -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; } } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java index 570fb3630e5..06109d82b11 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java @@ -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> settingsByModule = new HashMap>(); public Map settings(String projectKey) { - return settingsByModule.get(projectKey); + return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.emptyMap(); } public ProjectReferentials addSettings(String projectKey, Map settings) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java index d7d866f3d79..d08d78beafb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java @@ -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); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java index 50a736b5e4c..fbf973640ed 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TempFolderProvider.java @@ -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; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java index a42ca1ae1b0..92cb3a3ffbb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java @@ -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 bootstrapProperties = new HashMap(); @@ -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> projectSettings = new HashMap>(); - - @Override - public Map projectSettings(String projectKey) { - return projectSettings.containsKey(projectKey) ? projectSettings.get(projectKey) : Collections.emptyMap(); - } - - } - private static class FackPluginsReferential implements PluginsReferential { private List pluginList = new ArrayList(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java index 4405eb259e8..700b477d1d6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java @@ -19,128 +19,39 @@ */ 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 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 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())); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsLoader.java index f34e358ceec..e4bad9f1e13 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsLoader.java @@ -20,12 +20,11 @@ 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); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsProvider.java b/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsProvider.java index eab96e511da..03486bfdcee 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/ProjectReferentialsProvider.java @@ -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(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java index 31201d4de9d..72063cc1541 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java @@ -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) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java index bfff4d73aab..e404ad07527 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java @@ -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 index f9d7d499018..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/settings/DefaultSettingsReferential.java +++ /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 projectSettings(String moduleKey) { - return downloadSettings(moduleKey); - } - - private Map downloadSettings(@Nullable String moduleKey) { - Map result = Maps.newHashMap(); - String url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?dryRun=" + analysisMode.isPreview(); - if (moduleKey != null) { - url += "&project=" + moduleKey; - } - String jsonText = serverClient.request(url); - - List> json = new Gson().fromJson(jsonText, new TypeToken>>() { - }.getType()); - - for (Map 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 index d8e4603826d..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/settings/SettingsReferential.java +++ /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 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 index 7e52b5b6d3e..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/settings/package-info.java +++ /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; diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java index 20e593585ab..3bbed76aa17 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java @@ -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"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java index ce7466ecc23..c40d9456ce3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java @@ -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); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java index 1c6dd28f3b1..4f7726f6695 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java @@ -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.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 index 8687bf8a0e8..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/settings/DefaultSettingsReferentialTest.java +++ /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")); - } - -} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java index 9e597b79d59..a61f4d8f081 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/PreviewDatabaseFactory.java @@ -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)); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java index c9e14d6f836..42da994a956 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java @@ -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;