import org.sonar.server.computation.issue.SourceLinesCache;
import org.sonar.server.computation.language.PlatformLanguageRepository;
import org.sonar.server.computation.measure.MeasureRepositoryImpl;
-import org.sonar.server.computation.measure.MetricCache;
import org.sonar.server.computation.metric.MetricRepositoryImpl;
import org.sonar.server.computation.period.PeriodsHolderImpl;
import org.sonar.server.computation.qualitygate.QualityGateHolderImpl;
RuleCache.class,
RuleCacheLoader.class,
IssueCache.class,
- MetricCache.class,
UpdateConflictResolver.class,
// views
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.computation.measure;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Maps;
-import org.sonar.core.metric.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.NotFoundException;
-
-import java.util.List;
-import java.util.Map;
-
-public class MetricCache {
- private final Map<String, MetricDto> metrics;
-
- public MetricCache(DbClient dbClient) {
- DbSession dbSession = dbClient.openSession(false);
- try {
- List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession);
- this.metrics = Maps.uniqueIndex(metricList, new Function<MetricDto, String>() {
- @Override
- public String apply(MetricDto metric) {
- return metric.getKey();
- }
- });
- } finally {
- MyBatis.closeQuietly(dbSession);
- }
- }
-
- public MetricDto get(String key) {
- MetricDto metric = metrics.get(key);
- if (metric == null) {
- throw new NotFoundException(String.format("Not found: '%s'", key));
- }
-
- return metric;
- }
-}
import org.sonar.server.computation.component.DbIdsRepository;
import org.sonar.server.computation.component.DepthTraversalTypeAwareVisitor;
import org.sonar.server.computation.component.TreeRootHolder;
-import org.sonar.server.computation.measure.MetricCache;
+import org.sonar.server.computation.metric.MetricRepository;
import org.sonar.server.db.DbClient;
import org.sonar.server.source.index.SourceLineIndex;
private final DbClient dbClient;
private final SourceLineIndex sourceLineIndex;
- private final MetricCache metricCache;
+ private final MetricRepository metricRepository;
private final System2 system;
private final TreeRootHolder treeRootHolder;
private final BatchReportReader reportReader;
private final DbIdsRepository dbIdsRepository;
- public PersistNumberOfDaysSinceLastCommitStep(System2 system, DbClient dbClient, SourceLineIndex sourceLineIndex, MetricCache metricCache,
+ public PersistNumberOfDaysSinceLastCommitStep(System2 system, DbClient dbClient, SourceLineIndex sourceLineIndex, MetricRepository metricRepository,
TreeRootHolder treeRootHolder, BatchReportReader reportReader, DbIdsRepository dbIdsRepository) {
this.dbClient = dbClient;
this.sourceLineIndex = sourceLineIndex;
- this.metricCache = metricCache;
+ this.metricRepository = metricRepository;
this.system = system;
this.treeRootHolder = treeRootHolder;
this.reportReader = reportReader;
try {
dbClient.measureDao().insert(dbSession, new MeasureDto()
.setValue((double) numberOfDaysSinceLastCommit)
- .setMetricId(metricCache.get(CoreMetrics.DAYS_SINCE_LAST_COMMIT_KEY).getId())
+ .setMetricId(metricRepository.getByKey(CoreMetrics.DAYS_SINCE_LAST_COMMIT_KEY).getId())
.setSnapshotId(projectSnapshotId));
dbSession.commit();
} finally {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.server.computation.measure;
-
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.metric.persistence.MetricDao;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MetricCacheTest {
-
- @ClassRule
- public static DbTester db = new DbTester();
-
- MetricCache sut;
-
- @Before
- public void setUp() {
- db.prepareDbUnit(getClass(), "metrics.xml");
- sut = new MetricCache(new DbClient(db.database(), db.myBatis(), new MetricDao()));
- }
-
- @Test
- public void cache_give_access_to_enabled_metrics() {
- assertThat(sut.get("ncloc").getId()).isEqualTo(1);
- assertThat(sut.get("coverage").getId()).isEqualTo(2);
- }
-
- @Test(expected = NotFoundException.class)
- public void fail_when_metric_not_found() {
- sut.get("complexity");
- }
-}
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.core.metric.db.MetricDto;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.batch.BatchReportReaderRule;
import org.sonar.server.computation.batch.TreeRootHolderRule;
import org.sonar.server.computation.component.DbIdsRepository;
import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.computation.language.LanguageRepository;
-import org.sonar.server.computation.measure.MetricCache;
+import org.sonar.server.computation.metric.Metric;
+import org.sonar.server.computation.metric.MetricImpl;
+import org.sonar.server.computation.metric.MetricRepository;
import org.sonar.server.db.DbClient;
import org.sonar.server.measure.persistence.MeasureDao;
import org.sonar.server.source.index.SourceLineIndex;
DbClient dbClient;
SourceLineIndex sourceLineIndex;
- MetricCache metricCache;
+ MetricRepository metricRepository;
Settings projectSettings;
LanguageRepository languageRepository;
db.truncateTables();
dbClient = new DbClient(db.database(), db.myBatis(), new MeasureDao());
sourceLineIndex = mock(SourceLineIndex.class);
- metricCache = mock(MetricCache.class);
+ metricRepository = mock(MetricRepository.class);
projectSettings = new Settings();
languageRepository = mock(LanguageRepository.class);
- when(metricCache.get(anyString())).thenReturn(new MetricDto().setId(10));
+ when(metricRepository.getByKey(anyString())).thenReturn(new MetricImpl(10, "key", "name", Metric.MetricType.STRING));
- sut = new PersistNumberOfDaysSinceLastCommitStep(System2.INSTANCE, dbClient, sourceLineIndex, metricCache, treeRootHolder, reportReader, dbIdsRepository);
+ sut = new PersistNumberOfDaysSinceLastCommitStep(System2.INSTANCE, dbClient, sourceLineIndex, metricRepository, treeRootHolder, reportReader, dbIdsRepository);
}
@Override