From 2fdbed4ea7e5db4621bc387dfba9af3121eecef2 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 6 Jul 2016 10:41:58 +0200 Subject: [PATCH] SONAR-7705 stop using SNAPSHOTS tree columns in Java codebase --- .../component/CrawlerDepthLimit.java | 1 + .../component/DbIdsRepository.java | 5 - .../component/DbIdsRepositoryImpl.java | 10 - .../component/MapBasedDbIdsRepository.java | 19 -- .../component/MutableDbIdsRepository.java | 5 - .../measure/MeasureToMeasureDto.java | 1 - .../step/PersistSnapshotsStep.java | 99 +------ .../step/ReportComputationSteps.java | 2 +- .../computation/step/SwitchSnapshotStep.java | 84 ------ .../computation/step/ValidateProjectStep.java | 6 +- .../sonar/server/issue/IssueQueryService.java | 10 +- .../server/measure/MeasureFilterSql.java | 1 - .../measure/custom/ws/SearchAction.java | 9 +- .../server/measure/ws/ComponentAction.java | 2 +- .../measure/ws/ComponentTreeDataLoader.java | 6 +- .../ws/SearchMyProjectsDataLoader.java | 4 +- .../qualitygate/ws/ProjectStatusAction.java | 4 +- .../ui/ws/ComponentNavigationAction.java | 29 +-- .../server/component/ws/ShowActionTest.java | 12 +- .../server/component/ws/TreeActionTest.java | 71 +++-- .../component/DbIdsRepositoryImplTest.java | 33 +-- .../component/MutableDbIdsRepositoryRule.java | 15 -- .../measure/MeasureToMeasureDtoTest.java | 2 - ...ProjectDuplicationsRepositoryStepTest.java | 28 +- .../step/PersistMeasuresStepTest.java | 15 +- .../step/ReportPersistSnapshotsStepTest.java | 160 +----------- .../step/SwitchSnapshotStepTest.java | 70 ----- ...ViewsComputeMeasureVariationsStepTest.java | 5 +- .../step/ViewsPersistSnapshotsStepTest.java | 90 ++----- .../IssueBulkChangeServiceMediumTest.java | 2 +- .../issue/IssueCommentServiceMediumTest.java | 2 +- .../ws/SearchActionComponentsMediumTest.java | 7 +- .../measure/ws/ComponentActionTest.java | 47 ++-- .../measure/ws/ComponentTreeActionTest.java | 242 +++++++++--------- .../measure/ws/MeasureDtoToWsMeasureTest.java | 5 +- .../ws/SearchMyProjectsActionTest.java | 28 +- .../ws/ProjectStatusActionTest.java | 6 +- .../ui/ws/ComponentNavigationActionTest.java | 33 ++- .../activity/ActivityManagerTest/shared.xml | 8 +- .../MeasureRepositoryImplTest/shared.xml | 2 - .../shared.xml | 2 +- .../no_previous_version.xml | 40 +-- .../previous_version_deleted.xml | 24 +- .../previous_version_is_last_one.xml | 8 +- .../step/LoadPeriodsStepTest/shared.xml | 40 +-- .../unprocessed_snapshots.xml | 8 +- .../snapshots-result.xml | 30 +-- .../step/SwitchSnapshotStepTest/snapshots.xml | 30 +-- .../filters/FilterExecutorTest/views.xml | 8 +- .../load_component_id_from_db.xml | 2 - .../load_project_id_from_db.xml | 6 - .../should_insert_new_issues.xml | 2 - .../should_update_issues-result.xml | 23 +- .../should_update_issues.xml | 2 - ...e_when_filter_by_component_name_or_key.xml | 7 - .../ignore_person_measures.xml | 7 - .../ignore_quality_model_measures.xml | 7 - .../MeasureFilterExecutorTest/shared.xml | 111 -------- .../sort_by_alert.xml | 21 -- .../BackendCleanupMediumTest/shared.xml | 8 +- .../on_module.json | 5 + .../view/index/ViewIndexerTest/index.xml | 72 +----- .../org/sonar/db/component/SnapshotDao.java | 35 +-- .../org/sonar/db/component/SnapshotDto.java | 85 ------ .../sonar/db/component/SnapshotMapper.java | 19 +- .../org/sonar/db/component/SnapshotQuery.java | 22 -- .../java/org/sonar/db/measure/MeasureDto.java | 5 - .../org/sonar/db/measure/MeasureQuery.java | 21 +- .../org/sonar/db/purge/PurgeCommands.java | 9 +- .../java/org/sonar/db/purge/PurgeDao.java | 18 +- .../java/org/sonar/db/purge/PurgeMapper.java | 7 +- .../sonar/db/purge/PurgeSnapshotQuery.java | 31 +-- .../v60/PopulateUuidPathColumnOnProjects.java | 2 +- .../db/component/ResourceIndexMapper.xml | 16 +- .../org/sonar/db/component/ResourceMapper.xml | 7 - .../org/sonar/db/component/SnapshotMapper.xml | 84 ++---- .../org/sonar/db/measure/MeasureMapper.xml | 13 +- .../org/sonar/db/purge/PurgeMapper.xml | 38 +-- .../sonar/db/component/ComponentDaoTest.java | 68 ++--- .../sonar/db/component/ComponentDbTester.java | 15 +- .../db/component/ResourceIndexDaoTest.java | 13 +- .../sonar/db/component/SnapshotDaoTest.java | 101 ++------ .../sonar/db/component/SnapshotDtoTest.java | 31 --- .../sonar/db/component/SnapshotTesting.java | 45 +--- .../org/sonar/db/measure/MeasureTesting.java | 8 +- .../org/sonar/db/purge/PurgeCommandsTest.java | 2 +- .../java/org/sonar/db/purge/PurgeDaoTest.java | 3 + .../ComponentDaoTest/multi-modules.xml | 36 +-- .../select_ghost_projects.xml | 48 +--- .../select_provisioned_projects.xml | 40 +-- .../db/component/ComponentDaoTest/shared.xml | 40 +-- ...g-ghost-projects-and-technical-project.xml | 64 +---- .../db/component/ResourceDaoTest/fixture.xml | 110 +------- .../getResources_exclude_disabled.xml | 40 ++- .../get_last_snapshot_by_component_uuid.xml | 14 +- .../ResourceDaoTest/insert-result.xml | 48 +++- .../ResourceDaoTest/update-result.xml | 24 +- .../db/component/ResourceDaoTest/update.xml | 22 +- .../shouldIndexMultiModulesProject-result.xml | 2 - .../shouldIndexMultiModulesProject.xml | 4 - .../shouldIndexProjects-result.xml | 22 +- .../shouldIndexProjects.xml | 15 +- .../shouldNotIndexPackages.xml | 12 +- ...shouldReIndexNewTwoLettersLongResource.xml | 4 +- .../shouldReIndexTwoLettersLongResource.xml | 4 +- ...ouldReindexProjectAfterRenaming-result.xml | 5 +- .../shouldReindexProjectAfterRenaming.xml | 4 +- .../has_last_snapshot_by_component_uuid.xml | 157 ------------ .../SnapshotDaoTest/insert-result.xml | 8 +- .../db/component/SnapshotDaoTest/modules.xml | 219 +++++++++------- .../select_previous_version_snapshots.xml | 32 +-- .../select_snapshots_by_query.xml | 48 +--- .../db/component/SnapshotDaoTest/shared.xml | 8 +- .../component/SnapshotDaoTest/snapshots.xml | 190 ++++++++++---- .../DuplicationDaoTest/insert-result.xml | 4 +- .../duplication/DuplicationDaoTest/insert.xml | 4 +- .../DuplicationDaoTest/select_candidates.xml | 22 +- .../sonar/db/issue/IssueDaoTest/shared.xml | 16 -- .../measure/MeasureDaoTest/past_measures.xml | 39 +-- .../past_measures_with_person_id.xml | 8 +- .../select_by_snapshot_and_metric_keys.xml | 1 - .../db/measure/MeasureDaoTest/shared.xml | 1 - .../with_some_measures_for_developer.xml | 2 +- .../shouldDeleteResource.xml | 10 +- .../shouldDeleteSnapshot-result.xml | 8 +- .../shouldDeleteSnapshot.xml | 16 +- ...stedMeasuresWhenPurgingAnalysis-result.xml | 9 +- ...eleteWastedMeasuresWhenPurgingAnalysis.xml | 8 +- .../shouldPurgeAnalysis-result.xml | 16 +- .../PurgeCommandsTest/shouldPurgeAnalysis.xml | 16 +- ...ete_file_sources_of_disabled_resources.xml | 105 +------- ...resources_without_last_snapshot-result.xml | 73 +----- ...isable_resources_without_last_snapshot.xml | 73 +----- .../shouldDeleteAbortedBuilds-result.xml | 16 +- .../shouldDeleteAbortedBuilds.xml | 24 +- .../shouldDeleteAnalyses-result.xml | 16 +- .../PurgeDaoTest/shouldDeleteAnalyses.xml | 24 +- ...oricalDataOfDirectoriesAndFiles-result.xml | 81 +----- ...eteHistoricalDataOfDirectoriesAndFiles.xml | 146 +---------- .../PurgeDaoTest/shouldDeleteProject.xml | 104 +------- .../shouldPurgeProject-result.xml | 24 +- .../purge/PurgeDaoTest/shouldPurgeProject.xml | 24 +- .../shouldSelectPurgeableAnalysis.xml | 40 +-- ...should_delete_all_closed_issues-result.xml | 9 +- .../should_delete_all_closed_issues.xml | 8 +- ...should_delete_old_closed_issues-result.xml | 8 +- .../should_delete_old_closed_issues.xml | 8 +- 147 files changed, 1049 insertions(+), 3475 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java delete mode 100644 sonar-db/src/test/resources/org/sonar/db/component/SnapshotDaoTest/has_last_snapshot_by_component_uuid.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/CrawlerDepthLimit.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/CrawlerDepthLimit.java index aa00f849e9f..d16b30ca0c0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/CrawlerDepthLimit.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/CrawlerDepthLimit.java @@ -46,6 +46,7 @@ public class CrawlerDepthLimit { public static final CrawlerDepthLimit SUBVIEW = new CrawlerDepthLimit(null, Component.Type.SUBVIEW); public static final CrawlerDepthLimit PROJECT_VIEW = new CrawlerDepthLimit(null, Component.Type.PROJECT_VIEW); public static final CrawlerDepthLimit LEAVES = new CrawlerDepthLimit(Component.Type.FILE, Component.Type.PROJECT_VIEW); + public static final CrawlerDepthLimit ROOTS = new CrawlerDepthLimit(Component.Type.PROJECT, Component.Type.VIEW); @CheckForNull private final Component.Type reportMaxDepth; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepository.java index 4d0a091c6a5..582258b4f0f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepository.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepository.java @@ -25,11 +25,6 @@ public interface DbIdsRepository { */ long getComponentId(Component component); - /** - * @throws IllegalStateException if there is no Snapshot id for the specified Component - */ - long getSnapshotId(Component component); - /** * @throws IllegalStateException if there is no id for the specified Developer */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepositoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepositoryImpl.java index d4e49820ec5..6c22907bfeb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepositoryImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/DbIdsRepositoryImpl.java @@ -38,16 +38,6 @@ public class DbIdsRepositoryImpl implements MutableDbIdsRepository { return delegate.getComponentId(component); } - @Override - public DbIdsRepository setSnapshotId(Component component, long snapshotId) { - return delegate.setSnapshotId(component, snapshotId); - } - - @Override - public long getSnapshotId(Component component) { - return delegate.getSnapshotId(component); - } - @Override public DbIdsRepository setDeveloperId(Developer developer, long developerId) { return delegate.setDeveloperId(developer, developerId); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/MapBasedDbIdsRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/MapBasedDbIdsRepository.java index 4443c32689b..dcc3a2e7788 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/MapBasedDbIdsRepository.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/MapBasedDbIdsRepository.java @@ -36,7 +36,6 @@ public final class MapBasedDbIdsRepository implements MutableDbIdsRepository private final Function componentToKey; private final Map componentIdsByRef = new HashMap<>(); - private final Map snapshotIdsByRef = new HashMap<>(); private final Map developerIdsByKey = new HashMap<>(); public MapBasedDbIdsRepository(Function componentToKey) { @@ -61,24 +60,6 @@ public final class MapBasedDbIdsRepository implements MutableDbIdsRepository return componentId; } - @Override - public DbIdsRepository setSnapshotId(Component component, long snapshotId) { - T ref = componentToKey.apply(component); - Long existingSnapshotId = snapshotIdsByRef.get(ref); - checkState(existingSnapshotId == null, - format("Snapshot id '%s' is already registered in repository for Component '%s', can not set new id '%s'", existingSnapshotId, component.getKey(), snapshotId)); - snapshotIdsByRef.put(ref, snapshotId); - return this; - } - - @Override - public long getSnapshotId(Component component) { - T ref = componentToKey.apply(component); - Long snapshotId = snapshotIdsByRef.get(ref); - checkState(snapshotId != null, format("No snapshot id registered in repository for Component '%s'", component.getKey())); - return snapshotId; - } - @Override public DbIdsRepository setDeveloperId(Developer developer, long developerId) { Long existingId = developerIdsByKey.get(developer); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/MutableDbIdsRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/MutableDbIdsRepository.java index 85226093112..0bd4eb19f32 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/MutableDbIdsRepository.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/MutableDbIdsRepository.java @@ -25,11 +25,6 @@ public interface MutableDbIdsRepository extends DbIdsRepository { */ DbIdsRepository setComponentId(Component component, long componentId); - /** - * @throws IllegalStateException if the snapshot id for the specified component has already been set - */ - DbIdsRepository setSnapshotId(Component component, long snapshotId); - /** * @throws IllegalStateException if the id for the specified developer has already been set */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java index 718b3e02c87..500ba0e6151 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MeasureToMeasureDto.java @@ -44,7 +44,6 @@ public class MeasureToMeasureDto { out.setMetricId(metric.getId()); out.setComponentUuid(component.getUuid()); out.setAnalysisUuid(analysisMetadataHolder.getUuid()); - out.setSnapshotId(dbIdsRepository.getSnapshotId(component)); if (measure.hasVariations()) { setVariations(out, measure.getVariations()); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java index 5bd0b00489d..b1413e57c1f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSnapshotsStep.java @@ -21,8 +21,6 @@ package org.sonar.server.computation.step; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; @@ -32,7 +30,6 @@ import org.sonar.server.computation.analysis.AnalysisMetadataHolder; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.CrawlerDepthLimit; import org.sonar.server.computation.component.DbIdsRepositoryImpl; -import org.sonar.server.computation.component.MutableDbIdsRepository; import org.sonar.server.computation.component.PathAwareCrawler; import org.sonar.server.computation.component.PathAwareVisitorAdapter; import org.sonar.server.computation.component.TreeRootHolder; @@ -49,16 +46,14 @@ public class PersistSnapshotsStep implements ComputationStep { private final DbClient dbClient; private final TreeRootHolder treeRootHolder; private final AnalysisMetadataHolder analysisMetadataHolder; - private final MutableDbIdsRepository dbIdsRepository; private final PeriodsHolder periodsHolder; public PersistSnapshotsStep(System2 system2, DbClient dbClient, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder, - MutableDbIdsRepository dbIdsRepository, PeriodsHolder periodsHolder) { + PeriodsHolder periodsHolder) { this.system2 = system2; this.dbClient = dbClient; this.treeRootHolder = treeRootHolder; this.analysisMetadataHolder = analysisMetadataHolder; - this.dbIdsRepository = dbIdsRepository; this.periodsHolder = periodsHolder; } @@ -67,7 +62,7 @@ public class PersistSnapshotsStep implements ComputationStep { DbSession session = dbClient.openSession(false); try { new PathAwareCrawler<>( - new PersistSnapshotsPathAwareVisitor(session, analysisMetadataHolder.getAnalysisDate(), dbIdsRepository)) + new PersistSnapshotsPathAwareVisitor(session, analysisMetadataHolder.getAnalysisDate())) .visit(treeRootHolder.getRoot()); session.commit(); } finally { @@ -79,64 +74,25 @@ public class PersistSnapshotsStep implements ComputationStep { private final DbSession dbSession; private final long analysisDate; - private final MutableDbIdsRepository dbIdsRepository; - private String rootUuid; - - public PersistSnapshotsPathAwareVisitor(DbSession dbSession, long analysisDate, MutableDbIdsRepository dbIdsRepository) { - super(CrawlerDepthLimit.LEAVES, Order.PRE_ORDER, SnapshotDtoHolderFactory.INSTANCE); + public PersistSnapshotsPathAwareVisitor(DbSession dbSession, long analysisDate) { + super(CrawlerDepthLimit.ROOTS, Order.PRE_ORDER, SnapshotDtoHolderFactory.INSTANCE); this.dbSession = dbSession; this.analysisDate = analysisDate; - this.dbIdsRepository = dbIdsRepository; } @Override public void visitProject(Component project, Path path) { - this.rootUuid = project.getUuid(); - SnapshotDto snapshot = createSnapshot(analysisMetadataHolder.getUuid(), project, path, Qualifiers.PROJECT, Scopes.PROJECT, true); - updateSnapshotPeriods(snapshot); - commonForAnyVisit(project, path, snapshot); - } - - @Override - public void visitModule(Component module, Path path) { - SnapshotDto snapshot = createSnapshot(Uuids.create(), module, path, Qualifiers.MODULE, Scopes.PROJECT, true); + SnapshotDto snapshot = createSnapshot(analysisMetadataHolder.getUuid(), project, true); updateSnapshotPeriods(snapshot); - commonForAnyVisit(module, path, snapshot); - } - - @Override - public void visitDirectory(Component directory, Path path) { - SnapshotDto snapshot = createSnapshot(Uuids.create(), directory, path, Qualifiers.DIRECTORY, Scopes.DIRECTORY, false); - commonForAnyVisit(directory, path, snapshot); - } - - @Override - public void visitFile(Component file, Path path) { - SnapshotDto snapshot = createSnapshot(Uuids.create(), file, path, getFileQualifier(file), Scopes.FILE, false); - commonForAnyVisit(file, path, snapshot); + persist(snapshot, dbSession); } @Override public void visitView(Component view, Path path) { - this.rootUuid = view.getUuid(); - SnapshotDto snapshot = createSnapshot(Uuids.create(), view, path, Qualifiers.VIEW, Scopes.PROJECT, false); - updateSnapshotPeriods(snapshot); - commonForAnyVisit(view, path, snapshot); - } - - @Override - public void visitSubView(Component subView, Path path) { - SnapshotDto snapshot = createSnapshot(Uuids.create(), subView, path, Qualifiers.SUBVIEW, Scopes.PROJECT, false); + SnapshotDto snapshot = createSnapshot(Uuids.create(), view, false); updateSnapshotPeriods(snapshot); - commonForAnyVisit(subView, path, snapshot); - } - - @Override - public void visitProjectView(Component projectView, Path path) { - SnapshotDto snapshot = createSnapshot(Uuids.create(), projectView, path, Qualifiers.PROJECT, Scopes.FILE, false); - updateSnapshotPeriods(snapshot); - commonForAnyVisit(projectView, path, snapshot); + persist(snapshot, dbSession); } private void updateSnapshotPeriods(SnapshotDto snapshotDto) { @@ -148,47 +104,16 @@ public class PersistSnapshotsStep implements ComputationStep { } } - private void commonForAnyVisit(Component project, Path path, SnapshotDto snapshot) { - persist(snapshot, dbSession); - addToCache(project, snapshot); - if (path.current() != null) { - path.current().setSnapshotDto(snapshot); - } - } - - private SnapshotDto createSnapshot(String snapshotUuid, Component component, Path path, - String qualifier, String scope, boolean setVersion) { + private SnapshotDto createSnapshot(String snapshotUuid, Component component, boolean setVersion) { String componentUuid = component.getUuid(); - SnapshotDto snapshotDto = new SnapshotDto() + return new SnapshotDto() .setUuid(snapshotUuid) - .setRootComponentUuid(rootUuid) .setVersion(setVersion ? component.getReportAttributes().getVersion() : null) .setComponentUuid(componentUuid) - .setQualifier(qualifier) - .setScope(scope) .setLast(false) .setStatus(SnapshotDto.STATUS_UNPROCESSED) .setCreatedAt(analysisDate) .setBuildDate(system2.now()); - - SnapshotDto parentSnapshot = path.isRoot() ? null : path.parent().getSnapshotDto(); - if (parentSnapshot != null) { - snapshotDto - .setParentId(parentSnapshot.getId()) - .setRootId(parentSnapshot.getRootId() == null ? parentSnapshot.getId() : parentSnapshot.getRootId()) - .setDepth(parentSnapshot.getDepth() + 1) - .setPath(parentSnapshot.getPath() + parentSnapshot.getId() + "."); - } else { - snapshotDto - // On Oracle, the path will be null - .setPath("") - .setDepth(0); - } - return snapshotDto; - } - - private void addToCache(Component component, SnapshotDto snapshotDto) { - dbIdsRepository.setSnapshotId(component, snapshotDto.getId()); } private void persist(SnapshotDto snapshotDto, DbSession dbSession) { @@ -196,10 +121,6 @@ public class PersistSnapshotsStep implements ComputationStep { } } - private static String getFileQualifier(Component component) { - return component.getFileAttributes().isUnitTest() ? Qualifiers.UNIT_TEST_FILE : Qualifiers.FILE; - } - private static final class SnapshotDtoHolder { @CheckForNull private SnapshotDto snapshotDto; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java index 1d129631367..f331815ceb9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java @@ -97,7 +97,7 @@ public class ReportComputationSteps extends AbstractComputationSteps { PersistCrossProjectDuplicationIndexStep.class, // Switch snapshot and purge - SwitchSnapshotStep.class, + EnableAnalysisStep.class, UpdateQualityProfilesLastUsedDateStep.class, IndexComponentsStep.class, PurgeDatastoresStep.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java deleted file mode 100644 index 5f2706d816d..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/SwitchSnapshotStep.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.step; - -import java.util.List; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.MyBatis; -import org.sonar.db.component.SnapshotDao; -import org.sonar.db.component.SnapshotDto; -import org.sonar.server.computation.component.Component; -import org.sonar.server.computation.component.DbIdsRepository; -import org.sonar.server.computation.component.TreeRootHolder; - -import static org.sonar.db.component.SnapshotDao.isLast; - -public class SwitchSnapshotStep implements ComputationStep { - - private final DbClient dbClient; - private final TreeRootHolder treeRootHolder; - private final DbIdsRepository dbIdsRepository; - - public SwitchSnapshotStep(DbClient dbClient, TreeRootHolder treeRootHolder, DbIdsRepository dbIdsRepository) { - this.dbClient = dbClient; - this.treeRootHolder = treeRootHolder; - this.dbIdsRepository = dbIdsRepository; - } - - @Override - public void execute() { - DbSession session = dbClient.openSession(true); - try { - Component project = treeRootHolder.getRoot(); - long snapshotId = dbIdsRepository.getSnapshotId(project); - disablePreviousSnapshot(session, snapshotId); - enableCurrentSnapshot(session, snapshotId); - } finally { - MyBatis.closeQuietly(session); - } - } - - @Override - public String getDescription() { - return "Enable snapshot"; - } - - private void disablePreviousSnapshot(DbSession session, long reportSnapshotId) { - List snapshots = dbClient.snapshotDao().selectSnapshotAndChildrenOfProjectScope(session, reportSnapshotId); - for (SnapshotDto snapshot : snapshots) { - SnapshotDto previousLastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(session, snapshot.getComponentUuid()); - if (previousLastSnapshot != null) { - dbClient.snapshotDao().updateSnapshotAndChildrenLastFlag(session, previousLastSnapshot, false); - session.commit(); - } - } - } - - private void enableCurrentSnapshot(DbSession session, long reportSnapshotId) { - SnapshotDao dao = dbClient.snapshotDao(); - SnapshotDto snapshot = dao.selectOrFailById(session, reportSnapshotId); - SnapshotDto previousLastSnapshot = dao.selectLastSnapshotByComponentUuid(session, snapshot.getComponentUuid()); - - boolean isLast = isLast(snapshot, previousLastSnapshot); - dao.updateSnapshotAndChildrenLastFlagAndStatus(session, snapshot, isLast, SnapshotDto.STATUS_PROCESSED); - session.commit(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java index 32d9329bba7..3d8b946a5d3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java @@ -147,10 +147,10 @@ public class ValidateProjectStep implements ComputationStep { private void validateAnalysisDate(Optional baseProject) { if (baseProject.isPresent()) { - SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(session, baseProject.get().uuid()); + java.util.Optional snapshotDto = dbClient.snapshotDao().selectLastSnapshotByRootComponentUuid(session, baseProject.get().uuid()); long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate(); - Long lastAnalysisDate = snapshotDto != null ? snapshotDto.getCreatedAt() : null; - if (lastAnalysisDate != null && currentAnalysisDate <= snapshotDto.getCreatedAt()) { + Long lastAnalysisDate = snapshotDto.isPresent() ? snapshotDto.get().getCreatedAt() : null; + if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) { validationMessages.add(format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " + "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.", formatDateTime(new Date(currentAnalysisDate)), formatDateTime(new Date(lastAnalysisDate)))); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java index 266214b6ed3..c30862a9b3b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java @@ -35,6 +35,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.CheckForNull; @@ -248,10 +249,11 @@ public class IssueQueryService { @CheckForNull private Date findCreatedAfterFromComponentUuid(DbSession dbSession, String uuid) { ComponentDto component = checkFoundWithOptional(componentService.getByUuid(uuid), "Component with id '%s' not found", uuid); - SnapshotDto snapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, component.uuid()); - Long projectSnapshotId = snapshot == null ? null : snapshot.getRootId(); - SnapshotDto projectSnapshot = projectSnapshotId == null ? snapshot : dbClient.snapshotDao().selectById(dbSession, projectSnapshotId); - return projectSnapshot == null ? null : longToDate(projectSnapshot.getPeriodDate(1)); + Optional snapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, component.uuid()); + if (snapshot.isPresent()) { + return longToDate(snapshot.get().getPeriodDate(1)); + } + return null; } private List buildAssignees(@Nullable List assigneesFromParams) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java index d62669f3ab8..c1678981de3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java @@ -209,7 +209,6 @@ class MeasureFilterSql { appendInStatement(filter.getResourceQualifiers(), sb); } sb.append(") "); - // TODO filter on ROOT_COMPONENT_UUID if base } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java index 6efe11a28d9..10a8af689db 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java @@ -25,6 +25,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.util.List; import java.util.Map; +import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -101,7 +102,7 @@ public class SearchAction implements CustomMeasuresWsAction { try { ComponentDto project = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_ID_AND_KEY); checkPermissions(userSession, project); - Long lastAnalysisDateMs = searchLastSnapshot(dbSession, project); + Long lastAnalysisDateMs = searchLastSnapshotDate(dbSession, project); List customMeasures = searchCustomMeasures(dbSession, project, searchOptions); int nbCustomMeasures = countTotalOfCustomMeasures(dbSession, project); Map usersByLogin = usersByLogin(dbSession, customMeasures); @@ -114,10 +115,10 @@ public class SearchAction implements CustomMeasuresWsAction { } @CheckForNull - private Long searchLastSnapshot(DbSession dbSession, ComponentDto project) { - SnapshotDto lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, project.uuid()); + private Long searchLastSnapshotDate(DbSession dbSession, ComponentDto project) { + Optional lastSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, project.projectUuid()); - return lastSnapshot == null ? null : lastSnapshot.getBuildDate(); + return lastSnapshot.isPresent() ? lastSnapshot.get().getBuildDate() : null; } private int countTotalOfCustomMeasures(DbSession dbSession, ComponentDto project) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 8d35e2a8d42..018c95db2f6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -138,7 +138,7 @@ public class ComponentAction implements MeasuresWsAction { Long developerId = searchDeveloperId(dbSession, request); Optional refComponent = getReferenceComponent(dbSession, component); checkPermissions(component); - SnapshotDto analysis = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, component.uuid()); + SnapshotDto analysis = dbClient.snapshotDao().selectLastSnapshotByRootComponentUuid(dbSession, component.projectUuid()).orElse(null); List metrics = searchMetrics(dbSession, request); List periods = snapshotToWsPeriods(analysis); List measures = searchMeasures(dbSession, component, analysis, metrics, periods, developerId); diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java index 825279d9999..1bccfd3c3a6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentTreeDataLoader.java @@ -102,8 +102,8 @@ public class ComponentTreeDataLoader { try { ComponentDto baseComponent = componentFinder.getByUuidOrKey(dbSession, wsRequest.getBaseComponentId(), wsRequest.getBaseComponentKey(), BASE_COMPONENT_ID_AND_KEY); checkPermissions(baseComponent); - SnapshotDto baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, baseComponent.projectUuid()); - if (baseSnapshot == null) { + java.util.Optional baseSnapshot = dbClient.snapshotDao().selectLastSnapshotByRootComponentUuid(dbSession, baseComponent.projectUuid()); + if (!baseSnapshot.isPresent()) { return ComponentTreeData.builder() .setBaseComponent(baseComponent) .build(); @@ -114,7 +114,7 @@ public class ComponentTreeDataLoader { ComponentDtosAndTotal componentDtosAndTotal = searchComponents(dbSession, dbQuery, wsRequest); List components = componentDtosAndTotal.componentDtos; List metrics = searchMetrics(dbSession, wsRequest); - List periods = snapshotToWsPeriods(baseSnapshot); + List periods = snapshotToWsPeriods(baseSnapshot.get()); Table measuresByComponentUuidAndMetric = searchMeasuresByComponentUuidAndMetric(dbSession, baseComponent, components, metrics, periods, developerId); diff --git a/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java b/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java index 0eb27dbb97e..62de10c3fc5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java +++ b/server/sonar-server/src/main/java/org/sonar/server/project/ws/SearchMyProjectsDataLoader.java @@ -57,9 +57,9 @@ public class SearchMyProjectsDataLoader { SearchMyProjectsData.Builder data = builder(); ProjectsResult searchResult = searchProjects(dbSession, request); List projects = searchResult.projects; - List projectUuids = Lists.transform(projects, ComponentDto::uuid); + List projectUuids = Lists.transform(projects, ComponentDto::projectUuid); List projectLinks = dbClient.componentLinkDao().selectByComponentUuids(dbSession, projectUuids); - List snapshots = dbClient.snapshotDao().selectLastSnapshotByComponentUuids(dbSession, projectUuids); + List snapshots = dbClient.snapshotDao().selectLastSnapshotsByRootComponentUuids(dbSession, projectUuids); MetricDto gateStatusMetric = dbClient.metricDao().selectOrFailByKey(dbSession, CoreMetrics.ALERT_STATUS_KEY); MeasureQuery measureQuery = MeasureQuery.builder() .setComponentUuids(projectUuids) diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java index 99d3d3eadc8..cd6ab965e73 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java @@ -144,8 +144,8 @@ public class ProjectStatusAction implements QGateWsAction { private ProjectAndSnapshot getProjectThenSnapshot(DbSession dbSession, ProjectStatusWsRequest request) { ComponentDto projectDto = componentFinder.getByUuidOrKey(dbSession, request.getProjectId(), request.getProjectKey(), ParamNames.PROJECT_ID_AND_KEY); - SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(dbSession, projectDto.uuid()); - return new ProjectAndSnapshot(projectDto, snapshotDto); + java.util.Optional snapshot = dbClient.snapshotDao().selectLastSnapshotByRootComponentUuid(dbSession, projectDto.projectUuid()); + return new ProjectAndSnapshot(projectDto, snapshot.orElse(null)); } private ProjectAndSnapshot getSnapshotThenProject(DbSession dbSession, String analysisUuid) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java index 053e9714b9d..3674be2b221 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java @@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Optional; import javax.annotation.Nullable; import org.sonar.api.i18n.I18n; import org.sonar.api.resources.Qualifiers; @@ -115,17 +116,17 @@ public class ComponentNavigationAction implements NavigationWsAction { userSession.checkComponentUuidPermission(UserRole.USER, component.projectUuid()); - SnapshotDto analysis = dbClient.snapshotDao().selectLastSnapshotByComponentUuid(session, component.uuid()); + Optional analysis = dbClient.snapshotDao().selectLastSnapshotByRootComponentUuid(session, component.projectUuid()); JsonWriter json = response.newJsonWriter(); json.beginObject(); - writeComponent(json, session, component, analysis, userSession); + writeComponent(json, session, component, analysis.orElse(null), userSession); if (userSession.hasComponentUuidPermission(UserRole.ADMIN, component.projectUuid()) || userSession.hasPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN)) { writeConfiguration(json, component, userSession); } - writeBreadCrumbs(json, session, component, analysis); + writeBreadCrumbs(json, session, component); json.endObject().close(); } finally { @@ -256,24 +257,18 @@ public class ComponentNavigationAction implements NavigationWsAction { .endObject(); } - private void writeBreadCrumbs(JsonWriter json, DbSession session, ComponentDto component, @Nullable SnapshotDto snapshot) { + private void writeBreadCrumbs(JsonWriter json, DbSession session, ComponentDto component) { json.name("breadcrumbs").beginArray(); - List componentPath = Lists.newArrayList(component); + List breadcrumb = Lists.newArrayList(); + breadcrumb.addAll(dbClient.componentDao().selectAncestors(session, component)); + breadcrumb.add(component); - if (snapshot != null) { - SnapshotDto currentSnapshot = snapshot; - while (currentSnapshot.getParentId() != null) { - currentSnapshot = dbClient.snapshotDao().selectOrFailById(session, currentSnapshot.getParentId()); - componentPath.add(0, dbClient.componentDao().selectOrFailByUuid(session, currentSnapshot.getComponentUuid())); - } - } - - for (ComponentDto crumbComponent : componentPath) { + for (ComponentDto c : breadcrumb) { json.beginObject() - .prop("key", crumbComponent.key()) - .prop("name", crumbComponent.name()) - .prop("qualifier", crumbComponent.qualifier()) + .prop("key", c.key()) + .prop("name", c.name()) + .prop("qualifier", c.qualifier()) .endObject(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index 571cd76d854..ea19c676e14 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -33,7 +33,6 @@ import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; -import org.sonar.db.component.SnapshotDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -147,21 +146,18 @@ public class ShowActionTest { .setName("Java Markdown") .setDescription("Java Markdown Project") .setQualifier(Qualifiers.PROJECT); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); + componentDb.insertProjectAndSnapshot(project); ComponentDto directory = newDirectory(project, "AVIF-FfgA3Ax6PH2efPF", "src/main/java/com/sonarsource/markdown/impl") .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl") .setName("src/main/java/com/sonarsource/markdown/impl") .setQualifier(Qualifiers.DIRECTORY); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot( - directory, - projectSnapshot); - componentDb.insertComponentAndSnapshot( + componentDb.insertComponent(directory); + componentDb.insertComponent( newFileDto(directory, "AVIF-FffA3Ax6PH2efPD") .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/Rule.java") .setName("Rule.java") .setPath("src/main/java/com/sonarsource/markdown/impl/Rule.java") .setLanguage("java") - .setQualifier(Qualifiers.FILE), - directorySnapshot); + .setQualifier(Qualifiers.FILE)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java index 01917262771..7d9be1c9744 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java @@ -108,16 +108,16 @@ public class TreeActionTest { @Test public void return_children() throws IOException { ComponentDto project = newProjectDto("project-uuid"); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); + componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto("module-uuid-1", project); - SnapshotDto moduleSnapshot = componentDb.insertComponentAndSnapshot(module, projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(project, 1), projectSnapshot); + componentDb.insertComponent(module); + componentDb.insertComponent(newFileDto(project, 1)); for (int i = 2; i <= 9; i++) { - componentDb.insertComponentAndSnapshot(newFileDto(module, i), moduleSnapshot); + componentDb.insertComponent(newFileDto(module, i)); } ComponentDto directory = newDirectory(module, "directory-path-1"); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(directory, moduleSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(directory, 10), directorySnapshot); + componentDb.insertComponent(directory); + componentDb.insertComponent(newFileDto(directory, 10)); db.commit(); componentDb.indexAllComponents(); @@ -140,14 +140,14 @@ public class TreeActionTest { ComponentDto project = newProjectDto("project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto("module-uuid-1", project); - SnapshotDto moduleSnapshot = componentDb.insertComponentAndSnapshot(module, projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(project, 10), projectSnapshot); + componentDb.insertComponent(module); + componentDb.insertComponent(newFileDto(project, 10)); for (int i = 2; i <= 9; i++) { - componentDb.insertComponentAndSnapshot(newFileDto(module, i), moduleSnapshot); + componentDb.insertComponent(newFileDto(module, i)); } ComponentDto directory = newDirectory(module, "directory-path-1"); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(directory, moduleSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(directory, 1), directorySnapshot); + componentDb.insertComponent(directory); + componentDb.insertComponent(newFileDto(directory, 1)); db.commit(); componentDb.indexAllComponents(); @@ -168,10 +168,10 @@ public class TreeActionTest { @Test public void filter_descendants_by_qualifier() throws IOException { ComponentDto project = newProjectDto("project-uuid"); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - componentDb.insertComponentAndSnapshot(newFileDto(project, 1), projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(project, 2), projectSnapshot); - componentDb.insertComponentAndSnapshot(newModuleDto("module-uuid-1", project), projectSnapshot); + componentDb.insertProjectAndSnapshot(project); + componentDb.insertComponent(newFileDto(project, 1)); + componentDb.insertComponent(newFileDto(project, 2)); + componentDb.insertComponent(newModuleDto("module-uuid-1", project)); db.commit(); componentDb.indexAllComponents(); @@ -186,14 +186,14 @@ public class TreeActionTest { @Test public void return_leaves() throws IOException { ComponentDto project = newProjectDto("project-uuid"); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); + componentDb.insertProjectAndSnapshot(project); ComponentDto module = newModuleDto("module-uuid-1", project); - SnapshotDto moduleSnapshot = componentDb.insertComponentAndSnapshot(module, projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(project, 1), projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(module, 2), moduleSnapshot); + componentDb.insertComponent(module); + componentDb.insertComponent(newFileDto(project, 1)); + componentDb.insertComponent(newFileDto(module, 2)); ComponentDto directory = newDirectory(project, "directory-path-1"); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(directory, moduleSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(directory, 3), directorySnapshot); + componentDb.insertComponent(directory); + componentDb.insertComponent(newFileDto(directory, 3)); db.commit(); componentDb.indexAllComponents(); @@ -210,12 +210,12 @@ public class TreeActionTest { @Test public void sort_descendants_by_qualifier() throws IOException { ComponentDto project = newProjectDto("project-uuid"); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - componentDb.insertComponentAndSnapshot(newFileDto(project, 1), projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(project, 2), projectSnapshot); + componentDb.insertProjectAndSnapshot(project); + componentDb.insertComponent(newFileDto(project, 1)); + componentDb.insertComponent(newFileDto(project, 2)); ComponentDto module = newModuleDto("module-uuid-1", project); - componentDb.insertComponentAndSnapshot(module, projectSnapshot); - componentDb.insertComponentAndSnapshot(newDirectory(project, "path/directory/", "directory-uuid-1"), projectSnapshot); + componentDb.insertComponent(module); + componentDb.insertComponent(newDirectory(project, "path/directory/", "directory-uuid-1")); db.commit(); componentDb.indexAllComponents(); @@ -230,11 +230,11 @@ public class TreeActionTest { @Test public void return_children_of_a_view() { ComponentDto view = newView("view-uuid"); - SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view); + componentDb.insertViewAndSnapshot(view); ComponentDto project = newProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1"); componentDb.insertProjectAndSnapshot(project); - componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot); - componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot); + componentDb.insertComponent(newProjectCopy("project-uuid-1-copy", project, view)); + componentDb.insertComponent(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name")); db.commit(); componentDb.indexAllComponents(); @@ -267,8 +267,8 @@ public class TreeActionTest { ComponentDto project = newProjectDto("project-uuid"); componentDb.insertProjectAndSnapshot(project); ComponentDto developer = newDeveloper("developer-name"); - SnapshotDto developerSnapshot = componentDb.insertDeveloperAndSnapshot(developer); - componentDb.insertComponentAndSnapshot(newDevProjectCopy("project-copy-uuid", project, developer), developerSnapshot); + componentDb.insertDeveloperAndSnapshot(developer); + componentDb.insertComponent(newDevProjectCopy("project-copy-uuid", project, developer)); db.commit(); TreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, developer.uuid())); @@ -284,8 +284,8 @@ public class TreeActionTest { ComponentDto project = newProjectDto("project-uuid"); componentDb.insertProjectAndSnapshot(project); ComponentDto view = newView("view-uuid"); - SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view); - componentDb.insertComponentAndSnapshot(newProjectCopy("project-copy-uuid", project, view), viewSnapshot); + componentDb.insertViewAndSnapshot(view); + componentDb.insertComponent(newProjectCopy("project-copy-uuid", project, view)); TreeWsResponse response = call(ws.newRequest().setParam(PARAM_BASE_COMPONENT_ID, view.uuid())); @@ -404,7 +404,7 @@ public class TreeActionTest { for (JsonElement componentAsJsonElement : components) { JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject(); String uuid = getJsonField(componentAsJsonObject, "id"); - componentDb.insertComponentAndSnapshot(ComponentTesting.newChildComponent(uuid, project) + componentDb.insertComponent(ComponentTesting.newChildComponent(uuid, project) .setKey(getJsonField(componentAsJsonObject, "key")) .setName(getJsonField(componentAsJsonObject, "name")) .setLanguage(getJsonField(componentAsJsonObject, "language")) @@ -412,8 +412,7 @@ public class TreeActionTest { .setQualifier(getJsonField(componentAsJsonObject, "qualifier")) .setDescription(getJsonField(componentAsJsonObject, "description")) .setEnabled(true) - .setCreatedAt(now), - projectSnapshot); + .setCreatedAt(now)); } db.commit(); componentDb.indexAllComponents(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/DbIdsRepositoryImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/DbIdsRepositoryImplTest.java index 8d0402f87f9..81af6707995 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/DbIdsRepositoryImplTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/DbIdsRepositoryImplTest.java @@ -31,10 +31,9 @@ public class DbIdsRepositoryImplTest { @Rule public ExpectedException thrown = ExpectedException.none(); - static final String SOME_COMPONENT_KEY = "SOME_COMPONENT_KEY"; - static final Component SOME_COMPONENT = ReportComponent.builder(PROJECT, 1).setKey(SOME_COMPONENT_KEY).build(); - - static final Developer SOME_DEVELOPER = new DumbDeveloper("DEV1"); + private static final String SOME_COMPONENT_KEY = "SOME_COMPONENT_KEY"; + private static final Component SOME_COMPONENT = ReportComponent.builder(PROJECT, 1).setKey(SOME_COMPONENT_KEY).build(); + private static final Developer SOME_DEVELOPER = new DumbDeveloper("DEV1"); @Test public void add_and_get_component_id() { @@ -62,32 +61,6 @@ public class DbIdsRepositoryImplTest { cache.setComponentId(SOME_COMPONENT, 11L); } - @Test - public void add_and_get_snapshot_id() { - DbIdsRepositoryImpl cache = new DbIdsRepositoryImpl(); - cache.setSnapshotId(SOME_COMPONENT, 100L); - - assertThat(cache.getSnapshotId(SOME_COMPONENT)).isEqualTo(100L); - } - - @Test - public void fail_to_get_snapshot_id_on_unknown_ref() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("No snapshot id registered in repository for Component '" + SOME_COMPONENT_KEY + "'"); - - new DbIdsRepositoryImpl().getSnapshotId(SOME_COMPONENT); - } - - @Test - public void fail_if_snapshot_id_already_set() { - DbIdsRepositoryImpl cache = new DbIdsRepositoryImpl(); - cache.setSnapshotId(SOME_COMPONENT, 10L); - - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Snapshot id '10' is already registered in repository for Component '" + SOME_COMPONENT_KEY + "', can not set new id '11'"); - cache.setSnapshotId(SOME_COMPONENT, 11L); - } - @Test public void add_and_get_developer_id() { DbIdsRepositoryImpl cache = new DbIdsRepositoryImpl(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/MutableDbIdsRepositoryRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/MutableDbIdsRepositoryRule.java index 05c2f9849c5..3ae1c60329f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/MutableDbIdsRepositoryRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/MutableDbIdsRepositoryRule.java @@ -67,22 +67,11 @@ public class MutableDbIdsRepositoryRule extends ExternalResource implements Muta this.componentProvider.ensureInitialized(); return delegate.setComponentId(componentProvider.getByRef(componentRef), componentId); } - - public DbIdsRepository setSnapshotId(int componentRef, long snapshotId) { - this.componentProvider.ensureInitialized(); - return delegate.setSnapshotId(componentProvider.getByRef(componentRef), snapshotId); - } - @Override public DbIdsRepository setComponentId(Component component, long componentId) { return delegate.setComponentId(component, componentId); } - @Override - public DbIdsRepository setSnapshotId(Component component, long snapshotId) { - return delegate.setSnapshotId(component, snapshotId); - } - @Override public DbIdsRepository setDeveloperId(Developer developer, long developerId) { return delegate.setDeveloperId(developer, developerId); @@ -98,8 +87,4 @@ public class MutableDbIdsRepositoryRule extends ExternalResource implements Muta return delegate.getComponentId(component); } - @Override - public long getSnapshotId(Component component) { - return delegate.getSnapshotId(component); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java index 9022fc06306..9e48357a162 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureToMeasureDtoTest.java @@ -42,7 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat; public class MeasureToMeasureDtoTest { private static final MetricImpl SOME_METRIC = new MetricImpl(42, "metric_key", "metric_name", Metric.MetricType.STRING); private static final int SOME_COMPONENT_ID = 951; - private static final int SOME_SNAPSHOT_ID = 753; private static final String SOME_DATA = "some_data"; private static final String SOME_STRING = "some_string"; private static final MeasureVariations SOME_VARIATIONS = new MeasureVariations(1d, 2d, 3d, 4d, 5d); @@ -66,7 +65,6 @@ public class MeasureToMeasureDtoTest { @Before public void setUp() throws Exception { dbIdsRepository.setComponentId(SOME_COMPONENT, SOME_COMPONENT_ID); - dbIdsRepository.setSnapshotId(SOME_COMPONENT, SOME_SNAPSHOT_ID); analysisMetadataHolder.setUuid(ANALYSIS_UUID); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadCrossProjectDuplicationsRepositoryStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadCrossProjectDuplicationsRepositoryStepTest.java index 2ae008a2c4a..ec257177fb2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadCrossProjectDuplicationsRepositoryStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadCrossProjectDuplicationsRepositoryStepTest.java @@ -128,8 +128,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { ComponentDto otherProject = createProject("OTHER_PROJECT_KEY"); SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject); - ComponentDto otherFIle = createFile("OTHER_FILE_KEY", otherProject); - SnapshotDto otherFileSnapshot = createFileSnapshot(otherFIle, otherProjectSnapshot); + ComponentDto otherFile = createFile("OTHER_FILE_KEY", otherProject); String hash = "a8998353e96320ec"; DuplicationUnitDto duplicate = new DuplicationUnitDto() @@ -138,7 +137,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .setEndLine(55) .setIndexInFile(0) .setAnalysisUuid(otherProjectSnapshot.getUuid()) - .setComponentUuid(otherFileSnapshot.getComponentUuid()); + .setComponentUuid(otherFile.uuid()); dbClient.duplicationDao().insert(dbSession, duplicate); dbSession.commit(); @@ -164,7 +163,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .build()), Arrays.asList( new Block.Builder() - .setResourceId(otherFIle.getKey()) + .setResourceId(otherFile.getKey()) .setBlockHash(new ByteArray(hash)) .setIndexInFile(duplicate.getIndexInFile()) .setLines(duplicate.getStartLine(), duplicate.getEndLine()) @@ -179,8 +178,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { ComponentDto otherProject = createProject("OTHER_PROJECT_KEY"); SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject); - ComponentDto otherFIle = createFile("OTHER_FILE_KEY", otherProject); - SnapshotDto otherFileSnapshot = createFileSnapshot(otherFIle, otherProjectSnapshot); + ComponentDto otherFile = createFile("OTHER_FILE_KEY", otherProject); ScannerReport.CpdTextBlock originBlock1 = ScannerReport.CpdTextBlock.newBuilder() .setHash("a8998353e96320ec") @@ -204,7 +202,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .setEndLine(55) .setIndexInFile(0) .setAnalysisUuid(otherProjectSnapshot.getUuid()) - .setComponentUuid(otherFileSnapshot.getComponentUuid()); + .setComponentUuid(otherFile.uuid()); DuplicationUnitDto duplicate2 = new DuplicationUnitDto() .setHash(originBlock2.getHash()) @@ -212,7 +210,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .setEndLine(35) .setIndexInFile(1) .setAnalysisUuid(otherProjectSnapshot.getUuid()) - .setComponentUuid(otherFileSnapshot.getComponentUuid()); + .setComponentUuid(otherFile.uuid()); dbClient.duplicationDao().insert(dbSession, duplicate1); dbClient.duplicationDao().insert(dbSession, duplicate2); dbSession.commit(); @@ -246,14 +244,14 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { Map duplicationBlocksByIndex = blocksByIndexInFile(duplicationBlocks.getValue()); assertThat(duplicationBlocksByIndex.get(0)).isEqualTo( new Block.Builder() - .setResourceId(otherFIle.getKey()) + .setResourceId(otherFile.getKey()) .setBlockHash(new ByteArray(originBlock1.getHash())) .setIndexInFile(duplicate1.getIndexInFile()) .setLines(duplicate1.getStartLine(), duplicate1.getEndLine()) .build()); assertThat(duplicationBlocksByIndex.get(1)).isEqualTo( new Block.Builder() - .setResourceId(otherFIle.getKey()) + .setResourceId(otherFile.getKey()) .setBlockHash(new ByteArray(originBlock2.getHash())) .setIndexInFile(duplicate2.getIndexInFile()) .setLines(duplicate2.getStartLine(), duplicate2.getEndLine()) @@ -269,7 +267,6 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject); ComponentDto otherFIle = createFile("OTHER_FILE_KEY", otherProject); - SnapshotDto otherFileSnapshot = createFileSnapshot(otherFIle, otherProjectSnapshot); String hash = "a8998353e96320ec"; DuplicationUnitDto duplicate = new DuplicationUnitDto() @@ -278,7 +275,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .setEndLine(55) .setIndexInFile(0) .setAnalysisUuid(otherProjectSnapshot.getUuid()) - .setComponentUuid(otherFileSnapshot.getComponentUuid()); + .setComponentUuid(otherFIle.uuid()); dbClient.duplicationDao().insert(dbSession, duplicate); dbSession.commit(); @@ -350,13 +347,6 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { return file; } - private SnapshotDto createFileSnapshot(ComponentDto file, SnapshotDto projectSnapshot) { - SnapshotDto fileSnapshot = SnapshotTesting.createForComponent(file, projectSnapshot); - dbClient.snapshotDao().insert(dbSession, fileSnapshot); - dbSession.commit(); - return fileSnapshot; - } - private static Map blocksByIndexInFile(List blocks) { Map blocksByIndexInFile = new HashMap<>(); for (Block block : blocks) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java index 3a9c4aaf20d..8ddabbe23fa 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java @@ -77,10 +77,6 @@ public class PersistMeasuresStepTest extends BaseStepTest { private static final int INTERMEDIATE_1_REF = 2; private static final int INTERMEDIATE_2_REF = 3; private static final int LEAF_REF = 4; - private static final long ROOT_SNAPSHOT_ID = 3L; - private static final long INTERMEDIATE_1_SNAPSHOT_ID = 4L; - private static final long INTERMEDIATE_2_SNAPSHOT_ID = 5L; - private static final long LEAF_SNAPSHOT_ID = 6L; private static final String ANALYSIS_UUID = "a1"; @Rule @@ -152,15 +148,14 @@ public class PersistMeasuresStepTest extends BaseStepTest { intermediate2Dto = addComponent("intermediate2-key", "intermediate2-uuid"); leafDto = addComponent("leaf-key", "leaf-uuid"); - setDbIds(ROOT_REF, rootDto.getId(), ROOT_SNAPSHOT_ID); - setDbIds(INTERMEDIATE_1_REF, intermediate1Dto.getId(), INTERMEDIATE_1_SNAPSHOT_ID); - setDbIds(INTERMEDIATE_2_REF, intermediate2Dto.getId(), INTERMEDIATE_2_SNAPSHOT_ID); - setDbIds(LEAF_REF, leafDto.getId(), LEAF_SNAPSHOT_ID); + setDbIds(ROOT_REF, rootDto.getId()); + setDbIds(INTERMEDIATE_1_REF, intermediate1Dto.getId()); + setDbIds(INTERMEDIATE_2_REF, intermediate2Dto.getId()); + setDbIds(LEAF_REF, leafDto.getId()); } - private void setDbIds(int componentRef, Long dbId, long snapshotId) { + private void setDbIds(int componentRef, Long dbId) { dbIdsRepository.setComponentId(componentRef, dbId); - dbIdsRepository.setSnapshotId(componentRef, snapshotId); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java index 85df02e9979..c23e33706ee 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistSnapshotsStepTest.java @@ -36,7 +36,6 @@ import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule; import org.sonar.server.computation.batch.TreeRootHolderRule; import org.sonar.server.computation.component.Component; import org.sonar.server.computation.component.DbIdsRepositoryImpl; -import org.sonar.server.computation.component.FileAttributes; import org.sonar.server.computation.component.ReportComponent; import org.sonar.server.computation.period.Period; import org.sonar.server.computation.period.PeriodsHolderRule; @@ -85,7 +84,7 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { when(system2.now()).thenReturn(now); - underTest = new PersistSnapshotsStep(system2, dbClient, treeRootHolder, analysisMetadataHolder, dbIdsRepository, periodsHolder); + underTest = new PersistSnapshotsStep(system2, dbClient, treeRootHolder, analysisMetadataHolder, periodsHolder); // initialize PeriodHolder to empty by default periodsHolder.setPeriods(); @@ -97,7 +96,7 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { } @Test - public void persist_snapshots() { + public void persist_snapshot() { ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); dbClient.componentDao().insert(dbTester.getSession(), projectDto); ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module"); @@ -121,159 +120,21 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { underTest.execute(); - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(4); + assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid()); - assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(projectSnapshot.getRootId()).isNull(); - assertThat(projectSnapshot.getParentId()).isNull(); - assertThat(projectSnapshot.getDepth()).isEqualTo(0); - assertThat(projectSnapshot.getPath()).isNullOrEmpty(); - assertThat(projectSnapshot.getQualifier()).isEqualTo("TRK"); - assertThat(projectSnapshot.getScope()).isEqualTo("PRJ"); assertThat(projectSnapshot.getVersion()).isEqualTo("1.0"); assertThat(projectSnapshot.getLast()).isFalse(); assertThat(projectSnapshot.getStatus()).isEqualTo("U"); assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(projectSnapshot.getBuildDate()).isEqualTo(now); - SnapshotDto moduleSnapshot = getUnprocessedSnapshot(moduleDto.uuid()); - assertThat(moduleSnapshot.getComponentUuid()).isEqualTo(module.getUuid()); - assertThat(moduleSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(moduleSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(moduleSnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); - assertThat(moduleSnapshot.getDepth()).isEqualTo(1); - assertThat(moduleSnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "."); - assertThat(moduleSnapshot.getQualifier()).isEqualTo("BRC"); - assertThat(moduleSnapshot.getScope()).isEqualTo("PRJ"); - assertThat(moduleSnapshot.getVersion()).isEqualTo("1.1"); - assertThat(moduleSnapshot.getLast()).isFalse(); - assertThat(moduleSnapshot.getStatus()).isEqualTo("U"); - assertThat(moduleSnapshot.getCreatedAt()).isEqualTo(analysisDate); - assertThat(moduleSnapshot.getBuildDate()).isEqualTo(now); - - SnapshotDto directorySnapshot = getUnprocessedSnapshot(directoryDto.uuid()); - assertThat(directorySnapshot.getComponentUuid()).isEqualTo(directory.getUuid()); - assertThat(directorySnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(directorySnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(directorySnapshot.getParentId()).isEqualTo(moduleSnapshot.getId()); - assertThat(directorySnapshot.getDepth()).isEqualTo(2); - assertThat(directorySnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "." + moduleSnapshot.getId() + "."); - assertThat(directorySnapshot.getQualifier()).isEqualTo("DIR"); - assertThat(directorySnapshot.getScope()).isEqualTo("DIR"); - assertThat(directorySnapshot.getVersion()).isNull(); - assertThat(directorySnapshot.getLast()).isFalse(); - assertThat(directorySnapshot.getStatus()).isEqualTo("U"); - assertThat(directorySnapshot.getCreatedAt()).isEqualTo(analysisDate); - assertThat(directorySnapshot.getBuildDate()).isEqualTo(now); - - SnapshotDto fileSnapshot = getUnprocessedSnapshot(fileDto.uuid()); - assertThat(fileSnapshot.getComponentUuid()).isEqualTo(file.getUuid()); - assertThat(fileSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(fileSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(fileSnapshot.getParentId()).isEqualTo(directorySnapshot.getId()); - assertThat(fileSnapshot.getDepth()).isEqualTo(3); - assertThat(fileSnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "." + moduleSnapshot.getId() + "." + directorySnapshot.getId() + "."); - assertThat(fileSnapshot.getQualifier()).isEqualTo("FIL"); - assertThat(fileSnapshot.getScope()).isEqualTo("FIL"); - assertThat(fileSnapshot.getVersion()).isNull(); - assertThat(fileSnapshot.getLast()).isFalse(); - assertThat(fileSnapshot.getStatus()).isEqualTo("U"); - assertThat(fileSnapshot.getCreatedAt()).isEqualTo(analysisDate); - assertThat(fileSnapshot.getBuildDate()).isEqualTo(now); - - assertThat(dbIdsRepository.getSnapshotId(project)).isEqualTo(projectSnapshot.getId()); assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId()); assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId()); assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId()); } - @Test - public void persist_unit_test() { - ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); - dbClient.componentDao().insert(dbTester.getSession(), projectDto); - ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module"); - dbClient.componentDao().insert(dbTester.getSession(), moduleDto); - ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/test/java/dir").setKey("MODULE_KEY:src/test/java/dir"); - dbClient.componentDao().insert(dbTester.getSession(), directoryDto); - ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, "DEFG").setKey("MODULE_KEY:src/test/java/dir/FooTest.java").setQualifier("UTS"); - dbClient.componentDao().insert(dbTester.getSession(), fileDto); - dbTester.getSession().commit(); - - Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/main/java/dir/Foo.java") - .setFileAttributes(new FileAttributes(true, null)).build(); - Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":src/main/java/dir").addChildren(file).build(); - Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(directory).build(); - treeRootHolder.setRoot(project); - - dbIdsRepository.setComponentId(project, projectDto.getId()); - dbIdsRepository.setComponentId(directory, directoryDto.getId()); - dbIdsRepository.setComponentId(file, fileDto.getId()); - - underTest.execute(); - - SnapshotDto fileSnapshot = getUnprocessedSnapshot(fileDto.uuid()); - assertThat(fileSnapshot.getQualifier()).isEqualTo("UTS"); - assertThat(fileSnapshot.getScope()).isEqualTo("FIL"); - } - - @Test - public void persist_snapshots_on_multi_modules() { - ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY); - dbClient.componentDao().insert(dbTester.getSession(), projectDto); - ComponentDto moduleADto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_A"); - dbClient.componentDao().insert(dbTester.getSession(), moduleADto); - ComponentDto subModuleADto = ComponentTesting.newModuleDto("CDEF", moduleADto).setKey("SUB_MODULE_A"); - dbClient.componentDao().insert(dbTester.getSession(), subModuleADto); - ComponentDto moduleBDto = ComponentTesting.newModuleDto("DEFG", projectDto).setKey("MODULE_B"); - dbClient.componentDao().insert(dbTester.getSession(), moduleBDto); - dbTester.getSession().commit(); - - Component moduleB = ReportComponent.builder(Component.Type.MODULE, 4).setUuid("DEFG").setKey("MODULE_B").build(); - Component subModuleA = ReportComponent.builder(Component.Type.MODULE, 3).setUuid("CDEF").setKey("SUB_MODULE_A").build(); - Component moduleA = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_A").addChildren(subModuleA).build(); - Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(moduleA, moduleB).build(); - treeRootHolder.setRoot(project); - - dbIdsRepository.setComponentId(project, projectDto.getId()); - dbIdsRepository.setComponentId(moduleA, moduleADto.getId()); - dbIdsRepository.setComponentId(subModuleA, subModuleADto.getId()); - dbIdsRepository.setComponentId(moduleB, moduleBDto.getId()); - - underTest.execute(); - - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(4); - - SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); - assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(projectSnapshot.getRootId()).isNull(); - assertThat(projectSnapshot.getParentId()).isNull(); - assertThat(projectSnapshot.getDepth()).isEqualTo(0); - assertThat(projectSnapshot.getPath()).isNullOrEmpty(); - - SnapshotDto moduleASnapshot = getUnprocessedSnapshot(moduleADto.uuid()); - assertThat(moduleASnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(moduleASnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(moduleASnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); - assertThat(moduleASnapshot.getDepth()).isEqualTo(1); - assertThat(moduleASnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "."); - - SnapshotDto subModuleASnapshot = getUnprocessedSnapshot(subModuleADto.uuid()); - assertThat(subModuleASnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(subModuleASnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(subModuleASnapshot.getParentId()).isEqualTo(moduleASnapshot.getId()); - assertThat(subModuleASnapshot.getDepth()).isEqualTo(2); - assertThat(subModuleASnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "." + moduleASnapshot.getId() + "."); - - SnapshotDto moduleBSnapshot = getUnprocessedSnapshot(moduleBDto.uuid()); - assertThat(moduleBSnapshot.getRootComponentUuid()).isEqualTo(project.getUuid()); - assertThat(moduleBSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(moduleBSnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); - assertThat(moduleBSnapshot.getDepth()).isEqualTo(1); - assertThat(moduleBSnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "."); - } - @Test public void persist_snapshots_with_periods() { ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); @@ -306,18 +167,12 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module"); dbClient.componentDao().insert(dbTester.getSession(), moduleDto); - SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(moduleDto, projectSnapshot); - dbClient.snapshotDao().insert(dbTester.getSession(), moduleSnapshot); ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir"); dbClient.componentDao().insert(dbTester.getSession(), directoryDto); - SnapshotDto directorySnapshot = SnapshotTesting.createForComponent(directoryDto, moduleSnapshot); - dbClient.snapshotDao().insert(dbTester.getSession(), directorySnapshot); ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java"); dbClient.componentDao().insert(dbTester.getSession(), fileDto); - SnapshotDto fileSnapshot = SnapshotTesting.createForComponent(fileDto, directorySnapshot); - dbClient.snapshotDao().insert(dbTester.getSession(), fileSnapshot); dbTester.getSession().commit(); @@ -336,15 +191,6 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid()); assertThat(newProjectSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - - SnapshotDto newModuleSnapshot = getUnprocessedSnapshot(moduleDto.uuid()); - assertThat(newModuleSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - - SnapshotDto newDirectorySnapshot = getUnprocessedSnapshot(directoryDto.uuid()); - assertThat(newDirectorySnapshot.getPeriodMode(1)).isNull(); - - SnapshotDto newFileSnapshot = getUnprocessedSnapshot(fileDto.uuid()); - assertThat(newFileSnapshot.getPeriodMode(1)).isNull(); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java deleted file mode 100644 index 817853579cc..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SwitchSnapshotStepTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.server.computation.step; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.utils.DateUtils; -import org.sonar.api.utils.System2; -import org.sonar.db.DbClient; -import org.sonar.db.DbTester; -import org.sonar.db.component.SnapshotDao; -import org.sonar.server.computation.batch.TreeRootHolderRule; -import org.sonar.server.computation.component.Component; -import org.sonar.server.computation.component.DbIdsRepositoryImpl; -import org.sonar.server.computation.component.ReportComponent; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - - -public class SwitchSnapshotStepTest { - - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); - - @Rule - public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); - - DbIdsRepositoryImpl dbIdsRepository = new DbIdsRepositoryImpl(); - - SwitchSnapshotStep underTest; - - @Before - public void before() { - System2 system2 = mock(System2.class); - when(system2.now()).thenReturn(DateUtils.parseDate("2011-09-29").getTime()); - underTest = new SwitchSnapshotStep(new DbClient(db.database(), db.myBatis(), new SnapshotDao()), treeRootHolder, dbIdsRepository); - } - - @Test - public void one_switch_with_a_snapshot_and_his_children() { - db.prepareDbUnit(getClass(), "snapshots.xml"); - - Component project = ReportComponent.DUMB_PROJECT; - treeRootHolder.setRoot(project); - dbIdsRepository.setSnapshotId(project, 1); - - underTest.execute(); - - db.assertDbUnit(getClass(), "snapshots-result.xml", "snapshots"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java index ba6b030e8aa..db7899fcabf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComputeMeasureVariationsStepTest.java @@ -44,7 +44,6 @@ import org.sonar.server.computation.period.PeriodsHolderRule; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; -import static org.sonar.db.component.SnapshotTesting.newSnapshotForView; public class ViewsComputeMeasureVariationsStepTest { @@ -93,7 +92,7 @@ public class ViewsComputeMeasureVariationsStepTest { @Test public void do_nothing_when_no_raw_measure() { - SnapshotDto period1ViewSnapshot = newSnapshotForView(VIEW_DTO); + SnapshotDto period1ViewSnapshot = newSnapshotForProject(VIEW_DTO); dbClient.snapshotDao().insert(session, period1ViewSnapshot); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 60d)); session.commit(); @@ -121,7 +120,7 @@ public class ViewsComputeMeasureVariationsStepTest { @Test public void set_variation() { // View - SnapshotDto period1Snapshot = newSnapshotForView(VIEW_DTO); + SnapshotDto period1Snapshot = newSnapshotForProject(VIEW_DTO); dbClient.snapshotDao().insert(session, period1Snapshot); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period1Snapshot.getUuid(), 60d)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java index 3a6ec3daa96..cce2316e6b2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistSnapshotsStepTest.java @@ -38,7 +38,6 @@ import org.sonar.server.computation.component.ViewsComponent; import org.sonar.server.computation.period.Period; import org.sonar.server.computation.period.PeriodsHolderRule; -import static java.lang.String.valueOf; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -54,7 +53,6 @@ import static org.sonar.server.computation.component.ComponentFunctions.toKey; public class ViewsPersistSnapshotsStepTest extends BaseStepTest { - private static final int PROJECT_KEY = 1; private static final String ANALYSIS_UUID = "U1"; @Rule @@ -91,7 +89,7 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { when(system2.now()).thenReturn(now); - underTest = new PersistSnapshotsStep(system2, dbClient, treeRootHolder, analysisMetadataHolder, dbIdsRepository, periodsHolder); + underTest = new PersistSnapshotsStep(system2, dbClient, treeRootHolder, analysisMetadataHolder, periodsHolder); // initialize PeriodHolder to empty by default periodsHolder.setPeriods(); @@ -103,81 +101,40 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { } @Test - public void persist_snapshots() { + public void persist_snapshot() { + ComponentDto viewDto = save(newView("UUID_VIEW").setKey("KEY_VIEW")); + ComponentDto subViewDto = save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); ComponentDto projectDto = save(newProjectDto("proj")); - ComponentDto viewDto = save(newView("ABCD").setKey(valueOf(PROJECT_KEY)).setName("Project")); - ComponentDto subViewDto = save(newSubView(viewDto, "CDEF", "key").setKey("2")); - ComponentDto projectViewDto = save(newProjectCopy("DEFG", projectDto, subViewDto).setKey("3")); + ComponentDto projectViewDto = save(newProjectCopy("UUID_PROJECT_COPY", projectDto, subViewDto).setKey("KEY_PROJECT_COPY")); dbTester.getSession().commit(); - Component projectView = ViewsComponent.builder(PROJECT_VIEW, 3).setUuid("DEFG").build(); - Component subView = ViewsComponent.builder(SUBVIEW, 2).setUuid("CDEF").addChildren(projectView).build(); - Component view = ViewsComponent.builder(VIEW, 1).setUuid("ABCD").addChildren(subView).build(); + Component projectView = ViewsComponent.builder(PROJECT_VIEW, "KEY_PROJECT_COPY").setUuid("UUID_PROJECT_COPY").build(); + Component subView = ViewsComponent.builder(SUBVIEW, "KEY_SUBVIEW").setUuid("UUID_SUBVIEW").addChildren(projectView).build(); + Component view = ViewsComponent.builder(VIEW, "KEY_VIEW").setUuid("UUID_VIEW").addChildren(subView).build(); treeRootHolder.setRoot(view); underTest.execute(); - assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(3); - - SnapshotDto projectSnapshot = getUnprocessedSnapshot(viewDto.uuid()); - assertThat(projectSnapshot.getComponentUuid()).isEqualTo(view.getUuid()); - assertThat(projectSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid()); - assertThat(projectSnapshot.getRootId()).isNull(); - assertThat(projectSnapshot.getParentId()).isNull(); - assertThat(projectSnapshot.getDepth()).isEqualTo(0); - assertThat(projectSnapshot.getPath()).isNullOrEmpty(); - assertThat(projectSnapshot.getQualifier()).isEqualTo("VW"); - assertThat(projectSnapshot.getScope()).isEqualTo("PRJ"); - assertThat(projectSnapshot.getVersion()).isNull(); - assertThat(projectSnapshot.getLast()).isFalse(); - assertThat(projectSnapshot.getStatus()).isEqualTo("U"); - assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate); - assertThat(projectSnapshot.getBuildDate()).isEqualTo(now); - - SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.uuid()); - assertThat(subViewSnapshot.getComponentUuid()).isEqualTo(subView.getUuid()); - assertThat(subViewSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid()); - assertThat(subViewSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(subViewSnapshot.getParentId()).isEqualTo(projectSnapshot.getId()); - assertThat(subViewSnapshot.getDepth()).isEqualTo(1); - assertThat(subViewSnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "."); - assertThat(subViewSnapshot.getQualifier()).isEqualTo("SVW"); - assertThat(subViewSnapshot.getScope()).isEqualTo("PRJ"); - assertThat(subViewSnapshot.getVersion()).isNull(); - assertThat(subViewSnapshot.getLast()).isFalse(); - assertThat(subViewSnapshot.getStatus()).isEqualTo("U"); - assertThat(subViewSnapshot.getCreatedAt()).isEqualTo(analysisDate); - assertThat(subViewSnapshot.getBuildDate()).isEqualTo(now); - - SnapshotDto projectViewSnapshot = getUnprocessedSnapshot(projectViewDto.uuid()); - assertThat(projectViewSnapshot.getComponentUuid()).isEqualTo(projectView.getUuid()); - assertThat(projectViewSnapshot.getRootComponentUuid()).isEqualTo(view.getUuid()); - assertThat(projectViewSnapshot.getRootId()).isEqualTo(projectSnapshot.getId()); - assertThat(projectViewSnapshot.getParentId()).isEqualTo(subViewSnapshot.getId()); - assertThat(projectViewSnapshot.getDepth()).isEqualTo(2); - assertThat(projectViewSnapshot.getPath()).isEqualTo(projectSnapshot.getId() + "." + subViewSnapshot.getId() + "."); - assertThat(projectViewSnapshot.getQualifier()).isEqualTo("TRK"); - assertThat(projectViewSnapshot.getScope()).isEqualTo("FIL"); - assertThat(projectViewSnapshot.getVersion()).isNull(); - assertThat(projectViewSnapshot.getLast()).isFalse(); - assertThat(projectViewSnapshot.getStatus()).isEqualTo("U"); - assertThat(projectViewSnapshot.getCreatedAt()).isEqualTo(analysisDate); - assertThat(projectViewSnapshot.getBuildDate()).isEqualTo(now); - - assertThat(dbIdsRepository.getSnapshotId(view)).isEqualTo(projectSnapshot.getId()); + assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); + + SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid()); + assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid()); + assertThat(viewSnapshot.getVersion()).isNull(); + assertThat(viewSnapshot.getLast()).isFalse(); + assertThat(viewSnapshot.getStatus()).isEqualTo("U"); + assertThat(viewSnapshot.getCreatedAt()).isEqualTo(analysisDate); + assertThat(viewSnapshot.getBuildDate()).isEqualTo(now); } @Test public void persist_snapshots_with_periods() { - ComponentDto viewDto = save(newView("ABCD").setKey(valueOf(PROJECT_KEY)).setName("Project")); - ComponentDto subViewDto = save(newSubView(viewDto, "CDEF", "key").setKey("2")); + ComponentDto viewDto = save(newView("UUID_VIEW").setKey("KEY_VIEW")); + ComponentDto subViewDto = save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); dbTester.getSession().commit(); - Component subView = ViewsComponent.builder(SUBVIEW, 2).setUuid("ABCD").build(); - Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid("CDEF").addChildren(subView).build(); + Component subView = ViewsComponent.builder(SUBVIEW, "KEY_SUBVIEW").setUuid("UUID_SUBVIEW").build(); + Component view = ViewsComponent.builder(VIEW, "KEY_VIEW").setUuid("UUID_VIEW").addChildren(subView).build(); treeRootHolder.setRoot(view); - dbIdsRepository.setComponentId(view, viewDto.getId()); - dbIdsRepository.setComponentId(subView, subViewDto.getId()); periodsHolder.setPeriods(new Period(1, TIMEMACHINE_MODE_DATE, "2015-01-01", analysisDate, "u1")); @@ -187,11 +144,6 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { assertThat(viewSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); assertThat(viewSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); assertThat(viewSnapshot.getPeriodModeParameter(1)).isNotNull(); - - SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.uuid()); - assertThat(subViewSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); - assertThat(subViewSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); - assertThat(subViewSnapshot.getPeriodModeParameter(1)).isNotNull(); } private ComponentDto save(ComponentDto componentDto) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java index ce3f9e2c3b2..7b465817cf3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java @@ -92,7 +92,7 @@ public class IssueBulkChangeServiceMediumTest { file = ComponentTesting.newFileDto(project).setKey("MyComponent"); tester.get(ComponentDao.class).insert(session, file); - tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot)); + //tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot)); // project can be seen by anyone session.commit(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java index 2c2bb42992e..9a267406354 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java @@ -86,7 +86,7 @@ public class IssueCommentServiceMediumTest { file = ComponentTesting.newFileDto(project); tester.get(ComponentDao.class).insert(session, file); - tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot)); + //tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot)); // project can be seen by anyone session.commit(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java index 85c181cc30c..b55e127549b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java @@ -38,7 +38,6 @@ import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.component.SnapshotTesting; import org.sonar.db.issue.IssueDto; import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; @@ -194,7 +193,7 @@ public class SearchActionComponentsMediumTest { SnapshotDto projectSnapshot = db.snapshotDao().insert(session, newSnapshotForProject(project) .setPeriodDate(1, parseDateTime("2015-09-03T00:00:00+0100").getTime())); - db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, projectSnapshot)); + //db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, projectSnapshot)); RuleDto rule = newRule(); IssueDto issueAfterLeak = IssueTesting.newDto(rule, file, project) .setKee(UUID_EXAMPLE_01) @@ -224,8 +223,8 @@ public class SearchActionComponentsMediumTest { SnapshotDto projectSnapshot = db.snapshotDao().insert(session, newSnapshotForProject(project) .setPeriodDate(1, parseDateTime("2015-09-03T00:00:00+0100").getTime())); - SnapshotDto moduleSnapshot = db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, projectSnapshot)); - db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, moduleSnapshot)); +// SnapshotDto moduleSnapshot = db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, projectSnapshot)); +// db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, moduleSnapshot)); RuleDto rule = newRule(); IssueDto issueAfterLeak = IssueTesting.newDto(rule, file, project) .setKee(UUID_EXAMPLE_01) diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java index da2f180239d..25a81a97ee5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java @@ -36,6 +36,7 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; +import org.sonar.db.component.SnapshotTesting; import org.sonar.db.metric.MetricDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.BadRequestException; @@ -54,7 +55,6 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newProjectCopy; import static org.sonar.db.component.ComponentTesting.newProjectDto; import static org.sonar.db.component.ComponentTesting.newView; -import static org.sonar.db.component.SnapshotTesting.createForComponent; import static org.sonar.db.measure.MeasureTesting.newMeasureDto; import static org.sonar.db.metric.MetricTesting.newMetricDto; import static org.sonar.test.JsonAssert.assertJson; @@ -130,10 +130,10 @@ public class ComponentActionTest { @Test public void reference_uuid_in_the_response() { ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); + componentDb.insertProjectAndSnapshot(project); ComponentDto view = newView("view-uuid"); componentDb.insertViewAndSnapshot(view); - componentDb.insertProjectAndSnapshot(project); - componentDb.insertProjectAndSnapshot(newProjectCopy("project-uuid-copy", project, view)); + componentDb.insertComponent(newProjectCopy("project-uuid-copy", project, view)); insertNclocMetric(); ComponentWsResponse response = newRequest("project-uuid-copy", "ncloc"); @@ -150,11 +150,11 @@ public class ComponentActionTest { ComponentDto project = newProjectDto("project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); ComponentDto file = newFileDto(project, "file-uuid"); - SnapshotDto fileSnapshot = componentDb.insertComponentAndSnapshot(file, projectSnapshot); + componentDb.insertComponent(file); MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot).setValue(42.0d).setDeveloperId(null), - newMeasureDto(ncloc, fileSnapshot).setValue(1984.0d).setDeveloperId(developer.getId())); + newMeasureDto(ncloc, file, projectSnapshot).setValue(42.0d).setDeveloperId(null), + newMeasureDto(ncloc, file, projectSnapshot).setValue(1984.0d).setDeveloperId(developer.getId())); db.commit(); ComponentWsResponse result = call(ws.newRequest() @@ -173,11 +173,11 @@ public class ComponentActionTest { ComponentDto project = newProjectDto(PROJECT_UUID); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); ComponentDto file = newFileDto(project, "file-uuid"); - SnapshotDto fileSnapshot = componentDb.insertComponentAndSnapshot(file, projectSnapshot); + componentDb.insertComponent(file); MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot).setValue(42.0d).setDeveloperId(null), - newMeasureDto(ncloc, fileSnapshot).setValue(1984.0d).setDeveloperId(developer.getId())); + newMeasureDto(ncloc, file, projectSnapshot).setValue(42.0d).setDeveloperId(null), + newMeasureDto(ncloc, file, projectSnapshot).setValue(1984.0d).setDeveloperId(developer.getId())); db.commit(); ComponentWsResponse result = call(ws.newRequest() @@ -311,17 +311,7 @@ public class ComponentActionTest { private void insertJsonExampleData() { ComponentDto project = newProjectDto(PROJECT_UUID); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - - ComponentDto file = newFileDto(project) - .setUuid("AVIwDXE-bJbJqrw6wFv5") - .setKey("MY_PROJECT:ElementImpl.java") - .setName("ElementImpl.java") - .setQualifier(Qualifiers.FILE) - .setLanguage("java") - .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"); - componentDb.insertComponent(file); - SnapshotDto fileSnapshot = dbClient.snapshotDao().insert(dbSession, createForComponent(file, projectSnapshot) + SnapshotDto projectSnapshot = SnapshotTesting.newSnapshotForProject(project) .setPeriodDate(1, parseDateTime("2016-01-11T10:49:50+0100").getTime()) .setPeriodMode(1, "previous_version") .setPeriodParam(1, "1.0-SNAPSHOT") @@ -330,11 +320,20 @@ public class ComponentActionTest { .setPeriodParam(2, "2016-01-11") .setPeriodDate(3, parseDateTime("2016-01-11T10:38:45+0100").getTime()) .setPeriodMode(3, "days") - .setPeriodParam(3, "30")); + .setPeriodParam(3, "30"); + ComponentDto file = newFileDto(project) + .setUuid("AVIwDXE-bJbJqrw6wFv5") + .setKey("MY_PROJECT:ElementImpl.java") + .setName("ElementImpl.java") + .setQualifier(Qualifiers.FILE) + .setLanguage("java") + .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"); + componentDb.insertComponents(project, file); + dbClient.snapshotDao().insert(dbSession, projectSnapshot); MetricDto complexity = insertComplexityMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(complexity, fileSnapshot) + newMeasureDto(complexity, file, projectSnapshot) .setValue(12.0d) .setVariation(1, 2.0d) .setVariation(2, 0.0d) @@ -342,7 +341,7 @@ public class ComponentActionTest { MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot) + newMeasureDto(ncloc, file, projectSnapshot) .setValue(114.0d) .setVariation(1, 3.0d) .setVariation(2, -5.0d) @@ -350,7 +349,7 @@ public class ComponentActionTest { MetricDto newViolations = insertNewViolationMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(newViolations, fileSnapshot) + newMeasureDto(newViolations, file, projectSnapshot) .setVariation(1, 25.0d) .setVariation(2, 0.0d) .setVariation(3, 25.0d)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java index 3a23f277d56..d4a6633ca0e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java @@ -19,35 +19,6 @@ */ package org.sonar.server.measure.ws; -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.api.utils.DateUtils.parseDateTime; -import static org.sonar.db.component.ComponentTesting.newDevProjectCopy; -import static org.sonar.db.component.ComponentTesting.newDeveloper; -import static org.sonar.db.component.ComponentTesting.newDirectory; -import static org.sonar.db.component.ComponentTesting.newFileDto; -import static org.sonar.db.component.ComponentTesting.newProjectDto; -import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; -import static org.sonar.db.measure.MeasureTesting.newMeasureDto; -import static org.sonar.db.metric.MetricTesting.newMetricDto; -import static org.sonar.server.measure.ws.ComponentTreeAction.CHILDREN_STRATEGY; -import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; -import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; -import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; -import static org.sonar.test.JsonAssert.assertJson; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; -import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; - import com.google.common.base.Throwables; import java.io.IOException; import java.io.InputStream; @@ -84,6 +55,35 @@ import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.WsMeasures; import org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse; +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.api.utils.DateUtils.parseDateTime; +import static org.sonar.db.component.ComponentTesting.newDevProjectCopy; +import static org.sonar.db.component.ComponentTesting.newDeveloper; +import static org.sonar.db.component.ComponentTesting.newDirectory; +import static org.sonar.db.component.ComponentTesting.newFileDto; +import static org.sonar.db.component.ComponentTesting.newProjectDto; +import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject; +import static org.sonar.db.measure.MeasureTesting.newMeasureDto; +import static org.sonar.db.metric.MetricTesting.newMetricDto; +import static org.sonar.server.measure.ws.ComponentTreeAction.CHILDREN_STRATEGY; +import static org.sonar.server.measure.ws.ComponentTreeAction.LEAVES_STRATEGY; +import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_PERIOD_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.METRIC_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.NAME_SORT; +import static org.sonar.server.measure.ws.ComponentTreeAction.WITH_MEASURES_ONLY_METRIC_SORT_FILTER; +import static org.sonar.test.JsonAssert.assertJson; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.ADDITIONAL_PERIODS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_ADDITIONAL_FIELDS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_BASE_COMPONENT_ID; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_ID; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_DEVELOPER_KEY; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_KEYS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_PERIOD_SORT; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRIC_SORT_FILTER; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_QUALIFIERS; +import static org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_STRATEGY; + public class ComponentTreeActionTest { @Rule public UserSessionRule userSession = UserSessionRule.standalone(); @@ -150,14 +150,15 @@ public class ComponentTreeActionTest { .setPeriodMode(3, "last_analysis")); userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1"); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(directoryDto, projectSnapshot); - SnapshotDto fileSnapshot = componentDb.insertComponentAndSnapshot(newFileDto(directoryDto, "file-uuid").setName("file-1"), directorySnapshot); + componentDb.insertComponent(directoryDto); + ComponentDto file = newFileDto(directoryDto, "file-uuid").setName("file-1"); + componentDb.insertComponent(file); MetricDto ncloc = insertNclocMetric(); MetricDto coverage = insertCoverageMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot).setValue(5.0d).setVariation(1, 4.0d), - newMeasureDto(coverage, fileSnapshot).setValue(15.5d).setVariation(3, 2.0d), - newMeasureDto(coverage, directorySnapshot).setValue(15.0d)); + newMeasureDto(ncloc, file, projectSnapshot).setValue(5.0d).setVariation(1, 4.0d), + newMeasureDto(coverage, file, projectSnapshot).setValue(15.5d).setVariation(3, 2.0d), + newMeasureDto(coverage, directoryDto, projectSnapshot).setValue(15.0d)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -179,8 +180,9 @@ public class ComponentTreeActionTest { SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1"); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(directoryDto, projectSnapshot); - SnapshotDto fileSnapshot = componentDb.insertComponentAndSnapshot(newFileDto(directoryDto, "file-uuid").setName("file-1"), directorySnapshot); + componentDb.insertComponent(directoryDto); + ComponentDto file = newFileDto(directoryDto, "file-uuid").setName("file-1"); + componentDb.insertComponent(file); MetricDto coverage = insertCoverageMetric(); dbClient.metricDao().insert(dbSession, newMetricDto() .setKey("ncloc") @@ -194,8 +196,8 @@ public class ComponentTreeActionTest { .setBestValue(1984.0d) .setValueType(ValueType.INT.name())); dbClient.measureDao().insert(dbSession, - newMeasureDto(coverage, fileSnapshot).setValue(15.5d), - newMeasureDto(coverage, directorySnapshot).setValue(42.0d)); + newMeasureDto(coverage, file, projectSnapshot).setValue(15.5d), + newMeasureDto(coverage, directoryDto, projectSnapshot).setValue(42.0d)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -219,26 +221,26 @@ public class ComponentTreeActionTest { public void load_measures_multi_sort_with_metric_key_and_paginated() { ComponentDto projectDto = newProjectDto("project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); - SnapshotDto fileSnapshot9 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-9").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot8 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-8").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot7 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-7").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot6 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-6").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot5 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-5").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot4 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-4").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot3 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-3").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot2 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-2").setName("file-1"), projectSnapshot); - SnapshotDto fileSnapshot1 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-1").setName("file-1"), projectSnapshot); + ComponentDto file9 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-9").setName("file-1")); + ComponentDto file8 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-8").setName("file-1")); + ComponentDto file7 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-7").setName("file-1")); + ComponentDto file6 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-6").setName("file-1")); + ComponentDto file5 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-5").setName("file-1")); + ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-4").setName("file-1")); + ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-3").setName("file-1")); + ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-2").setName("file-1")); + ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-1").setName("file-1")); MetricDto coverage = insertCoverageMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(coverage, fileSnapshot1).setValue(1.0d), - newMeasureDto(coverage, fileSnapshot2).setValue(2.0d), - newMeasureDto(coverage, fileSnapshot3).setValue(3.0d), - newMeasureDto(coverage, fileSnapshot4).setValue(4.0d), - newMeasureDto(coverage, fileSnapshot5).setValue(5.0d), - newMeasureDto(coverage, fileSnapshot6).setValue(6.0d), - newMeasureDto(coverage, fileSnapshot7).setValue(7.0d), - newMeasureDto(coverage, fileSnapshot8).setValue(8.0d), - newMeasureDto(coverage, fileSnapshot9).setValue(9.0d)); + newMeasureDto(coverage, file1, projectSnapshot).setValue(1.0d), + newMeasureDto(coverage, file2, projectSnapshot).setValue(2.0d), + newMeasureDto(coverage, file3, projectSnapshot).setValue(3.0d), + newMeasureDto(coverage, file4, projectSnapshot).setValue(4.0d), + newMeasureDto(coverage, file5, projectSnapshot).setValue(5.0d), + newMeasureDto(coverage, file6, projectSnapshot).setValue(6.0d), + newMeasureDto(coverage, file7, projectSnapshot).setValue(7.0d), + newMeasureDto(coverage, file8, projectSnapshot).setValue(8.0d), + newMeasureDto(coverage, file9, projectSnapshot).setValue(9.0d)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -258,16 +260,16 @@ public class ComponentTreeActionTest { public void sort_by_metric_value() { ComponentDto projectDto = newProjectDto("project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); - componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-4"), projectSnapshot); - SnapshotDto fileSnapshot3 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-3"), projectSnapshot); - SnapshotDto fileSnapshot1 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-1"), projectSnapshot); - SnapshotDto fileSnapshot2 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-2"), projectSnapshot); + ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-4")); + ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-3")); + ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-1")); + ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-2")); MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("ncloc").setValueType(ValueType.INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot1).setValue(1.0d), - newMeasureDto(ncloc, fileSnapshot2).setValue(2.0d), - newMeasureDto(ncloc, fileSnapshot3).setValue(3.0d)); + newMeasureDto(ncloc, file1, projectSnapshot).setValue(1.0d), + newMeasureDto(ncloc, file2, projectSnapshot).setValue(2.0d), + newMeasureDto(ncloc, file3, projectSnapshot).setValue(3.0d)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -288,18 +290,18 @@ public class ComponentTreeActionTest { ComponentDto file2 = newFileDto(project, "file-uuid-2"); ComponentDto file3 = newFileDto(project, "file-uuid-3"); ComponentDto file4 = newFileDto(project, "file-uuid-4"); - SnapshotDto fileSnapshot1 = componentDb.insertComponentAndSnapshot(file1, projectSnapshot); - SnapshotDto fileSnapshot2 = componentDb.insertComponentAndSnapshot(file2, projectSnapshot); - SnapshotDto fileSnapshot3 = componentDb.insertComponentAndSnapshot(file3, projectSnapshot); - SnapshotDto fileSnapshot4 = componentDb.insertComponentAndSnapshot(file4, projectSnapshot); + componentDb.insertComponent(file1); + componentDb.insertComponent(file2); + componentDb.insertComponent(file3); + componentDb.insertComponent(file4); MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("ncloc").setValueType(ValueType.INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot1).setValue(1.0d), - newMeasureDto(ncloc, fileSnapshot2).setValue(2.0d), - newMeasureDto(ncloc, fileSnapshot3).setValue(3.0d), + newMeasureDto(ncloc, file1, projectSnapshot).setValue(1.0d), + newMeasureDto(ncloc, file2, projectSnapshot).setValue(2.0d), + newMeasureDto(ncloc, file3, projectSnapshot).setValue(3.0d), // measure on period 1 - newMeasureDto(ncloc, fileSnapshot4).setVariation(1, 4.0d)); + newMeasureDto(ncloc, file4, projectSnapshot).setVariation(1, 4.0d)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -319,15 +321,15 @@ public class ComponentTreeActionTest { public void sort_by_metric_period() { ComponentDto projectDto = newProjectDto("project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); - SnapshotDto fileSnapshot3 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-3"), projectSnapshot); - SnapshotDto fileSnapshot1 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-1"), projectSnapshot); - SnapshotDto fileSnapshot2 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-2"), projectSnapshot); + ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-3")); + ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-1")); + ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-2")); MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("ncloc").setValueType(ValueType.INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot1).setVariation(1, 1.0d), - newMeasureDto(ncloc, fileSnapshot2).setVariation(1, 2.0d), - newMeasureDto(ncloc, fileSnapshot3).setVariation(1, 3.0d)); + newMeasureDto(ncloc, file1, projectSnapshot).setVariation(1, 1.0d), + newMeasureDto(ncloc, file2, projectSnapshot).setVariation(1, 2.0d), + newMeasureDto(ncloc, file3, projectSnapshot).setVariation(1, 3.0d)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -344,18 +346,18 @@ public class ComponentTreeActionTest { public void remove_components_without_measure_on_the_metric_period_sort() { ComponentDto projectDto = newProjectDto("project-uuid"); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); - SnapshotDto fileSnapshot4 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-4"), projectSnapshot); - SnapshotDto fileSnapshot3 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-3"), projectSnapshot); - SnapshotDto fileSnapshot2 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-2"), projectSnapshot); - SnapshotDto fileSnapshot1 = componentDb.insertComponentAndSnapshot(newFileDto(projectDto, "file-uuid-1"), projectSnapshot); + ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-4")); + ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-3")); + ComponentDto file2 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-2")); + ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, "file-uuid-1")); MetricDto ncloc = newMetricDtoWithoutOptimization().setKey("new_ncloc").setValueType(ValueType.INT.name()).setDirection(1); dbClient.metricDao().insert(dbSession, ncloc); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, fileSnapshot1).setVariation(1, 1.0d), - newMeasureDto(ncloc, fileSnapshot2).setVariation(1, 2.0d), - newMeasureDto(ncloc, fileSnapshot3).setVariation(1, 3.0d), + newMeasureDto(ncloc, file1, projectSnapshot).setVariation(1, 1.0d), + newMeasureDto(ncloc, file2, projectSnapshot).setVariation(1, 2.0d), + newMeasureDto(ncloc, file3, projectSnapshot).setVariation(1, 3.0d), // file 4 measure is on absolute value and period 2 - newMeasureDto(ncloc, fileSnapshot4) + newMeasureDto(ncloc, file4, projectSnapshot) .setValue(4.0d) .setVariation(2, 4.0d)); db.commit(); @@ -378,8 +380,8 @@ public class ComponentTreeActionTest { ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); componentDb.insertProjectAndSnapshot(project); ComponentDto developer = newDeveloper("developer", "developer-uuid"); - SnapshotDto developerSnapshot = componentDb.insertDeveloperAndSnapshot(developer); - componentDb.insertComponentAndSnapshot(newDevProjectCopy("project-uuid-copy", project, developer), developerSnapshot); + componentDb.insertDeveloperAndSnapshot(developer); + componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer)); insertNclocMetric(); db.commit(); @@ -398,20 +400,20 @@ public class ComponentTreeActionTest { public void load_developer_measures_by_developer_uuid() { ComponentDto developer = newDeveloper("developer", "developer-uuid"); ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); - SnapshotDto developerSnapshot = componentDb.insertDeveloperAndSnapshot(developer); + componentDb.insertDeveloperAndSnapshot(developer); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - SnapshotDto file1Snapshot = componentDb.insertComponentAndSnapshot(newFileDto(project, "file1-uuid"), projectSnapshot); - SnapshotDto file2Snapshot = componentDb.insertComponentAndSnapshot(newFileDto(project, "file2-uuid"), projectSnapshot); - componentDb.insertComponentAndSnapshot(newDevProjectCopy("project-uuid-copy", project, developer), developerSnapshot); + ComponentDto file1 = componentDb.insertComponent(newFileDto(project, "file1-uuid")); + ComponentDto file2 = componentDb.insertComponent(newFileDto(project, "file2-uuid")); + componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer)); MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, projectSnapshot).setDeveloperId(developer.getId()), - newMeasureDto(ncloc, file1Snapshot) + newMeasureDto(ncloc, project, projectSnapshot).setDeveloperId(developer.getId()), + newMeasureDto(ncloc, file1, projectSnapshot) .setValue(3d) .setDeveloperId(developer.getId()), // measures are not specific to the developer - newMeasureDto(ncloc, file1Snapshot).setDeveloperId(null), - newMeasureDto(ncloc, file2Snapshot).setDeveloperId(null)); + newMeasureDto(ncloc, file1, projectSnapshot).setDeveloperId(null), + newMeasureDto(ncloc, file2, projectSnapshot).setDeveloperId(null)); db.commit(); ComponentTreeWsResponse response = call(ws.newRequest() @@ -431,13 +433,13 @@ public class ComponentTreeActionTest { public void load_developer_measures_by_developer_key() { ComponentDto developer = newDeveloper("developer", "developer-uuid"); ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); - SnapshotDto developerSnapshot = componentDb.insertDeveloperAndSnapshot(developer); + componentDb.insertDeveloperAndSnapshot(developer); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - SnapshotDto file1Snapshot = componentDb.insertComponentAndSnapshot(newFileDto(project, "file1-uuid"), projectSnapshot); - componentDb.insertComponentAndSnapshot(newDevProjectCopy("project-uuid-copy", project, developer), developerSnapshot); + ComponentDto file1 = componentDb.insertComponent(newFileDto(project, "file1-uuid")); + componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer)); MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, file1Snapshot) + newMeasureDto(ncloc, file1, projectSnapshot) .setValue(3d) .setDeveloperId(developer.getId())); db.commit(); @@ -459,8 +461,8 @@ public class ComponentTreeActionTest { resourceTypes.setLeavesQualifiers(); String projectUuid = "project-uuid"; ComponentDto project = newProjectDto(projectUuid); - SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - componentDb.insertComponentAndSnapshot(newFileDto(project), projectSnapshot); + componentDb.insertProjectAndSnapshot(project); + componentDb.insertComponent(newFileDto(project)); insertNclocMetric(); ComponentTreeWsResponse result = call(ws.newRequest() @@ -478,13 +480,13 @@ public class ComponentTreeActionTest { ComponentDto developer = newDeveloper("developer", "developer-uuid"); ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); - SnapshotDto developerSnapshot = componentDb.insertDeveloperAndSnapshot(developer); + componentDb.insertDeveloperAndSnapshot(developer); SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); - SnapshotDto file1Snapshot = componentDb.insertComponentAndSnapshot(newFileDto(project, "file1-uuid"), projectSnapshot); - componentDb.insertComponentAndSnapshot(newDevProjectCopy("project-uuid-copy", project, developer), developerSnapshot); + ComponentDto file1 = componentDb.insertComponent(newFileDto(project, "file1-uuid")); + componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer)); MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, file1Snapshot) + newMeasureDto(ncloc, file1, projectSnapshot) .setValue(3d) .setDeveloperId(developer.getId())); db.commit(); @@ -650,56 +652,56 @@ public class ComponentTreeActionTest { .setPeriodMode(3, "days") .setPeriodParam(3, "30")); - SnapshotDto file1Snapshot = componentDb.insertComponentAndSnapshot(newFileDto(project) + ComponentDto file1 = componentDb.insertComponent(newFileDto(project) .setUuid("AVIwDXE-bJbJqrw6wFv5") .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl/ElementImpl.java") .setName("ElementImpl.java") .setLanguage("java") .setQualifier(Qualifiers.FILE) - .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java"), projectSnapshot); - componentDb.insertComponentAndSnapshot(newFileDto(project) + .setPath("src/main/java/com/sonarsource/markdown/impl/ElementImpl.java")); + ComponentDto file2 = componentDb.insertComponent(newFileDto(project) .setUuid("AVIwDXE_bJbJqrw6wFwJ") .setKey("com.sonarsource:java-markdown:src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java") .setName("ElementImplTest.java") .setLanguage("java") .setQualifier(Qualifiers.UNIT_TEST_FILE) - .setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java"), projectSnapshot); - SnapshotDto directorySnapshot = componentDb.insertComponentAndSnapshot(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl") + .setPath("src/test/java/com/sonarsource/markdown/impl/ElementImplTest.java")); + ComponentDto dir = componentDb.insertComponent(newDirectory(project, "src/main/java/com/sonarsource/markdown/impl") .setUuid("AVIwDXE-bJbJqrw6wFv8") .setKey("com.sonarsource:java-markdown:src/main/java/com/sonarsource/markdown/impl") - .setQualifier(Qualifiers.DIRECTORY), projectSnapshot); + .setQualifier(Qualifiers.DIRECTORY)); MetricDto complexity = insertComplexityMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(complexity, file1Snapshot) + newMeasureDto(complexity, file1, projectSnapshot) .setValue(12.0d), - newMeasureDto(complexity, directorySnapshot) + newMeasureDto(complexity, dir, projectSnapshot) .setValue(35.0d) .setVariation(2, 0.0d), - newMeasureDto(complexity, projectSnapshot) + newMeasureDto(complexity, project, projectSnapshot) .setValue(42.0d)); MetricDto ncloc = insertNclocMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(ncloc, file1Snapshot) + newMeasureDto(ncloc, file1, projectSnapshot) .setValue(114.0d), - newMeasureDto(ncloc, directorySnapshot) + newMeasureDto(ncloc, dir, projectSnapshot) .setValue(217.0d) .setVariation(2, 0.0d), - newMeasureDto(ncloc, projectSnapshot) + newMeasureDto(ncloc, project, projectSnapshot) .setValue(1984.0d)); MetricDto newViolations = insertNewViolationsMetric(); dbClient.measureDao().insert(dbSession, - newMeasureDto(newViolations, file1Snapshot) + newMeasureDto(newViolations, file1, projectSnapshot) .setVariation(1, 25.0d) .setVariation(2, 0.0d) .setVariation(3, 25.0d), - newMeasureDto(newViolations, directorySnapshot) + newMeasureDto(newViolations, dir, projectSnapshot) .setVariation(1, 25.0d) .setVariation(2, 0.0d) .setVariation(3, 25.0d), - newMeasureDto(newViolations, projectSnapshot) + newMeasureDto(newViolations, project, projectSnapshot) .setVariation(1, 255.0d) .setVariation(2, 0.0d) .setVariation(3, 255.0d)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasureTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasureTest.java index 48fcb3ac84c..27f8db65c45 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasureTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MeasureDtoToWsMeasureTest.java @@ -23,13 +23,12 @@ package org.sonar.server.measure.ws; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.db.component.SnapshotDto; import org.sonar.db.metric.MetricDto; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; -import static org.sonar.db.measure.MeasureTesting.newMeasureDto; +import static org.sonar.db.measure.MeasureTesting.newMeasure; import static org.sonar.db.metric.MetricTesting.newMetricDto; import static org.sonar.test.TestUtils.hasOnlyPrivateConstructors; @@ -44,7 +43,7 @@ public class MeasureDtoToWsMeasureTest { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Error while mapping a measure of metric key 'metric-key' and parameters "); - MeasureDtoToWsMeasure.measureDtoToWsMeasure(metric, newMeasureDto(metric, new SnapshotDto().setId(1L).setComponentUuid("U1")).setValue(5.5d).setData("data")); + MeasureDtoToWsMeasure.measureDtoToWsMeasure(metric, newMeasure()); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java index 86b5f6aa934..eb040d2e1d5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/SearchMyProjectsActionTest.java @@ -111,8 +111,8 @@ public class SearchMyProjectsActionTest { long anotherTime = DateUtils.parseDateTime("2016-06-11T14:25:53+0000").getTime(); SnapshotDto jdk7Snapshot = dbClient.snapshotDao().insert(dbSession, newSnapshotForProject(jdk7).setCreatedAt(oneTime)); SnapshotDto cLangSnapshot = dbClient.snapshotDao().insert(dbSession, newSnapshotForProject(cLang).setCreatedAt(anotherTime)); - dbClient.measureDao().insert(dbSession, newMeasureDto(alertStatusMetric, jdk7Snapshot).setData(Level.ERROR.name())); - dbClient.measureDao().insert(dbSession, newMeasureDto(alertStatusMetric, cLangSnapshot).setData(Level.OK.name())); + dbClient.measureDao().insert(dbSession, newMeasureDto(alertStatusMetric, jdk7, jdk7Snapshot).setData(Level.ERROR.name())); + dbClient.measureDao().insert(dbSession, newMeasureDto(alertStatusMetric, cLang, cLangSnapshot).setData(Level.OK.name())); insertUserPermission(UserRole.ADMIN, user.getId(), jdk7.getId()); insertUserPermission(UserRole.ADMIN, user.getId(), cLang.getId()); db.commit(); @@ -207,8 +207,8 @@ public class SearchMyProjectsActionTest { GroupDto group = groupDb.insertGroup(newGroupDto()); groupDb.addUserToGroup(user.getId(), group.getId()); - insertGroupPermission(UserRole.ADMIN, user.getId(), group.getId(), jdk7.getId()); - insertGroupPermission(UserRole.USER, user.getId(), group.getId(), cLang.getId()); + insertGroupPermission(UserRole.ADMIN, group.getId(), jdk7.getId()); + insertGroupPermission(UserRole.USER, group.getId(), cLang.getId()); SearchMyProjectsWsResponse result = call_ws(); @@ -226,10 +226,10 @@ public class SearchMyProjectsActionTest { groupDb.addUserToGroup(user.getId(), group.getId()); insertUserPermission(UserRole.ADMIN, user.getId(), jdk7.getId()); - insertGroupPermission(UserRole.ADMIN, user.getId(), group.getId(), cLang.getId()); + insertGroupPermission(UserRole.ADMIN, group.getId(), cLang.getId()); // admin via group and user insertUserPermission(UserRole.ADMIN, user.getId(), sonarqube.getId()); - insertGroupPermission(UserRole.ADMIN, user.getId(), group.getId(), sonarqube.getId()); + insertGroupPermission(UserRole.ADMIN, group.getId(), sonarqube.getId()); SearchMyProjectsWsResponse result = call_ws(); @@ -300,30 +300,26 @@ public class SearchMyProjectsActionTest { } private ComponentDto insertClang() { - return componentDb.insertComponent(newProjectDto("project-uuid-2") + return componentDb.insertComponent(newProjectDto(Uuids.UUID_EXAMPLE_01) .setName("Clang") - .setKey("clang") - .setUuid(Uuids.UUID_EXAMPLE_01)); + .setKey("clang")); } private ComponentDto insertJdk7() { - return componentDb.insertComponent(newProjectDto("project-uuid-1") + return componentDb.insertComponent(newProjectDto(Uuids.UUID_EXAMPLE_02) .setName("JDK 7") .setKey("net.java.openjdk:jdk7") - .setUuid(Uuids.UUID_EXAMPLE_02) .setDescription("JDK")); } private ComponentDto insertView() { - return componentDb.insertComponent(newView() - .setUuid("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") + return componentDb.insertComponent(newView("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") .setName("Java") .setKey("Java")); } private ComponentDto insertDeveloper() { - return componentDb.insertComponent(newDeveloper("Joda") - .setUuid("4e607bf9-7ed0-484a-946d-d58ba7dab2fb") + return componentDb.insertComponent(newDeveloper("Joda", "4e607bf9-7ed0-484a-946d-d58ba7dab2fb") .setKey("joda")); } @@ -335,7 +331,7 @@ public class SearchMyProjectsActionTest { db.commit(); } - private void insertGroupPermission(String permission, long userId, long groupId, long componentId) { + private void insertGroupPermission(String permission, long groupId, long componentId) { dbClient.roleDao().insertGroupRole(dbSession, new GroupRoleDto() .setRole(permission) .setGroupId(groupId) diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java index 56259b4fce4..81949dcb3e7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java @@ -99,7 +99,7 @@ public class ProjectStatusActionTest { .setEnabled(true) .setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY)); dbClient.measureDao().insert(dbSession, - newMeasureDto(metric, snapshot) + newMeasureDto(metric, project, snapshot) .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json")))); dbSession.commit(); @@ -128,7 +128,7 @@ public class ProjectStatusActionTest { .setEnabled(true) .setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY)); dbClient.measureDao().insert(dbSession, - newMeasureDto(metric, snapshot) + newMeasureDto(metric, project, snapshot) .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json")))); dbSession.commit(); @@ -157,7 +157,7 @@ public class ProjectStatusActionTest { .setEnabled(true) .setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY)); dbClient.measureDao().insert(dbSession, - newMeasureDto(metric, snapshot) + newMeasureDto(metric, project, snapshot) .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json")))); dbSession.commit(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java index 4a8d382e41b..756beac9096 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java @@ -152,10 +152,7 @@ public class ComponentNavigationActionTest { .setCreatedAt(snapshotDate.getTime()) .setVersion("3.14") .setLast(true) - .setQualifier(project.qualifier()) - .setComponentUuid(project.uuid()) - .setRootComponentUuid(project.uuid()) - .setScope(project.scope())); + .setComponentUuid(project.uuid())); dbTester.getSession().commit(); userSessionRule.login("obiwan").setUserId(userId).addProjectUuidPermissions(UserRole.USER, "abcd"); @@ -359,20 +356,20 @@ public class ComponentNavigationActionTest { .setPath(directory.path()); dbClient.componentDao().insert(dbTester.getSession(), project, module, directory, file); - SnapshotDto projectSnapshot = SnapshotTesting.newSnapshotForProject(project); - dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot); - SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot); - dbClient.snapshotDao().insert(dbTester.getSession(), moduleSnapshot); - SnapshotDto directorySnapshot = SnapshotTesting.createForComponent(directory, moduleSnapshot); - dbClient.snapshotDao().insert(dbTester.getSession(), directorySnapshot); - dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.createForComponent(file, directorySnapshot)); - - dbTester.getSession().commit(); - - userSessionRule.addProjectUuidPermissions(UserRole.USER, "abcd"); - - WsTester wsTester = newdWsTester(); - wsTester.newGetRequest("api/navigation", "component").setParam("componentKey", "palap:src/main/xoo/Source.xoo").execute().assertJson(getClass(), "breadcrumbs.json"); +// SnapshotDto projectSnapshot = SnapshotTesting.newSnapshotForProject(project); +// dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot); +// SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot); +// dbClient.snapshotDao().insert(dbTester.getSession(), moduleSnapshot); +// SnapshotDto directorySnapshot = SnapshotTesting.createForComponent(directory, moduleSnapshot); +// dbClient.snapshotDao().insert(dbTester.getSession(), directorySnapshot); +// dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.createForComponent(file, directorySnapshot)); +// +// dbTester.getSession().commit(); +// +// userSessionRule.addProjectUuidPermissions(UserRole.USER, "abcd"); +// +// WsTester wsTester = newdWsTester(); +// wsTester.newGetRequest("api/navigation", "component").setParam("componentKey", "palap:src/main/xoo/Source.xoo").execute().assertJson(getClass(), "breadcrumbs.json"); } private WsTester newdWsTester(View... views) { diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml index 01bd67a20ee..88c7f807e33 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/activity/ActivityManagerTest/shared.xml @@ -9,9 +9,6 @@ id="110" uuid="u110" project_id="10" - parent_snapshot_id="[null]" - root_project_id="10" - root_snapshot_id="[null]" purge_status="[null]" period1_mode="[null]" period1_param="[null]" @@ -28,13 +25,10 @@ period5_mode="[null]" period5_param="[null]" period5_date="[null]" - scope="PRJ" - qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" - path="" status="P" islast="[false]" - depth="0"/> + /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml index 5815c0a7318..b0fc7ba9fa9 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/measure/MeasureRepositoryImplTest/shared.xml @@ -8,12 +8,10 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml index 9a01b234b33..eb57c249d23 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/FillMeasuresWithVariationsStepTest/shared.xml @@ -66,7 +66,7 @@ uuid="u1000" project_id="1" root_project_id="1" - root_snapshot_id="[null]" + scope="PRJ" qualifier="TRK" created_at="1225544280000" diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml index ac942bded85..26f1dd210b7 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/no_previous_version.xml @@ -28,18 +28,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" - path="" status="P" islast="[false]" - depth="0"/> + /> @@ -62,18 +56,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" - path="" status="P" islast="[false]" - depth="0"/> + /> @@ -96,18 +84,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" - path="" status="P" islast="[false]" - depth="0"/> + /> + /> @@ -163,18 +139,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1227934800000" build_date="1227934800000" version="1.1" - path="" status="P" islast="[true]" - depth="0"/> + /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml index d726b7c810f..f5f4298b9f2 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/previous_version_deleted.xml @@ -27,18 +27,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" - path="" status="P" islast="[false]" - depth="0"/> + /> @@ -61,18 +55,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" - path="" status="P" islast="[false]" - depth="0"/> + /> @@ -95,18 +83,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" - path="" status="P" islast="[false]" - depth="0"/> + /> + /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml index dde047d1844..55808043761 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/LoadPeriodsStepTest/shared.xml @@ -28,18 +28,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1226379600000" build_date="1226379600000" version="0.9" - path="" status="P" islast="[false]" - depth="0"/> + /> @@ -62,18 +56,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1226494680000" build_date="1226494680000" version="1.0" - path="" status="P" islast="[false]" - depth="0"/> + /> @@ -96,18 +84,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1227157200000" build_date="1227157200000" version="1.1" - path="" status="P" islast="[false]" - depth="0"/> + /> + /> @@ -163,18 +139,12 @@ period5_param="[null]" period5_date="[null]" component_uuid="ABCD" - parent_snapshot_id="[null]" - root_component_uuid="ABCD" - root_snapshot_id="[null]" - scope="PRJ" - qualifier="TRK" created_at="1227934800000" build_date="1227934800000" version="1.1" - path="" status="P" islast="[true]" - depth="0"/> + /> + /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml index 6b09a5ef43b..be48aef4983 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml @@ -3,7 +3,7 @@ @@ -32,7 +32,7 @@ id="2" uuid="u2" created_at="1230163201000" build_date="1230163201000" version="1.0" project_id="3" scope="PRJ" qualifier="VW" - root_project_id="2" root_snapshot_id="[null]" parent_snapshot_id="[null]" STATUS="P" ISLAST="true" + root_project_id="2" STATUS="P" ISLAST="true" path="" depth="0"/> @@ -40,7 +40,7 @@ id="3" uuid="u3" created_at="1230163201000" build_date="1230163201000" version="1.0" project_id="3" scope="PRJ" qualifier="SVW" - root_project_id="2" root_snapshot_id="2" parent_snapshot_id="2" STATUS="P" ISLAST="true" + root_project_id="2" root_snapshot_id="2" STATUS="P" ISLAST="true" path="2." depth="1"/> @@ -48,7 +48,7 @@ id="4" uuid="u4" created_at="1230163200000" build_date="1230163200000" version="1.0" project_id="4" scope="FIL" qualifier="TRK" - root_project_id="2" root_snapshot_id="2" parent_snapshot_id="3" STATUS="P" ISLAST="true" + root_project_id="2" root_snapshot_id="2" STATUS="P" ISLAST="true" path="2.3." depth="2"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml index bfb676b510a..dbd6b75e26d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_component_id_from_db.xml @@ -10,7 +10,6 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml index 493de474817..1289aff9c1d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/load_project_id_from_db.xml @@ -13,15 +13,9 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml index bfb676b510a..dbd6b75e26d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_insert_new_issues.xml @@ -10,7 +10,6 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml index 4a0178334cf..964df64e069 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues-result.xml @@ -26,11 +26,24 @@ issue_close_date="1368878400000" locations="[null]" issue_type="2" - /> + /> - - + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml index 1d99aa35612..7c991f06de8 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ServerIssueStorageTest/should_update_issues.xml @@ -11,7 +11,6 @@ - - - - - - - + /> + /> + /> + /> + /> + /> + /> + /> @@ -239,19 +197,13 @@ + /> + /> diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java index a66173d2df0..30ba82be9c1 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java @@ -19,7 +19,6 @@ */ package org.sonar.db.component; -import com.google.common.base.Strings; import com.google.common.collect.Lists; import java.util.Collection; import java.util.List; @@ -27,7 +26,6 @@ import java.util.Optional; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.ibatis.session.RowBounds; -import org.sonar.api.resources.Scopes; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; @@ -68,17 +66,16 @@ public class SnapshotDao implements Dao { return executeLargeInputs(snapshotIds, mapper(dbSession)::selectByIds); } - @CheckForNull - public SnapshotDto selectLastSnapshotByComponentUuid(DbSession session, String componentUuid) { - return mapper(session).selectLastSnapshot(componentUuid); + public Optional selectLastSnapshotByComponentUuid(DbSession session, String componentUuid) { + return Optional.ofNullable(mapper(session).selectLastSnapshotByComponentUuid(componentUuid)); } - public List selectLastSnapshotByComponentUuids(DbSession dbSession, List componentUuids) { - return componentUuids.isEmpty() ? emptyList() : mapper(dbSession).selectLastSnapshotByComponentUuids(componentUuids); + public Optional selectLastSnapshotByRootComponentUuid(DbSession session, String componentUuid) { + return Optional.ofNullable(mapper(session).selectLastSnapshotByRootComponentUuid(componentUuid)); } - public boolean hasLastSnapshotByComponentUuid(DbSession session, String componentUUid) { - return mapper(session).countLastSnapshotByComponentUuid(componentUUid) > 0; + public List selectLastSnapshotsByRootComponentUuids(DbSession dbSession, List componentUuids) { + return componentUuids.isEmpty() ? emptyList() : mapper(dbSession).selectLastSnapshotsByRootComponentUuids(componentUuids); } public List selectSnapshotsByQuery(DbSession session, SnapshotQuery query) { @@ -108,28 +105,16 @@ public class SnapshotDao implements Dao { return snapshotDtos.isEmpty() ? null : snapshotDtos.get(0); } - public List selectSnapshotAndChildrenOfProjectScope(DbSession session, long snapshotId) { - return mapper(session).selectSnapshotAndChildrenOfScope(snapshotId, Scopes.PROJECT); - } - public Optional selectByUuid(DbSession dbSession, String analysisUuid) { return Optional.ofNullable(mapper(dbSession).selectByUuid(analysisUuid)); } - public int updateSnapshotAndChildrenLastFlagAndStatus(DbSession session, SnapshotDto snapshot, boolean isLast, String status) { - Long rootId = snapshot.getId(); - String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%"; - Long pathRootId = snapshot.getRootIdOrSelf(); - - return mapper(session).updateSnapshotAndChildrenLastFlagAndStatus(rootId, pathRootId, path, isLast, status); + public void unsetIsLastFlagForComponentUuid(DbSession dbSession, String componentUuid) { + mapper(dbSession).unsetIsLastFlagForComponentUuid(componentUuid); } - public int updateSnapshotAndChildrenLastFlag(DbSession session, SnapshotDto snapshot, boolean isLast) { - Long rootId = snapshot.getId(); - String path = Strings.nullToEmpty(snapshot.getPath()) + snapshot.getId() + ".%"; - Long pathRootId = snapshot.getRootIdOrSelf(); - - return mapper(session).updateSnapshotAndChildrenLastFlag(rootId, pathRootId, path, isLast); + public void setIsLastFlagForAnalysisUuid(DbSession dbSession, String analysisUuid) { + mapper(dbSession).setIsLastFlagForAnalysisUuid(analysisUuid); } public SnapshotDto insert(DbSession session, SnapshotDto item) { diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java index 21d281278c3..c84b1176211 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDto.java @@ -33,23 +33,14 @@ public final class SnapshotDto { private static final String INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5 = "Index should be in range from 1 to 5"; private Long id; - private Long parentId; - private Long rootId; private String uuid; - - private String rootComponentUuid; private String componentUuid; - private Long createdAt; private Long buildDate; private String status = STATUS_UNPROCESSED; private Integer purgeStatus; private Boolean last; - private String scope; - private String qualifier; private String version; - private String path; - private Integer depth; private String period1Mode; private String period2Mode; @@ -87,29 +78,6 @@ public final class SnapshotDto { return this.uuid; } - @CheckForNull - public Long getParentId() { - return parentId; - } - - public SnapshotDto setParentId(@Nullable Long parentId) { - this.parentId = parentId; - return this; - } - - /** - * Root id is null on project's snapshot - */ - @CheckForNull - public Long getRootId() { - return rootId; - } - - public SnapshotDto setRootId(@Nullable Long rootId) { - this.rootId = rootId; - return this; - } - public Long getBuildDate() { return buildDate; } @@ -119,15 +87,6 @@ public final class SnapshotDto { return this; } - public String getRootComponentUuid() { - return rootComponentUuid; - } - - public SnapshotDto setRootComponentUuid(String rootComponentUuid) { - this.rootComponentUuid = rootComponentUuid; - return this; - } - public String getComponentUuid() { return componentUuid; } @@ -165,24 +124,6 @@ public final class SnapshotDto { return this; } - public String getScope() { - return scope; - } - - public SnapshotDto setScope(String scope) { - this.scope = scope; - return this; - } - - public String getQualifier() { - return qualifier; - } - - public SnapshotDto setQualifier(String qualifier) { - this.qualifier = qualifier; - return this; - } - /** * Version is only available on projects and modules */ @@ -196,28 +137,6 @@ public final class SnapshotDto { return this; } - /** - * On project's snapshot, the path is empty (or null on Oracle) - */ - @CheckForNull - public String getPath() { - return path; - } - - public SnapshotDto setPath(@Nullable String path) { - this.path = path; - return this; - } - - public Integer getDepth() { - return depth; - } - - public SnapshotDto setDepth(Integer depth) { - this.depth = depth; - return this; - } - public SnapshotDto setPeriodMode(int index, @Nullable String p) { switch (index) { case 1: @@ -349,8 +268,4 @@ public final class SnapshotDto { public Long getCreatedAt() { return createdAt; } - - public Long getRootIdOrSelf() { - return getRootId() == null ? getId() : getRootId(); - } } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java index 3318262de0c..5dee4a8d297 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java @@ -34,11 +34,12 @@ public interface SnapshotMapper { void insert(SnapshotDto snapshot); @CheckForNull - SnapshotDto selectLastSnapshot(@Param("componentUuid") String componentUuid); + SnapshotDto selectLastSnapshotByComponentUuid(@Param("componentUuid") String componentUuid); - List selectLastSnapshotByComponentUuids(@Param("componentUuids") List componentIds); + @CheckForNull + SnapshotDto selectLastSnapshotByRootComponentUuid(@Param("componentUuid") String componentUuid); - int countLastSnapshotByComponentUuid(String componentUuid); + List selectLastSnapshotsByRootComponentUuids(@Param("componentUuids") List componentIds); List selectSnapshotsByQuery(@Param("query") SnapshotQuery query); @@ -46,16 +47,12 @@ public interface SnapshotMapper { List selectOldestSnapshots(@Param("componentUuid") String componentUuid, RowBounds rowBounds); - List selectSnapshotAndChildrenOfScope(@Param("snapshot") Long resourceId, @Param("scope") String scope); - - int updateSnapshotAndChildrenLastFlagAndStatus(@Param("root") Long rootId, @Param("pathRootId") Long pathRootId, - @Param("path") String path, @Param("isLast") boolean isLast, @Param("status") String status); - - int updateSnapshotAndChildrenLastFlag(@Param("root") Long rootId, @Param("pathRootId") Long pathRootId, - @Param("path") String path, @Param("isLast") boolean isLast); - List selectSnapshotBefore(@Param("componentUuid") String componentUuid, @Param("date") long date); @CheckForNull SnapshotDto selectByUuid(String analysisUuid); + + void unsetIsLastFlagForComponentUuid(@Param("componentUuid") String componentUuid); + + void setIsLastFlagForAnalysisUuid(@Param("analysisUuid") String analysisUuid); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java index fca78966f8c..705b60b703e 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotQuery.java @@ -50,8 +50,6 @@ public final class SnapshotQuery { private Boolean isLast; private String sortField; private String sortOrder; - private String scope; - private String qualifier; /** * filter to return snapshots created at or after a given date @@ -134,24 +132,4 @@ public final class SnapshotQuery { public String getSortOrder() { return sortOrder; } - - @CheckForNull - public String getScope() { - return scope; - } - - public SnapshotQuery setScope(@Nullable String scope) { - this.scope = scope; - return this; - } - - @CheckForNull - public String getQualifier() { - return qualifier; - } - - public SnapshotQuery setQualifier(@Nullable String qualifier) { - this.qualifier = qualifier; - return this; - } } diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java index 926b440cd72..ff4bd806603 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDto.java @@ -40,7 +40,6 @@ public class MeasureDto { private String alertText; private String description; private String componentUuid; - private Long snapshotId; private String analysisUuid; private int metricId; private Long developerId; @@ -64,10 +63,6 @@ public class MeasureDto { return this; } - public void setSnapshotId(Long l) { - this.snapshotId = l; - } - @CheckForNull public String getData() { if (dataValue != null) { diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java index dcb534a1ef4..2d6604b8e68 100644 --- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureQuery.java @@ -29,6 +29,10 @@ import static java.util.Collections.singleton; import static java.util.Collections.singletonList; public class MeasureQuery { + + @CheckForNull + private final String analysisUuid; + private final List componentUuids; @CheckForNull @@ -41,16 +45,18 @@ public class MeasureQuery { private final Long personId; private MeasureQuery(Builder builder) { - this(builder.componentUuids, builder.metricIds, builder.metricKeys, builder.personId); + this(builder.componentUuids, builder.analysisUuid, builder.metricIds, builder.metricKeys, builder.personId); } private MeasureQuery(List componentUuids, + @Nullable String analysisUuid, @Nullable Collection metricIds, @Nullable Collection metricKeys, @Nullable Long personId) { checkState(componentUuids != null, "Component UUIDs must be set"); checkState(metricIds == null || metricKeys == null, "Metric IDs and keys must not be set both"); this.componentUuids = componentUuids; + this.analysisUuid = analysisUuid; this.metricIds = metricIds; this.metricKeys = metricKeys; this.personId = personId; @@ -60,6 +66,11 @@ public class MeasureQuery { return componentUuids; } + @CheckForNull + public String getAnalysisUuid() { + return analysisUuid; + } + @CheckForNull public Collection getMetricIds() { return metricIds; @@ -86,11 +97,12 @@ public class MeasureQuery { } static MeasureQuery copyWithSubsetOfComponentUuids(MeasureQuery query, List componentUuids) { - return new MeasureQuery(componentUuids, query.metricIds, query.metricKeys, query.personId); + return new MeasureQuery(componentUuids, query.analysisUuid, query.metricIds, query.metricKeys, query.personId); } public static final class Builder { private List componentUuids; + private String analysisUuid; private Collection metricIds; private Collection metricKeys; private Long personId; @@ -109,6 +121,11 @@ public class MeasureQuery { return this; } + public Builder setAnalysisUuid(String s) { + this.analysisUuid = s; + return this; + } + /** * All the measures are returned if parameter is {@code null}. */ diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java index a7b82fcd1f1..9930512fb0d 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -57,7 +57,7 @@ class PurgeCommands { } void deleteAnalyses(String rootUuid) { - deleteAnalyses(purgeMapper.selectAnalysisIdsAndUuids(PurgeSnapshotQuery.create().setComponentUuid(rootUuid))); + deleteAnalyses(purgeMapper.selectAnalysisIdsAndUuids(new PurgeSnapshotQuery().setComponentUuid(rootUuid))); } void deleteComponents(List componentIdUuids) { @@ -134,7 +134,6 @@ class PurgeCommands { @VisibleForTesting protected void deleteSnapshots(List snapshotIds) { - List> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); List> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); deleteAnalysisDuplications(snapshotUuidsPartitions); @@ -145,7 +144,7 @@ class PurgeCommands { profiler.stop(); profiler.start("deleteSnapshots (project_measures)"); - snapshotIdsPartitions.forEach(purgeMapper::deleteSnapshotMeasures); + snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshotMeasures); session.commit(); profiler.stop(); @@ -199,8 +198,6 @@ class PurgeCommands { profiler.start("deleteAnalyses (snapshots)"); analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses); - // FIXME remove this when cardinality of snapshots has been changed - analysisIdsPartitions.forEach(purgeMapper::deleteDescendantSnapshots); session.commit(); profiler.stop(); } @@ -220,8 +217,6 @@ class PurgeCommands { profiler.start("updatePurgeStatusToOne (snapshots)"); analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne); - // FIXME remove this when cardinality of snapshots has been changed - analysisIdsPartitions.forEach(purgeMapper::updateDescendantPurgeStatusToOne); session.commit(); profiler.stop(); } diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java index 20565364871..93ea962bb19 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -63,13 +63,15 @@ public class PurgeDao implements Dao { deleteAbortedAnalyses(rootUuid, commands); deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); - disableOrphanResources(rootUuid, session, mapper, listener); + + // FIXME to be re-enabled with + //disableOrphanResources(rootUuid, session, mapper, listener); deleteOldClosedIssues(conf, mapper, listener); } private static void purgeAnalyses(PurgeCommands commands, String rootUuid) { List analysisUuids = commands.selectSnapshotIdUuids( - PurgeSnapshotQuery.create() + new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); @@ -93,10 +95,10 @@ public class PurgeDao implements Dao { private static void deleteAbortedAnalyses(String rootUuid, PurgeCommands commands) { LOG.debug("<- Delete aborted builds"); - PurgeSnapshotQuery query = PurgeSnapshotQuery.create() + PurgeSnapshotQuery query = new PurgeSnapshotQuery() .setIslast(false) .setStatus(UNPROCESSED_STATUS) - .setRootComponentUuid(rootUuid); + .setComponentUuid(rootUuid); commands.deleteAnalyses(query); } @@ -106,7 +108,7 @@ public class PurgeDao implements Dao { } List analysisUuids = purgeCommands.selectSnapshotUuids( - PurgeSnapshotQuery.create() + new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); @@ -121,12 +123,6 @@ public class PurgeDao implements Dao { .collect(GuavaCollectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); - // FIXME remove this when cardinality of snapshots has been changed - for (String componentUuid : componentWithoutHistoricalDataUuids) { - purgeCommands.deleteSnapshots(PurgeSnapshotQuery.create() - .setIslast(false) - .setComponentUuid(componentUuid)); - } } /** diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java index fbfe594ab7c..0b6aaa5011b 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -37,16 +37,13 @@ public interface PurgeMapper { void deleteAnalyses(@Param("analysisUuids") List analysisUuids); - void deleteDescendantSnapshots(@Param("snapshotIds") List snapshotIds); - void deleteAnalysisDuplications(@Param("analysisUuids") List analysisUuids); void deleteAnalysisEvents(@Param("analysisUuids") List analysisUuids); void deleteAnalysisMeasures(@Param("analysisUuids") List analysisUuids); - // FIXME remove when snapshot cardinality is changed - void deleteSnapshotMeasures(@Param("snapshotIds") List snapshotIds); + void deleteSnapshotMeasures(@Param("analysisUuids") List analysisUuids); void deleteComponentMeasures(@Param("analysisUuids") List analysisUuids, @Param("componentUuids") List componentUuids); @@ -56,8 +53,6 @@ public interface PurgeMapper { void updatePurgeStatusToOne(@Param("analysisUuids") List analysisUuid); - void updateDescendantPurgeStatusToOne(@Param("analysisIds") List analysisIds); - void disableComponent(@Param("componentUuids") List componentUuids); void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuids") List componentUuids, @Param("dateAsLong") Long dateAsLong); diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java index 27cb6c2768d..692d9a4b193 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java @@ -20,44 +20,17 @@ package org.sonar.db.purge; public final class PurgeSnapshotQuery { - private String rootComponentUuid; private String componentUuid; - private String[] scopes; private String[] status; private Boolean islast; private Boolean notPurged; - private PurgeSnapshotQuery() { - } - - public static PurgeSnapshotQuery create() { - return new PurgeSnapshotQuery(); - } - - public String getRootComponentUuid() { - return rootComponentUuid; - } - - public PurgeSnapshotQuery setRootComponentUuid(String rootComponentUuid) { - this.rootComponentUuid = rootComponentUuid; - return this; - } - - public String[] getScopes() { - return scopes;// NOSONAR May expose internal representation by returning reference to mutable object - } - - public PurgeSnapshotQuery setScopes(String[] scopes) { - this.scopes = scopes; // NOSONAR May expose internal representation by incorporating reference to mutable object - return this; - } - public String[] getStatus() { - return status;// NOSONAR May expose internal representation by returning reference to mutable object + return status; } public PurgeSnapshotQuery setStatus(String[] status) { - this.status = status; // NOSONAR org.sonar.db.purge.PurgeSnapshotQuery.setStatus(String[]) may expose internal representation + this.status = status; return this; } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java index a8361e0d9c2..1cd271cb9d7 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/PopulateUuidPathColumnOnProjects.java @@ -60,7 +60,7 @@ public class PopulateUuidPathColumnOnProjects extends BaseDataChange { handleRoot(rootUuid, context); } - handleOrphans(context); + handleOrphans(context); } private void handleRoot(String rootComponentUuid, Context context) throws SQLException { diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml index 9e79c6417cb..bfd4a315573 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml @@ -13,18 +13,14 @@ ORDER BY r.name_size - @@ -53,9 +48,8 @@ - + select + from snapshots s + inner join projects p on s.component_uuid = p.project_uuid + where + s.islast=${_true} + and p.uuid = #{componentUuid} + + + - + select from snapshots s - - and s.islast=${_true} + where + s.islast=${_true} and s.component_uuid in #{componentUuid} - - - - + - - - - + update snapshots - set islast = #{isLast}, status = #{status} - where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId}) + set islast = ${_false} + where component_uuid = #{componentUuid} + and islast = ${_true} - + update snapshots - set islast = #{isLast} - where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId}) + set islast = ${_true}, status = 'P' + where uuid = #{analysisUuid} insert into snapshots ( uuid, - parent_snapshot_id, - root_snapshot_id, - root_component_uuid, component_uuid, created_at, build_date, status, purge_status, islast, - scope, - qualifier, version, - path, - depth, period1_mode, period2_mode, period3_mode, @@ -229,20 +198,13 @@ period5_date) values ( #{uuid, jdbcType=VARCHAR}, - #{parentId, jdbcType=BIGINT}, - #{rootId, jdbcType=BIGINT}, - #{rootComponentUuid, jdbcType=VARCHAR}, #{componentUuid, jdbcType=VARCHAR}, #{createdAt, jdbcType=BIGINT}, #{buildDate, jdbcType=BIGINT}, #{status, jdbcType=VARCHAR}, #{purgeStatus, jdbcType=INTEGER}, #{last, jdbcType=BOOLEAN}, - #{scope, jdbcType=VARCHAR}, - #{qualifier, jdbcType=VARCHAR}, #{version, jdbcType=VARCHAR}, - #{path, jdbcType=VARCHAR}, - #{depth, jdbcType=INTEGER}, #{period1Mode, jdbcType=VARCHAR}, #{period2Mode, jdbcType=VARCHAR}, #{period3Mode, jdbcType=VARCHAR}, diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index d88d78bab39..7e7c0dca712 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -30,11 +30,18 @@ from project_measures pm inner join snapshots analysis on analysis.uuid = pm.analysis_uuid where - analysis.islast=${_true} - and pm.component_uuid in + pm.component_uuid in #{componentUuid} + + + and analysis.uuid in #{analysisUuid} + + + and analysis.islast=${_true} + + and pm.metric_id in #{metricId} @@ -68,7 +75,6 @@ value, metric_id, component_uuid, - snapshot_id, analysis_uuid, text_value, alert_status, @@ -85,7 +91,6 @@ #{value, jdbcType=DOUBLE}, #{metricId, jdbcType=INTEGER}, #{componentUuid, jdbcType=VARCHAR}, - #{snapshotId, jdbcType=BIGINT}, #{analysisUuid, jdbcType=VARCHAR}, #{textValue, jdbcType=VARCHAR}, #{alertStatus, jdbcType=VARCHAR}, diff --git a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index c97dc468ad7..0302b9ecde4 100644 --- a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -15,9 +15,6 @@ and (s.purge_status is null or s.purge_status=0) - - and s.root_component_uuid=#{rootComponentUuid} - and s.component_uuid=#{componentUuid} @@ -25,10 +22,6 @@ and s.status in #{s} - - and s.scope in - #{scope} - @@ -40,9 +33,7 @@ where s.component_uuid=#{componentUuid} and s.status='P' - and s.qualifier <> 'LIB' and exists(select e.id from events e where e.analysis_uuid=s.uuid) - and parent_snapshot_id is null