forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-5876 add SqaleNewMeasuresVisitor to compute new_sqale_debt_ratio
- Loading branch information
Showing
19 changed files
with
931 additions
and
29 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
it/it-projects/measure/xoo-new-debt-ratio-v1/sonar-project.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sonar.projectKey=sample | ||
sonar.projectName=Sample | ||
sonar.projectVersion=1.0-SNAPSHOT | ||
sonar.sources=src/main/xoo | ||
sonar.language=xoo | ||
sonar.scm.provider=xoo |
13 changes: 13 additions & 0 deletions
13
it/it-projects/measure/xoo-new-debt-ratio-v1/src/main/xoo/sample/Sample.xoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package sample; | ||
|
||
// class comment | ||
public class Sample { | ||
|
||
public Sample(int i) { | ||
int j = i++; | ||
} | ||
|
||
private String method1() { | ||
return "hello"; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
it/it-projects/measure/xoo-new-debt-ratio-v1/src/main/xoo/sample/Sample.xoo.measures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ncloc:9 | ||
comment_lines:5 | ||
ncloc_data:1=1;2=0;3=0;4=1;5=0;6=1;7=1;8=1;9=0;10=1;11=1;12=1;13=1;14=0 | ||
classes:1 |
14 changes: 14 additions & 0 deletions
14
it/it-projects/measure/xoo-new-debt-ratio-v1/src/main/xoo/sample/Sample.xoo.scm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 | ||
1,user1,2015-08-01 |
6 changes: 6 additions & 0 deletions
6
it/it-projects/measure/xoo-new-debt-ratio-v2/sonar-project.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sonar.projectKey=sample | ||
sonar.projectName=Sample | ||
sonar.projectVersion=1.0-SNAPSHOT | ||
sonar.sources=src/main/xoo | ||
sonar.language=xoo | ||
sonar.scm.provider=xoo |
17 changes: 17 additions & 0 deletions
17
it/it-projects/measure/xoo-new-debt-ratio-v2/src/main/xoo/sample/Sample.xoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package sample; | ||
|
||
// class comment | ||
public class Sample { | ||
|
||
public Sample(int i) { | ||
int j = i++; | ||
} | ||
|
||
private String method1() { | ||
return "hello"; | ||
} | ||
|
||
private String method2() { | ||
return "hello2"; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
it/it-projects/measure/xoo-new-debt-ratio-v2/src/main/xoo/sample/Sample.xoo.measures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ncloc:12 | ||
comment_lines:6 | ||
ncloc_data:1=1;2=0;3=0;4=1;5=0;6=1;7=1;8=1;9=0;10=1;11=1;12=1;13=0;14=1;15=1;16=1;17=1;18=0 | ||
classes:1 |
18 changes: 18 additions & 0 deletions
18
it/it-projects/measure/xoo-new-debt-ratio-v2/src/main/xoo/sample/Sample.xoo.scm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
2,user2,2015-09-17 | ||
2,user2,2015-09-17 | ||
2,user2,2015-09-17 | ||
2,user2,2015-09-17 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 |
6 changes: 6 additions & 0 deletions
6
it/it-projects/measure/xoo-new-debt-ratio-v3/sonar-project.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sonar.projectKey=sample | ||
sonar.projectName=Sample | ||
sonar.projectVersion=1.0-SNAPSHOT | ||
sonar.sources=src/main/xoo | ||
sonar.language=xoo | ||
sonar.scm.provider=xoo |
22 changes: 22 additions & 0 deletions
22
it/it-projects/measure/xoo-new-debt-ratio-v3/src/main/xoo/sample/Sample.xoo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sample; | ||
|
||
// class comment | ||
public class Sample { | ||
|
||
public Sample(int i) { | ||
int j = i++; | ||
} | ||
|
||
private String method1() { | ||
return "hello"; | ||
} | ||
|
||
private String method2() { | ||
return "hello2"; | ||
} | ||
|
||
private String method3() { | ||
String e = "hello3"; | ||
return e; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
it/it-projects/measure/xoo-new-debt-ratio-v3/src/main/xoo/sample/Sample.xoo.measures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ncloc:16 | ||
comment_lines:7 | ||
ncloc_data:1=1;2=0;3=0;4=1;5=0;6=1;7=1;8=1;9=0;10=1;11=1;12=1;13=0;14=1;15=1;16=1;17=0;18=1;19=1;20=1;21=1;22=1;23=0 | ||
classes:1 |
23 changes: 23 additions & 0 deletions
23
it/it-projects/measure/xoo-new-debt-ratio-v3/src/main/xoo/sample/Sample.xoo.scm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 | ||
2,user2,2015-09-17 | ||
2,user2,2015-09-17 | ||
2,user2,2015-09-17 | ||
2,user2,2015-09-17 | ||
3,user2,2015-09-20 | ||
3,user2,2015-09-20 | ||
3,user2,2015-09-20 | ||
3,user2,2015-09-20 | ||
3,user2,2015-09-20 | ||
1,user1,2015-09-01 | ||
1,user1,2015-09-01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
it/it-tests/src/test/java/analysis/suite/measure/NewDebtRatioMeasureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package analysis.suite.measure; | ||
|
||
import analysis.suite.AnalysisTestSuite; | ||
import com.sonar.orchestrator.Orchestrator; | ||
import com.sonar.orchestrator.locator.FileLocation; | ||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.sonar.wsclient.services.Measure; | ||
import org.sonar.wsclient.services.Resource; | ||
import org.sonar.wsclient.services.ResourceQuery; | ||
import util.ItUtils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.within; | ||
|
||
/** | ||
* SONAR-5876 | ||
*/ | ||
public class NewDebtRatioMeasureTest { | ||
|
||
private static final String NEW_DEBT_RATIO_METRIC_KEY = "new_sqale_debt_ratio"; | ||
|
||
@ClassRule | ||
public static Orchestrator orchestrator = AnalysisTestSuite.ORCHESTRATOR; | ||
|
||
@Before | ||
public void cleanUpAnalysisData() { | ||
orchestrator.resetData(); | ||
} | ||
|
||
@Test | ||
public void new_debt_ratio_is_computed_from_nes_debt_and_new_ncloc_count_per_file() throws Exception { | ||
// This test assumes that period 1 is "since previous analysis" and 2 is "over 30 days" | ||
|
||
// run analysis on the day of after the first commit (2015-09-01), with 'one-issue-per-line' profile | ||
// => some issues at date 2015-09-02 | ||
defineQualityProfile("one-issue-per-line"); | ||
provisionSampleProject(); | ||
setSampleProjectQualityProfile("one-issue-per-line"); | ||
runSampleProjectAnalysis("v1", "sonar.projectDate", "2015-09-02"); | ||
|
||
// first analysis, no previous snapshot => periods not resolved => no value | ||
assertNoNewDebtRatio(); | ||
|
||
// run analysis on the day after of second commit (2015-09-17) 'one-issue-per-line' profile* | ||
// => 3 new issues will be created at date 2015-09-18 | ||
runSampleProjectAnalysis("v2", "sonar.projectDate", "2015-09-18"); | ||
assertNewDebtRatio(4.44, 4.44); | ||
|
||
// run analysis on the day after of third commit (2015-09-20) 'one-issue-per-line' profile* | ||
// => 4 new issues will be created at date 2015-09-21 | ||
runSampleProjectAnalysis("v3", "sonar.projectDate", "2015-09-21"); | ||
assertNewDebtRatio(4.17, 4.28); | ||
} | ||
|
||
private void assertNoNewDebtRatio() { | ||
assertThat(getFileResourceWithVariations(NEW_DEBT_RATIO_METRIC_KEY)).isNull(); | ||
} | ||
|
||
private void assertNewDebtRatio(@Nullable Double valuePeriod1, @Nullable Double valuePeriod2) { | ||
Resource newTechnicalDebt = getFileResourceWithVariations(NEW_DEBT_RATIO_METRIC_KEY); | ||
List<Measure> measures = newTechnicalDebt.getMeasures(); | ||
assertThat(measures.get(0).getVariation1()).isEqualTo(valuePeriod1, within(0.01)); | ||
assertThat(measures.get(0).getVariation2()).isEqualTo(valuePeriod2, within(0.01)); | ||
} | ||
|
||
private void setSampleProjectQualityProfile(String qualityProfileKey) { | ||
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", qualityProfileKey); | ||
} | ||
|
||
private void provisionSampleProject() { | ||
orchestrator.getServer().provisionProject("sample", "sample"); | ||
} | ||
|
||
private void defineQualityProfile(String qualityProfileKey) { | ||
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/measure/suite/" + qualityProfileKey + ".xml")); | ||
} | ||
|
||
private void runSampleProjectAnalysis(String projectVersion, String... properties) { | ||
ItUtils.runProjectAnalysis( | ||
NewDebtRatioMeasureTest.orchestrator, | ||
"measure/xoo-new-debt-ratio-" + projectVersion, | ||
ItUtils.concat(properties, | ||
// disable standard scm support so that it does not interfere with Xoo Scm sensor | ||
"sonar.scm.disabled", "false") | ||
); | ||
} | ||
|
||
private Resource getFileResourceWithVariations(String metricKey) { | ||
return orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("sample:src/main/xoo/sample/Sample.xoo", metricKey).setIncludeTrends(true)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.