package com.sonarsource;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-
@Properties({
@Property(
key = DumpSettingsInitializer.SONAR_SHOW_SETTINGS,
- type = PropertyType.BOOLEAN,
+ type = PropertyType.STRING,
name = "Property to decide if it should output settings",
- defaultValue = "false")
+ multiValues = true,
+ defaultValue = "")
})
public class DumpSettingsInitializer extends Initializer {
@Override
public void execute(Project project) {
- if (settings.getBoolean(SONAR_SHOW_SETTINGS)) {
+ Set<String> settingsToDump = new HashSet<>(Arrays.asList(settings.getStringArray(SONAR_SHOW_SETTINGS)));
+ if (!settingsToDump.isEmpty()) {
TreeMap<String, String> treemap = new TreeMap<String, String>(settings.getProperties());
for (Entry<String, String> prop : treemap.entrySet()) {
- System.out.println(" o " + project.getKey() + ":" + prop.getKey() + " = " + prop.getValue());
+ if (settingsToDump.contains(prop.getKey())) {
+ System.out.println(" o " + project.getKey() + ":" + prop.getKey() + " = " + prop.getValue());
+ }
}
}
}
*/
package batch;
-import util.ItUtils;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildFailureException;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.FileLocation;
-
import java.io.File;
import java.io.IOException;
import java.util.Date;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
import org.apache.commons.io.FileUtils;
import org.junit.Assume;
import org.junit.Before;
import org.sonar.wsclient.services.PropertyUpdateQuery;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
public class BatchTest {
.addPlugin(ItUtils.xooPlugin())
.setContext("/")
- .addPlugin(ItUtils.pluginArtifact("batch-plugin"))
+ .addPlugin(ItUtils.pluginArtifact("batch-plugin"))
// Java is only used in convert_library_into_module test
.setOrchestratorProperty("javaVersion", "LATEST_RELEASE").addPlugin("java")
- .build();
+ .build();
@Rule
public ExpectedException thrown = ExpectedException.none();
public void module_should_load_own_settings_from_database() {
orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample");
orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line");
-
+
Sonar sonar = orchestrator.getServer().getAdminWsClient();
String propKey = "myFakeProperty";
String rootModuleKey = "com.sonarsource.it.samples:multi-modules-sample";
sonar.delete(new PropertyDeleteQuery(propKey, rootModuleKey));
sonar.delete(new PropertyDeleteQuery(propKey, moduleBKey));
- BuildResult result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", "true");
+ BuildResult result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
assertThat(result.getLogs()).doesNotContain(rootModuleKey + ":" + propKey);
assertThat(result.getLogs()).doesNotContain(moduleBKey + ":" + propKey);
// Set property only on root project
sonar.update(new PropertyUpdateQuery(propKey, "project", rootModuleKey));
- result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", "true");
+ result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
assertThat(result.getLogs()).contains(rootModuleKey + ":" + propKey + " = project");
assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = project");
// Override property on moduleB
sonar.update(new PropertyUpdateQuery(propKey, "moduleB", moduleBKey));
- result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", "true");
+ result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
assertThat(result.getLogs()).contains(rootModuleKey + ":" + propKey + " = project");
assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = moduleB");
public void should_not_exclude_root_module() {
orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample");
orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line");
-
+
thrown.expect(BuildFailureException.class);
scan("shared/xoo-multi-modules-sample",
"sonar.skippedModules", "multi-modules-sample");
public void should_display_explicit_message_when_no_plugin_language_available() {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
-
+
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.language", "foo",
"sonar.profile", "");
public void should_display_explicit_message_when_wrong_profile() {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
-
+
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.profile", "unknow");
assertThat(buildResult.getStatus()).isEqualTo(1);
try {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
-
+
orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "true"));
BuildResult buildResult = scanQuietly("shared/xoo-sample",
try {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
-
+
orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "true"));
BuildResult buildResult = scanQuietly("shared/xoo-sample");
public void should_display_explicit_message_when_invalid_project_key_or_branch() {
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
-
+
BuildResult buildResult = scanQuietly("shared/xoo-sample",
"sonar.projectKey", "ar g$l:");
assertThat(buildResult.getStatus()).isEqualTo(1);
// message
.contains("Error message from plugin")
- // but not stacktrace
+ // but not stacktrace
.doesNotContain("at com.sonarsource.RaiseMessageException");
}
scan("batch/prevent-common-module/projectAB");
assertThat(getResource("com.sonarsource.it.samples:moduleA")).isNotNull();
assertThat(getResource("com.sonarsource.it.samples:moduleB")).isNotNull();
-
+
orchestrator.getServer().provisionProject("projectAC", "project AC");
orchestrator.getServer().associateProjectToQualityProfile("projectAC", "xoo", "one-issue-per-line");
*/
@Test
public void test_project_creation_date() {
- long before = new Date().getTime()-2000l;
+ long before = new Date().getTime() - 2000l;
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample")));
- long after = new Date().getTime()+2000l;
+ long after = new Date().getTime() + 2000l;
Resource xooSample = orchestrator.getServer().getWsClient().find(new ResourceQuery().setResourceKeyOrId("sample"));
assertThat(xooSample.getCreationDate().getTime()).isGreaterThan(before).isLessThan(after);
}