diff options
author | Jenkins CI <ci@sonarsource.com> | 2016-01-06 12:50:23 +0100 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2016-01-06 12:50:23 +0100 |
commit | 0429a8b70f7d60755f65602037d1c6fd01011c75 (patch) | |
tree | 8556eb60c0dcd8ad6f16dcf118dc1cec3fd192b3 | |
parent | 0fddc5fa4ea33882b60e072eee51f0e1ea585b4c (diff) | |
parent | 36619d7c9a56bef27d2430b77685e7a4f65abb55 (diff) | |
download | sonarqube-0429a8b70f7d60755f65602037d1c6fd01011c75.tar.gz sonarqube-0429a8b70f7d60755f65602037d1c6fd01011c75.zip |
Automatic merge from branch-5.3
* origin/branch-5.3:
SONAR-7093 Allow projects to define their leak period
fix display of date leak period
5 files changed, 113 insertions, 11 deletions
diff --git a/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java b/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java index 2fc05eede5b..904fb1e0fa2 100644 --- a/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java +++ b/it/it-tests/src/test/java/it/measureHistory/DifferentialPeriodsTest.java @@ -24,6 +24,7 @@ import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.selenium.Selenese; import it.Category1Suite; +import java.util.Date; import java.util.List; import org.junit.After; import org.junit.Before; @@ -33,13 +34,18 @@ import org.sonar.wsclient.services.Measure; import org.sonar.wsclient.services.Resource; import org.sonar.wsclient.services.ResourceQuery; import util.ItUtils; +import util.selenium.SeleneseTest; +import static org.apache.commons.lang.time.DateUtils.addDays; import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.formatDate; import static util.ItUtils.projectDir; import static util.ItUtils.setServerProperty; public class DifferentialPeriodsTest { + static final String PROJECT_KEY = "sample"; + @ClassRule public static final Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; @@ -65,18 +71,18 @@ public class DifferentialPeriodsTest { */ @Test public void ensure_differential_period_4_and_5_defined_at_project_level_is_taken_into_account() throws Exception { - setServerProperty(orchestrator, "sonar.timemachine.period4", "30"); - setServerProperty(orchestrator, "sonar.timemachine.period5", "previous_analysis"); + 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().provisionProject("sample", "sample"); - orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty"); + orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty"); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample")) - .setProperty("sonar.projectDate", "2013-01-01")); + .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("sample", "xoo", "one-issue-per-line"); + 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 @@ -87,7 +93,7 @@ public class DifferentialPeriodsTest { 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("sample", "xoo", "one-issue-per-line"); + orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line"); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); newTechnicalDebt = orchestrator.getServer().getWsClient().find( @@ -99,12 +105,48 @@ public class DifferentialPeriodsTest { } /** + * 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); + } + + /** * SONAR-4700 */ @Test public void not_display_periods_selection_dropdown_on_first_analysis() { - orchestrator.getServer().provisionProject("sample", "sample"); - orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty"); + orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY); + orchestrator.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "empty"); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); // Use old way to execute Selenium because 'assertSelectOptions' action is not supported by SeleneseTest diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java index b25b564479f..865790b75a5 100644 --- a/it/it-tests/src/test/java/util/ItUtils.java +++ b/it/it-tests/src/test/java/util/ItUtils.java @@ -220,10 +220,14 @@ public class ItUtils { } public static void setServerProperty(Orchestrator orchestrator, String key, @Nullable String value) { + setServerProperty(orchestrator, null, key, value); + } + + public static void setServerProperty(Orchestrator orchestrator, @Nullable String componentKey, String key, @Nullable String value) { if (value == null) { - orchestrator.getServer().getAdminWsClient().delete(new PropertyDeleteQuery(key)); + orchestrator.getServer().getAdminWsClient().delete(new PropertyDeleteQuery(key).setResourceKeyOrId(componentKey)); } else { - orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery().setKey(key).setValue(value)); + orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery().setKey(key).setResourceKeyOrId(componentKey).setValue(value)); } } @@ -267,4 +271,9 @@ public class ItUtils { } } + public static String formatDate(Date d) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + return sdf.format(d); + } + } diff --git a/it/it-tests/src/test/resources/measureHistory/DifferentialPeriodsTest/define-leak-period-on-project.html b/it/it-tests/src/test/resources/measureHistory/DifferentialPeriodsTest/define-leak-period-on-project.html new file mode 100644 index 00000000000..1d426c899f0 --- /dev/null +++ b/it/it-tests/src/test/resources/measureHistory/DifferentialPeriodsTest/define-leak-period-on-project.html @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <title>display-added-files</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> + <thead> + <tr> + <td rowspan="1" colspan="3">should_display_added_files_in_differential_drilldown</td> + </tr> + </thead> + <tbody> + <tr> + <td>open</td> + <td>/sonar/sessions/logout</td> + <td></td> +</tr> +<tr> + <td>open</td> + <td>/sonar/project/settings?id=sample&category=general&subcategory=differentialviews</td> + <td></td> +</tr> +<tr> + <td>type</td> + <td>id=login</td> + <td>admin</td> +</tr> +<tr> + <td>type</td> + <td>id=password</td> + <td>admin</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>name=commit</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>properties</td> + <td>*Leak Period*</td> +</tr> +</tbody> +</table> +</body> +</html> diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index d6000bff228..b21d43a3c47 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -237,6 +237,7 @@ public class CorePropertyDefinitions { .defaultValue(TIMEMACHINE_DEFAULT_PERIOD_1) .category(CoreProperties.CATEGORY_GENERAL) .subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) + .onQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW) .build(), PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 2) diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 86e4eac69e7..fc841d7e677 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3125,6 +3125,7 @@ overview.period.previous_version_only_date=since previous version overview.period.previous_analysis=since previous analysis overview.period.days=last {0} days overview.period.version=since {0} +overview.period.date=since {0} overview.gate.ERROR=Failed overview.gate.WARN=Warning |