diff options
Diffstat (limited to 'it/src/test')
-rw-r--r-- | it/src/test/java/com/sonar/runner/it/CacheTest.java | 68 | ||||
-rw-r--r-- | it/src/test/java/com/sonar/runner/it/JavaTest.java | 263 | ||||
-rw-r--r-- | it/src/test/java/com/sonar/runner/it/MultimoduleTest.java | 249 | ||||
-rw-r--r-- | it/src/test/java/com/sonar/runner/it/RunnerTestCase.java | 69 | ||||
-rw-r--r-- | it/src/test/java/com/sonar/runner/it/SonarRunnerTestSuite.java | 30 | ||||
-rw-r--r-- | it/src/test/resources/requires-bytecode-profile.xml | 17 | ||||
-rw-r--r-- | it/src/test/resources/sonar-way-profile.xml | 691 |
7 files changed, 1387 insertions, 0 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 new file mode 100644 index 0000000..788b82c --- /dev/null +++ b/it/src/test/java/com/sonar/runner/it/CacheTest.java @@ -0,0 +1,68 @@ +/* + * SonarSource :: IT :: SonarQube Runner + * 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.build.BuildFailureException; + +import com.sonar.orchestrator.locator.ResourceLocation; +import com.sonar.orchestrator.build.BuildResult; +import com.sonar.orchestrator.build.SonarRunner; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.*; +import static org.junit.Assume.assumeTrue; + +public class CacheTest extends RunnerTestCase { + @Test + public void testOffline() { + assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); + orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); + + SonarRunner build = createRunner(true); + BuildResult result = orchestrator.executeBuild(build); + stopServer(); + + build = createRunner(false); + try { + result = orchestrator.executeBuild(build, false); + } catch (BuildFailureException e) { + // expected + } + + build = createRunner(true); + result = orchestrator.executeBuild(build, false); + assertTrue(result.isSuccess()); + } + + private SonarRunner createRunner(boolean enableOffline) { + SonarRunner runner = newRunner(new File("projects/java-sample")) + .setProperty("sonar.analysis.mode", "preview") + .setProfile("sonar-way"); + + if (enableOffline) { + runner.setProperty("sonar.enableOffline", "true"); + } + + return runner; + } + +} diff --git a/it/src/test/java/com/sonar/runner/it/JavaTest.java b/it/src/test/java/com/sonar/runner/it/JavaTest.java new file mode 100644 index 0000000..23cc3a4 --- /dev/null +++ b/it/src/test/java/com/sonar/runner/it/JavaTest.java @@ -0,0 +1,263 @@ +/* + * SonarSource :: IT :: SonarQube Runner + * 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.build.BuildResult; +import com.sonar.orchestrator.build.SonarRunner; +import com.sonar.orchestrator.locator.ResourceLocation; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.wsclient.issue.Issue; +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 { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + /** + * No bytecode, only sources + */ + @Test + public void scan_java_sources() { + orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); + + SonarRunner build = newRunner(new File("projects/java-sample")) + .setProperty("sonar.verbose", "true") + .addArguments("-e", "-X") + .setProfile("sonar-way"); + // SONARPLUGINS-3061 + // Add a trailing slash + build.setProperty("sonar.host.url", orchestrator.getServer().getUrl() + "/"); + orchestrator.executeBuild(build); + + Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:sample").setMetrics("files", "ncloc", "classes", "lcom4", "violations")); + // SONARPLUGINS-2399 + assertThat(project.getName()).isEqualTo("Java Sample, with comma"); + assertThat(project.getDescription()).isEqualTo("This is a Java sample"); + assertThat(project.getVersion()).isEqualTo("1.2.3"); + if (!orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) { + assertThat(project.getLanguage()).isEqualTo("java"); + } + assertThat(project.getMeasureIntValue("files")).isEqualTo(2); + assertThat(project.getMeasureIntValue("classes")).isEqualTo(2); + assertThat(project.getMeasureIntValue("ncloc")).isGreaterThan(10); + assertThat(project.getMeasureIntValue("lcom4")).isNull(); // no bytecode + if (orchestrator.getServer().version().isGreaterThanOrEquals("3.7")) { + // the squid rules enabled in sonar-way-profile do not exist in SQ 3.0 + assertThat(project.getMeasureIntValue("violations")).isGreaterThan(0); + } + + Resource file = orchestrator.getServer().getWsClient() + .find(new ResourceQuery(helloFileKey()).setMetrics("files", "ncloc", "classes", "lcom4", "violations")); + if (orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) { + assertThat(file.getName()).isEqualTo("Hello.java"); + } else { + assertThat(file.getName()).isEqualTo("Hello"); + assertThat(file.getMeasureIntValue("lcom4")).isNull(); // no bytecode + } + assertThat(file.getMeasureIntValue("ncloc")).isEqualTo(7); + if (orchestrator.getServer().version().isGreaterThanOrEquals("3.7")) { + // the squid rules enabled in sonar-way-profile do not exist in SQ 3.0 + assertThat(file.getMeasureIntValue("violations")).isGreaterThan(0); + } + } + + @Test + public void scan_java_sources_and_bytecode() { + orchestrator.getServer().restoreProfile(ResourceLocation.create("/requires-bytecode-profile.xml")); + SonarRunner build = newRunner(new File("projects/java-bytecode")).setProfile("requires-bytecode"); + orchestrator.executeBuild(build); + + Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:bytecode").setMetrics("lcom4", "violations")); + assertThat(project.getName()).isEqualTo("Java Bytecode Sample"); + if (!orchestrator.getServer().version().isGreaterThanOrEquals("4.1")) { + // SONAR-4853 LCOM4 is no more computed on SQ 4.1 + assertThat(project.getMeasureIntValue("lcom4")).isGreaterThanOrEqualTo(1); + } + // the squid rules enabled in sonar-way-profile do not exist in SQ 3.0 + assertThat(project.getMeasureIntValue("violations")).isGreaterThan(0); + + Resource file = orchestrator.getServer().getWsClient().find(new ResourceQuery(findbugsFileKey()).setMetrics("lcom4", "violations")); + assertThat(file.getMeasureIntValue("violations")).isGreaterThan(0); + + // findbugs is executed on bytecode + List<Issue> issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("findbugs:DM_EXIT")).list(); + assertThat(issues).hasSize(1); + assertThat(issues.get(0).ruleKey()).isEqualTo("findbugs:DM_EXIT"); + + // Squid performs analysis of dependencies + issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("squid:CallToDeprecatedMethod")).list(); + assertThat(issues).hasSize(1); + assertThat(issues.get(0).ruleKey()).isEqualTo("squid:CallToDeprecatedMethod"); + } + + @Test + public void basedir_contains_java_sources() { + orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); + SonarRunner build = newRunner(new File("projects/basedir-with-source")).setProfile("sonar-way"); + orchestrator.executeBuild(build); + + Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:basedir-with-source").setMetrics("files", "ncloc")); + assertThat(project.getMeasureIntValue("files")).isEqualTo(1); + assertThat(project.getMeasureIntValue("ncloc")).isGreaterThan(1); + } + + /** + * Replace the maven format groupId:artifactId by a single key + */ + @Test + public void should_support_simple_project_keys() { + orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); + SonarRunner build = newRunner(new File("projects/java-sample")) + .setProjectKey("SAMPLE") + .setProfile("sonar-way"); + orchestrator.executeBuild(build); + + Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("SAMPLE").setMetrics("files", "ncloc")); + assertThat(project.getMeasureIntValue("files")).isEqualTo(2); + assertThat(project.getMeasureIntValue("ncloc")).isGreaterThan(1); + } + + /** + * SONARPLUGINS-1230 + */ + @Test + public void should_override_working_dir_with_relative_path() { + SonarRunner build = newRunner(new File("projects/override-working-dir")) + .setProperty("sonar.working.directory", ".overridden-relative-sonar"); + orchestrator.executeBuild(build); + + assertThat(new File("projects/override-working-dir/.sonar")).doesNotExist(); + assertThat(new File("projects/override-working-dir/.overridden-relative-sonar")).exists().isDirectory(); + } + + /** + * SONARPLUGINS-1230 + */ + @Test + public void should_override_working_dir_with_absolute_path() { + File projectHome = new File("projects/override-working-dir"); + SonarRunner build = newRunner(projectHome) + .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(); + } + + /** + * SONARPLUGINS-1856 + */ + @Test + public void should_fail_if_source_dir_does_not_exist() { + SonarRunner build = newRunner(new File("projects/bad-source-dirs")); + + BuildResult result = orchestrator.executeBuildQuietly(build); + assertThat(result.getStatus()).isNotEqualTo(0); + // with the following message + assertThat(result.getLogs()).contains("The folder 'bad' does not exist for 'bad-source-dirs'"); + } + + /** + * SONARPLUGINS-2203 + */ + @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")); + + BuildResult result = orchestrator.executeBuild(build); + String logs = result.getLogs(); + assertThat(logs).contains("/!\\ The 'sources' property is deprecated and is replaced by 'sonar.sources'. Don't forget to update your files."); + assertThat(logs).contains("/!\\ The 'tests' property is deprecated and is replaced by 'sonar.tests'. Don't forget to update your files."); + assertThat(logs).contains("/!\\ The 'binaries' property is deprecated and is replaced by 'sonar.binaries'. Don't forget to update your files."); + assertThat(logs).contains("/!\\ The 'libraries' property is deprecated and is replaced by 'sonar.libraries'. Don't forget to update your files."); + } + + /** + * SONARPLUGINS-2256 + */ + @Test + public void should_warn_when_analysis_is_platform_dependent() { + SonarRunner build = newRunner(new File("projects/java-sample")) + // ORCH-243 + .setSourceEncoding(""); + String log = orchestrator.executeBuild(build).getLogs(); + + // Note: we can't really check the locale value and the charset because the ones used during the Sonar analysis may not be the ones + // used to launch the tests. But we can check that the analysis is platform dependent (i.e. "sonar.sourceEncoding" hasn't been set). + assertThat(log).contains("Default locale:"); + assertThat(log).contains(", source code encoding:"); + assertThat(log).contains("(analysis is platform dependent)"); + } + + @Test + public void should_fail_if_unable_to_connect() { + SonarRunner build = newRunner(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("ERROR: Sonar 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) + .setProperty("sonar.projectBaseDir", new File("projects/java-sample").getAbsolutePath()) + .addArguments("-e"); + orchestrator.executeBuild(build); + + Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:sample").setMetrics("files", "ncloc", "classes", "lcom4", "violations")); + assertThat(project.getDescription()).isEqualTo("This is a Java sample"); + assertThat(project.getVersion()).isEqualTo("1.2.3"); + } + + private String findbugsFileKey() { + if (orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) { + return "java:bytecode:src/HasFindbugsViolation.java"; + } else { + return "java:bytecode:[default].HasFindbugsViolation"; + } + } + + private String helloFileKey() { + if (orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) { + return "java:sample:src/basic/Hello.java"; + } else { + return "java:sample:basic.Hello"; + } + } +} diff --git a/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java b/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java new file mode 100644 index 0000000..35dc8d9 --- /dev/null +++ b/it/src/test/java/com/sonar/runner/it/MultimoduleTest.java @@ -0,0 +1,249 @@ +/* + * SonarSource :: IT :: SonarQube Runner + * 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.build.BuildResult; +import com.sonar.orchestrator.build.SonarRunner; +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; +import static org.junit.Assume.assumeTrue; + +public class MultimoduleTest extends RunnerTestCase { + + /** + * 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")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("simplest-with-props-on-root"); + assertThat(rootProject.getName()).isEqualTo("Simplest multi-module project with all properties set on the root project"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + + // Verify that we have the modules + Resource module1 = findResource("simplest-with-props-on-root:module1"); + assertThat(module1.getName()).isEqualTo("module1"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + + Resource module2 = findResource("simplest-with-props-on-root:module2"); + assertThat(module2.getName()).isEqualTo("module2"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + + // 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/.sonar"); + 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/.sonar")).doesNotExist(); + assertThat(new File("projects/multi-module/simplest/simplest-with-props-on-root/module2/.sonar")).doesNotExist(); + } + + /** + * SONARPLUGINS-2421 + */ + @Test + public void test_multi_language_with_same_projectdir() { + SonarRunner build = newRunner(new File("projects/multi-module/multi-language")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("multi-language"); + assertThat(rootProject.getName()).isEqualTo("Simplest multi-language project"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + + // Verify that we have the modules + Resource module1 = findResource("multi-language:java-module"); + assertThat(module1.getName()).isEqualTo("java-module"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + + Resource module2 = findResource("multi-language:js-module"); + assertThat(module2.getName()).isEqualTo("js-module"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + } + + /** + * SONARPLUGINS-2202 + */ + @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")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("simplest-with-props-each-module"); + assertThat(rootProject.getName()).isEqualTo("Simplest multi-module project with properties set on each module"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + + // Verify that we have the modules + Resource module1 = findResource("simplest-with-props-each-module:module1"); + assertThat(module1.getName()).isEqualTo("module1"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + + Resource module2 = findResource("simplest-with-props-each-module:overridden-key-for-module2"); + assertThat(module2.getName()).isEqualTo("Module 2"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + } + + /** + * SONARPLUGINS-2295 + */ + @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")); + + assertThat(orchestrator.executeBuild(build).getLogs()).contains("/!\\ A multi-module project can't have source folders"); + } + + /** + * SONARPLUGINS-2202 + */ + @Test + public void test_deep_path_for_modules() { + SonarRunner build = newRunner(new File("projects/multi-module/customization/deep-path-for-modules")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("deep-path-for-modules"); + assertThat(rootProject.getName()).isEqualTo("Project with deep path for modules"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + + // Verify that we have the modules + Resource module1 = findResource("deep-path-for-modules:mod1"); + assertThat(module1.getName()).isEqualTo("Module 1"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + + Resource module2 = findResource("deep-path-for-modules:mod2"); + assertThat(module2.getName()).isEqualTo("Module 2"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + } + + /** + * SONARPLUGINS-2202 + */ + @Test + public void test_module_path_with_space() { + SonarRunner build = newRunner(new File("projects/multi-module/customization/module-path-with-space")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("module-path-with-space"); + assertThat(rootProject.getName()).isEqualTo("Project with module path that contain spaces"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + + // Verify that we have the modules + Resource module1 = findResource("module-path-with-space:module1"); + assertThat(module1.getName()).isEqualTo("Module 1"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + + Resource module2 = findResource("module-path-with-space:module2"); + assertThat(module2.getName()).isEqualTo("Module 2"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + } + + /** + * SONARPLUGINS-2202 + */ + @Test + public void test_overwriting_parent_properties() { + SonarRunner build = newRunner(new File("projects/multi-module/customization/overwriting-parent-properties")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("overwriting-parent-properties"); + assertThat(rootProject.getName()).isEqualTo("Project with modules that overwrite properties"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + assertThat(rootProject.getDescription()).isEqualTo("Description of root project"); + + // Verify that we have the modules + Resource module1 = findResource("overwriting-parent-properties:module1-new-key"); + assertThat(module1.getName()).isEqualTo("Module 1"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + assertThat(module1.getDescription()).isEqualTo("Description of module 1"); + + Resource module2 = findResource("overwriting-parent-properties:module2-new-key"); + assertThat(module2.getName()).isEqualTo("Module 2"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + assertThat(module2.getDescription()).isEqualTo("Description of module 2"); + } + + /** + * SONARPLUGINS-2202 + */ + @Test + public void test_using_config_file_property() { + SonarRunner build = newRunner(new File("projects/multi-module/advanced/using-config-file-prop")); + + orchestrator.executeBuild(build); + + Resource rootProject = findResource("using-config-file-prop"); + assertThat(rootProject.getName()).isEqualTo("Advanced use case - mostly used by the Ant task"); + assertThat(rootProject.getVersion()).isEqualTo("1.2.3"); + + // Verify that we have the modules + Resource module1 = findResource("using-config-file-prop:module1"); + assertThat(module1.getName()).isEqualTo("Module 1"); + assertThat(module1.getVersion()).isEqualTo("1.2.3"); + + Resource module2 = findResource("using-config-file-prop:module2"); + assertThat(module2.getName()).isEqualTo("Module 2"); + assertThat(module2.getVersion()).isEqualTo("1.2.3"); + } + + /** + * SONARPLUGINS-2202 + */ + @Test + public void should_fail_if_unexisting_base_dir() { + SonarRunner build = newRunner(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"); + + } + + /** + * SONARPLUGINS-2202 + */ + @Test + public void should_fail_if_unexisting_config_file() { + SonarRunner build = newRunner(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"); + } + + private Resource findResource(String resourceKey) { + return orchestrator.getServer().getWsClient().find(new ResourceQuery(resourceKey)); + } +} diff --git a/it/src/test/java/com/sonar/runner/it/RunnerTestCase.java b/it/src/test/java/com/sonar/runner/it/RunnerTestCase.java new file mode 100644 index 0000000..bd308c4 --- /dev/null +++ b/it/src/test/java/com/sonar/runner/it/RunnerTestCase.java @@ -0,0 +1,69 @@ +/* + * SonarSource :: IT :: SonarQube Runner + * 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(); + } + } + + 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/SonarRunnerTestSuite.java b/it/src/test/java/com/sonar/runner/it/SonarRunnerTestSuite.java new file mode 100644 index 0000000..e33768d --- /dev/null +++ b/it/src/test/java/com/sonar/runner/it/SonarRunnerTestSuite.java @@ -0,0 +1,30 @@ +/* + * SonarSource :: IT :: SonarQube Runner + * 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 org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({JavaTest.class, MultimoduleTest.class}) +public class SonarRunnerTestSuite { + +} diff --git a/it/src/test/resources/requires-bytecode-profile.xml b/it/src/test/resources/requires-bytecode-profile.xml new file mode 100644 index 0000000..284596f --- /dev/null +++ b/it/src/test/resources/requires-bytecode-profile.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?><!-- Generated by Sonar --> +<profile> + <name>requires-bytecode</name> + <language>java</language> + <rules> + <rule> + <repositoryKey>squid</repositoryKey> + <key>CallToDeprecatedMethod</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>findbugs</repositoryKey> + <key>DM_EXIT</key> + <priority>MAJOR</priority> + </rule> + </rules> +</profile>
\ No newline at end of file diff --git a/it/src/test/resources/sonar-way-profile.xml b/it/src/test/resources/sonar-way-profile.xml new file mode 100644 index 0000000..a5b203d --- /dev/null +++ b/it/src/test/resources/sonar-way-profile.xml @@ -0,0 +1,691 @@ +<?xml version="1.0" encoding="UTF-8"?><!-- Generated by SonarQube --> +<profile> + <name>sonar-way</name> + <language>java</language> + <rules> + <rule> + <repositoryKey>common-java</repositoryKey> + <key>DuplicatedBlocks</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>common-java</repositoryKey> + <key>InsufficientBranchCoverage</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>minimumBranchCoverageRatio</key> + <value>65.0</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00105</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>MethodCyclomaticComplexity</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>max</key> + <value>10</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ClassCyclomaticComplexity</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>max</key> + <value>200</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>CommentedOutCodeLine</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00108</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00107</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>maximumMethodParameters</key> + <value>7</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00112</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00100</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[a-z][a-zA-Z0-9]*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00101</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[A-Z][a-zA-Z0-9]*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00114</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[A-Z][a-zA-Z0-9]*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00115</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00116</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[a-z][a-zA-Z0-9]*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00117</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[a-z][a-zA-Z0-9]*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00119</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[A-Z]$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00120</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>^[a-z]+(\.[a-z][a-z0-9]*)*$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00121</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S00122</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>RightCurlyBraceSameLineAsNextBlockCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>RightCurlyBraceStartLineCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>LeftCurlyBraceEndLineCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>UselessParenthesesCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ObjectFinalizeCheck</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ObjectFinalizeOverridenCheck</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ObjectFinalizeOverridenCallsSuperFinalizeCheck</key> + <priority>BLOCKER</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ClassVariableVisibilityCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ForLoopCounterChangedCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>LabelsShouldNotBeUsedCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>SwitchLastCaseIsDefaultCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>EmptyStatementUsageCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>ModifiersOrderCheck</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>AssignmentInSubExpressionCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>StringEqualityComparisonCheck</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>TrailingCommentCheck</key> + <priority>MINOR</priority> + <parameters> + <parameter> + <key>legalCommentPattern</key> + <value>^\s*+[^\s]++$</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>UselessImportCheck</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>LowerCaseLongSuffixCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>MissingDeprecatedCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>HiddenFieldCheck</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1133</key> + <priority>INFO</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1134</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1135</key> + <priority>INFO</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1118</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1132</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1126</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1125</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1067</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>max</key> + <value>3</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1141</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1147</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1143</key> + <priority>BLOCKER</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1145</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1157</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1155</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1149</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1171</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1168</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1170</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1163</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S106</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1165</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1066</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S134</key> + <priority>MINOR</priority> + <parameters> + <parameter> + <key>max</key> + <value>3</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1181</key> + <priority>BLOCKER</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1150</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1182</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1151</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>max</key> + <value>5</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S128</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1166</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1190</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1188</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>max</key> + <value>20</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1191</key> + <priority>MAJOR</priority> + <parameters></parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S135</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1186</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1185</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1174</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1175</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1153</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1148</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1195</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1194</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1193</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1192</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1158</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1215</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1197</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1220</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1221</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1199</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1214</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1201</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1210</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1206</key> + <priority>BLOCKER</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1219</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1301</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1314</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1226</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1313</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1312</key> + <priority>MAJOR</priority> + <parameters> + <parameter> + <key>format</key> + <value>LOG(?:GER)?</value> + </parameter> + </parameters> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1318</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1223</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1319</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1231</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1444</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1452</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1481</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1068</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1317</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1596</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>UnusedPrivateMethod</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>RedundantThrowsDeclarationCheck</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1160</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1217</key> + <priority>CRITICAL</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1488</key> + <priority>MINOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1602</key> + <priority>MAJOR</priority> + </rule> + <rule> + <repositoryKey>squid</repositoryKey> + <key>S1611</key> + <priority>MINOR</priority> + </rule> + </rules> +</profile>
\ No newline at end of file |