aboutsummaryrefslogtreecommitdiffstats
path: root/it/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-01-11 16:44:38 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2016-01-11 17:28:15 +0100
commit8d6e9a735a3ac5c6a729861e776c687d5639e9c1 (patch)
tree58d9b6d8401e9a70809162b0eb6d2da39f37d2da /it/src
parent5e187f8dc1099ce63c00b9185b9a8a8d9ce92f92 (diff)
downloadsonar-scanner-cli-8d6e9a735a3ac5c6a729861e776c687d5639e9c1.tar.gz
sonar-scanner-cli-8d6e9a735a3ac5c6a729861e776c687d5639e9c1.zip
Update ITs and enable Dory analysis
Diffstat (limited to 'it/src')
-rw-r--r--it/src/test/java/com/sonar/runner/it/CacheTest.java11
-rw-r--r--it/src/test/java/com/sonar/runner/it/JavaTest.java39
-rw-r--r--it/src/test/java/com/sonar/runner/it/MultimoduleTest.java31
-rw-r--r--it/src/test/java/com/sonar/runner/it/RunnerTestCase.java70
-rw-r--r--it/src/test/java/com/sonar/runner/it/ScannerTestCase.java62
-rw-r--r--it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java (renamed from it/src/test/java/com/sonar/runner/it/SonarRunnerTestSuite.java)14
6 files changed, 124 insertions, 103 deletions
diff --git a/it/src/test/java/com/sonar/runner/it/CacheTest.java b/it/src/test/java/com/sonar/runner/it/CacheTest.java
index 82abe07..8a7d704 100644
--- a/it/src/test/java/com/sonar/runner/it/CacheTest.java
+++ b/it/src/test/java/com/sonar/runner/it/CacheTest.java
@@ -25,6 +25,7 @@ import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.ResourceLocation;
import java.io.File;
import java.io.IOException;
+import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -33,7 +34,7 @@ import org.junit.rules.TemporaryFolder;
import static org.assertj.core.api.Assertions.assertThat;
-public class CacheTest extends RunnerTestCase {
+public class CacheTest extends ScannerTestCase {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -42,12 +43,18 @@ public class CacheTest extends RunnerTestCase {
@BeforeClass
public static void setUpClass() {
+ orchestrator.resetData();
orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml"));
orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma");
orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way");
serverRunning = true;
}
+ @AfterClass
+ public static void restartForOtherTests() {
+ ensureStarted();
+ }
+
private static void ensureStarted() {
if (!serverRunning) {
orchestrator.start();
@@ -142,7 +149,7 @@ public class CacheTest extends RunnerTestCase {
currentTemp = temp.newFolder();
}
- SonarRunner runner = newRunner(new File("projects/" + project))
+ SonarRunner runner = newScanner(new File("projects/" + project))
.setProperty("sonar.analysis.mode", mode)
.setProperty("sonar.userHome", currentTemp.getAbsolutePath());
diff --git a/it/src/test/java/com/sonar/runner/it/JavaTest.java b/it/src/test/java/com/sonar/runner/it/JavaTest.java
index a9ece3b..2d0c2fb 100644
--- a/it/src/test/java/com/sonar/runner/it/JavaTest.java
+++ b/it/src/test/java/com/sonar/runner/it/JavaTest.java
@@ -22,6 +22,10 @@ package com.sonar.runner.it;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.ResourceLocation;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -30,18 +34,19 @@ import org.sonar.wsclient.issue.IssueQuery;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
-public class JavaTest extends RunnerTestCase {
+public class JavaTest extends ScannerTestCase {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
+ @After
+ public void cleanup() {
+ orchestrator.resetData();
+ }
+
/**
* No bytecode, only sources
*/
@@ -51,7 +56,7 @@ public class JavaTest extends RunnerTestCase {
orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma");
orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way");
- SonarRunner build = newRunner(new File("projects/java-sample"))
+ SonarRunner build = newScanner(new File("projects/java-sample"))
.setProperty("sonar.verbose", "true")
.addArguments("-e");
// SONARPLUGINS-3061
@@ -97,7 +102,7 @@ public class JavaTest extends RunnerTestCase {
orchestrator.getServer().provisionProject("java:bytecode", "Java Bytecode Sample");
orchestrator.getServer().associateProjectToQualityProfile("java:bytecode", "java", "requires-bytecode");
- SonarRunner build = newRunner(new File("projects/java-bytecode"));
+ SonarRunner build = newScanner(new File("projects/java-bytecode"));
orchestrator.executeBuild(build);
Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:bytecode").setMetrics("lcom4", "violations"));
@@ -129,7 +134,7 @@ public class JavaTest extends RunnerTestCase {
orchestrator.getServer().provisionProject("java:basedir-with-source", "Basedir with source");
orchestrator.getServer().associateProjectToQualityProfile("java:basedir-with-source", "java", "sonar-way");
- SonarRunner build = newRunner(new File("projects/basedir-with-source"));
+ SonarRunner build = newScanner(new File("projects/basedir-with-source"));
orchestrator.executeBuild(build);
Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:basedir-with-source").setMetrics("files", "ncloc"));
@@ -146,7 +151,7 @@ public class JavaTest extends RunnerTestCase {
orchestrator.getServer().provisionProject("SAMPLE", "Java Sample, with comma");
orchestrator.getServer().associateProjectToQualityProfile("SAMPLE", "java", "sonar-way");
- SonarRunner build = newRunner(new File("projects/java-sample"))
+ SonarRunner build = newScanner(new File("projects/java-sample"))
.setProjectKey("SAMPLE");
orchestrator.executeBuild(build);
@@ -160,7 +165,7 @@ public class JavaTest extends RunnerTestCase {
*/
@Test
public void should_override_working_dir_with_relative_path() {
- SonarRunner build = newRunner(new File("projects/override-working-dir"))
+ SonarRunner build = newScanner(new File("projects/override-working-dir"))
.setProperty("sonar.working.directory", ".overridden-relative-sonar");
orchestrator.executeBuild(build);
@@ -174,7 +179,7 @@ public class JavaTest extends RunnerTestCase {
@Test
public void should_override_working_dir_with_absolute_path() {
File projectHome = new File("projects/override-working-dir");
- SonarRunner build = newRunner(projectHome)
+ SonarRunner build = newScanner(projectHome)
.setProperty("sonar.working.directory", new File(projectHome, ".overridden-absolute-sonar").getAbsolutePath());
orchestrator.executeBuild(build);
@@ -187,7 +192,7 @@ public class JavaTest extends RunnerTestCase {
*/
@Test
public void should_fail_if_source_dir_does_not_exist() {
- SonarRunner build = newRunner(new File("projects/bad-source-dirs"));
+ SonarRunner build = newScanner(new File("projects/bad-source-dirs"));
BuildResult result = orchestrator.executeBuildQuietly(build);
assertThat(result.getStatus()).isNotEqualTo(0);
@@ -201,7 +206,7 @@ public class JavaTest extends RunnerTestCase {
@Test
public void should_log_message_when_deprecated_properties_are_used() {
assumeTrue(!orchestrator.getServer().version().isGreaterThanOrEquals("4.3"));
- SonarRunner build = newRunner(new File("projects/using-deprecated-props"));
+ SonarRunner build = newScanner(new File("projects/using-deprecated-props"));
BuildResult result = orchestrator.executeBuild(build);
String logs = result.getLogs();
@@ -216,7 +221,7 @@ public class JavaTest extends RunnerTestCase {
*/
@Test
public void should_warn_when_analysis_is_platform_dependent() {
- SonarRunner build = newRunner(new File("projects/java-sample"))
+ SonarRunner build = newScanner(new File("projects/java-sample"))
// ORCH-243
.setSourceEncoding("");
String log = orchestrator.executeBuild(build).getLogs();
@@ -230,21 +235,21 @@ public class JavaTest extends RunnerTestCase {
@Test
public void should_fail_if_unable_to_connect() {
- SonarRunner build = newRunner(new File("projects/java-sample"))
+ SonarRunner build = newScanner(new File("projects/java-sample"))
.setProperty("sonar.host.url", "http://foo");
BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure
assertThat(result.getStatus()).isNotEqualTo(0);
// with the following message
- assertThat(result.getLogs()).contains("server 'http://foo' can not be reached");
+ assertThat(result.getLogs()).contains("SonarQube server [http://foo] can not be reached");
}
// SONARPLUGINS-3574
@Test
public void run_from_external_location() throws IOException {
File tempDir = temp.newFolder();
- SonarRunner build = newRunner(tempDir)
+ SonarRunner build = newScanner(tempDir)
.setProperty("sonar.projectBaseDir", new File("projects/java-sample").getAbsolutePath())
.addArguments("-e");
orchestrator.executeBuild(build);
diff --git a/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java b/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java
index c8941b2..b09ca8d 100644
--- a/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java
+++ b/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java
@@ -21,22 +21,27 @@ package com.sonar.runner.it;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
+import java.io.File;
+import org.junit.After;
import org.junit.Test;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
-import java.io.File;
-
import static org.fest.assertions.Assertions.assertThat;
-public class MultimoduleTest extends RunnerTestCase {
+public class MultimoduleTest extends ScannerTestCase {
+
+ @After
+ public void cleanup() {
+ orchestrator.resetData();
+ }
/**
* SONARPLUGINS-2202
*/
@Test
public void test_simplest_with_props_on_root() {
- SonarRunner build = newRunner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
+ SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
orchestrator.executeBuild(build);
@@ -67,7 +72,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_multi_language_with_same_projectdir() {
- SonarRunner build = newRunner(new File("projects/multi-module/multi-language"));
+ SonarRunner build = newScanner(new File("projects/multi-module/multi-language"));
orchestrator.executeBuild(build);
@@ -90,7 +95,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_simplest_with_props_on_each_module() {
- SonarRunner build = newRunner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
+ SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
orchestrator.executeBuild(build);
@@ -113,7 +118,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_warning_when_source_folder_on_root_module() {
- SonarRunner build = newRunner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
+ SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
assertThat(orchestrator.executeBuild(build).getLogs()).contains("/!\\ A multi-module project can't have source folders");
}
@@ -123,7 +128,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_deep_path_for_modules() {
- SonarRunner build = newRunner(new File("projects/multi-module/customization/deep-path-for-modules"));
+ SonarRunner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
orchestrator.executeBuild(build);
@@ -146,7 +151,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_module_path_with_space() {
- SonarRunner build = newRunner(new File("projects/multi-module/customization/module-path-with-space"));
+ SonarRunner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
orchestrator.executeBuild(build);
@@ -169,7 +174,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_overwriting_parent_properties() {
- SonarRunner build = newRunner(new File("projects/multi-module/customization/overwriting-parent-properties"));
+ SonarRunner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
orchestrator.executeBuild(build);
@@ -195,7 +200,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void test_using_config_file_property() {
- SonarRunner build = newRunner(new File("projects/multi-module/advanced/using-config-file-prop"));
+ SonarRunner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
orchestrator.executeBuild(build);
@@ -218,7 +223,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void should_fail_if_unexisting_base_dir() {
- SonarRunner build = newRunner(new File("projects/multi-module/failures/unexisting-base-dir"));
+ SonarRunner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure
@@ -233,7 +238,7 @@ public class MultimoduleTest extends RunnerTestCase {
*/
@Test
public void should_fail_if_unexisting_config_file() {
- SonarRunner build = newRunner(new File("projects/multi-module/failures/unexisting-config-file"));
+ SonarRunner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure
diff --git a/it/src/test/java/com/sonar/runner/it/RunnerTestCase.java b/it/src/test/java/com/sonar/runner/it/RunnerTestCase.java
deleted file mode 100644
index 79a1edd..0000000
--- a/it/src/test/java/com/sonar/runner/it/RunnerTestCase.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarSource :: IT :: SonarQube Scanner
- * Copyright (C) 2009 SonarSource
- * sonarqube@googlegroups.com
- *
- * This program 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.
- *
- * This program 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 02
- */
-package com.sonar.runner.it;
-
-import com.sonar.orchestrator.version.Version;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.OrchestratorBuilder;
-import com.sonar.orchestrator.build.SonarRunner;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
-
-import java.io.File;
-
-public abstract class RunnerTestCase {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- public static Orchestrator orchestrator = null;
-
- @BeforeClass
- public static void startServer() {
- OrchestratorBuilder builder = Orchestrator.builderEnv()
- // TODO Java projects should be replaced by Xoo projects
- .setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
- .addPlugin("java")
- .setOrchestratorProperty("findbugsVersion", "LATEST_RELEASE")
- .addPlugin("findbugs")
- .setOrchestratorProperty("javascriptVersion", "LATEST_RELEASE")
- .addPlugin("javascript");
-
- orchestrator = builder.build();
- orchestrator.start();
- }
-
- @AfterClass
- public static void stopServer() {
- if (orchestrator != null) {
- orchestrator.stop();
- orchestrator = null;
- }
- }
-
- SonarRunner newRunner(File baseDir, String... keyValueProperties) {
- SonarRunner runner = SonarRunner.create(baseDir, keyValueProperties);
- String runnerVersion = Version.create(orchestrator.getConfiguration().getString("sonarRunner.version")).toString();
- runner.setRunnerVersion(runnerVersion);
- return runner;
- }
-}
diff --git a/it/src/test/java/com/sonar/runner/it/ScannerTestCase.java b/it/src/test/java/com/sonar/runner/it/ScannerTestCase.java
new file mode 100644
index 0000000..6f0d851
--- /dev/null
+++ b/it/src/test/java/com/sonar/runner/it/ScannerTestCase.java
@@ -0,0 +1,62 @@
+/*
+ * SonarSource :: IT :: SonarQube Scanner
+ * Copyright (C) 2009 SonarSource
+ * sonarqube@googlegroups.com
+ *
+ * This program 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.
+ *
+ * This program 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 02
+ */
+package com.sonar.runner.it;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import com.sonar.orchestrator.version.Version;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+
+public abstract class ScannerTestCase {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @ClassRule
+ public static Orchestrator orchestrator = SonarScannerTestSuite.ORCHESTRATOR;
+
+ private static Version artifactVersion;
+
+ private static Version artifactVersion() {
+ if (artifactVersion == null) {
+ 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"));
+ return artifactVersion;
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return artifactVersion;
+ }
+
+ SonarScanner newScanner(File baseDir, String... keyValueProperties) {
+ SonarScanner scannerCli = SonarScanner.create(baseDir, keyValueProperties);
+ scannerCli.setRunnerVersion(artifactVersion().toString());
+ return scannerCli;
+ }
+}
diff --git a/it/src/test/java/com/sonar/runner/it/SonarRunnerTestSuite.java b/it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java
index 6157d7c..8114fcd 100644
--- a/it/src/test/java/com/sonar/runner/it/SonarRunnerTestSuite.java
+++ b/it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java
@@ -19,12 +19,24 @@
*/
package com.sonar.runner.it;
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({JavaTest.class, MultimoduleTest.class, CacheTest.class})
-public class SonarRunnerTestSuite {
+public class SonarScannerTestSuite {
+
+ @ClassRule
+ public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+ .setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
+ .addPlugin("java")
+ .setOrchestratorProperty("findbugsVersion", "LATEST_RELEASE")
+ .addPlugin("findbugs")
+ .setOrchestratorProperty("javascriptVersion", "LATEST_RELEASE")
+ .addPlugin("javascript")
+ .build();
}