@Test public void test() throws Exception { assertTrue( "SonarQube 5.1 is the minimum version to generate the issues report, change your orchestrator.properties", orchestrator.getConfiguration().getSonarVersion().isGreaterThanOrEquals("5.1")); File litsDifferencesFile = FileLocation.of("target/differences").getFile(); SonarRunner build = SonarRunner.create(FileLocation.of("../sources/src").getFile()) .setProjectKey("project") .setProjectName("project") .setProjectVersion("1") .setLanguage("js") .setSourceDirs("./") .setSourceEncoding("utf-8") .setProfile("rules") .setProperty("sonar.analysis.mode", "preview") .setProperty("sonar.issuesReport.html.enable", "true") .setProperty( "dump.old", FileLocation.of("src/test/expected").getFile().getAbsolutePath()) .setProperty("dump.new", FileLocation.of("target/actual").getFile().getAbsolutePath()) .setProperty("lits.differences", litsDifferencesFile.getAbsolutePath()) .setProperty("sonar.cpd.skip", "true") .setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx1024m"); orchestrator.executeBuild(build); assertThat(Files.toString(litsDifferencesFile, StandardCharsets.UTF_8)).isEmpty(); }
static { OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv() // PHP Plugin .addPlugin( FileLocation.of( Iterables.getOnlyElement( Arrays.asList( new File("../../../sonar-php-plugin/target/") .listFiles( new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar") && !name.endsWith("-sources.jar"); } }))) .getAbsolutePath())) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "profile.xml")) // Custom rules plugin .addPlugin( FileLocation.of( "../plugins/php-custom-rules-plugin/target/php-custom-rules-plugin-1.0-SNAPSHOT.jar")) .restoreProfileAtStartup( FileLocation.ofClasspath(RESOURCE_DIRECTORY + "profile-php-custom-rules.xml")); ORCHESTRATOR = orchestratorBuilder.build(); }
@Before public void prepareData() { ORCHESTRATOR.resetData(); ORCHESTRATOR .getServer() .restoreProfile(FileLocation.ofClasspath("/issue/issue-on-tag-foobar.xml")); ORCHESTRATOR .getServer() .restoreProfile( FileLocation.ofClasspath("/issue/IssueTrackingTest/one-issue-per-module-profile.xml")); ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY); adminClient = newAdminWsClient(ORCHESTRATOR); }
@Before public void setUpProject() throws IOException { orchestrator.resetData(); orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/duplication/xoo-duplication-profile.xml")); FileUtils.copyDirectory(ItUtils.projectDir(PROJECT_DIR), temp.getRoot()); projectDir = temp.getRoot(); }
/** SONAR-6787 */ @Test public void ensure_differential_period_4_and_5_defined_at_project_level_is_taken_into_account() throws Exception { orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); setServerProperty(orchestrator, PROJECT_KEY, "sonar.timemachine.period4", "30"); setServerProperty(orchestrator, PROJECT_KEY, "sonar.timemachine.period5", "previous_analysis"); // Execute an analysis in the past to have a past snapshot without any issues orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty"); orchestrator.executeBuild( SonarRunner.create(projectDir("shared/xoo-sample")) .setProperty("sonar.projectDate", formatDate(addDays(new Date(), -60)))); // Second analysis -> issues will be created orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/measureHistory/one-issue-per-line-profile.xml")); orchestrator .getServer() .associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line"); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); // New technical debt only comes from new issues Resource newTechnicalDebt = orchestrator .getServer() .getWsClient() .find( ResourceQuery.createForMetrics( "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt") .setIncludeTrends(true)); List<Measure> measures = newTechnicalDebt.getMeasures(); assertThat(measures.get(0).getVariation4()).isEqualTo(17); assertThat(measures.get(0).getVariation5()).isEqualTo(17); // Third analysis, with exactly the same profile -> no new issues so no new technical debt orchestrator .getServer() .associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line"); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); newTechnicalDebt = orchestrator .getServer() .getWsClient() .find( ResourceQuery.createForMetrics( "sample:src/main/xoo/sample/Sample.xoo", "new_technical_debt") .setIncludeTrends(true)); // No variation => measure is purged assertThat(newTechnicalDebt).isNull(); }
/** SONAR-926 SONAR-5069 */ @Test public void test_sonar_runner_inspection() { orchestrator .getServer() .restoreProfile( FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line.xml")); orchestrator .getServer() .restoreProfile( FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line-xoo2.xml")); orchestrator.getServer().provisionProject("multi-language-sample", "multi-language-sample"); orchestrator .getServer() .associateProjectToQualityProfile("multi-language-sample", "xoo", "one-issue-per-line"); orchestrator .getServer() .associateProjectToQualityProfile( "multi-language-sample", "xoo2", "one-issue-per-line-xoo2"); SonarRunner build = SonarRunner.create().setProjectDir(ItUtils.projectDir("analysis/xoo-multi-languages")); BuildResult result = orchestrator.executeBuild(build); assertThat(result.getLogs()).contains("2 files indexed"); assertThat(result.getLogs()).contains("Quality profile for xoo: one-issue-per-line"); assertThat(result.getLogs()).contains("Quality profile for xoo2: one-issue-per-line-xoo2"); // modules Resource project = getResource("multi-language-sample", "files", "violations"); assertThat(project.getMeasureIntValue("files")).isEqualTo(2); assertThat(project.getMeasureIntValue("violations")).isEqualTo(26); Resource xooFile = getResource("multi-language-sample:src/sample/Sample.xoo", "violations"); assertThat(xooFile.getMeasureIntValue("violations")).isEqualTo(13); Resource xoo2File = getResource("multi-language-sample:src/sample/Sample.xoo2", "violations"); assertThat(xoo2File.getMeasureIntValue("violations")).isEqualTo(13); }
/** SONAR-7093 */ @Test public void ensure_leak_period_defined_at_project_level_is_taken_into_account() throws Exception { orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); // Set a global property and a project property to ensure project property is used setServerProperty(orchestrator, "sonar.timemachine.period1", "previous_analysis"); setServerProperty(orchestrator, PROJECT_KEY, "sonar.timemachine.period1", "30"); // Execute an analysis in the past to have a past snapshot without any issues orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty"); orchestrator.executeBuild( SonarRunner.create(projectDir("shared/xoo-sample")) .setProperty("sonar.projectDate", formatDate(addDays(new Date(), -15)))); // Second analysis -> issues will be created orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/measureHistory/one-issue-per-line-profile.xml")); orchestrator .getServer() .associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line"); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); // Third analysis -> There's no new issue from previous analysis orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); // Project should have 17 new issues for period 1 Resource newTechnicalDebt = orchestrator .getServer() .getWsClient() .find(ResourceQuery.createForMetrics(PROJECT_KEY, "violations").setIncludeTrends(true)); List<Measure> measures = newTechnicalDebt.getMeasures(); assertThat(measures.get(0).getVariation1()).isEqualTo(17); // Check on ui that it's possible to define leak period on project new SeleneseTest( Selenese.builder() .setHtmlTestsInClasspath( "define-leak-period-on-project", "/measureHistory/DifferentialPeriodsTest/define-leak-period-on-project.html") .build()) .runOn(orchestrator); }
@BeforeClass public static void analyzeProject() { orchestrator.resetData(); orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/authorisation/one-issue-per-line-profile.xml")); orchestrator.getServer().provisionProject(PROJECT_KEY, "Sample"); orchestrator .getServer() .associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample")); orchestrator.executeBuild(sampleProject); adminWsClient = newAdminWsClient(orchestrator); permissionsWsClient = adminWsClient.permissions(); createUser(LOGIN, "George Orwell"); createGroup(GROUP_NAME); }
static { OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv() .addPlugin("java") .addPlugin("checkstyle") .setMainPluginKey("checkstyle") .addPlugin(FileLocation.of(pluginJar("checkstyle-extension-plugin"))) .restoreProfileAtStartup( FileLocation.ofClasspath( "/com/sonar/it/java/CheckstyleExtensionsTest/extension-backup.xml")) .restoreProfileAtStartup( FileLocation.ofClasspath("/com/sonar/it/java/CheckstyleTest/checkstyle-backup.xml")) .restoreProfileAtStartup( FileLocation.ofClasspath( "/com/sonar/it/java/CheckstyleTest/suppression-comment-filter.xml")) .restoreProfileAtStartup( FileLocation.ofClasspath( "/com/sonar/it/java/CheckstyleTest/suppress-warnings-filter.xml")) .restoreProfileAtStartup(FileLocation.ofClasspath("/sonar-way-2.7.xml")); ORCHESTRATOR = orchestratorBuilder.build(); }
private void restoreProfile(String fileName) { orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/batch/IssuesModeTest/" + fileName)); }