From 566094fc629ab1e92afb0cdf191a0e2c685b5c35 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 20 Sep 2022 11:59:16 -0500 Subject: SONAR-17352 Refactor component keys to not include branch suffix --- .../ce/task/projectanalysis/analysis/Branch.java | 13 +++ .../MeasureComputerContextImpl.java | 4 +- .../component/BranchPersisterImpl.java | 2 +- .../task/projectanalysis/component/Component.java | 7 -- .../projectanalysis/component/ComponentImpl.java | 19 +--- .../component/ComponentTreeBuilder.java | 17 +-- .../component/DefaultBranchImpl.java | 8 -- .../component/DepthTraversalTypeAwareCrawler.java | 2 +- .../component/PathAwareCrawler.java | 4 +- .../component/ReferenceBranchComponentUuids.java | 2 +- .../component/SiblingComponentsWithOpenIssues.java | 4 +- .../projectanalysis/component/VisitorsCrawler.java | 4 +- .../projectanalysis/duplication/Duplication.java | 2 +- .../duplication/DuplicationRepositoryImpl.java | 4 +- .../IntegrateCrossProjectDuplications.java | 4 +- .../filemove/MutableMovedFilesRepositoryImpl.java | 6 +- .../issue/IntegrateIssuesVisitor.java | 2 +- .../issue/ProjectTrackerBaseLazyInput.java | 2 +- .../issue/SiblingsIssuesLoader.java | 2 +- .../issue/SourceBranchComponentUuids.java | 2 +- .../issue/TargetBranchComponentUuids.java | 11 +- .../issue/TrackerReferenceBranchInputFactory.java | 2 +- .../issue/TrackerSourceBranchInputFactory.java | 2 +- .../issue/TrackerTargetBranchInputFactory.java | 2 +- .../measure/MapBasedRawMeasureRepository.java | 4 +- .../NewCodeReferenceBranchComponentUuids.java | 2 +- .../task/projectanalysis/scm/ScmInfoDbLoader.java | 4 +- .../projectanalysis/scm/ScmInfoRepositoryImpl.java | 4 +- .../projectanalysis/source/DbLineHashVersion.java | 2 +- .../source/PersistFileSourcesStep.java | 2 +- .../source/SourceHashRepositoryImpl.java | 8 +- .../source/SourceLinesDiffImpl.java | 4 +- .../source/linereader/HighlightingLineReader.java | 2 +- .../source/linereader/SymbolsLineReader.java | 2 +- .../step/BuildComponentTreeStep.java | 15 +-- ...LoadCrossProjectDuplicationsRepositoryStep.java | 6 +- .../step/PersistComponentsStep.java | 20 ++-- .../step/PersistDuplicationDataStep.java | 6 +- .../step/QualityGateEventsStep.java | 2 +- .../projectanalysis/step/ValidateProjectStep.java | 8 +- .../component/ExportComponentsStep.java | 4 +- .../taskprocessor/ProjectDescriptor.java | 2 +- .../AnalysisFromSonarQube94VisitorTest.java | 2 +- .../analysis/ProjectConfigurationFactoryTest.java | 4 +- .../component/BranchPersisterImplTest.java | 16 +-- .../component/CallRecorderPathAwareVisitor.java | 4 +- .../component/CallRecorderTypeAwareVisitor.java | 2 +- .../component/ComponentImplTest.java | 16 +-- .../component/ComponentTreeBuilderTest.java | 60 +++++------ .../ComponentUuidFactoryWithMigrationTest.java | 96 ++++++++--------- .../component/ProjectPersisterTest.java | 6 +- .../ReferenceBranchComponentUuidsTest.java | 4 +- .../SiblingComponentsWithOpenIssuesTest.java | 7 +- ...ostOrderDepthTraversalTypeAwareCrawlerTest.java | 2 +- ...PreOrderDepthTraversalTypeAwareCrawlerTest.java | 2 +- .../component/ViewsVisitorsCrawlerTest.java | 2 +- .../filemove/FileMoveDetectionStepTest.java | 36 +++---- .../issue/IntegrateIssuesVisitorTest.java | 8 +- .../issue/MovedIssueVisitorTest.java | 1 - .../issue/ProjectTrackerBaseLazyInputTest.java | 4 +- .../issue/PullRequestSourceBranchMergerTest.java | 8 +- .../issue/SiblingsIssueMergerTest.java | 8 +- .../issue/SourceBranchComponentUuidsTest.java | 6 +- .../issue/TargetBranchComponentUuidsTest.java | 8 +- .../TrackerReferenceBranchInputFactoryTest.java | 4 +- .../issue/TrackerSourceBranchInputFactoryTest.java | 6 +- .../issue/TrackerTargetBranchInputFactoryTest.java | 6 +- .../NewCodeReferenceBranchComponentUuidsTest.java | 8 +- .../projectanalysis/scm/ScmInfoDbLoaderTest.java | 6 +- .../source/DbLineHashVersionTest.java | 6 +- .../step/BuildComponentTreeStepTest.java | 60 +++++------ ...CrossProjectDuplicationsRepositoryStepTest.java | 10 +- .../LoadReportAnalysisMetadataHolderStepTest.java | 16 +-- .../step/PersistComponentsStepTest.java | 2 +- .../step/PersistDuplicationDataStepTest.java | 4 +- .../step/PersistLiveMeasuresStepTest.java | 6 +- .../step/PersistMeasuresStepTest.java | 4 +- .../step/QualityGateEventsStepTest.java | 2 +- .../step/ReportPersistAnalysisStepTest.java | 20 ++-- .../step/ReportPersistComponentsStepTest.java | 119 ++++++++++----------- .../step/SendIssueNotificationsStepTest.java | 26 ++--- .../step/UpdateNeedIssueSyncStepTest.java | 2 +- .../step/ValidateProjectStepTest.java | 6 +- .../step/ViewsPersistAnalysisStepTest.java | 4 +- .../step/ViewsPersistComponentsStepTest.java | 24 ++--- .../analysis/ExportAnalysesStepTest.java | 12 +-- .../branches/ExportBranchesStepTest.java | 4 +- .../component/ExportComponentsStepTest.java | 12 +-- .../projectexport/issue/ExportIssuesStepTest.java | 2 +- .../rule/ExportAdHocRulesStepTest.java | 4 +- .../projectexport/steps/ExportEventsStepTest.java | 4 +- .../projectexport/steps/ExportLinksStepTest.java | 4 +- .../steps/ExportMeasuresStepTest.java | 12 +-- .../steps/ExportNewCodePeriodsStepTest.java | 8 +- .../steps/ExportSettingsStepTest.java | 8 +- .../projectexport/steps/LoadProjectStepTest.java | 2 +- .../projectanalysis/component/ReportComponent.java | 21 +--- .../component/TreeComponentProvider.java | 2 +- .../component/TreeRootHolderRule.java | 2 +- .../projectanalysis/component/ViewsComponent.java | 7 +- .../measure/MeasureRepositoryRule.java | 26 +---- 101 files changed, 441 insertions(+), 556 deletions(-) (limited to 'server/sonar-ce-task-projectanalysis') diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java index 08f8865ac38..9fff3120fde 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/Branch.java @@ -19,10 +19,14 @@ */ package org.sonar.ce.task.projectanalysis.analysis; +import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import org.sonar.ce.task.projectanalysis.component.ComponentKeyGenerator; import org.sonar.db.component.BranchType; +import static org.apache.logging.log4j.util.Strings.trimToNull; +import static org.sonar.core.component.ComponentKeys.createEffectiveKey; + @Immutable public interface Branch extends ComponentKeyGenerator { @@ -61,4 +65,13 @@ public interface Branch extends ComponentKeyGenerator { * @throws IllegalStateException if this branch configuration is not a pull request. */ String getTargetBranchName(); + + @Override + default String generateKey(String projectKey, @Nullable String fileOrDirPath) { + if (fileOrDirPath == null) { + return projectKey; + } else { + return createEffectiveKey(projectKey, trimToNull(fileOrDirPath)); + } + } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java index f5c2283b3ff..de24223936e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java @@ -169,7 +169,7 @@ public class MeasureComputerContextImpl implements MeasureComputerContext { checkArgument(definition.getOutputMetrics().contains(metric.getKey()), "Only metrics in %s can be used to add measures. Metric '%s' is not allowed.", definition.getOutputMetrics(), metric.getKey()); if (measureRepository.getRawMeasure(internalComponent, metric).isPresent()) { - throw new UnsupportedOperationException(String.format("A measure on metric '%s' already exists on component '%s'", metric.getKey(), internalComponent.getDbKey())); + throw new UnsupportedOperationException(String.format("A measure on metric '%s' already exists on component '%s'", metric.getKey(), internalComponent.getKey())); } } @@ -180,7 +180,7 @@ public class MeasureComputerContextImpl implements MeasureComputerContext { private static Component newComponent(org.sonar.ce.task.projectanalysis.component.Component component) { return new ComponentImpl( - component.getDbKey(), + component.getKey(), Component.Type.valueOf(component.getType().name()), component.getType() == org.sonar.ce.task.projectanalysis.component.Component.Type.FILE ? new ComponentImpl.FileAttributesImpl(component.getFileAttributes().getLanguageKey(), component.getFileAttributes().isUnitTest()) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java index 03aa3ee0fa9..60a686166d5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java @@ -81,7 +81,7 @@ public class BranchPersisterImpl implements BranchPersister { dto.setUuid(componentDto.uuid()); // MainBranchProjectUuid will be null if it's a main branch - String projectUuid = firstNonNull(componentDto.getMainBranchProjectUuid(), componentDto.projectUuid()); + String projectUuid = firstNonNull(componentDto.getMainBranchProjectUuid(), componentDto.branchUuid()); dto.setProjectUuid(projectUuid); dto.setBranchType(branch.getType()); dto.setExcludeFromPurge(excludeFromPurge); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/Component.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/Component.java index 31bff319be0..4889401417a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/Component.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/Component.java @@ -75,13 +75,6 @@ public interface Component { */ String getUuid(); - /** - * Returns the component key as defined in database - * It may differ from keys listed in scanner report - * when analyzing a branch. - */ - String getDbKey(); - /** * Returns the key as it will be displayed in the ui. * If legacy branch feature is used, the key will contain the branch name diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentImpl.java index 3aca5f5287d..a9ac6fbbd26 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentImpl.java @@ -41,7 +41,6 @@ public class ComponentImpl implements Component { private final Status status; private final String name; private final String shortName; - private final String dbKey; private final String key; private final String uuid; @@ -57,8 +56,7 @@ public class ComponentImpl implements Component { private ComponentImpl(Builder builder) { this.type = builder.type; this.status = builder.status; - this.dbKey = builder.dbKey; - this.key = MoreObjects.firstNonNull(builder.key, builder.dbKey); + this.key = builder.key; this.name = builder.name; this.shortName = MoreObjects.firstNonNull(builder.shortName, builder.name).intern(); this.description = builder.description; @@ -84,11 +82,6 @@ public class ComponentImpl implements Component { return uuid; } - @Override - public String getDbKey() { - return dbKey; - } - @Override public String getKey() { return key; @@ -153,7 +146,6 @@ public class ComponentImpl implements Component { public static final class Builder { - private static final String DB_KEY_CANNOT_BE_NULL = "DB key can't be null"; private static final String KEY_CANNOT_BE_NULL = "Key can't be null"; private static final String UUID_CANNOT_BE_NULL = "uuid can't be null"; private static final String REPORT_ATTRIBUTES_CANNOT_BE_NULL = "reportAttributes can't be null"; @@ -165,7 +157,6 @@ public class ComponentImpl implements Component { private ProjectAttributes projectAttributes; private ReportAttributes reportAttributes; private String uuid; - private String dbKey; private String key; private String name; private String shortName; @@ -192,11 +183,6 @@ public class ComponentImpl implements Component { return this; } - public Builder setDbKey(String s) { - this.dbKey = requireNonNull(s, DB_KEY_CANNOT_BE_NULL); - return this; - } - public Builder setKey(String key) { this.key = requireNonNull(key, KEY_CANNOT_BE_NULL); return this; @@ -244,7 +230,7 @@ public class ComponentImpl implements Component { public ComponentImpl build() { requireNonNull(reportAttributes, REPORT_ATTRIBUTES_CANNOT_BE_NULL); requireNonNull(uuid, UUID_CANNOT_BE_NULL); - requireNonNull(dbKey, DB_KEY_CANNOT_BE_NULL); + requireNonNull(key, KEY_CANNOT_BE_NULL); requireNonNull(name, NAME_CANNOT_BE_NULL); requireNonNull(status, STATUS_CANNOT_BE_NULL); checkProjectAttributes(this.projectAttributes); @@ -262,7 +248,6 @@ public class ComponentImpl implements Component { "type=" + type + ", status=" + status + ", name='" + name + '\'' + - ", dbKey='" + dbKey + '\'' + ", key='" + key + '\'' + ", uuid='" + uuid + '\'' + ", description='" + description + '\'' + diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java index 6808c7b6db8..4ca4a8ab048 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java @@ -45,9 +45,7 @@ import static org.apache.commons.lang.StringUtils.trimToNull; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE; public class ComponentTreeBuilder { - private final ComponentKeyGenerator keyGenerator; - private final ComponentKeyGenerator publicKeyGenerator; /** * Will supply the UUID for any component in the tree, given it's key. *

@@ -72,7 +70,6 @@ public class ComponentTreeBuilder { public ComponentTreeBuilder( ComponentKeyGenerator keyGenerator, - ComponentKeyGenerator publicKeyGenerator, UnaryOperator uuidSupplier, Function scannerComponentSupplier, Project project, @@ -80,7 +77,6 @@ public class ComponentTreeBuilder { ProjectAttributes projectAttributes) { this.keyGenerator = keyGenerator; - this.publicKeyGenerator = publicKeyGenerator; this.uuidSupplier = uuidSupplier; this.scannerComponentSupplier = scannerComponentSupplier; this.project = project; @@ -169,11 +165,9 @@ public class ComponentTreeBuilder { private Component buildProject(List children) { String projectKey = keyGenerator.generateKey(rootComponent.getKey(), null); String uuid = uuidSupplier.apply(projectKey); - String projectPublicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), null); ComponentImpl.Builder builder = ComponentImpl.builder(Component.Type.PROJECT) .setUuid(uuid) - .setDbKey(projectKey) - .setKey(projectPublicKey) + .setKey(projectKey) .setStatus(convertStatus(rootComponent.getStatus())) .setProjectAttributes(projectAttributes) .setReportAttributes(createAttributesBuilder(rootComponent.getRef(), rootComponent.getProjectRelativePath(), scmBasePath).build()) @@ -184,11 +178,9 @@ public class ComponentTreeBuilder { private ComponentImpl buildFile(ScannerReport.Component component) { String key = keyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); - String publicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); return ComponentImpl.builder(Component.Type.FILE) .setUuid(uuidSupplier.apply(key)) - .setDbKey(key) - .setKey(publicKey) + .setKey(key) .setName(component.getProjectRelativePath()) .setShortName(FilenameUtils.getName(component.getProjectRelativePath())) .setStatus(convertStatus(component.getStatus())) @@ -200,11 +192,9 @@ public class ComponentTreeBuilder { private ComponentImpl buildDirectory(String parentPath, String path, List children) { String key = keyGenerator.generateKey(rootComponent.getKey(), path); - String publicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), path); return ComponentImpl.builder(Component.Type.DIRECTORY) .setUuid(uuidSupplier.apply(key)) - .setDbKey(key) - .setKey(publicKey) + .setKey(key) .setName(path) .setShortName(removeStart(removeStart(path, parentPath), "/")) .setStatus(convertStatus(FileStatus.UNAVAILABLE)) @@ -268,7 +258,6 @@ public class ComponentTreeBuilder { private static ComponentImpl.Builder changedComponentBuilder(Component component, String newShortName) { return ComponentImpl.builder(component.getType()) .setUuid(component.getUuid()) - .setDbKey(component.getDbKey()) .setKey(component.getKey()) .setStatus(component.getStatus()) .setReportAttributes(component.getReportAttributes()) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java index b07d637679e..80ce63ab899 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java @@ -73,12 +73,4 @@ public class DefaultBranchImpl implements Branch { public String getTargetBranchName() { throw new IllegalStateException("Only on a pull request"); } - - @Override - public String generateKey(String projectKey, @Nullable String fileOrDirPath) { - if (isEmpty(fileOrDirPath)) { - return projectKey; - } - return ComponentKeys.createEffectiveKey(projectKey, trimToNull(fileOrDirPath)); - } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DepthTraversalTypeAwareCrawler.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DepthTraversalTypeAwareCrawler.java index a937e967ce1..6b40dc47f8c 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DepthTraversalTypeAwareCrawler.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DepthTraversalTypeAwareCrawler.java @@ -38,7 +38,7 @@ public final class DepthTraversalTypeAwareCrawler implements ComponentCrawler { try { visitImpl(component); } catch (RuntimeException e) { - VisitException.rethrowOrWrap(e, "Visit of Component {key=%s,uuid=%s,type=%s} failed", component.getDbKey(), component.getUuid(), component.getType()); + VisitException.rethrowOrWrap(e, "Visit of Component {key=%s,uuid=%s,type=%s} failed", component.getKey(), component.getUuid(), component.getType()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/PathAwareCrawler.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/PathAwareCrawler.java index 37ae2e227e5..d0c643eed03 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/PathAwareCrawler.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/PathAwareCrawler.java @@ -52,7 +52,7 @@ public final class PathAwareCrawler implements ComponentCrawler { VisitException.rethrowOrWrap( e, "Visit failed for Component {key=%s,type=%s} %s", - component.getDbKey(), component.getType(), new ComponentPathPrinter<>(stack)); + component.getKey(), component.getType(), new ComponentPathPrinter<>(stack)); } } @@ -169,7 +169,7 @@ public final class PathAwareCrawler implements ComponentCrawler { @Override @Nonnull public String apply(@Nonnull PathAwareVisitor.PathElement input) { - return format("%s(type=%s)", input.getComponent().getDbKey(), input.getComponent().getType()); + return format("%s(type=%s)", input.getComponent().getKey(), input.getComponent().getType()); } } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java index 809b0eea786..f77a898e369 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuids.java @@ -69,7 +69,7 @@ public class ReferenceBranchComponentUuids { hasReferenceBranchAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, referenceBranchUuid).isPresent(); if (hasReferenceBranchAnalysis) { - List components = dbClient.componentDao().selectByProjectUuid(referenceBranchUuid, dbSession); + List components = dbClient.componentDao().selectByBranchUuid(referenceBranchUuid, dbSession); for (ComponentDto dto : components) { referenceBranchComponentsUuidsByKey.put(dto.getKey(), dto.uuid()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java index 668e2115cd1..ffa537805b2 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java @@ -76,7 +76,7 @@ public class SiblingComponentsWithOpenIssues { List components = dbClient.componentDao().selectComponentsFromBranchesThatHaveOpenIssues(dbSession, branchUuids); for (KeyWithUuidDto dto : components) { - uuidsByKey.computeIfAbsent(removeBranchAndPullRequestFromKey(dto.key()), s -> new HashSet<>()).add(dto.uuid()); + uuidsByKey.computeIfAbsent(dto.key(), s -> new HashSet<>()).add(dto.uuid()); } } @@ -84,7 +84,7 @@ public class SiblingComponentsWithOpenIssues { List components = dbClient.componentDao().selectComponentsFromPullRequestsTargetingCurrentBranchThatHaveOpenIssues( dbSession, referenceBranchUuid, currentBranchUuid); for (KeyWithUuidDto dto : components) { - uuidsByKey.computeIfAbsent(removeBranchAndPullRequestFromKey(dto.key()), s -> new HashSet<>()).add(dto.uuid()); + uuidsByKey.computeIfAbsent(dto.key(), s -> new HashSet<>()).add(dto.uuid()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java index 32da9e33c9a..c5239c88d1d 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java @@ -71,7 +71,7 @@ public class VisitorsCrawler implements ComponentCrawler { VisitException.rethrowOrWrap( e, "Visit of Component {key=%s,type=%s} failed", - component.getDbKey(), component.getType()); + component.getKey(), component.getType()); } } @@ -110,7 +110,7 @@ public class VisitorsCrawler implements ComponentCrawler { private void visitNode(Component component, VisitorWrapper visitor) { Profiler profiler = Profiler.create(Loggers.get(visitor.getWrappedVisitor().getClass())) - .startTrace("Visiting component {}", component.getDbKey()); + .startTrace("Visiting component {}", component.getKey()); visitor.visitAny(component); switch (component.getType()) { case PROJECT: diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java index 07874e2ccf2..9f349fbfe1f 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java @@ -148,7 +148,7 @@ public final class Duplication { return ""; } if (duplicate instanceof InProjectDuplicate) { - return ((InProjectDuplicate) duplicate).getFile().getDbKey(); + return ((InProjectDuplicate) duplicate).getFile().getKey(); } if (duplicate instanceof CrossProjectDuplicate) { return ((CrossProjectDuplicate) duplicate).getFileKey(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryImpl.java index e2f30e018aa..fa3d895b8eb 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryImpl.java @@ -39,7 +39,7 @@ public class DuplicationRepositoryImpl implements DuplicationRepository { public Iterable getDuplications(Component file) { checkFileComponentArgument(file); - Collection res = this.duplications.asMap().get(file.getDbKey()); + Collection res = this.duplications.asMap().get(file.getKey()); if (res == null) { return Collections.emptyList(); } @@ -51,7 +51,7 @@ public class DuplicationRepositoryImpl implements DuplicationRepository { checkFileComponentArgument(file); checkNotNull(duplication, "duplication can not be null"); - duplications.put(file.getDbKey(), duplication); + duplications.put(file.getKey(), duplication); } private static void checkFileComponentArgument(Component file) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java index 38f79cb3cca..273a6dc68e8 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java @@ -91,7 +91,7 @@ public class IntegrateCrossProjectDuplications { for (CloneGroup duplication : duplications) { cloneGroupCount++; if (cloneGroupCount > MAX_CLONE_GROUP_PER_FILE) { - LOGGER.warn("Too many duplication groups on file {}. Keeping only the first {} groups.", file.getDbKey(), MAX_CLONE_GROUP_PER_FILE); + LOGGER.warn("Too many duplication groups on file {}. Keeping only the first {} groups.", file.getKey(), MAX_CLONE_GROUP_PER_FILE); break; } addDuplication(file, duplication); @@ -174,7 +174,7 @@ public class IntegrateCrossProjectDuplications { public boolean test(@Nonnull ClonePart input) { if (counter == MAX_CLONE_PART_PER_GROUP) { LOGGER.warn("Too many duplication references on file {} for block at line {}. Keeping only the first {} references.", - file.getDbKey(), originPart.getStartLine(), MAX_CLONE_PART_PER_GROUP); + file.getKey(), originPart.getStartLine(), MAX_CLONE_PART_PER_GROUP); } boolean res = counter < MAX_CLONE_GROUP_PER_FILE; counter++; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImpl.java index ee56d508686..b05ba83cf86 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImpl.java @@ -37,11 +37,11 @@ public class MutableMovedFilesRepositoryImpl implements MutableMovedFilesReposit requireNonNull(originalFile, "originalFile can't be null"); checkArgument(file.getType() == Component.Type.FILE, "file must be of type FILE"); - OriginalFile existingOriginalFile = originalFiles.get(file.getDbKey()); + OriginalFile existingOriginalFile = originalFiles.get(file.getKey()); checkState(existingOriginalFile == null || existingOriginalFile.equals(originalFile), "Original file %s already registered for file %s. Unable to register %s.", existingOriginalFile, file, originalFile); if (existingOriginalFile == null) { - originalFiles.put(file.getDbKey(), originalFile); + originalFiles.put(file.getKey(), originalFile); } } @@ -52,6 +52,6 @@ public class MutableMovedFilesRepositoryImpl implements MutableMovedFilesReposit return Optional.empty(); } - return Optional.ofNullable(originalFiles.get(file.getDbKey())); + return Optional.ofNullable(originalFiles.get(file.getKey())); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java index 805354d96e0..db09538cac3 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java @@ -103,7 +103,7 @@ public class IntegrateIssuesVisitor extends TypeAwareVisitorAdapter { } issueVisitors.afterComponent(component); } catch (Exception e) { - throw new IllegalStateException(String.format("Fail to process issues of component '%s'", component.getDbKey()), e); + throw new IllegalStateException(String.format("Fail to process issues of component '%s'", component.getKey()), e); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java index df0a01e52aa..ea027852f83 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInput.java @@ -72,7 +72,7 @@ class ProjectTrackerBaseLazyInput extends BaseInputFactory.BaseLazyInput { if (!dirOrModulesUuidsWithIssues.isEmpty()) { Map pathByModuleKey = reportModulesPath.get(); // Migrate issues that were previously on modules or directories to the root project - Map modulesByUuid = dbClient.componentDao().selectProjectAndModulesFromProjectKey(dbSession, component.getDbKey(), true) + Map modulesByUuid = dbClient.componentDao().selectProjectAndModulesFromProjectKey(dbSession, component.getKey(), true) .stream().collect(Collectors.toMap(ComponentDto::uuid, Function.identity())); List dirOrModulesWithIssues = dbClient.componentDao().selectByUuids(dbSession, dirOrModulesUuidsWithIssues); dirOrModulesWithIssues.forEach(c -> { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java index 641ce331a27..60c94d1f999 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssuesLoader.java @@ -52,7 +52,7 @@ public class SiblingsIssuesLoader { } public Collection loadCandidateSiblingIssuesForMerging(Component component) { - String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getDbKey()); + String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getKey()); Set uuids = siblingComponentsWithOpenIssues.getUuids(componentKey); if (uuids.isEmpty()) { return Collections.emptyList(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java index 06c108f27e3..409c8204d48 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuids.java @@ -66,7 +66,7 @@ public class SourceBranchComponentUuids { String sourceBranchUuid = branchDtoOpt.map(BranchDto::getUuid).orElse(null); hasSourceBranchAnalysis = sourceBranchUuid != null && dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, sourceBranchUuid).isPresent(); if (hasSourceBranchAnalysis) { - List targetComponents = dbClient.componentDao().selectByProjectUuid(sourceBranchUuid, dbSession); + List targetComponents = dbClient.componentDao().selectByBranchUuid(sourceBranchUuid, dbSession); for (ComponentDto dto : targetComponents) { sourceBranchComponentsUuidsByKey.put(dto.getKey(), dto.uuid()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java index 126db444ec3..725cf52f6da 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuids.java @@ -40,8 +40,6 @@ public class TargetBranchComponentUuids { private final DbClient dbClient; private Map targetBranchComponentsUuidsByKey; private boolean hasTargetBranchAnalysis; - @CheckForNull - private String targetBranchUuid; public TargetBranchComponentUuids(AnalysisMetadataHolder analysisMetadataHolder, DbClient dbClient) { this.analysisMetadataHolder = analysisMetadataHolder; @@ -65,10 +63,10 @@ public class TargetBranchComponentUuids { private void initForTargetBranch(DbSession dbSession) { Optional branchDtoOpt = dbClient.branchDao().selectByBranchKey(dbSession, analysisMetadataHolder.getProject().getUuid(), analysisMetadataHolder.getBranch().getTargetBranchName()); - targetBranchUuid = branchDtoOpt.map(BranchDto::getUuid).orElse(null); + String targetBranchUuid = branchDtoOpt.map(BranchDto::getUuid).orElse(null); hasTargetBranchAnalysis = targetBranchUuid != null && dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, targetBranchUuid).isPresent(); if (hasTargetBranchAnalysis) { - List targetComponents = dbClient.componentDao().selectByProjectUuid(targetBranchUuid, dbSession); + List targetComponents = dbClient.componentDao().selectByBranchUuid(targetBranchUuid, dbSession); for (ComponentDto dto : targetComponents) { targetBranchComponentsUuidsByKey.put(dto.getKey(), dto.uuid()); } @@ -81,9 +79,8 @@ public class TargetBranchComponentUuids { } @CheckForNull - public String getTargetBranchComponentUuid(String dbKey) { + public String getTargetBranchComponentUuid(String key) { lazyInit(); - String cleanComponentKey = removeBranchAndPullRequestFromKey(dbKey); - return targetBranchComponentsUuidsByKey.get(cleanComponentKey); + return targetBranchComponentsUuidsByKey.get(key); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactory.java index 1af1181f314..cde50da9556 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactory.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactory.java @@ -46,7 +46,7 @@ public class TrackerReferenceBranchInputFactory { } public Input create(Component component) { - String referenceBranchComponentUuid = referenceBranchComponentUuids.getComponentUuid(component.getDbKey()); + String referenceBranchComponentUuid = referenceBranchComponentUuids.getComponentUuid(component.getKey()); return new ReferenceLazyInput(component.getType(), referenceBranchComponentUuid); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactory.java index 01aa876990e..0a7b5fcae60 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactory.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactory.java @@ -49,7 +49,7 @@ public class TrackerSourceBranchInputFactory { } public Input createForSourceBranch(Component component) { - String sourceBranchComponentUuid = sourceBranchComponentUuids.getSourceBranchComponentUuid(component.getDbKey()); + String sourceBranchComponentUuid = sourceBranchComponentUuids.getSourceBranchComponentUuid(component.getKey()); return new SourceBranchLazyInput(component.getType(), sourceBranchComponentUuid); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactory.java index 326a9ff2e3d..1e28a40b382 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactory.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactory.java @@ -50,7 +50,7 @@ public class TrackerTargetBranchInputFactory { } public Input createForTargetBranch(Component component) { - String targetBranchComponentUuid = targetBranchComponentUuids.getTargetBranchComponentUuid(component.getDbKey()); + String targetBranchComponentUuid = targetBranchComponentUuids.getTargetBranchComponentUuid(component.getKey()); return new TargetLazyInput(component.getType(), targetBranchComponentUuid); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java index 18ea64976ee..187699ee7c9 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java @@ -70,7 +70,7 @@ public final class MapBasedRawMeasureRepository implements MeasureRepository throw new UnsupportedOperationException( format( "a measure can be set only once for a specific Component (key=%s), Metric (key=%s). Use update method", - component.getDbKey(), + component.getKey(), metric.getKey())); } add(component, metric, measure, OverridePolicy.OVERRIDE); @@ -86,7 +86,7 @@ public final class MapBasedRawMeasureRepository implements MeasureRepository throw new UnsupportedOperationException( format( "a measure can be updated only if one already exists for a specific Component (key=%s), Metric (key=%s). Use add method", - component.getDbKey(), + component.getKey(), metric.getKey())); } add(component, metric, measure, OverridePolicy.OVERRIDE); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java index d57e0b0c489..c45a933d1d3 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuids.java @@ -68,7 +68,7 @@ public class NewCodeReferenceBranchComponentUuids { boolean hasReferenceBranchAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, referenceBranchUuid).isPresent(); if (hasReferenceBranchAnalysis) { - List components = dbClient.componentDao().selectByProjectUuid(referenceBranchUuid, dbSession); + List components = dbClient.componentDao().selectByBranchUuid(referenceBranchUuid, dbSession); for (ComponentDto dto : components) { referenceBranchComponentsUuidsByKey.put(dto.getKey(), dto.uuid()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java index fc35319a17f..a6741048cc9 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java @@ -83,7 +83,7 @@ public class ScmInfoDbLoader { } if (isReferenceBranch()) { - var referencedBranchComponentUuid = newCodeReferenceBranchComponentUuids.getComponentUuid(file.getDbKey()); + var referencedBranchComponentUuid = newCodeReferenceBranchComponentUuids.getComponentUuid(file.getKey()); if (referencedBranchComponentUuid != null) { return Optional.of(referencedBranchComponentUuid); } @@ -94,7 +94,7 @@ public class ScmInfoDbLoader { // at this point, it's the first analysis of a branch with copyFromPrevious flag true or any analysis of a PR Branch branch = analysisMetadataHolder.getBranch(); if (!branch.isMain()) { - return Optional.ofNullable(referenceBranchComponentUuid.getComponentUuid(file.getDbKey())); + return Optional.ofNullable(referenceBranchComponentUuid.getComponentUuid(file.getKey())); } return Optional.empty(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImpl.java index 609a3e942e9..ae9ae38d637 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImpl.java @@ -69,7 +69,7 @@ public class ScmInfoRepositoryImpl implements ScmInfoRepository { ScannerReport.Changesets changesets = scannerReportReader.readChangesets(component.getReportAttributes().getRef()); if (changesets == null) { - LOGGER.trace("No SCM info for file '{}'", component.getDbKey()); + LOGGER.trace("No SCM info for file '{}'", component.getKey()); // SCM not available. It might have been available before - copy information for unchanged lines but don't keep author and revision. return generateAndMergeDb(component, false); } @@ -82,7 +82,7 @@ public class ScmInfoRepositoryImpl implements ScmInfoRepository { } private static Optional getScmInfoFromReport(Component file, ScannerReport.Changesets changesets) { - LOGGER.trace("Reading SCM info from report for file '{}'", file.getDbKey()); + LOGGER.trace("Reading SCM info from report for file '{}'", file.getKey()); return Optional.of(ReportScmInfo.create(changesets)); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersion.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersion.java index 2ebe386f670..432ac99ff8a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersion.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersion.java @@ -74,7 +74,7 @@ public class DbLineHashVersion { @CheckForNull private String getReferenceComponentUuid(Component component) { if (analysisMetadataHolder.isPullRequest()) { - return referenceBranchComponentUuids.getComponentUuid(component.getDbKey()); + return referenceBranchComponentUuids.getComponentUuid(component.getKey()); } else { return component.getUuid(); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java index 7748b6206f3..8bbed5af9c8 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/PersistFileSourcesStep.java @@ -96,7 +96,7 @@ public class PersistFileSourcesStep implements ComputationStep { FileSourceDataComputer.Data fileSourceData = fileSourceDataComputer.compute(file, fileSourceDataWarnings); persistSource(fileSourceData, file); } catch (Exception e) { - throw new IllegalStateException(String.format("Cannot persist sources of %s", file.getDbKey()), e); + throw new IllegalStateException(String.format("Cannot persist sources of %s", file.getKey()), e); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceHashRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceHashRepositoryImpl.java index c2d81df3cdd..6c08682bd62 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceHashRepositoryImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceHashRepositoryImpl.java @@ -43,12 +43,12 @@ public class SourceHashRepositoryImpl implements SourceHashRepository { @Override public String getRawSourceHash(Component file) { checkComponentArgument(file); - if (rawSourceHashesByKey.containsKey(file.getDbKey())) { - return checkSourceHash(file.getDbKey(), rawSourceHashesByKey.get(file.getDbKey())); + if (rawSourceHashesByKey.containsKey(file.getKey())) { + return checkSourceHash(file.getKey(), rawSourceHashesByKey.get(file.getKey())); } else { String newSourceHash = computeRawSourceHash(file); - rawSourceHashesByKey.put(file.getDbKey(), newSourceHash); - return checkSourceHash(file.getDbKey(), newSourceHash); + rawSourceHashesByKey.put(file.getKey(), newSourceHash); + return checkSourceHash(file.getKey(), newSourceHash); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesDiffImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesDiffImpl.java index 17c9e49775c..2774ea83309 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesDiffImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesDiffImpl.java @@ -69,9 +69,9 @@ public class SourceLinesDiffImpl implements SourceLinesDiff { try (DbSession dbSession = dbClient.openSession(false)) { String uuid; if (analysisMetadataHolder.isPullRequest()) { - uuid = referenceBranchComponentUuids.getComponentUuid(component.getDbKey()); + uuid = referenceBranchComponentUuids.getComponentUuid(component.getKey()); } else if (periodHolder.hasPeriod() && periodHolder.getPeriod().getMode().equals(NewCodePeriodType.REFERENCE_BRANCH.name())) { - uuid = newCodeReferenceBranchComponentUuids.getComponentUuid(component.getDbKey()); + uuid = newCodeReferenceBranchComponentUuids.getComponentUuid(component.getKey()); } else { Optional originalFile = movedFilesRepository.getOriginalFile(component); uuid = originalFile.map(MovedFilesRepository.OriginalFile::getUuid).orElse(component.getUuid()); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java index 02fabbadb64..aa62cb9a48f 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java @@ -80,7 +80,7 @@ public class HighlightingLineReader implements LineReader { processHighlightings(lineBuilder); } catch (RangeOffsetConverterException e) { readError = new ReadError(HIGHLIGHTING, lineBuilder.getLine()); - LOG.debug(format("Inconsistency detected in Highlighting data. Highlighting will be ignored for file '%s'", file.getDbKey()), e); + LOG.debug(format("Inconsistency detected in Highlighting data. Highlighting will be ignored for file '%s'", file.getKey()), e); } } return Optional.ofNullable(readError); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java index 17e36140311..262e88e4cd0 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java @@ -72,7 +72,7 @@ public class SymbolsLineReader implements LineReader { processSymbols(lineBuilder); } catch (RangeOffsetConverter.RangeOffsetConverterException e) { readError = new ReadError(Data.SYMBOLS, lineBuilder.getLine()); - LOG.warn(format("Inconsistency detected in Symbols data. Symbols will be ignored for file '%s'", file.getDbKey()), e); + LOG.warn(format("Inconsistency detected in Symbols data. Symbols will be ignored for file '%s'", file.getKey()), e); } } return Optional.ofNullable(readError); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java index 15b3dc5a792..6607b973a75 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java @@ -23,14 +23,12 @@ import java.util.Optional; import java.util.function.Function; import javax.annotation.Nullable; import org.sonar.ce.task.projectanalysis.analysis.Analysis; -import org.sonar.ce.task.projectanalysis.analysis.Branch; import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder; import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; import org.sonar.ce.task.projectanalysis.component.Component; import org.sonar.ce.task.projectanalysis.component.ComponentKeyGenerator; import org.sonar.ce.task.projectanalysis.component.ComponentTreeBuilder; import org.sonar.ce.task.projectanalysis.component.ComponentUuidFactoryWithMigration; -import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; import org.sonar.ce.task.projectanalysis.component.MutableTreeRootHolder; import org.sonar.ce.task.projectanalysis.component.ProjectAttributes; import org.sonar.ce.task.projectanalysis.component.ReportModulesPath; @@ -75,7 +73,6 @@ public class BuildComponentTreeStep implements ComputationStep { try (DbSession dbSession = dbClient.openSession(false)) { ScannerReport.Component reportProject = reportReader.readComponent(analysisMetadataHolder.getRootComponentRef()); ComponentKeyGenerator keyGenerator = loadKeyGenerator(); - ComponentKeyGenerator publicKeyGenerator = loadPublicKeyGenerator(); ScannerReport.Metadata metadata = reportReader.readMetadata(); // root key of branch, not necessarily of project @@ -87,7 +84,7 @@ public class BuildComponentTreeStep implements ComputationStep { String rootUuid = componentUuidFactoryWithMigration.getOrCreateForKey(rootKey); Optional baseAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, rootUuid); - ComponentTreeBuilder builder = new ComponentTreeBuilder(keyGenerator, publicKeyGenerator, + ComponentTreeBuilder builder = new ComponentTreeBuilder(keyGenerator, componentUuidFactoryWithMigration::getOrCreateForKey, reportReader::readComponent, analysisMetadataHolder.getProject(), @@ -131,16 +128,6 @@ public class BuildComponentTreeStep implements ComputationStep { return analysisMetadataHolder.getBranch(); } - private ComponentKeyGenerator loadPublicKeyGenerator() { - Branch branch = analysisMetadataHolder.getBranch(); - - // for non-legacy branches, the public key is different from the DB key. - if (!branch.isMain()) { - return new DefaultBranchImpl(); - } - return branch; - } - private static Analysis toAnalysis(SnapshotDto dto) { return new Analysis.Builder() .setUuid(dto.getUuid()) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java index db681383f58..c1a4c03ff0a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java @@ -100,7 +100,7 @@ public class LoadCrossProjectDuplicationsRepositoryStep implements ComputationSt cpdTextBlocks.add(blocksIt.next()); } } - LOGGER.trace("Found {} cpd blocks on file {}", cpdTextBlocks.size(), file.getDbKey()); + LOGGER.trace("Found {} cpd blocks on file {}", cpdTextBlocks.size(), file.getKey()); if (cpdTextBlocks.isEmpty()) { return; } @@ -112,8 +112,8 @@ public class LoadCrossProjectDuplicationsRepositoryStep implements ComputationSt } Collection duplicatedBlocks = dtos.stream().map(DtoToBlock.INSTANCE).collect(Collectors.toList()); - Collection originBlocks = cpdTextBlocks.stream().map(new CpdTextBlockToBlock(file.getDbKey())).collect(Collectors.toList()); - LOGGER.trace("Found {} duplicated cpd blocks on file {}", duplicatedBlocks.size(), file.getDbKey()); + Collection originBlocks = cpdTextBlocks.stream().map(new CpdTextBlockToBlock(file.getKey())).collect(Collectors.toList()); + LOGGER.trace("Found {} duplicated cpd blocks on file {}", duplicatedBlocks.size(), file.getKey()); integrateCrossProjectDuplications.computeCpd(file, originBlocks, duplicatedBlocks); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java index 390f67cf315..16adb079fbd 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java @@ -139,7 +139,7 @@ public class PersistComponentsStep implements ComputationStep { if (Component.Type.VIEW == root.getType()) { return false; } - throw new IllegalStateException(String.format("The project '%s' is not stored in the database, during a project analysis.", root.getDbKey())); + throw new IllegalStateException(String.format("The project '%s' is not stored in the database, during a project analysis.", root.getKey())); } return rootDto.isPrivate(); } @@ -149,7 +149,7 @@ public class PersistComponentsStep implements ComputationStep { * disabled components. */ private Map indexExistingDtosByUuids(DbSession session) { - return dbClient.componentDao().selectAllComponentsFromProjectKey(session, treeRootHolder.getRoot().getDbKey()) + return dbClient.componentDao().selectAllComponentsFromProjectKey(session, treeRootHolder.getRoot().getKey()) .stream() .collect(Collectors.toMap(ComponentDto::uuid, Function.identity())); } @@ -237,7 +237,7 @@ public class PersistComponentsStep implements ComputationStep { // update the fields in memory in order the PathAwareVisitor.Path // to be up-to-date - existingComponent.setDbKey(updateDto.getBKey()); + existingComponent.setKey(updateDto.getBKey()); existingComponent.setCopyComponentUuid(updateDto.getBCopyComponentUuid()); existingComponent.setDescription(updateDto.getBDescription()); existingComponent.setEnabled(updateDto.isBEnabled()); @@ -264,7 +264,7 @@ public class PersistComponentsStep implements ComputationStep { res.setLongName(res.name()); res.setDescription(project.getDescription()); - res.setProjectUuid(res.uuid()); + res.setBranchUuid(res.uuid()); res.setRootUuid(res.uuid()); res.setUuidPath(UUID_PATH_OF_ROOT); res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR); @@ -310,7 +310,7 @@ public class PersistComponentsStep implements ComputationStep { res.setDescription(view.getDescription()); res.setLongName(res.name()); - res.setProjectUuid(res.uuid()); + res.setBranchUuid(res.uuid()); res.setRootUuid(res.uuid()); res.setUuidPath(UUID_PATH_OF_ROOT); res.setModuleUuidPath(UUID_PATH_SEPARATOR + res.uuid() + UUID_PATH_SEPARATOR); @@ -348,12 +348,12 @@ public class PersistComponentsStep implements ComputationStep { } private ComponentDto createBase(Component component) { - String componentKey = component.getDbKey(); + String componentKey = component.getKey(); String componentUuid = component.getUuid(); ComponentDto componentDto = new ComponentDto(); componentDto.setUuid(componentUuid); - componentDto.setDbKey(componentKey); + componentDto.setKey(componentKey); componentDto.setMainBranchProjectUuid(mainBranchProjectUuid); componentDto.setEnabled(true); componentDto.setCreatedAt(new Date(system2.now())); @@ -367,7 +367,7 @@ public class PersistComponentsStep implements ComputationStep { private void setRootAndParentModule(ComponentDto res, PathAwareVisitor.Path path) { ComponentDto rootDto = path.root().getDto(); res.setRootUuid(rootDto.uuid()); - res.setProjectUuid(rootDto.uuid()); + res.setBranchUuid(rootDto.uuid()); ComponentDto parentModule = path.parent().getDto(); res.setUuidPath(formatUuidPathFromParent(parentModule)); @@ -380,7 +380,7 @@ public class PersistComponentsStep implements ComputationStep { * Applies to a node of type either DIRECTORY or FILE */ private static void setParentModuleProperties(ComponentDto componentDto, PathAwareVisitor.Path path) { - componentDto.setProjectUuid(path.root().getDto().uuid()); + componentDto.setBranchUuid(path.root().getDto().uuid()); ComponentDto parentModule = StreamSupport.stream(path.getCurrentPath().spliterator(), false) .filter(p -> p.getComponent().getType() == Component.Type.PROJECT) @@ -397,7 +397,7 @@ public class PersistComponentsStep implements ComputationStep { private static Optional compareForUpdate(ComponentDto existing, ComponentDto target) { boolean hasDifferences = !StringUtils.equals(existing.getCopyComponentUuid(), target.getCopyComponentUuid()) || !StringUtils.equals(existing.description(), target.description()) || - !StringUtils.equals(existing.getDbKey(), target.getDbKey()) || + !StringUtils.equals(existing.getKey(), target.getKey()) || !existing.isEnabled() || !StringUtils.equals(existing.getUuidPath(), target.getUuidPath()) || !StringUtils.equals(existing.language(), target.language()) || diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java index 1f5a175952e..9d61445def2 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java @@ -106,7 +106,7 @@ public class PersistDuplicationDataStep implements ComputationStep { } private void computeDuplications(Component component, Iterable duplications) { - Measure measure = generateMeasure(component.getDbKey(), duplications); + Measure measure = generateMeasure(component.getKey(), duplications); LiveMeasureDto dto = measureToMeasureDto.toLiveMeasureDto(measure, duplicationDataMetric, component); nonPersistedBuffer.add(dto); persist(false); @@ -161,10 +161,10 @@ public class PersistDuplicationDataStep implements ComputationStep { appendDuplication(xml, componentDbKey, duplicate); } else if (duplicate instanceof InExtendedProjectDuplicate) { // Duplication is on a different file that is not saved in the DB - appendDuplication(xml, ((InExtendedProjectDuplicate) duplicate).getFile().getDbKey(), duplicate.getTextBlock(), true); + appendDuplication(xml, ((InExtendedProjectDuplicate) duplicate).getFile().getKey(), duplicate.getTextBlock(), true); } else if (duplicate instanceof InProjectDuplicate) { // Duplication is on a different file - appendDuplication(xml, ((InProjectDuplicate) duplicate).getFile().getDbKey(), duplicate); + appendDuplication(xml, ((InProjectDuplicate) duplicate).getFile().getKey(), duplicate); } else if (duplicate instanceof CrossProjectDuplicate) { // Only componentKey is set for cross project duplications String crossProjectComponentKey = ((CrossProjectDuplicate) duplicate).getFileKey(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java index 6f509796b8d..0fcf5a36bb6 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java @@ -105,7 +105,7 @@ public class QualityGateEventsStep implements ComputationStep { } if (!baseMeasure.get().hasQualityGateStatus()) { - LOGGER.warn(String.format("Previous Quality gate status for project %s is not a supported value. Can not compute Quality Gate event", project.getDbKey())); + LOGGER.warn(String.format("Previous Quality gate status for project %s is not a supported value. Can not compute Quality Gate event", project.getKey())); checkNewQualityGate(project, rawStatus); return; } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java index ab661165bcf..52716dd4e90 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java @@ -67,8 +67,8 @@ public class ValidateProjectStep implements ComputationStep { validateTargetBranch(dbSession); Component root = treeRootHolder.getRoot(); // FIXME if module have really be dropped, no more need to load them - List baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getDbKey()); - Map baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getDbKey, x -> x)); + List baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey()); + Map baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getKey, x -> x)); ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey); new DepthTraversalTypeAwareCrawler(visitor).visit(root); @@ -83,7 +83,7 @@ public class ValidateProjectStep implements ComputationStep { return; } String referenceBranchUuid = analysisMetadataHolder.getBranch().getReferenceBranchUuid(); - int moduleCount = dbClient.componentDao().countEnabledModulesByProjectUuid(session, referenceBranchUuid); + int moduleCount = dbClient.componentDao().countEnabledModulesByBranchUuid(session, referenceBranchUuid); if (moduleCount > 0) { Optional opt = dbClient.branchDao().selectByUuid(session, referenceBranchUuid); checkState(opt.isPresent(), "Reference branch '%s' does not exist", referenceBranchUuid); @@ -112,7 +112,7 @@ public class ValidateProjectStep implements ComputationStep { @Override public void visitProject(Component rawProject) { - String rawProjectKey = rawProject.getDbKey(); + String rawProjectKey = rawProject.getKey(); Optional baseProjectOpt = loadBaseComponent(rawProjectKey); if (baseProjectOpt.isPresent()) { ComponentDto baseProject = baseProjectOpt.get(); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/component/ExportComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/component/ExportComponentsStep.java index b0fbb6b12e1..d2505d8f20a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/component/ExportComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/component/ExportComponentsStep.java @@ -45,9 +45,9 @@ public class ExportComponentsStep implements ComputationStep { private static final String QUERY = "select" + " p.uuid, p.qualifier, p.uuid_path, p.kee, p.name," + " p.description, p.scope, p.language, p.long_name, p.path," + - " p.module_uuid, p.module_uuid_path, p.deprecated_kee, p.project_uuid, p.main_branch_project_uuid" + + " p.module_uuid, p.module_uuid_path, p.deprecated_kee, p.branch_uuid, p.main_branch_project_uuid" + " from components p" + - " join components pp on pp.uuid = p.project_uuid" + + " join components pp on pp.uuid = p.branch_uuid" + " join project_branches pb on pb.uuid = pp.uuid" + " where pb.project_uuid=? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge=? and p.enabled=?"; private final DbClient dbClient; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java index d78c4252d37..cf6baffad0e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java @@ -42,7 +42,7 @@ public class ProjectDescriptor { * Build a {@link ProjectDescriptor} without checking qualifier of ComponentDto. */ public static ProjectDescriptor of(ComponentDto project) { - return new ProjectDescriptor(project.uuid(), project.getDbKey(), project.name()); + return new ProjectDescriptor(project.uuid(), project.getKey(), project.name()); } public final String getUuid() { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94VisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94VisitorTest.java index 19bd1e91961..5c2fe225db9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94VisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisFromSonarQube94VisitorTest.java @@ -57,7 +57,7 @@ public class AnalysisFromSonarQube94VisitorTest { @Test public void visitProject_createMeasureForMetric() { Component project = builder(FILE).setUuid("uuid") - .setDbKey("dbKey") + .setKey("dbKey") .setName("name") .setStatus(Component.Status.SAME) .setReportAttributes(mock(ReportAttributes.class)) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java index fb727aa27b8..f6c512561db 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java @@ -57,7 +57,7 @@ public class ProjectConfigurationFactoryTest { newComponentPropertyDto(project).setKey("2").setValue("val2"), newComponentPropertyDto(project).setKey("3").setValue("val3")); - Configuration config = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl()); + Configuration config = underTest.newProjectConfiguration(project.getKey(), new DefaultBranchImpl()); assertThat(config.get("1")).hasValue("val1"); assertThat(config.get("2")).hasValue("val2"); @@ -71,7 +71,7 @@ public class ProjectConfigurationFactoryTest { db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("key").setValue("value2")); - Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl()); + Configuration projectConfig = underTest.newProjectConfiguration(project.getKey(), new DefaultBranchImpl()); assertThat(projectConfig.get("key")).hasValue("value2"); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java index f441e18eed9..b87bd61a7d9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java @@ -104,7 +104,7 @@ public class BranchPersisterImplTest { String branchName = "branch"; // add project and branch in table PROJECTS - ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setDbKey(MAIN.getKey()); + ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setKey(MAIN.getKey()); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); dbTester.components().insertComponents(mainComponent, component); @@ -131,7 +131,7 @@ public class BranchPersisterImplTest { public void main_branch_is_excluded_from_branch_purge_by_default() { analysisMetadataHolder.setBranch(createBranch(BRANCH, true, "master")); treeRootHolder.setRoot(MAIN); - dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); + dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid())); dbTester.commit(); underTest.persist(dbTester.getSession()); @@ -147,7 +147,7 @@ public class BranchPersisterImplTest { analysisMetadataHolder.setProject(PROJECT); analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY")); treeRootHolder.setRoot(BRANCH1); - ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); + ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid())); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component); @@ -165,7 +165,7 @@ public class BranchPersisterImplTest { analysisMetadataHolder.setProject(PROJECT); analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY")); treeRootHolder.setRoot(BRANCH1); - ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); + ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid())); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component); @@ -184,7 +184,7 @@ public class BranchPersisterImplTest { analysisMetadataHolder.setProject(PROJECT); analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY")); treeRootHolder.setRoot(BRANCH1); - ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); + ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid())); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component); @@ -205,7 +205,7 @@ public class BranchPersisterImplTest { analysisMetadataHolder.setBranch(createPullRequest(PR1.getKey(), MAIN.getUuid())); analysisMetadataHolder.setPullRequestKey(PR1.getKey()); treeRootHolder.setRoot(PR1); - ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); + ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid())); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto() .setUuid(PR1.getUuid()) .setKey(PR1.getKey()) @@ -228,7 +228,7 @@ public class BranchPersisterImplTest { analysisMetadataHolder.setProject(PROJECT); analysisMetadataHolder.setBranch(createBranch(BRANCH, false, "BRANCH_KEY")); treeRootHolder.setRoot(BRANCH1); - ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setDbKey(MAIN.getDbKey()).setUuid(MAIN.getUuid())); + ComponentDto mainComponent = dbTester.components().insertPublicProject(p -> p.setKey(MAIN.getKey()).setUuid(MAIN.getUuid())); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(BRANCH)); dbTester.getDbClient().componentDao().insert(dbTester.getSession(), component); @@ -254,7 +254,7 @@ public class BranchPersisterImplTest { String pullRequestId = "pr-123"; // add project and branch in table PROJECTS - ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setDbKey(MAIN.getKey()); + ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(MAIN.getUuid()).setKey(MAIN.getKey()); ComponentDto component = ComponentTesting.newBranchComponent(mainComponent, new BranchDto().setUuid(BRANCH1.getUuid()).setKey(BRANCH1.getKey()).setBranchType(PULL_REQUEST)); dbTester.components().insertComponents(mainComponent, component); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java index 945490fb4c2..9069b69b66f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java @@ -34,7 +34,7 @@ class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter { super(maxDepth, order, new SimpleStackElementFactory() { @Override public Integer createForAny(Component component) { - return component.getType().isReportType() ? component.getReportAttributes().getRef() : Integer.valueOf(component.getDbKey()); + return component.getType().isReportType() ? component.getReportAttributes().getRef() : Integer.valueOf(component.getKey()); } }); } @@ -80,7 +80,7 @@ class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter { } private static PathAwareCallRecord viewsCallRecord(Component component, Path path, String method) { - return PathAwareCallRecord.viewsCallRecord(method, component.getDbKey(), path.current(), getParent(path), path.root(), + return PathAwareCallRecord.viewsCallRecord(method, component.getKey(), path.current(), getParent(path), path.root(), toValueList(path)); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderTypeAwareVisitor.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderTypeAwareVisitor.java index 6d747471a18..b5e7b4fa33e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderTypeAwareVisitor.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderTypeAwareVisitor.java @@ -69,7 +69,7 @@ class CallRecorderTypeAwareVisitor extends TypeAwareVisitorAdapter { } private static CallRecord viewsCallRecord(Component component, String method) { - return CallRecord.viewsCallRecord(method, component.getDbKey()); + return CallRecord.viewsCallRecord(method, component.getKey()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java index 0f493b4db78..0e3ba073adc 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java @@ -43,7 +43,7 @@ public class ComponentImplTest { public void verify_key_uuid_and_name() { ComponentImpl component = buildSimpleComponent(FILE, KEY).setUuid(UUID).setName("name").build(); - assertThat(component.getDbKey()).isEqualTo(KEY); + assertThat(component.getKey()).isEqualTo(KEY); assertThat(component.getUuid()).isEqualTo(UUID); assertThat(component.getName()).isEqualTo("name"); } @@ -65,7 +65,7 @@ public class ComponentImplTest { assertThatThrownBy(() -> { builder(Component.Type.DIRECTORY) .setName("DIR") - .setDbKey(KEY) + .setKey(KEY) .setUuid(UUID) .setReportAttributes(ReportAttributes.newBuilder(1).build()) .build(); @@ -81,7 +81,7 @@ public class ComponentImplTest { @Test public void set_uuid_throws_NPE_if_component_arg_is_Null() { - assertThatThrownBy(() -> builder(FILE).setDbKey(null)) + assertThatThrownBy(() -> builder(FILE).setKey(null)) .isInstanceOf(NullPointerException.class); } @@ -93,7 +93,7 @@ public class ComponentImplTest { @Test public void build_without_uuid_throws_NPE_if_component_arg_is_Null() { - assertThatThrownBy(() -> builder(FILE).setDbKey(KEY).build()) + assertThatThrownBy(() -> builder(FILE).setKey(KEY).build()) .isInstanceOf(NullPointerException.class); } @@ -192,14 +192,14 @@ public class ComponentImplTest { public void build_with_child() { ComponentImpl child = builder(FILE) .setName("CHILD_NAME") - .setDbKey("CHILD_KEY") + .setKey("CHILD_KEY") .setUuid("CHILD_UUID") .setStatus(Status.UNAVAILABLE) .setReportAttributes(ReportAttributes.newBuilder(2).build()) .build(); ComponentImpl componentImpl = builder(Component.Type.DIRECTORY) .setName("DIR") - .setDbKey(KEY) + .setKey(KEY) .setUuid(UUID) .setStatus(Status.UNAVAILABLE) .setReportAttributes(ReportAttributes.newBuilder(1).build()) @@ -208,7 +208,7 @@ public class ComponentImplTest { assertThat(componentImpl.getChildren()).hasSize(1); Component childReloaded = componentImpl.getChildren().iterator().next(); - assertThat(childReloaded.getDbKey()).isEqualTo("CHILD_KEY"); + assertThat(childReloaded.getKey()).isEqualTo("CHILD_KEY"); assertThat(childReloaded.getUuid()).isEqualTo("CHILD_UUID"); assertThat(childReloaded.getType()).isEqualTo(FILE); } @@ -234,7 +234,7 @@ public class ComponentImplTest { private static ComponentImpl.Builder buildSimpleComponent(Component.Type type, String dbKey) { ComponentImpl.Builder builder = builder(type) .setName("name_" + dbKey) - .setDbKey(dbKey) + .setKey(dbKey) .setStatus(Status.UNAVAILABLE) .setUuid("uuid_" + dbKey) .setReportAttributes(ReportAttributes.newBuilder(dbKey.hashCode()).build()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java index c5b115aa8a2..62f11b55be3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java @@ -46,17 +46,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; -import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.PROJECT; import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED; +import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder; public class ComponentTreeBuilderTest { - private static final ComponentKeyGenerator KEY_GENERATOR = (projectKey, path) -> "generated_" - + ComponentKeys.createEffectiveKey(projectKey, path); - private static final ComponentKeyGenerator PUBLIC_KEY_GENERATOR = (projectKey, path) -> "public_" - + ComponentKeys.createEffectiveKey(projectKey, path); + private static final ComponentKeyGenerator KEY_GENERATOR = (projectKey, path) -> "generated_" + ComponentKeys.createEffectiveKey(projectKey, path); private static final UnaryOperator UUID_SUPPLIER = (componentKey) -> componentKey + "_uuid"; private static final EnumSet REPORT_TYPES = EnumSet.of(PROJECT, FILE); private static final String NO_SCM_BASE_PATH = ""; @@ -64,11 +61,10 @@ public class ComponentTreeBuilderTest { private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes( randomAlphabetic(20), new Random().nextBoolean() ? null : randomAlphabetic(12), "1def5123"); - @Rule public ScannerComponentProvider scannerComponentProvider = new ScannerComponentProvider(); - private Project projectInDb = Project.from(newPrivateProjectDto(UUID_SUPPLIER.apply("K1")).setDbKey("K1").setDescription(null)); + private Project projectInDb = Project.from(newPrivateProjectDto(UUID_SUPPLIER.apply("K1")).setKey("K1").setDescription(null)); @Test public void build_throws_IAE_for_all_types_except_PROJECT_and_FILE() { @@ -130,8 +126,7 @@ public class ComponentTreeBuilderTest { .build(), NO_SCM_BASE_PATH, new ProjectAttributes("6.5", buildString, "4124af4")); assertThat(root.getUuid()).isEqualTo("generated_K1_uuid"); - assertThat(root.getDbKey()).isEqualTo("generated_K1"); - assertThat(root.getKey()).isEqualTo("public_K1"); + assertThat(root.getKey()).isEqualTo("generated_K1"); assertThat(root.getType()).isEqualTo(Component.Type.PROJECT); assertThat(root.getName()).isEqualTo(nameInReport); assertThat(root.getShortName()).isEqualTo(nameInReport); @@ -294,18 +289,15 @@ public class ComponentTreeBuilderTest { ScannerReport.Component project = createProject(); Component root = call(project); - assertThat(root.getDbKey()).isEqualTo("generated_" + projectInDb.getKey()); - assertThat(root.getKey()).isEqualTo("public_" + projectInDb.getKey()); + assertThat(root.getKey()).isEqualTo("generated_" + projectInDb.getKey()); assertThat(root.getChildren()).hasSize(1); Component directory = root.getChildren().iterator().next(); - assertThat(directory.getDbKey()).isEqualTo("generated_" + projectInDb.getKey() + ":src/js"); - assertThat(directory.getKey()).isEqualTo("public_" + projectInDb.getKey() + ":src/js"); + assertThat(directory.getKey()).isEqualTo("generated_" + projectInDb.getKey() + ":src/js"); assertThat(directory.getChildren()).hasSize(1); Component file = directory.getChildren().iterator().next(); - assertThat(file.getDbKey()).isEqualTo("generated_" + projectInDb.getKey() + ":src/js/Foo.js"); - assertThat(file.getKey()).isEqualTo("public_" + projectInDb.getKey() + ":src/js/Foo.js"); + assertThat(file.getKey()).isEqualTo("generated_" + projectInDb.getKey() + ":src/js/Foo.js"); assertThat(file.getChildren()).isEmpty(); } @@ -359,21 +351,21 @@ public class ComponentTreeBuilderTest { assertThat(root.getChildren()).hasSize(2); Component pom = root.getChildren().get(1); - assertThat(pom.getKey()).isEqualTo("public_K1:pom.xml"); + assertThat(pom.getKey()).isEqualTo("generated_K1:pom.xml"); assertThat(pom.getName()).isEqualTo("pom.xml"); Component directory = root.getChildren().get(0); - assertThat(directory.getKey()).isEqualTo("public_K1:src"); + assertThat(directory.getKey()).isEqualTo("generated_K1:src"); assertThat(directory.getName()).isEqualTo("src"); // folders are collapsed and they only contain one directory Component d1 = directory.getChildren().get(0); - assertThat(d1.getKey()).isEqualTo("public_K1:src/main/xoo"); + assertThat(d1.getKey()).isEqualTo("generated_K1:src/main/xoo"); assertThat(d1.getName()).isEqualTo("src/main/xoo"); assertThat(d1.getShortName()).isEqualTo("main/xoo"); Component d2 = directory.getChildren().get(1); - assertThat(d2.getKey()).isEqualTo("public_K1:src/test/xoo/org/sonar"); + assertThat(d2.getKey()).isEqualTo("generated_K1:src/test/xoo/org/sonar"); assertThat(d2.getName()).isEqualTo("src/test/xoo/org/sonar"); assertThat(d2.getShortName()).isEqualTo("test/xoo/org/sonar"); } @@ -396,12 +388,12 @@ public class ComponentTreeBuilderTest { // folders are collapsed and they only contain one directory Component dir = root.getChildren().get(0); - assertThat(dir.getKey()).isEqualTo("public_K1:src/test/xoo/org/sonar"); + assertThat(dir.getKey()).isEqualTo("generated_K1:src/test/xoo/org/sonar"); assertThat(dir.getName()).isEqualTo("src/test/xoo/org/sonar"); assertThat(dir.getShortName()).isEqualTo("src/test/xoo/org/sonar"); Component file = dir.getChildren().get(0); - assertThat(file.getKey()).isEqualTo("public_K1:src/test/xoo/org/sonar/Foo2.js"); + assertThat(file.getKey()).isEqualTo("generated_K1:src/test/xoo/org/sonar/Foo2.js"); assertThat(file.getName()).isEqualTo("src/test/xoo/org/sonar/Foo2.js"); assertThat(file.getShortName()).isEqualTo("Foo2.js"); } @@ -423,12 +415,12 @@ public class ComponentTreeBuilderTest { Component root = call(project); Component directory = root.getChildren().iterator().next(); - assertThat(directory.getKey()).isEqualTo("public_K1:src/js"); + assertThat(directory.getKey()).isEqualTo("generated_K1:src/js"); assertThat(directory.getName()).isEqualTo("src/js"); assertThat(directory.getShortName()).isEqualTo("src/js"); Component file = directory.getChildren().iterator().next(); - assertThat(file.getKey()).isEqualTo("public_K1:src/js/Foo.js"); + assertThat(file.getKey()).isEqualTo("generated_K1:src/js/Foo.js"); assertThat(file.getName()).isEqualTo("src/js/Foo.js"); assertThat(file.getShortName()).isEqualTo("Foo.js"); } @@ -484,22 +476,22 @@ public class ComponentTreeBuilderTest { Component root = call(project); Component directory = root.getChildren().iterator().next(); - assertThat(directory.getKey()).isEqualTo("public_K1:src"); + assertThat(directory.getKey()).isEqualTo("generated_K1:src"); assertThat(directory.getName()).isEqualTo("src"); assertThat(directory.getShortName()).isEqualTo("src"); Component directoryJava = directory.getChildren().get(0); - assertThat(directoryJava.getKey()).isEqualTo("public_K1:src/java"); + assertThat(directoryJava.getKey()).isEqualTo("generated_K1:src/java"); assertThat(directoryJava.getName()).isEqualTo("src/java"); assertThat(directoryJava.getShortName()).isEqualTo("java"); Component directoryJs = directory.getChildren().get(1); - assertThat(directoryJs.getKey()).isEqualTo("public_K1:src/js"); + assertThat(directoryJs.getKey()).isEqualTo("generated_K1:src/js"); assertThat(directoryJs.getName()).isEqualTo("src/js"); assertThat(directoryJs.getShortName()).isEqualTo("js"); Component file = directoryJs.getChildren().iterator().next(); - assertThat(file.getKey()).isEqualTo("public_K1:src/js/Foo.js"); + assertThat(file.getKey()).isEqualTo("generated_K1:src/js/Foo.js"); assertThat(file.getName()).isEqualTo("src/js/Foo.js"); assertThat(file.getShortName()).isEqualTo("Foo.js"); } @@ -524,8 +516,7 @@ public class ComponentTreeBuilderTest { Component root = call(project); Map componentsByKey = indexComponentByKey(root); - assertThat(componentsByKey.values()).extracting("key").startsWith("public_project 1"); - assertThat(componentsByKey.values()).extracting("dbKey").startsWith("generated_project 1"); + assertThat(componentsByKey.values()).extracting("key").startsWith("generated_project 1"); } @Test @@ -740,7 +731,7 @@ public class ComponentTreeBuilderTest { .setType(FILE) .setProjectRelativePath("src/js/Foo.js")); - assertThatThrownBy(() -> call(project)) + assertThatThrownBy(() -> call(project)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("File 'src/js/Foo.js' has no line"); } @@ -758,7 +749,7 @@ public class ComponentTreeBuilderTest { .setProjectRelativePath("src/js/Foo.js") .setLines(0)); - assertThatThrownBy(() -> call(project)) + assertThatThrownBy(() -> call(project)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("File 'src/js/Foo.js' has no line"); } @@ -776,7 +767,7 @@ public class ComponentTreeBuilderTest { .setProjectRelativePath("src/js/Foo.js") .setLines(-10)); - assertThatThrownBy(() -> call(project)) + assertThatThrownBy(() -> call(project)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("File 'src/js/Foo.js' has no line"); } @@ -817,8 +808,7 @@ public class ComponentTreeBuilderTest { private ComponentTreeBuilder newUnderTest(ProjectAttributes projectAttributes, boolean mainBranch) { Branch branch = mock(Branch.class); when(branch.isMain()).thenReturn(mainBranch); - return new ComponentTreeBuilder(KEY_GENERATOR, PUBLIC_KEY_GENERATOR, UUID_SUPPLIER, scannerComponentProvider, - projectInDb, branch, projectAttributes); + return new ComponentTreeBuilder(KEY_GENERATOR, UUID_SUPPLIER, scannerComponentProvider, projectInDb, branch, projectAttributes); } private static Map indexComponentByKey(Component root) { @@ -827,7 +817,7 @@ public class ComponentTreeBuilderTest { new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, PRE_ORDER) { @Override public void visitAny(Component any) { - componentsByKey.put(any.getDbKey(), any); + componentsByKey.put(any.getKey(), any); } }).visit(root); return componentsByKey; diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java index 224cb391815..230d04ee3d3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java @@ -43,156 +43,156 @@ public class ComponentUuidFactoryWithMigrationTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project)); Map reportModulesPath = Collections.singletonMap(module.getKey(), "module1_path"); - pathToKey = path -> path != null ? project.getDbKey() + ":" + path : project.getDbKey(); + pathToKey = path -> path != null ? project.getKey() + ":" + path : project.getKey(); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, reportModulesPath); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, reportModulesPath); - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); - assertThat(underTest.getOrCreateForKey(module.getDbKey())).isEqualTo(module.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(module.getKey())).isEqualTo(module.uuid()); } @Test public void migrate_project_with_modules() { - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project")); + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1")); + .setKey("project:module1")); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1) - .setDbKey("project:module1:module2")); + .setKey("project:module1:module2")); ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:file1") + .setKey("project:file1") .setPath("file1_path")); ComponentDto file2 = db.components().insertComponent(ComponentTesting.newFileDto(module2) - .setDbKey("project:module1:module2:file2") + .setKey("project:module1:module2:file2") .setPath("file2_path")); assertThat(file2.moduleUuidPath()).isEqualTo("." + project.uuid() + "." + module1.uuid() + "." + module2.uuid() + "."); Map modulesRelativePaths = new HashMap<>(); modulesRelativePaths.put("project:module1", "module1_path"); modulesRelativePaths.put("project:module1:module2", "module1_path/module2_path"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // migrated files assertThat(underTest.getOrCreateForKey("project:file1_path")).isEqualTo(file1.uuid()); assertThat(underTest.getOrCreateForKey("project:module1_path/module2_path/file2_path")).isEqualTo(file2.uuid()); // project remains the same - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); } @Test public void migrate_project_with_disabled_components_no_path() { - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project")); + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1")); + .setKey("project:module1")); ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:file1") + .setKey("project:file1") .setPath("file1")); ComponentDto disabledFileNoPath = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:file2") + .setKey("project:file2") .setPath(null) .setEnabled(false)); Map modulesRelativePaths = new HashMap<>(); modulesRelativePaths.put("project:module1", "module1_path"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // migrated files assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid()); // project remains the same - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); } @Test public void migrate_project_with_disabled_components_same_path() { - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project")); + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1")); + .setKey("project:module1")); ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:file1") + .setKey("project:file1") .setPath("file1")); ComponentDto disabledFileSamePath = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:file2") + .setKey("project:file2") .setPath("file1") .setEnabled(false)); Map modulesRelativePaths = new HashMap<>(); modulesRelativePaths.put("project:module1", "module1_path"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // migrated files assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid()); // project remains the same - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); } @Test public void prefers_component_having_same_key() { - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project")); + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1")); + .setKey("project:module1")); ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(module1) - .setDbKey("project:module1:file1") + .setKey("project:module1:file1") .setPath("file1")); ComponentDto disabledFileSameKey = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:module1/file1") + .setKey("project:module1/file1") .setPath("module1_path/file1") .setEnabled(false)); Map modulesRelativePaths = new HashMap<>(); modulesRelativePaths.put("project:module1", "module1_path"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // in theory we should migrate file1. But since disabledFileSameKey already have the expected migrated key, let's reuse it. assertThat(underTest.getOrCreateForKey("project:module1/file1")).isEqualTo(disabledFileSameKey.uuid()); // project remains the same - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); } @Test public void migrate_branch_with_modules() { - pathToKey = path -> path != null ? "project:" + path + ":BRANCH:branch1" : "project:BRANCH:branch1"; - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project:BRANCH:branch1")); + pathToKey = path -> path != null ? "project:" + path : "project"; + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1:BRANCH:branch1")); + .setKey("project:module1")); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1) - .setDbKey("project:module1:module2:BRANCH:branch1")); + .setKey("project:module1:module2")); ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project) - .setDbKey("project:file1:BRANCH:branch1") + .setKey("project:file1") .setPath("file1_path")); ComponentDto file2 = db.components().insertComponent(ComponentTesting.newFileDto(module2) - .setDbKey("project:module1:module2:file2:BRANCH:branch1") + .setKey("project:module1:module2:file2") .setPath("file2_path")); assertThat(file2.moduleUuidPath()).isEqualTo("." + project.uuid() + "." + module1.uuid() + "." + module2.uuid() + "."); Map modulesRelativePaths = new HashMap<>(); modulesRelativePaths.put("project:module1", "module1_path"); modulesRelativePaths.put("project:module1:module2", "module1_path/module2_path"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // migrated files - assertThat(underTest.getOrCreateForKey("project:file1_path:BRANCH:branch1")).isEqualTo(file1.uuid()); - assertThat(underTest.getOrCreateForKey("project:module1_path/module2_path/file2_path:BRANCH:branch1")).isEqualTo(file2.uuid()); + assertThat(underTest.getOrCreateForKey("project:file1_path")).isEqualTo(file1.uuid()); + assertThat(underTest.getOrCreateForKey("project:module1_path/module2_path/file2_path")).isEqualTo(file2.uuid()); // project remains the same - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); } @Test public void migrate_project_with_root_folders() { - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project")); + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1")); + .setKey("project:module1")); ComponentDto dir1 = db.components().insertComponent(ComponentTesting.newDirectory(module1, "/") - .setDbKey("project:module1:/")); + .setKey("project:module1:/")); Map modulesRelativePaths = Collections.singletonMap("project:module1", "module1_path"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // project remains the same - assertThat(underTest.getOrCreateForKey(project.getDbKey())).isEqualTo(project.uuid()); + assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid()); // module migrated to folder assertThat(underTest.getOrCreateForKey("project:module1_path")).isEqualTo(module1.uuid()); @@ -200,17 +200,17 @@ public class ComponentUuidFactoryWithMigrationTest { @Test public void dont_override_root_uuid_if_module_path_is_not_sent() { - ComponentDto project = db.components().insertPrivateProject(dto -> dto.setDbKey("project")); + ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project")); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module1") + .setKey("project:module1") .setEnabled(false)); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project) - .setDbKey("project:module2") + .setKey("project:module2") .setEnabled(false)); Map modulesRelativePaths = new HashMap<>(); modulesRelativePaths.put("project", ""); modulesRelativePaths.put("project:module2", "module2"); - ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getDbKey(), pathToKey, modulesRelativePaths); + ComponentUuidFactoryWithMigration underTest = new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), pathToKey, modulesRelativePaths); // check root project. assertThat(underTest.getOrCreateForKey("project")).isEqualTo(project.uuid()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java index f95daa30bb3..9f07abe0bfd 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterTest.java @@ -75,7 +75,7 @@ public class ProjectPersisterTest { @Test public void update_description() { ProjectDto p1 = dbTester.components().insertPublicProjectDto( - c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")); + c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")); assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt()); underTest.persist(dbTester.getSession()); @@ -85,7 +85,7 @@ public class ProjectPersisterTest { @Test public void update_name() { ProjectDto p1 = dbTester.components().insertPublicProjectDto( - c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())); + c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())); assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt()); underTest.persist(dbTester.getSession()); @@ -95,7 +95,7 @@ public class ProjectPersisterTest { @Test public void dont_update() { ProjectDto p1 = dbTester.components().insertPublicProjectDto( - c -> c.setUuid("PROJECT_UUID").setDbKey(ROOT.getKey()).setName(ROOT.getName()).setDescription(ROOT.getDescription())); + c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription(ROOT.getDescription())); assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt()); underTest.persist(dbTester.getSession()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsTest.java index 5b4775a44c1..9c0a1f8272a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReferenceBranchComponentUuidsTest.java @@ -81,7 +81,7 @@ public class ReferenceBranchComponentUuidsTest { when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); when(branch.getTargetBranchName()).thenReturn("notAnalyzedBranch"); db.components().insertSnapshot(newAnalysis(branch1)); - assertThat(underTest.getComponentUuid(pr1File.getDbKey())).isEqualTo(branch1File.uuid()); + assertThat(underTest.getComponentUuid(pr1File.getKey())).isEqualTo(branch1File.uuid()); assertThat(underTest.hasReferenceBranchAnalysis()).isTrue(); assertThat(underTest.getReferenceBranchName()).isEqualTo("branch1"); } @@ -109,6 +109,6 @@ public class ReferenceBranchComponentUuidsTest { when(branch.getReferenceBranchUuid()).thenReturn(branch1.uuid()); when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); when(branch.getTargetBranchName()).thenReturn("notAnalyzedBranch"); - assertThat(underTest.getComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getComponentUuid(pr1File.getKey())).isNull(); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java index c3d0c03d4df..a0e4080abe0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssuesTest.java @@ -93,11 +93,11 @@ public class SiblingComponentsWithOpenIssuesTest { String fileKey = "file-x"; fileXWithOneResolvedIssueOnBranch1Pr1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr1, null) - .setDbKey(fileKey + ":BRANCH:branch1pr1")); + .setKey(fileKey)); db.issues().insert(rule, branch1pr1, fileXWithOneResolvedIssueOnBranch1Pr1, i -> i.setStatus("RESOLVED")); fileXWithOneResolvedIssueOnBranch1Pr2 = db.components().insertComponent(ComponentTesting.newFileDto(branch1pr2, null) - .setDbKey(fileKey + ":BRANCH:branch1pr2")); + .setKey(fileKey)); db.issues().insert(rule, branch1pr2, fileXWithOneResolvedIssueOnBranch1Pr2, i -> i.setStatus("RESOLVED")); branch2 = db.components().insertProjectBranch(project, b -> b.setKey("branch2"), b -> b.setBranchType(BranchType.BRANCH)); @@ -141,8 +141,7 @@ public class SiblingComponentsWithOpenIssuesTest { assertThat(underTest.getUuids(fileWithOneResolvedIssueOnBranch1Pr1.getKey())).isEmpty(); assertThat(underTest.getUuids(fileWithOneOpenTwoResolvedIssuesOnBranch1Pr1.getKey())).isEmpty(); - assertThat(underTest.getUuids(fileXWithOneResolvedIssueOnBranch1Pr1.getKey())).containsOnly( - fileXWithOneResolvedIssueOnBranch1Pr2.uuid()); + assertThat(underTest.getUuids(fileXWithOneResolvedIssueOnBranch1Pr1.getKey())).containsOnly(fileXWithOneResolvedIssueOnBranch1Pr2.uuid()); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPostOrderDepthTraversalTypeAwareCrawlerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPostOrderDepthTraversalTypeAwareCrawlerTest.java index 5bb80181bbb..a418537b178 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPostOrderDepthTraversalTypeAwareCrawlerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPostOrderDepthTraversalTypeAwareCrawlerTest.java @@ -183,7 +183,7 @@ public class ViewsPostOrderDepthTraversalTypeAwareCrawlerTest { } private static CallRecord viewsCallRecord(String methodName, Component component) { - return CallRecord.viewsCallRecord(methodName, component.getDbKey()); + return CallRecord.viewsCallRecord(methodName, component.getKey()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPreOrderDepthTraversalTypeAwareCrawlerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPreOrderDepthTraversalTypeAwareCrawlerTest.java index d1528201994..36d4451b1d2 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPreOrderDepthTraversalTypeAwareCrawlerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPreOrderDepthTraversalTypeAwareCrawlerTest.java @@ -183,7 +183,7 @@ public class ViewsPreOrderDepthTraversalTypeAwareCrawlerTest { } private static CallRecord viewsCallRecord(String methodName, Component component) { - return CallRecord.viewsCallRecord(methodName, component.getDbKey()); + return CallRecord.viewsCallRecord(methodName, component.getKey()); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsVisitorsCrawlerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsVisitorsCrawlerTest.java index 558acc0c377..f50d8e2c418 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsVisitorsCrawlerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsVisitorsCrawlerTest.java @@ -153,7 +153,7 @@ public class ViewsVisitorsCrawlerTest { super(maxDepth, order, new SimpleStackElementFactory() { @Override public Integer createForAny(Component component) { - return Integer.valueOf(component.getDbKey()); + return Integer.valueOf(component.getKey()); } }); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java index b67e4bf4595..fec6d2ee4d9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java @@ -328,7 +328,7 @@ public class FileMoveDetectionStepTest { assertThat(movedFilesRepository.getComponentsWithOriginal()).containsExactly(file2); MovedFilesRepository.OriginalFile originalFile = movedFilesRepository.getOriginalFile(file2).get(); - assertThat(originalFile.getKey()).isEqualTo(dtos[0].getDbKey()); + assertThat(originalFile.getKey()).isEqualTo(dtos[0].getKey()); assertThat(originalFile.getUuid()).isEqualTo(dtos[0].uuid()); assertThat(addedFileRepository.getComponents()).isEmpty(); verifyStatistics(context, 1, 1, 1, 1); @@ -339,8 +339,8 @@ public class FileMoveDetectionStepTest { analysisMetadataHolder.setBaseAnalysis(ANALYSIS); Component file1 = fileComponent(FILE_1_REF, null); Component file2 = fileComponent(FILE_2_REF, LESS_CONTENT1); - insertFiles(file1.getDbKey()); - insertContentOfFileInDb(file1.getDbKey(), CONTENT1); + insertFiles(file1.getKey()); + insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); TestComputationStepContext context = new TestComputationStepContext(); @@ -359,8 +359,8 @@ public class FileMoveDetectionStepTest { analysisMetadataHolder.setBaseAnalysis(ANALYSIS); Component file1 = fileComponent(FILE_1_REF, null); Component file2 = fileComponent(FILE_2_REF, CONTENT1); - insertFiles(file1.getDbKey()); - insertContentOfFileInDb(file1.getDbKey(), CONTENT_EMPTY); + insertFiles(file1.getKey()); + insertContentOfFileInDb(file1.getKey(), CONTENT_EMPTY); setFilesInReport(file2); TestComputationStepContext context = new TestComputationStepContext(); @@ -377,8 +377,8 @@ public class FileMoveDetectionStepTest { analysisMetadataHolder.setBaseAnalysis(ANALYSIS); Component file1 = fileComponent(FILE_1_REF, null); Component file2 = fileComponent(FILE_2_REF, CONTENT1); - insertFiles(key -> newComponentDto(key).setPath(null), file1.getDbKey()); - insertContentOfFileInDb(file1.getDbKey(), CONTENT1); + insertFiles(key -> newComponentDto(key).setPath(null), file1.getKey()); + insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); TestComputationStepContext context = new TestComputationStepContext(); @@ -395,8 +395,8 @@ public class FileMoveDetectionStepTest { analysisMetadataHolder.setBaseAnalysis(ANALYSIS); Component file1 = fileComponent(FILE_1_REF, null); Component file2 = fileComponent(FILE_2_REF, CONTENT_EMPTY); - insertFiles(file1.getDbKey()); - insertContentOfFileInDb(file1.getDbKey(), CONTENT1); + insertFiles(file1.getKey()); + insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2); TestComputationStepContext context = new TestComputationStepContext(); @@ -415,8 +415,8 @@ public class FileMoveDetectionStepTest { Component file1 = fileComponent(FILE_1_REF, null); Component file2 = fileComponent(FILE_2_REF, CONTENT1); Component file3 = fileComponent(FILE_3_REF, CONTENT1); - insertFiles(file1.getDbKey()); - insertContentOfFileInDb(file1.getDbKey(), CONTENT1); + insertFiles(file1.getKey()); + insertContentOfFileInDb(file1.getKey(), CONTENT1); setFilesInReport(file2, file3); TestComputationStepContext context = new TestComputationStepContext(); @@ -493,10 +493,10 @@ public class FileMoveDetectionStepTest { assertThat(movedFilesRepository.getComponentsWithOriginal()).containsOnly(file3, file6); MovedFilesRepository.OriginalFile originalFile2 = movedFilesRepository.getOriginalFile(file3).get(); - assertThat(originalFile2.getKey()).isEqualTo(dtos[0].getDbKey()); + assertThat(originalFile2.getKey()).isEqualTo(dtos[0].getKey()); assertThat(originalFile2.getUuid()).isEqualTo(dtos[0].uuid()); MovedFilesRepository.OriginalFile originalFile5 = movedFilesRepository.getOriginalFile(file6).get(); - assertThat(originalFile5.getKey()).isEqualTo(dtos[3].getDbKey()); + assertThat(originalFile5.getKey()).isEqualTo(dtos[3].getKey()); assertThat(originalFile5.getUuid()).isEqualTo(dtos[3].uuid()); assertThat(scoreMatrixDumper.scoreMatrix.getMaxScore()).isGreaterThan(MIN_REQUIRED_SCORE); assertThat(addedFileRepository.getComponents()).isEmpty(); @@ -510,9 +510,9 @@ public class FileMoveDetectionStepTest { Component file2 = fileComponent(FILE_2_REF, null); Component file3 = fileComponent(FILE_3_REF, arrayOf(118)); Component file4 = fileComponent(5, arrayOf(25)); - insertFiles(file1.getDbKey(), file2.getDbKey()); - insertContentOfFileInDb(file1.getDbKey(), arrayOf(100)); - insertContentOfFileInDb(file2.getDbKey(), arrayOf(30)); + insertFiles(file1.getKey(), file2.getKey()); + insertContentOfFileInDb(file1.getKey(), arrayOf(100)); + insertContentOfFileInDb(file2.getKey(), arrayOf(30)); setFilesInReport(file3, file4); TestComputationStepContext context = new TestComputationStepContext(); @@ -595,7 +595,7 @@ public class FileMoveDetectionStepTest { FileSourceDto fileSourceDto = new FileSourceDto() .setUuid(Uuids.createFast()) .setFileUuid(file.uuid()) - .setProjectUuid(file.projectUuid()) + .setProjectUuid(file.branchUuid()) .setLineHashes(linesHashesComputer.getLineHashes()); dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), fileSourceDto); dbTester.commit(); @@ -623,7 +623,7 @@ public class FileMoveDetectionStepTest { private ComponentDto newComponentDto(String uuid) { return ComponentTesting.newFileDto(project) - .setDbKey("key_" + uuid) + .setKey("key_" + uuid) .setUuid(uuid) .setPath("path_" + uuid); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java index 454a56f4074..e4eb4bb9037 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java @@ -334,8 +334,8 @@ public class IntegrateIssuesVisitorTest { } private void addBaseIssue(RuleKey ruleKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(PROJECT_UUID).setDbKey(PROJECT_KEY); - ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setDbKey(FILE_KEY); + ComponentDto project = ComponentTesting.newPrivateProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); + ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); dbTester.components().insertComponents(project, file); RuleDto ruleDto = RuleTesting.newDto(ruleKey); @@ -351,8 +351,8 @@ public class IntegrateIssuesVisitorTest { } private void addBaseIssueOnBranch(RuleKey ruleKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto(PROJECT_UUID_ON_BRANCH).setDbKey(PROJECT_KEY); - ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID_ON_BRANCH).setDbKey(FILE_KEY); + ComponentDto project = ComponentTesting.newPrivateProjectDto(PROJECT_UUID_ON_BRANCH).setKey(PROJECT_KEY); + ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID_ON_BRANCH).setKey(FILE_KEY); dbTester.components().insertComponents(project, file); RuleDto ruleDto = RuleTesting.newDto(ruleKey); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java index 15f88d5a3cd..80b1ba6e5ae 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java @@ -43,7 +43,6 @@ public class MovedIssueVisitorTest { private static final String FILE_UUID = "file uuid"; private static final Component FILE = ReportComponent.builder(Component.Type.FILE, 1) .setKey("key_1") - .setPublicKey("public_key_1") .setUuid(FILE_UUID) .build(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java index db85e27e3da..1de550b1323 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ProjectTrackerBaseLazyInputTest.java @@ -76,7 +76,7 @@ public class ProjectTrackerBaseLazyInputTest { ruleRepositoryRule.add(rule.getKey()); rootProjectDto = dbTester.components().insertPublicProject(); ReportComponent rootProject = ReportComponent.builder(Component.Type.FILE, 1) - .setKey(rootProjectDto.getDbKey()) + .setKey(rootProjectDto.getKey()) .setUuid(rootProjectDto.uuid()).build(); reportModulesPath = mock(ReportModulesPath.class); underTest = new ProjectTrackerBaseLazyInput(analysisMetadataHolder, mock(ComponentsWithUnprocessedIssues.class), dbClient, new IssueFieldsSetter(), issuesLoader, @@ -112,7 +112,7 @@ public class ProjectTrackerBaseLazyInputTest { @Test public void migrate_and_return_module_and_folder_issues_on_module() { ComponentDto module = dbTester.components().insertComponent(newModuleDto(rootProjectDto).setPath("moduleAInDb")); - when(reportModulesPath.get()).thenReturn(ImmutableMap.of(module.getDbKey(), "moduleAInReport")); + when(reportModulesPath.get()).thenReturn(ImmutableMap.of(module.getKey(), "moduleAInReport")); ComponentDto folder = dbTester.components().insertComponent(newDirectory(module, "src")); ComponentDto file = dbTester.components().insertComponent(newFileDto(module)); IssueDto openIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("OPEN").setResolution(null)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java index 763986106e3..6de4ad9b575 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/PullRequestSourceBranchMergerTest.java @@ -88,7 +88,7 @@ public class PullRequestSourceBranchMergerTest { issueLifecycle, sourceBranchInputFactory); - ComponentDto projectDto = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY).setUuid(PROJECT_UUID)); + ComponentDto projectDto = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY).setUuid(PROJECT_UUID)); ComponentDto branch1Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch1") .setBranchType(BranchType.PULL_REQUEST) .setMergeBranchUuid(projectDto.uuid())); @@ -98,9 +98,9 @@ public class PullRequestSourceBranchMergerTest { ComponentDto branch3Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch3") .setBranchType(BranchType.PULL_REQUEST) .setMergeBranchUuid(projectDto.uuid())); - db.components().insertComponent(newFileDto(branch1Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1")); - db.components().insertComponent(newFileDto(branch2Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2")); - db.components().insertComponent(newFileDto(branch3Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3")); + db.components().insertComponent(newFileDto(branch1Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1")); + db.components().insertComponent(newFileDto(branch2Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2")); + db.components().insertComponent(newFileDto(branch3Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3")); rule = db.rules().insert(); rawIssue = createIssue("issue1", rule.getKey(), Issue.STATUS_OPEN, new Date()); rawIssuesInput = new DefaultTrackingInput(singletonList(rawIssue), mock(LineHashSequence.class), mock(BlockHashSequence.class)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java index b7d6758719d..ebd2a0573cf 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SiblingsIssueMergerTest.java @@ -105,7 +105,7 @@ public class SiblingsIssueMergerTest { copier = new SiblingsIssueMerger(new SiblingsIssuesLoader(new SiblingComponentsWithOpenIssues(treeRootHolder, metadataHolder, dbClient), dbClient, componentIssuesLoader), tracker, issueLifecycle); - projectDto = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY).setUuid(PROJECT_UUID)); + projectDto = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY).setUuid(PROJECT_UUID)); branch1Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch1") .setBranchType(BranchType.PULL_REQUEST) .setMergeBranchUuid(projectDto.uuid())); @@ -115,9 +115,9 @@ public class SiblingsIssueMergerTest { branch3Dto = db.components().insertProjectBranch(projectDto, b -> b.setKey("myBranch3") .setBranchType(BranchType.PULL_REQUEST) .setMergeBranchUuid(projectDto.uuid())); - fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1")); - fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2")); - fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto).setDbKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3")); + fileOnBranch1Dto = db.components().insertComponent(newFileDto(branch1Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch1")); + fileOnBranch2Dto = db.components().insertComponent(newFileDto(branch2Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch2")); + fileOnBranch3Dto = db.components().insertComponent(newFileDto(branch3Dto).setKey(FILE_1_KEY + ":PULL_REQUEST:myBranch3")); rule = db.rules().insert(); when(branch.getReferenceBranchUuid()).thenReturn(projectDto.uuid()); metadataHolder.setBranch(branch); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsTest.java index 65f792c7b7c..79656060e44 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/SourceBranchComponentUuidsTest.java @@ -79,7 +79,7 @@ public class SourceBranchComponentUuidsTest { when(branch.getPullRequestKey()).thenReturn(PR_KEY); db.components().insertSnapshot(newAnalysis(branch1)); - assertThat(underTest.getSourceBranchComponentUuid(pr1File.getDbKey())).isEqualTo(branch1File.uuid()); + assertThat(underTest.getSourceBranchComponentUuid(pr1File.getKey())).isEqualTo(branch1File.uuid()); assertThat(underTest.hasSourceBranchAnalysis()).isTrue(); } @@ -108,7 +108,7 @@ public class SourceBranchComponentUuidsTest { when(branch.getType()).thenReturn(BranchType.BRANCH); when(branch.getName()).thenReturn(BRANCH_KEY); - assertThat(underTest.getSourceBranchComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getSourceBranchComponentUuid(pr1File.getKey())).isNull(); } @Test @@ -116,6 +116,6 @@ public class SourceBranchComponentUuidsTest { when(branch.getType()).thenReturn(BranchType.PULL_REQUEST); when(branch.getName()).thenReturn(BRANCH_KEY); - assertThat(underTest.getSourceBranchComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getSourceBranchComponentUuid(pr1File.getKey())).isNull(); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsTest.java index 81a318693cd..9271b7f32a0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TargetBranchComponentUuidsTest.java @@ -40,7 +40,7 @@ public class TargetBranchComponentUuidsTest { private static final String BRANCH_KEY = "branch1"; private static final String PR_KEY = "pr1"; - @org.junit.Rule + @Rule public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); @Rule @@ -80,7 +80,7 @@ public class TargetBranchComponentUuidsTest { when(branch.getPullRequestKey()).thenReturn(PR_KEY); db.components().insertSnapshot(newAnalysis(branch1)); - assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isEqualTo(branch1File.uuid()); + assertThat(underTest.getTargetBranchComponentUuid(pr1File.getKey())).isEqualTo(branch1File.uuid()); assertThat(underTest.hasTargetBranchAnalysis()).isTrue(); } @@ -112,7 +112,7 @@ public class TargetBranchComponentUuidsTest { when(branch.getName()).thenReturn("prBranch"); when(branch.getTargetBranchName()).thenReturn(BRANCH_KEY); - assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getTargetBranchComponentUuid(pr1File.getKey())).isNull(); } @Test @@ -121,6 +121,6 @@ public class TargetBranchComponentUuidsTest { when(branch.getName()).thenReturn("prBranch"); when(branch.getTargetBranchName()).thenReturn(BRANCH_KEY); - assertThat(underTest.getTargetBranchComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getTargetBranchComponentUuid(pr1File.getKey())).isNull(); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java index 5560ce021bc..3e8dd552d35 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerReferenceBranchInputFactoryTest.java @@ -60,7 +60,7 @@ public class TrackerReferenceBranchInputFactoryTest { db.fileSources().insertFileSource(fileDto, 3); Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.create(component); @@ -71,7 +71,7 @@ public class TrackerReferenceBranchInputFactoryTest { @Test public void gets_nothing_when_there_is_no_matching_component() { Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.create(component); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryTest.java index ea5b6f3ba4b..2ea7feed1d6 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerSourceBranchInputFactoryTest.java @@ -59,7 +59,7 @@ public class TrackerSourceBranchInputFactoryTest { db.fileSources().insertFileSource(fileDto, 3); Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.createForSourceBranch(component); @@ -76,7 +76,7 @@ public class TrackerSourceBranchInputFactoryTest { db.fileSources().insertFileSource(fileDto, 0); Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.createForSourceBranch(component); @@ -87,7 +87,7 @@ public class TrackerSourceBranchInputFactoryTest { @Test public void gets_nothing_when_there_is_no_matching_component() { Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.createForSourceBranch(component); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryTest.java index 7fa7e8c250f..5c678fee52a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerTargetBranchInputFactoryTest.java @@ -59,7 +59,7 @@ public class TrackerTargetBranchInputFactoryTest { db.fileSources().insertFileSource(fileDto, 3); Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.createForTargetBranch(component); @@ -76,7 +76,7 @@ public class TrackerTargetBranchInputFactoryTest { db.fileSources().insertFileSource(fileDto, 0); Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.createForTargetBranch(component); @@ -87,7 +87,7 @@ public class TrackerTargetBranchInputFactoryTest { @Test public void gets_nothing_when_there_is_no_matching_component() { Component component = mock(Component.class); - when(component.getDbKey()).thenReturn(COMPONENT_KEY); + when(component.getKey()).thenReturn(COMPONENT_KEY); when(component.getType()).thenReturn(Component.Type.FILE); Input input = underTest.createForTargetBranch(component); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsTest.java index 51f632821a4..b5a7a89deea 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/period/NewCodeReferenceBranchComponentUuidsTest.java @@ -78,7 +78,7 @@ public class NewCodeReferenceBranchComponentUuidsTest { public void should_support_db_key_when_looking_for_reference_component() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "branch1", null)); db.components().insertSnapshot(newAnalysis(branch1)); - assertThat(underTest.getComponentUuid(pr1File.getDbKey())).isEqualTo(branch1File.uuid()); + assertThat(underTest.getComponentUuid(pr1File.getKey())).isEqualTo(branch1File.uuid()); } @Test @@ -98,19 +98,19 @@ public class NewCodeReferenceBranchComponentUuidsTest { @Test public void skip_init_if_no_reference_branch_analysis() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "branch1", null)); - assertThat(underTest.getComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getComponentUuid(pr1File.getKey())).isNull(); } @Test public void skip_init_if_branch_not_found() { periodHolder.setPeriod(new Period(NewCodePeriodType.REFERENCE_BRANCH.name(), "unknown", null)); - assertThat(underTest.getComponentUuid(pr1File.getDbKey())).isNull(); + assertThat(underTest.getComponentUuid(pr1File.getKey())).isNull(); } @Test public void throw_ise_if_mode_is_not_reference_branch() { periodHolder.setPeriod(new Period(NewCodePeriodType.NUMBER_OF_DAYS.name(), "10", 1000L)); - assertThatThrownBy(() -> underTest.getComponentUuid(pr1File.getDbKey())) + assertThatThrownBy(() -> underTest.getComponentUuid(pr1File.getKey())) .isInstanceOf(IllegalStateException.class); } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java index 12a2ac8948c..d5902805e5b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java @@ -112,7 +112,7 @@ public class ScmInfoDbLoaderTest { String referenceFileUuid = "referenceFileUuid"; String hash = computeSourceHash(1); - when(referenceBranchComponentUuids.getComponentUuid(FILE.getDbKey())).thenReturn(referenceFileUuid); + when(referenceBranchComponentUuids.getComponentUuid(FILE.getKey())).thenReturn(referenceFileUuid); addFileSourceInDb("henry", DATE_1, "rev-1", hash, referenceFileUuid); DbScmInfo scmInfo = underTest.getScmInfo(FILE).get(); @@ -131,7 +131,7 @@ public class ScmInfoDbLoaderTest { String targetBranchFileUuid = "targetBranchFileUuid"; String hash = computeSourceHash(1); - when(referenceBranchComponentUuids.getComponentUuid(FILE.getDbKey())).thenReturn(targetBranchFileUuid); + when(referenceBranchComponentUuids.getComponentUuid(FILE.getKey())).thenReturn(targetBranchFileUuid); addFileSourceInDb("henry", DATE_1, "rev-1", hash, targetBranchFileUuid); DbScmInfo scmInfo = underTest.getScmInfo(FILE).get(); @@ -152,7 +152,7 @@ public class ScmInfoDbLoaderTest { String targetBranchFileUuid = "targetBranchFileUuid"; String hash = computeSourceHash(1); - when(newCodeReferenceBranchComponentUuids.getComponentUuid(FILE.getDbKey())).thenReturn(targetBranchFileUuid); + when(newCodeReferenceBranchComponentUuids.getComponentUuid(FILE.getKey())).thenReturn(targetBranchFileUuid); addFileSourceInDb("henry", DATE_1, "rev-1", hash, targetBranchFileUuid); DbScmInfo scmInfo = underTest.getScmInfo(FILE).get(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionTest.java index e080f565cc1..78ed47cfc77 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/DbLineHashVersionTest.java @@ -66,7 +66,7 @@ public class DbLineHashVersionTest { assertThat(underTest.hasLineHashesWithSignificantCode(component)).isFalse(); verify(analysisMetadataHolder).isPullRequest(); - verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey()); + verify(referenceBranchComponentUuids).getComponentUuid(component.getKey()); } @Test @@ -81,7 +81,7 @@ public class DbLineHashVersionTest { assertThat(underTest.hasLineHashesWithSignificantCode(component)).isFalse(); verify(analysisMetadataHolder).isPullRequest(); - verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey()); + verify(referenceBranchComponentUuids).getComponentUuid(component.getKey()); } @Test @@ -97,7 +97,7 @@ public class DbLineHashVersionTest { assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue(); verify(analysisMetadataHolder).isPullRequest(); - verify(referenceBranchComponentUuids).getComponentUuid(component.getDbKey()); + verify(referenceBranchComponentUuids).getComponentUuid(component.getKey()); } @Test diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java index e6643465dee..c6e5069d34f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java @@ -233,11 +233,11 @@ public class BuildComponentTreeStepTest { @Test public void return_existing_uuids() { setAnalysisMetadataHolder(); - ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); ComponentDto directory = newDirectory(project, "CDEF", REPORT_DIR_PATH_1); - insertComponent(directory.setDbKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1)); + insertComponent(directory.setKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1)); insertComponent(newFileDto(project, directory, "DEFG") - .setDbKey(REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1) + .setKey(REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1) .setPath(REPORT_FILE_PATH_1)); // new structure, without modules @@ -247,7 +247,7 @@ public class BuildComponentTreeStepTest { underTest.execute(new TestComputationStepContext()); verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), "ABCD"); - verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1, "CDEF"); + verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1, "CDEF"); verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, "DEFG"); } @@ -259,7 +259,7 @@ public class BuildComponentTreeStepTest { when(branch.generateKey(any(), any())).thenReturn("generated"); analysisMetadataHolder.setRootComponentRef(ROOT_REF) .setAnalysisDate(ANALYSIS_DATE) - .setProject(Project.from(newPrivateProjectDto().setDbKey(REPORT_PROJECT_KEY))) + .setProject(Project.from(newPrivateProjectDto().setKey(REPORT_PROJECT_KEY))) .setBranch(branch); BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF)); @@ -267,10 +267,8 @@ public class BuildComponentTreeStepTest { underTest.execute(new TestComputationStepContext()); - verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null); - - verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated", REPORT_DIR_PATH_1); - verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null); + verifyComponentByRef(ROOT_REF, "generated", analysisMetadataHolder.getProject().getName(), null); + verifyComponentByRef(FILE_1_REF, "generated", REPORT_FILE_NAME_1, null); } @Test @@ -280,7 +278,7 @@ public class BuildComponentTreeStepTest { Branch branch = mock(Branch.class); when(branch.getName()).thenReturn(branchDto.getBranch()); when(branch.isMain()).thenReturn(false); - when(branch.generateKey(any(), any())).thenReturn(branchDto.getDbKey()); + when(branch.generateKey(any(), any())).thenReturn(branchDto.getKey()); analysisMetadataHolder.setRootComponentRef(ROOT_REF) .setAnalysisDate(ANALYSIS_DATE) .setProject(Project.from(projectDto)) @@ -290,7 +288,7 @@ public class BuildComponentTreeStepTest { underTest.execute(new TestComputationStepContext()); - verifyComponentByRef(ROOT_REF, branchDto.getDbKey(), branchDto.getKey(), analysisMetadataHolder.getProject().getName(), branchDto.uuid()); + verifyComponentByRef(ROOT_REF, branchDto.getKey(), analysisMetadataHolder.getProject().getName(), branchDto.uuid()); } @Test @@ -302,9 +300,9 @@ public class BuildComponentTreeStepTest { underTest.execute(new TestComputationStepContext()); - verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null); + verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null); verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1); - verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null); + verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null); } @Test @@ -348,7 +346,7 @@ public class BuildComponentTreeStepTest { @Test public void set_no_base_project_snapshot_when_no_last_snapshot() { setAnalysisMetadataHolder(); - ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setLast(false)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -360,7 +358,7 @@ public class BuildComponentTreeStepTest { @Test public void set_base_project_snapshot_when_last_snapshot_exist() { setAnalysisMetadataHolder(); - ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setLast(true)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -383,7 +381,7 @@ public class BuildComponentTreeStepTest { @UseDataProvider("oneParameterNullNonNullCombinations") public void set_projectVersion_to_previous_analysis_when_not_set(@Nullable String previousAnalysisProjectVersion) { setAnalysisMetadataHolder(); - ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -416,7 +414,7 @@ public class BuildComponentTreeStepTest { String scannerProjectVersion = randomAlphabetic(12); setAnalysisMetadataHolder(); reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING)); - ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setDbKey(REPORT_PROJECT_KEY)); + ComponentDto project = insertComponent(newPrivateProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true)); reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); @@ -454,27 +452,18 @@ public class BuildComponentTreeStepTest { } private void verifyComponentByRef(int ref, String key, String shortName) { - verifyComponentByRef(ref, key, key, shortName, null); - } - - private void verifyComponentByRef(int ref, String key, String shortName, @Nullable String uuid) { - verifyComponentByRef(ref, key, key, shortName, uuid); + verifyComponentByRef(ref, key, shortName, null); } - private void verifyComponentByKey(String publicKey, String shortName) { - verifyComponentByKey(publicKey, publicKey, shortName, null); + private void verifyComponentByKey(String key, String shortName) { + verifyComponentByKey(key, shortName, null); } - private void verifyComponentByKey(String publicKey, String key, String shortName) { - verifyComponentByKey(publicKey, key, shortName, null); - } - - private void verifyComponentByKey(String publicKey, String key, String shortName, @Nullable String uuid) { + private void verifyComponentByKey(String key, String shortName, @Nullable String uuid) { Map componentsByKey = indexAllComponentsInTreeByKey(treeRootHolder.getRoot()); - Component component = componentsByKey.get(publicKey); - assertThat(component.getDbKey()).isEqualTo(key); + Component component = componentsByKey.get(key); + assertThat(component.getKey()).isEqualTo(key); assertThat(component.getReportAttributes().getRef()).isNull(); - assertThat(component.getKey()).isEqualTo(publicKey); assertThat(component.getShortName()).isEqualTo(shortName); if (uuid != null) { assertThat(component.getUuid()).isEqualTo(uuid); @@ -483,11 +472,10 @@ public class BuildComponentTreeStepTest { } } - private void verifyComponentByRef(int ref, String key, String publicKey, String shortName, @Nullable String uuid) { + private void verifyComponentByRef(int ref, String key, String shortName, @Nullable String uuid) { Map componentsByRef = indexAllComponentsInTreeByRef(treeRootHolder.getRoot()); Component component = componentsByRef.get(ref); - assertThat(component.getDbKey()).isEqualTo(key); - assertThat(component.getKey()).isEqualTo(publicKey); + assertThat(component.getKey()).isEqualTo(key); assertThat(component.getShortName()).isEqualTo(shortName); if (uuid != null) { assertThat(component.getUuid()).isEqualTo(uuid); @@ -572,7 +560,7 @@ public class BuildComponentTreeStepTest { analysisMetadataHolder.setRootComponentRef(ROOT_REF) .setAnalysisDate(ANALYSIS_DATE) .setBranch(branch) - .setProject(Project.from(newPrivateProjectDto().setDbKey(REPORT_PROJECT_KEY).setName(REPORT_PROJECT_KEY))); + .setProject(Project.from(newPrivateProjectDto().setKey(REPORT_PROJECT_KEY).setName(REPORT_PROJECT_KEY))); } public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String buildString) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java index ce62cb4792d..1a8a328a3de 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStepTest.java @@ -157,7 +157,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { .build()), singletonList( new Block.Builder() - .setResourceId(otherFile.getDbKey()) + .setResourceId(otherFile.getKey()) .setBlockHash(new ByteArray(hash)) .setIndexInFile(duplicate.getIndexInFile()) .setLines(duplicate.getStartLine(), duplicate.getEndLine()) @@ -238,14 +238,14 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { Map duplicationBlocksByIndex = blocksByIndexInFile(duplicationBlocks.getValue()); assertThat(duplicationBlocksByIndex.get(0)).isEqualTo( new Block.Builder() - .setResourceId(otherFile.getDbKey()) + .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.getDbKey()) + .setResourceId(otherFile.getKey()) .setBlockHash(new ByteArray(originBlock2.getHash())) .setIndexInFile(duplicate2.getIndexInFile()) .setLines(duplicate2.getStartLine(), duplicate2.getEndLine()) @@ -319,7 +319,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { } private ComponentDto createProject(String projectKey) { - ComponentDto project = ComponentTesting.newPrivateProjectDto().setDbKey(projectKey); + ComponentDto project = ComponentTesting.newPrivateProjectDto().setKey(projectKey); return dbTester.components().insertComponent(project); } @@ -332,7 +332,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { private ComponentDto createFile(String fileKey, ComponentDto project) { ComponentDto file = ComponentTesting.newFileDto(project, null) - .setDbKey(fileKey) + .setKey(fileKey) .setLanguage(XOO_LANGUAGE); dbClient.componentDao().insert(dbSession, file); dbSession.commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java index 6339dbfa4a4..05131c002c9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java @@ -76,7 +76,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { public void setUp() { CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY); underTest = createStep(defaultOrgCeTask); - project = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY)); + project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)); } @Test @@ -127,7 +127,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { Project project = analysisMetadataHolder.getProject(); assertThat(project.getUuid()).isEqualTo(this.project.uuid()); - assertThat(project.getKey()).isEqualTo(this.project.getDbKey()); + assertThat(project.getKey()).isEqualTo(this.project.getKey()); assertThat(project.getName()).isEqualTo(this.project.name()); assertThat(project.getDescription()).isEqualTo(this.project.description()); } @@ -215,12 +215,12 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComponentDto otherProject = db.components().insertPublicProject(); reportReader.setMetadata( ScannerReport.Metadata.newBuilder() - .setProjectKey(otherProject.getDbKey()) + .setProjectKey(otherProject.getKey()) .build()); assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())) .isInstanceOf(MessageException.class) - .hasMessage("ProjectKey in report (" + otherProject.getDbKey() + ") is not consistent with projectKey under which the report has been submitted (" + PROJECT_KEY + ")"); + .hasMessage("ProjectKey in report (" + otherProject.getKey() + ") is not consistent with projectKey under which the report has been submitted (" + PROJECT_KEY + ")"); } @@ -229,7 +229,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComponentDto otherProject = db.components().insertPublicProject(); reportReader.setMetadata( ScannerReport.Metadata.newBuilder() - .setProjectKey(otherProject.getDbKey()) + .setProjectKey(otherProject.getKey()) .build()); try { @@ -244,7 +244,7 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComponentDto otherProject = db.components().insertPublicProject(); reportReader.setMetadata( ScannerReport.Metadata.newBuilder() - .setProjectKey(otherProject.getDbKey()) + .setProjectKey(otherProject.getKey()) .setAnalysisDate(ANALYSIS_DATE) .build()); @@ -260,11 +260,11 @@ public class LoadReportAnalysisMetadataHolderStepTest { ComponentDto project = db.components().insertPublicProject(); ScannerReport.Metadata.Builder metadataBuilder = newBatchReportBuilder(); metadataBuilder - .setProjectKey(project.getDbKey()); + .setProjectKey(project.getKey()); metadataBuilder.putQprofilesPerLanguage("js", ScannerReport.Metadata.QProfile.newBuilder().setKey("p1").setName("Sonar way").setLanguage("js").build()); reportReader.setMetadata(metadataBuilder.build()); - ComputationStep underTest = createStep(createCeTask(project.getDbKey())); + ComputationStep underTest = createStep(createCeTask(project.getKey())); underTest.execute(new TestComputationStepContext()); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java index 92b0c04112c..b20ca1a6088 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java @@ -51,7 +51,7 @@ public class PersistComponentsStepTest { String projectKey = randomAlphabetic(20); doReturn(component).when(treeRootHolder).getRoot(); - doReturn(projectKey).when(component).getDbKey(); + doReturn(projectKey).when(component).getKey(); doReturn(componentDao).when(dbClient).componentDao(); doReturn(emptyList()).when(componentDao).selectAllComponentsFromProjectKey(any(DbSession.class), eq(projectKey)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java index 3b39bdcdc34..e6dabb7a5b9 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java @@ -175,11 +175,11 @@ public class PersistDuplicationDataStepTest extends BaseStepTest { private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() - .setDbKey(key) + .setKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) - .setProjectUuid(uuid); + .setBranchUuid(uuid); db.components().insertComponent(componentDto); return componentDto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java index be8adf493fc..a4a2a343b2b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java @@ -267,7 +267,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { .build()) .build(); treeRootHolder.setRoot(project); - analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getDbKey(), project.getName(), project.getDescription(), emptyList())); + analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getKey(), project.getName(), project.getDescription(), emptyList())); // components as persisted in db ComponentDto projectDto = insertComponent("project-key", "project-uuid"); @@ -304,11 +304,11 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest { private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() - .setDbKey(key) + .setKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) - .setProjectUuid(uuid); + .setBranchUuid(uuid); db.components().insertComponent(componentDto); return componentDto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java index 83e62f7c60b..c293d0a4538 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java @@ -223,11 +223,11 @@ public class PersistMeasuresStepTest extends BaseStepTest { private ComponentDto insertComponent(String key, String uuid) { ComponentDto componentDto = new ComponentDto() - .setDbKey(key) + .setKey(key) .setUuid(uuid) .setUuidPath(uuid + ".") .setRootUuid(uuid) - .setProjectUuid(uuid); + .setBranchUuid(uuid); db.components().insertComponent(componentDto); return componentDto; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java index a68cff2659a..0ae78766c07 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java @@ -97,7 +97,7 @@ public class QualityGateEventsStepTest { public void setUp() { when(metricRepository.getByKey(ALERT_STATUS_KEY)).thenReturn(alertStatusMetric); analysisMetadataHolder - .setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getDbKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList())); + .setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList())); analysisMetadataHolder.setBranch(mock(Branch.class)); treeRootHolder.setRoot(PROJECT_COMPONENT); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java index 06cddbc136d..dd4de426878 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java @@ -93,13 +93,13 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_analysis() { String projectVersion = randomAlphabetic(10); - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); dbTester.components().insertComponent(projectDto); - ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module"); + ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module"); dbTester.components().insertComponent(moduleDto); - ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir"); + ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir"); dbTester.components().insertComponent(directoryDto); - ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java"); + ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java"); dbTester.components().insertComponent(fileDto); dbTester.getSession().commit(); @@ -134,7 +134,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_snapshots_with_new_code_period() { - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); dbTester.components().insertComponent(projectDto); SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime()); dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); @@ -156,18 +156,18 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { public void only_persist_snapshots_with_new_code_period_on_project_and_module() { periodsHolder.setPeriod(new Period("PREVIOUS_VERSION", null, analysisDate)); - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); dbTester.components().insertComponent(projectDto); SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto); dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot); - ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setDbKey("MODULE_KEY").setName("Module"); + ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module"); dbTester.components().insertComponent(moduleDto); - ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setDbKey("MODULE_KEY:src/main/java/dir"); + ComponentDto directoryDto = ComponentTesting.newDirectory(moduleDto, "CDEF", "MODULE_KEY:src/main/java/dir").setKey("MODULE_KEY:src/main/java/dir"); dbTester.components().insertComponent(directoryDto); - ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setDbKey("MODULE_KEY:src/main/java/dir/Foo.java"); + ComponentDto fileDto = ComponentTesting.newFileDto(moduleDto, directoryDto, "DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java"); dbTester.components().insertComponent(fileDto); dbTester.getSession().commit(); @@ -185,7 +185,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void set_no_period_on_snapshots_when_no_period() { - ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY).setName("Project"); + ComponentDto projectDto = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); dbTester.components().insertComponent(projectDto); SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto); dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java index efaca113b35..18fe2164751 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java @@ -43,8 +43,10 @@ import org.sonar.ce.task.step.ComputationStep; import org.sonar.ce.task.step.TestComputationStepContext; import org.sonar.db.DbClient; import org.sonar.db.DbTester; +import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; +import org.sonar.db.project.ProjectDto; import org.sonar.server.project.Project; import static org.assertj.core.api.Assertions.assertThat; @@ -125,7 +127,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directoryDto.moduleUuid()).isEqualTo(projectDto.uuid()); assertThat(directoryDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath()); assertThat(directoryDto.getMainBranchProjectUuid()).isNull(); - assertThat(directoryDto.projectUuid()).isEqualTo(projectDto.uuid()); + assertThat(directoryDto.branchUuid()).isEqualTo(projectDto.uuid()); assertThat(directoryDto.qualifier()).isEqualTo("DIR"); assertThat(directoryDto.scope()).isEqualTo("DIR"); assertThat(directoryDto.getRootUuid()).isEqualTo(projectDto.uuid()); @@ -142,7 +144,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(fileDto.moduleUuid()).isEqualTo(projectDto.uuid()); assertThat(fileDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath()); assertThat(fileDto.getMainBranchProjectUuid()).isNull(); - assertThat(fileDto.projectUuid()).isEqualTo(projectDto.uuid()); + assertThat(fileDto.branchUuid()).isEqualTo(projectDto.uuid()); assertThat(fileDto.qualifier()).isEqualTo("FIL"); assertThat(fileDto.scope()).isEqualTo("FIL"); assertThat(fileDto.getRootUuid()).isEqualTo(projectDto.uuid()); @@ -151,7 +153,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { @Test public void persist_components_of_existing_branch() { - ComponentDto project = prepareBranch("feature/foo"); + ComponentDto branch = prepareBranch("feature/foo"); Component file = builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java") .setName("src/main/java/dir/Foo.java") .setShortName("Foo.java") @@ -163,7 +165,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .setShortName("dir") .addChildren(file) .build(); - Component treeRoot = asTreeRoot(project) + Component treeRoot = asTreeRoot(branch) .addChildren(directory) .build(); treeRootHolder.setRoot(treeRoot); @@ -172,23 +174,23 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(db.countRowsOfTable("components")).isEqualTo(3); - ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); + ComponentDto directoryDto = dbClient.componentDao().selectByKeyAndBranch(db.getSession(), "PROJECT_KEY:src/main/java/dir", "feature/foo").get(); assertThat(directoryDto.name()).isEqualTo("dir"); assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir"); assertThat(directoryDto.description()).isNull(); assertThat(directoryDto.path()).isEqualTo("src/main/java/dir"); assertThat(directoryDto.uuid()).isEqualTo("CDEF"); - assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + project.uuid() + UUID_PATH_SEPARATOR); - assertThat(directoryDto.moduleUuid()).isEqualTo(project.uuid()); - assertThat(directoryDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(project.uuid()); - assertThat(directoryDto.projectUuid()).isEqualTo(project.uuid()); + assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + branch.uuid() + UUID_PATH_SEPARATOR); + assertThat(directoryDto.moduleUuid()).isEqualTo(branch.uuid()); + assertThat(directoryDto.moduleUuidPath()).isEqualTo(branch.moduleUuidPath()); + assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(branch.uuid()); + assertThat(directoryDto.branchUuid()).isEqualTo(branch.uuid()); assertThat(directoryDto.qualifier()).isEqualTo("DIR"); assertThat(directoryDto.scope()).isEqualTo("DIR"); - assertThat(directoryDto.getRootUuid()).isEqualTo(project.uuid()); + assertThat(directoryDto.getRootUuid()).isEqualTo(branch.uuid()); assertThat(directoryDto.getCreatedAt()).isEqualTo(now); - ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); + ComponentDto fileDto = dbClient.componentDao().selectByKeyAndBranch(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java", "feature/foo").get(); assertThat(fileDto.name()).isEqualTo("Foo.java"); assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java"); assertThat(fileDto.description()).isNull(); @@ -196,13 +198,13 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(fileDto.language()).isEqualTo("java"); assertThat(fileDto.uuid()).isEqualTo("DEFG"); assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR); - assertThat(fileDto.moduleUuid()).isEqualTo(project.uuid()); - assertThat(fileDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(project.uuid()); - assertThat(fileDto.projectUuid()).isEqualTo(project.uuid()); + assertThat(fileDto.moduleUuid()).isEqualTo(branch.uuid()); + assertThat(fileDto.moduleUuidPath()).isEqualTo(branch.moduleUuidPath()); + assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(branch.uuid()); + assertThat(fileDto.branchUuid()).isEqualTo(branch.uuid()); assertThat(fileDto.qualifier()).isEqualTo("FIL"); assertThat(fileDto.scope()).isEqualTo("FIL"); - assertThat(fileDto.getRootUuid()).isEqualTo(project.uuid()); + assertThat(fileDto.getRootUuid()).isEqualTo(branch.uuid()); assertThat(fileDto.getCreatedAt()).isEqualTo(now); } @@ -212,16 +214,16 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { treeRootHolder.setRoot( asTreeRoot(projectDto) .addChildren( - builder(FILE, 2).setUuid("DEFG").setKey(projectDto.getDbKey() + ":pom.xml") + builder(FILE, 2).setUuid("DEFG").setKey(projectDto.getKey() + ":pom.xml") .setName("pom.xml") .build()) .build()); underTest.execute(new TestComputationStepContext()); - assertThat(dbClient.componentDao().selectByKey(db.getSession(), projectDto.getDbKey() + ":/")).isNotPresent(); + assertThat(dbClient.componentDao().selectByKey(db.getSession(), projectDto.getKey() + ":/")).isNotPresent(); - ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), projectDto.getDbKey() + ":pom.xml").get(); + ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), projectDto.getKey() + ":pom.xml").get(); assertThat(file.name()).isEqualTo("pom.xml"); assertThat(file.path()).isEqualTo("pom.xml"); } @@ -256,9 +258,9 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { @Test public void update_file_to_directory_change_scope() { ComponentDto project = prepareProject(); - ComponentDto directory = ComponentTesting.newDirectory(project, "src").setUuid("CDEF").setDbKey("PROJECT_KEY:src"); + ComponentDto directory = ComponentTesting.newDirectory(project, "src").setUuid("CDEF").setKey("PROJECT_KEY:src"); ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/foo").setName("foo") - .setDbKey("PROJECT_KEY:src/foo"); + .setKey("PROJECT_KEY:src/foo"); dbClient.componentDao().insert(db.getSession(), directory, file); db.getSession().commit(); @@ -294,7 +296,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { @Test public void update_module_to_directory_change_scope() { ComponentDto project = prepareProject(); - ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("CDEF").setDbKey("MODULE_KEY").setPath("module"); + ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("CDEF").setKey("MODULE_KEY").setPath("module"); dbClient.componentDao().insert(db.getSession(), module); db.getSession().commit(); @@ -330,7 +332,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { db.getSession().commit(); treeRootHolder.setRoot( - builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) + builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()) .setName("Project") .addChildren( builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir") @@ -347,7 +349,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(db.countRowsOfTable("components")).isEqualTo(3); - ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get(); + ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get(); assertThat(projectReloaded.uuid()).isEqualTo(project.uuid()); assertThat(projectReloaded.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT); assertThat(projectReloaded.getMainBranchProjectUuid()).isNull(); @@ -356,7 +358,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directory.getUuidPath()).isEqualTo(directory.getUuidPath()); assertThat(directory.moduleUuid()).isEqualTo(project.uuid()); assertThat(directory.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(directory.projectUuid()).isEqualTo(project.uuid()); + assertThat(directory.branchUuid()).isEqualTo(project.uuid()); assertThat(directory.getRootUuid()).isEqualTo(project.uuid()); assertThat(directory.getMainBranchProjectUuid()).isNull(); @@ -364,7 +366,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(file.getUuidPath()).isEqualTo(file.getUuidPath()); assertThat(file.moduleUuid()).isEqualTo(project.uuid()); assertThat(file.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(file.projectUuid()).isEqualTo(project.uuid()); + assertThat(file.branchUuid()).isEqualTo(project.uuid()); assertThat(file.getRootUuid()).isEqualTo(project.uuid()); assertThat(file.getMainBranchProjectUuid()).isNull(); } @@ -372,14 +374,14 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { @Test public void nothing_to_persist() { ComponentDto project = prepareProject(); - ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setDbKey("PROJECT_KEY:src/main/java/dir"); + ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir"); ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java") - .setDbKey("PROJECT_KEY:src/main/java/dir/Foo.java"); + .setKey("PROJECT_KEY:src/main/java/dir/Foo.java"); dbClient.componentDao().insert(db.getSession(), directory, file); db.getSession().commit(); treeRootHolder.setRoot( - builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) + builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()) .setName("Project") .addChildren( builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir") @@ -394,15 +396,15 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("components")).isEqualTo(3); - assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().uuid()).isEqualTo(project.uuid()); + assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get().uuid()).isEqualTo(project.uuid()); assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().uuid()).isEqualTo(directory.uuid()); assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().uuid()).isEqualTo(file.uuid()); - ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get(); + ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get(); assertThat(projectReloaded.uuid()).isEqualTo(project.uuid()); assertThat(projectReloaded.moduleUuid()).isEqualTo(project.moduleUuid()); assertThat(projectReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(projectReloaded.projectUuid()).isEqualTo(project.projectUuid()); + assertThat(projectReloaded.branchUuid()).isEqualTo(project.branchUuid()); assertThat(projectReloaded.getRootUuid()).isEqualTo(project.getRootUuid()); ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get(); @@ -410,7 +412,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directoryReloaded.getUuidPath()).isEqualTo(directory.getUuidPath()); assertThat(directoryReloaded.moduleUuid()).isEqualTo(directory.moduleUuid()); assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(directory.moduleUuidPath()); - assertThat(directoryReloaded.projectUuid()).isEqualTo(directory.projectUuid()); + assertThat(directoryReloaded.branchUuid()).isEqualTo(directory.branchUuid()); assertThat(directoryReloaded.getRootUuid()).isEqualTo(directory.getRootUuid()); assertThat(directoryReloaded.name()).isEqualTo(directory.name()); assertThat(directoryReloaded.path()).isEqualTo(directory.path()); @@ -420,7 +422,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(fileReloaded.getUuidPath()).isEqualTo(file.getUuidPath()); assertThat(fileReloaded.moduleUuid()).isEqualTo(file.moduleUuid()); assertThat(fileReloaded.moduleUuidPath()).isEqualTo(file.moduleUuidPath()); - assertThat(fileReloaded.projectUuid()).isEqualTo(file.projectUuid()); + assertThat(fileReloaded.branchUuid()).isEqualTo(file.branchUuid()); assertThat(fileReloaded.getRootUuid()).isEqualTo(file.getRootUuid()); assertThat(fileReloaded.name()).isEqualTo(file.name()); assertThat(fileReloaded.path()).isEqualTo(file.path()); @@ -429,14 +431,14 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { @Test public void update_module_uuid_when_moving_a_module() { ComponentDto project = prepareProject(); - ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setDbKey("PROJECT_KEY:src/main/java/dir"); + ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir"); ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java") - .setDbKey("PROJECT_KEY:src/main/java/dir/Foo.java"); + .setKey("PROJECT_KEY:src/main/java/dir/Foo.java"); dbClient.componentDao().insert(db.getSession(), directory, file); db.getSession().commit(); treeRootHolder.setRoot( - builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) + builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()) .setName("Project") .addChildren( builder(DIRECTORY, 4).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir") @@ -462,7 +464,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directoryReloaded.getUuidPath()).isEqualTo(directoryReloaded.getUuidPath()); assertThat(directoryReloaded.moduleUuid()).isEqualTo(project.uuid()); assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(directoryReloaded.projectUuid()).isEqualTo(project.uuid()); + assertThat(directoryReloaded.branchUuid()).isEqualTo(project.uuid()); assertThat(directoryReloaded.getRootUuid()).isEqualTo(project.uuid()); ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get(); @@ -471,7 +473,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(fileReloaded.getUuidPath()).isEqualTo(fileReloaded.getUuidPath()); assertThat(fileReloaded.moduleUuid()).isEqualTo(project.uuid()); assertThat(fileReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(fileReloaded.projectUuid()).isEqualTo(project.uuid()); + assertThat(fileReloaded.branchUuid()).isEqualTo(project.uuid()); assertThat(fileReloaded.getRootUuid()).isEqualTo(project.uuid()); } @@ -482,7 +484,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { db.getSession().commit(); treeRootHolder.setRoot( - builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) + builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()) .build()); underTest.execute(new TestComputationStepContext()); @@ -498,19 +500,19 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { .setLongName("src/main/java/dir") .setName("dir") .setUuid("CDEF") - .setDbKey("PROJECT_KEY:src/main/java/dir") + .setKey("PROJECT_KEY:src/main/java/dir") .setEnabled(false); ComponentDto removedFile = ComponentTesting.newFileDto(project, removedDirectory, "DEFG") .setPath("src/main/java/dir/Foo.java") .setLongName("src/main/java/dir/Foo.java") .setName("Foo.java") - .setDbKey("PROJECT_KEY:src/main/java/dir/Foo.java") + .setKey("PROJECT_KEY:src/main/java/dir/Foo.java") .setEnabled(false); dbClient.componentDao().insert(db.getSession(), removedDirectory, removedFile); db.getSession().commit(); treeRootHolder.setRoot( - builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()) + builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()) .setName("Project") .addChildren( builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir") @@ -527,20 +529,20 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("components")).isEqualTo(3); - assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().uuid()).isEqualTo(project.uuid()); + assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get().uuid()).isEqualTo(project.uuid()); assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().uuid()).isEqualTo(removedDirectory.uuid()); assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().uuid()).isEqualTo(removedFile.uuid()); - assertExistButDisabled(removedDirectory.getDbKey(), removedFile.getDbKey()); + assertExistButDisabled(removedDirectory.getKey(), removedFile.getKey()); // commit the functional transaction dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid()); - ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get(); + ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get(); assertThat(projectReloaded.uuid()).isEqualTo(project.uuid()); assertThat(projectReloaded.getUuidPath()).isEqualTo(project.getUuidPath()); assertThat(projectReloaded.moduleUuid()).isEqualTo(project.moduleUuid()); assertThat(projectReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath()); - assertThat(projectReloaded.projectUuid()).isEqualTo(project.projectUuid()); + assertThat(projectReloaded.branchUuid()).isEqualTo(project.branchUuid()); assertThat(projectReloaded.getRootUuid()).isEqualTo(project.getRootUuid()); assertThat(projectReloaded.isEnabled()).isTrue(); @@ -549,7 +551,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(directoryReloaded.getUuidPath()).isEqualTo(removedDirectory.getUuidPath()); assertThat(directoryReloaded.moduleUuid()).isEqualTo(removedDirectory.moduleUuid()); assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(removedDirectory.moduleUuidPath()); - assertThat(directoryReloaded.projectUuid()).isEqualTo(removedDirectory.projectUuid()); + assertThat(directoryReloaded.branchUuid()).isEqualTo(removedDirectory.branchUuid()); assertThat(directoryReloaded.getRootUuid()).isEqualTo(removedDirectory.getRootUuid()); assertThat(directoryReloaded.name()).isEqualTo(removedDirectory.name()); assertThat(directoryReloaded.longName()).isEqualTo(removedDirectory.longName()); @@ -561,7 +563,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { assertThat(fileReloaded.getUuidPath()).isEqualTo(removedFile.getUuidPath()); assertThat(fileReloaded.moduleUuid()).isEqualTo(removedFile.moduleUuid()); assertThat(fileReloaded.moduleUuidPath()).isEqualTo(removedFile.moduleUuidPath()); - assertThat(fileReloaded.projectUuid()).isEqualTo(removedFile.projectUuid()); + assertThat(fileReloaded.branchUuid()).isEqualTo(removedFile.branchUuid()); assertThat(fileReloaded.getRootUuid()).isEqualTo(removedFile.getRootUuid()); assertThat(fileReloaded.name()).isEqualTo(removedFile.name()); assertThat(fileReloaded.path()).isEqualTo(removedFile.path()); @@ -580,7 +582,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { ComponentDto project = prepareProject(p -> p.setPrivate(true)); ComponentDto module = newModuleDto(project).setPrivate(false); db.components().insertComponent(module); - ComponentDto dir = db.components().insertComponent(newDirectory(module, "DEFG", "Directory").setDbKey("DIR").setPrivate(true)); + ComponentDto dir = db.components().insertComponent(newDirectory(module, "DEFG", "Directory").setKey("DIR").setPrivate(true)); treeRootHolder.setRoot(createSampleProjectComponentTree(project)); underTest.execute(new TestComputationStepContext()); @@ -592,7 +594,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { } private ReportComponent createSampleProjectComponentTree(ComponentDto project) { - return createSampleProjectComponentTree(project.uuid(), project.getDbKey()); + return createSampleProjectComponentTree(project.uuid(), project.getKey()); } private ReportComponent createSampleProjectComponentTree(String projectUuid, String projectKey) { @@ -610,7 +612,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { } private ReportComponent.Builder asTreeRoot(ComponentDto project) { - return builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey()).setName(project.name()); + return builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setName(project.name()); } private ComponentDto prepareProject() { @@ -625,14 +627,11 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { } private ComponentDto prepareBranch(String branchName) { - return prepareBranch(branchName, defaults()); - } - - private ComponentDto prepareBranch(String branchName, Consumer populators) { - ComponentDto dto = db.components().insertPrivateProject(populators); - analysisMetadataHolder.setProject(Project.from(dto)); + ComponentDto projectDto = db.components().insertPublicProject(); + ComponentDto branchDto = db.components().insertProjectBranch(projectDto, b -> b.setKey(branchName)); + analysisMetadataHolder.setProject(Project.from(projectDto)); analysisMetadataHolder.setBranch(new TestBranch(branchName)); - return dto; + return branchDto; } private static Consumer defaults() { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java index 338d7516a28..a0b7c98b26b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -497,8 +497,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void do_not_send_new_issues_notifications_for_hotspot() { UserDto user = db.users().insertUser(); - ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); - ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); + ComponentDto project = newPrivateProjectDto().setKey(PROJECT.getKey()).setLongName(PROJECT.getName()); + ComponentDto file = newFileDto(project).setKey(FILE.getKey()).setLongName(FILE.getName()); RuleDto ruleDefinitionDto = newRule(); prepareIssue(ANALYSE_DATE, user, project, file, ruleDefinitionDto, RuleType.SECURITY_HOTSPOT); analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList())); @@ -519,12 +519,12 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { private void sendIssueChangeNotification(long issueCreatedAt) { UserDto user = db.users().insertUser(); - ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); + ComponentDto project = newPrivateProjectDto().setKey(PROJECT.getKey()).setLongName(PROJECT.getName()); analysisMetadataHolder.setProject(Project.from(project)); - ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); - treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(project.getDbKey()).setPublicKey(project.getKey()).setName(project.longName()).setUuid(project.uuid()) + ComponentDto file = newFileDto(project).setKey(FILE.getKey()).setLongName(FILE.getName()); + treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(project.getKey()).setName(project.longName()).setUuid(project.uuid()) .addChildren( - builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()) + builder(Type.FILE, 11).setKey(file.getKey()).setName(file.longName()).build()) .build()); RuleDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; @@ -550,7 +550,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { DefaultIssue issue = newIssue(ruleDefinitionDto, project, file).setType(type).toDefaultIssue() .setNew(false).setChanged(true).setSendNotifications(true).setCreationDate(new Date(issueCreatedAt)).setAssigneeUuid(user.getUuid()); protoIssueCache.newAppender().append(issue).close(); - when(notificationService.hasProjectSubscribersForTypes(project.projectUuid(), NOTIF_TYPES)).thenReturn(true); + when(notificationService.hasProjectSubscribersForTypes(project.branchUuid(), NOTIF_TYPES)).thenReturn(true); return issue; } @@ -568,8 +568,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { ComponentDto project = newPrivateProjectDto(); ComponentDto branch = newBranchComponent(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto file = newFileDto(branch); - treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( - builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); + treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( + builder(Type.FILE, 11).setKey(file.getKey()).setName(file.longName()).build()).build()); analysisMetadataHolder.setProject(Project.from(project)); RuleDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; @@ -599,8 +599,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { @Test public void sends_one_issue_change_notification_every_1000_issues() { UserDto user = db.users().insertUser(); - ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName()); - ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName()); + ComponentDto project = newPrivateProjectDto().setKey(PROJECT.getKey()).setLongName(PROJECT.getName()); + ComponentDto file = newFileDto(project).setKey(FILE.getKey()).setLongName(FILE.getName()); RuleDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; List issues = IntStream.range(0, 2001 + new Random().nextInt(10)) @@ -700,8 +700,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { private ComponentDto setUpBranch(ComponentDto project, BranchType branchType) { ComponentDto branch = newBranchComponent(project, newBranchDto(project, branchType).setKey(BRANCH_NAME)); ComponentDto file = newFileDto(branch); - treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( - builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); + treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( + builder(Type.FILE, 11).setKey(file.getKey()).setName(file.longName()).build()).build()); return branch; } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepTest.java index 29c2eb8c9f7..e749ab9593b 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/UpdateNeedIssueSyncStepTest.java @@ -49,7 +49,7 @@ public class UpdateNeedIssueSyncStepTest { @Test public void analysis_step_updates_need_issue_sync_flag() { ComponentDto project = db.components() - .insertPrivateProject(c -> c.setUuid(PROJECT.getUuid()).setDbKey(PROJECT.getDbKey())); + .insertPrivateProject(c -> c.setUuid(PROJECT.getUuid()).setKey(PROJECT.getKey())); dbClient.branchDao().updateNeedIssueSync(db.getSession(), PROJECT.getUuid(), true); db.getSession().commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java index 8f7dfe180bd..0e36782973a 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java @@ -80,7 +80,7 @@ public class ValidateProjectStepTest { @Test public void not_fail_if_analysis_date_is_after_last_analysis() { - ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY); + ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY); db.components().insertComponent(project); dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(PAST_ANALYSIS_TIME)); db.getSession().commit(); @@ -112,7 +112,7 @@ public class ValidateProjectStepTest { public void fail_if_analysis_date_is_before_last_analysis() { analysisMetadataHolder.setAnalysisDate(DateUtils.parseDate("2015-01-01")); - ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setDbKey(PROJECT_KEY); + ComponentDto project = ComponentTesting.newPrivateProjectDto("ABCD").setKey(PROJECT_KEY); db.components().insertComponent(project); dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1433131200000L)); // 2015-06-01 db.getSession().commit(); @@ -129,7 +129,7 @@ public class ValidateProjectStepTest { @Test public void fail_when_project_key_is_invalid() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("inv$lid!")); + ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("inv$lid!")); db.components().insertSnapshot(project, a -> a.setCreatedAt(PAST_ANALYSIS_TIME)); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1) .setUuid(project.uuid()) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java index 8e05800f5ed..c5a8dc8d5cb 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java @@ -90,7 +90,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_analysis() { - ComponentDto viewDto = save(ComponentTesting.newPortfolio("UUID_VIEW").setDbKey("KEY_VIEW")); + ComponentDto viewDto = save(ComponentTesting.newPortfolio("UUID_VIEW").setKey("KEY_VIEW")); save(ComponentTesting.newSubPortfolio(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); save(newPrivateProjectDto("proj")); dbTester.getSession().commit(); @@ -116,7 +116,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_snapshots_with_new_code_period() { - ComponentDto viewDto = save(ComponentTesting.newPortfolio("UUID_VIEW").setDbKey("KEY_VIEW")); + ComponentDto viewDto = save(ComponentTesting.newPortfolio("UUID_VIEW").setKey("KEY_VIEW")); ComponentDto subViewDto = save(ComponentTesting.newSubPortfolio(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); dbTester.getSession().commit(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java index 792586ca326..0ba046193a3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java @@ -298,7 +298,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { ComponentDto project = ComponentTesting.newPrivateProjectDto(); persistComponents(view, project); ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view) - .setDbKey(PROJECT_VIEW_1_KEY) + .setKey(PROJECT_VIEW_1_KEY) .setName("Old name") .setCreatedAt(now); persistComponents(projectView); @@ -328,7 +328,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { // Project view in DB is associated to project1 ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project1, view) - .setDbKey(PROJECT_VIEW_1_KEY) + .setKey(PROJECT_VIEW_1_KEY) .setCreatedAt(now); persistComponents(projectView); @@ -393,7 +393,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() { boolean isRootPrivate = new Random().nextBoolean(); ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto()); - ComponentDto view = newViewDto().setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); + ComponentDto view = newViewDto().setUuid(VIEW_UUID).setKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); dbTester.components().insertComponent(view); treeRootHolder.setRoot( createViewBuilder(PORTFOLIO) @@ -416,11 +416,11 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() { boolean isRootPrivate = new Random().nextBoolean(); ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto()); - ComponentDto view = newViewDto().setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); + ComponentDto view = newViewDto().setUuid(VIEW_UUID).setKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate); dbTester.components().insertComponent(view); - ComponentDto subView = newSubPortfolio(view).setUuid("BCDE").setDbKey("MODULE").setPrivate(!isRootPrivate); + ComponentDto subView = newSubPortfolio(view).setUuid("BCDE").setKey("MODULE").setPrivate(!isRootPrivate); dbTester.components().insertComponent(subView); - dbTester.components().insertComponent(newProjectCopy("DEFG", project, view).setDbKey("DIR").setPrivate(isRootPrivate)); + dbTester.components().insertComponent(newProjectCopy("DEFG", project, view).setKey("DIR").setPrivate(isRootPrivate)); treeRootHolder.setRoot( createViewBuilder(PORTFOLIO) .addChildren( @@ -459,7 +459,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { .setUuid(PROJECT_VIEW_1_UUID) .setName(PROJECT_VIEW_1_NAME) .setDescription("project view description is not persisted") - .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), project.getDbKey(), analysisDate, project.getBranch())); + .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), project.getKey(), analysisDate, project.getBranch())); } private void persistComponents(ComponentDto... componentDtos) { @@ -480,7 +480,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { private ComponentDto newViewDto() { return ComponentTesting.newPortfolio(VIEW_UUID) - .setDbKey(VIEW_KEY) + .setKey(VIEW_KEY) .setName(VIEW_NAME); } @@ -498,7 +498,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); assertThat(dto.path()).isNull(); assertThat(dto.uuid()).isEqualTo(VIEW_UUID); - assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID); + assertThat(dto.branchUuid()).isEqualTo(VIEW_UUID); assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID); assertThat(dto.moduleUuid()).isNull(); assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + "."); @@ -517,7 +517,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION); assertThat(dto.path()).isNull(); assertThat(dto.uuid()).isEqualTo(VIEW_UUID); - assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID); + assertThat(dto.branchUuid()).isEqualTo(VIEW_UUID); assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID); assertThat(dto.moduleUuid()).isNull(); assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + "."); @@ -536,7 +536,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION); assertThat(sv1Dto.path()).isNull(); assertThat(sv1Dto.uuid()).isEqualTo(SUBVIEW_1_UUID); - assertThat(sv1Dto.projectUuid()).isEqualTo(viewDto.uuid()); + assertThat(sv1Dto.branchUuid()).isEqualTo(viewDto.uuid()); assertThat(sv1Dto.getRootUuid()).isEqualTo(viewDto.uuid()); assertThat(sv1Dto.moduleUuid()).isEqualTo(viewDto.uuid()); assertThat(sv1Dto.moduleUuidPath()).isEqualTo(viewDto.moduleUuidPath() + sv1Dto.uuid() + "."); @@ -552,7 +552,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { assertThat(pv1Dto.description()).isNull(); assertThat(pv1Dto.path()).isNull(); assertThat(pv1Dto.uuid()).isEqualTo(PROJECT_VIEW_1_UUID); - assertThat(pv1Dto.projectUuid()).isEqualTo(viewDto.uuid()); + assertThat(pv1Dto.branchUuid()).isEqualTo(viewDto.uuid()); assertThat(pv1Dto.getRootUuid()).isEqualTo(viewDto.uuid()); assertThat(pv1Dto.moduleUuid()).isEqualTo(parentViewDto.uuid()); assertThat(pv1Dto.moduleUuidPath()).isEqualTo(parentViewDto.moduleUuidPath() + pv1Dto.uuid() + "."); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java index 552c8cb8488..4569a9eb7ff 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/analysis/ExportAnalysesStepTest.java @@ -60,7 +60,7 @@ public class ExportAnalysesStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) - .setDbKey("the_project") + .setKey("the_project") .setName("The Project") .setDescription("The project description") .setEnabled(true) @@ -69,7 +69,7 @@ public class ExportAnalysesStepTest { .setRootUuid(PROJECT_UUID) .setModuleUuid(null) .setModuleUuidPath("." + PROJECT_UUID + ".") - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); private static final String MODULE_UUID = "MODULE_UUID"; private static final String MODULE_UUID_PATH = UUID_PATH_OF_ROOT + UUID_PATH_SEPARATOR + MODULE_UUID; @@ -77,7 +77,7 @@ public class ExportAnalysesStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.MODULE) - .setDbKey("the_module") + .setKey("the_module") .setName("The Module") .setDescription("description of module") .setEnabled(true) @@ -86,14 +86,14 @@ public class ExportAnalysesStepTest { .setRootUuid(MODULE_UUID) .setModuleUuid(PROJECT_UUID) .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.") - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); private static final String FILE_UUID = "FILE_UUID"; private static final ComponentDto FILE = new ComponentDto() // no id yet .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) - .setDbKey("the_file") + .setKey("the_file") .setName("The File") .setUuid(FILE_UUID) .setUuidPath(MODULE_UUID_PATH + UUID_PATH_SEPARATOR + FILE_UUID) @@ -101,7 +101,7 @@ public class ExportAnalysesStepTest { .setEnabled(true) .setModuleUuid(MODULE_UUID) .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.") - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepTest.java index cf4d9543828..ace1622934d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepTest.java @@ -57,7 +57,7 @@ public class ExportBranchesStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) - .setDbKey("the_project") + .setKey("the_project") .setName("The Project") .setDescription("The project description") .setEnabled(true) @@ -66,7 +66,7 @@ public class ExportBranchesStepTest { .setRootUuid(PROJECT_UUID) .setModuleUuid(null) .setModuleUuidPath("." + PROJECT_UUID + ".") - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); @Rule public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java index 95112cb3587..256134357af 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepTest.java @@ -53,7 +53,7 @@ public class ExportComponentsStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) - .setDbKey("the_project") + .setKey("the_project") .setName("The Project") .setDescription("The project description") .setEnabled(true) @@ -63,7 +63,7 @@ public class ExportComponentsStepTest { .setModuleUuid(null) .setModuleUuidPath("." + PROJECT_UUID + ".") .setCreatedAt(new Date(1596749115856L)) - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); private static final String MODULE_UUID = "MODULE_UUID"; private static final String MODULE_UUID_PATH = UUID_PATH_OF_ROOT + MODULE_UUID + UUID_PATH_SEPARATOR; @@ -71,7 +71,7 @@ public class ExportComponentsStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.MODULE) - .setDbKey("the_module") + .setKey("the_module") .setName("The Module") .setDescription("description of module") .setEnabled(true) @@ -81,7 +81,7 @@ public class ExportComponentsStepTest { .setModuleUuid(PROJECT_UUID) .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.") .setCreatedAt(new Date(1596749132539L)) - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); private static final String FILE_UUID = "FILE_UUID"; private static final String FILE_UUID_PATH = MODULE_UUID_PATH + FILE_UUID + UUID_PATH_SEPARATOR; @@ -89,7 +89,7 @@ public class ExportComponentsStepTest { // no id yet .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) - .setDbKey("the_file") + .setKey("the_file") .setName("The File") .setUuid(FILE_UUID) .setRootUuid(MODULE_UUID) @@ -98,7 +98,7 @@ public class ExportComponentsStepTest { .setModuleUuid(MODULE_UUID) .setModuleUuidPath("." + PROJECT_UUID + ".MODULE_UUID.") .setCreatedAt(new Date(1596749148406L)) - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java index 437996f023f..03136fac933 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/issue/ExportIssuesStepTest.java @@ -360,7 +360,7 @@ public class ExportIssuesStepTest { } private ProjectDto createProject() { - ComponentDto projectDto = dbTester.components().insertPrivateProject(c -> c.setDbKey(PROJECT_KEY).setUuid(SOME_PROJECT_UUID)); + ComponentDto projectDto = dbTester.components().insertPrivateProject(c -> c.setKey(PROJECT_KEY).setUuid(SOME_PROJECT_UUID)); dbTester.commit(); return dbTester.components().getProjectDto(projectDto); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java index 60fdd5efc6c..dab76d1d232 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepTest.java @@ -61,7 +61,7 @@ public class ExportAdHocRulesStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) - .setDbKey("the_project") + .setKey("the_project") .setName("The Project") .setDescription("The project description") .setEnabled(true) @@ -70,7 +70,7 @@ public class ExportAdHocRulesStepTest { .setRootUuid(PROJECT_UUID) .setModuleUuid(null) .setModuleUuidPath("." + PROJECT_UUID + ".") - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); private static final List BRANCHES = ImmutableList.of( new BranchDto().setBranchType(BranchType.PULL_REQUEST).setProjectUuid(PROJECT_UUID).setKey("pr-1").setUuid("pr-1-uuid").setMergeBranchUuid("master"), diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java index c81dcebc7a9..7206e841b9c 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportEventsStepTest.java @@ -51,10 +51,10 @@ public class ExportEventsStepTest { .setUuid(PROJECT_UUID) .setUuidPath(UUID_PATH_OF_ROOT) .setRootUuid(PROJECT_UUID) - .setProjectUuid(PROJECT_UUID) + .setBranchUuid(PROJECT_UUID) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) - .setDbKey("the_project") + .setKey("the_project") .setEnabled(true); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepTest.java index 4566f46913a..5e6248f4eae 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportLinksStepTest.java @@ -49,7 +49,7 @@ public class ExportLinksStepTest { // no id yet .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.PROJECT) - .setDbKey("the_project") + .setKey("the_project") .setName("The Project") .setDescription("The project description") .setEnabled(true) @@ -58,7 +58,7 @@ public class ExportLinksStepTest { .setUuidPath(UUID_PATH_OF_ROOT) .setModuleUuid(null) .setModuleUuidPath("." + PROJECT_UUID + ".") - .setProjectUuid(PROJECT_UUID); + .setBranchUuid(PROJECT_UUID); @Rule public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java index e681f8448e5..faccb9279b3 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportMeasuresStepTest.java @@ -49,24 +49,24 @@ import static org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED; public class ExportMeasuresStepTest { private static final ComponentDto PROJECT = new ComponentDto() - .setDbKey("project_key") + .setKey("project_key") .setUuid("project_uuid") .setRootUuid("project_uuid") - .setProjectUuid("project_uuid") + .setBranchUuid("project_uuid") .setUuidPath(UUID_PATH_OF_ROOT) .setEnabled(true); private static final ComponentDto FILE = new ComponentDto() - .setDbKey("file_key") + .setKey("file_key") .setUuid("file_uuid") .setRootUuid("project_uuid") - .setProjectUuid("project_uuid") + .setBranchUuid("project_uuid") .setUuidPath(UUID_PATH_OF_ROOT + PROJECT.uuid() + UUID_PATH_SEPARATOR) .setEnabled(true); private static final ComponentDto ANOTHER_PROJECT = new ComponentDto() - .setDbKey("another_project_key") + .setKey("another_project_key") .setUuid("another_project_uuid") .setRootUuid("another_project_uuid") - .setProjectUuid("another_project_uuid") + .setBranchUuid("another_project_uuid") .setUuidPath(UUID_PATH_OF_ROOT) .setEnabled(true); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepTest.java index ec9393f4f92..ce87c38f7e0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepTest.java @@ -54,18 +54,18 @@ public class ExportNewCodePeriodsStepTest { .setUuid(PROJECT_UUID) .setUuidPath(UUID_PATH_OF_ROOT) .setRootUuid(PROJECT_UUID) - .setProjectUuid(PROJECT_UUID) + .setBranchUuid(PROJECT_UUID) .setQualifier(Qualifiers.PROJECT) .setName("project") - .setDbKey("the_project"); + .setKey("the_project"); private static final ComponentDto ANOTHER_PROJECT = new ComponentDto() .setUuid(ANOTHER_PROJECT_UUID) .setUuidPath(UUID_PATH_OF_ROOT) .setRootUuid(ANOTHER_PROJECT_UUID) - .setProjectUuid(ANOTHER_PROJECT_UUID) + .setBranchUuid(ANOTHER_PROJECT_UUID) .setQualifier(Qualifiers.PROJECT) .setName("another_project") - .setDbKey("another_project"); + .setKey("another_project"); private static final List PROJECT_BRANCHES = ImmutableList.of( new BranchDto().setBranchType(BranchType.PULL_REQUEST).setProjectUuid(PROJECT_UUID).setKey("pr-1").setUuid("pr-uuid-1").setMergeBranchUuid("master"), diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepTest.java index d471a915e7e..49c11d277ea 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepTest.java @@ -48,14 +48,14 @@ public class ExportSettingsStepTest { .setUuid("project_uuid") .setUuidPath(UUID_PATH_OF_ROOT) .setRootUuid("project_uuid") - .setProjectUuid("project_uuid") - .setDbKey("the_project"); + .setBranchUuid("project_uuid") + .setKey("the_project"); private static final ComponentDto ANOTHER_PROJECT = new ComponentDto() .setUuid("another_project_uuid") .setUuidPath(UUID_PATH_OF_ROOT) .setRootUuid("another_project_uuid") - .setProjectUuid("another_project_uuid") - .setDbKey("another_project"); + .setBranchUuid("another_project_uuid") + .setKey("another_project"); @Rule public LogTester logTester = new LogTester(); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepTest.java index 466faf4533c..7d4bd734caf 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/LoadProjectStepTest.java @@ -68,7 +68,7 @@ public class LoadProjectStepTest { @Test public void registers_project_if_valid() { - ComponentDto project = dbTester.components().insertPublicProject(c -> c.setDbKey(PROJECT_KEY)); + ComponentDto project = dbTester.components().insertPublicProject(c -> c.setKey(PROJECT_KEY)); underTest.execute(new TestComputationStepContext()); assertThat(definitionHolder.projectDto().getKey()).isEqualTo(project.getKey()); } diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ReportComponent.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ReportComponent.java index 5bcbcd9d11c..c99dc67efb3 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ReportComponent.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ReportComponent.java @@ -40,7 +40,6 @@ public class ReportComponent implements Component { public static final Component DUMB_PROJECT = builder(Type.PROJECT, 1) .setKey("PROJECT_KEY") - .setPublicKey("PUBLIC_PROJECT_KEY") .setUuid("PROJECT_UUID") .setName("Project Name") .setProjectVersion("1.0-SNAPSHOT") @@ -53,7 +52,6 @@ public class ReportComponent implements Component { @CheckForNull private final String description; private final String key; - private final String publicKey; private final String uuid; private final ProjectAttributes projectAttributes; private final ReportAttributes reportAttributes; @@ -64,7 +62,6 @@ public class ReportComponent implements Component { this.type = builder.type; this.status = builder.status; this.key = builder.key; - this.publicKey = builder.publicKey; this.name = builder.name == null ? String.valueOf(builder.key) : builder.name; this.shortName = builder.shortName == null ? this.name : builder.shortName; this.description = builder.description; @@ -97,21 +94,13 @@ public class ReportComponent implements Component { } @Override - public String getDbKey() { + public String getKey() { if (key == null) { throw new UnsupportedOperationException(String.format("Component key of ref '%d' has not be fed yet", this.reportAttributes.getRef())); } return key; } - @Override - public String getKey() { - if (publicKey == null) { - throw new UnsupportedOperationException(String.format("Component key of ref '%d' has not be fed yet", this.reportAttributes.getRef())); - } - return publicKey; - } - @Override public String getName() { return this.name; @@ -192,7 +181,7 @@ public class ReportComponent implements Component { } public static Builder builder(Type type, int ref, String key) { - return new Builder(type, ref).setKey(key).setPublicKey(key).setUuid("uuid_" + ref).setName("name_" + ref); + return new Builder(type, ref).setKey(key).setUuid("uuid_" + ref).setName("name_" + ref); } public static Builder builder(Type type, int ref) { @@ -205,7 +194,6 @@ public class ReportComponent implements Component { private Status status; private String uuid; private String key; - private String publicKey; private String name; private String shortName; private String projectVersion; @@ -249,11 +237,6 @@ public class ReportComponent implements Component { return this; } - public Builder setPublicKey(String publicKey) { - this.publicKey = requireNonNull(publicKey); - return this; - } - public Builder setProjectVersion(@Nullable String s) { checkProjectVersion(s); this.projectVersion = s; diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeComponentProvider.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeComponentProvider.java index 24683fcfe8c..38665c35348 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeComponentProvider.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeComponentProvider.java @@ -34,7 +34,7 @@ public final class TreeComponentProvider extends AbstractComponentProvider { } private static String getRef(Component component) { - return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getDbKey(); + return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getKey(); } @Override diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderRule.java index ffe4830db1b..aeb2ce00f55 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderRule.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/TreeRootHolderRule.java @@ -72,7 +72,7 @@ public class TreeRootHolderRule extends ExternalResource implements TreeRootHold new TypeAwareVisitorAdapter(CrawlerDepthLimit.LEAVES, POST_ORDER) { @Override public void visitAny(Component component) { - builder.put(component.getDbKey(), component); + builder.put(component.getKey(), component); } }).visit(getRoot()); this.componentsByKey = builder.build(); diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ViewsComponent.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ViewsComponent.java index 9597710d0ef..e6ee9be30cc 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ViewsComponent.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/component/ViewsComponent.java @@ -152,17 +152,12 @@ public class ViewsComponent implements Component { return uuid; } - @Override - public String getDbKey() { - return key; - } - /** * Views has no branch feature, the public key is the same as the key */ @Override public String getKey() { - return getDbKey(); + return this.key; } @Override diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java index 973f1176d21..e68d51fd69e 100644 --- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java +++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java @@ -272,30 +272,6 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe } private static String getRef(Component component) { - return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getDbKey(); + return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getKey(); } - - private static class MatchMetric implements Predicate> { - private final Metric metric; - - public MatchMetric(Metric metric) { - this.metric = metric; - } - - @Override - public boolean apply(@Nonnull Map.Entry input) { - return input.getKey().getMetricKey().equals(metric.getKey()); - } - } - - private enum ToMeasure implements Function, Measure> { - INSTANCE; - - @Nullable - @Override - public Measure apply(@Nonnull Map.Entry input) { - return input.getValue(); - } - } - } -- cgit v1.2.3