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;
}
}
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
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) {
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;
new FileCacheProvider(),
System2.INSTANCE,
new GlobalReferentialsProvider());
- if (getComponentByType(SettingsReferential.class) == null) {
- add(DefaultSettingsReferential.class);
- }
if (getComponentByType(PluginsReferential.class) == null) {
add(DefaultPluginsReferential.class);
}
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;
}
}
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;
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;
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;
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>();
.setEnableLoggingConfiguration(true)
.addComponents(
new EnvironmentInformation("mediumTest", "1.0"),
- builder.settingsReferential,
builder.pluginsReferential,
builder.globalRefProvider,
builder.projectRefProvider,
private ProjectReferentials ref = new ProjectReferentials();
@Override
- public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
+ public ProjectReferentials load(ProjectReactor reactor, TaskProperties taskProperties) {
return ref;
}
}
}
- 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>();
*/
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()));
}
}
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);
}
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 {
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();
}
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;
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));
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) {
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;
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);
}
addProperties(globalSettings.getProperties());
- addProperties(settingsReferential.projectSettings(reactor.getRoot().getKeyWithBranch()));
+ addProperties(projectReferentials.settings(reactor.getRoot().getKeyWithBranch()));
addProperties(reactor.getRoot().getProperties());
}
+++ /dev/null
-/*
- * 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;
- }
-
-}
+++ /dev/null
-/*
- * 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);
-
-}
+++ /dev/null
-/*
- * 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;
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;
@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);
}
"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");
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");
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");
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;
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);
}
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;
@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;
@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);
}
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");
}
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");
@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);
@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");
+++ /dev/null
-/*
- * 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"));
- }
-
-}
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));
import org.sonar.api.profiles.RulesProfile;
import javax.annotation.CheckForNull;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.List;