public SumNclocDbQuery build() { checkNotNull(organizationUuid); checkNotNull(onlyPrivateProjects); return new SumNclocDbQuery(this); } }
/** * Example: * If Main Branch = 0 LOCs (provisioned but never analyzed) and the "largest long-lived branch" is 120 LOCs, I'm expecting to consider the value 120. * If Main Branch = 100 LOCs and the "largest long-lived branch" is 120 LOCs, I'm expecting to consider the value 120. * If Main Branch = 100 LOCs and the "largest long-lived branch" is 80 LOCs, I'm expecting to consider the value 100. */ public long sumNclocOfBiggestLongLivingBranch(DbSession dbSession, SumNclocDbQuery dbQuery) { Long ncloc = mapper(dbSession).sumNclocOfBiggestLongLivingBranch( NCLOC_KEY, KeyType.BRANCH, BranchType.LONG, dbQuery.getOrganizationUuid(), dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude()); return ncloc == null ? 0L : ncloc; }
private long computeNcloc() { try (DbSession dbSession = dbClient.openSession(false)) { SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) .setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) .build(); return dbClient.liveMeasureDao().sumNclocOfBiggestLongLivingBranch(dbSession, query); } } }
public TelemetryData load() { TelemetryData.Builder data = TelemetryData.builder(); data.setServerId(server.getId()); data.setVersion(server.getVersion()); data.setEdition(editionProvider.get()); ofNullable(licenseReader) .flatMap(reader -> licenseReader.read()) .ifPresent(license -> data.setLicenseType(license.getType())); Function<PluginInfo, String> getVersion = plugin -> plugin.getVersion() == null ? "undefined" : plugin.getVersion().getName(); Map<String, String> plugins = pluginRepository.getPluginInfos().stream().collect(MoreCollectors.uniqueIndex(PluginInfo::getKey, getVersion)); data.setPlugins(plugins); long userCount = userIndex.search(UserQuery.builder().build(), new SearchOptions().setLimit(1)).getTotal(); data.setUserCount(userCount); ProjectMeasuresStatistics projectMeasuresStatistics = projectMeasuresIndex.searchTelemetryStatistics(); data.setProjectMeasuresStatistics(projectMeasuresStatistics); try (DbSession dbSession = dbClient.openSession(false)) { data.setDatabase(loadDatabaseMetadata(dbSession)); data.setUsingBranches(dbClient.branchDao().hasNonMainBranches(dbSession)); SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) .setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) .build(); data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestLongLivingBranch(dbSession, query)); } return data.build(); }
@Test public void countNcloc_empty() { db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString())); SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) .setOrganizationUuid(db.getDefaultOrganization().getUuid()) .build(); long result = underTest.sumNclocOfBiggestLongLivingBranch(db.getSession(), query); assertThat(result).isEqualTo(0L); }
@Test public void countNcloc() { OrganizationDto organization = db.organizations().insert(); MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString())); ComponentDto simpleProject = db.components().insertMainBranch(organization); db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); ComponentDto projectWithBiggerLongLivingBranch = db.components().insertMainBranch(organization); ComponentDto bigLongLivingLongBranch = db.components().insertProjectBranch(projectWithBiggerLongLivingBranch, b -> b.setBranchType(BranchType.LONG)); db.measures().insertLiveMeasure(projectWithBiggerLongLivingBranch, ncloc, m -> m.setValue(100d)); db.measures().insertLiveMeasure(bigLongLivingLongBranch, ncloc, m -> m.setValue(200d)); ComponentDto projectWithLinesButNoLoc = db.components().insertMainBranch(organization); db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d)); db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d)); SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) .setOrganizationUuid(organization.getUuid()) .build(); long result = underTest.sumNclocOfBiggestLongLivingBranch(db.getSession(), query); assertThat(result).isEqualTo(10L + 200L); }
@Test public void countNcloc_and_exclude_project() { OrganizationDto organization = db.organizations().insert(); MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); ComponentDto simpleProject = db.components().insertMainBranch(organization); db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); ComponentDto projectWithBiggerLongLivingBranch = db.components().insertMainBranch(organization); ComponentDto bigLongLivingBranch = db.components().insertProjectBranch(projectWithBiggerLongLivingBranch, b -> b.setBranchType(BranchType.LONG)); db.measures().insertLiveMeasure(projectWithBiggerLongLivingBranch, ncloc, m -> m.setValue(100d)); db.measures().insertLiveMeasure(bigLongLivingBranch, ncloc, m -> m.setValue(200d)); ComponentDto projectToExclude = db.components().insertMainBranch(organization); ComponentDto projectToExcludeBranch = db.components().insertProjectBranch(projectToExclude, b -> b.setBranchType(BranchType.LONG)); db.measures().insertLiveMeasure(projectToExclude, ncloc, m -> m.setValue(300d)); db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d)); SumNclocDbQuery query = SumNclocDbQuery.builder() .setOrganizationUuid(organization.getUuid()) .setProjectUuidToExclude(projectToExclude.uuid()) .setOnlyPrivateProjects(false) .build(); long result = underTest.sumNclocOfBiggestLongLivingBranch(db.getSession(), query); assertThat(result).isEqualTo(10L + 200L); }