-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-18872 improve total ncloc computation
- Loading branch information
1 parent
3758946
commit 4114d41
Showing
23 changed files
with
593 additions
and
76 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...sis/src/main/java/org/sonar/ce/task/projectanalysis/step/ProjectNclocComputationStep.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,51 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT 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 02110-1301, USA. | ||
*/ | ||
package org.sonar.ce.task.projectanalysis.step; | ||
|
||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; | ||
import org.sonar.ce.task.step.ComputationStep; | ||
import org.sonar.db.DbClient; | ||
import org.sonar.db.DbSession; | ||
|
||
public class ProjectNclocComputationStep implements ComputationStep { | ||
|
||
private final AnalysisMetadataHolder analysisMetadataHolder; | ||
private final DbClient dbClient; | ||
|
||
public ProjectNclocComputationStep(AnalysisMetadataHolder analysisMetadataHolder, DbClient dbClient) { | ||
this.analysisMetadataHolder = analysisMetadataHolder; | ||
this.dbClient = dbClient; | ||
} | ||
|
||
@Override | ||
public void execute(Context context) { | ||
try (DbSession dbSession = dbClient.openSession(false)) { | ||
String projectUuid = analysisMetadataHolder.getProject().getUuid(); | ||
long maxncloc = dbClient.liveMeasureDao().sumNclocOfBiggestBranchForProject(dbSession, projectUuid); | ||
dbClient.projectDao().updateNcloc(dbSession, projectUuid, maxncloc); | ||
dbSession.commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Compute total Project ncloc"; | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...s/src/test/java/org/sonar/ce/task/projectanalysis/step/ProjectNclocComputationStepIT.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,65 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT 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 02110-1301, USA. | ||
*/ | ||
package org.sonar.ce.task.projectanalysis.step; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | ||
import org.sonar.ce.task.step.TestComputationStepContext; | ||
import org.sonar.db.DbClient; | ||
import org.sonar.db.DbTester; | ||
import org.sonar.db.component.BranchType; | ||
import org.sonar.db.component.ComponentDto; | ||
import org.sonar.db.metric.MetricDto; | ||
import org.sonar.server.project.Project; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.sonar.api.measures.Metric.ValueType.INT; | ||
|
||
public class ProjectNclocComputationStepIT { | ||
@Rule | ||
public DbTester db = DbTester.create(); | ||
private final DbClient dbClient = db.getDbClient(); | ||
|
||
@Rule | ||
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); | ||
|
||
private final ProjectNclocComputationStep step = new ProjectNclocComputationStep(analysisMetadataHolder, dbClient); | ||
|
||
@Test | ||
public void test_computing_branch_ncloc() { | ||
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); | ||
ComponentDto project = db.components().insertPublicProject(); | ||
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)); | ||
db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(200d)); | ||
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)); | ||
db.measures().insertLiveMeasure(branch2, ncloc, m -> m.setValue(10d)); | ||
analysisMetadataHolder.setProject(new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList())); | ||
step.execute(TestComputationStepContext.TestStatistics::new); | ||
|
||
assertThat(dbClient.projectDao().getNclocSum(db.getSession())).isEqualTo(200L); | ||
} | ||
|
||
@Test | ||
public void description_is_not_missing() { | ||
assertThat(step.getDescription()).isNotBlank(); | ||
} | ||
} |
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
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
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
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
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.