env: | env: | ||||
matrix: | matrix: | ||||
- PR_ANALYSIS=true | |||||
- RUN_ITS=true SQ_VERSION=DEV | |||||
- RUN_ITS=true SQ_VERSION=5.1.2 | |||||
- RUN_ITS=true SQ_VERSION=LTS | |||||
- TARGET=CI | |||||
- TARGET=IT SQ_VERSION=DEV | |||||
- TARGET=IT SQ_VERSION=5.1.2 | |||||
- TARGET=IT SQ_VERSION=LTS | |||||
cache: | cache: | ||||
directories: | directories: |
<dependency> | <dependency> | ||||
<groupId>org.sonarsource.orchestrator</groupId> | <groupId>org.sonarsource.orchestrator</groupId> | ||||
<artifactId>sonar-orchestrator</artifactId> | <artifactId>sonar-orchestrator</artifactId> | ||||
<version>3.8</version> | |||||
<version>3.9-SNAPSHOT</version> | |||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>junit</groupId> | <groupId>junit</groupId> | ||||
<artifactId>maven-surefire-plugin</artifactId> | <artifactId>maven-surefire-plugin</artifactId> | ||||
<configuration> | <configuration> | ||||
<includes> | <includes> | ||||
<include>**/SonarRunnerTestSuite.java</include> | |||||
<include>**/SonarScannerTestSuite.java</include> | |||||
</includes> | </includes> | ||||
</configuration> | </configuration> | ||||
</plugin> | </plugin> |
import com.sonar.orchestrator.locator.ResourceLocation; | import com.sonar.orchestrator.locator.ResourceLocation; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import org.junit.AfterClass; | |||||
import org.junit.Assume; | import org.junit.Assume; | ||||
import org.junit.BeforeClass; | import org.junit.BeforeClass; | ||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
public class CacheTest extends RunnerTestCase { | |||||
public class CacheTest extends ScannerTestCase { | |||||
@Rule | @Rule | ||||
public TemporaryFolder temp = new TemporaryFolder(); | public TemporaryFolder temp = new TemporaryFolder(); | ||||
@BeforeClass | @BeforeClass | ||||
public static void setUpClass() { | public static void setUpClass() { | ||||
orchestrator.resetData(); | |||||
orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); | orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); | ||||
orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma"); | orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma"); | ||||
orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way"); | orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way"); | ||||
serverRunning = true; | serverRunning = true; | ||||
} | } | ||||
@AfterClass | |||||
public static void restartForOtherTests() { | |||||
ensureStarted(); | |||||
} | |||||
private static void ensureStarted() { | private static void ensureStarted() { | ||||
if (!serverRunning) { | if (!serverRunning) { | ||||
orchestrator.start(); | orchestrator.start(); | ||||
currentTemp = temp.newFolder(); | currentTemp = temp.newFolder(); | ||||
} | } | ||||
SonarRunner runner = newRunner(new File("projects/" + project)) | |||||
SonarRunner runner = newScanner(new File("projects/" + project)) | |||||
.setProperty("sonar.analysis.mode", mode) | .setProperty("sonar.analysis.mode", mode) | ||||
.setProperty("sonar.userHome", currentTemp.getAbsolutePath()); | .setProperty("sonar.userHome", currentTemp.getAbsolutePath()); | ||||
import com.sonar.orchestrator.build.BuildResult; | import com.sonar.orchestrator.build.BuildResult; | ||||
import com.sonar.orchestrator.build.SonarRunner; | import com.sonar.orchestrator.build.SonarRunner; | ||||
import com.sonar.orchestrator.locator.ResourceLocation; | 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.Rule; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.rules.TemporaryFolder; | import org.junit.rules.TemporaryFolder; | ||||
import org.sonar.wsclient.services.Resource; | import org.sonar.wsclient.services.Resource; | ||||
import org.sonar.wsclient.services.ResourceQuery; | 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.fest.assertions.Assertions.assertThat; | ||||
import static org.junit.Assume.assumeTrue; | import static org.junit.Assume.assumeTrue; | ||||
public class JavaTest extends RunnerTestCase { | |||||
public class JavaTest extends ScannerTestCase { | |||||
@Rule | @Rule | ||||
public TemporaryFolder temp = new TemporaryFolder(); | public TemporaryFolder temp = new TemporaryFolder(); | ||||
@After | |||||
public void cleanup() { | |||||
orchestrator.resetData(); | |||||
} | |||||
/** | /** | ||||
* No bytecode, only sources | * No bytecode, only sources | ||||
*/ | */ | ||||
orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma"); | orchestrator.getServer().provisionProject("java:sample", "Java Sample, with comma"); | ||||
orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way"); | 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") | .setProperty("sonar.verbose", "true") | ||||
.addArguments("-e"); | .addArguments("-e"); | ||||
// SONARPLUGINS-3061 | // SONARPLUGINS-3061 | ||||
orchestrator.getServer().provisionProject("java:bytecode", "Java Bytecode Sample"); | orchestrator.getServer().provisionProject("java:bytecode", "Java Bytecode Sample"); | ||||
orchestrator.getServer().associateProjectToQualityProfile("java:bytecode", "java", "requires-bytecode"); | 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); | orchestrator.executeBuild(build); | ||||
Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:bytecode").setMetrics("lcom4", "violations")); | Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:bytecode").setMetrics("lcom4", "violations")); | ||||
orchestrator.getServer().provisionProject("java:basedir-with-source", "Basedir with source"); | orchestrator.getServer().provisionProject("java:basedir-with-source", "Basedir with source"); | ||||
orchestrator.getServer().associateProjectToQualityProfile("java:basedir-with-source", "java", "sonar-way"); | 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); | orchestrator.executeBuild(build); | ||||
Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:basedir-with-source").setMetrics("files", "ncloc")); | Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:basedir-with-source").setMetrics("files", "ncloc")); | ||||
orchestrator.getServer().provisionProject("SAMPLE", "Java Sample, with comma"); | orchestrator.getServer().provisionProject("SAMPLE", "Java Sample, with comma"); | ||||
orchestrator.getServer().associateProjectToQualityProfile("SAMPLE", "java", "sonar-way"); | 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"); | .setProjectKey("SAMPLE"); | ||||
orchestrator.executeBuild(build); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void should_override_working_dir_with_relative_path() { | 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"); | .setProperty("sonar.working.directory", ".overridden-relative-sonar"); | ||||
orchestrator.executeBuild(build); | orchestrator.executeBuild(build); | ||||
@Test | @Test | ||||
public void should_override_working_dir_with_absolute_path() { | public void should_override_working_dir_with_absolute_path() { | ||||
File projectHome = new File("projects/override-working-dir"); | 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()); | .setProperty("sonar.working.directory", new File(projectHome, ".overridden-absolute-sonar").getAbsolutePath()); | ||||
orchestrator.executeBuild(build); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void should_fail_if_source_dir_does_not_exist() { | 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); | BuildResult result = orchestrator.executeBuildQuietly(build); | ||||
assertThat(result.getStatus()).isNotEqualTo(0); | assertThat(result.getStatus()).isNotEqualTo(0); | ||||
@Test | @Test | ||||
public void should_log_message_when_deprecated_properties_are_used() { | public void should_log_message_when_deprecated_properties_are_used() { | ||||
assumeTrue(!orchestrator.getServer().version().isGreaterThanOrEquals("4.3")); | 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); | BuildResult result = orchestrator.executeBuild(build); | ||||
String logs = result.getLogs(); | String logs = result.getLogs(); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void should_warn_when_analysis_is_platform_dependent() { | 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 | // ORCH-243 | ||||
.setSourceEncoding(""); | .setSourceEncoding(""); | ||||
String log = orchestrator.executeBuild(build).getLogs(); | String log = orchestrator.executeBuild(build).getLogs(); | ||||
@Test | @Test | ||||
public void should_fail_if_unable_to_connect() { | 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"); | .setProperty("sonar.host.url", "http://foo"); | ||||
BuildResult result = orchestrator.executeBuildQuietly(build); | BuildResult result = orchestrator.executeBuildQuietly(build); | ||||
// expect build failure | // expect build failure | ||||
assertThat(result.getStatus()).isNotEqualTo(0); | assertThat(result.getStatus()).isNotEqualTo(0); | ||||
// with the following message | // 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 | // SONARPLUGINS-3574 | ||||
@Test | @Test | ||||
public void run_from_external_location() throws IOException { | public void run_from_external_location() throws IOException { | ||||
File tempDir = temp.newFolder(); | File tempDir = temp.newFolder(); | ||||
SonarRunner build = newRunner(tempDir) | |||||
SonarRunner build = newScanner(tempDir) | |||||
.setProperty("sonar.projectBaseDir", new File("projects/java-sample").getAbsolutePath()) | .setProperty("sonar.projectBaseDir", new File("projects/java-sample").getAbsolutePath()) | ||||
.addArguments("-e"); | .addArguments("-e"); | ||||
orchestrator.executeBuild(build); | orchestrator.executeBuild(build); |
import com.sonar.orchestrator.build.BuildResult; | import com.sonar.orchestrator.build.BuildResult; | ||||
import com.sonar.orchestrator.build.SonarRunner; | import com.sonar.orchestrator.build.SonarRunner; | ||||
import java.io.File; | |||||
import org.junit.After; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.wsclient.services.Resource; | import org.sonar.wsclient.services.Resource; | ||||
import org.sonar.wsclient.services.ResourceQuery; | import org.sonar.wsclient.services.ResourceQuery; | ||||
import java.io.File; | |||||
import static org.fest.assertions.Assertions.assertThat; | 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 | * SONARPLUGINS-2202 | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_simplest_with_props_on_root() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_multi_language_with_same_projectdir() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_simplest_with_props_on_each_module() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_warning_when_source_folder_on_root_module() { | 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"); | assertThat(orchestrator.executeBuild(build).getLogs()).contains("/!\\ A multi-module project can't have source folders"); | ||||
} | } | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_deep_path_for_modules() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_module_path_with_space() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_overwriting_parent_properties() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void test_using_config_file_property() { | 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); | orchestrator.executeBuild(build); | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void should_fail_if_unexisting_base_dir() { | 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); | BuildResult result = orchestrator.executeBuildQuietly(build); | ||||
// expect build failure | // expect build failure | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void should_fail_if_unexisting_config_file() { | 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); | BuildResult result = orchestrator.executeBuildQuietly(build); | ||||
// expect build failure | // expect build failure |
/* | |||||
* 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; | |||||
} | |||||
} |
/* | |||||
* 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; | |||||
} | |||||
} |
*/ | */ | ||||
package com.sonar.runner.it; | package com.sonar.runner.it; | ||||
import com.sonar.orchestrator.Orchestrator; | |||||
import org.junit.ClassRule; | |||||
import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||
import org.junit.runners.Suite; | import org.junit.runners.Suite; | ||||
import org.junit.runners.Suite.SuiteClasses; | import org.junit.runners.Suite.SuiteClasses; | ||||
@RunWith(Suite.class) | @RunWith(Suite.class) | ||||
@SuiteClasses({JavaTest.class, MultimoduleTest.class, CacheTest.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(); | |||||
} | } |
#!/bin/bash | |||||
#!/bin/bash -v | |||||
set -euo pipefail | set -euo pipefail | ||||
function installTravisTools { | function installTravisTools { | ||||
mkdir ~/.local | |||||
mkdir -p ~/.local | |||||
curl -sSL https://github.com/SonarSource/travis-utils/tarball/v21 | tar zx --strip-components 1 -C ~/.local | curl -sSL https://github.com/SonarSource/travis-utils/tarball/v21 | tar zx --strip-components 1 -C ~/.local | ||||
source ~/.local/bin/install | source ~/.local/bin/install | ||||
} | } | ||||
if [ -n "${PR_ANALYSIS:-}" ] && [ "${PR_ANALYSIS}" == true ] | |||||
then | |||||
if [ "$TRAVIS_PULL_REQUEST" != "false" ] | |||||
then | |||||
# For security reasons environment variables are not available on the pull requests | |||||
# coming from outside repositories | |||||
# http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests | |||||
if [ -n "$SONAR_GITHUB_OAUTH" ]; then | |||||
function strongEcho { | |||||
echo "" | |||||
echo "================ $1 =================" | |||||
} | |||||
case "$TARGET" in | |||||
# Switch to java 8 as the Dory HTTPS certificate is not supported by Java 7 | |||||
export JAVA_HOME=/usr/lib/jvm/java-8-oracle | |||||
export PATH=$JAVA_HOME/bin:$PATH | |||||
CI) | |||||
if [ "${TRAVIS_BRANCH}" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then | |||||
strongEcho 'Build and analyze commit in master' | |||||
# this commit is master must be built and analyzed (with upload of report) | |||||
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify -Pcoverage-per-test -Dmaven.test.redirectTestOutputToFile=false -B -e -V | |||||
# PR analysis | |||||
mvn verify sonar:sonar -B -e -V \ | |||||
-Dsonar.analysis.mode=issues \ | |||||
# Switch to java 8 as the Dory HTTPS certificate is not supported by Java 7 | |||||
export JAVA_HOME=/usr/lib/jvm/java-8-oracle | |||||
export PATH=$JAVA_HOME/bin:$PATH | |||||
export MAVEN_OPTS="-Xmx1G -Xms128m" | |||||
mvn sonar:sonar -B -e -V \ | |||||
-Dsonar.host.url=$SONAR_HOST_URL \ | |||||
-Dsonar.login=$SONAR_TOKEN | |||||
elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "$GITHUB_TOKEN" ]; then | |||||
# For security reasons environment variables are not available on the pull requests | |||||
# coming from outside repositories | |||||
# http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests | |||||
# That's why the analysis does not need to be executed if the variable SONAR_GITHUB_OAUTH is not defined. | |||||
strongEcho 'Build and analyze pull request' | |||||
# this pull request must be built and analyzed (without upload of report) | |||||
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify -Pcoverage-per-test -Dmaven.test.redirectTestOutputToFile=false -B -e -V | |||||
# Switch to java 8 as the Dory HTTPS certificate is not supported by Java 7 | |||||
export JAVA_HOME=/usr/lib/jvm/java-8-oracle | |||||
export PATH=$JAVA_HOME/bin:$PATH | |||||
mvn sonar:sonar -B -e -V \ | |||||
-Dsonar.analysis.mode=issues \ | |||||
-Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \ | -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \ | ||||
-Dsonar.github.repository=$TRAVIS_REPO_SLUG \ | -Dsonar.github.repository=$TRAVIS_REPO_SLUG \ | ||||
-Dsonar.github.login=$SONAR_GITHUB_LOGIN \ | |||||
-Dsonar.github.oauth=$SONAR_GITHUB_OAUTH \ | |||||
-Dsonar.github.oauth=$GITHUB_TOKEN \ | |||||
-Dsonar.host.url=$SONAR_HOST_URL \ | -Dsonar.host.url=$SONAR_HOST_URL \ | ||||
-Dsonar.login=$SONAR_LOGIN \ | |||||
-Dsonar.password=$SONAR_PASSWD | |||||
fi | |||||
fi | |||||
else | |||||
# Regular CI (use install for ITs) | |||||
mvn install -B -e -V | |||||
fi | |||||
-Dsonar.login=$SONAR_TOKEN | |||||
if [ -n "${RUN_ITS:-}" ] && [ "${RUN_ITS}" == true ] | |||||
then | |||||
installTravisTools | |||||
build_snapshot "SonarSource/orchestrator" | |||||
else | |||||
strongEcho 'Build, no analysis' | |||||
# Build branch, without any analysis | |||||
# No need for Maven goal "install" as the generated JAR file does not need to be installed | |||||
# in Maven local repository | |||||
mvn verify -Dmaven.test.redirectTestOutputToFile=false -B -e -V | |||||
fi | |||||
;; | |||||
IT) | |||||
installTravisTools | |||||
if [ "${SQ_VERSION}" == "DEV" ] | if [ "${SQ_VERSION}" == "DEV" ] | ||||
then | then | ||||
build_snapshot "SonarSource/sonarqube" | build_snapshot "SonarSource/sonarqube" | ||||
fi | fi | ||||
# Need install because ITs will take artifact from local repo | |||||
mvn install -B -e -V -Dsource.skip=true -Denforcer.skip=true -Danimal.sniffer.skip=true -Dmaven.test.skip=true | |||||
cd it | cd it | ||||
mvn -DsonarRunner.version="2.5-SNAPSHOT" -Dsonar.runtimeVersion=$SQ_VERSION -Dmaven.test.redirectTestOutputToFile=false install | |||||
build_snapshot "SonarSource/orchestrator" | |||||
mvn -Dsonar.runtimeVersion="$SQ_VERSION" -Dmaven.test.redirectTestOutputToFile=false verify | |||||
;; | |||||
*) | |||||
echo "Unexpected TARGET value: $TARGET" | |||||
exit 1 | |||||
;; | |||||
fi | |||||
esac |