Search in sources :

Example 11 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaTest method should_execute_rule_on_test.

@Test
public void should_execute_rule_on_test() throws Exception {
    MavenLocation junit_4_11 = MavenLocation.of("junit", "junit", "4.11");
    new MavenLocator(orchestrator.getConfiguration()).copyToDirectory(junit_4_11, tmp.getRoot());
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("java-inner-classes")).setProperty("sonar.profile", "ignored-test-check").setProperty("sonar.java.test.binaries", "target/test-classes").setProperty("sonar.java.test.libraries", new File(tmp.getRoot(), junit_4_11.getFilename()).getAbsolutePath()).setCleanPackageSonarGoals();
    orchestrator.executeBuild(build);
    assertThat(getMeasureAsInteger("com.sonarsource.it.samples:java-inner-classes", "violations")).isEqualTo(1);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) MavenLocator(com.sonar.orchestrator.locator.MavenLocator) File(java.io.File) MavenLocation(com.sonar.orchestrator.locator.MavenLocation) Test(org.junit.Test)

Example 12 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaTest method measures_on_directory.

@Test
public void measures_on_directory() {
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("measures-on-directory")).setCleanPackageSonarGoals();
    BuildResult result = orchestrator.executeBuildQuietly(build);
    // since sonar-java 2.1 does not fail if multiple package in same directory.
    assertThat(result.getLastStatus()).isEqualTo(0);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) BuildResult(com.sonar.orchestrator.build.BuildResult) Test(org.junit.Test)

Example 13 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaTest method shouldAcceptFilenamesWithDollar.

/**
 * See SONAR-1865
 */
@Test
public void shouldAcceptFilenamesWithDollar() {
    MavenBuild build = MavenBuild.create(TestUtils.projectPom("dollar-in-names")).setCleanPackageSonarGoals().setProperty("sonar.dynamicAnalysis", "false");
    orchestrator.executeBuild(build);
    WsComponents.Component file = getComponent(JavaTestSuite.keyFor("org.sonar.it.core:dollar-in-names", "dollars/", "FilenameWith$Dollar.java"));
    assertThat(file).isNotNull();
    assertThat(file.getName()).contains("FilenameWith$Dollar");
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) WsComponents(org.sonarqube.ws.WsComponents) Test(org.junit.Test)

Example 14 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaTest method should_create_issue_pom_xml.

@Test
public void should_create_issue_pom_xml() {
    assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("6.3"));
    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/profile-pom-xml.xml"));
    orchestrator.getServer().provisionProject("org.sonarsource.java:test-project", "Test Project");
    orchestrator.getServer().associateProjectToQualityProfile("org.sonarsource.java:test-project", "java", "java-pom-xml");
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("pom-xml")).setCleanPackageSonarGoals();
    orchestrator.executeBuild(build);
    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
    List<Issue> issues = issueClient.find(IssueQuery.create().components("org.sonarsource.java:test-project:pom.xml")).list();
    assertThat(issues).hasSize(1);
    assertThat(issues.iterator().next().ruleKey()).isEqualTo("squid:S3423");
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Issue(org.sonar.wsclient.issue.Issue) IssueClient(org.sonar.wsclient.issue.IssueClient) Test(org.junit.Test)

Example 15 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaTest method multiple_package_in_directory_should_not_fail.

@Test
public void multiple_package_in_directory_should_not_fail() throws Exception {
    MavenBuild inspection = MavenBuild.create().setPom(TestUtils.projectPom("multiple-packages-in-directory")).setCleanPackageSonarGoals();
    BuildResult result = orchestrator.executeBuildQuietly(inspection);
    assertThat(result.getLastStatus()).isEqualTo(0);
    inspection = MavenBuild.create().setPom(TestUtils.projectPom("multiple-packages-in-directory")).setProperty("sonar.skipPackageDesign", "true").setGoals("sonar:sonar");
    result = orchestrator.executeBuildQuietly(inspection);
    assertThat(result.getLastStatus()).isEqualTo(0);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) BuildResult(com.sonar.orchestrator.build.BuildResult) Test(org.junit.Test)

Aggregations

MavenBuild (com.sonar.orchestrator.build.MavenBuild)30 Test (org.junit.Test)23 BuildResult (com.sonar.orchestrator.build.BuildResult)7 BeforeClass (org.junit.BeforeClass)4 Issue (org.sonar.wsclient.issue.Issue)3 IssueClient (org.sonar.wsclient.issue.IssueClient)3 File (java.io.File)2 Measure (org.sonarqube.ws.WsMeasures.Measure)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 FileLocation (com.sonar.orchestrator.locator.FileLocation)1 MavenLocation (com.sonar.orchestrator.locator.MavenLocation)1 MavenLocator (com.sonar.orchestrator.locator.MavenLocator)1 Double.parseDouble (java.lang.Double.parseDouble)1 WsComponents (org.sonarqube.ws.WsComponents)1