</organization>
<properties>
- <sonar.buildVersion>6.7</sonar.buildVersion>
+ <sonar.buildVersion>7.9.1</sonar.buildVersion>
<!-- following properties must be set in command-line : sonar.runtimeVersion and sonarRunner.version -->
</properties>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
- <version>6.7</version>
+ <version>${sonar.buildVersion}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
import java.util.Map;
import org.junit.After;
import org.junit.Test;
-import org.sonarqube.ws.WsMeasures.Measure;
+import org.sonarqube.ws.Measures.Measure;
import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;
}
@Test
- public void should_succeed_with_self_contained_jre_despite_rubbish_java_home() throws IOException, InterruptedException {
+ public void should_succeed_with_self_contained_jre_despite_rubbish_java_home()
+ throws IOException, InterruptedException {
String projectKey = "basedir-with-source";
File projectDir = new File("projects/basedir-with-source");
.useNative();
orchestrator.executeBuild(build, true);
- Map<String, Measure> projectMeasures = getMeasures(projectKey, "files", "ncloc");
+ Map<String, Measure> projectMeasures = getMeasures(projectKey, "files",
+ "ncloc");
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
- assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue()))
+ .isGreaterThan(1);
}
@Test(expected = BuildFailureException.class)
- public void should_fail_without_self_contained_jre_when_rubbish_java_home() throws IOException, InterruptedException {
+ public void should_fail_without_self_contained_jre_when_rubbish_java_home()
+ throws IOException, InterruptedException {
String projectKey = "basedir-with-source";
File projectDir = new File("projects/basedir-with-source");
import java.io.File;
import org.junit.After;
import org.junit.Test;
-import org.sonarqube.ws.WsComponents.Component;
+import org.sonarqube.ws.Components.Component;
import static org.assertj.core.api.Assertions.assertThat;
*/
@Test
public void test_simplest_with_props_on_root() {
- SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
+ SonarScanner build = newScanner(
+ new File("projects/multi-module/simplest/simplest-with-props-on-root"));
orchestrator.executeBuild(build);
- assertThat(getComponent("simplest-with-props-on-root").getName()).isEqualTo("Simplest multi-module project with all properties set on the root project");
+ assertThat(getComponent("simplest-with-props-on-root").getName()).isEqualTo(
+ "Simplest multi-module project with all properties set on the root project");
if (noMoreModules()) {
// Verify that we have the folders
- assertThat(getComponent("simplest-with-props-on-root:module1/src").getName()).isEqualTo("module1/src");
- assertThat(getComponent("simplest-with-props-on-root:module2/src").getName()).isEqualTo("module2/src");
+ assertThat(
+ getComponent("simplest-with-props-on-root:module1/src").getName())
+ .isEqualTo("module1/src");
+ assertThat(
+ getComponent("simplest-with-props-on-root:module2/src").getName())
+ .isEqualTo("module2/src");
} else {
// Verify that we have the modules
- assertThat(getComponent("simplest-with-props-on-root:module1").getName()).isEqualTo("module1");
- assertThat(getComponent("simplest-with-props-on-root:module2").getName()).isEqualTo("module2");
+ assertThat(getComponent("simplest-with-props-on-root:module1").getName())
+ .isEqualTo("module1");
+ assertThat(getComponent("simplest-with-props-on-root:module2").getName())
+ .isEqualTo("module2");
}
// And verify that the working directories are all located in the root folder
- File workDir = new File("projects/multi-module/simplest/simplest-with-props-on-root/.scannerwork");
+ File workDir = new File(
+ "projects/multi-module/simplest/simplest-with-props-on-root/.scannerwork");
assertThat(workDir).exists();
- assertThat(new File(workDir, "simplest-with-props-on-root_module1")).exists();
- assertThat(new File(workDir, "simplest-with-props-on-root_module2")).exists();
- assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module1/.scannerwork")).doesNotExist();
- assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module2/.scannerwork")).doesNotExist();
+ assertThat(new File(workDir, "simplest-with-props-on-root_module1"))
+ .exists();
+ assertThat(new File(workDir, "simplest-with-props-on-root_module2"))
+ .exists();
+ assertThat(new File(
+ "projects/multi-module/simplest/simplest-with-props-on-root/module1/.scannerwork"))
+ .doesNotExist();
+ assertThat(new File(
+ "projects/multi-module/simplest/simplest-with-props-on-root/module2/.scannerwork"))
+ .doesNotExist();
}
/**
*/
@Test
public void test_simplest_with_props_on_each_module() {
- SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
+ SonarScanner build = newScanner(new File(
+ "projects/multi-module/simplest/simplest-with-props-on-each-module"));
orchestrator.executeBuild(build);
- assertThat(getComponent("simplest-with-props-each-module").getName()).isEqualTo("Simplest multi-module project with properties set on each module");
+ assertThat(getComponent("simplest-with-props-each-module").getName())
+ .isEqualTo(
+ "Simplest multi-module project with properties set on each module");
if (noMoreModules()) {
- assertThat(getComponent("simplest-with-props-each-module:module1/src").getName()).isEqualTo("module1/src");
- assertThat(getComponent("simplest-with-props-each-module:module2/src").getName()).isEqualTo("module2/src");
+ assertThat(
+ getComponent("simplest-with-props-each-module:module1/src").getName())
+ .isEqualTo("module1/src");
+ assertThat(
+ getComponent("simplest-with-props-each-module:module2/src").getName())
+ .isEqualTo("module2/src");
} else {
// Verify that we have the modules
- assertThat(getComponent("simplest-with-props-each-module:module1").getName()).isEqualTo("module1");
- assertThat(getComponent("simplest-with-props-each-module:overridden-key-for-module2").getName()).isEqualTo("Module 2");
+ assertThat(
+ getComponent("simplest-with-props-each-module:module1").getName())
+ .isEqualTo("module1");
+ assertThat(getComponent(
+ "simplest-with-props-each-module:overridden-key-for-module2").getName())
+ .isEqualTo("Module 2");
}
}
*/
@Test
public void test_deep_path_for_modules() {
- SonarScanner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
+ SonarScanner build = newScanner(
+ new File("projects/multi-module/customization/deep-path-for-modules"));
orchestrator.executeBuild(build);
- assertThat(getComponent("deep-path-for-modules").getName()).isEqualTo("Project with deep path for modules");
+ assertThat(getComponent("deep-path-for-modules").getName())
+ .isEqualTo("Project with deep path for modules");
if (noMoreModules()) {
- assertThat(getComponent("deep-path-for-modules:modules/module1/src").getName()).isEqualTo("module1/src");
- assertThat(getComponent("deep-path-for-modules:modules/module2/src").getName()).isEqualTo("module2/src");
+ assertThat(
+ getComponent("deep-path-for-modules:modules/module1/src").getName())
+ .isEqualTo("module1/src");
+ assertThat(
+ getComponent("deep-path-for-modules:modules/module2/src").getName())
+ .isEqualTo("module2/src");
} else {
// Verify that we have the modules
- assertThat(getComponent("deep-path-for-modules:mod1").getName()).isEqualTo("Module 1");
- assertThat(getComponent("deep-path-for-modules:mod2").getName()).isEqualTo("Module 2");
+ assertThat(getComponent("deep-path-for-modules:mod1").getName())
+ .isEqualTo("Module 1");
+ assertThat(getComponent("deep-path-for-modules:mod2").getName())
+ .isEqualTo("Module 2");
}
}
*/
@Test
public void test_module_path_with_space() {
- SonarScanner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
+ SonarScanner build = newScanner(
+ new File("projects/multi-module/customization/module-path-with-space"));
orchestrator.executeBuild(build);
- assertThat(getComponent("module-path-with-space").getName()).isEqualTo("Project with module path that contain spaces");
+ assertThat(getComponent("module-path-with-space").getName())
+ .isEqualTo("Project with module path that contain spaces");
if (noMoreModules()) {
- assertThat(getComponent("module-path-with-space:my module 1/src").getName()).isEqualTo("my module 1/src");
- assertThat(getComponent("module-path-with-space:my module 2/src").getName()).isEqualTo("my module 2/src");
+ assertThat(
+ getComponent("module-path-with-space:my module 1/src").getName())
+ .isEqualTo("my module 1/src");
+ assertThat(
+ getComponent("module-path-with-space:my module 2/src").getName())
+ .isEqualTo("my module 2/src");
} else {
// Verify that we have the modules
- assertThat(getComponent("module-path-with-space:module1").getName()).isEqualTo("Module 1");
- assertThat(getComponent("module-path-with-space:module2").getName()).isEqualTo("Module 2");
+ assertThat(getComponent("module-path-with-space:module1").getName())
+ .isEqualTo("Module 1");
+ assertThat(getComponent("module-path-with-space:module2").getName())
+ .isEqualTo("Module 2");
}
}
*/
@Test
public void test_overwriting_parent_properties() {
- SonarScanner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
+ SonarScanner build = newScanner(new File(
+ "projects/multi-module/customization/overwriting-parent-properties"));
orchestrator.executeBuild(build);
Component rootProject = getComponent("overwriting-parent-properties");
- assertThat(rootProject.getName()).isEqualTo("Project with modules that overwrite properties");
- assertThat(rootProject.getDescription()).isEqualTo("Description of root project");
+ assertThat(rootProject.getName())
+ .isEqualTo("Project with modules that overwrite properties");
+ assertThat(rootProject.getDescription())
+ .isEqualTo("Description of root project");
if (noMoreModules()) {
- assertThat(getComponent("overwriting-parent-properties:module1/src1").getName()).isEqualTo("module1/src1");
- assertThat(getComponent("overwriting-parent-properties:module2/src2").getName()).isEqualTo("module2/src2");
+ assertThat(
+ getComponent("overwriting-parent-properties:module1/src1").getName())
+ .isEqualTo("module1/src1");
+ assertThat(
+ getComponent("overwriting-parent-properties:module2/src2").getName())
+ .isEqualTo("module2/src2");
} else {
// Verify that we have the modules
- Component module1 = getComponent("overwriting-parent-properties:module1-new-key");
+ Component module1 = getComponent(
+ "overwriting-parent-properties:module1-new-key");
assertThat(module1.getName()).isEqualTo("Module 1");
assertThat(module1.getDescription()).isEqualTo("Description of module 1");
- Component module2 = getComponent("overwriting-parent-properties:module2-new-key");
+ Component module2 = getComponent(
+ "overwriting-parent-properties:module2-new-key");
assertThat(module2.getName()).isEqualTo("Module 2");
assertThat(module2.getDescription()).isEqualTo("Description of module 2");
}
*/
@Test
public void test_using_config_file_property() {
- SonarScanner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
+ SonarScanner build = newScanner(
+ new File("projects/multi-module/advanced/using-config-file-prop"));
orchestrator.executeBuild(build);
- assertThat(getComponent("using-config-file-prop").getName()).isEqualTo("Advanced use case - mostly used by the Ant task");
+ assertThat(getComponent("using-config-file-prop").getName())
+ .isEqualTo("Advanced use case - mostly used by the Ant task");
if (noMoreModules()) {
- assertThat(getComponent("using-config-file-prop:module1/src").getName()).isEqualTo("module1/src");
- assertThat(getComponent("using-config-file-prop:module2/src").getName()).isEqualTo("module2/src");
+ assertThat(getComponent("using-config-file-prop:module1/src").getName())
+ .isEqualTo("module1/src");
+ assertThat(getComponent("using-config-file-prop:module2/src").getName())
+ .isEqualTo("module2/src");
} else {
// Verify that we have the modules
- assertThat(getComponent("using-config-file-prop:module1").getName()).isEqualTo("Module 1");
- assertThat(getComponent("using-config-file-prop:module2").getName()).isEqualTo("Module 2");
+ assertThat(getComponent("using-config-file-prop:module1").getName())
+ .isEqualTo("Module 1");
+ assertThat(getComponent("using-config-file-prop:module2").getName())
+ .isEqualTo("Module 2");
}
}
*/
@Test
public void should_fail_if_unexisting_base_dir() {
- SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
+ SonarScanner build = newScanner(
+ new File("projects/multi-module/failures/unexisting-base-dir"));
BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure
assertThat(result.getStatus()).isNotEqualTo(0);
// with the following message
- assertThat(result.getLogs()).contains("The base directory of the module 'module3' does not exist");
+ assertThat(result.getLogs())
+ .contains("The base directory of the module 'module3' does not exist");
}
*/
@Test
public void should_fail_if_unexisting_config_file() {
- SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
+ SonarScanner build = newScanner(
+ new File("projects/multi-module/failures/unexisting-config-file"));
BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure
assertThat(result.getStatus()).isNotEqualTo(0);
// with the following message
- assertThat(result.getLogs()).contains("The properties file of the module 'module1' does not exist");
+ assertThat(result.getLogs())
+ .contains("The properties file of the module 'module1' does not exist");
}
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonarqube.ws.WsMeasures.Measure;
+import org.sonarqube.ws.Measures.Measure;
import static java.lang.Integer.parseInt;
import static org.assertj.core.api.Assertions.assertThat;
SonarScanner build = newScanner(new File("projects/basedir-with-source"));
orchestrator.executeBuild(build);
- Map<String, Measure> projectMeasures = getMeasures("java:basedir-with-source", "files", "ncloc");
+ Map<String, Measure> projectMeasures = getMeasures(
+ "java:basedir-with-source", "files", "ncloc");
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1);
- assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue()))
+ .isGreaterThan(1);
}
/**
.setProjectKey("SAMPLE");
orchestrator.executeBuild(build);
- Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files", "ncloc");
+ Map<String, Measure> projectMeasures = getMeasures("SAMPLE", "files",
+ "ncloc");
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(2);
- assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1);
+ assertThat(parseInt(projectMeasures.get("ncloc").getValue()))
+ .isGreaterThan(1);
}
/**
orchestrator.executeBuild(build);
assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist();
- assertThat(new File("projects/override-working-dir/.overridden-relative-sonar")).exists().isDirectory();
+ assertThat(
+ new File("projects/override-working-dir/.overridden-relative-sonar"))
+ .exists().isDirectory();
}
/**
public void should_override_working_dir_with_absolute_path() {
File projectHome = new File("projects/override-working-dir");
SonarScanner build = newScanner(projectHome)
- .setProperty("sonar.working.directory", new File(projectHome, ".overridden-absolute-sonar").getAbsolutePath());
+ .setProperty("sonar.working.directory",
+ new File(projectHome, ".overridden-absolute-sonar").getAbsolutePath());
orchestrator.executeBuild(build);
assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist();
- assertThat(new File("projects/override-working-dir/.overridden-absolute-sonar")).exists().isDirectory();
+ assertThat(
+ new File("projects/override-working-dir/.overridden-absolute-sonar"))
+ .exists().isDirectory();
}
/**
BuildResult result = orchestrator.executeBuildQuietly(build);
assertThat(result.getStatus()).isNotEqualTo(0);
// with the following message
- assertThat(result.getLogs()).contains("Invalid value of sonar.sources for bad-source-dirs");
+ assertThat(result.getLogs())
+ .contains("Invalid value of sonar.sources for bad-source-dirs");
}
/**
@Test
public void should_use_json_environment_props() {
- SonarScanner build = newScanner(new File("projects/simple-sample-no-properties"))
+ SonarScanner build = newScanner(
+ new File("projects/simple-sample-no-properties"))
.setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{"
+ "\"sonar.projectKey\" : \"sample\"," +
"\"sonar.projectName\" : \"Sample, with comma\"," +
BuildResult buildResult = runner.runQuietly(null, build);
assertThat(buildResult.isSuccess()).isFalse();
- assertThat(buildResult.getLogs()).contains("SonarQube server [http://from-env.org] can not be reached");
+ assertThat(buildResult.getLogs())
+ .contains("SonarQube server [http://from-env.org] can not be reached");
}
@Test
public void should_skip_analysis() {
SonarScanner build = newScanner(new File("projects/simple-sample"))
.setProperty("sonar.host.url", "http://foo")
- .setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{ \"sonar.scanner.skip\":\"true\" }");
+ .setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS",
+ "{ \"sonar.scanner.skip\":\"true\" }");
BuildResult result = orchestrator.executeBuild(build);
assertThat(result.getLogs()).contains("SonarQube Scanner analysis skipped");
// expect build failure
assertThat(result.isSuccess()).isFalse();
// with the following message
- assertThat(result.getLogs()).contains("SonarQube server [http://foo] can not be reached");
+ assertThat(result.getLogs())
+ .contains("SonarQube server [http://foo] can not be reached");
}
// SONARPLUGINS-3574
public void run_from_external_location() throws IOException {
File tempDir = temp.newFolder();
SonarScanner build = newScanner(tempDir)
- .setProperty("sonar.projectBaseDir", new File("projects/simple-sample").getAbsolutePath())
+ .setProperty("sonar.projectBaseDir",
+ new File("projects/simple-sample").getAbsolutePath())
.addArguments("-e");
orchestrator.executeBuild(build);
- assertThat(getComponent("sample").getDescription()).isEqualTo("This is a sample");
- Map<String, Measure> projectMeasures = getMeasures("sample", "files", "ncloc", "classes", "violations");
- assertThat(projectMeasures.values().stream().filter(measure -> measure.getValue() != null).collect(Collectors.toList())).hasSize(4);
+ assertThat(getComponent("sample").getDescription())
+ .isEqualTo("This is a sample");
+ Map<String, Measure> projectMeasures = getMeasures("sample", "files",
+ "ncloc", "classes", "violations");
+ assertThat(projectMeasures.values().stream()
+ .filter(measure -> measure.getValue() != null)
+ .collect(Collectors.toList())).hasSize(4);
}
@Test
public void should_override_project_settings_path() {
File projectHome = new File("projects/override-project-settings-path");
SonarScanner build = newScanner(projectHome)
- .setProperty("project.settings", new File(projectHome, "conf/sq-project.properties").getAbsolutePath());
+ .setProperty("project.settings",
+ new File(projectHome, "conf/sq-project.properties").getAbsolutePath());
orchestrator.executeBuild(build);
- assertThat(getComponent("sample-with-custom-settings-path").getName()).isEqualTo("Test with custom settings location");
+ assertThat(getComponent("sample-with-custom-settings-path").getName())
+ .isEqualTo("Test with custom settings location");
}
// SQSCANNER-61
File projectHome = new File("projects/override-project-settings-path");
SonarScanner build = newScanner(projectHome)
.setEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "{"
- + "\"project.settings\" : \"" + StringEscapeUtils.escapeJavaScript(new File(projectHome, "conf/sq-project.properties").getAbsolutePath()) + "\"}");
+ + "\"project.settings\" : \"" + StringEscapeUtils.escapeJavaScript(
+ new File(projectHome, "conf/sq-project.properties").getAbsolutePath())
+ + "\"}");
orchestrator.executeBuild(build);
- assertThat(getComponent("sample-with-custom-settings-path").getName()).isEqualTo("Test with custom settings location");
+ assertThat(getComponent("sample-with-custom-settings-path").getName())
+ .isEqualTo("Test with custom settings location");
}
}
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonarqube.ws.WsComponents;
-import org.sonarqube.ws.WsComponents.Component;
-import org.sonarqube.ws.WsMeasures;
-import org.sonarqube.ws.WsMeasures.Measure;
+import org.sonarqube.ws.Components.Component;
+import org.sonarqube.ws.Measures;
+import org.sonarqube.ws.Measures.Measure;
import org.sonarqube.ws.client.HttpConnector;
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsClientFactories;
-import org.sonarqube.ws.client.component.ShowWsRequest;
-import org.sonarqube.ws.client.measure.ComponentWsRequest;
+import org.sonarqube.ws.client.components.ShowRequest;
+import org.sonarqube.ws.client.measures.ComponentRequest;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
public abstract class ScannerTestCase {
- private static final Logger LOG = LoggerFactory.getLogger(ScannerTestCase.class);
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ScannerTestCase.class);
@Rule
public ExpectedException thrown = ExpectedException.none();
LOG.info("Use provided Scanner version: " + scannerVersion);
artifactVersion = Version.create(scannerVersion);
} else {
- try (FileInputStream fis = new FileInputStream(new File("../target/maven-archiver/pom.properties"))) {
+ try (FileInputStream fis = new FileInputStream(
+ new File("../target/maven-archiver/pom.properties"))) {
Properties props = new Properties();
props.load(fis);
artifactVersion = Version.create(props.getProperty("version"));
}
@CheckForNull
- static Map<String, Measure> getMeasures(String componentKey, String... metricKeys) {
- return newWsClient().measures().component(new ComponentWsRequest()
- .setComponentKey(componentKey)
+ static Map<String, Measure> getMeasures(String componentKey,
+ String... metricKeys) {
+ return newWsClient().measures().component(new ComponentRequest()
+ .setComponent(componentKey)
.setMetricKeys(asList(metricKeys)))
.getComponent().getMeasuresList()
.stream()
@CheckForNull
static Measure getMeasure(String componentKey, String metricKey) {
- WsMeasures.ComponentWsResponse response = newWsClient().measures().component(new ComponentWsRequest()
- .setComponentKey(componentKey)
- .setMetricKeys(singletonList(metricKey)));
+ Measures.ComponentWsResponse response = newWsClient().measures()
+ .component(new ComponentRequest()
+ .setComponent(componentKey)
+ .setMetricKeys(singletonList(metricKey)));
List<Measure> measures = response.getComponent().getMeasuresList();
return measures.size() == 1 ? measures.get(0) : null;
}
@CheckForNull
static Component getComponent(String componentKey) {
- return newWsClient().components().show(new ShowWsRequest().setKey(componentKey)).getComponent();
+ return newWsClient().components()
+ .show(new ShowRequest().setComponent(componentKey)).getComponent();
}
static WsClient newWsClient() {